Skip to content

Commit

Permalink
Fix #1759
Browse files Browse the repository at this point in the history
  • Loading branch information
halx99 committed Mar 20, 2024
1 parent 43b1b73 commit 2701bd1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions core/renderer/backend/opengl/OpenGLState.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ struct OpenGLState
};

constexpr static int MAX_VERTEX_ATTRIBS = 16;
constexpr static int MAX_TEXTURE_UNITS = 16;

template <typename _Left>
static inline void try_enable(GLenum target, _Left& opt)
Expand Down Expand Up @@ -259,12 +260,20 @@ struct OpenGLState
void stencilMaskFront(GLuint v) { try_callu(glStencilMaskSeparate, GL_FRONT, _stencilMaskFront, v); }
void stencilMaskBack(GLuint v) { try_callu(glStencilMaskSeparate, GL_BACK, _stencilMaskBack, v); }
void activeTexture(GLenum v) { try_call(glActiveTexture, _activeTexture, v); }
void bindTexture(GLenum target, GLuint handle) { try_callx(glBindTexture, _textureBinding, target, handle); }
void bindTexture(GLenum target, GLuint handle) {
auto activeLayer = _activeTexture.has_value() ? _activeTexture.value() - GL_TEXTURE0 : 0;
if(activeLayer < MAX_TEXTURE_UNITS)
try_callx(glBindTexture, _textureBindings[activeLayer], target, handle);
}
void deleteTexture(GLenum target, GLuint handle)
{
glDeleteTextures(1, &handle);
if (_textureBinding.has_value() && _textureBinding->handle == handle)
_textureBinding.reset();

for (auto& textureBinding : _textureBindings)
{
if (textureBinding.has_value() && textureBinding->handle == handle)
textureBinding.reset();
}
}
GLenum bindBuffer(BufferType type, GLuint buffer)
{
Expand Down Expand Up @@ -388,6 +397,7 @@ struct OpenGLState
uint32_t _attribBits{0}; // vertexAttribArray bitset
uint32_t _divisorBits{0}; // divisor bitset
std::optional<GLuint> _bufferBindings[(int)BufferType::COUNT];
std::optional<CommonBindState> _textureBindings[MAX_TEXTURE_UNITS];

std::optional<Viewport> _viewPort;
std::optional<Winding> _winding;
Expand Down Expand Up @@ -416,7 +426,6 @@ struct OpenGLState
std::optional<GLuint> _stencilMaskFront;
std::optional<GLuint> _stencilMaskBack;
std::optional<GLenum> _activeTexture;
std::optional<CommonBindState> _textureBinding;
std::optional<UniformBufferBaseBindState> _uniformBufferState;
};

Expand Down
2 changes: 1 addition & 1 deletion core/renderer/backend/opengl/TextureGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void TextureInfoGL::recreateAll(GLenum target)
{
if (texID)
{
glDeleteTextures(1, &texID);
__gl->deleteTexture(target, texID);
texID = 0;
ensure(idx, target);
}
Expand Down

0 comments on commit 2701bd1

Please sign in to comment.