Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions modules/renders/rendergl/includes/commandbuffergl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <commandbuffer.h>

class TextureGL;

class CommandBufferGL : public CommandBuffer {
A_OBJECT_OVERRIDE(CommandBufferGL, CommandBuffer, System)

Expand All @@ -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;

Expand All @@ -35,6 +39,8 @@ class CommandBufferGL : public CommandBuffer {
protected:
uint32_t m_globalBuffer;

uint32_t m_textures[32];

};

#endif // COMMANDBUFFERGL_H
19 changes: 19 additions & 0 deletions modules/renders/rendergl/src/commandbuffergl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);

Expand Down
17 changes: 1 addition & 16 deletions modules/renders/rendergl/src/resources/materialgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextureGL *>(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<TextureGL *>(texture(*buffer, it.binding)));
i++;
}

Expand Down
Loading