GL Studio C++ Runtime API
gls_triangle_storage.h
Go to the documentation of this file.
1/*! \file
2 \brief The disti::GlsTriangleStrip2D class.
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.
38
39 */
40
41#ifndef GLS_TRIANGLE_STORAGE_H
42#define GLS_TRIANGLE_STORAGE_H
43
44#include "dynamic_array.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/// \details The GlsTriangleStrip2D class. Wraps an OpenGL triangle strip drawable.
58{
59public:
60 static const GLuint VERT_SIZE = sizeof( V2f ); ///< Size of a vertex in bytes.
61 static const GLuint TEX_SIZE = sizeof( V2f ); ///< Size of a texture coordinate in bytes.
62
63 /// Constant offsets to the primitive vertex attribute.
64 /// \note Theoretically should be GLuints, but OpenGL's functions to pass integer offsets as pointers.
65 static const void* const VERT_OFFSET;
66
67 /// Constant offsets to the primitive texture coordinate attribute.
68 /// \note Theoretically should be GLuints, but OpenGL's functions to pass integer offsets as pointers.
69 static const void* const TEX_COORD_OFFSET;
70
71 /** Default constructor
72 */
74
75 /** Destructor
76 */
78
79 /** Sets this object into strip building mode. During strip building mode the user adds individual triangles to the strip
80 * When strip building mode is finished, the object will create a triangle strip from the individual triangles
81 * \pre none
82 * \post _stripified == false
83 */
85
86 /** Set the texture to be used for this triangle strip. The triangle strip may only have one texture, so it is an error to call this
87 * more than once after StartBuildingStrip() has been called.
88 * \pre _texture == NULL && _stripified == false
89 * \post _texture == img
90 * \param image The texture to assign, or NULL if no texture
91 */
92 void SetTexture( Image* image );
93
94 /** Set the texture coordinates to be used for the next triangle that is added (or subsequent triangles if this is not called again
95 * \param x1 X coord of vertex 1
96 * \param y1 Y coord of vertex 1
97 * \param x2 X coord of vertex 2
98 * \param y2 Y coord of vertex 2
99 * \param x3 X coord of vertex 3
100 * \param y3 Y coord of vertex 3
101 * \pre _texture != NULL && _stripified == false
102 * \post _currentTex contains input values
103 */
104 void SetTexCoords( const float x1, const float y1, const float x2, const float y2, const float x3, const float y3 );
105
106 /** Add the next triangle to the strip. Must be connected using previous two vertices of strip or be degenerate
107 * \param x1 X coord of vertex 1
108 * \param y1 Y coord of vertex 1
109 * \param x2 X coord of vertex 2
110 * \param y2 Y coord of vertex 2
111 * \param x3 X coord of vertex 3
112 * \param y3 Y coord of vertex 3
113 * \pre _stripified == false
114 * \post _numTriangles++, triangle is added to strip
115 */
116 void AddTriangle2D( const float x1, const float y1, const float x2, const float y2, const float x3, const float y3 );
117
118 /** Finish building strip and bake it to a VBO
119 * \param stateManager StateManager object to issue GL commands to
120 * \pre _stripified == false
121 * \pre _stripified == true
122 */
123 void Bake( IGlsStateManager* stateManager );
124
125 /** Draw the triangle strip
126 * \param stateManager StateManager object to issue GL commands to
127 * \param enableTexture True if strip will be drawn textured
128 * \pre _stripified == true
129 * \post The strip is drawn
130 */
131 void Draw( IGlsStateManager* stateManager, const bool enableTexture );
132
133 /// \return The number of triangles in this strip.
134 unsigned int GetNumTriangles()
135 {
136 return _numTriangles;
137 }
138
139protected:
140 unsigned int _numTriangles; /**< The number of triangles in the strip */
141 unsigned int _stripSize; /**< The number of vertices in the strip */
142
143 DynamicArray<V2f_T2f, true> _vertData; /**< DynamicArray to store vertex and texture coordinates */
144 V2f _currentTex[ 3 ]; /**< Current texture coordinates supplied for current triangle
145 (Texture coordinates are not required to change per triangle)
146 Used only while building list.
147 */
148
149 Image* _texture; /**< Texture to use when drawing strip. NULL if untextured */
150
151 unsigned int _vboHandle; /**< VBO Handle for this triangle strip */
152 unsigned int _vboBufferSize; /**< Size of the VBO buffer. Cached to so that when a strip is cleared and reset
153 we will only reallocate the VBO when its size changes. */
154 bool _stripified; /**< True if triangles have been created into a strip */
155
156 /** Allocate the next triangle in the set of ordered, connected triangles */
158
159 /** Convert the set of ordered, connected triangles in this object into tristrip
160 * \pre _stripified == false
161 * \pre _stripified == true
162 */
163 void Stripify();
164};
165
166} // namespace disti
167
168#endif
Definition: dynamic_array.h:79
Definition: gls_triangle_storage.h:58
static const GLuint TEX_SIZE
Size of a texture coordinate in bytes.
Definition: gls_triangle_storage.h:61
DynamicArray< V2f_T2f, true > _vertData
Definition: gls_triangle_storage.h:143
static const void *const TEX_COORD_OFFSET
Definition: gls_triangle_storage.h:69
void SetTexCoords(const float x1, const float y1, const float x2, const float y2, const float x3, const float y3)
unsigned int _vboBufferSize
Definition: gls_triangle_storage.h:152
unsigned int GetNumTriangles()
Definition: gls_triangle_storage.h:134
V2f _currentTex[3]
Definition: gls_triangle_storage.h:144
static const void *const VERT_OFFSET
Definition: gls_triangle_storage.h:65
static const GLuint VERT_SIZE
Size of a vertex in bytes.
Definition: gls_triangle_storage.h:60
unsigned int _numTriangles
Definition: gls_triangle_storage.h:140
void SetTexture(Image *image)
void Draw(IGlsStateManager *stateManager, const bool enableTexture)
void AddTriangle2D(const float x1, const float y1, const float x2, const float y2, const float x3, const float y3)
unsigned int _stripSize
Definition: gls_triangle_storage.h:141
unsigned int _vboHandle
Definition: gls_triangle_storage.h:151
Image * _texture
Definition: gls_triangle_storage.h:149
void Bake(IGlsStateManager *stateManager)
bool _stripified
Definition: gls_triangle_storage.h:154
Definition: gls_state_manager_interface.h:69
Definition: image.h:178
Definition: non_copyable.h:47
The disti::DynamicArray class. A templated array of objects capable of dynamically growing.
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
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.