mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-19 23:11:03 +00:00
Fixed: depth tested FBO did not work
This commit is contained in:
parent
6f122d28c3
commit
99a90512f1
4 changed files with 28 additions and 14 deletions
|
@ -218,12 +218,18 @@ void RenderDevice::SetSamplerState(TextureAddress addressU, TextureAddress addre
|
|||
}
|
||||
}
|
||||
|
||||
void RenderDevice::ApplyViewport()
|
||||
{
|
||||
glViewport(0, 0, mViewportWidth, mViewportHeight);
|
||||
}
|
||||
|
||||
void RenderDevice::Draw(PrimitiveType type, int startIndex, int primitiveCount)
|
||||
{
|
||||
static const int modes[] = { GL_LINES, GL_TRIANGLES, GL_TRIANGLE_STRIP };
|
||||
static const int toVertexCount[] = { 2, 3, 1 };
|
||||
static const int toVertexStart[] = { 0, 0, 2 };
|
||||
|
||||
ApplyViewport();
|
||||
if (mNeedApply) ApplyChanges();
|
||||
glDrawArrays(modes[(int)type], startIndex, toVertexStart[(int)type] + primitiveCount * toVertexCount[(int)type]);
|
||||
}
|
||||
|
@ -234,6 +240,7 @@ void RenderDevice::DrawIndexed(PrimitiveType type, int startIndex, int primitive
|
|||
static const int toVertexCount[] = { 2, 3, 1 };
|
||||
static const int toVertexStart[] = { 0, 0, 2 };
|
||||
|
||||
ApplyViewport();
|
||||
if (mNeedApply) ApplyChanges();
|
||||
glDrawElements(modes[(int)type], toVertexStart[(int)type] + primitiveCount * toVertexCount[(int)type], GL_UNSIGNED_INT, (const void*)(startIndex * sizeof(uint32_t)));
|
||||
}
|
||||
|
@ -246,6 +253,7 @@ void RenderDevice::DrawData(PrimitiveType type, int startIndex, int primitiveCou
|
|||
|
||||
int vertcount = toVertexStart[(int)type] + primitiveCount * toVertexCount[(int)type];
|
||||
|
||||
ApplyViewport();
|
||||
if (mNeedApply) ApplyChanges();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mStreamVertexBuffer);
|
||||
|
@ -263,12 +271,16 @@ void RenderDevice::StartRendering(bool clear, int backcolor, Texture* target, bo
|
|||
if (target)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, target->GetFramebuffer(usedepthbuffer));
|
||||
glViewport(0, 0, target->GetWidth(), target->GetHeight());
|
||||
mViewportWidth = target->GetWidth();
|
||||
mViewportHeight = target->GetHeight();
|
||||
ApplyViewport();
|
||||
}
|
||||
else
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glViewport(0, 0, Context->GetWidth(), Context->GetHeight());
|
||||
mViewportWidth = Context->GetWidth();
|
||||
mViewportHeight = Context->GetHeight();
|
||||
ApplyViewport();
|
||||
}
|
||||
|
||||
if (clear && usedepthbuffer)
|
||||
|
|
|
@ -115,6 +115,7 @@ public:
|
|||
|
||||
void InvalidateTexture(Texture* texture);
|
||||
|
||||
void ApplyViewport();
|
||||
void ApplyChanges();
|
||||
void ApplyVertexBuffer();
|
||||
void ApplyIndexBuffer();
|
||||
|
@ -184,4 +185,7 @@ public:
|
|||
bool mRasterizerStateChanged = true;
|
||||
|
||||
bool mContextIsCurrent = false;
|
||||
|
||||
int mViewportWidth = 0;
|
||||
int mViewportHeight = 0;
|
||||
};
|
||||
|
|
|
@ -42,11 +42,9 @@ void Texture::Invalidate()
|
|||
{
|
||||
if (mDepthRenderbuffer) glDeleteRenderbuffers(1, &mDepthRenderbuffer);
|
||||
if (mFramebuffer) glDeleteFramebuffers(1, &mFramebuffer);
|
||||
if (mFramebufferDepth) glDeleteFramebuffers(1, &mFramebufferDepth);
|
||||
if (mTexture) glDeleteTextures(1, &mTexture);
|
||||
mDepthRenderbuffer = 0;
|
||||
mFramebuffer = 0;
|
||||
mFramebufferDepth = 0;
|
||||
mTexture = 0;
|
||||
}
|
||||
|
||||
|
@ -112,16 +110,16 @@ GLuint Texture::GetFramebuffer(bool usedepthbuffer)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (mFramebuffer == mFramebufferDepth)
|
||||
if (mDepthRenderbuffer == 0)
|
||||
{
|
||||
if (mDepthRenderbuffer == 0)
|
||||
{
|
||||
glGenRenderbuffers(1, &mDepthRenderbuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, mDepthRenderbuffer);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, mWidth, mHeight);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
}
|
||||
glGenRenderbuffers(1, &mDepthRenderbuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, mDepthRenderbuffer);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, mWidth, mHeight);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
}
|
||||
|
||||
if (mFramebuffer == 0)
|
||||
{
|
||||
GLuint texture = GetTexture();
|
||||
glGenFramebuffers(1, &mFramebuffer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
|
||||
|
@ -129,8 +127,9 @@ GLuint Texture::GetFramebuffer(bool usedepthbuffer)
|
|||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mDepthRenderbuffer);
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
throw std::runtime_error("glCheckFramebufferStatus did not return GL_FRAMEBUFFER_COMPLETE");
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
return mFramebufferDepth;
|
||||
return mFramebuffer;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,5 @@ private:
|
|||
std::map<int, std::vector<uint32_t>> mPixels;
|
||||
GLuint mTexture = 0;
|
||||
GLuint mFramebuffer = 0;
|
||||
GLuint mFramebufferDepth = 0;
|
||||
GLuint mDepthRenderbuffer = 0;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue