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

@@ -174,11 +174,12 @@ void CameraNode::attach(BufferComponent buffer, GLenum internalFormat)
_bufferAttachmentMap[buffer]._internalFormat = internalFormat;
}
void CameraNode::attach(BufferComponent buffer, osg::Texture* texture, unsigned int level, unsigned int face)
void CameraNode::attach(BufferComponent buffer, osg::Texture* texture, unsigned int level, unsigned int face, bool mipMapGeneration)
{
_bufferAttachmentMap[buffer]._texture = texture;
_bufferAttachmentMap[buffer]._level = level;
_bufferAttachmentMap[buffer]._face = face;
_bufferAttachmentMap[buffer]._mipMapGeneration = mipMapGeneration;
}
void CameraNode::attach(BufferComponent buffer, osg::Image* image)

View File

@@ -14,6 +14,7 @@
#include <osgProducer/GraphicsContextImplementation>
#include <osg/TextureRectangle>
#include <osg/TextureCubeMap>
#include <osg/Notify>
using namespace osgProducer;
@@ -56,7 +57,8 @@ GraphicsContextImplementation::GraphicsContextImplementation(Traits* traits)
if (traits->_target)
{
_rs->setRenderToTextureOptions(Producer::RenderSurface::RenderToTextureOptions_Default);
_rs->setRenderToTextureOptions(traits->_mipMapGeneration ? Producer::RenderSurface::RequestSpaceForMipMaps :
Producer::RenderSurface::RenderToTextureOptions_Default);
_rs->setRenderToTextureMipMapLevel(traits->_level);
_rs->setRenderToTextureMode(traits->_alpha>0 ? Producer::RenderSurface::RenderToRGBATexture :
Producer::RenderSurface::RenderToRGBTexture);
@@ -70,10 +72,12 @@ GraphicsContextImplementation::GraphicsContextImplementation(Traits* traits)
_rs->setRenderToTextureTarget(Producer::RenderSurface::Texture2D);
break;
case(GL_TEXTURE_3D) :
osg::notify(osg::NOTICE)<<"PBuffer render to Texture3D not supported."<<std::endl;
// not supported.
// _rs->setRenderToTextureTarget(Producer::RenderSurface::Texture3D);
break;
case(GL_TEXTURE_RECTANGLE) :
osg::notify(osg::NOTICE)<<"PBuffer render to TextureRectangle not supported."<<std::endl;
// not supported.
// _rs->setRenderToTextureTarget(Producer::RenderSurface::TextureRectangle);
break;

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.