diff --git a/modules/renders/rendergl/includes/commandbuffergl.h b/modules/renders/rendergl/includes/commandbuffergl.h index 690598e96..116ecec1c 100644 --- a/modules/renders/rendergl/includes/commandbuffergl.h +++ b/modules/renders/rendergl/includes/commandbuffergl.h @@ -3,6 +3,8 @@ #include +class TextureGL; + class CommandBufferGL : public CommandBuffer { A_OBJECT_OVERRIDE(CommandBufferGL, CommandBuffer, System) @@ -12,6 +14,8 @@ class CommandBufferGL : public CommandBuffer { static void setObjectName(int32_t type, int32_t id, const TString &name); + void bindTexture(uint32_t index, TextureGL *texture); + protected: void dispatchCompute(ComputeInstance &shader, int32_t groupsX, int32_t groupsY, int32_t groupsZ) override; @@ -35,6 +39,8 @@ class CommandBufferGL : public CommandBuffer { protected: uint32_t m_globalBuffer; + uint32_t m_textures[32]; + }; #endif // COMMANDBUFFERGL_H diff --git a/modules/renders/rendergl/src/commandbuffergl.cpp b/modules/renders/rendergl/src/commandbuffergl.cpp index 93c4e5e34..f3e87487b 100644 --- a/modules/renders/rendergl/src/commandbuffergl.cpp +++ b/modules/renders/rendergl/src/commandbuffergl.cpp @@ -3,6 +3,7 @@ #include "agl.h" #include "resources/meshgl.h" +#include "resources/texturegl.h" #include "resources/materialgl.h" #include "resources/rendertargetgl.h" #include "resources/computeshadergl.h" @@ -149,6 +150,24 @@ void CommandBufferGL::setObjectName(int32_t type, int32_t id, const TString &nam #endif } +void CommandBufferGL::bindTexture(uint32_t index, TextureGL *texture) { + if(texture) { + uint32_t handle = texture->nativeHandle(); + + if(handle != m_textures[index]) { + uint32_t textureType = (texture->depth() > 1) ? GL_TEXTURE_3D : GL_TEXTURE_2D; + if(texture->isCubemap()) { + textureType = GL_TEXTURE_CUBE_MAP; + } + + glActiveTexture(GL_TEXTURE0 + index); + glBindTexture(textureType, handle); + + m_textures[index] = handle; + } + } +} + void CommandBufferGL::setViewProjection(const Matrix4 &viewProjection) { CommandBuffer::setViewProjection(viewProjection); diff --git a/modules/renders/rendergl/src/resources/materialgl.cpp b/modules/renders/rendergl/src/resources/materialgl.cpp index 11a20205f..19ec60e26 100644 --- a/modules/renders/rendergl/src/resources/materialgl.cpp +++ b/modules/renders/rendergl/src/resources/materialgl.cpp @@ -395,23 +395,8 @@ bool MaterialInstanceGL::bind(CommandBufferGL *buffer, uint32_t layer, uint32_t } uint8_t i = 0; - - static uint32_t textures[32]; for(auto &it : material->textures()) { - Texture *tex = texture(*buffer, it.binding); - if(tex) { - uint32_t handle = static_cast(tex)->nativeHandle(); - if(handle != textures[i]) { - uint32_t textureType = (tex->depth() > 1) ? GL_TEXTURE_3D : GL_TEXTURE_2D; - if(tex->isCubemap()) { - textureType = GL_TEXTURE_CUBE_MAP; - } - - glActiveTexture(GL_TEXTURE0 + i); - glBindTexture(textureType, handle); - textures[i] = handle; - } - } + buffer->bindTexture(i, static_cast(texture(*buffer, it.binding))); i++; }