mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-01-31 04:20:34 +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())
|
if (!IsEnabled())
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
if (width <= 0 || height <= 0)
|
if (width <= 0 || height <= 0)
|
||||||
I_FatalError("Requested invalid render buffer sizes: screen = %dx%d", width, height);
|
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);
|
glActiveTexture(activeTex);
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
|
if (FailedCreate)
|
||||||
|
{
|
||||||
|
ClearScene();
|
||||||
|
ClearPipeline();
|
||||||
|
ClearBloom();
|
||||||
|
mWidth = 0;
|
||||||
|
mHeight = 0;
|
||||||
|
mSamples = 0;
|
||||||
|
mBloomWidth = 0;
|
||||||
|
mBloomHeight = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !FailedCreate;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -340,8 +354,8 @@ GLuint FGLRenderBuffers::CreateFrameBuffer(const FString &name, GLuint colorbuff
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, handle);
|
glBindFramebuffer(GL_FRAMEBUFFER, handle);
|
||||||
FGLDebug::LabelObject(GL_FRAMEBUFFER, handle, name);
|
FGLDebug::LabelObject(GL_FRAMEBUFFER, handle, name);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuffer, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuffer, 0);
|
||||||
CheckFrameBufferCompleteness();
|
if (CheckFrameBufferCompleteness())
|
||||||
ClearFrameBuffer(false, false);
|
ClearFrameBuffer(false, false);
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,8 +370,8 @@ GLuint FGLRenderBuffers::CreateFrameBuffer(const FString &name, GLuint colorbuff
|
||||||
else
|
else
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuffer, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuffer, 0);
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthstencil);
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthstencil);
|
||||||
CheckFrameBufferCompleteness();
|
if (CheckFrameBufferCompleteness())
|
||||||
ClearFrameBuffer(true, true);
|
ClearFrameBuffer(true, true);
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,8 +387,8 @@ GLuint FGLRenderBuffers::CreateFrameBuffer(const FString &name, GLuint colorbuff
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuffer, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuffer, 0);
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencil);
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencil);
|
||||||
CheckFrameBufferCompleteness();
|
if (CheckFrameBufferCompleteness())
|
||||||
ClearFrameBuffer(true, true);
|
ClearFrameBuffer(true, true);
|
||||||
return handle;
|
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);
|
GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||||
if (result == GL_FRAMEBUFFER_COMPLETE)
|
if (result == GL_FRAMEBUFFER_COMPLETE)
|
||||||
return;
|
return true;
|
||||||
|
|
||||||
|
FailedCreate = true;
|
||||||
|
|
||||||
|
#if 0
|
||||||
FString error = "glCheckFramebufferStatus failed: ";
|
FString error = "glCheckFramebufferStatus failed: ";
|
||||||
switch (result)
|
switch (result)
|
||||||
{
|
{
|
||||||
|
@ -404,6 +421,9 @@ void FGLRenderBuffers::CheckFrameBufferCompleteness()
|
||||||
case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: error << "GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS"; break;
|
case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: error << "GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS"; break;
|
||||||
}
|
}
|
||||||
I_FatalError(error);
|
I_FatalError(error);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -539,5 +559,7 @@ void FGLRenderBuffers::BindOutputFB()
|
||||||
|
|
||||||
bool FGLRenderBuffers::IsEnabled()
|
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();
|
||||||
~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 BindSceneFB();
|
||||||
void BlitSceneToTexture();
|
void BlitSceneToTexture();
|
||||||
|
@ -53,7 +53,7 @@ private:
|
||||||
GLuint CreateFrameBuffer(const FString &name, GLuint colorbuffer);
|
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 depthstencil, bool colorIsARenderBuffer);
|
||||||
GLuint CreateFrameBuffer(const FString &name, GLuint colorbuffer, GLuint depth, GLuint stencil, 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 ClearFrameBuffer(bool stencil, bool depth);
|
||||||
void DeleteTexture(GLuint &handle);
|
void DeleteTexture(GLuint &handle);
|
||||||
void DeleteRenderBuffer(GLuint &handle);
|
void DeleteRenderBuffer(GLuint &handle);
|
||||||
|
@ -84,6 +84,8 @@ private:
|
||||||
|
|
||||||
// Back buffer frame buffer
|
// Back buffer frame buffer
|
||||||
GLuint mOutputFB = 0;
|
GLuint mOutputFB = 0;
|
||||||
|
|
||||||
|
static bool FailedCreate;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -289,9 +289,8 @@ void FGLRenderer::SetupLevel()
|
||||||
|
|
||||||
void FGLRenderer::Begin2D()
|
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)
|
if (mDrawingScene2D)
|
||||||
mBuffers->BindSceneFB();
|
mBuffers->BindSceneFB();
|
||||||
else
|
else
|
||||||
|
|
|
@ -168,9 +168,8 @@ void FGLRenderer::Reset3DViewport()
|
||||||
|
|
||||||
void FGLRenderer::Set3DViewport(bool mainview)
|
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();
|
mBuffers->BindSceneFB();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue