forked from LeenkxTeam/LNXSDK
VOX_PATCH_2 + VOX_5
This commit is contained in:
@ -821,8 +821,19 @@ int kinc_g4_max_bound_textures(void) {
|
||||
return units;
|
||||
}
|
||||
|
||||
static int getUnitStage(kinc_g4_texture_unit_t unit) {
|
||||
for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) {
|
||||
if (unit.stages[i] >= 0) {
|
||||
return unit.stages[i];
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void setTextureAddressingInternal(GLenum target, kinc_g4_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {
|
||||
glActiveTexture(GL_TEXTURE0 + unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
|
||||
int stage = getUnitStage(unit);
|
||||
if (stage < 0) return;
|
||||
glActiveTexture(GL_TEXTURE0 + stage);
|
||||
GLenum texDir;
|
||||
switch (dir) {
|
||||
case KINC_G4_TEXTURE_DIRECTION_U:
|
||||
@ -841,39 +852,39 @@ static void setTextureAddressingInternal(GLenum target, kinc_g4_texture_unit_t u
|
||||
case KINC_G4_TEXTURE_ADDRESSING_CLAMP:
|
||||
glTexParameteri(target, texDir, GL_CLAMP_TO_EDGE);
|
||||
if (dir == KINC_G4_TEXTURE_DIRECTION_U) {
|
||||
texModesU[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_CLAMP_TO_EDGE;
|
||||
texModesU[stage] = GL_CLAMP_TO_EDGE;
|
||||
}
|
||||
else {
|
||||
texModesV[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_CLAMP_TO_EDGE;
|
||||
texModesV[stage] = GL_CLAMP_TO_EDGE;
|
||||
}
|
||||
break;
|
||||
case KINC_G4_TEXTURE_ADDRESSING_REPEAT:
|
||||
glTexParameteri(target, texDir, GL_REPEAT);
|
||||
if (dir == KINC_G4_TEXTURE_DIRECTION_U) {
|
||||
texModesU[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_REPEAT;
|
||||
texModesU[stage] = GL_REPEAT;
|
||||
}
|
||||
else {
|
||||
texModesV[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_REPEAT;
|
||||
texModesV[stage] = GL_REPEAT;
|
||||
}
|
||||
break;
|
||||
case KINC_G4_TEXTURE_ADDRESSING_BORDER:
|
||||
// unsupported
|
||||
glTexParameteri(target, texDir, GL_CLAMP_TO_EDGE);
|
||||
if (dir == KINC_G4_TEXTURE_DIRECTION_U) {
|
||||
texModesU[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_CLAMP_TO_EDGE;
|
||||
texModesU[stage] = GL_CLAMP_TO_EDGE;
|
||||
}
|
||||
else {
|
||||
texModesV[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_CLAMP_TO_EDGE;
|
||||
texModesV[stage] = GL_CLAMP_TO_EDGE;
|
||||
}
|
||||
break;
|
||||
case KINC_G4_TEXTURE_ADDRESSING_MIRROR:
|
||||
// unsupported
|
||||
glTexParameteri(target, texDir, GL_REPEAT);
|
||||
if (dir == KINC_G4_TEXTURE_DIRECTION_U) {
|
||||
texModesU[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_REPEAT;
|
||||
texModesU[stage] = GL_REPEAT;
|
||||
}
|
||||
else {
|
||||
texModesV[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_REPEAT;
|
||||
texModesV[stage] = GL_REPEAT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -881,11 +892,15 @@ static void setTextureAddressingInternal(GLenum target, kinc_g4_texture_unit_t u
|
||||
}
|
||||
|
||||
int Kinc_G4_Internal_TextureAddressingU(kinc_g4_texture_unit_t unit) {
|
||||
return texModesU[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]];
|
||||
int stage = getUnitStage(unit);
|
||||
if (stage < 0) return GL_CLAMP_TO_EDGE;
|
||||
return texModesU[stage];
|
||||
}
|
||||
|
||||
int Kinc_G4_Internal_TextureAddressingV(kinc_g4_texture_unit_t unit) {
|
||||
return texModesV[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]];
|
||||
int stage = getUnitStage(unit);
|
||||
if (stage < 0) return GL_CLAMP_TO_EDGE;
|
||||
return texModesV[stage];
|
||||
}
|
||||
|
||||
void kinc_g4_set_texture_addressing(kinc_g4_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {
|
||||
@ -899,7 +914,9 @@ void kinc_g4_set_texture3d_addressing(kinc_g4_texture_unit_t unit, kinc_g4_textu
|
||||
}
|
||||
|
||||
static void setTextureMagnificationFilterInternal(GLenum target, kinc_g4_texture_unit_t texunit, kinc_g4_texture_filter_t filter) {
|
||||
glActiveTexture(GL_TEXTURE0 + texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
|
||||
int stage = getUnitStage(texunit);
|
||||
if (stage < 0) return;
|
||||
glActiveTexture(GL_TEXTURE0 + stage);
|
||||
glCheckErrors();
|
||||
switch (filter) {
|
||||
case KINC_G4_TEXTURE_FILTER_POINT:
|
||||
@ -964,26 +981,34 @@ static void setMinMipFilters(GLenum target, int unit) {
|
||||
}
|
||||
|
||||
void kinc_g4_set_texture_minification_filter(kinc_g4_texture_unit_t texunit, kinc_g4_texture_filter_t filter) {
|
||||
minFilters[texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = filter;
|
||||
setMinMipFilters(GL_TEXTURE_2D, texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
|
||||
int stage = getUnitStage(texunit);
|
||||
if (stage < 0) return;
|
||||
minFilters[stage] = filter;
|
||||
setMinMipFilters(GL_TEXTURE_2D, stage);
|
||||
}
|
||||
|
||||
void kinc_g4_set_texture3d_minification_filter(kinc_g4_texture_unit_t texunit, kinc_g4_texture_filter_t filter) {
|
||||
minFilters[texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = filter;
|
||||
int stage = getUnitStage(texunit);
|
||||
if (stage < 0) return;
|
||||
minFilters[stage] = filter;
|
||||
#ifndef KINC_OPENGL_ES
|
||||
setMinMipFilters(GL_TEXTURE_3D, texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
|
||||
setMinMipFilters(GL_TEXTURE_3D, stage);
|
||||
#endif
|
||||
}
|
||||
|
||||
void kinc_g4_set_texture_mipmap_filter(kinc_g4_texture_unit_t texunit, kinc_g4_mipmap_filter_t filter) {
|
||||
mipFilters[texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = filter;
|
||||
setMinMipFilters(GL_TEXTURE_2D, texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
|
||||
int stage = getUnitStage(texunit);
|
||||
if (stage < 0) return;
|
||||
mipFilters[stage] = filter;
|
||||
setMinMipFilters(GL_TEXTURE_2D, stage);
|
||||
}
|
||||
|
||||
void kinc_g4_set_texture3d_mipmap_filter(kinc_g4_texture_unit_t texunit, kinc_g4_mipmap_filter_t filter) {
|
||||
mipFilters[texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = filter;
|
||||
int stage = getUnitStage(texunit);
|
||||
if (stage < 0) return;
|
||||
mipFilters[stage] = filter;
|
||||
#ifndef KINC_OPENGL_ES
|
||||
setMinMipFilters(GL_TEXTURE_3D, texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
|
||||
setMinMipFilters(GL_TEXTURE_3D, stage);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -190,6 +190,17 @@ void kinc_g4_set_compute_shader(kinc_g4_compute_shader *shader) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void kinc_g4_set_image_render_target(kinc_g4_texture_unit_t unit, kinc_g4_render_target_t *render_target) {
|
||||
#if defined(KINC_WINDOWS) || (defined(KINC_LINUX) && defined(GL_VERSION_4_4))
|
||||
for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) {
|
||||
if (unit.stages[i] >= 0) {
|
||||
glBindImageTexture(unit.stages[i], render_target->impl._texture, 0, GL_FALSE, 0, GL_READ_WRITE, convertInternalRTFormat((kinc_g4_render_target_format_t)render_target->impl.format));
|
||||
}
|
||||
}
|
||||
glCheckErrors();
|
||||
#endif
|
||||
}
|
||||
|
||||
void kinc_g4_compute(int x, int y, int z) {
|
||||
#ifdef HAS_COMPUTE
|
||||
glDispatchCompute(x, y, z);
|
||||
|
||||
@ -360,17 +360,23 @@ void kinc_g4_render_target_destroy(kinc_g4_render_target_t *renderTarget) {
|
||||
}
|
||||
|
||||
void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderTarget, kinc_g4_texture_unit_t unit) {
|
||||
glActiveTexture(GL_TEXTURE0 + unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
|
||||
glCheckErrors();
|
||||
glBindTexture(renderTarget->isCubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, renderTarget->impl._texture);
|
||||
glCheckErrors();
|
||||
for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) {
|
||||
if (unit.stages[i] >= 0) {
|
||||
glActiveTexture(GL_TEXTURE0 + unit.stages[i]);
|
||||
glBindTexture(renderTarget->isCubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, renderTarget->impl._texture);
|
||||
glCheckErrors();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void kinc_g4_render_target_use_depth_as_texture(kinc_g4_render_target_t *renderTarget, kinc_g4_texture_unit_t unit) {
|
||||
glActiveTexture(GL_TEXTURE0 + unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
|
||||
glCheckErrors();
|
||||
glBindTexture(renderTarget->isCubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, renderTarget->impl._depthTexture);
|
||||
glCheckErrors();
|
||||
for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) {
|
||||
if (unit.stages[i] >= 0) {
|
||||
glActiveTexture(GL_TEXTURE0 + unit.stages[i]);
|
||||
glBindTexture(renderTarget->isCubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, renderTarget->impl._depthTexture);
|
||||
glCheckErrors();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void kinc_g4_render_target_set_depth_stencil_from(kinc_g4_render_target_t *renderTarget, kinc_g4_render_target_t *source) {
|
||||
|
||||
@ -99,6 +99,8 @@ static int convertFormat(kinc_image_format_t format) {
|
||||
case KINC_IMAGE_FORMAT_A16:
|
||||
case KINC_IMAGE_FORMAT_GREY8:
|
||||
return GL_RED;
|
||||
case KINC_IMAGE_FORMAT_R32UI:
|
||||
return GL_RED_INTEGER;
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,6 +134,8 @@ static int convertInternalFormat(kinc_image_format_t format) {
|
||||
#else
|
||||
return GL_R8;
|
||||
#endif
|
||||
case KINC_IMAGE_FORMAT_R32UI:
|
||||
return GL_R32UI;
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,6 +149,8 @@ static int convertType(kinc_image_format_t format) {
|
||||
case KINC_IMAGE_FORMAT_RGBA32:
|
||||
default:
|
||||
return GL_UNSIGNED_BYTE;
|
||||
case KINC_IMAGE_FORMAT_R32UI:
|
||||
return GL_UNSIGNED_INT;
|
||||
}
|
||||
}
|
||||
|
||||
@ -483,7 +489,7 @@ void kinc_g4_texture_init3d(kinc_g4_texture_t *texture, int width, int height, i
|
||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glCheckErrors();
|
||||
|
||||
glTexImage3D(GL_TEXTURE_3D, 0, convertInternalFormat(format), width, height, depth, 0, convertFormat(format), GL_UNSIGNED_BYTE, NULL);
|
||||
glTexImage3D(GL_TEXTURE_3D, 0, convertInternalFormat(format), width, height, depth, 0, convertFormat(format), convertType(format), NULL);
|
||||
glCheckErrors();
|
||||
#endif
|
||||
}
|
||||
@ -523,8 +529,8 @@ void Kinc_G4_Internal_TextureSet(kinc_g4_texture_t *texture, kinc_g4_texture_uni
|
||||
#else
|
||||
glBindTexture(target, texture->impl.texture);
|
||||
glCheckErrors();
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, Kinc_G4_Internal_TextureAddressingU(unit));
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, Kinc_G4_Internal_TextureAddressingV(unit));
|
||||
glTexParameteri(target, GL_TEXTURE_WRAP_S, Kinc_G4_Internal_TextureAddressingU(unit));
|
||||
glTexParameteri(target, GL_TEXTURE_WRAP_T, Kinc_G4_Internal_TextureAddressingV(unit));
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -532,7 +538,7 @@ void Kinc_G4_Internal_TextureImageSet(kinc_g4_texture_t *texture, kinc_g4_textur
|
||||
#if defined(KINC_WINDOWS) || (defined(KINC_LINUX) && defined(GL_VERSION_4_4))
|
||||
for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) {
|
||||
if (unit.stages[i] >= 0) {
|
||||
glBindImageTexture(unit.stages[i], texture->impl.texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, convertInternalFormat(texture->format));
|
||||
glBindImageTexture(unit.stages[i], texture->impl.texture, 0, GL_FALSE, 0, GL_READ_WRITE, convertInternalFormat(texture->format));
|
||||
}
|
||||
}
|
||||
glCheckErrors();
|
||||
|
||||
Reference in New Issue
Block a user