00001 #ifndef RENDERBUFFER_H 00002 #define RENDERBUFFER_H 00003 00004 #include "Types.h" 00005 #include "Util.h" 00006 00007 #include "Sampler.h" 00008 #include "RelationalNode.h" 00009 #include "PropertyProxy.h" 00010 #include "BindingInterface.h" 00011 00012 using namespace std; 00013 00014 namespace RenderTools { 00015 00023 class Renderbuffer : public BindingInterface, public AbstractPropertyContainer { 00024 public: 00025 00026 enum BufferType { 00027 UNACCEPTABLE, 00028 COLORBUFFER, 00029 STENCILBUFFER, 00030 DEPTHBUFFER, 00031 DEPTHSTENCILBUFFER, 00032 }; 00033 00034 Renderbuffer( void ); 00035 virtual ~Renderbuffer( void ); 00036 00037 static PropertyPtr create( const XMLNodePtr & xml = XMLNodePtr() ); 00038 virtual void createProperties( void ); 00039 virtual void onPropertyEvent( const PropertyEvent & ); 00040 virtual const string getTypeName( bool ofComponent = false ) const; 00041 virtual void onInitialize( void ); 00042 virtual void onBind( int unit = -1 ); 00043 virtual void onUnbind( int unit = -1 ); 00044 00045 GLuint getID( void ) const; 00046 GLuint getWidth( void ) const; 00047 GLuint getHeight( void ) const; 00048 BufferType getType( void ) const; 00049 const SamplerProxyPtr getSamplerProxy( void ) const; 00050 bool hasSampler( void ) const; 00051 static void onUnbind( void ); 00052 static BufferType getTypeFromFormat( GLint format ); 00053 static void setDefaultColorbufferID( GLuint id ); 00054 static void setDefaultDepthbufferID( GLuint id ); 00055 static void setDefaultStencilbufferID( GLuint id ); 00056 static GLuint getDefaultColorbufferID( void ); 00057 static GLuint getDefaultDepthbufferID( void ); 00058 static GLuint getDefaultStencilbufferID( void ); 00059 private: 00060 GLuint m_id; // renderbuffer id 00061 SamplerProxyPtr m_sampler; 00062 GLuint m_format; 00063 GLuint m_w; 00064 GLuint m_h; 00065 00066 static GLuint s_defaultColorbufferID; 00067 static GLuint s_defaultDepthbufferID; 00068 static GLuint s_defaultStencilbufferID; 00069 }; 00070 00071 inline EnumList getRenderbufferTypeEnums( void ){ 00072 EnumList r; 00073 r.push_back("UNACCEPTABLE"); 00074 r.push_back("COLORBUFFER"); 00075 r.push_back("STENCILBUFFER"); 00076 r.push_back("DEPTHBUFFER"); 00077 r.push_back("DEPTHSTENCILBUFFER"); 00078 return( r ); 00079 } 00080 00081 struct BufferTypeStruct { 00082 BufferTypeStruct( Renderbuffer::BufferType * e = 0 ): 00083 m_value( e ){ 00084 } 00085 00086 bool operator == ( const BufferTypeStruct & v2 ){ 00087 return( m_value == v2.m_value ); 00088 } 00089 bool operator != ( const BufferTypeStruct & v2 ){ 00090 return( ! ( m_value == v2.m_value ) ); 00091 } 00092 Renderbuffer::BufferType operator [] ( const unsigned int i ){ 00093 return( * m_value ); 00094 } 00095 00096 Renderbuffer::BufferType * m_value; 00097 }; 00098 00099 inline ostream & operator << ( ostream & s, const BufferTypeStruct & v ){ 00100 switch( * v.m_value ){ 00101 case Renderbuffer::UNACCEPTABLE: 00102 s << string( "UNACCEPTABLE" ); 00103 break; 00104 case Renderbuffer::COLORBUFFER: 00105 s << string( "COLORBUFFER" ); 00106 break; 00107 case Renderbuffer::STENCILBUFFER: 00108 s << string( "STENCILBUFFER" ); 00109 break; 00110 case Renderbuffer::DEPTHBUFFER: 00111 s << string( "DEPTHBUFFER" ); 00112 break; 00113 case Renderbuffer::DEPTHSTENCILBUFFER: 00114 s << string( "DEPTHSTENCILBUFFER" ); 00115 break; 00116 default: 00117 s << string( "UNACCEPTABLE" ); 00118 } 00119 return( s ); 00120 } 00121 00122 inline istream & operator >> ( istream & s, BufferTypeStruct & v ){ 00123 string value; 00124 s >> value; 00125 00126 if( ! s.fail() ){ 00127 if( value == "UNACCEPTABLE" ){ 00128 * v.m_value = Renderbuffer::UNACCEPTABLE; 00129 } 00130 else if( value == "COLORBUFFER" ){ 00131 * v.m_value = Renderbuffer::COLORBUFFER; 00132 } 00133 else if( value == "STENCILBUFFER" ){ 00134 * v.m_value = Renderbuffer::STENCILBUFFER; 00135 } 00136 else if( value == "DEPTHBUFFER" ){ 00137 * v.m_value = Renderbuffer::DEPTHBUFFER; 00138 } 00139 else if( value == "DEPTHSTENCILBUFFER" ){ 00140 * v.m_value = Renderbuffer::DEPTHSTENCILBUFFER; 00141 } 00142 } 00143 return( s ); 00144 } 00145 00146 00147 }; // namespace RenderTools 00148 00149 00150 #endif
1.5.8