Commit 4c252831 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - render pass and texture HUD entries can now be named. Texture HUD is able to display it.

parent 938c135e
......@@ -22,6 +22,8 @@
//
//---------------------------------------------------------------------------
#include <string>
#include "callbacks/WGEViewportCallback.h"
#include "WGEOffscreenRenderNode.h"
......@@ -48,41 +50,44 @@ WGEOffscreenRenderNode::~WGEOffscreenRenderNode()
// cleanup
}
osg::ref_ptr< WGEOffscreenRenderPass > WGEOffscreenRenderNode::addGeometryRenderPass( osg::ref_ptr< osg::Node > node )
osg::ref_ptr< WGEOffscreenRenderPass > WGEOffscreenRenderNode::addRenderPass( std::string name )
{
// create a new pass
osg::ref_ptr< WGEOffscreenRenderPass > pass = new WGEOffscreenRenderPass( m_textureWidth, m_textureHeight, m_hud, m_nextPassNum );
osg::ref_ptr< WGEOffscreenRenderPass > pass = new WGEOffscreenRenderPass( m_textureWidth, m_textureHeight, m_hud, name, m_nextPassNum );
m_nextPassNum++;
// this node needs to keep all the pass instances. Only this way, the OSG traverses and renders these nodes in the order specified by
// m_nextPassNum.
pass->addChild( node );
insert( pass ); // insert into this group
// ensure proper propagation of viewport changes
pass->addUpdateCallback( new WGEViewportCallback< WGEOffscreenRenderPass >( m_referenceCamera ) );
// set clear mask and color according to reference cam
pass->setClearMask( m_referenceCamera->getClearMask() );
pass->setClearColor( m_referenceCamera->getClearColor() );
// ensure proper propagation of viewport changes
pass->addUpdateCallback( new WGEViewportCallback< WGEOffscreenRenderPass >( m_referenceCamera ) );
return pass;
}
osg::ref_ptr< WGEOffscreenRenderPass > WGEOffscreenRenderNode::addTextureProcessingPass()
osg::ref_ptr< WGEOffscreenRenderPass > WGEOffscreenRenderNode::addGeometryRenderPass( osg::ref_ptr< osg::Node > node, std::string name )
{
osg::ref_ptr< WGEOffscreenRenderPass > pass = new WGEOffscreenRenderPass( m_textureWidth, m_textureHeight, m_hud, m_nextPassNum );
m_nextPassNum++;
insert( pass ); // insert into this group
// create a plain render pass and add some geometry
osg::ref_ptr< WGEOffscreenRenderPass > pass = addRenderPass( name );
pass->addChild( node );
return pass;
}
// we need to create a nice quad for texture processing spanning the whole texture space
osg::ref_ptr< WGEOffscreenRenderPass > WGEOffscreenRenderNode::addTextureProcessingPass( std::string name )
{
osg::ref_ptr< WGEOffscreenRenderPass > pass = addRenderPass( name );
// we need to create a nice quad for texture processing spanning the whole texture space
// ensure proper propagation of viewport changes
pass->addUpdateCallback( new WGEViewportCallback< WGEOffscreenRenderPass >( m_referenceCamera ) );
return pass;
}
......@@ -25,6 +25,8 @@
#ifndef WGEOFFSCREENRENDERNODE_H
#define WGEOFFSCREENRENDERNODE_H
#include <string>
#include <osg/Camera>
#include "WGEGroupNode.h"
......@@ -49,14 +51,15 @@ class WGEOffscreenRenderNode: public WGEGroupNode
public:
/**
* Create a new managing instance. It uses the specified camera as reference to all created offscreen-render-pass instances. Especially
* viewport, clear-mask and clear-color get used.
* viewport, clear-mask and clear-color get used. The default texture resolution is 2048x2048 which is more than full-HD resolution. So it
* should be enough.
*
* \param reference camera used as reference
* \param width the width of the textures used in this rendering
* \param height the height of the textures used in this rendering*
* \param noHud If true, no hud gets displayed showing the created and used textures.
*/
WGEOffscreenRenderNode( osg::ref_ptr< osg::Camera > reference, size_t width, size_t height, bool noHud = false );
WGEOffscreenRenderNode( osg::ref_ptr< osg::Camera > reference, size_t width = 2048, size_t height = 2048, bool noHud = false );
/**
* Destructor.
......@@ -67,12 +70,13 @@ public:
* Creates a new offscreen-render-pass coupled with the reference camera which renders a specified OSG graph to a texture.
*
* \param node the node which represents the subgraph.
* \param name the name of the render pass. You should specify it to enable the nice debugging feature of WGETextureHud.
*
* \note never forget to remove the returned node if not used anymore or use WGEGroup::clean.
*
* \return the geometry render pass.
*/
virtual osg::ref_ptr< WGEOffscreenRenderPass > addGeometryRenderPass( osg::ref_ptr< osg::Node > node );
virtual osg::ref_ptr< WGEOffscreenRenderPass > addGeometryRenderPass( osg::ref_ptr< osg::Node > node, std::string name = "Unnamed" );
/**
* Creates a new offscreen-render-pass coupled with the reference camera which simply processes textures. All the in- and output textures
......@@ -80,9 +84,21 @@ public:
*
* \note never forget to remove the returned node if not used anymore or use WGEGroup::clean.
*
* \param name the name of the render pass. You should specify it to enable the nice debugging feature of WGETextureHud.
*
* \return the texture processing pass created.
*/
virtual osg::ref_ptr< WGEOffscreenRenderPass > addTextureProcessingPass();
virtual osg::ref_ptr< WGEOffscreenRenderPass > addTextureProcessingPass( std::string name = "Unnamed" );
/**
* Creates a new offscreen-render-pass coupled with the reference camera. This pass actually does nothing. The method is useful for custom
* variants of WGEOffscreenRenderPass.
*
* \param name the name of the render pass. You should specify it to enable the nice debugging feature of WGETextureHud.
*
* \return new instance of a plain render pass
*/
virtual osg::ref_ptr< WGEOffscreenRenderPass > addRenderPass( std::string name = "Unnamed" );
protected:
......
......@@ -22,6 +22,10 @@
//
//---------------------------------------------------------------------------
#include <string>
#include <boost/lexical_cast.hpp>
#include <osg/Texture>
#include <osg/Texture2D>
......@@ -44,12 +48,14 @@ WGEOffscreenRenderPass::WGEOffscreenRenderPass( size_t textureWidth, size_t text
setRenderOrder( osg::Camera::PRE_RENDER, num );
}
WGEOffscreenRenderPass::WGEOffscreenRenderPass( size_t textureWidth, size_t textureHeight, osg::ref_ptr< WGETextureHud > hud, int num ):
WGEOffscreenRenderPass::WGEOffscreenRenderPass( size_t textureWidth, size_t textureHeight, osg::ref_ptr< WGETextureHud > hud, std::string name,
int num ):
osg::Camera(),
m_width( textureWidth ),
m_height( textureHeight ),
m_fbo( new osg::FrameBufferObject() ),
m_hud( hud )
m_hud( hud ),
m_name( name )
{
// initialize members
setClearColor( osg::Vec4( 0.0, 0.0, 0.0, 0.0 ) );
......@@ -70,7 +76,7 @@ void WGEOffscreenRenderPass::attach( BufferComponent buffer, osg::ref_ptr< osg::
if ( m_hud )
{
m_hud->addTexture( new WGETextureHud::WGETextureHudEntry( texture ) );
m_hud->addTexture( new WGETextureHud::WGETextureHudEntry( texture, m_name + " " + boost::lexical_cast< std::string >( buffer ) ) );
}
osg::Camera::attach( buffer, texture );
......@@ -121,3 +127,8 @@ osg::ref_ptr< osg::Texture2D > WGEOffscreenRenderPass::createTexture( GLint inte
return tex;
}
std::string WGEOffscreenRenderPass::getName() const
{
return m_name;
}
......@@ -25,6 +25,8 @@
#ifndef WGEOFFSCREENRENDERPASS_H
#define WGEOFFSCREENRENDERPASS_H
#include <string>
#include <osg/Camera>
#include <osg/FrameBufferObject>
......@@ -59,8 +61,9 @@ public:
* viewport size.*
* \param num the order number. This camera gets rendered at the num'th place in the pre render queue of the subgraph it is attached to.
* \param hud the hud that gets notified about attached and detached textures. Useful for debugging.
* \param name the name of this render pass. This is a nice debugging feature in conjunction with WGETextureHud as it gets displayed there.
*/
WGEOffscreenRenderPass( size_t textureWidth, size_t textureHeight, osg::ref_ptr< WGETextureHud > hud, int num = 0 );
WGEOffscreenRenderPass( size_t textureWidth, size_t textureHeight, osg::ref_ptr< WGETextureHud > hud, std::string name, int num = 0 );
/**
* Destructor.
......@@ -106,6 +109,13 @@ public:
*/
osg::ref_ptr< osg::Texture2D > createTexture( GLint internalFormat = GL_RGBA );
/**
* Returns the name of this render pass.
*
* \return the name
*/
std::string getName() const;
protected:
/**
......@@ -128,6 +138,10 @@ protected:
*/
osg::ref_ptr< WGETextureHud > m_hud;
/**
* The name if the rendering pass. Especially useful in conjunction with m_hud.
*/
std::string m_name;
private:
};
......
......@@ -29,6 +29,9 @@
#include <osg/Geometry>
#include <osg/MatrixTransform>
#include <osg/TexEnv>
#include <osgText/Text>
#include "../common/WPathHelper.h"
#include "WGETextureHud.h"
......@@ -88,7 +91,7 @@ void WGETextureHud::SafeUpdateCallback::operator()( osg::Node* node, osg::NodeVi
// scale them to their final size
osg::Matrixd scale = osg::Matrixd::scale( m_hud->getMaxElementWidth(), height, 1.0 );
// need to add a "linebreak"?
// need to add a "line-break"?
if ( nextY + height + border > screenHeight )
{
nextX += m_hud->getMaxElementWidth() + border;
......@@ -99,7 +102,7 @@ void WGETextureHud::SafeUpdateCallback::operator()( osg::Node* node, osg::NodeVi
osg::Matrixd translate = osg::Matrixd::translate( static_cast< double >( nextX ), static_cast< double >( nextY ), 0.0 );
tex->setMatrix( scale * translate );
// calc the y position of the next texture
// calculate the y position of the next texture
nextY += height + border;
}
......@@ -137,13 +140,17 @@ class TexCoordUpdate: public osg::StateAttribute::Callback
};
WGETextureHud::WGETextureHudEntry::WGETextureHudEntry( osg::ref_ptr< osg::Texture2D > texture, bool transparency ):
WGETextureHud::WGETextureHudEntry::WGETextureHudEntry( osg::ref_ptr< osg::Texture2D > texture, std::string name, bool transparency ):
osg::MatrixTransform(),
m_texture( texture )
m_texture( texture ),
m_name( name )
{
setMatrix( osg::Matrixd::identity() );
setReferenceFrame( osg::Transform::ABSOLUTE_RF );
//////////////////////////////////////////////////
// Texture Quad
osg::Geode* geode = new osg::Geode();
// Set up geometry for the HUD and add it to the HUD
......@@ -214,6 +221,22 @@ WGETextureHud::WGETextureHudEntry::WGETextureHudEntry( osg::ref_ptr< osg::Textur
// add the geode
addChild( geode );
//////////////////////////////////////////////////
// Text
osg::ref_ptr< osg::Geode > textGeode = new osg::Geode();
state = textGeode->getOrCreateStateSet();
state->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );
addChild( textGeode );
osgText::Text* label = new osgText::Text();
label->setFont( WPathHelper::getAllFonts().Default.file_string() );
label->setBackdropType( osgText::Text::OUTLINE );
label->setCharacterSize( 15 );
label->setText( m_name );
label->setAxisAlignment( osgText::Text::SCREEN );
label->setPosition( osg::Vec3( 0.01, 0.01, -1.0 ) );
label->setColor( osg::Vec4( 1.0, 1.0, 1.0, 1.0 ) );
textGeode->addDrawable( label );
}
WGETextureHud::WGETextureHudEntry::~WGETextureHudEntry()
......@@ -221,22 +244,27 @@ WGETextureHud::WGETextureHudEntry::~WGETextureHudEntry()
// cleanup
}
unsigned int WGETextureHud::WGETextureHudEntry::getRealWidth()
unsigned int WGETextureHud::WGETextureHudEntry::getRealWidth() const
{
return m_texture->getTextureWidth();
}
unsigned int WGETextureHud::WGETextureHudEntry::getRealHeight()
unsigned int WGETextureHud::WGETextureHudEntry::getRealHeight() const
{
return m_texture->getTextureHeight();
}
osg::ref_ptr< osg::TexMat > WGETextureHud::WGETextureHudEntry::getTextureMatrix()
osg::ref_ptr< osg::TexMat > WGETextureHud::WGETextureHudEntry::getTextureMatrix() const
{
return m_texMat;
}
unsigned int WGETextureHud::getMaxElementWidth()
std::string WGETextureHud::WGETextureHudEntry::getName() const
{
return m_name;
}
unsigned int WGETextureHud::getMaxElementWidth() const
{
return m_maxElementWidth;
}
......
......@@ -26,6 +26,7 @@
#define WGETEXTUREHUD_H
#include <list>
#include <string>
#include <boost/thread.hpp>
......@@ -66,9 +67,10 @@ public:
* Constructor.
*
* \param texture the texture to show in the HUD
* \param name a telling name to support the illustrative function of the HUD
* \param transparency true if transparency should be shown
*/
WGETextureHudEntry( osg::ref_ptr< osg::Texture2D > texture, bool transparency = false );
WGETextureHudEntry( osg::ref_ptr< osg::Texture2D > texture, std::string name, bool transparency = false );
/**
* Destructor.
......@@ -80,21 +82,29 @@ public:
*
* \return the real width.
*/
unsigned int getRealWidth();
unsigned int getRealWidth() const;
/**
* Returns the real height of the contained texture.
*
* \return the real height.
*/
unsigned int getRealHeight();
unsigned int getRealHeight() const;
/**
* Get the texture matrix state for this entry.
*
* \return the texture matrix state
*/
osg::ref_ptr< osg::TexMat > getTextureMatrix();
osg::ref_ptr< osg::TexMat > getTextureMatrix() const;
/**
* Returns the name of the entry.
*
* \return name of the entry.
*/
std::string getName() const;
protected:
/**
......@@ -106,6 +116,12 @@ public:
* The texture matrix for this entry.
*/
osg::ref_ptr< osg::TexMat > m_texMat;
/**
* The name for this HUD entry.
*/
std::string m_name;
private:
};
......@@ -135,7 +151,7 @@ public:
*
* \return the maximum width.
*/
unsigned int getMaxElementWidth();
unsigned int getMaxElementWidth() const;
/**
* Sets the new maximum width of a texture column.
......
......@@ -23,6 +23,7 @@
//---------------------------------------------------------------------------
#include <cmath>
#include <cstdlib>
#include <vector>
#include <string>
......@@ -158,34 +159,55 @@ void WMImageSpaceLIC::moduleMain()
// Remember the condition provided to some properties in properties()? The condition can now be used with this condition set.
m_moduleState.add( m_propCondition );
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Preparation 1: create noise texture
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// we need a noise texture with a sufficient resolution. Create it.
const size_t resX = 2048;
const size_t resY = 2048;
std::srand( time( 0 ) );
osg::ref_ptr< osg::Image > randImage = new osg::Image();
randImage->allocateImage( resX, resY, 1, GL_LUMINANCE, GL_UNSIGNED_BYTE );
unsigned char *randomLuminance = randImage->data(); // should be 4 megs
for( unsigned int x = 0; x < resX; x++ )
{
for( unsigned int y = 0; y < resY; y++ )
{
randomLuminance[ ( y * resY ) + x ] = ( unsigned char )( std::rand() % 255 );
}
}
// finally, create a texture from the image
osg::ref_ptr< osg::Texture2D > randTexture = new osg::Texture2D();
randTexture->setFilter( osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR );
randTexture->setFilter( osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR );
randTexture->setImage( randImage );
randTexture->setResizeNonPowerOfTwoHint( false );
// done.
ready();
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Preparation 2: initialize offscreen renderer and hardwire it
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// create the root node for all the geometry
m_output = osg::ref_ptr< WGEManagedGroupNode > ( new WGEManagedGroupNode( m_active ) );
// the WGEOffscreenRenderNode manages each of the render-passes for us
osg::ref_ptr< WGEOffscreenRenderNode > offscreen = new WGEOffscreenRenderNode(
WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getCamera(),
1024,
1024
resX,
resY
);
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( offscreen );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( m_output );
// setup all the passes needed for image space advection
osg::ref_ptr< WGEOffscreenRenderPass > transformation = offscreen->addGeometryRenderPass( m_output );
/*osg::ref_ptr< WGEOffscreen > edgeDetection = new WGEOffscreen( WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getCamera(), 1 );
osg::ref_ptr< WGEOffscreen > advection = new WGEOffscreen( WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getCamera(), 2 );
osg::ref_ptr< WGEOffscreen > blending = new WGEOffscreen( WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getCamera(), 3 );*/
// the first render-pass needs the geometry
// transformation->addChild( m_output );
// the others need a slice as large as the viewport on which the textures are projected so that the fragment shader can pass each fragment
// each pass needs to be rendered. The order of rendering is defined by the second construction argument
//WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( transformation );
//WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( edgeDetection );
//WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( advection );
//WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( blending );
osg::ref_ptr< WGEOffscreenRenderPass > transformation = offscreen->addGeometryRenderPass( m_output, "Transformation" );
osg::ref_ptr< WGEOffscreenRenderPass > edgeDetection = offscreen->addTextureProcessingPass( "Edge Detection" );
// hardwire the textures to use for each pass:
......@@ -197,10 +219,16 @@ void WMImageSpaceLIC::moduleMain()
osg::ref_ptr< osg::Texture2D > transformationOut1 = transformation->attach( osg::Camera::COLOR_BUFFER0 );
osg::ref_ptr< osg::Texture2D > transformationDepth = transformation->attach( osg::Camera::DEPTH_BUFFER );
// Edge Detection Pass, needs Depth
// Edge Detection Pass, needs Depth as input
// * Depth in R
// * Edges in G
// osg::ref_ptr< osg::Texture2D > edgeDetectionOut1 = edgeDetection->attach( COLOR_BUFFER0 );
osg::ref_ptr< osg::Texture2D > edgeDetectionOut1 = edgeDetection->attach( osg::Camera::COLOR_BUFFER0 );
osg::StateSet* state = edgeDetection->getOrCreateStateSet();
state->setTextureAttributeAndModes( 0, transformationDepth, osg::StateAttribute::ON );
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Main loop
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// main loop
while ( !m_shutdownFlag() )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment