Perliminary support for glGenerateMinMapEXT.

This commit is contained in:
Robert Osfield
2005-07-25 16:12:24 +00:00
parent 384830d37e
commit bddaefd569
6 changed files with 53 additions and 4 deletions

View File

@@ -1066,6 +1066,7 @@ void CullVisitor::apply(osg::CameraNode& camera)
if (!rtts)
{
rtts = new osgUtil::RenderToTextureStage;
rtts->setCameraNode(&camera);
camera.setRenderingCache(rtts.get());
}
else

View File

@@ -43,6 +43,28 @@ void RenderToTextureStage::reset()
RenderStage::reset();
}
class GenerateMipMapHelper : public StateAttribute::ModeUsage
{
public:
GenerateMipMapHelper(osg::FBOExtensions* fbo_ext):
_fbo_ext(fbo_ext) {}
virtual ~GenerateMipMapHelper() {}
virtual void usesMode(StateAttribute::GLMode)
{
}
virtual void usesTextureMode(StateAttribute::GLMode mode)
{
_fbo_ext->glGenerateMipmapEXT((GLenum)mode);
}
osg::FBOExtensions* _fbo_ext;
};
void RenderToTextureStage::draw(osg::State& state,RenderLeaf*& previous)
{
@@ -126,6 +148,23 @@ void RenderToTextureStage::draw(osg::State& state,RenderLeaf*& previous)
_image->readPixels(_viewport->x(),_viewport->y(),_viewport->width(),_viewport->height(),_imageReadPixelFormat,_imageReadPixelDataType);
}
if (fbo_supported && _camera)
{
// now generate mipmaps if they are required.
const osg::CameraNode::BufferAttachmentMap& bufferAttachements = _camera->getBufferAttachmentMap();
for(osg::CameraNode::BufferAttachmentMap::const_iterator itr = bufferAttachements.begin();
itr != bufferAttachements.end();
++itr)
{
if (itr->second._texture.valid() && itr->second._mipMapGeneration)
{
itr->second._texture->apply(*useState);
GenerateMipMapHelper generateMipMap(fbo_ext);
itr->second._texture->getModeUsage(generateMipMap);
}
}
}
if (_camera && _camera->getPostDrawCallback())
{
// if we have a camera with a post draw callback invoke it.