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  * \note Theoretically should be GLuints, but OpenGL's functions to pass integer offsets as pointers.
72  */
73  static const void* const VERT_OFFSET;
74  static const void* const COLOR_OFFSET;
75 
76  /** Default constructor
77  */
79 
80  /** Destructor
81  */
82  virtual ~GlsQuadListVC_3D();
83 
84  /** Add a quad defined by a 2D rectangle from x1,y1 to x2,y2
85  * \param x1 X coord of point 1
86  * \param y1 Y coord of point 1
87  * \param x2 X coord of point 2
88  * \param y2 Y coord of point 2
89  */
90  void AddQuad2D( const float x1, const float y1, const float x2, const float y2 );
91 
92  /** Add a 3D quad defined by 4 3D vertices
93  * \param v Array of 4 vertices containing the vertices of the 3D quad
94  */
95  void AddQuad3D( const Vector v[] );
96 
97  /** Set the current drawing color. When a quad is added, its vertex colors are set to the current color
98  * \param color The color to set
99  */
100  void SetColor( const glsColor& color );
101 
102  /** Put the quad list in list building mode. Process for using this quad list:
103  * 1. Build the list
104  * 2. Bake the list (creates VBOs)
105  * 3. Draw the list
106  */
107  void StartBuilding();
108 
109  /** Bakes the quad list, creating VBOs within the GL context.
110  * The VBOs created by Bake are used when the object is later drawn with Draw
111  * \param stateManager The StateManager object to create the VBOs within
112  */
113  void Bake( IGlsStateManager* stateManager );
114 
115  /** Draws this quad list
116  * \param stateManager OpenGL context to draw list in
117  * \param enableColor Whether or not to use the per vertex colors when drawing
118  */
119  void Draw( IGlsStateManager* stateManager, const bool enableColor );
120 
121  /** Draws this quad list as a series of line loops
122  * \param stateManager OpenGL context to draw list in
123  * \param enableColor Whether or not to use the per vertex colors when drawing
124  */
125  void DrawOutlines( IGlsStateManager* stateManager, const bool enableColor );
126 
127  /** \return Returns the number of quads in the list */
128  unsigned int NumQuads()
129  {
130  return _numQuads;
131  }
132 
133 protected:
134  unsigned int _numQuads; /**< Number of quads in the list */
135  DynamicArray<V3f_C4ub, true> _vertData; /**< Vertices for the quad list */
136  DynamicArray<GLushort, true> _indices; /**< Indices for the quad list */
137 
138  unsigned int _vboHandle; /**< VBO Handle for this quad storage */
139  unsigned int _indexBufferHandle; /**< Index buffer Handle for this quad storage */
140  unsigned int _vboBufferSize; /**< Size of the VBO buffer. Cached to so that when a quad is cleared and reset
141  we will only reallocate the VBO when its size changes. */
142 
143  glsColor _currentColor; /**< Last color that was set. Used only while building a list */
144 
145  /* Called by AddQuad methods to internally allocate the next quad */
146  void AllocateNextQuad();
147 
148  /** Bind the quad list's VBOs and prepare for drawing
149  * \param stateManager OpenGL context to draw list in
150  * \param enableColor Whether or not to use the per vertex colors when drawing
151  */
152  void SetupVBO( IGlsStateManager* stateManager, const bool enableColor );
153 };
154 
155 /**
156  * GlsQuadListVCT_2D
157  */
159 {
160 public:
161  /** Constant sizes of the primitive vertex attributes */
162  static const GLuint VERT_SIZE = sizeof( V2f );
163  static const GLuint TEX_SIZE = sizeof( V2f );
164  static const GLuint COLOR_SIZE = sizeof( glsColor );
165 
166  /** Constant offsets to the primitive vertex attributes.
167  * \note Strange casting is to support OpenGL's repurposed functions that pass offsets as pointers.
168  */
169  static const void* const VERT_OFFSET;
170  static const void* const TEX_COORD_OFFSET;
171  static const void* const COLOR_OFFSET;
172 
173  /** Default constructor
174  */
176 
177  /** Destructor
178  */
179  virtual ~GlsQuadListVCT_2D();
180 
181  /** Set the current texture coordinates. When a quad is added, these texture coordinates will be used.
182  * x1,y1 will map to quad vertex[0] and x2,y2 will map to quad vertex[1]
183  * \param x1 X coord of point 1
184  * \param y1 Y coord of point 1
185  * \param x2 X coord of point 2
186  * \param y2 Y coord of point 2
187  */
188  void SetTexCoords( const float x1, const float y1, const float x2, const float y2 );
189 
190  /** Set the current texture. This texture will be used when drawing the quad list (if not NULL)
191  * \param image The texture to set, NULL for no texture
192  */
193  void SetTexture( IFontImage* image );
194 
195  /** Set the current drawing color. When a quad is added, its vertex colors are set to the current color
196  * \param color The color to set
197  */
198  void SetColor( const glsColor& color );
199 
200  /** Put the quad list in list building mode. Process for using this quad list:
201  * 1. Build the list
202  * 2. Bake the list (creates VBOs)
203  * 3. Draw the list
204  */
205  void StartBuilding();
206 
207  /** Bakes the quad list, creating VBOs within the GL context.
208  * The VBOs created by Bake are used when the object is later drawn with Draw
209  * \param stateManager The StateManager object to create the VBOs within
210  */
211  void Bake( IGlsStateManager* stateManager );
212 
213  /** Add a quad defined by a 2D rectangle from x1,y1 to x2,y2
214  * \param x1 X coord of point 1
215  * \param y1 Y coord of point 1
216  * \param x2 X coord of point 2
217  * \param y2 Y coord of point 2
218  */
219  void AddQuad2D( const float x1, const float y1, const float x2, const float y2 );
220 
221  /** Draws this quad list
222  * \param stateManager OpenGL context to draw list in
223  * \param enableColor Whether or not to use the per vertex colors when drawing
224  * \param enableTexture Whether or not to use the texture when drawing
225  */
226  void Draw( IGlsStateManager* stateManager, const bool enableColor, const bool enableTexture );
227 
228  /** \return Returns the number of quads in the list */
229  unsigned int NumQuads()
230  {
231  return _numQuads;
232  }
233 
234 protected:
235  class TextureGroup : public NonCopyable
236  {
237  public:
238  /** Default constructor
239  */
240  TextureGroup();
241 
242  /** Destructor
243  */
244  virtual ~TextureGroup();
245 
246  /** Set the current texture. This texture will be used when drawing the quad list (if not NULL)
247  * \param image The texture to set, NULL for no texture
248  */
249  void SetTexture( IFontImage* texture );
250 
251  /** Get the current texture. This texture will be used when drawing the quad list (if not NULL)
252  * \return The texture to set, NULL for no texture
253  */
255 
256  /** Put the quad list in list building mode. Process for using this quad list:
257  * 1. Build the list
258  * 2. Bake the list (creates VBOs)
259  * 3. Draw the list
260  */
261  void StartBuilding();
262 
263  /** Bakes the quad list, creating VBOs within the GL context.
264  * The VBOs created by Bake are used when the object is later drawn with Draw
265  * \param stateManager The StateManager object to create the VBOs within
266  */
267  void Bake( IGlsStateManager* stateManager );
268 
269  /** Add a quad defined by a 2D rectangle from x1,y1 to x2,y2
270  * \param x1 X coord of point 1
271  * \param y1 Y coord of point 1
272  * \param x2 X coord of point 2
273  * \param y2 Y coord of point 2
274  * \param tex texture coordinates
275  * \param color color of the quad points
276  */
277  void AddQuad2D( const float x1, const float y1, const float x2, const float y2,
278  const V2f tex[], const glsColor& color );
279 
280  /** Draws this quad list
281  * \param stateManager OpenGL context to draw list in
282  * \param enableColor Whether or not to use the per vertex colors when drawing
283  * \param enableTexture Whether or not to use the texture when drawing
284  */
285  void Draw( IGlsStateManager* stateManager, const bool enableColor, const bool enableTexture );
286 
287  protected:
288  unsigned int _numQuads; /**< Number of quads in the list */
289  DynamicArray<V2f_T2f_C4ub, true> _vertData; /**< Vertices for the quad list */
290  DynamicArray<GLushort, true> _indices; /**< Indices for the quad list */
291 
292  IFontImage* _texture; /**< Texture to use when drawing quad storage. NULL if untextured */
293 
294  unsigned int _vboHandle; /**< VBO Handle for this quad storage */
295  unsigned int _indexBufferHandle; /**< Index buffer Handle for this quad storage */
296  unsigned int _vboBufferSize; /**< Size of the VBO buffer. Cached to so that when a quad is cleared and reset
297  we will only reallocate the VBO when its size changes. */
298 
299  /* Called by AddQuad methods to internally allocate the next quad */
300  void AllocateNextQuad();
301  };
302 
303  DynamicArray<TextureGroup*, false> _textureGroups; /**< The list of all textured quad groups. */
304  unsigned int _numTextureGroups; /**< The number of textured quad groups in the list. */
305  TextureGroup* _currentTextureGroup; /** Pointer to the current texture group that quads will be added to with the next call to AddQuad */
306 
307  unsigned int _numQuads; /**< Number of quads in the list (total) */
308 
309  V2f _currentTex[ 4 ]; /**< Current texture coordinates supplied for current quad
310  (Texture coordinates are not required to change per quad).
311  Used only while building list. */
312 
313  glsColor _currentColor; /**< Last color that was set. Used only while building a list */
314 };
315 
316 } // namespace disti
317 
318 #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:235
void DrawOutlines(IGlsStateManager *stateManager, const bool enableColor)
Definition: dynamic_array.h:66
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:290
unsigned int _numQuads
Definition: gls_quad_storage.h:307
DynamicArray< GLushort, true > _indices
Definition: gls_quad_storage.h:136
IFontImage * _texture
Definition: gls_quad_storage.h:292
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:135
unsigned int _vboBufferSize
Definition: gls_quad_storage.h:296
void SetColor(const glsColor &color)
DynamicArray< V2f_T2f_C4ub, true > _vertData
Definition: gls_quad_storage.h:289
DynamicArray< TextureGroup *, false > _textureGroups
Definition: gls_quad_storage.h:303
V2f _currentTex[4]
Definition: gls_quad_storage.h:309
Definition: gls_state_manager_interface.h:67
Definition: gls_quad_storage.h:158
static const void *const VERT_OFFSET
Definition: gls_quad_storage.h:169
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:229
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.
static const void *const VERT_OFFSET
Definition: gls_quad_storage.h:73
unsigned int _vboBufferSize
Definition: gls_quad_storage.h:140
unsigned int _numTextureGroups
Definition: gls_quad_storage.h:304
static const GLuint VERT_SIZE
Definition: gls_quad_storage.h:162
glsColor _currentColor
Definition: gls_quad_storage.h:143
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:128
unsigned int _indexBufferHandle
Definition: gls_quad_storage.h:139
Definition: gls_color.h:53
void SetTexture(IFontImage *texture)
static const GLuint VERT_SIZE
Definition: gls_quad_storage.h:67
Definition: vertex.h:84
void SetTexCoords(const float x1, const float y1, const float x2, const float y2)
unsigned int _numQuads
Definition: gls_quad_storage.h:134
void AddQuad2D(const float x1, const float y1, const float x2, const float y2)
unsigned int _numQuads
Definition: gls_quad_storage.h:288
void SetColor(const glsColor &color)
Definition: non_copyable.h:45
unsigned int _vboHandle
Definition: gls_quad_storage.h:294
glsColor _currentColor
Definition: gls_quad_storage.h:313
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:138
void Bake(IGlsStateManager *stateManager)
unsigned int _indexBufferHandle
Definition: gls_quad_storage.h:295
IFontImage.
void Bake(IGlsStateManager *stateManager)
The gls_gl.