From e89852e25f009dc01799be9e39aa9d277a947106 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 4 Feb 2006 21:20:25 +0000 Subject: [PATCH] From Marco Jez, " I've modified in order to make FBO mipmapping work. In FrameBufferObject.cpp there is also another fix: when initializing a FBO attachment from a CameraNode attachment, the renderbuffer's format must be set to the attachment's internal format, not to the image's pixel format. Another problem is that attaching a renderbuffer to the FBO through CameraNode is not simple (if not impossible) if you don't intend to specify an Image object. Probably CameraNode could be enriched with an "attach(buffer, width, height, format)" method. For example if you attach a color buffer as a texture whose size is different than that of the CameraNode's viewport you also need to attach a depth buffer of the same size, because the depth buffer that is automatically attached by RenderStage has the viewport's size. FBOs require that all attachment have the same dimensions, so said setup will fail if you can't specify a custom depth renderbuffer" --- src/osg/FrameBufferObject.cpp | 10 +++++++--- src/osgProducer/OsgCameraGroup.cpp | 2 +- src/osgUtil/RenderStage.cpp | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/osg/FrameBufferObject.cpp b/src/osg/FrameBufferObject.cpp index 3ae88c5c2..76137dee7 100644 --- a/src/osg/FrameBufferObject.cpp +++ b/src/osg/FrameBufferObject.cpp @@ -338,10 +338,13 @@ FrameBufferAttachment::FrameBufferAttachment(CameraNode::Attachment& attachment) osg::Image* image = attachment._image.get(); if (image) { - if (image->s()>0 && image->t()>0 && image->getPixelFormat()>0) + if (image->s()>0 && image->t()>0) { + GLenum format = attachment._image->getInternalTextureFormat(); + if (format == 0) + format = attachment._internalFormat; _ximpl = new Pimpl(Pimpl::RENDERBUFFER); - _ximpl->renderbufferTarget = new osg::RenderBuffer(image->s(), image->t(), image->getPixelFormat()); + _ximpl->renderbufferTarget = new osg::RenderBuffer(image->s(), image->t(), format); } else { @@ -379,7 +382,6 @@ void FrameBufferAttachment::createRequiredTexturesAndApplyGenerateMipMap(State & { _ximpl->textureTarget->compileGLObjects(state); tobj = _ximpl->textureTarget->getTextureObject(contextID); - } if (!tobj || tobj->_id == 0) return; @@ -390,6 +392,8 @@ void FrameBufferAttachment::createRequiredTexturesAndApplyGenerateMipMap(State & minFilter==Texture::NEAREST_MIPMAP_LINEAR || minFilter==Texture::NEAREST_MIPMAP_NEAREST) { + state.setActiveTextureUnit(0); + state.applyTextureAttribute(0, _ximpl->textureTarget.get()); ext->glGenerateMipmapEXT(_ximpl->textureTarget->getTextureTarget()); } diff --git a/src/osgProducer/OsgCameraGroup.cpp b/src/osgProducer/OsgCameraGroup.cpp index 732ce7fdd..c491fadf4 100644 --- a/src/osgProducer/OsgCameraGroup.cpp +++ b/src/osgProducer/OsgCameraGroup.cpp @@ -234,7 +234,7 @@ void OsgCameraGroup::_init() if (_thread_model==ThreadPerCamera && _cfg->getNumberOfCameras()>1) { // switch on thread safe reference counting by default when running multi-threaded. - osg::Referenced::setThreadSafeReferenceCounting(true); + // osg::Referenced::setThreadSafeReferenceCounting(true); } _scene_data = NULL; diff --git a/src/osgUtil/RenderStage.cpp b/src/osgUtil/RenderStage.cpp index 1b89521bc..699c7fa19 100644 --- a/src/osgUtil/RenderStage.cpp +++ b/src/osgUtil/RenderStage.cpp @@ -684,8 +684,9 @@ void RenderStage::drawInner(osg::State& state,RenderLeaf*& previous, bool& doCop { if (itr->second._texture.valid() && itr->second._mipMapGeneration) { - itr->second._texture->apply(state); - // fbo_ext->glGenerateMipmapEXT(itr->second._texture->getTextureTarget()); + state.setActiveTextureUnit(0); + state.applyTextureAttribute(0, itr->second._texture.get()); + fbo_ext->glGenerateMipmapEXT(itr->second._texture->getTextureTarget()); } } }