Skip to content

Commit

Permalink
Add Kong texture support for OpenGL
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Oct 4, 2023
1 parent aff73d2 commit d4fba32
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -789,12 +789,21 @@ void kinc_g4_set_index_buffer(kinc_g4_index_buffer_t *indexBuffer) {
kinc_internal_g4_index_buffer_set(indexBuffer);
}

void Kinc_G4_Internal_TextureSet(kinc_g4_texture_t *texture, kinc_g4_texture_unit_t unit);
void Kinc_G4_Internal_TextureImageSet(kinc_g4_texture_t *texture, kinc_g4_texture_unit_t unit);

#ifdef KINC_KONG
void Kinc_G4_Internal_TextureSet(kinc_g4_texture_t *texture, uint32_t unit);

void kinc_g4_set_texture(uint32_t unit, kinc_g4_texture_t *texture) {
Kinc_G4_Internal_TextureSet(texture, unit);
}
#else
void Kinc_G4_Internal_TextureSet(kinc_g4_texture_t *texture, kinc_g4_texture_unit_t unit);

void kinc_g4_set_texture(kinc_g4_texture_unit_t unit, kinc_g4_texture_t *texture) {
Kinc_G4_Internal_TextureSet(texture, unit);
}
#endif

void kinc_g4_set_image_texture(kinc_g4_texture_unit_t unit, kinc_g4_texture_t *texture) {
Kinc_G4_Internal_TextureImageSet(texture, unit);
Expand Down Expand Up @@ -865,13 +874,23 @@ static void setTextureAddressingInternal(GLenum target, kinc_g4_texture_unit_t u
glCheckErrors();
}

#ifdef KINC_KONG
int Kinc_G4_Internal_TextureAddressingU(uint32_t unit) {
return texModesU[unit];
}

int Kinc_G4_Internal_TextureAddressingV(uint32_t unit) {
return texModesV[unit];
}
#else
int Kinc_G4_Internal_TextureAddressingU(kinc_g4_texture_unit_t unit) {
return texModesU[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]];
}

int Kinc_G4_Internal_TextureAddressingV(kinc_g4_texture_unit_t unit) {
return texModesV[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]];
}
#endif

void kinc_g4_set_texture_addressing(kinc_g4_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {
setTextureAddressingInternal(GL_TEXTURE_2D, unit, dir, addressing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
extern "C" {
#endif

#ifdef KINC_KONG
int Kinc_G4_Internal_TextureAddressingU(uint32_t unit);
int Kinc_G4_Internal_TextureAddressingV(uint32_t unit);
#else
int Kinc_G4_Internal_TextureAddressingU(kinc_g4_texture_unit_t unit);
int Kinc_G4_Internal_TextureAddressingV(kinc_g4_texture_unit_t unit);
#endif
int Kinc_G4_Internal_StencilFunc(kinc_g4_compare_mode_t mode);

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,22 @@ void kinc_g4_render_target_destroy(kinc_g4_render_target_t *renderTarget) {
GLuint framebuffers[] = {renderTarget->impl._framebuffer};
glDeleteFramebuffers(1, framebuffers);
}

#ifdef KINC_KONG
void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderTarget, uint32_t unit) {
glActiveTexture(GL_TEXTURE0 + unit);
glCheckErrors();
glBindTexture(renderTarget->isCubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, renderTarget->impl._texture);
glCheckErrors();
}
#else
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();
}
#endif

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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,28 @@ void kinc_g4_texture_destroy(kinc_g4_texture_t *texture) {
glFlush();
}

#ifdef KINC_KONG
void Kinc_G4_Internal_TextureSet(kinc_g4_texture_t *texture, uint32_t unit) {
GLenum target = texture->tex_depth > 1 ? GL_TEXTURE_3D : GL_TEXTURE_2D;
glActiveTexture(GL_TEXTURE0 + unit);
glCheckErrors();
#ifdef KORE_ANDROID
if (texture->impl.external_oes) {
glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture->impl.texture);
glCheckErrors();
}
else {
glBindTexture(target, texture->impl.texture);
glCheckErrors();
}
#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));
#endif
}
#else
void Kinc_G4_Internal_TextureSet(kinc_g4_texture_t *texture, kinc_g4_texture_unit_t unit) {
GLenum target = texture->tex_depth > 1 ? GL_TEXTURE_3D : GL_TEXTURE_2D;
glActiveTexture(GL_TEXTURE0 + unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
Expand All @@ -522,6 +544,7 @@ void Kinc_G4_Internal_TextureSet(kinc_g4_texture_t *texture, kinc_g4_texture_uni
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, Kinc_G4_Internal_TextureAddressingV(unit));
#endif
}
#endif

void Kinc_G4_Internal_TextureImageSet(kinc_g4_texture_t *texture, kinc_g4_texture_unit_t unit) {
#if defined(KORE_WINDOWS) || (defined(KORE_LINUX) && defined(GL_VERSION_4_4))
Expand Down

0 comments on commit d4fba32

Please sign in to comment.