Equalizer  1.4.1
seqPly/vertexBufferState.h
00001 
00002 /* Copyright (c) 2009-2012, Stefan Eilemann <eile@equalizergraphics.com>
00003  *                    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 
00031 #ifndef MESH_VERTEXBUFFERSTATE_H
00032 #define MESH_VERTEXBUFFERSTATE_H
00033 
00034 #include "typedefs.h"
00035 #include <map>
00036 
00037 #ifdef EQUALIZER
00038 #  include <eq/eq.h>
00039 #  include "channel.h"
00040 #endif // EQUALIZER
00041 
00042 namespace mesh 
00043 {
00044     /*  The abstract base class for kd-tree rendering state.  */
00045     class VertexBufferState
00046     {
00047     public:
00048         enum
00049         {
00050             INVALID = 0 //<! return value for failed operations.
00051         };
00052 
00053         virtual bool useColors() const { return _useColors; }
00054         virtual void setColors( const bool colors ) { _useColors = colors; }
00055         virtual bool stopRendering() const { return false; }
00056         virtual RenderMode getRenderMode() const { return _renderMode; }
00057         virtual void setRenderMode( const RenderMode mode );
00058         virtual bool useFrustumCulling() const { return _useFrustumCulling; }
00059         virtual void setFrustumCulling( const bool frustumCullingState )
00060             { _useFrustumCulling = frustumCullingState; }
00061 
00062         void setProjectionModelViewMatrix( const Matrix4f& pmv )
00063             { _pmvMatrix = pmv; }
00064         const Matrix4f& getProjectionModelViewMatrix() const
00065             { return _pmvMatrix; }
00066 
00067         void setRange( const Range& range ) { _range = range; }
00068         const Range& getRange() const { return _range; }
00069 
00070         void resetRegion();
00071         void updateRegion( const BoundingBox& box );
00072         virtual void declareRegion( const Vector4f& region ) {}
00073         Vector4f getRegion() const;
00074 
00075         virtual GLuint getDisplayList( const void* key ) = 0;
00076         virtual GLuint newDisplayList( const void* key ) = 0;
00077         virtual GLuint getBufferObject( const void* key ) = 0;
00078         virtual GLuint newBufferObject( const void* key ) = 0;
00079         virtual void deleteAll() = 0;
00080 
00081         const GLEWContext* glewGetContext() const { return _glewContext; }
00082         
00083     protected:
00084         VertexBufferState( const GLEWContext* glewContext );        
00085         virtual ~VertexBufferState() {}
00086         
00087         Matrix4f      _pmvMatrix; 
00088         Range         _range; 
00089         const GLEWContext* const _glewContext;
00090         RenderMode    _renderMode;
00091         Vector4f      _region; 
00092         bool          _useColors;
00093         bool          _useFrustumCulling;
00094         
00095     private:
00096     };
00097     
00098     
00099     /*  Simple state for stand-alone single-pipe usage.  */
00100     class VertexBufferStateSimple : public VertexBufferState 
00101     {
00102     private:
00103         typedef std::map< const void*, GLuint > GLMap;
00104         typedef GLMap::const_iterator GLMapCIter;
00105 
00106     public:
00107         VertexBufferStateSimple( const GLEWContext* glewContext )
00108             : VertexBufferState( glewContext ) {}
00109         
00110         virtual GLuint getDisplayList( const void* key );
00111         virtual GLuint newDisplayList( const void* key );        
00112         virtual GLuint getBufferObject( const void* key );        
00113         virtual GLuint newBufferObject( const void* key );
00114         virtual void deleteAll();
00115 
00116     private:
00117         GLMap  _displayLists;
00118         GLMap  _bufferObjects;
00119     };
00120 } // namespace mesh
00121 
00122 #ifdef EQUALIZER
00123 namespace eqPly
00124 {
00125     /*  State for Equalizer usage, uses Eq's Object Manager.  */
00126     class VertexBufferState : public mesh::VertexBufferState 
00127     {
00128     public:
00129         VertexBufferState( eq::Window::ObjectManager* objectManager ) 
00130                 : mesh::VertexBufferState( objectManager->glewGetContext( ))
00131                 , _objectManager( objectManager )
00132             {} 
00133         
00134         virtual GLuint getDisplayList( const void* key )
00135             { return _objectManager->getList( key ); }
00136         
00137         virtual GLuint newDisplayList( const void* key )
00138             { return _objectManager->newList( key ); }
00139         
00140         virtual GLuint getTexture( const void* key )
00141             { return _objectManager->getTexture( key ); }
00142         
00143         virtual GLuint newTexture( const void* key )
00144             { return _objectManager->newTexture( key ); }
00145         
00146         virtual GLuint getBufferObject( const void* key )
00147             { return _objectManager->getBuffer( key ); }
00148         
00149         virtual GLuint newBufferObject( const void* key )
00150             { return _objectManager->newBuffer( key ); }
00151         
00152         virtual GLuint getProgram( const void* key )
00153             { return _objectManager->getProgram( key ); }
00154         
00155         virtual GLuint newProgram( const void* key )
00156             { return _objectManager->newProgram( key ); }
00157         
00158         virtual GLuint getShader( const void* key )
00159             { return _objectManager->getShader( key ); }
00160         
00161         virtual GLuint newShader( const void* key, GLenum type )
00162             { return _objectManager->newShader( key, type ); }
00163 
00164         virtual void deleteAll() { _objectManager->deleteAll(); }
00165         bool isShared() const { return _objectManager->isShared(); }
00166         
00167         void setChannel( Channel* channel ) { _channel = channel; }
00168 
00169         virtual bool stopRendering( ) const
00170             { return _channel ? _channel->stopRendering() : false; }
00171 
00172         virtual void declareRegion( const mesh::Vector4f& region ) 
00173             { if( _channel ) _channel->declareRegion( eq::Viewport( region )); }
00174 
00175     private:
00176         eq::Window::ObjectManager* _objectManager;
00177         Channel* _channel;
00178     };
00179 } // namespace eqPly
00180 #endif // EQUALIZER
00181     
00182 
00183 #endif // MESH_VERTEXBUFFERSTATE_H
Generated on Mon Nov 26 2012 14:41:50 for Equalizer 1.4.1 by  doxygen 1.7.6.1