OpenGL Renderer: Fix possible crash that may occur if the 3D framebuffer is used before the 3D renderer has a chance to render at least once. (Partially addresses #59.)
This commit is contained in:
parent
4ea08792cb
commit
f8bbbec0ae
|
@ -4439,10 +4439,17 @@ Render3DError OpenGLRenderer_1_2::SetFramebufferSize(size_t w, size_t h)
|
||||||
return OGLERROR_BEGINGL_FAILED;
|
return OGLERROR_BEGINGL_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->_mappedFramebuffer != NULL)
|
const size_t newFramebufferColorSizeBytes = w * h * sizeof(FragmentColor);
|
||||||
|
|
||||||
|
if (this->isPBOSupported)
|
||||||
{
|
{
|
||||||
glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB);
|
if (this->_mappedFramebuffer != NULL)
|
||||||
this->_mappedFramebuffer = NULL;
|
{
|
||||||
|
glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB);
|
||||||
|
}
|
||||||
|
|
||||||
|
glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, newFramebufferColorSizeBytes, NULL, GL_STREAM_READ_ARB);
|
||||||
|
this->_mappedFramebuffer = (FragmentColor *__restrict)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->isShaderSupported && this->isFBOSupported && this->isVBOSupported)
|
if (this->isShaderSupported && this->isFBOSupported && this->isVBOSupported)
|
||||||
|
@ -4495,15 +4502,12 @@ Render3DError OpenGLRenderer_1_2::SetFramebufferSize(size_t w, size_t h)
|
||||||
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, sampleSize, GL_DEPTH24_STENCIL8_EXT, w, h);
|
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, sampleSize, GL_DEPTH24_STENCIL8_EXT, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t newFramebufferColorSizeBytes = w * h * sizeof(FragmentColor);
|
|
||||||
|
|
||||||
this->_framebufferWidth = w;
|
this->_framebufferWidth = w;
|
||||||
this->_framebufferHeight = h;
|
this->_framebufferHeight = h;
|
||||||
this->_framebufferColorSizeBytes = newFramebufferColorSizeBytes;
|
this->_framebufferColorSizeBytes = newFramebufferColorSizeBytes;
|
||||||
|
|
||||||
if (this->isPBOSupported)
|
if (this->isPBOSupported)
|
||||||
{
|
{
|
||||||
glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, newFramebufferColorSizeBytes, NULL, GL_STREAM_READ_ARB);
|
|
||||||
this->_framebufferColor = NULL;
|
this->_framebufferColor = NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -1973,12 +1973,16 @@ Render3DError OpenGLRenderer_3_2::SetFramebufferSize(size_t w, size_t h)
|
||||||
return OGLERROR_BEGINGL_FAILED;
|
return OGLERROR_BEGINGL_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const size_t newFramebufferColorSizeBytes = w * h * sizeof(FragmentColor);
|
||||||
|
|
||||||
if (this->_mappedFramebuffer != NULL)
|
if (this->_mappedFramebuffer != NULL)
|
||||||
{
|
{
|
||||||
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
|
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
|
||||||
this->_mappedFramebuffer = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glBufferData(GL_PIXEL_PACK_BUFFER, newFramebufferColorSizeBytes, NULL, GL_STREAM_READ);
|
||||||
|
this->_mappedFramebuffer = (FragmentColor *__restrict)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_FinalColor);
|
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_FinalColor);
|
||||||
glBindTexture(GL_TEXTURE_2D, OGLRef.texFinalColorID);
|
glBindTexture(GL_TEXTURE_2D, OGLRef.texFinalColorID);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
|
||||||
|
@ -2030,9 +2034,6 @@ Render3DError OpenGLRenderer_3_2::SetFramebufferSize(size_t w, size_t h)
|
||||||
glBindTexture(GL_TEXTURE_2D, OGLRef.texGDepthStencilAlphaID);
|
glBindTexture(GL_TEXTURE_2D, OGLRef.texGDepthStencilAlphaID);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, w, h, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, w, h, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
|
||||||
|
|
||||||
const size_t newFramebufferColorSizeBytes = w * h * sizeof(FragmentColor);
|
|
||||||
glBufferData(GL_PIXEL_PACK_BUFFER, newFramebufferColorSizeBytes, NULL, GL_STREAM_READ);
|
|
||||||
|
|
||||||
this->_framebufferWidth = w;
|
this->_framebufferWidth = w;
|
||||||
this->_framebufferHeight = h;
|
this->_framebufferHeight = h;
|
||||||
this->_framebufferColorSizeBytes = newFramebufferColorSizeBytes;
|
this->_framebufferColorSizeBytes = newFramebufferColorSizeBytes;
|
||||||
|
|
Loading…
Reference in New Issue