00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <string>
00026
00027 #include "../WGETextureHud.h"
00028 #include "../WGEGeodeUtils.h"
00029
00030 #include "WGEOffscreenTexturePass.h"
00031
00032 WGEOffscreenTexturePass::WGEOffscreenTexturePass( size_t textureWidth, size_t textureHeight, int num ):
00033 WGEOffscreenRenderPass( textureWidth, textureHeight, num )
00034 {
00035
00036 setup();
00037 }
00038
00039 WGEOffscreenTexturePass::WGEOffscreenTexturePass( size_t textureWidth, size_t textureHeight, osg::ref_ptr< WGETextureHud > hud, std::string name,
00040 int num ):
00041 WGEOffscreenRenderPass( textureWidth, textureHeight, hud, name, num )
00042 {
00043
00044 setup();
00045 }
00046
00047 WGEOffscreenTexturePass::~WGEOffscreenTexturePass()
00048 {
00049
00050 }
00051
00052 void WGEOffscreenTexturePass::setup()
00053 {
00054
00055 osg::ref_ptr< osg::Geode > geode = wge::genFinitePlane( osg::Vec3( 0.0, 0.0, 0.0 ),
00056 osg::Vec3( 1.0, 0.0, 0.0 ),
00057 osg::Vec3( 0.0, 1.0, 0.0 ) );
00058
00059 geode->addUpdateCallback( new TextureMatrixUpdateCallback( this ) );
00060
00061
00062 this->addChild( geode );
00063
00064
00065 osg::StateSet* state = this->getOrCreateStateSet();
00066 state->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );
00067 state->setMode( GL_LIGHTING, osg::StateAttribute::PROTECTED );
00068 state->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
00069 state->setMode( GL_BLEND, osg::StateAttribute::PROTECTED );
00070 state->setMode( GL_BLEND, osg::StateAttribute::OFF );
00071
00072
00073 this->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
00074 this->setProjectionMatrixAsOrtho2D( 0.0, 1.0, 0.0, 1.0 );
00075 this->setViewMatrix( osg::Matrixd::identity() );
00076
00077
00078 m_texMat = new osg::TexMat;
00079 m_texMat->setMatrix( osg::Matrixd::identity() );
00080 state->setTextureAttributeAndModes( 0, m_texMat, osg::StateAttribute::ON );
00081 }
00082
00083 void WGEOffscreenTexturePass::TextureMatrixUpdateCallback::operator()( osg::Node* node, osg::NodeVisitor* nv )
00084 {
00085 osg::ref_ptr< osg::TexMat > texMat = m_pass->m_texMat;
00086
00087
00088
00089 unsigned int screenWidth = m_pass->getViewport()->width();
00090 unsigned int screenHeight = m_pass->getViewport()->height();
00091
00092 texMat->setMatrix( osg::Matrixd::scale( static_cast< float >( screenWidth ) / static_cast< float >( m_pass->getTextureWidth() ),
00093 static_cast< float >( screenHeight )/ static_cast< float >( m_pass->getTextureHeight() ), 1.0 ) );
00094
00095
00096 traverse( node, nv );
00097 }
00098