Equalizer 1.0

vertexBufferState.h

00001 
00002 /* Copyright (c) 2009, Stefan Eilemann <eile@equalizergraphics.com>
00003  * Copyright (c) 2007, Tobias Wolf <twolf@access.unizh.ch>
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  * - Redistributions of source code must retain the above copyright notice, this
00009  *   list of conditions and the following disclaimer.
00010  * - Redistributions in binary form must reproduce the above copyright notice,
00011  *   this list of conditions and the following disclaimer in the documentation
00012  *   and/or other materials provided with the distribution.
00013  * - Neither the name of Eyescale Software GmbH nor the names of its
00014  *   contributors may be used to endorse or promote products derived from this
00015  *   software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028   
00029     
00030     Header file of the VertexBufferState class.
00031 */
00032 
00033 
00034 #ifndef MESH_VERTEXBUFFERSTATE_H
00035 #define MESH_VERTEXBUFFERSTATE_H
00036 
00037 
00038 #include "typedefs.h"
00039 #include <map>
00040 
00041 #ifdef EQUALIZER
00042 #   include <eq/eq.h>
00043 #   include "channel.h"
00044 #endif // EQUALIZER
00045 
00046 
00047 namespace mesh 
00048 {
00049     /*  The abstract base class for kd-tree rendering state.  */
00050     class VertexBufferState
00051     {
00052     public:
00053         enum
00054         {
00055             INVALID = 0 //<! return value for failed operations.
00056         };
00057 
00058         virtual bool useColors() const { return _useColors; }
00059         virtual void setColors( const bool colors ) { _useColors = colors; }
00060         virtual bool stopRendering() const { return false; }
00061         virtual RenderMode getRenderMode() const { return _renderMode; }
00062         virtual void setRenderMode( const RenderMode mode ) 
00063         { 
00064             if( _renderMode == mode )
00065                 return;
00066 
00067             _renderMode = mode;
00068 
00069             // Check if VBO funcs available, else fall back to display lists
00070             if( _renderMode == RENDER_MODE_BUFFER_OBJECT && !GLEW_VERSION_1_5 )
00071             {
00072                 MESHINFO << "VBO not available, using display lists"
00073                          << std::endl;
00074                 _renderMode = RENDER_MODE_DISPLAY_LIST;
00075             }
00076         }
00077 
00078         virtual GLuint getDisplayList( const void* key ) = 0;
00079         virtual GLuint newDisplayList( const void* key ) = 0;
00080         virtual GLuint getBufferObject( const void* key ) = 0;
00081         virtual GLuint newBufferObject( const void* key ) = 0;
00082         
00083         virtual void deleteAll() = 0;
00084 
00085         const GLEWContext* glewGetContext() const { return _glewContext; }
00086         
00087     protected:
00088         VertexBufferState( const GLEWContext* glewContext ) 
00089             : _glewContext( glewContext ), _useColors( false ), 
00090               _renderMode( RENDER_MODE_DISPLAY_LIST ) 
00091         {
00092             MESHASSERT( glewContext );
00093         } 
00094         
00095         virtual ~VertexBufferState() {}
00096         
00097         const GLEWContext* const _glewContext;
00098         bool          _useColors;
00099         RenderMode    _renderMode;
00100         
00101     private:
00102     };
00103     
00104     
00105     /*  Simple state for stand-alone single-pipe usage.  */
00106     class VertexBufferStateSimple : public VertexBufferState 
00107     {
00108     public:
00109         VertexBufferStateSimple( const GLEWContext* glewContext )
00110             : VertexBufferState( glewContext ) {}
00111         
00112         virtual GLuint getDisplayList( const void* key )
00113         {
00114             if( _displayLists.find( key ) == _displayLists.end() )
00115                 return INVALID;
00116             return _displayLists[key];
00117         }
00118         
00119         virtual GLuint newDisplayList( const void* key )
00120         {
00121             _displayLists[key] = glGenLists( 1 );
00122             return _displayLists[key];
00123         }
00124         
00125         virtual GLuint getBufferObject( const void* key )
00126         {
00127             if( _bufferObjects.find( key ) == _bufferObjects.end() )
00128                 return INVALID;
00129             return _bufferObjects[key];
00130         }
00131         
00132         virtual GLuint newBufferObject( const void* key )
00133         {
00134             if( !GLEW_VERSION_1_5 )
00135                 return INVALID;
00136             glGenBuffers( 1, &_bufferObjects[key] );
00137             return _bufferObjects[key];
00138         }
00139         
00140         virtual void deleteAll() { /* NOP, TBD */ }
00141 
00142     private:
00143         std::map< const void*, GLuint >  _displayLists;
00144         std::map< const void*, GLuint >  _bufferObjects;
00145     };
00146 } // namespace mesh
00147 
00148 #ifdef EQUALIZER
00149 namespace eqPly
00150 {
00151     /*  State for Equalizer usage, uses Eq's Object Manager.  */
00152     class VertexBufferState : public mesh::VertexBufferState 
00153     {
00154     public:
00155         VertexBufferState( eq::Window::ObjectManager* objectManager ) 
00156                 : mesh::VertexBufferState( objectManager->glewGetContext( ))
00157                 , _objectManager( objectManager )
00158             {} 
00159         
00160         virtual GLuint getDisplayList( const void* key )
00161             { return _objectManager->getList( key ); }
00162         
00163         virtual GLuint newDisplayList( const void* key )
00164             { return _objectManager->newList( key ); }
00165         
00166         virtual GLuint getTexture( const void* key )
00167             { return _objectManager->getTexture( key ); }
00168         
00169         virtual GLuint newTexture( const void* key )
00170             { return _objectManager->newTexture( key ); }
00171         
00172         virtual GLuint getBufferObject( const void* key )
00173             { return _objectManager->getBuffer( key ); }
00174         
00175         virtual GLuint newBufferObject( const void* key )
00176             { return _objectManager->newBuffer( key ); }
00177         
00178         virtual GLuint getProgram( const void* key )
00179             { return _objectManager->getProgram( key ); }
00180         
00181         virtual GLuint newProgram( const void* key )
00182             { return _objectManager->newProgram( key ); }
00183         
00184         virtual GLuint getShader( const void* key )
00185             { return _objectManager->getShader( key ); }
00186         
00187         virtual GLuint newShader( const void* key, GLenum type )
00188             { return _objectManager->newShader( key, type ); }
00189 
00190         virtual void deleteAll() { _objectManager->deleteAll(); }
00191         bool isShared() const { return _objectManager->isShared(); }
00192         
00193         void setChannel( const Channel* channel )
00194              { _channel = channel; }
00195 
00196         virtual bool stopRendering( ) const
00197             { EQASSERT( _channel ); return _channel->stopRendering(); }
00198 
00199     private:
00200         eq::Window::ObjectManager* _objectManager;
00201         const Channel* _channel;
00202     };
00203 } // namespace eqPly
00204 #endif // EQUALIZER
00205     
00206     
00207 
00208 #endif // MESH_VERTEXBUFFERSTATE_H
Generated on Sun May 8 2011 19:11:07 for Equalizer 1.0 by  doxygen 1.7.3