00001 #pragma once
00002 #ifndef RENDERNODE_H
00003 #define RENDERNODE_H
00004
00005 #include "Types.h"
00006 #include "AbstractPropertyContainer.h"
00007 #include "PropertyProxyContainer.h"
00008 #include "BindingInterface.h"
00009 #include "RenderInterface.h"
00010 #include "RelationalNode.h"
00011
00012 using namespace std;
00013
00014 namespace RenderTools {
00015
00016 class Rendernode : public BindingInterface, public RenderInterface, public RelationalNode {
00017 public:
00022 typedef unsigned int ComponentMask;
00023 enum RenderComponents{
00024 NONE = 0x0000,
00025 BOUNDS = 0x0001,
00026 AXES = 0x0002,
00027 NORMALS = 0x0040,
00028 ALL = 0xFFFF
00029 };
00030
00034 Rendernode( void );
00035 virtual ~Rendernode( void );
00036
00037 static PropertyPtr create( const XMLNodePtr & xml = XMLNodePtr() );
00038 virtual void createProperties( void );
00039 virtual const string getTypeName( bool ofComponent = false ) const;
00040
00041 void removeVertexBuffers( bool send = true );
00042 void addVertexBuffer( const string buffer, bool send = true );
00043 void addVertexBuffer( const VertexbufferPtr buffer, bool send = true );
00044 const VertexbufferProxyContainerPtr getVertexbufferProxies( void ) const;
00045 const Vec3 & getColor( void ) const;
00046 void setColor( const Vec3 & color, bool send = true );
00047 virtual void onInitialize( void );
00048 virtual void onRender( void );
00049 virtual void onBind( int unit = -1 );
00050 virtual void onUnbind( int unit = -1 );
00051
00052 #ifndef RT_GLES1
00053 void setProgram( string name, bool send = true );
00054 const ProgramProxyPtr getProgramProxy( void ) const;
00055 #endif
00056 void setSampler( string name, bool send = true );
00057 const SamplerProxyPtr getSamplerProxy( void ) const;
00058 void setStateset( string name, bool send = true );
00059 const StatesetProxyPtr getStatesetProxy( void ) const;
00060
00061 void setComponentMask( ComponentMask mask, bool send = true );
00062 void setComponentMask( int mask, bool send = true );
00063 ComponentMask getComponentMask( void ) const;
00064 void setIndex( int index, bool send = true );
00065 bool getVisible( void ) const;
00066 void setVisible( bool state, bool send = true );
00067
00068 protected:
00069 Vec3 m_color;
00070 #ifndef RT_GLES1
00071 ProgramProxyPtr m_program;
00072 #endif
00073 StatesetProxyPtr m_stateset;
00074 SamplerProxyPtr m_sampler;
00075 VertexbufferProxyContainerPtr m_buffers;
00076 ComponentMask m_componentMask;
00077 int m_index;
00078 bool m_visible;
00079 };
00080
00081 struct RenderComponentMaskStruct {
00082 RenderComponentMaskStruct( Rendernode::ComponentMask * e = 0 ):
00083 m_value( e ){
00084 }
00085
00086 bool operator == ( const RenderComponentMaskStruct & v2 ) const{
00087 return( m_value == v2.m_value );
00088 }
00089
00090 Rendernode::ComponentMask * m_value;
00091 };
00092
00093 inline EnumList getRenderComponentsEnums( void ){
00094 EnumList r;
00095 r.push_back("NONE");
00096 r.push_back("BOUNDS");
00097 r.push_back("AXES");
00098 r.push_back("NORMALS");
00099 r.push_back("ALL");
00100 return( r );
00101 }
00102
00103 inline ostream & operator << ( ostream & s, const RenderComponentMaskStruct & v ){
00104 if( ( * v.m_value ) == Rendernode::NONE ){
00105 s << string( "NONE" );
00106 }
00107 else{
00108 if( ( * v.m_value ) & Rendernode::BOUNDS ) s << string( "BOUNDS " );
00109 if( ( * v.m_value ) & Rendernode::AXES ) s << string( "AXES " );
00110 if( ( * v.m_value ) & Rendernode::NORMALS ) s << string( "NORMALS " );
00111 }
00112 return( s );
00113 }
00114
00115 inline istream & operator >> ( istream & s, RenderComponentMaskStruct & v ){
00116 ( * v.m_value ) = Rendernode::NONE;
00117 string value;
00118 while( ! s.fail() ){
00119 s >> value;
00120 if( value == "BOUNDS" ){
00121 ( * v.m_value ) |= Rendernode::BOUNDS;
00122 }
00123 else if( value == "AXES" ){
00124 ( * v.m_value ) |= Rendernode::AXES;
00125 }
00126 else if( value == "NORMALS" ){
00127 ( * v.m_value ) |= Rendernode::NORMALS;
00128 }
00129 else if( value == "ALL" ){
00130 ( * v.m_value ) |= Rendernode::ALL;
00131 }
00132 }
00133 return( s );
00134 }
00135
00136 };
00137
00138
00139 #endif