osgPPU::Unit Class Reference

Abstract base class of any unit. More...

Inheritance diagram for osgPPU::Unit:

osgPPU::UnitBypass osgPPU::UnitInOut osgPPU::UnitOut osgPPU::UnitTexture osgPPU::UnitCamera osgPPU::UnitCameraAttachmentBypass osgPPU::UnitInMipmapOut osgPPU::UnitInOutModule osgPPU::UnitInResampleOut osgPPU::UnitMipmapInMipmapOut osgPPU::UnitText osgPPU::UnitOutCapture

Public Types

typedef std::map< int,
osg::ref_ptr< osg::Texture > > 
TextureMap
typedef std::vector< unsigned int > IgnoreInputList
typedef std::map< osg::ref_ptr
< Unit >, std::pair
< std::string, unsigned int > > 
InputToUniformMap
typedef std::map< int,
osg::ref_ptr
< osg::PixelDataBufferObject > > 
PixelDataBufferObjectMap

Public Member Functions

 META_Node (osgPPU, Unit)
 Unit ()
 Unit (const Unit &, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
virtual ~Unit ()
bool setInputToUniform (Unit *parent, const std::string &uniform, bool add=false)
bool setInputToUniform (int index, const std::string &uniform)
void removeInputToUniform (const std::string &uniform, bool del=false)
void removeInputToUniform (Unit *parent, bool del=false)
const InputToUniformMap & getInputToUniformMap () const
osg::Texture * getInputTexture (int inputIndex)
const TextureMap & getInputTextureMap () const
osg::Texture * getOutputTexture (int mrt=0)
virtual osg::Texture * getOrCreateOutputTexture (int mrt=0)
const TextureMap & getOutputTextureMap () const
void setIgnoreInput (unsigned int index, bool b=true)
const IgnoreInputList & getIgnoreInputList () const
bool getIgnoreInput (unsigned int index) const
virtual void init ()
virtual void update ()
void setViewport (osg::Viewport *vp)
osg::Viewport * getViewport () const
void setActive (bool b)
bool getActive () const
void setRenderingFrustum (float left, float top, float right, float bottom)
void setInputTextureIndexForViewportReference (int index)
int getInputTextureIndexForViewportReference () const
virtual void dirty ()
bool isDirty () const
osg::Geode * getGeode ()
const osg::Geode * getGeode () const
void setupBlockedChildren ()
void setColorAttribute (ColorAttribute *ca)
ColorAttributegetColorAttribute ()
const ColorAttributegetColorAttribute () const
const osg::PixelDataBufferObject * getInputPBO (int inputIndex)
const osg::PixelDataBufferObject * getOutputPBO (int mrt)
const PixelDataBufferObjectMap & getInputPBOMap () const
const PixelDataBufferObjectMap & getOutputPBOMap () const
void setUsePBOForInputTexture (int index)
bool getUsePBOForInputTexture (int index)
void setUsePBOForOutputTexture (int mrt)
bool getUsePBOForOutputTexture (int mrt)
void pushFrameBufferObject (osg::State &state)
void popFrameBufferObject (osg::State &state)
void setBeginDrawCallback (NotifyCallback *cb)
NotifyCallbackgetBeginDrawCallback ()
const NotifyCallbackgetBeginDrawCallback () const
void setEndDrawCallback (NotifyCallback *cb)
NotifyCallbackgetEndDrawCallback ()
const NotifyCallbackgetEndDrawCallback () const

Protected Member Functions

virtual void updateUniforms ()
virtual void setupInputsFromParents ()
virtual bool noticeBeginRendering (osg::RenderInfo &, const osg::Drawable *)
 Method to let the unit know that the rendering will now beginns, if returned false, then drawable is not rendered.
virtual void noticeFinishRendering (osg::RenderInfo &, const osg::Drawable *)
 Let the unit know that the drawing is done.
virtual void noticeChangeViewport ()
 Notice underlying classes, that viewport size is changed.
virtual void noticeChangeInput ()
 Notice derived classes, when input texture has changed.
virtual void assignInputTexture ()
 Assign the input texture to the quad object.
virtual void assignViewport ()
 Assign currently choosen viewport to the stateset.
virtual void assignInputPBO ()
 Assign input/output PBOs to according textures.
osg::Drawable * createTexturedQuadDrawable (const osg::Vec3 &corner=osg::Vec3(0, 0, 0), const osg::Vec3 &widthVec=osg::Vec3(1, 0, 0), const osg::Vec3 &heightVec=osg::Vec3(0, 1, 0), float l=0.0, float b=0.0, float r=1.0, float t=1.0)
 Helper function to create screen sized quads.
virtual void traverse (osg::NodeVisitor &nv)
 Traverse the unit.

Protected Attributes

TextureMap mInputTex
 Input texture.
TextureMap mOutputTex
 Output textures.
PixelDataBufferObjectMap mInputPBO
 Input pbos of the textures.
PixelDataBufferObjectMap mOutputPBO
 Output pbos of the textures.
IgnoreInputList mIgnoreList
 List of ignored inputs.
InputToUniformMap mInputToUniformMap
 Map of the uniform to parent links.
osg::ref_ptr< osg::Drawable > mDrawable
 Here we store a screen sized quad, so it can be used for rendering.
osg::ref_ptr< osg::RefMatrix > sProjectionMatrix
 Projection matrix of the ppu (default: 2D ortho view).
osg::ref_ptr< osg::RefMatrix > sModelviewMatrix
 Modelview matrix of the ppu (default: identity matrix).
osg::ref_ptr< osg::Viewport > mViewport
 Store here the viewport of the camera, to which one this PPUs are applied.
osg::ref_ptr< osg::Geode > mGeode
 This geode is used to setup the unit's drawable.
osg::ref_ptr< ColorAttributemColorAttribute
 Color attribute for fast direct access.
bool mbDirty
 Is the unit dirty.
int mInputTexIndexForViewportReference
 Index of the input texture which size is used as viewport.
osg::buffered_value< GLuint > mPushedFBO
 Pushed FBOs.

Friends

class Processor
class Pipeline
class CleanUpdateTraversedVisitor
class CleanCullTraversedVisitor
class SetMaximumInputsVisitor

Data Structures

class  DrawCallback
struct  EmptyDrawCallback
struct  NotifyCallback

Detailed Description

Abstract base class of any unit.

Units represents renderable units of the osgPPU library. Each unit has its own functionality. Units can be setted up as a graph, where child units always get as input the output of the parental units. Units has to be a subgraph of the Processor otherwise the rendering wouldn't work, because processor do setup the units in a proper way.


Constructor & Destructor Documentation

osgPPU::Unit::Unit (  ) 

Empty constructor. The unit will be initialized with default values.

osgPPU::Unit::Unit ( const Unit ,
const osg::CopyOp &  copyop = osg::CopyOp::SHALLOW_COPY 
)

Copy constructor.

virtual osgPPU::Unit::~Unit (  )  [virtual]

Release used memory by the ppu.


Member Function Documentation

bool osgPPU::Unit::setInputToUniform ( Unit parent,
const std::string &  uniform,
bool  add = false 
)

Set an input from the given parent to be linked with the given uniform name. This is required to automatically setup uniforms for input textures of the assigned shader, which is based on the index of the given parent unit in the parent list. The type of the given uniform will be equivalent to the type of the input texture (e.g. SAMPLER_2D = Texture2D).

Parameters:
parent Pointer to the parent which output to use
uniform Name of the uniform to use to bind the texture to
add if true will add the given parent to the parent list (same as calling parent->addChild()) [default=false]
Returns:
true if uniform is set or false otherwise

bool osgPPU::Unit::setInputToUniform ( int  index,
const std::string &  uniform 
)

Set input texture of this unit as uniform of this unit.

Parameters:
index Input texture index to be used as input
uniform Name of the uniform

void osgPPU::Unit::removeInputToUniform ( const std::string &  uniform,
bool  del = false 
)

Remove an assigned parent output uniform.

See also:
assignParentToUniform()
Parameters:
uniform Name of the uniform
del Should this unit be removed from the child list of the parent connected with the given uniform [default=false]

void osgPPU::Unit::removeInputToUniform ( Unit parent,
bool  del = false 
)

Remove an assigned parent output uniform.

See also:
assignParentToUniform()
Parameters:
parent Pointer to the parent node
del Should this unit be removed from the child list of this parent [default=false]

const InputToUniformMap& osgPPU::Unit::getInputToUniformMap (  )  const

Get the map which maps uniform to input units

osg::Texture* osgPPU::Unit::getInputTexture ( int  inputIndex  ) 

Return an input texture of a certain index.

Parameters:
inputIndex Index of the input texture (index is equal to the texture unit)

const TextureMap& osgPPU::Unit::getInputTextureMap (  )  const

Return complete index to texture mapping

osg::Texture* osgPPU::Unit::getOutputTexture ( int  mrt = 0  ) 

Get output texture of certain MRT index. NOTE: If you haven't initialized the Unit before calling this method it might end up in a NULL as output texture. For this purpose do use the getOrCreateOutputTexture().

virtual osg::Texture* osgPPU::Unit::getOrCreateOutputTexture ( int  mrt = 0  )  [virtual]

Return an output texture of the certain MRT index. If there is no output texture for that index is specified, then it will be allocated. The method should be overwriten by the derived Units if they use any Output texture. Otherwise the result is always the same as from getOutputTexture().

Reimplemented in osgPPU::UnitInOut, and osgPPU::UnitText.

const TextureMap& osgPPU::Unit::getOutputTextureMap (  )  const

Get mrt index to texture mapping

void osgPPU::Unit::setIgnoreInput ( unsigned int  index,
bool  b = true 
)

If you like that a unit doesn't use a certain input you can specify its index here. This allows to place units on certain positions in the unit graph without using its parents as inputs.

const IgnoreInputList& osgPPU::Unit::getIgnoreInputList (  )  const

Get input ignorance map which list all indices of input data which are ignored

bool osgPPU::Unit::getIgnoreInput ( unsigned int  index  )  const

Check whenever the input of the given index is ignored or not

virtual void osgPPU::Unit::init (  )  [virtual]

Initialze the unit. This method should be overwritten by the derived classes to support non-standard initialization routines. If an unit is marked as dirty this method will be used to resetup the unit. Hence do provide a "reinitialable"-code here ;-)

Reimplemented in osgPPU::UnitCameraAttachmentBypass, osgPPU::UnitInMipmapOut, osgPPU::UnitInOut, osgPPU::UnitInOutModule, osgPPU::UnitInResampleOut, osgPPU::UnitMipmapInMipmapOut, osgPPU::UnitOut, osgPPU::UnitOutCapture, osgPPU::UnitText, and osgPPU::UnitTexture.

virtual void osgPPU::Unit::update (  )  [virtual]

Update the unit. Call this method every time you want to update the unit. It is a good idea to call this method every frame otherwise the behaviour of the unit might be unpredictable.

void osgPPU::Unit::setViewport ( osg::Viewport *  vp  ) 

Set viewport which is used for this Unit while rendering. Setting any viewport will force it to be used. If no viewport is set, then either input texture size is used as viewport or processors camera viewport is used as input.

osg::Viewport* osgPPU::Unit::getViewport (  )  const

Get viewport of this unit

void osgPPU::Unit::setActive ( bool  b  ) 

Activate or deactive the ppu. An active ppu is updated during the update of the post processor.

Parameters:
b True to activate, false to deactive

bool osgPPU::Unit::getActive (  )  const

Check if the Unit's active flag

void osgPPU::Unit::setRenderingFrustum ( float  left,
float  top,
float  right,
float  bottom 
)

Change drawing position and size of this ppu by using the new frustum planes in the orthogonal projection matrix. This changes the projection matrix, therefor it is better not to change this parameters until you really need this. If you just want to place the ppu on another position, then just play with the viewport.

void osgPPU::Unit::setInputTextureIndexForViewportReference ( int  index  ) 

Set index of an input texture which size is used as reference for the viewport size. The viewport size will be changed according to the texture size. If you change the input texture the size will be also changed. Specify -1 if you do not want to have this behaviour. If -1, then by next change of the input texture the viewport size will not be changed.

int osgPPU::Unit::getInputTextureIndexForViewportReference (  )  const

Get index of the input texture which dimension is used for setting up the viewport.

virtual void osgPPU::Unit::dirty (  )  [virtual]

Mark this unit as dirty. This will force it to resetup its data on next update. Also every child unit will be marked as dirty. This yields of reinitialization of children units on next update method too.

Reimplemented in osgPPU::UnitInResampleOut.

bool osgPPU::Unit::isDirty (  )  const

Checks whenever the unit is marked as dirty or not.

osg::Geode* osgPPU::Unit::getGeode (  ) 

Get geode to which the unit's drawables are attached. The geodes are used to render the unit.

void osgPPU::Unit::setupBlockedChildren (  ) 

Setup children nodes if they are connected by a barrier node. This method don't need to be called outside of the unit. The method is placed here to allow acess to it from the derived units.

void osgPPU::Unit::setColorAttribute ( ColorAttribute ca  ) 

Set a new color attribute for this unit. This will replace the color attribute if it is already set. The color attribute can be used to bind a color to an unit. Very useful for blending units.

ColorAttribute* osgPPU::Unit::getColorAttribute (  ) 

Get current color attribute of the unit.

const osg::PixelDataBufferObject* osgPPU::Unit::getInputPBO ( int  inputIndex  ) 

Return a PixelDataBufferObject associated with the input texture. If using of pbos is deactivated, then undefined result might be given back.

void osgPPU::Unit::setUsePBOForInputTexture ( int  index  ) 

Specify a flag whenever input textures have to be mapped to the input PixelDataBufferObjects. If enabled, data from the input texture will be written to the according input PBO on each apply. This gives you the possibility of using the data stored in the buffer externally. NOTE: A PixelDataBufferObject resides also on the GPU as the texture does. Hence reading/writing of data in/to PBO isn't that costly, because data is copied in the video memory.

void osgPPU::Unit::pushFrameBufferObject ( osg::State &  state  ) 

Push current FBO, so that it can safely be overwritten. Derived classes and its subclasses get use of this method.

void osgPPU::Unit::popFrameBufferObject ( osg::State &  state  ) 

Restore last used FrameBufferObject back. This will restore the FBO pushed before with pushFrameBufferObject method.

void osgPPU::Unit::setBeginDrawCallback ( NotifyCallback cb  ) 

Set before rendering notify callback. Callback is executed before main drawable of a unit is drawed.

void osgPPU::Unit::setEndDrawCallback ( NotifyCallback cb  ) 

Set after rendering notify callback. Callback is executed after main drawable of a unit is drawed.

virtual void osgPPU::Unit::updateUniforms (  )  [protected, virtual]

Use this method in the derived classes to implement and update some unit specific uniforms. The base class do only update uniforms like viewport size or, if defined, input texture indices.

virtual void osgPPU::Unit::setupInputsFromParents (  )  [protected, virtual]

Setup the input textures based on the parents. Each unit has to setup its input textures properly. This method do scan for all parents up to the Processor and use the output textures of that parents units and the processor as input to this unit. Call this method from derived units to setup inputs properly.

Reimplemented in osgPPU::UnitBypass, and osgPPU::UnitCameraAttachmentBypass.


The documentation for this class was generated from the following file:

Back to Homepage of osgPPU

Copyright (C) 2008 by Art Tevs (LGPL)