| 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"
51#include "gls_primitive_storage_types.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 */
63 class GlsQuadListVC_3D : public NonCopyable
64{
65 public:
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 */
79 GlsQuadListVC_3D();
80
81 /** Destructor
82 */
83 virtual ~GlsQuadListVC_3D();
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 */
108 void StartBuilding();
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
134 protected:
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.
147 void AllocateNextQuad();
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 */
159 class GlsQuadListVCT_2D : public NonCopyable
160{
161 public:
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 */
180 GlsQuadListVCT_2D();
181
182 /** Destructor
183 */
184 virtual ~GlsQuadListVCT_2D();
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 */
210 void StartBuilding();
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
239 protected:
240 /// \details The TextureGroup class. Holds a number of textured quads.
241 class TextureGroup : public NonCopyable
242 {
243 public:
244 /** Default constructor
245 */
246 TextureGroup();
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 */
260 IFontImage* GetTexture();
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 */
267 void StartBuilding();
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.
306 void AllocateNextQuad();
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.h
IFontImage.
disti::DynamicArray
Definition: dynamic_array.h:79
disti::GlsColor
Definition: gls_color.h:54
disti::GlsQuadListVCT_2D::TextureGroup
Definition: gls_quad_storage.h:242
disti::GlsQuadListVCT_2D::TextureGroup::_texture
IFontImage * _texture
Definition: gls_quad_storage.h:298
disti::GlsQuadListVCT_2D::TextureGroup::_vboBufferSize
unsigned int _vboBufferSize
Definition: gls_quad_storage.h:302
disti::GlsQuadListVCT_2D::TextureGroup::_numQuads
unsigned int _numQuads
Definition: gls_quad_storage.h:294
disti::GlsQuadListVCT_2D::TextureGroup::_indices
DynamicArray< GLushort, true > _indices
Definition: gls_quad_storage.h:296
disti::GlsQuadListVCT_2D::TextureGroup::AddQuad2D
void AddQuad2D(const float x1, const float y1, const float x2, const float y2, const V2f tex[], const glsColor &color)
disti::GlsQuadListVCT_2D::TextureGroup::_indexBufferHandle
unsigned int _indexBufferHandle
Definition: gls_quad_storage.h:301
disti::GlsQuadListVCT_2D::TextureGroup::Draw
void Draw(IGlsStateManager *stateManager, const bool enableColor, const bool enableTexture)
disti::GlsQuadListVCT_2D::TextureGroup::_vertData
DynamicArray< V2f_T2f_C4ub, true > _vertData
Definition: gls_quad_storage.h:295
disti::GlsQuadListVCT_2D::TextureGroup::StartBuilding
void StartBuilding()
disti::GlsQuadListVCT_2D::TextureGroup::~TextureGroup
virtual ~TextureGroup()
disti::GlsQuadListVCT_2D::TextureGroup::_vboHandle
unsigned int _vboHandle
Definition: gls_quad_storage.h:300
disti::GlsQuadListVCT_2D::TextureGroup::AllocateNextQuad
void AllocateNextQuad()
Called by AddQuad methods to internally allocate the next quad.
disti::GlsQuadListVCT_2D::TextureGroup::TextureGroup
TextureGroup()
disti::GlsQuadListVCT_2D::TextureGroup::SetTexture
void SetTexture(IFontImage *texture)
disti::GlsQuadListVCT_2D::TextureGroup::Bake
void Bake(IGlsStateManager *stateManager)
disti::GlsQuadListVCT_2D::TextureGroup::GetTexture
IFontImage * GetTexture()
disti::GlsQuadListVCT_2D
Definition: gls_quad_storage.h:160
disti::GlsQuadListVCT_2D::TEX_SIZE
static const GLuint TEX_SIZE
Size of a texture coordinate in bytes.
Definition: gls_quad_storage.h:163
disti::GlsQuadListVCT_2D::_textureGroups
DynamicArray< TextureGroup *, false > _textureGroups
The list of all textured quad groups.
Definition: gls_quad_storage.h:309
disti::GlsQuadListVCT_2D::TEX_COORD_OFFSET
static const void *const TEX_COORD_OFFSET
Definition: gls_quad_storage.h:172
disti::GlsQuadListVCT_2D::SetColor
void SetColor(const glsColor &color)
disti::GlsQuadListVCT_2D::COLOR_OFFSET
static const void *const COLOR_OFFSET
Definition: gls_quad_storage.h:176
disti::GlsQuadListVCT_2D::_numQuads
unsigned int _numQuads
Definition: gls_quad_storage.h:313
disti::GlsQuadListVCT_2D::VERT_OFFSET
static const void *const VERT_OFFSET
Definition: gls_quad_storage.h:168
disti::GlsQuadListVCT_2D::_numTextureGroups
unsigned int _numTextureGroups
The number of textured quad groups in the list.
Definition: gls_quad_storage.h:310
disti::GlsQuadListVCT_2D::COLOR_SIZE
static const GLuint COLOR_SIZE
Size of a color in bytes.
Definition: gls_quad_storage.h:164
disti::GlsQuadListVCT_2D::VERT_SIZE
static const GLuint VERT_SIZE
Size of a vertex in bytes.
Definition: gls_quad_storage.h:162
disti::GlsQuadListVCT_2D::_currentColor
glsColor _currentColor
Definition: gls_quad_storage.h:319
disti::GlsQuadListVCT_2D::Draw
void Draw(IGlsStateManager *stateManager, const bool enableColor, const bool enableTexture)
disti::GlsQuadListVCT_2D::StartBuilding
void StartBuilding()
disti::GlsQuadListVCT_2D::SetTexCoords
void SetTexCoords(const float x1, const float y1, const float x2, const float y2)
disti::GlsQuadListVCT_2D::GlsQuadListVCT_2D
GlsQuadListVCT_2D()
disti::GlsQuadListVCT_2D::~GlsQuadListVCT_2D
virtual ~GlsQuadListVCT_2D()
disti::GlsQuadListVCT_2D::SetTexture
void SetTexture(IFontImage *image)
disti::GlsQuadListVCT_2D::Bake
void Bake(IGlsStateManager *stateManager)
disti::GlsQuadListVCT_2D::AddQuad2D
void AddQuad2D(const float x1, const float y1, const float x2, const float y2)
disti::GlsQuadListVCT_2D::_currentTextureGroup
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
disti::GlsQuadListVCT_2D::NumQuads
unsigned int NumQuads()
Definition: gls_quad_storage.h:234
disti::GlsQuadListVCT_2D::_currentTex
V2f _currentTex[4]
Definition: gls_quad_storage.h:315
disti::GlsQuadListVC_3D
Definition: gls_quad_storage.h:64
disti::GlsQuadListVC_3D::SetColor
void SetColor(const glsColor &color)
disti::GlsQuadListVC_3D::_vertData
DynamicArray< V3f_C4ub, true > _vertData
Definition: gls_quad_storage.h:136
disti::GlsQuadListVC_3D::COLOR_OFFSET
static const void *const COLOR_OFFSET
Definition: gls_quad_storage.h:75
disti::GlsQuadListVC_3D::_vboBufferSize
unsigned int _vboBufferSize
Definition: gls_quad_storage.h:141
disti::GlsQuadListVC_3D::Draw
void Draw(IGlsStateManager *stateManager, const bool enableColor)
disti::GlsQuadListVC_3D::_numQuads
unsigned int _numQuads
Definition: gls_quad_storage.h:135
disti::GlsQuadListVC_3D::VERT_OFFSET
static const void *const VERT_OFFSET
Definition: gls_quad_storage.h:71
disti::GlsQuadListVC_3D::_indices
DynamicArray< GLushort, true > _indices
Definition: gls_quad_storage.h:137
disti::GlsQuadListVC_3D::AddQuad3D
void AddQuad3D(const Vector v[])
disti::GlsQuadListVC_3D::COLOR_SIZE
static const GLuint COLOR_SIZE
Size of a color in bytes.
Definition: gls_quad_storage.h:67
disti::GlsQuadListVC_3D::VERT_SIZE
static const GLuint VERT_SIZE
Size of a vertex in bytes.
Definition: gls_quad_storage.h:66
disti::GlsQuadListVC_3D::_indexBufferHandle
unsigned int _indexBufferHandle
Definition: gls_quad_storage.h:140
disti::GlsQuadListVC_3D::_currentColor
glsColor _currentColor
Definition: gls_quad_storage.h:144
disti::GlsQuadListVC_3D::GlsQuadListVC_3D
GlsQuadListVC_3D()
disti::GlsQuadListVC_3D::StartBuilding
void StartBuilding()
disti::GlsQuadListVC_3D::DrawOutlines
void DrawOutlines(IGlsStateManager *stateManager, const bool enableColor)
disti::GlsQuadListVC_3D::_vboHandle
unsigned int _vboHandle
Definition: gls_quad_storage.h:139
disti::GlsQuadListVC_3D::SetupVBO
void SetupVBO(IGlsStateManager *stateManager, const bool enableColor)
disti::GlsQuadListVC_3D::AllocateNextQuad
void AllocateNextQuad()
Called by AddQuad methods to internally allocate the next quad.
disti::GlsQuadListVC_3D::~GlsQuadListVC_3D
virtual ~GlsQuadListVC_3D()
disti::GlsQuadListVC_3D::Bake
void Bake(IGlsStateManager *stateManager)
disti::GlsQuadListVC_3D::AddQuad2D
void AddQuad2D(const float x1, const float y1, const float x2, const float y2)
disti::GlsQuadListVC_3D::NumQuads
unsigned int NumQuads()
Definition: gls_quad_storage.h:129
disti::IFontImage
Definition: IFontImage.h:54
disti::IGlsStateManager
Definition: gls_state_manager_interface.h:69
disti::NonCopyable
Definition: non_copyable.h:47
disti::VertexNoColor
Definition: vertex.h:85
dynamic_array.h
The disti::DynamicArray class. A templated array of objects capable of dynamically growing.
gls_color.h
The Color class: Implements a 4 component RGBA color.
gls_gl.h
The gls_gl.
gls_include.h
A file for all GL Studio files to include.
gls_primitive_storage_types.h
The disti::V2f, disti::V2f_C4ub, disti::V3f_C4ub, disti::V2f_T2f_C4ub, and the disti::V2f_T2f structs...
gls_state_manager.h
The disti::GlsStateManager factory class. Creates an instance of a state manager that manages the GL ...
disti
Definition: bmpimage.h:47
disti::glsColor
GlsColor glsColor
Alias for backwards compatibility.
Definition: gls_color.h:286
disti::Vector
VertexNoColor Vector
Definition: gls_font_base.h:69
non_copyable.h
A base class for objects that are not copyable via the standard C++ copy constructor.
disti::V2f
Definition: gls_primitive_storage_types.h:52
vertex.h
The disti::Vertex class. A class for manipulating 3D vertices.