Skip to content

Commit

Permalink
Merge branch 'gl_texture_cache_fix' of https://github.com/allcreater/…
Browse files Browse the repository at this point in the history
…sokol into allcreater-gl_texture_cache_fix
  • Loading branch information
floooh committed Feb 15, 2023
2 parents 966f49b + 79f22b5 commit e6a6d0e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions sokol_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -4069,6 +4069,10 @@ typedef struct {
GLuint texture;
} _sg_gl_texture_bind_slot;

enum {
_SG_GL_IMAGE_CACHE_SIZE = SG_MAX_SHADERSTAGE_IMAGES * SG_NUM_SHADER_STAGES,
};

typedef struct {
sg_depth_state depth;
sg_stencil_state stencil;
Expand All @@ -4086,7 +4090,7 @@ typedef struct {
GLuint stored_vertex_buffer;
GLuint stored_index_buffer;
GLuint prog;
_sg_gl_texture_bind_slot textures[SG_MAX_SHADERSTAGE_IMAGES];
_sg_gl_texture_bind_slot textures[_SG_GL_IMAGE_CACHE_SIZE];
_sg_gl_texture_bind_slot stored_texture;
int cur_ib_offset;
GLenum cur_primitive_type;
Expand Down Expand Up @@ -6719,7 +6723,7 @@ _SOKOL_PRIVATE void _sg_gl_cache_active_texture(GLenum texture) {
}

_SOKOL_PRIVATE void _sg_gl_cache_clear_texture_bindings(bool force) {
for (int i = 0; (i < SG_MAX_SHADERSTAGE_IMAGES) && (i < _sg.gl.max_combined_texture_image_units); i++) {
for (int i = 0; (i < _SG_GL_IMAGE_CACHE_SIZE) && (i < _sg.gl.max_combined_texture_image_units); i++) {
if (force || (_sg.gl.cache.textures[i].texture != 0)) {
GLenum gl_texture_slot = (GLenum) (GL_TEXTURE0 + i);
glActiveTexture(gl_texture_slot);
Expand All @@ -6743,7 +6747,7 @@ _SOKOL_PRIVATE void _sg_gl_cache_bind_texture(int slot_index, GLenum target, GLu
target=0 will unbind the previous binding, texture=0 will clear
the new binding
*/
SOKOL_ASSERT(slot_index < SG_MAX_SHADERSTAGE_IMAGES);
SOKOL_ASSERT(slot_index < _SG_GL_IMAGE_CACHE_SIZE);
if (slot_index >= _sg.gl.max_combined_texture_image_units) {
return;
}
Expand All @@ -6764,12 +6768,12 @@ _SOKOL_PRIVATE void _sg_gl_cache_bind_texture(int slot_index, GLenum target, GLu
}

_SOKOL_PRIVATE void _sg_gl_cache_store_texture_binding(int slot_index) {
SOKOL_ASSERT(slot_index < SG_MAX_SHADERSTAGE_IMAGES);
SOKOL_ASSERT(slot_index < _SG_GL_IMAGE_CACHE_SIZE);
_sg.gl.cache.stored_texture = _sg.gl.cache.textures[slot_index];
}

_SOKOL_PRIVATE void _sg_gl_cache_restore_texture_binding(int slot_index) {
SOKOL_ASSERT(slot_index < SG_MAX_SHADERSTAGE_IMAGES);
SOKOL_ASSERT(slot_index < _SG_GL_IMAGE_CACHE_SIZE);
_sg_gl_texture_bind_slot* slot = &_sg.gl.cache.stored_texture;
if (slot->texture != 0) {
/* we only care restoring valid ids */
Expand All @@ -6782,7 +6786,7 @@ _SOKOL_PRIVATE void _sg_gl_cache_restore_texture_binding(int slot_index) {

/* called from _sg_gl_destroy_texture() */
_SOKOL_PRIVATE void _sg_gl_cache_invalidate_texture(GLuint tex) {
for (int i = 0; i < SG_MAX_SHADERSTAGE_IMAGES; i++) {
for (int i = 0; i < _SG_GL_IMAGE_CACHE_SIZE; i++) {
_sg_gl_texture_bind_slot* slot = &_sg.gl.cache.textures[i];
if (tex == slot->texture) {
_sg_gl_cache_active_texture((GLenum)(GL_TEXTURE0 + i));
Expand Down

0 comments on commit e6a6d0e

Please sign in to comment.