Fix binding error that Nvidia didn't complain about but Intel on Mac does

This commit is contained in:
Magnus Norddahl 2016-07-31 03:16:48 +02:00
parent c93204cace
commit b789aaa0eb
2 changed files with 14 additions and 8 deletions

View file

@ -183,12 +183,12 @@ void FGLRenderBuffers::CreateScene(int width, int height, int samples)
{ {
mSceneDepth = CreateRenderBuffer(GL_DEPTH_COMPONENT24, samples, width, height); mSceneDepth = CreateRenderBuffer(GL_DEPTH_COMPONENT24, samples, width, height);
mSceneStencil = CreateRenderBuffer(GL_STENCIL_INDEX8, samples, width, height); mSceneStencil = CreateRenderBuffer(GL_STENCIL_INDEX8, samples, width, height);
mSceneFB = CreateFrameBuffer(samples > 1 ? mSceneMultisample : mSceneTexture, mSceneDepth, mSceneStencil); mSceneFB = CreateFrameBuffer(samples > 1 ? mSceneMultisample : mSceneTexture, mSceneDepth, mSceneStencil, samples > 1);
} }
else else
{ {
mSceneDepthStencil = CreateRenderBuffer(GL_DEPTH24_STENCIL8, samples, width, height); mSceneDepthStencil = CreateRenderBuffer(GL_DEPTH24_STENCIL8, samples, width, height);
mSceneFB = CreateFrameBuffer(samples > 1 ? mSceneMultisample : mSceneTexture, mSceneDepthStencil); mSceneFB = CreateFrameBuffer(samples > 1 ? mSceneMultisample : mSceneTexture, mSceneDepthStencil, samples > 1);
} }
} }
@ -327,22 +327,28 @@ GLuint FGLRenderBuffers::CreateFrameBuffer(GLuint colorbuffer)
return handle; return handle;
} }
GLuint FGLRenderBuffers::CreateFrameBuffer(GLuint colorbuffer, GLuint depthstencil) GLuint FGLRenderBuffers::CreateFrameBuffer(GLuint colorbuffer, GLuint depthstencil, bool colorIsARenderBuffer)
{ {
GLuint handle = 0; GLuint handle = 0;
glGenFramebuffers(1, &handle); glGenFramebuffers(1, &handle);
glBindFramebuffer(GL_FRAMEBUFFER, handle); glBindFramebuffer(GL_FRAMEBUFFER, handle);
if (colorIsARenderBuffer)
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorbuffer);
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(); CheckFrameBufferCompleteness();
return handle; return handle;
} }
GLuint FGLRenderBuffers::CreateFrameBuffer(GLuint colorbuffer, GLuint depth, GLuint stencil) GLuint FGLRenderBuffers::CreateFrameBuffer(GLuint colorbuffer, GLuint depth, GLuint stencil, bool colorIsARenderBuffer)
{ {
GLuint handle = 0; GLuint handle = 0;
glGenFramebuffers(1, &handle); glGenFramebuffers(1, &handle);
glBindFramebuffer(GL_FRAMEBUFFER, handle); glBindFramebuffer(GL_FRAMEBUFFER, handle);
if (colorIsARenderBuffer)
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorbuffer);
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_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);

View file

@ -45,8 +45,8 @@ private:
GLuint CreateRenderBuffer(GLuint format, int width, int height); GLuint CreateRenderBuffer(GLuint format, int width, int height);
GLuint CreateRenderBuffer(GLuint format, int samples, int width, int height); GLuint CreateRenderBuffer(GLuint format, int samples, int width, int height);
GLuint CreateFrameBuffer(GLuint colorbuffer); GLuint CreateFrameBuffer(GLuint colorbuffer);
GLuint CreateFrameBuffer(GLuint colorbuffer, GLuint depthstencil); GLuint CreateFrameBuffer(GLuint colorbuffer, GLuint depthstencil, bool colorIsARenderBuffer);
GLuint CreateFrameBuffer(GLuint colorbuffer, GLuint depth, GLuint stencil); GLuint CreateFrameBuffer(GLuint colorbuffer, GLuint depth, GLuint stencil, bool colorIsARenderBuffer);
void CheckFrameBufferCompleteness(); void CheckFrameBufferCompleteness();
void DeleteTexture(GLuint &handle); void DeleteTexture(GLuint &handle);
void DeleteRenderBuffer(GLuint &handle); void DeleteRenderBuffer(GLuint &handle);