Equalizer  1.6.1
eqPly/vertexBufferState.h
1 
2 /* Copyright (c) 2009-2012, Stefan Eilemann <eile@equalizergraphics.com>
3  * 2007, Tobias Wolf <twolf@access.unizh.ch>
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * - Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  * - Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * - Neither the name of Eyescale Software GmbH nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 
31 #ifndef MESH_VERTEXBUFFERSTATE_H
32 #define MESH_VERTEXBUFFERSTATE_H
33 
34 #include "typedefs.h"
35 #include <map>
36 
37 #ifdef EQUALIZER
38 # include <eq/eq.h>
39 # include "channel.h"
40 #endif // EQUALIZER
41 
42 namespace mesh
43 {
44  /* The abstract base class for kd-tree rendering state. */
46  {
47  public:
48  enum
49  {
50  INVALID = 0 //<! return value for failed operations.
51  };
52 
53  virtual bool useColors() const { return _useColors; }
54  virtual void setColors( const bool colors ) { _useColors = colors; }
55  virtual bool stopRendering() const { return false; }
56  virtual RenderMode getRenderMode() const { return _renderMode; }
57  virtual void setRenderMode( const RenderMode mode );
58  virtual bool useFrustumCulling() const { return _useFrustumCulling; }
59  virtual void setFrustumCulling( const bool frustumCullingState )
60  { _useFrustumCulling = frustumCullingState; }
61 
62  void setProjectionModelViewMatrix( const Matrix4f& pmv )
63  { _pmvMatrix = pmv; }
64  const Matrix4f& getProjectionModelViewMatrix() const
65  { return _pmvMatrix; }
66 
67  void setRange( const Range& range ) { _range = range; }
68  const Range& getRange() const { return _range; }
69 
70  void resetRegion();
71  void updateRegion( const BoundingBox& box );
72  virtual void declareRegion( const Vector4f& region ) {}
73  Vector4f getRegion() const;
74 
75  virtual GLuint getDisplayList( const void* key ) = 0;
76  virtual GLuint newDisplayList( const void* key ) = 0;
77  virtual GLuint getBufferObject( const void* key ) = 0;
78  virtual GLuint newBufferObject( const void* key ) = 0;
79  virtual void deleteAll() = 0;
80 
81  const GLEWContext* glewGetContext() const { return _glewContext; }
82 
83  protected:
84  VertexBufferState( const GLEWContext* glewContext );
85  virtual ~VertexBufferState() {}
86 
87  Matrix4f _pmvMatrix;
89  const GLEWContext* const _glewContext;
90  RenderMode _renderMode;
91  Vector4f _region;
92  bool _useColors;
93  bool _useFrustumCulling;
94 
95  private:
96  };
97 
98 
99  /* Simple state for stand-alone single-pipe usage. */
101  {
102  private:
103  typedef std::map< const void*, GLuint > GLMap;
104  typedef GLMap::const_iterator GLMapCIter;
105 
106  public:
107  VertexBufferStateSimple( const GLEWContext* glewContext )
108  : VertexBufferState( glewContext ) {}
109 
110  virtual GLuint getDisplayList( const void* key );
111  virtual GLuint newDisplayList( const void* key );
112  virtual GLuint getBufferObject( const void* key );
113  virtual GLuint newBufferObject( const void* key );
114  virtual void deleteAll();
115 
116  private:
117  GLMap _displayLists;
118  GLMap _bufferObjects;
119  };
120 } // namespace mesh
121 
122 #ifdef EQUALIZER
123 namespace eqPly
124 {
125  /* State for Equalizer usage, uses Eq's Object Manager. */
127  {
128  public:
130  : mesh::VertexBufferState( objectManager->glewGetContext( ))
131  , _objectManager( objectManager )
132  {}
133 
134  virtual GLuint getDisplayList( const void* key )
135  { return _objectManager->getList( key ); }
136 
137  virtual GLuint newDisplayList( const void* key )
138  { return _objectManager->newList( key ); }
139 
140  virtual GLuint getTexture( const void* key )
141  { return _objectManager->getTexture( key ); }
142 
143  virtual GLuint newTexture( const void* key )
144  { return _objectManager->newTexture( key ); }
145 
146  virtual GLuint getBufferObject( const void* key )
147  { return _objectManager->getBuffer( key ); }
148 
149  virtual GLuint newBufferObject( const void* key )
150  { return _objectManager->newBuffer( key ); }
151 
152  virtual GLuint getProgram( const void* key )
153  { return _objectManager->getProgram( key ); }
154 
155  virtual GLuint newProgram( const void* key )
156  { return _objectManager->newProgram( key ); }
157 
158  virtual GLuint getShader( const void* key )
159  { return _objectManager->getShader( key ); }
160 
161  virtual GLuint newShader( const void* key, GLenum type )
162  { return _objectManager->newShader( key, type ); }
163 
164  virtual void deleteAll() { _objectManager->deleteAll(); }
165  bool isShared() const { return _objectManager->isShared(); }
166 
167  void setChannel( Channel* channel ) { _channel = channel; }
168 
169  virtual bool stopRendering( ) const
170  { return _channel ? _channel->stopRendering() : false; }
171 
172  virtual void declareRegion( const mesh::Vector4f& region )
173  { if( _channel ) _channel->declareRegion( eq::Viewport( region )); }
174 
175  private:
176  eq::Window::ObjectManager* _objectManager;
177  Channel* _channel;
178  };
179 } // namespace eqPly
180 #endif // EQUALIZER
181 
182 
183 #endif // MESH_VERTEXBUFFERSTATE_H
bool isShared() const
Definition: objectManager.h:75
Matrix4f _pmvMatrix
projection * modelView matrix
Range _range
normalized [0,1] part of the model to draw
The rendering entity, updating a part of a Window.
Vector4f _region
normalized x1 y1 x2 y2 region from cullDraw
A facility class to manage OpenGL objects across shared contexts.
void deleteAll()
Delete all managed objects and associated GL objects.
virtual void declareRegion(const eq::PixelViewport &region)
Declare a region covered by the current draw or assemble operation.