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";
Class for wrapping around the OSG Camera class.
std::string m_name
The name if the rendering pass.
osg::ref_ptr< WGETextureHud > m_hud
Gets notified about any added and removed attachment.
osg::ref_ptr< osg::Texture2D > createTexture(GLint internalFormat=GL_RGBA)
Creates a new texture suitable for this offscreen rendering instance.
osg::ref_ptr< osg::FrameBufferObject > m_fbo
The framebuffer object to use for this camera.
size_t m_height
The height of the textures used for this pass.
WGEOffscreenRenderPass(size_t textureWidth, size_t textureHeight, int num=0)
Creates a new offscreen rendering instance.
void attach(BufferComponent buffer, osg::ref_ptr< osg::Texture2D > texture)
Attach a given texture to a buffer.
void detach(BufferComponent buffer)
Detaches the texture currently bound to the specified buffer.
size_t m_width
The width of the textures used for this pass.
size_t getTextureWidth() const
Get the size of the underlying texture.
virtual void addUniform(osg::ref_ptr< osg::Uniform > uniform)
The uniform to add.
size_t getTextureHeight() const
Get the size of the underlying texture.
static std::string getBufferName(BufferComponent buffer)
Returns the buffer name.
virtual ~WGEOffscreenRenderPass()
Destructor.
std::string getName() const
Returns the name of this render pass.
Class implementing one texture HUD entry representing a texture in the HUD.
WStreamedLogger warn(const std::string &source)
Logging a warning message.