28 #include <osg/Texture>
29 #include <osg/Texture2D>
31 #include "core/common/WLogger.h"
32 #include "../WGETextureHud.h"
34 #include "WGEOffscreenRenderPass.h"
38 m_width( textureWidth ),
39 m_height( textureHeight ),
40 m_fbo( new osg::FrameBufferObject() ),
44 setClearColor( osg::Vec4( 0.0, 0.0, 0.0, 0.0 ) );
45 setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
46 setReferenceFrame( osg::Transform::RELATIVE_RF );
47 setRenderTargetImplementation( WGECamera::FRAME_BUFFER_OBJECT );
48 setRenderOrder( WGECamera::PRE_RENDER, num );
54 m_width( textureWidth ),
55 m_height( textureHeight ),
56 m_fbo( new osg::FrameBufferObject() ),
61 setClearColor( osg::Vec4( 0.0, 0.0, 0.0, 0.0 ) );
62 setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
63 setReferenceFrame( osg::Transform::RELATIVE_RF );
64 setRenderTargetImplementation( WGECamera::FRAME_BUFFER_OBJECT );
65 setRenderOrder( WGECamera::PRE_RENDER, num );
75 m_fbo->setAttachment( buffer, osg::FrameBufferAttachment( texture ) );
83 texture->setUseHardwareMipMapGeneration(
true );
84 texture->setNumMipmapLevels( 0 );
87 WGECamera::attach( buffer, texture, 0, 0,
true );
92 WGECamera::attach( buffer, image );
97 osg::ref_ptr< osg::Texture2D > tex;
98 if( buffer == DEPTH_BUFFER )
104 #if defined(__APPLE__)
105 if( internalFormat != GL_RGBA )
107 wlog::warn(
"WGEOffscreenRenderPass::attach:" ) <<
108 "Changing internal format to GL_RGBA because the original format is not supported on Mac OSX.";
122 if(
m_hud && WGECamera::getBufferAttachmentMap().count( buffer ) )
124 m_hud->removeTexture( WGECamera::getBufferAttachmentMap()[ buffer ]._texture );
127 m_fbo->setAttachment( buffer, osg::FrameBufferAttachment() );
129 WGECamera::detach( buffer );
134 osg::ref_ptr< osg::Texture2D > tex =
new osg::Texture2D;
136 tex->setInternalFormat( internalFormat );
138 switch( internalFormat )
141 tex->setSourceType( GL_HALF_FLOAT );
142 tex->setSourceFormat( GL_RED );
145 tex->setSourceType( GL_FLOAT );
146 tex->setSourceFormat( GL_RED );
152 tex->setSourceType( GL_HALF_FLOAT );
153 tex->setSourceFormat( GL_RGB );
158 tex->setSourceType( GL_HALF_FLOAT );
159 tex->setSourceFormat( GL_RGBA );
164 tex->setSourceType( GL_FLOAT );
165 tex->setSourceFormat( GL_RGB );
170 tex->setSourceType( GL_FLOAT );
171 tex->setSourceFormat( GL_RGBA );
181 tex->setFilter( osg::Texture::MIN_FILTER, osg::Texture::LINEAR );
182 tex->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );
185 tex->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT );
186 tex->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT );
208 this->getOrCreateStateSet()->addUniform( uniform );
219 case PACKED_DEPTH_STENCIL_BUFFER:
220 return "Depth+Stencil";