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 
52 namespace disti
53 {
54 class Image;
55 
57 {
58 public:
59  /** Constant sizes of the primitive vertex attributes */
60  static const GLuint VERT_SIZE = sizeof( V2f );
61  static const GLuint TEX_SIZE = sizeof( V2f );
62 
63  /** Constant offsets to the primitive vertex attributes. */
64  static const GLuint VERT_OFFSET = 0;
65  static const GLuint TEX_COORD_OFFSET = VERT_SIZE;
66 
67  /** Default constructor
68  */
70 
71  /** Destructor
72  */
73  virtual ~GlsTriangleStrip2D();
74 
75  /** Sets this object into strip building mode. During strip building mode the user adds individual triangles to the strip
76  * When strip building mode is finished, the object will create a triangle strip from the individual triangles
77  * \pre none
78  * \post _stripified == false
79  */
80  void StartBuildingStrip();
81 
82  /** 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
83  * more than once after StartBuildingStrip() has been called.
84  * \pre _texture == NULL && _stripified == false
85  * \post _texture == img
86  * \param image The texture to assign, or NULL if no texture
87  */
88  void SetTexture( Image* image );
89 
90  /** Set the texture coordinates to be used for the next triangle that is added (or subsequent triangles if this is not called again
91  * \param x1 X coord of vertex 1
92  * \param y1 Y coord of vertex 1
93  * \param x2 X coord of vertex 2
94  * \param y2 Y coord of vertex 2
95  * \param x3 X coord of vertex 3
96  * \param y3 Y coord of vertex 3
97  * \pre _texture != NULL && _stripified == false
98  * \post _currentTex contains input values
99  */
100  void SetTexCoords( const float x1, const float y1, const float x2, const float y2, const float x3, const float y3 );
101 
102  /** Add the next triangle to the strip. Must be connected using previous two vertices of strip or be degenerate
103  * \param x1 X coord of vertex 1
104  * \param y1 Y coord of vertex 1
105  * \param x2 X coord of vertex 2
106  * \param y2 Y coord of vertex 2
107  * \param x3 X coord of vertex 3
108  * \param y3 Y coord of vertex 3
109  * \pre _stripified == false
110  * \post _numTriangles++, triangle is added to strip
111  */
112  void AddTriangle2D( const float x1, const float y1, const float x2, const float y2, const float x3, const float y3 );
113 
114  /** Finish building strip and bake it to a VBO
115  * \param stateManager StateManager object to issue GL commands to
116  * \pre _stripified == false
117  * \pre _stripified == true
118  */
119  void Bake( IGlsStateManager* stateManager );
120 
121  /** Draw the triangle strip
122  * \param stateManager StateManager object to issue GL commands to
123  * \param enableTexture True if strip will be drawn textured
124  * \pre _stripified == true
125  * \post The strip is drawn
126  */
127  void Draw( IGlsStateManager* stateManager, const bool enableTexture );
128 
129  /** Returns the number of triangles in this strip */
130  unsigned int GetNumTriangles()
131  {
132  return _numTriangles;
133  }
134 
135 protected:
136  unsigned int _numTriangles; /**< The number of triangles in the strip */
137  unsigned int _stripSize; /**< The number of vertices in the strip */
138 
139  DynamicArray<V2f_T2f, true> _vertData; /**< DynamicArray to store vertex and texture coordinates */
140  V2f _currentTex[ 3 ]; /**< Current texture coordinates supplied for current triangle
141  (Texture coordinates are not required to change per triangle)
142  Used only while building list.
143  */
144 
145  Image* _texture; /**< Texture to use when drawing strip. NULL if untextured */
146 
147  unsigned int _vboHandle; /**< VBO Handle for this triangle strip */
148  unsigned int _vboBufferSize; /**< Size of the VBO buffer. Cached to so that when a strip is cleared and reset
149  we will only reallocate the VBO when its size changes. */
150  bool _stripified; /**< True if triangles have been created into a strip */
151 
152  /** Allocate the next triangle in the set of ordered, connected triangles */
153  void AllocateNextTriangle();
154 
155  /** Convert the set of ordered, connected triangles in this object into tristrip
156  * \pre _stripified == false
157  * \pre _stripified == true
158  */
159  void Stripify();
160 };
161 
162 } // namespace disti
163 
164 #endif
Definition: gls_triangle_storage.h:56
unsigned int GetNumTriangles()
Definition: gls_triangle_storage.h:130
Definition: image.h:162
Definition: gls_primitive_storage_types.h:50
bool _stripified
Definition: gls_triangle_storage.h:150
The disti::V2f, disti::V2f_C4ub, disti::V3f_C4ub, disti::V2f_T2f_C4ub, and the disti::V2f_T2f structs...
void Draw(IGlsStateManager *stateManager, const bool enableTexture)
static const GLuint VERT_OFFSET
Definition: gls_triangle_storage.h:64
void Bake(IGlsStateManager *stateManager)
Definition: dynamic_array.h:62
The disti::DynamicArray class. A templated array of objects capable of dynamically growing...
unsigned int _vboHandle
Definition: gls_triangle_storage.h:147
A base class for objects that are not copyable via the standard C++ copy constructor.
void AddTriangle2D(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:148
void SetTexture(Image *image)
Definition: gls_state_manager_interface.h:66
The disti::GlsStateManager factory class. Creates an instance of a state manager that manages the GL ...
A file for all GL Studio files to include.
static const GLuint VERT_SIZE
Definition: gls_triangle_storage.h:60
DynamicArray< V2f_T2f, true > _vertData
Definition: gls_triangle_storage.h:139
unsigned int _stripSize
Definition: gls_triangle_storage.h:137
The disti::Vertex class. A class for manipulating 3D vertices.
void SetTexCoords(const float x1, const float y1, const float x2, const float y2, const float x3, const float y3)
V2f _currentTex[3]
Definition: gls_triangle_storage.h:140
Image * _texture
Definition: gls_triangle_storage.h:145
unsigned int _numTriangles
Definition: gls_triangle_storage.h:136
Definition: non_copyable.h:45
Definition: bmpimage.h:46
The gls_gl.