GL Studio C++ Runtime API
gls_quad_storage.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::GlsQuadListVC_3D and GlsQuadListVCT_2D classes.
3 
4  \par Copyright Information
5 
6  Copyright (c) 2017 by The DiSTI Corporation.<br>
7  11301 Corporate Blvd; Suite 100<br>
8  Orlando, Florida 32817<br>
9  USA<br>
10  <br>
11  All rights reserved.<br>
12 
13  This Software contains proprietary trade secrets of DiSTI and may not be
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19 
20  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26 
27  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35 
36  The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America. Use, distribution,
38 duplication, or disclosure by the U. S. Government is subject to
39 "Restricted Rights" as set forth in DFARS 252.227-7014(c)(1)(ii).
40 
41 */
42 
43 #ifndef GLS_QUAD_STORAGE_H
44 #define GLS_QUAD_STORAGE_H
45 
46 #include "IFontImage.h"
47 #include "dynamic_array.h"
48 #include "gls_color.h"
49 #include "gls_gl.h"
50 #include "gls_include.h"
52 #include "gls_state_manager.h"
53 #include "non_copyable.h"
54 #include "vertex.h"
55 
56 namespace disti
57 {
58 class Image;
59 
60 /**
61  * GlsQuadListVC_3D
62  */
64 {
65 public:
66  /** Constant sizes of the primitive vertex attributes */
67  static const GLuint VERT_SIZE = sizeof( Vector );
68  static const GLuint COLOR_SIZE = sizeof( glsColor );
69 
70  /** Constant offsets to the primitive vertex attributes. */
71  static const GLuint VERT_OFFSET = 0;
72  static const GLuint COLOR_OFFSET = VERT_SIZE;
73 
74  /** Default constructor
75  */
77 
78  /** Destructor
79  */
80  virtual ~GlsQuadListVC_3D();
81 
82  /** Add a quad defined by a 2D rectangle from x1,y1 to x2,y2
83  * \param x1 X coord of point 1
84  * \param y1 Y coord of point 1
85  * \param x2 X coord of point 2
86  * \param y2 Y coord of point 2
87  */
88  void AddQuad2D( const float x1, const float y1, const float x2, const float y2 );
89 
90  /** Add a 3D quad defined by 4 3D vertices
91  * \param v Array of 4 vertices containing the vertices of the 3D quad
92  */
93  void AddQuad3D( const Vector v[] );
94 
95  /** Set the current drawing color. When a quad is added, its vertex colors are set to the current color
96  * \param color The color to set
97  */
98  void SetColor( const glsColor& color );
99 
100  /** Put the quad list in list building mode. Process for using this quad list:
101  * 1. Build the list
102  * 2. Bake the list (creates VBOs)
103  * 3. Draw the list
104  */
105  void StartBuilding();
106 
107  /** Bakes the quad list, creating VBOs within the GL context.
108  * The VBOs created by Bake are used when the object is later drawn with Draw
109  * \param stateManager The StateManager object to create the VBOs within
110  */
111  void Bake( IGlsStateManager* stateManager );
112 
113  /** Draws this quad list
114  * \param stateManager OpenGL context to draw list in
115  * \param enableColor Whether or not to use the per vertex colors when drawing
116  */
117  void Draw( IGlsStateManager* stateManager, const bool enableColor );
118 
119  /** Draws this quad list as a series of line loops
120  * \param stateManager OpenGL context to draw list in
121  * \param enableColor Whether or not to use the per vertex colors when drawing
122  */
123  void DrawOutlines( IGlsStateManager* stateManager, const bool enableColor );
124 
125  /** \return Returns the number of quads in the list */
126  unsigned int NumQuads()
127  {
128  return _numQuads;
129  }
130 
131 protected:
132  unsigned int _numQuads; /**< Number of quads in the list */
133  DynamicArray<V3f_C4ub, true> _vertData; /**< Vertices for the quad list */
134  DynamicArray<GLushort, true> _indices; /**< Indices for the quad list */
135 
136  unsigned int _vboHandle; /**< VBO Handle for this quad storage */
137  unsigned int _indexBufferHandle; /**< Index buffer Handle for this quad storage */
138  unsigned int _vboBufferSize; /**< Size of the VBO buffer. Cached to so that when a quad is cleared and reset
139  we will only reallocate the VBO when its size changes. */
140 
141  glsColor _currentColor; /**< Last color that was set. Used only while building a list */
142 
143  /* Called by AddQuad methods to internally allocate the next quad */
144  void AllocateNextQuad();
145 
146  /** Bind the quad list's VBOs and prepare for drawing
147  * \param stateManager OpenGL context to draw list in
148  * \param enableColor Whether or not to use the per vertex colors when drawing
149  */
150  void SetupVBO( IGlsStateManager* stateManager, const bool enableColor );
151 };
152 
153 /**
154  * GlsQuadListVCT_2D
155  */
157 {
158 public:
159  /** Constant sizes of the primitive vertex attributes */
160  static const GLuint VERT_SIZE = sizeof( V2f );
161  static const GLuint TEX_SIZE = sizeof( V2f );
162  static const GLuint COLOR_SIZE = sizeof( glsColor );
163 
164  /** Constant offsets to the primitive vertex attributes. */
165  static const GLuint VERT_OFFSET = 0;
166  static const GLuint TEX_COORD_OFFSET = VERT_SIZE;
167  static const GLuint COLOR_OFFSET = VERT_SIZE + TEX_SIZE;
168 
169  /** Default constructor
170  */
172 
173  /** Destructor
174  */
175  virtual ~GlsQuadListVCT_2D();
176 
177  /** Set the current texture coordinates. When a quad is added, these texture coordinates will be used.
178  * x1,y1 will map to quad vertex[0] and x2,y2 will map to quad vertex[1]
179  * \param x1 X coord of point 1
180  * \param y1 Y coord of point 1
181  * \param x2 X coord of point 2
182  * \param y2 Y coord of point 2
183  */
184  void SetTexCoords( const float x1, const float y1, const float x2, const float y2 );
185 
186  /** Set the current texture. This texture will be used when drawing the quad list (if not NULL)
187  * \param image The texture to set, NULL for no texture
188  */
189  void SetTexture( IFontImage* image );
190 
191  /** Set the current drawing color. When a quad is added, its vertex colors are set to the current color
192  * \param color The color to set
193  */
194  void SetColor( const glsColor& color );
195 
196  /** Put the quad list in list building mode. Process for using this quad list:
197  * 1. Build the list
198  * 2. Bake the list (creates VBOs)
199  * 3. Draw the list
200  */
201  void StartBuilding();
202 
203  /** Bakes the quad list, creating VBOs within the GL context.
204  * The VBOs created by Bake are used when the object is later drawn with Draw
205  * \param stateManager The StateManager object to create the VBOs within
206  */
207  void Bake( IGlsStateManager* stateManager );
208 
209  /** Add a quad defined by a 2D rectangle from x1,y1 to x2,y2
210  * \param x1 X coord of point 1
211  * \param y1 Y coord of point 1
212  * \param x2 X coord of point 2
213  * \param y2 Y coord of point 2
214  */
215  void AddQuad2D( const float x1, const float y1, const float x2, const float y2 );
216 
217  /** Draws this quad list
218  * \param stateManager OpenGL context to draw list in
219  * \param enableColor Whether or not to use the per vertex colors when drawing
220  * \param enableTexture Whether or not to use the texture when drawing
221  */
222  void Draw( IGlsStateManager* stateManager, const bool enableColor, const bool enableTexture );
223 
224  /** \return Returns the number of quads in the list */
225  unsigned int NumQuads()
226  {
227  return _numQuads;
228  }
229 
230 protected:
231  class TextureGroup : public NonCopyable
232  {
233  public:
234  /** Default constructor
235  */
236  TextureGroup();
237 
238  /** Destructor
239  */
240  virtual ~TextureGroup();
241 
242  /** Set the current texture. This texture will be used when drawing the quad list (if not NULL)
243  * \param image The texture to set, NULL for no texture
244  */
245  void SetTexture( IFontImage* texture );
246 
247  /** Get the current texture. This texture will be used when drawing the quad list (if not NULL)
248  * \return The texture to set, NULL for no texture
249  */
251 
252  /** Put the quad list in list building mode. Process for using this quad list:
253  * 1. Build the list
254  * 2. Bake the list (creates VBOs)
255  * 3. Draw the list
256  */
257  void StartBuilding();
258 
259  /** Bakes the quad list, creating VBOs within the GL context.
260  * The VBOs created by Bake are used when the object is later drawn with Draw
261  * \param stateManager The StateManager object to create the VBOs within
262  */
263  void Bake( IGlsStateManager* stateManager );
264 
265  /** Add a quad defined by a 2D rectangle from x1,y1 to x2,y2
266  * \param x1 X coord of point 1
267  * \param y1 Y coord of point 1
268  * \param x2 X coord of point 2
269  * \param y2 Y coord of point 2
270  * \param tex texture coordinates
271  * \param color color of the quad points
272  */
273  void AddQuad2D( const float x1, const float y1, const float x2, const float y2,
274  const V2f tex[], const glsColor& color );
275 
276  /** Draws this quad list
277  * \param stateManager OpenGL context to draw list in
278  * \param enableColor Whether or not to use the per vertex colors when drawing
279  * \param enableTexture Whether or not to use the texture when drawing
280  */
281  void Draw( IGlsStateManager* stateManager, const bool enableColor, const bool enableTexture );
282 
283  protected:
284  unsigned int _numQuads; /**< Number of quads in the list */
285  DynamicArray<V2f_T2f_C4ub, true> _vertData; /**< Vertices for the quad list */
286  DynamicArray<GLushort, true> _indices; /**< Indices for the quad list */
287 
288  IFontImage* _texture; /**< Texture to use when drawing quad storage. NULL if untextured */
289 
290  unsigned int _vboHandle; /**< VBO Handle for this quad storage */
291  unsigned int _indexBufferHandle; /**< Index buffer Handle for this quad storage */
292  unsigned int _vboBufferSize; /**< Size of the VBO buffer. Cached to so that when a quad is cleared and reset
293  we will only reallocate the VBO when its size changes. */
294 
295  /* Called by AddQuad methods to internally allocate the next quad */
296  void AllocateNextQuad();
297  };
298 
299  DynamicArray<TextureGroup*, false> _textureGroups; /**< The list of all textured quad groups. */
300  unsigned int _numTextureGroups; /**< The number of textured quad groups in the list. */
301  TextureGroup* _currentTextureGroup; /** Pointer to the current texture group that quads will be added to with the next call to AddQuad */
302 
303  unsigned int _numQuads; /**< Number of quads in the list (total) */
304 
305  V2f _currentTex[ 4 ]; /**< Current texture coordinates supplied for current quad
306  (Texture coordinates are not required to change per quad).
307  Used only while building list. */
308 
309  glsColor _currentColor; /**< Last color that was set. Used only while building a list */
310 };
311 
312 } // namespace disti
313 
314 #endif
GlsColor glsColor
Alias for backwards compatibility.
Definition: gls_color.h:272
void Bake(IGlsStateManager *stateManager)
void AddQuad3D(const Vector v[])
Definition: gls_primitive_storage_types.h:50
The disti::V2f, disti::V2f_C4ub, disti::V3f_C4ub, disti::V2f_T2f_C4ub, and the disti::V2f_T2f structs...
Definition: IFontImage.h:53
Definition: gls_quad_storage.h:231
void DrawOutlines(IGlsStateManager *stateManager, const bool enableColor)
Definition: dynamic_array.h:62
void SetTexture(IFontImage *image)
The disti::DynamicArray class. A templated array of objects capable of dynamically growing...
DynamicArray< GLushort, true > _indices
Definition: gls_quad_storage.h:286
unsigned int _numQuads
Definition: gls_quad_storage.h:303
DynamicArray< GLushort, true > _indices
Definition: gls_quad_storage.h:134
IFontImage * _texture
Definition: gls_quad_storage.h:288
void Draw(IGlsStateManager *stateManager, const bool enableColor)
A base class for objects that are not copyable via the standard C++ copy constructor.
DynamicArray< V3f_C4ub, true > _vertData
Definition: gls_quad_storage.h:133
unsigned int _vboBufferSize
Definition: gls_quad_storage.h:292
void SetColor(const glsColor &color)
DynamicArray< V2f_T2f_C4ub, true > _vertData
Definition: gls_quad_storage.h:285
DynamicArray< TextureGroup *, false > _textureGroups
Definition: gls_quad_storage.h:299
V2f _currentTex[4]
Definition: gls_quad_storage.h:305
Definition: gls_state_manager_interface.h:67
Definition: gls_quad_storage.h:156
void SetupVBO(IGlsStateManager *stateManager, const bool enableColor)
The disti::GlsStateManager factory class. Creates an instance of a state manager that manages the GL ...
The Color class: Implements a 4 component RGBA color.
unsigned int NumQuads()
Definition: gls_quad_storage.h:225
void AddQuad2D(const float x1, const float y1, const float x2, const float y2, const V2f tex[], const glsColor &color)
A file for all GL Studio files to include.
unsigned int _vboBufferSize
Definition: gls_quad_storage.h:138
unsigned int _numTextureGroups
Definition: gls_quad_storage.h:300
static const GLuint VERT_SIZE
Definition: gls_quad_storage.h:160
glsColor _currentColor
Definition: gls_quad_storage.h:141
VertexNoColor Vector
Definition: gls_font_base.h:66
void Draw(IGlsStateManager *stateManager, const bool enableColor, const bool enableTexture)
The disti::Vertex class. A class for manipulating 3D vertices.
unsigned int NumQuads()
Definition: gls_quad_storage.h:126
unsigned int _indexBufferHandle
Definition: gls_quad_storage.h:137
Definition: gls_color.h:53
static const GLuint VERT_OFFSET
Definition: gls_quad_storage.h:71
void SetTexture(IFontImage *texture)
static const GLuint VERT_SIZE
Definition: gls_quad_storage.h:67
Definition: vertex.h:83
static const GLuint VERT_OFFSET
Definition: gls_quad_storage.h:165
void SetTexCoords(const float x1, const float y1, const float x2, const float y2)
unsigned int _numQuads
Definition: gls_quad_storage.h:132
void AddQuad2D(const float x1, const float y1, const float x2, const float y2)
unsigned int _numQuads
Definition: gls_quad_storage.h:284
void SetColor(const glsColor &color)
Definition: non_copyable.h:45
unsigned int _vboHandle
Definition: gls_quad_storage.h:290
glsColor _currentColor
Definition: gls_quad_storage.h:309
void Draw(IGlsStateManager *stateManager, const bool enableColor, const bool enableTexture)
Definition: gls_quad_storage.h:63
Definition: bmpimage.h:46
void AddQuad2D(const float x1, const float y1, const float x2, const float y2)
unsigned int _vboHandle
Definition: gls_quad_storage.h:136
void Bake(IGlsStateManager *stateManager)
unsigned int _indexBufferHandle
Definition: gls_quad_storage.h:291
IFontImage.
void Bake(IGlsStateManager *stateManager)
The gls_gl.