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