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