mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-11 23:32:04 +00:00
Fall back to gl_renderbuffers 0 if buffer creation fails
This commit is contained in:
parent
47714509d6
commit
bb066f6f07
4 changed files with 39 additions and 17 deletions
|
@ -147,10 +147,10 @@ void FGLRenderBuffers::DeleteFrameBuffer(GLuint &handle)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void FGLRenderBuffers::Setup(int width, int height, int sceneWidth, int sceneHeight)
|
||||
bool FGLRenderBuffers::Setup(int width, int height, int sceneWidth, int sceneHeight)
|
||||
{
|
||||
if (!IsEnabled())
|
||||
return;
|
||||
return false;
|
||||
|
||||
if (width <= 0 || height <= 0)
|
||||
I_FatalError("Requested invalid render buffer sizes: screen = %dx%d", width, height);
|
||||
|
@ -189,6 +189,20 @@ void FGLRenderBuffers::Setup(int width, int height, int sceneWidth, int sceneHei
|
|||
glActiveTexture(activeTex);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
if (FailedCreate)
|
||||
{
|
||||
ClearScene();
|
||||
ClearPipeline();
|
||||
ClearBloom();
|
||||
mWidth = 0;
|
||||
mHeight = 0;
|
||||
mSamples = 0;
|
||||
mBloomWidth = 0;
|
||||
mBloomHeight = 0;
|
||||
}
|
||||
|
||||
return !FailedCreate;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -340,7 +354,7 @@ GLuint FGLRenderBuffers::CreateFrameBuffer(const FString &name, GLuint colorbuff
|
|||
glBindFramebuffer(GL_FRAMEBUFFER, handle);
|
||||
FGLDebug::LabelObject(GL_FRAMEBUFFER, handle, name);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuffer, 0);
|
||||
CheckFrameBufferCompleteness();
|
||||
if (CheckFrameBufferCompleteness())
|
||||
ClearFrameBuffer(false, false);
|
||||
return handle;
|
||||
}
|
||||
|
@ -356,7 +370,7 @@ GLuint FGLRenderBuffers::CreateFrameBuffer(const FString &name, GLuint colorbuff
|
|||
else
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuffer, 0);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthstencil);
|
||||
CheckFrameBufferCompleteness();
|
||||
if (CheckFrameBufferCompleteness())
|
||||
ClearFrameBuffer(true, true);
|
||||
return handle;
|
||||
}
|
||||
|
@ -373,7 +387,7 @@ GLuint FGLRenderBuffers::CreateFrameBuffer(const FString &name, GLuint colorbuff
|
|||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuffer, 0);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencil);
|
||||
CheckFrameBufferCompleteness();
|
||||
if (CheckFrameBufferCompleteness())
|
||||
ClearFrameBuffer(true, true);
|
||||
return handle;
|
||||
}
|
||||
|
@ -384,12 +398,15 @@ GLuint FGLRenderBuffers::CreateFrameBuffer(const FString &name, GLuint colorbuff
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void FGLRenderBuffers::CheckFrameBufferCompleteness()
|
||||
bool FGLRenderBuffers::CheckFrameBufferCompleteness()
|
||||
{
|
||||
GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (result == GL_FRAMEBUFFER_COMPLETE)
|
||||
return;
|
||||
return true;
|
||||
|
||||
FailedCreate = true;
|
||||
|
||||
#if 0
|
||||
FString error = "glCheckFramebufferStatus failed: ";
|
||||
switch (result)
|
||||
{
|
||||
|
@ -404,6 +421,9 @@ void FGLRenderBuffers::CheckFrameBufferCompleteness()
|
|||
case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: error << "GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS"; break;
|
||||
}
|
||||
I_FatalError(error);
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -539,5 +559,7 @@ void FGLRenderBuffers::BindOutputFB()
|
|||
|
||||
bool FGLRenderBuffers::IsEnabled()
|
||||
{
|
||||
return gl_renderbuffers && gl.glslversion != 0;
|
||||
return gl_renderbuffers && gl.glslversion != 0 && !FailedCreate;
|
||||
}
|
||||
|
||||
bool FGLRenderBuffers::FailedCreate = false;
|
||||
|
|
|
@ -20,7 +20,7 @@ public:
|
|||
FGLRenderBuffers();
|
||||
~FGLRenderBuffers();
|
||||
|
||||
void Setup(int width, int height, int sceneWidth, int sceneHeight);
|
||||
bool Setup(int width, int height, int sceneWidth, int sceneHeight);
|
||||
|
||||
void BindSceneFB();
|
||||
void BlitSceneToTexture();
|
||||
|
@ -53,7 +53,7 @@ private:
|
|||
GLuint CreateFrameBuffer(const FString &name, GLuint colorbuffer);
|
||||
GLuint CreateFrameBuffer(const FString &name, GLuint colorbuffer, GLuint depthstencil, bool colorIsARenderBuffer);
|
||||
GLuint CreateFrameBuffer(const FString &name, GLuint colorbuffer, GLuint depth, GLuint stencil, bool colorIsARenderBuffer);
|
||||
void CheckFrameBufferCompleteness();
|
||||
bool CheckFrameBufferCompleteness();
|
||||
void ClearFrameBuffer(bool stencil, bool depth);
|
||||
void DeleteTexture(GLuint &handle);
|
||||
void DeleteRenderBuffer(GLuint &handle);
|
||||
|
@ -84,6 +84,8 @@ private:
|
|||
|
||||
// Back buffer frame buffer
|
||||
GLuint mOutputFB = 0;
|
||||
|
||||
static bool FailedCreate;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -289,9 +289,8 @@ void FGLRenderer::SetupLevel()
|
|||
|
||||
void FGLRenderer::Begin2D()
|
||||
{
|
||||
if (FGLRenderBuffers::IsEnabled())
|
||||
if (mBuffers->Setup(mScreenViewport.width, mScreenViewport.height, mSceneViewport.width, mSceneViewport.height))
|
||||
{
|
||||
mBuffers->Setup(mScreenViewport.width, mScreenViewport.height, mSceneViewport.width, mSceneViewport.height);
|
||||
if (mDrawingScene2D)
|
||||
mBuffers->BindSceneFB();
|
||||
else
|
||||
|
|
|
@ -168,9 +168,8 @@ void FGLRenderer::Reset3DViewport()
|
|||
|
||||
void FGLRenderer::Set3DViewport(bool mainview)
|
||||
{
|
||||
if (mainview && FGLRenderBuffers::IsEnabled())
|
||||
if (mainview && mBuffers->Setup(mScreenViewport.width, mScreenViewport.height, mSceneViewport.width, mSceneViewport.height))
|
||||
{
|
||||
mBuffers->Setup(mScreenViewport.width, mScreenViewport.height, mSceneViewport.width, mSceneViewport.height);
|
||||
mBuffers->BindSceneFB();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue