Recreate framebuffer objects when opengl context changes

This commit is contained in:
codeanticode
2012-03-19 19:52:47 +00:00
parent 49eeb26cc6
commit d044f04d63
2 changed files with 28 additions and 2 deletions
@@ -402,6 +402,25 @@ public class PFramebuffer implements PConstants {
}
protected boolean contextIsOutdated() {
boolean outdated = !pgl.contextIsCurrent(context);
if (outdated) {
glFboID = 0;
glDepthBufferID = 0;
glStencilBufferID = 0;
glDepthStencilBufferID = 0;
glColorBufferMultisampleID = 0;
for (int i = 0; i < numColorBuffers; i++) {
colorBufferTex[i] = null;
}
backupTexture = null;
}
return outdated;
}
protected void createColorBufferMultisample() {
if (screenFb) return;
@@ -1376,7 +1376,14 @@ public class PGraphicsOpenGL extends PGraphics {
} else {
if (!pgl.initialized) {
initOffscreen();
}
} else {
boolean outdated = offscreenFramebuffer != null && offscreenFramebuffer.contextIsOutdated();
boolean outdatedMulti = offscreenFramebufferMultisample != null && offscreenFramebufferMultisample.contextIsOutdated();
if (outdated || outdatedMulti) {
pgl.initialized = false;
initOffscreen();
}
}
pushFramebuffer();
if (offscreenMultisample) {
@@ -4851,7 +4858,7 @@ public class PGraphicsOpenGL extends PGraphics {
protected void loadTextureImpl(int sampling) {
if (width == 0 || height == 0) return;
if (texture == null) {
if (texture == null || texture.contextIsOutdated()) {
PTexture.Parameters params = PTexture.newParameters(ARGB, sampling);
texture = new PTexture(parent, width, height, params);
texture.setFlippedY(true);