mirror of https://github.com/AxioDL/boo.git
Much more efficient glClear solution
This commit is contained in:
parent
40e94f88e0
commit
165b40448f
|
@ -228,8 +228,6 @@ public:
|
||||||
void bind(size_t idx, int b);
|
void bind(size_t idx, int b);
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::vector<GLuint> DepthInitializer;
|
|
||||||
|
|
||||||
class GLTextureR : public ITextureR
|
class GLTextureR : public ITextureR
|
||||||
{
|
{
|
||||||
friend class GLDataFactory;
|
friend class GLDataFactory;
|
||||||
|
@ -281,10 +279,11 @@ public:
|
||||||
glBindTexture(GL_TEXTURE_2D, m_texs[0]);
|
glBindTexture(GL_TEXTURE_2D, m_texs[0]);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_texs[1]);
|
glBindTexture(GL_TEXTURE_2D, m_texs[1]);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr);
|
||||||
|
|
||||||
if (DepthInitializer.size() < width * height)
|
glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
|
||||||
DepthInitializer.resize(width * height, ~0);
|
glDepthMask(GL_TRUE);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, DepthInitializer.data());
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
if (m_bindTexs[0])
|
if (m_bindTexs[0])
|
||||||
{
|
{
|
||||||
|
@ -955,7 +954,6 @@ struct GLCommandQueue : IGraphicsCommandQueue
|
||||||
}
|
}
|
||||||
std::vector<Command>& cmds = self->m_cmdBufs[self->m_drawBuf];
|
std::vector<Command>& cmds = self->m_cmdBufs[self->m_drawBuf];
|
||||||
GLenum currentPrim = GL_TRIANGLES;
|
GLenum currentPrim = GL_TRIANGLES;
|
||||||
const GLTextureR* currentTarget = nullptr;
|
|
||||||
for (const Command& cmd : cmds)
|
for (const Command& cmd : cmds)
|
||||||
{
|
{
|
||||||
switch (cmd.m_op)
|
switch (cmd.m_op)
|
||||||
|
@ -974,7 +972,6 @@ struct GLCommandQueue : IGraphicsCommandQueue
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
else
|
else
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, tex->m_fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, tex->m_fbo);
|
||||||
currentTarget = tex;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Command::Op::SetViewport:
|
case Command::Op::SetViewport:
|
||||||
|
@ -996,24 +993,9 @@ struct GLCommandQueue : IGraphicsCommandQueue
|
||||||
break;
|
break;
|
||||||
case Command::Op::ClearTarget:
|
case Command::Op::ClearTarget:
|
||||||
{
|
{
|
||||||
if (!currentTarget)
|
|
||||||
break;
|
|
||||||
GLbitfield glFlags = cmd.flags & ~GL_DEPTH_BUFFER_BIT;
|
|
||||||
if (glFlags)
|
|
||||||
glClear(glFlags);
|
|
||||||
if (cmd.flags & GL_DEPTH_BUFFER_BIT)
|
if (cmd.flags & GL_DEPTH_BUFFER_BIT)
|
||||||
{
|
glDepthMask(GL_TRUE);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glClear(cmd.flags);
|
||||||
size_t texels = currentTarget->m_width * currentTarget->m_height;
|
|
||||||
if (DepthInitializer.size() < texels)
|
|
||||||
DepthInitializer.resize(texels, ~0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, currentTarget->m_texs[1]);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24,
|
|
||||||
currentTarget->m_width, currentTarget->m_height,
|
|
||||||
0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT,
|
|
||||||
DepthInitializer.data());
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, currentTarget->m_fbo);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Command::Op::Draw:
|
case Command::Op::Draw:
|
||||||
|
|
Loading…
Reference in New Issue