Hello Michael,
On 02/01/2012 09:54 AM, Michael Raab wrote:
yes, that fixes the problem for Dither shadows. Thanks.
ok, I've fixed the other shadow types as well and committed the change.
My colleagues yet reported another issue.
After switching the pixel format and recreating the GL context, the
ShadowViewport seems to be damaged as well.
I guess Textures, FBO and so on need also to be recreated for the new
context.
Is there a smart way to do so?
hmm, the problem seems to be that the used FBOs are not created as
OpenSG GLObjects (which allows to keep track to which context they belong).
Can you give the attached a try (again Dither mode only)?
Cheers,
Carsten
Index: Source/Experimental/ShadowViewport/OSGDitherShadowMap.cpp
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/Experimental/ShadowViewport/OSGDitherShadowMap.cpp,v
retrieving revision 1.45
diff -u -r1.45 OSGDitherShadowMap.cpp
--- Source/Experimental/ShadowViewport/OSGDitherShadowMap.cpp 1 Feb 2012 20:28:03 -0000 1.45
+++ Source/Experimental/ShadowViewport/OSGDitherShadowMap.cpp 1 Feb 2012 20:49:08 -0000
@@ -600,8 +600,8 @@
DitherShadowMap::DitherShadowMap(ShadowViewport *source) :
TreeRenderer(source),
+ _fbo2Id(0),
_fb(0),
- _fb2(0),
_rb_depth(0),
_transforms(),
_tiledeco(NullFC),
@@ -889,8 +889,6 @@
if(_rb_depth != 0)
glDeleteRenderbuffersEXT(1, &_rb_depth);
#endif
- if(_fb2 != 0)
- glDeleteFramebuffersEXT(1, &_fb2);
}
/// Checks if FBO status is ok
@@ -954,7 +952,7 @@
if(width <= 0 || height <= 0)
return false;
- if(_fb2 != 0)
+ if(_fbo2Id != 0)
return true;
#ifdef USE_FBO_FOR_COLOR_AND_FACTOR_MAP
@@ -1009,18 +1007,10 @@
bool result = checkFrameBufferStatus(win);
#endif
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
-
- glGenFramebuffersEXT(1, &_fb2);
-
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fb2);
-
- glDrawBuffer(GL_NONE); // no color buffer dest
- glReadBuffer(GL_NONE); // no color buffer src
-
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
+ _fbo2Id = Window::registerGLObject(
+ osgTypedMethodVoidFunctor2ObjPtr<
+ DitherShadowMap, Window, UInt32 >(
+ this, &DitherShadowMap::handleFBO2GL), 1);
}
return true;
@@ -1436,18 +1426,19 @@
if(_shadowVP->_lights[i].second->getType() != PointLight::getClassType
() || !_shadowVP->_realPointLight[i])
{
+ Window *win = action->getWindow();
+ GLuint texId = _shadowVP->_texChunks[i]->getGLId();
- action->getWindow()->validateGLObject(
- _shadowVP->_texChunks[i]->getGLId());
+ win->validateGLObject(texId);
+ win->validateGLObject(_fbo2Id);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fb2);
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,
+ win->getGLObjectId(_fbo2Id));
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT
- , GL_TEXTURE_2D,
- action->getWindow
- ()->getGLObjectId(
- _shadowVP->_texChunks[i]->getGLId
- ()), 0);
+ glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
+ GL_DEPTH_ATTACHMENT_EXT,
+ GL_TEXTURE_2D,
+ win->getGLObjectId(texId), 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
@@ -1460,7 +1451,7 @@
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
_shadowVP->setVPSize(0, 0, _shadowVP->getMapSize(),
- _shadowVP->getMapSize());
+ _shadowVP->getMapSize() );
action->setCamera(getCPtr(_shadowVP->_lightCameras[i]));
@@ -1478,17 +1469,19 @@
{
MatrixCameraDecoratorPtr deco =
MatrixCameraDecorator::create();
- action->getWindow()->validateGLObject(
- _shadowVP->_texChunks[i]->getGLId());
+ Window *win = action->getWindow();
+ GLuint texId = _shadowVP->_texChunks[i]->getGLId();
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fb2);
+ win->validateGLObject(texId);
+ win->validateGLObject(_fbo2Id);
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT
- , GL_TEXTURE_2D,
- action->getWindow
- ()->getGLObjectId(
- _shadowVP->_texChunks[i]->getGLId
- ()), 0);
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,
+ win->getGLObjectId(_fbo2Id));
+
+ glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
+ GL_DEPTH_ATTACHMENT_EXT,
+ GL_TEXTURE_2D,
+ win->getGLObjectId(texId), 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
@@ -3037,3 +3030,32 @@
}
}
}
+
+void DitherShadowMap::handleFBO2GL(Window *win, UInt32 idStatus)
+{
+ Window::GLObjectStatusE mode;
+ UInt32 osgId;
+
+ Window::unpackIdStatus(idStatus, osgId, mode);
+
+ GLuint id = win->getGLObjectId(osgId);
+
+ if(mode == Window::destroy)
+ {
+ glDeleteFramebuffersEXT(1, &id);
+ win->setGLObjectId(osgId, 0);
+ }
+ else if(mode == Window::finaldestroy)
+ {
+ }
+ else if(mode == Window::initialize ||
+ mode == Window::reinitialize ||
+ mode == Window::needrefresh )
+ {
+ if(mode == Window::initialize)
+ {
+ glGenFramebuffersEXT(1, &id);
+ win->setGLObjectId(osgId, id);
+ }
+ }
+}
Index: Source/Experimental/ShadowViewport/OSGDitherShadowMap.h
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/Experimental/ShadowViewport/OSGDitherShadowMap.h,v
retrieving revision 1.14
diff -u -r1.14 OSGDitherShadowMap.h
--- Source/Experimental/ShadowViewport/OSGDitherShadowMap.h 29 Mar 2007 15:02:51 -0000 1.14
+++ Source/Experimental/ShadowViewport/OSGDitherShadowMap.h 1 Feb 2012 20:49:08 -0000
@@ -63,8 +63,10 @@
bool checkFrameBufferStatus(Window *win);
void initTextures(Window *win);
+ void handleFBO2GL(Window *win, UInt32 idstatus);
+
+ UInt32 _fbo2Id;
GLuint _fb;
- GLuint _fb2;
GLuint _rb_depth;
Matrix _transforms[6];
TileCameraDecoratorPtr _tiledeco;
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users