GL Studio C++ Runtime API
gls_geometry_resource.h
Go to the documentation of this file.
1/*! \file
2 \brief The disti::GlsGeometryResource 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
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.
38
39*/
40#ifndef GLS_GEOMETRY_RESOURCE_H_INCLUDED
41#define GLS_GEOMETRY_RESOURCE_H_INCLUDED
42
43#include "assert.h"
44
45#ifdef _WIN32
46# include <windows.h>
47#endif
48
49#ifdef LINUX
50# include <limits.h>
51#endif
52
53#ifdef GLES
54# include "gls_gl.h"
55# include "limits.h"
56#else
57# ifdef __APPLE__
58# include <OpenGL/gl.h>
59# else
60# include <GL/gl.h>
61# endif
62#endif
63
64#include "disti_assert.h"
65#include "gls_matrix_affine.h"
66#include "gls_render_effect.h"
67#include "gls_resource_file_mgr.h"
68#include "vertex.h"
69
70//////////////////// Provides support for creating DLLs ////////////////////////
71#if( defined( GLSGEN_EXPORT_GLSGEOMETRYRESOURCE ) || defined( GLSGEN_IMPORT_GLSGEOMETRYRESOURCE ) || defined( GLS_EXPORT_GENERATED ) || defined( GLS_IMPORT_GENERATED ) ) \
72 && defined( _MSC_VER )
73# if defined( GLSGEN_EXPORT_GLSGEOMETRYRESOURCE ) || defined( GLS_EXPORT_GENERATED )
74# define GLSGEN_GlsGeometryResource_EXPORT __declspec( dllexport )
75# else
76# define GLSGEN_GlsGeometryResource_EXPORT __declspec( dllimport )
77# endif
78#else
79# define GLSGEN_GlsGeometryResource_EXPORT
80#endif
81///////////////////////////////////////////////////////////////////////////////
82
83namespace disti
84{
85/** The geometry resource abstract base class */
87{
88public:
89 static const unsigned int MAX_TEXTURE_COORDS = 2; ///< GL_MAX_TEXTURE_COORDS. GlsGeometryResource currently only supports two sets of texture coordinates.
90 static const unsigned int MAX_VERTEX_ATTRIBS = 16; ///< GL_MAX_VERTEX_ATTRIBS.
91
92 static const unsigned int VERTEX_ATTRIBUTE_SIZE = 3 * sizeof( float ); ///< Size of vertex storage, in bytes.
93 static const unsigned int NORMAL_ATTRIBUTE_SIZE = 3 * sizeof( float ); ///< Size of normal storage, in bytes.
94 static const unsigned int COLOR_ATTRIBUTE_SIZE = 4 * sizeof( unsigned char ); ///< Size of color storage, in bytes.
95
96 static const unsigned int SECONDARY_COLOR_ATTRIBUTE_SIZE = 3 * sizeof( unsigned char ); ///< Size of secondary color storage, in bytes.
97 static const unsigned int TEXTURE_COORDINATE_ATTRIBUTE_SIZE = 2 * sizeof( float ); ///< Size of texture coordinate storage, in bytes.
98 static const unsigned int TANGENT_ATTRIBUTE_SIZE = 3 * sizeof( float ); ///< Size of tangent storage, in bytes.
99 static const unsigned int BINORMAL_ATTRIBUTE_SIZE = 3 * sizeof( float ); ///< Size of binormal storage, in bytes.
100
101 /// \details The TypeDesc class. Describes the underlying format of a GL vertex.
103 {
104 bool hasNormal; ///< True if vertices have normals (float[3]).
105 bool hasColor; ///< True if vertices have color (UINT32).
106 bool hasSecondaryColor; ///< True if vertices have secondary color (UINT32).
107#ifdef GLES
108 unsigned int normalType; ///< GL_FLOAT or GL_UNSIGNED_BYTE.
109 unsigned int texCoordType; ///< GL_FLOAT or GL_SHORT.
110#endif
111
112 unsigned char numTextureCoords; ///< Number of texture coordinates per vertex [0-MAX_TEXTURE_COORDS].
113 unsigned char texCoordDimension[ GlsGeometryResource::MAX_TEXTURE_COORDS ]; ///< Number of components for each texture coordinate.
114 unsigned char numVertexAttribs; ///< Number of generic vertex attributes per vertex [0-MAX_VERTEX_ATTRIBS].
115 GLint vertexAttribNumComponents[ GlsGeometryResource::MAX_VERTEX_ATTRIBS ]; ///< Number of components in the generic vertex attribute.
116 GLenum vertexAttribType[ GlsGeometryResource::MAX_VERTEX_ATTRIBS ]; ///< Specifies the type of each vertex attribute.
117 GLboolean vertexAttribNormalize[ GlsGeometryResource::MAX_VERTEX_ATTRIBS ]; ///< Specifies whether fixed-point data values should be normalized (GL_TRUE) or converted directly as fixed-point values (GL_FALSE) when they are accessed..
118 unsigned int vertexAttribSemantic[ GlsGeometryResource::MAX_VERTEX_ATTRIBS ]; ///< Semantic for each vertex attribute.
119 public:
120 // Default constructor
121 TypeDesc()
122 {
123 memset( this, 0, sizeof( TypeDesc ) );
124 unsigned int i;
125 for( i = 0; i < GlsGeometryResource::MAX_TEXTURE_COORDS; i++ )
126 {
127 texCoordDimension[ i ] = 2;
128 }
129 for( i = 0; i < GlsGeometryResource::MAX_VERTEX_ATTRIBS; i++ )
130 {
131 vertexAttribNumComponents[ i ] = 4;
132 }
133#ifdef GLES
134 normalType = GL_FLOAT;
135 texCoordType = GL_FLOAT;
136#endif
137 }
138
139 /// Set whether or not there should be storage for normals.
140 /// \param value The new normal storage flag.
141 void HasNormal( bool value ) { hasNormal = value; }
142
143 /// \return Whether or not this type stores normals.
144 bool HasNormal() const { return hasNormal; }
145
146#ifdef GLES
147 void NormalType( unsigned int value )
148 {
149 normalType = value;
150 }
151
152 unsigned int NormalType() const { return normalType; }
153
154 void TexCoordType( unsigned int value ) { texCoordType = value; }
155 unsigned int TexCoordType() const { return texCoordType; }
156#endif
157
158 /// Set whether or not there should be storage for colors.
159 /// \param value The new color storage flag.
160 void HasColor( bool value ) { hasColor = value; }
161
162 /// \return Whether or not this type stores colors.
163 bool HasColor() const { return hasColor; }
164
165 /// Set whether or not there should be storage for secondary colors.
166 /// \param value The new secondary color storage flag.
167 void HasSecondaryColor( bool value ) { hasSecondaryColor = value; }
168
169 /// \return Whether or not this type store secondary colors.
170 bool HasSecondaryColor() const { return hasSecondaryColor; }
171
172 /// Set the number of texture coordinates to be stored.
173 /// \param value The new number of texture coordinates to store.
174 void SetNumTextureCoords( unsigned char value )
175 {
177 {
178 numTextureCoords = value;
179 }
180 }
181
182 /// \return The number of texture coordinates stored.
183 unsigned char GetNumTextureCoords() const { return numTextureCoords; }
184
185 /// Set a component of a texture coordinate.
186 /// \param which 0 or 1
187 /// \param value 0 through 4
188 void SetTexCoordDimension( unsigned char which, unsigned char value )
189 {
190 if( which < GlsGeometryResource::MAX_TEXTURE_COORDS && value > 0 && value < 5 )
191 {
192 texCoordDimension[ which ] = value;
193 }
194 }
195
196 /// \return The component of a given texture coordinate (0 through 4).
197 /// \param which 0 or 1
198 unsigned char GetTexCoordDimension( unsigned char which ) const { return texCoordDimension[ which ]; }
199
200 /** Set the number of generic vertex attributes stored in the resource.
201 Generic vertex attributes are passed to OpenGL using glVertexAttribPointer.
202 These are special attributes to be used by the vertex shader.
203
204 \param value The new number of generic vertex attributes
205 \sa SetVertexAttribSizeBytes
206 */
207 void SetNumVertexAttribs( unsigned char value )
208 {
210 numVertexAttribs = value;
211 }
212
213 /// \return The number of vertex attributes.
214 unsigned char GetNumVertexAttribs() const { return numVertexAttribs; }
215
216 /// Set the size (number of components) in the generic vertex attribute.
217 /// See documentation on glVertexAttribPointer for details.
218 /// \param which The index of the attribute to set.
219 /// \param value The value to set at the attribute.
220 void SetVertexAttribComponents( unsigned char which, GLint value )
221 {
222 if( which < GlsGeometryResource::MAX_VERTEX_ATTRIBS && value > 0 && value < 5 )
223 vertexAttribNumComponents[ which ] = value;
224 }
225
226 /// \return The number of components of the given vertex attribute.
227 /// \param which The attribute in question.
228 GLint GetVertexAttribComponents( unsigned char which ) const { return vertexAttribNumComponents[ which ]; }
229
230 /// Set the type of a given generic vertex attribute.
231 /// See documentation on glVertexAttribPointer for details.
232 /// \param which The index of the attribute to set.
233 /// \param value The value to set at the attribute.
234 void SetVertexAttribType( unsigned char which, GLenum value )
235 {
237 {
238 vertexAttribType[ which ] = value;
239 }
240 }
241
242 /// \return The given vertex attribute.
243 /// \param which The index of the attribute.
244 GLenum GetVertexAttribType( unsigned char which ) const { return vertexAttribType[ which ]; }
245
246 /// Set whether fixed-point data values should be normalized (Default is false).
247 /// See documentation on glVertexAttribPointer for details.
248 /// \param which The index of the attribute to set.
249 /// \param value The value to set at the attribute.
250 void SetVertexAttribNormalize( unsigned char which, GLboolean value )
251 {
253 {
254 vertexAttribNormalize[ which ] = value;
255 }
256 }
257
258 /// \return The normalize flag for the given attribute.
259 /// \param which The index of the attribute.
260 GLboolean GetVertexAttribNormalize( unsigned char which ) const { return vertexAttribNormalize[ which ]; }
261
262 /// Set semantic of a given generic vertex attribute
263 /// The semantic value can be used to determine the "meaning" of the vertex attribute
264 /// \param which Which vertex attrib to set
265 /// \param semanticEnum The new sematic value (see AttributeSemanticEnum)
266 void SetVertexAttribSemantic( unsigned char which, int semanticEnum )
267 {
269 vertexAttribSemantic[ which ] = semanticEnum;
270 }
271
272 /// \return The semantic value for the given attribute index.
273 /// \param which The index of the attribute.
274 int GetVertexAttribSemantic( unsigned char which ) const { return vertexAttribSemantic[ which ]; }
275 };
276
277 /// Something that we can initialize the Resource ID to
278 /// and then check for to see if we have initialized the resource.
279 typedef enum
280 {
281 BAD_ID = 0xffffffff
282 } BadId;
283
284 virtual ~GlsGeometryResource() {}
285
286 /// \details The observer class is used for notifications when attributes that affect how the object would draw are changed
288 {
289 public:
290 /// Callback method to be called by this observer.
291 virtual void OnGeometryResourceChanged() = 0;
292
293 protected:
294 Observer() {}
295 virtual ~Observer() {}
296
297 private:
298 // Disable copying
299 Observer( const Observer& ) DISTI_SPECIAL_MEM_FUN_DELETE;
300 void operator=( const Observer& ) DISTI_SPECIAL_MEM_FUN_DELETE;
301 };
302
303 /// Adds a new observer to the list.
304 /// \param observer The new observer to add.
305 void AddObserver( Observer* observer )
306 {
307 _observers.PushBack( observer );
308 }
309
310 /// Removes the specified observer from the list.
311 /// \param observer The observer to remove.
312 void RemoveObserver( Observer* observer )
313 {
314 _observers.Erase( observer );
315 }
316
317protected:
318 DynamicArray<Observer*> _observers; ///< The held list of observers w/ callbacks.
319
320 /// Called to call all observer callbacks when the attribute changes.
322 {
323 for( unsigned int i = 0; i < _observers.Count(); ++i )
324 {
325 _observers[ i ]->OnGeometryResourceChanged();
326 }
327 }
328
329 /** Give this Resource a unique id so we can get it. */
330 unsigned int _resourceID;
331
332 /** The number of Parent Objects using this object. Once the number reaches zero, the object self deletes. */
333 unsigned int _referenceCount;
334
335 /** The TypeDesc that describes what is in this Resource */
337
338 /** The number of index buffers in this mesh */
339 unsigned int _numIndexBuffers;
340
341 Vector _boundingVolumeCenter; ///< Center location of the bounding volume.
342 float _boundingVolumeRadius; ///< Radius of the bounding volume.
343
344 // Shared between all instances
345 static bool _enableVBO; ///< If true, OpenGL supports vertex buffer objects (1.5 or greater).
346
347 /** Deletes this object from the heap that it was allocated on */
348 virtual void Destroy() = 0;
349
350public:
351 /// When enabled, GlsGeometryResource::CreateInstance will instantiate GlsGeometry_HalfFloat objects when possible.
352 /// \param value Whether or not to use half floats.
353 static GLSGEN_GlsGeometryResource_EXPORT void SetCreateInstanceMakesHalfFloat( bool value );
354
355 /// Construct an empty GlsGeometryResource with the given type.
356 /// The initial reference count is 1.
357 /// Call DecrementReference to free the resource when you are done with it.
358 /// \param type A description of the initial Structure.
359 /// \return A pointer to a new GlsGeometryResource.
360 static GLSGEN_GlsGeometryResource_EXPORT GlsGeometryResource* CreateInstance( const TypeDesc& type = GlsGeometryResource::TypeDesc() );
361
362 /// Construct a GlsGeometryResource from a binary resource.
363 /// The initial reference count is 1.
364 /// Call DecrementReference to free the GlsGeometryResource when you are done with it.
365 /// \param resource A pointer to a ResourceRef containing geometry data.
366 /// \return A pointer to a new GlsGeometryResource.
367 static GLSGEN_GlsGeometryResource_EXPORT GlsGeometryResource* CreateInstance( GlsResourceFileMgr::ResourceRef* resource );
368
369 /** Setup the OpenGL state for rendering this geometry.
370 To draw, call DrawIndexBuffer for each index buffer in the resource.
371 After drawing, call DrawCleanup to restore the OpenGL state.
372 \param shaderProgram interface to the shader program, used to lookup correct VertexAttrib index values (may be NULL)
373 \post The OpenGL state is configured for rendering from the index buffers.
374 */
375 virtual void DrawSetup( VertexAttribIndexLookup* shaderProgram ) = 0;
376
377 /** Draw the geometry specified by the given index buffer
378 This method should only be called between calls to DrawSetup
379 and DrawCleanup.
380 \pre DrawSetup has been called.
381 \param bufferNumber Which index buffer to draw
382 */
383 virtual void DrawIndexBuffer( unsigned int bufferNumber ) = 0;
384
385 /** Restore the OpenGL state after rendering.
386 \param shaderProgram Must be the same value that was passed to DrawSetup
387 \pre DrawSetup was called
388 \post The OpenGL state will be restored
389 */
390 virtual void DrawCleanup( VertexAttribIndexLookup* shaderProgram ) = 0;
391
392 /** Force the GlsGeometryResource to free any buffers it has allocated in the current OpenGL context.
393 */
394 virtual void FreeOpenGLBuffers() = 0;
395
396 /** Since calculating metrics like the extents can be an expensive operation, the user can call this
397 * function to see if the geometry resource has changed. Caching the expensive-to-calculate values
398 * is the responsibility of the caller.
399 * \return The current extents ID. Never equal to s_invalidDataChangedCounter.
400 * \sa s_invalidDataChangedCounter
401 */
402 virtual unsigned int GetDataChangedCounter() const = 0;
403
404 /** A sentinel value for clients to initialize their counts with. GetDataChangedCounter() will never return this value. */
405 static const unsigned int s_invalidDataChangedCounter = 0;
406
407 /** Calculate and return the geometry extents
408 * \param min Returns the minimum x,y,z values
409 * \param max Returns the maximum x,y,z values
410 * \param matrix (Optional) matrix to transform the vertices into the desired coordinate system
411 * \note This can be an expensive operation. GetDataChangedCounter() can be used to minimize this expense.
412 * \sa GetDataChangedCounter()
413 */
414 virtual void GetExtents( Vector& min, Vector& max, const GlsMatrixType* matrix = NULL ) = 0;
415
416 /** Updates the bounding volume of this object
417 * This method should be called if the vertices change for picking and
418 * culling to work correctly.
419 * \note This can be an expensive operation. GetDataChangedCounter() can be used to minimize this expense.
420 * \sa GetDataChangedCounter()
421 */
422 virtual void UpdateBoundingVolume() = 0;
423
424 /** Determines if the given ray hits the geometry bounding volume.
425 * Note: All parameters should be in this object's coordinates.
426 * @param point The starting point of the ray.
427 * @param direction The direction vector of the ray.
428 * @return True if this bounding volume is hit by the ray.
429 */
430 virtual bool BoundingVolumeHit( const Vector& point, const Vector& direction ) = 0;
431
432 /** Hit test the geometry against a picking line. All values are in geometry space.
433 * \param pickType The type of picking (see PickableType_e), must be PICK_FIRST or PICK_BEST
434 * \param pickLinePoint A point on the pick line.
435 * \param pickLineDirection The direction of the pick line.
436 * \param collisionPoint If the method returns true, this contains the point that was hit.
437 * \return true if the object was hit by the pick.
438 */
439 virtual bool HitTest( unsigned char pickType, const Vector& pickLinePoint, const Vector& pickLineDirection, Vector& collisionPoint ) = 0;
440
441 /// \return The vertex count for use in editor statistics.
442 /// \param bufferNumber The index of the buffer to count up.
443 virtual unsigned int StatsIndexBufferVertexCount( unsigned int bufferNumber ) = 0;
444
445 /// \return The polygon count for use in editor statistics.
446 /// \param bufferNumber The index of the buffer to count up.
447 virtual unsigned int StatsIndexBufferPolygonCount( unsigned int bufferNumber ) = 0;
448
449 /// \return The TypeDesc for this resource.
450 GLSGEN_GlsGeometryResource_EXPORT const TypeDesc& Type() { return _type; }
451
452 /** Increment the Reference count to this instance. */
453 GLSGEN_GlsGeometryResource_EXPORT void IncrementReference() { _referenceCount++; }
454
455 /** Decrement the Reference count to this instance.
456 * \note The OpenGL context should be available to free resources.
457 */
458 GLSGEN_GlsGeometryResource_EXPORT void DecrementReference()
459 {
461
463
464 if( _referenceCount == 0 )
465 {
466 Destroy();
467 }
468 }
469
470 /// \returns The number of index buffers in this geometry resource.
471 unsigned int NumIndexBuffers() const
472 {
473 return _numIndexBuffers;
474 }
475
476 /// \return The bounding sphere center.
478
479 /// \return The bounding sphere radius.
481
482 /** Sets a new resource ID
483 * \param id The new ID
484 * \pre id != BAD_ID
485 */
486 GLSGEN_GlsGeometryResource_EXPORT void SetResourceId( unsigned int id )
487 {
488 assert( BAD_ID != id );
489 _resourceID = id;
490 }
491
492 /// \return The current resource ID.
493 /// \pre _resourceID != BAD_ID
494 GLSGEN_GlsGeometryResource_EXPORT unsigned int GetResourceId()
495 {
496 assert( BAD_ID != _resourceID );
497 return _resourceID;
498 }
499};
500
501/** Forward declaration */
502class GlsGeometry_Generic_IndexBufferData;
503/** Flexible implementation of GlsGeometryResource that can store any type of geometry
504 * This resource is used in the editor and may be used at runtime if there is not a more efficient implementation for the desired TypeDesc.
505 */
507{
508public:
509 ////////////////////////////////
510 //
511 // GlsGeometryResource methods
512 //
513 ////////////////////////////////
514
515 virtual GLSGEN_GlsGeometryResource_EXPORT unsigned int StatsIndexBufferVertexCount( unsigned int bufferNumber ) DISTI_METHOD_OVERRIDE
516 {
517 return GetIndexBufferSize( bufferNumber ) / 3;
518 }
519
520 virtual GLSGEN_GlsGeometryResource_EXPORT unsigned int StatsIndexBufferPolygonCount( unsigned int bufferNumber ) DISTI_METHOD_OVERRIDE
521 {
522 return GetIndexBufferSize( bufferNumber );
523 }
524
525 virtual GLSGEN_GlsGeometryResource_EXPORT unsigned int GetDataChangedCounter() const DISTI_METHOD_OVERRIDE;
526 virtual GLSGEN_GlsGeometryResource_EXPORT void GetExtents( Vector& min, Vector& max, const GlsMatrixType* matrix = NULL ) DISTI_METHOD_OVERRIDE;
527 virtual GLSGEN_GlsGeometryResource_EXPORT void UpdateBoundingVolume() DISTI_METHOD_OVERRIDE;
528 virtual GLSGEN_GlsGeometryResource_EXPORT bool BoundingVolumeHit( const Vector& point, const Vector& direction ) DISTI_METHOD_OVERRIDE;
529 virtual GLSGEN_GlsGeometryResource_EXPORT bool HitTest( unsigned char pickType, const Vector& pickLinePoint, const Vector& pickLineDirection, Vector& collisionPoint ) DISTI_METHOD_OVERRIDE;
530 virtual GLSGEN_GlsGeometryResource_EXPORT void DrawSetup( VertexAttribIndexLookup* shaderProgram ) DISTI_METHOD_OVERRIDE;
531 virtual GLSGEN_GlsGeometryResource_EXPORT void DrawIndexBuffer( unsigned int bufferNumber ) DISTI_METHOD_OVERRIDE;
532 virtual GLSGEN_GlsGeometryResource_EXPORT void DrawCleanup( VertexAttribIndexLookup* shaderProgram ) DISTI_METHOD_OVERRIDE;
533 virtual GLSGEN_GlsGeometryResource_EXPORT void FreeOpenGLBuffers() DISTI_METHOD_OVERRIDE;
534
535 ////////////////////////////////
536 //
537 // GlsGeometry_Generic methods
538 //
539 ////////////////////////////////
540
541 /// Create GlsGeometry_Generic from TypeDesc.
542 /// \param type The storage format type to use.
543 /// \return The new geometry object.
544 static GLSGEN_GlsGeometryResource_EXPORT GlsGeometry_Generic* CreateInstance( const TypeDesc& type );
545
546 /// Construct a GlsGeometryResource from a binary resource
547 /// The initial reference count is 1.
548 /// Call DecrementReference to free the GlsGeometryResource when you are done with it.
549 /// \param resource pointer to a ResourceRef containing geometry data
550 /// \return The new geometry object.
551 static GLSGEN_GlsGeometryResource_EXPORT GlsGeometry_Generic* CreateInstance( GlsResourceFileMgr::ResourceRef* resource );
552
553 /// Create GlsGeometry_Generic from binary resource.
554 /// \param data The data to create object from.
555 /// \return The new geometry object.
556 static GLSGEN_GlsGeometryResource_EXPORT GlsGeometry_Generic* CreateFromBinaryResource( GlsResourceFileMgr::BinaryResource* data );
557
558 /// Create an empty GlsGeometry_Generic with default TypeDesc.
559 /// \return The new geometry object.
560 static GLSGEN_GlsGeometryResource_EXPORT GlsGeometry_Generic* CreateEmptyInstance();
561
562 /** Copy the geometry from another resource into this one.
563 Does not change the Type of this resource: only vertex attributes that both resources have in common will be copied.
564 \param rhs the resource to copy from
565 */
566 GLSGEN_GlsGeometryResource_EXPORT void CopyVertexAndIndexBuffers( GlsGeometry_Generic* rhs );
567
568 /** Changes the Type of this geometry resource.
569 This is a slow operation; it creates new storage according to the typeDesc and copys the existing vertex data.
570 If a vertex attribute does not map to the new type it will be lost. Any new attributes will be uninitialized.
571 Requires that the OpenGL context is current if this GlsGeometryResource has been previously drawn.
572
573 \param type The TypeDesc to use for the new structure
574 */
575 GLSGEN_GlsGeometryResource_EXPORT void ChangeType( const TypeDesc& type );
576
577 /** Attempt to Lock the Buffers, Non-Blocking
578 \return True if a lock is posible
579 */
580 GLSGEN_GlsGeometryResource_EXPORT bool LockBuffers();
581
582 /** Release the lock on the buffers.
583 Note: If the Vertex data was changed, you should typically call UpdateBoundingVolume() before unlocking.
584 \see UpdateBoundingVolume
585 \post If the buffer is not locked a debug message is sent to the terminal
586 */
587 GLSGEN_GlsGeometryResource_EXPORT void UnlockBuffers();
588
589 /** Get the size of the vertex buffer
590 \return The number of items in the vertex buffer
591 */
592 GLSGEN_GlsGeometryResource_EXPORT unsigned int VertexCount() const;
593
594 /** Set the size of the vertex buffer
595 \param count How many items the Vertex Buffer contains.
596 \pre size must be greater than zero
597 */
598 GLSGEN_GlsGeometryResource_EXPORT void VertexCount( unsigned int count );
599
600 /** Set a vertex
601 \param vertIndex The index of the vertex to change, 0 to VertexCount() - 1
602 \param *value Vertex can either be 3 or 4 floats depending on the type
603 \pre vertex must be a pointer to 3 or 4 floats, vertIndex must be less than VertexCount()
604 */
605 GLSGEN_GlsGeometryResource_EXPORT void SetVertex( GLuint vertIndex, const float* value );
606
607 /// Vector version of SetVertex().
608 /// \param vertIndex The index of the vertex to change, 0 to VertexCount() - 1.
609 /// \param value The Vector to set, uses its internal float array.
610 void SetVertex( GLuint vertIndex, const Vector* value ) { SetVertex( vertIndex, (float*)value ); }
611
612 /** Initialize the vertex data from an array of floats.
613
614 Steps through the array reading the data for each vertex. If Type() is POSITION_XYZ, the method will read 3 floats per vertex.
615 If Type() is POSITION_XYZW, the method will read 4 floats per vertex.
616
617 \param floatArray Pointer to the array to read from. The array must be at least (numVertices * stride) bytes.
618 \param numVertices Number of vertices to read from of the array
619 \param startVertIndex (optional) The vertex buffer index to start copying into
620 \param stride (optional) The distance between each vertex in the floatArray (in bytes)
621 */
622 GLSGEN_GlsGeometryResource_EXPORT void SetVertices( const float* floatArray,
623 unsigned int numVertices,
624 unsigned int startVertIndex = 0,
625 unsigned int stride = VERTEX_ATTRIBUTE_SIZE );
626
627 /** Set the vertex at a given index to a coordinate
628 \param vertIndex The index of the vertex to change, 0 to VertexCount() - 1
629 \param x The x-coord
630 \param y The y-coord
631 \param z The z-coord
632 \pre vertex must be a pointer to 3 or 4 floats, vertIndex must be less than VertexCount()
633 */
634 GLSGEN_GlsGeometryResource_EXPORT void SetVertex( GLuint vertIndex,
635 float x,
636 float y,
637 float z );
638
639 /** Return a pointer to an array of 3 or 4 floats which is the vertex
640 for the given index.
641
642 \param vertIndex The index of the vertex to get, 0 to VertexCount() - 1
643 \return a pointer to a 3 or 4 float vertex
644 \pre vertIndex must be less than VertexCount()
645 */
646 GLSGEN_GlsGeometryResource_EXPORT const float* GetVertex( GLuint vertIndex );
647
648 /** Set a Normal
649 \param vertIndex The index of the vertex to change, 0 to VertexCount() - 1
650 \param x X Normal value to assign
651 \param y Y Normal value to assign
652 \param z Z Normal value to assign
653 \pre normal must be a valid Vector, vertIndex must be less than VertexCount()
654 NORMAL must be part of the Type
655 */
656 GLSGEN_GlsGeometryResource_EXPORT void SetNormal( GLuint vertIndex, float x, float y, float z );
657
658 /** Initialize the vertex normals from an array of floats.
659
660 Steps through the array reading the normal data for each vertex. The method will read 3 floats for each normal.
661
662 \param floatArray Pointer to the array to read from. The array must be at least (numVertices * stride) bytes.
663 \param numVertices Number of vertices to read from of the array
664 \param startVertIndex (optional) The vertex buffer index to start copying into
665 \param stride (optional) The distance between each normal in the floatArray (in bytes)
666 */
667 GLSGEN_GlsGeometryResource_EXPORT void SetNormals( const float* floatArray,
668 unsigned int numVertices,
669 unsigned int startVertIndex = 0,
670 unsigned int stride = NORMAL_ATTRIBUTE_SIZE );
671
672 /** Get a pointer to the Normal for a given Vertex index. Do
673 not change the Normal, change it through the Set function!
674 \param vertIndex The index of the Normal to get, 0 to VertexCount() - 1
675 \return a pointer to an array of 3 floats.
676 \pre vertIndex must be less than VertexCount()
677 NORMAL must be part of the Type
678 */
679 GLSGEN_GlsGeometryResource_EXPORT const float* GetNormal( GLuint vertIndex );
680
681 /** Set a color value
682 \param vertIndex The index of the color value to change, 0 to VertexCount() - 1
683 \param red Red
684 \param green Green
685 \param blue Blue
686 \param alpha Alpha
687 */
688 GLSGEN_GlsGeometryResource_EXPORT void SetColor( GLuint vertIndex,
689 unsigned char red,
690 unsigned char green,
691 unsigned char blue,
692 unsigned char alpha );
693
694 /** Initialize the vertex colors from an array of unsigned int containing rgba color data.
695
696 Steps through the array reading the color data for each vertex. The method will read 1 integer for each color.
697
698 \param rgbaArray pointer to the array to read from. The array must be at least (numVertices * stride) bytes.
699 \param numVertices Number of vertices to read from of the array
700 \param startVertIndex (optional) The vertex buffer index to start copying into
701 \param stride (optional) The distance between each color in the rgbaArray (in bytes)
702 */
703 GLSGEN_GlsGeometryResource_EXPORT void SetColors( const unsigned int* rgbaArray,
704 unsigned int numVertices,
705 unsigned int startVertIndex = 0,
706 unsigned int stride = COLOR_ATTRIBUTE_SIZE );
707
708 /** Initialize Color from an array
709 \param array an array of color values in RGBA order of size VertexCount()
710 \pre The array must be of size VertexCount()
711 */
712 GLSGEN_GlsGeometryResource_EXPORT void SetColors( const unsigned int* array );
713
714 /** Gets the color value of the given vertex index
715 \param vertIndex The index of the color value to get, 0 to VertexCount() - 1
716 \return a pointer to a color array in rgba order
717 \pre vertIndex must be less than VertexCount(),
718 */
719 GLSGEN_GlsGeometryResource_EXPORT unsigned char* GetColor( GLuint vertIndex );
720
721 /** Set a secondary color value (specular)
722 \param red Red
723 \param green Green
724 \param blue Blue
725 \param vertIndex The index of the secondary color value to change, 0 to VertexCount() - 1
726 \pre vertIndex must be less than VertexCount()
727 */
728 GLSGEN_GlsGeometryResource_EXPORT void SetSecondaryColor( GLuint vertIndex,
729 unsigned char red,
730 unsigned char green,
731 unsigned char blue );
732
733 /** Initialize the vertex secondary colors from an array of unsigned int containing rgb color data. (Secondary colors do not include alpha)
734
735 Steps through the array reading the color data for each vertex. The method will read 3 bytes for each color.
736
737 \param rgbArray pointer to the array to read from. The array must be at least (numVertices * stride) bytes.
738 \param numVertices Number of vertices to read from of the array
739 \param startVertIndex (optional) The vertex buffer index to start copying into
740 \param stride (optional) The distance between each color in the array (in bytes)
741 */
742 GLSGEN_GlsGeometryResource_EXPORT void SetSecondaryColors( const unsigned int* rgbArray,
743 unsigned int numVertices,
744 unsigned int startVertIndex = 0,
745 unsigned int stride = SECONDARY_COLOR_ATTRIBUTE_SIZE );
746
747 /** Get the secondary color of the vertex at the given index.
748 \param vertIndex The index of the secondary color value to get, 0 to VertexCount() - 1
749 \return a pointer to a secondary color value in RGB order
750 \pre vertIndex must be less than VertexCount()
751 */
752 GLSGEN_GlsGeometryResource_EXPORT unsigned char* GetSecondaryColor( GLuint vertIndex );
753
754 /** Set a TextureCoord
755 \param textureCoord TextureCoord value to assign. Must point to a float array containing TextureCoordinateDepth() elements
756 \param vertIndex The index of the TextureCoord value to change, 0 to VertexCount() - 1
757 \param whichTexture Which set of texture coordinates to change, 0 to NumTextureCoordinateArrays() - 1.
758 \pre vertIndex must be less than VertexCount()
759 TEXCOORD must be part of the Type
760 whichTexture must be 0 to 7
761 */
762 GLSGEN_GlsGeometryResource_EXPORT void SetTextureCoord( GLuint vertIndex, unsigned int whichTexture, const float* textureCoord );
763
764 /// Two float version of SetTextureCoord().
765 /// \param vertIndex The index of the TextureCoord value to change, 0 to VertexCount() - 1.
766 /// \param whichTexture Which set of texture coordinates to change, 0 to NumTextureCoordinateArrays() - 1.
767 /// \param textureCoordU The new U coordinate to set.
768 /// \param textureCoordV The new V coordinate to set.
769 GLSGEN_GlsGeometryResource_EXPORT void SetTextureCoord( GLuint vertIndex, unsigned int whichTexture, float textureCoordU, float textureCoordV );
770
771#ifdef GLES
772 /** Sets all texture coordinates from a pointer of texture coordinate data
773
774 \param whichTexture Which set of texture coordinates to change, 0 to NumTextureCoordinateArrays() - 1.
775 \param textureCoordArray Pointer to texture coordinate data to assign. Must point to a float array containing TextureCoordinateDepth() elements
776 \param numVertices The number of vertices worth of texture coordinate data in the array
777 \param startIndex (optional) The texture coord vertex element to start copying into
778 \param stride (optional) The distance between each texture coordinate in the array (in bytes)
779 */
780 GLSGEN_GlsGeometryResource_EXPORT void SetTextureCoords( unsigned int whichTexture,
781 const float* textureCoordArray,
782 unsigned int numVertices,
783 unsigned int startVertIndex = 0,
784 unsigned int stride = TEXTURE_COORDINATE_ATTRIBUTE_SIZE );
785#endif
786
787 /** Get a TextureCoord
788 \param vertIndex The index of the TextureCoord value to change, 0 to VertexCount() - 1
789 \param whichTexture Which set of texture coordinates to change, 0 to NumTextureCoordinateArrays() - 1.
790 \return Return a pointer to the Texture Coordinates ask for
791 \pre vertIndex must be less than VertexCount()
792 TEXCOORD must be part of the Type
793 textureCount must be 1 to 8
794 */
795 GLSGEN_GlsGeometryResource_EXPORT const float* GetTextureCoord( GLuint vertIndex, unsigned int whichTexture );
796
797 /** Store a generic vertex attribute value
798 \param vertIndex The index of the vertex
799 \param attribIndex The index of the generic vertex attribute to be modified
800 \param value void pointer to the value
801 \param sizeBytes size of the value in bytes
802 */
803 GLSGEN_GlsGeometryResource_EXPORT void StoreVertexAttrib( GLuint vertIndex, GLuint attribIndex, void* value, GLuint sizeBytes );
804
805 /// One float version of StoreVertexAttrib().
806 /// \param vertIndex The index of the vertex.
807 /// \param attribIndex The index of the generic vertex attribute to be modified.
808 /// \param v A pointer to an array of floats.
809 void SetVertexAttrib1fv( GLuint vertIndex, GLuint attribIndex, const GLfloat* v ) { StoreVertexAttrib( vertIndex, attribIndex, (void*)v, 1 * sizeof( float ) ); }
810
811 /// Two float version of StoreVertexAttrib().
812 /// \param vertIndex The index of the vertex.
813 /// \param attribIndex The index of the generic vertex attribute to be modified.
814 /// \param v A pointer to an array of floats.
815 void SetVertexAttrib2fv( GLuint vertIndex, GLuint attribIndex, const GLfloat* v ) { StoreVertexAttrib( vertIndex, attribIndex, (void*)v, 2 * sizeof( float ) ); }
816
817 /// Three float version of StoreVertexAttrib().
818 /// \param vertIndex The index of the vertex.
819 /// \param attribIndex The index of the generic vertex attribute to be modified.
820 /// \param v A pointer to an array of floats.
821 void SetVertexAttrib3fv( GLuint vertIndex, GLuint attribIndex, const GLfloat* v ) { StoreVertexAttrib( vertIndex, attribIndex, (void*)v, 3 * sizeof( float ) ); }
822
823 /// Four float version of StoreVertexAttrib().
824 /// \param vertIndex The index of the vertex.
825 /// \param attribIndex The index of the generic vertex attribute to be modified.
826 /// \param v A pointer to an array of floats.
827 void SetVertexAttrib4fv( GLuint vertIndex, GLuint attribIndex, const GLfloat* v ) { StoreVertexAttrib( vertIndex, attribIndex, (void*)v, 4 * sizeof( float ) ); }
828
829#ifdef GLES
830 GLSGEN_GlsGeometryResource_EXPORT void SetVertexAttribs( const float* attribArray,
831
832 GLuint attribIndex,
833 unsigned int numVertices,
834 unsigned int startVertIndex = 0,
835 unsigned int stride = TANGENT_ATTRIBUTE_SIZE );
836#endif
837
838 /// Get pointer to the raw vertex attribute data, be careful with this!
839 /// \note This method may be removed in the future.
840 /// \param vertIndex The index of the vertex.
841 /// \param attribIndex The index of the generic vertex attribute.
842 /// \return A pointer to raw data.
843 GLSGEN_GlsGeometryResource_EXPORT void* GetVertexAttrib( GLuint vertIndex, GLuint attribIndex );
844
846
847 /** Get the number of available index buffers
848 * \param count Set the number of index buffers in this geometry resource.
849 */
850 GLSGEN_GlsGeometryResource_EXPORT void NumIndexBuffers( unsigned int count );
851
852 /** Gets the size of an index buffer
853 \param bufferNum Which index buffer to return the size of
854 \return The number of items that the given index buffer can hold
855 */
856 GLSGEN_GlsGeometryResource_EXPORT unsigned int GetIndexBufferSize( unsigned int bufferNum ) const;
857
858 /** Set the size of the specified index buffer
859 \param bufferNum Which index buffer to set the size of
860 \param newSize How many items the Index Buffer can hold.
861 \pre newSize must be greater than zero
862 */
863 GLSGEN_GlsGeometryResource_EXPORT void SetIndexBufferSize( unsigned int bufferNum, unsigned int newSize );
864
865 /** Change the Vertex index
866 \param bufferNum Which index buffer to modify
867 \param index The index of the Index to change, 0 to GetIndexBufferSize(bufferNum)) - 1
868 \param indexValue Index must be less than GetIndexBufferSize(bufferNum)
869 */
870 GLSGEN_GlsGeometryResource_EXPORT void SetIndex( unsigned int bufferNum, unsigned int index, unsigned int indexValue );
871
872#ifndef GLES
873
874 /** Initialize the Index buffer from an array of index values
875 *
876 * Steps through the array reading the color data for each vertex. The method will read 3 bytes for each color.
877 *
878 * \param bufferNum Which index buffer to modify
879 * \param indexArray pointer to the array to read from. The array must be at least (numIndices * stride) bytes.
880 * \param numIndices Number of indices to read from of the array
881 * \param startIndex (optional) The index buffer element to start copying into
882 * \param stride (optional) The distance between each index in the array (in bytes)
883 */
884 GLSGEN_GlsGeometryResource_EXPORT void SetIndices( unsigned int bufferNum,
885 const unsigned int* indexArray,
886 unsigned int numIndices,
887 unsigned int startIndex = 0,
888 unsigned int stride = sizeof( unsigned int ) );
889
890 /** Gets an index from an index buffer
891 \param bufferNum Which index buffer to read from
892 \param index The index of the Index to get, 0 to GetIndexBufferSize(bufferNum) - 1
893 \return an Index value
894 \pre index must be less than GetIndexBufferSize(bufferNum)
895 */
896 GLSGEN_GlsGeometryResource_EXPORT unsigned int GetIndex( unsigned int bufferNum, unsigned int index );
897
898 /// Merge two index buffers by adding the indexes from the source buffer to the dest buffer,
899 /// then deleting the source buffer.
900 /// \param dstBufferNum Which index buffer to add to.
901 /// \param srcBufferNum Which index buffer to delete.
902 GLSGEN_GlsGeometryResource_EXPORT void MergeIndexBuffers( unsigned int dstBufferNum, unsigned int srcBufferNum );
903
904#else // GLES
905
906 /** Initialize the Index buffer from an array of index values
907
908 Steps through the array reading the color data for each vertex. The method will read 3 bytes for each color.
909
910 \param bufferNum Which index buffer to modify
911 \param indexArray pointer to the array to read from. The array must be at least (numIndices * stride) bytes.
912 \param numIndices Number of indices to read from of the array
913 \param startIndex (optional) The index buffer element to start copying into
914 \param stride (optional) The distance between each index in the array (in bytes)
915 */
916 GLSGEN_GlsGeometryResource_EXPORT void SetIndices( unsigned int bufferNum,
917 const unsigned int* indexArray,
918 unsigned int numIndices,
919 unsigned int startIndex = 0,
920 unsigned int stride = sizeof( unsigned int ) );
921
922 /** Get an index from an index buffer
923 \param bufferNum Which index buffer to read from
924 \param index The index of the Index to get, 0 to GetIndexBufferSize(bufferNum) - 1
925 \return an Index value
926 \pre index must be less than GetIndexBufferSize(bufferNum)
927 */
928 GLSGEN_GlsGeometryResource_EXPORT unsigned short GetIndex( unsigned int bufferNum, unsigned short index );
929
930#endif // !GLES
931
932 /** See GlsGeometryResource::VertexSort() */
933 typedef struct
934 {
935 unsigned int _order; ///< The order the vertex should be in.
936 unsigned int _vertexTupleIndex; ///< The index of the primitive.
938
939 /** Sort the vertices, based on the input data
940
941 \param *sortData An array of VertexSortData structures, one for each primitive (set of three vertices).
942 The data in this is array is used to reorder the primitives. e.g.:
943 Input:
944 order 0,1,0,5,2
945 index 0,1,2,3,4
946 Sorted:
947 order 0,0,1,2,5
948 index 0,2,1,4,3
949
950 \pre sortData must be an array of VertexSortData VertexCount()/3 in size
951
952 \post The sortData array will be sorted based on _order.
953 The vertex buffer will be sorted based on the new order from the sortData.
954 */
955 GLSGEN_GlsGeometryResource_EXPORT void VertexSort( VertexSortData* sortData );
956
957 /** Dump all the vertices to the terminal
958 */
959 GLSGEN_GlsGeometryResource_EXPORT void DumpVertices();
960
961 /** Dump all the Normals to the terminal
962 */
963 GLSGEN_GlsGeometryResource_EXPORT void DumpNormals();
964
965 /** Dump all the Indices to the terminal
966 */
967 GLSGEN_GlsGeometryResource_EXPORT void DumpIndices();
968
969 /** Copy vertex attributes from srcGeom to dstGeom
970 Does not change the Type of the resource: only vertex attributes that both resources have in common will be copied.
971 \param dstGeom the resource to copy to
972 \param dstOffset vertex offset to start copying at
973 \param srcGeom the resource to copy from
974 \param srcOffset vertex offset to start copying from
975 \param vertexCount number of vertices to copy
976 \returns the number of vertices that were copied
977 */
978 static GLSGEN_GlsGeometryResource_EXPORT unsigned int CopyVertexData(
979 GlsGeometry_Generic* dstGeom, unsigned int dstOffset,
980 GlsGeometry_Generic* srcGeom, unsigned int srcOffset,
981 unsigned int vertexCount );
982
983 /// Apply a transform to the vertex attributes of the given mesh
984 /// The transform affects vertex position, normals, ATTRIB_TANGENT, and ATTRIB_BINORMAL
985 /// \param dstGeom The resource to modify.
986 /// \param transform The matrix used to convert vertex attributes.
987 /// \param vertexOffset Start of the range of verts to transform.
988 /// \param vertexCount Number of verts to transform.
989 /// \return The number of verts that were transformed.
990 static GLSGEN_GlsGeometryResource_EXPORT unsigned int TransformVertexData(
991 GlsGeometry_Generic* dstGeom,
992 GlsMatrixType* transform,
993 unsigned int vertexOffset = 0,
994 unsigned int vertexCount = UINT_MAX );
995
996 /// Generate tangents/binormals for all vertices in the given
997 /// GlsGeometryResource and adds them as vertex attributes.
998 /// \param geom The vertices to generate from.
999 /// \return Whether or not the generation was successful.
1000 static GLSGEN_GlsGeometryResource_EXPORT bool GenerateTangentsAndBinormals( GlsGeometry_Generic* geom );
1001
1002 /// \details The VertexStructureDefinition struct. Contains stride and attribute information associated with a vertex buffer object.
1003 typedef struct
1004 {
1005 unsigned int _size; ///< Total size of each vertex in bytes (depends on which data is included).
1006
1007 unsigned int _normalStride; ///< Offset between each normal in bytes.
1008 unsigned int _texcoordStride; ///< Offset between each texture coordinate in bytes.
1009 unsigned int _texcoord2Stride; ///< Offset between each secondary texture coordinate in bytes.
1010 unsigned int _colorStride; ///< Offset between each color in bytes.
1011 unsigned int _secondaryColorStride; ///< Offset between each secondary color in bytes.
1012 unsigned int _numVertexAttribs; ///< The count of vertex attributes.
1013 unsigned int _vertexAttribStride[ MAX_VERTEX_ATTRIBS ]; ///< A list of offsets in bytes for each vertex attribute.
1014 unsigned int _vertexAttribSize[ MAX_VERTEX_ATTRIBS ]; ///< The size of each vertex attribute in bytes.
1016
1017 /// Return the appropriate VertexStructureDefinition type derived from the incoming TypeDesc.
1018 /// \param vertStruct The returned vertex structure.
1019 /// \param type The type to generate a vertex structure definiton for.
1020 static GLSGEN_GlsGeometryResource_EXPORT void SetVertexStructureFromTypeDesc( VertexStructureDefinition& vertStruct, const TypeDesc& type );
1021
1022protected:
1023 bool _bufferLock; ///< Flag indicating that the vertex buffer is being written to.
1024
1025 char* _vertexBuffer; ///< Underlying storage for vertices.
1026 unsigned int _vertexBufferCount; ///< The number of vertices in the buffer.
1027 GLuint _vertexBufferID; ///< The OpenGL index for this vertex buffer object.
1028 bool _vertexBufferUpdated; ///< Is the video card vertex buffer up to date?
1029
1030 /** Index buffers array */
1031 GlsGeometry_Generic_IndexBufferData* _indexBuffers;
1032
1033 VertexStructureDefinition _structure; ///< Describes the internal storage pattern for vertices, i.e. does it have colors? textures? normals?
1034
1035 /// Copies vertex data from this buffer into the incoming geometry object.
1036 /// \param rhs The object to copy vertex data into.
1037 GLSGEN_GlsGeometryResource_EXPORT void CopyVertexBufferOnly( GlsGeometry_Generic* rhs );
1038
1039 /** Utility routine used by Hit. Performs a "BestHit" test, which performs a hit test on the object
1040 * and guarantees that the collision point returned by Hit is the closest collision point to the observer.
1041 * @param point The geometry coordinate of the click, relative to the object
1042 * @param directionVector The direction of the pick vector
1043 * @param collisionPoint Set to the point on the object hit by directionVector
1044 * @return booleanean indicating if the object was hit by the mouse
1045 */
1046 GLSGEN_GlsGeometryResource_EXPORT bool BestHit( const Vector& point, const Vector& directionVector, Vector& collisionPoint );
1047
1048 /** Utility routine used by Hit. Performs a "FirstHit" test, which performs a hit test on the object
1049 * but does not guarantee that the collision point returned by Hit is the closest collision point
1050 * to the observer
1051 * @param point The logical coordinate of the click, relative to the object
1052 * @param directionVector The direction of the pick vector
1053 * @param collisionPoint Set to the point on the object hit by directionVector
1054 * @return boolean indicating if the object was hit
1055 */
1056 GLSGEN_GlsGeometryResource_EXPORT bool FirstHit( const Vector& point, const Vector& directionVector, Vector& collisionPoint );
1057
1058 /// Shared initialization code used by all constructors.
1060
1061 /// Initialize this object from the incoming binary resource.
1062 /// \param resource The binary resource to initialize with.
1064
1065 /// \return The offset in bytes for the given texture index.
1066 /// \param whichTexture The texture index to locate.
1067 unsigned int GetTexcoordByteOffset( unsigned int whichTexture );
1068
1069 GLSGEN_GlsGeometryResource_EXPORT void Destroy() DISTI_METHOD_OVERRIDE;
1070
1071private:
1072 // Member data
1073 unsigned int _dataChangedCounter;
1074
1075 /** Should be called when any data changes. Used to optimize calls like GetExtents(). */
1076 void IncDataChangedCounter()
1077 {
1078 // If we hit the invalid ID, skip past it.
1079 if( ++_dataChangedCounter == s_invalidDataChangedCounter )
1080 {
1081 ++_dataChangedCounter;
1082 }
1083 }
1084
1085 /** Private Constructor: Use CreateInstance methods */
1086 GLSGEN_GlsGeometryResource_EXPORT GlsGeometry_Generic();
1087
1088 /** Private Destructor: Use DecrementReference to delete the object*/
1089 GLSGEN_GlsGeometryResource_EXPORT ~GlsGeometry_Generic();
1090
1091 // Disable implicit generated Members
1093 GlsGeometry_Generic& operator=( const GlsGeometry_Generic& rhs );
1094};
1095
1096} // namespace disti
1097
1098#endif
Definition: dynamic_array.h:79
Definition: gls_geometry_resource.h:288
virtual void OnGeometryResourceChanged()=0
Callback method to be called by this observer.
Definition: gls_geometry_resource.h:103
void SetVertexAttribComponents(unsigned char which, GLint value)
Definition: gls_geometry_resource.h:220
bool HasColor() const
Definition: gls_geometry_resource.h:163
int GetVertexAttribSemantic(unsigned char which) const
Definition: gls_geometry_resource.h:274
bool HasNormal() const
Definition: gls_geometry_resource.h:144
void SetVertexAttribType(unsigned char which, GLenum value)
Definition: gls_geometry_resource.h:234
unsigned char GetTexCoordDimension(unsigned char which) const
Definition: gls_geometry_resource.h:198
void SetNumVertexAttribs(unsigned char value)
Definition: gls_geometry_resource.h:207
void HasSecondaryColor(bool value)
Definition: gls_geometry_resource.h:167
void SetVertexAttribNormalize(unsigned char which, GLboolean value)
Definition: gls_geometry_resource.h:250
GLenum GetVertexAttribType(unsigned char which) const
Definition: gls_geometry_resource.h:244
void SetVertexAttribSemantic(unsigned char which, int semanticEnum)
Definition: gls_geometry_resource.h:266
GLboolean GetVertexAttribNormalize(unsigned char which) const
Definition: gls_geometry_resource.h:260
void HasColor(bool value)
Definition: gls_geometry_resource.h:160
GLint GetVertexAttribComponents(unsigned char which) const
Definition: gls_geometry_resource.h:228
void HasNormal(bool value)
Definition: gls_geometry_resource.h:141
unsigned char GetNumTextureCoords() const
Definition: gls_geometry_resource.h:183
unsigned char GetNumVertexAttribs() const
Definition: gls_geometry_resource.h:214
void SetTexCoordDimension(unsigned char which, unsigned char value)
Definition: gls_geometry_resource.h:188
bool HasSecondaryColor() const
Definition: gls_geometry_resource.h:170
void SetNumTextureCoords(unsigned char value)
Definition: gls_geometry_resource.h:174
Definition: gls_geometry_resource.h:87
static const unsigned int VERTEX_ATTRIBUTE_SIZE
Size of vertex storage, in bytes.
Definition: gls_geometry_resource.h:92
void OnGeometryResourceChanged()
Called to call all observer callbacks when the attribute changes.
Definition: gls_geometry_resource.h:321
DynamicArray< Observer * > _observers
The held list of observers w/ callbacks.
Definition: gls_geometry_resource.h:318
unsigned int GetResourceId()
Definition: gls_geometry_resource.h:494
virtual void GetExtents(Vector &min, Vector &max, const GlsMatrixType *matrix=NULL)=0
unsigned int _numIndexBuffers
Definition: gls_geometry_resource.h:339
virtual unsigned int StatsIndexBufferPolygonCount(unsigned int bufferNumber)=0
static const unsigned int TANGENT_ATTRIBUTE_SIZE
Size of tangent storage, in bytes.
Definition: gls_geometry_resource.h:98
const TypeDesc & Type()
Definition: gls_geometry_resource.h:450
static const unsigned int NORMAL_ATTRIBUTE_SIZE
Size of normal storage, in bytes.
Definition: gls_geometry_resource.h:93
float _boundingVolumeRadius
Radius of the bounding volume.
Definition: gls_geometry_resource.h:342
void DecrementReference()
Definition: gls_geometry_resource.h:458
virtual unsigned int StatsIndexBufferVertexCount(unsigned int bufferNumber)=0
virtual unsigned int GetDataChangedCounter() const =0
void RemoveObserver(Observer *observer)
Definition: gls_geometry_resource.h:312
static const unsigned int TEXTURE_COORDINATE_ATTRIBUTE_SIZE
Size of texture coordinate storage, in bytes.
Definition: gls_geometry_resource.h:97
void SetResourceId(unsigned int id)
Definition: gls_geometry_resource.h:486
virtual bool BoundingVolumeHit(const Vector &point, const Vector &direction)=0
void AddObserver(Observer *observer)
Definition: gls_geometry_resource.h:305
virtual bool HitTest(unsigned char pickType, const Vector &pickLinePoint, const Vector &pickLineDirection, Vector &collisionPoint)=0
virtual void Destroy()=0
void IncrementReference()
Definition: gls_geometry_resource.h:453
Vector _boundingVolumeCenter
Center location of the bounding volume.
Definition: gls_geometry_resource.h:341
static const unsigned int s_invalidDataChangedCounter
Definition: gls_geometry_resource.h:405
static const unsigned int MAX_TEXTURE_COORDS
GL_MAX_TEXTURE_COORDS. GlsGeometryResource currently only supports two sets of texture coordinates.
Definition: gls_geometry_resource.h:89
static GlsGeometryResource * CreateInstance(const TypeDesc &type=GlsGeometryResource::TypeDesc())
virtual void DrawSetup(VertexAttribIndexLookup *shaderProgram)=0
unsigned int NumIndexBuffers() const
Definition: gls_geometry_resource.h:471
virtual void DrawCleanup(VertexAttribIndexLookup *shaderProgram)=0
virtual void FreeOpenGLBuffers()=0
static bool _enableVBO
If true, OpenGL supports vertex buffer objects (1.5 or greater).
Definition: gls_geometry_resource.h:345
virtual void UpdateBoundingVolume()=0
TypeDesc _type
Definition: gls_geometry_resource.h:336
BadId
Definition: gls_geometry_resource.h:280
virtual void DrawIndexBuffer(unsigned int bufferNumber)=0
unsigned int _resourceID
Definition: gls_geometry_resource.h:330
static const unsigned int MAX_VERTEX_ATTRIBS
GL_MAX_VERTEX_ATTRIBS.
Definition: gls_geometry_resource.h:90
static const unsigned int SECONDARY_COLOR_ATTRIBUTE_SIZE
Size of secondary color storage, in bytes.
Definition: gls_geometry_resource.h:96
static const unsigned int COLOR_ATTRIBUTE_SIZE
Size of color storage, in bytes.
Definition: gls_geometry_resource.h:94
const Vector & BoundingVolumeCenter() const
Definition: gls_geometry_resource.h:477
unsigned int _referenceCount
Definition: gls_geometry_resource.h:333
static void SetCreateInstanceMakesHalfFloat(bool value)
static const unsigned int BINORMAL_ATTRIBUTE_SIZE
Size of binormal storage, in bytes.
Definition: gls_geometry_resource.h:99
float BoundingVolumeRadius() const
Definition: gls_geometry_resource.h:480
Definition: gls_geometry_resource.h:507
void SetColor(GLuint vertIndex, unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
unsigned int GetIndexBufferSize(unsigned int bufferNum) const
void InitializeMembers()
Shared initialization code used by all constructors.
virtual unsigned int StatsIndexBufferPolygonCount(unsigned int bufferNumber) DISTI_METHOD_OVERRIDE
Definition: gls_geometry_resource.h:520
virtual void DrawCleanup(VertexAttribIndexLookup *shaderProgram) DISTI_METHOD_OVERRIDE
void SetIndices(unsigned int bufferNum, const unsigned int *indexArray, unsigned int numIndices, unsigned int startIndex=0, unsigned int stride=sizeof(unsigned int))
void SetIndex(unsigned int bufferNum, unsigned int index, unsigned int indexValue)
GLuint _vertexBufferID
The OpenGL index for this vertex buffer object.
Definition: gls_geometry_resource.h:1027
VertexStructureDefinition _structure
Describes the internal storage pattern for vertices, i.e. does it have colors? textures?...
Definition: gls_geometry_resource.h:1033
void SetVertexAttrib4fv(GLuint vertIndex, GLuint attribIndex, const GLfloat *v)
Definition: gls_geometry_resource.h:827
static unsigned int TransformVertexData(GlsGeometry_Generic *dstGeom, GlsMatrixType *transform, unsigned int vertexOffset=0, unsigned int vertexCount=UINT_MAX)
bool BestHit(const Vector &point, const Vector &directionVector, Vector &collisionPoint)
virtual void DrawIndexBuffer(unsigned int bufferNumber) DISTI_METHOD_OVERRIDE
void MergeIndexBuffers(unsigned int dstBufferNum, unsigned int srcBufferNum)
static bool GenerateTangentsAndBinormals(GlsGeometry_Generic *geom)
void SetNormal(GLuint vertIndex, float x, float y, float z)
unsigned char * GetColor(GLuint vertIndex)
void ChangeType(const TypeDesc &type)
unsigned char * GetSecondaryColor(GLuint vertIndex)
virtual bool HitTest(unsigned char pickType, const Vector &pickLinePoint, const Vector &pickLineDirection, Vector &collisionPoint) DISTI_METHOD_OVERRIDE
void SetVertexAttrib1fv(GLuint vertIndex, GLuint attribIndex, const GLfloat *v)
Definition: gls_geometry_resource.h:809
void CopyVertexBufferOnly(GlsGeometry_Generic *rhs)
virtual unsigned int GetDataChangedCounter() const DISTI_METHOD_OVERRIDE
const float * GetNormal(GLuint vertIndex)
const float * GetVertex(GLuint vertIndex)
void SetVertices(const float *floatArray, unsigned int numVertices, unsigned int startVertIndex=0, unsigned int stride=VERTEX_ATTRIBUTE_SIZE)
void VertexSort(VertexSortData *sortData)
void SetVertex(GLuint vertIndex, const Vector *value)
Definition: gls_geometry_resource.h:610
char * _vertexBuffer
Underlying storage for vertices.
Definition: gls_geometry_resource.h:1025
bool FirstHit(const Vector &point, const Vector &directionVector, Vector &collisionPoint)
void SetVertex(GLuint vertIndex, const float *value)
void * GetVertexAttrib(GLuint vertIndex, GLuint attribIndex)
void SetColors(const unsigned int *rgbaArray, unsigned int numVertices, unsigned int startVertIndex=0, unsigned int stride=COLOR_ATTRIBUTE_SIZE)
void SetSecondaryColors(const unsigned int *rgbArray, unsigned int numVertices, unsigned int startVertIndex=0, unsigned int stride=SECONDARY_COLOR_ATTRIBUTE_SIZE)
virtual void GetExtents(Vector &min, Vector &max, const GlsMatrixType *matrix=NULL) DISTI_METHOD_OVERRIDE
static GlsGeometry_Generic * CreateInstance(const TypeDesc &type)
static unsigned int CopyVertexData(GlsGeometry_Generic *dstGeom, unsigned int dstOffset, GlsGeometry_Generic *srcGeom, unsigned int srcOffset, unsigned int vertexCount)
unsigned int _vertexBufferCount
The number of vertices in the buffer.
Definition: gls_geometry_resource.h:1026
const float * GetTextureCoord(GLuint vertIndex, unsigned int whichTexture)
static void SetVertexStructureFromTypeDesc(VertexStructureDefinition &vertStruct, const TypeDesc &type)
unsigned int NumIndexBuffers() const
Definition: gls_geometry_resource.h:471
virtual bool BoundingVolumeHit(const Vector &point, const Vector &direction) DISTI_METHOD_OVERRIDE
void SetTextureCoord(GLuint vertIndex, unsigned int whichTexture, const float *textureCoord)
void InitFromBinaryResource(GlsResourceFileMgr::BinaryResource *resource)
void SetVertexAttrib3fv(GLuint vertIndex, GLuint attribIndex, const GLfloat *v)
Definition: gls_geometry_resource.h:821
virtual unsigned int StatsIndexBufferVertexCount(unsigned int bufferNumber) DISTI_METHOD_OVERRIDE
Definition: gls_geometry_resource.h:515
static GlsGeometry_Generic * CreateEmptyInstance()
void SetIndexBufferSize(unsigned int bufferNum, unsigned int newSize)
bool _vertexBufferUpdated
Is the video card vertex buffer up to date?
Definition: gls_geometry_resource.h:1028
void SetVertexAttrib2fv(GLuint vertIndex, GLuint attribIndex, const GLfloat *v)
Definition: gls_geometry_resource.h:815
void SetSecondaryColor(GLuint vertIndex, unsigned char red, unsigned char green, unsigned char blue)
GlsGeometry_Generic_IndexBufferData * _indexBuffers
Definition: gls_geometry_resource.h:1031
void SetNormals(const float *floatArray, unsigned int numVertices, unsigned int startVertIndex=0, unsigned int stride=NORMAL_ATTRIBUTE_SIZE)
virtual void FreeOpenGLBuffers() DISTI_METHOD_OVERRIDE
void Destroy() DISTI_METHOD_OVERRIDE
virtual void UpdateBoundingVolume() DISTI_METHOD_OVERRIDE
unsigned int GetIndex(unsigned int bufferNum, unsigned int index)
virtual void DrawSetup(VertexAttribIndexLookup *shaderProgram) DISTI_METHOD_OVERRIDE
void CopyVertexAndIndexBuffers(GlsGeometry_Generic *rhs)
bool _bufferLock
Flag indicating that the vertex buffer is being written to.
Definition: gls_geometry_resource.h:1023
void StoreVertexAttrib(GLuint vertIndex, GLuint attribIndex, void *value, GLuint sizeBytes)
unsigned int GetTexcoordByteOffset(unsigned int whichTexture)
static GlsGeometry_Generic * CreateFromBinaryResource(GlsResourceFileMgr::BinaryResource *data)
unsigned int VertexCount() const
Definition: gls_resource_file_mgr.h:35
Definition: gls_resource_file_mgr.h:57
Definition: gls_resource_file_mgr.h:26
Definition: gls_render_effect.h:79
Definition: vertex.h:85
Contains the DistiAssert macro.
#define GLS_ASSERT(exp)
Definition: disti_assert.h:150
#define DISTI_SPECIAL_MEM_FUN_DELETE
Macro to wrap function deletion, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:235
#define DISTI_METHOD_OVERRIDE
Macro to wrap the override keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:214
The gls_gl.
The GlsMatrixAffine class.
The disti::GlsRenderEffect class.
Force inclusion of the DirectShow library.
Definition: bmpimage.h:47
Definition: gls_geometry_resource.h:934
unsigned int _order
The order the vertex should be in.
Definition: gls_geometry_resource.h:935
unsigned int _vertexTupleIndex
The index of the primitive.
Definition: gls_geometry_resource.h:936
Definition: gls_geometry_resource.h:1004
unsigned int _texcoordStride
Offset between each texture coordinate in bytes.
Definition: gls_geometry_resource.h:1008
unsigned int _texcoord2Stride
Offset between each secondary texture coordinate in bytes.
Definition: gls_geometry_resource.h:1009
unsigned int _numVertexAttribs
The count of vertex attributes.
Definition: gls_geometry_resource.h:1012
unsigned int _size
Total size of each vertex in bytes (depends on which data is included).
Definition: gls_geometry_resource.h:1005
unsigned int _colorStride
Offset between each color in bytes.
Definition: gls_geometry_resource.h:1010
unsigned int _normalStride
Offset between each normal in bytes.
Definition: gls_geometry_resource.h:1007
unsigned int _secondaryColorStride
Offset between each secondary color in bytes.
Definition: gls_geometry_resource.h:1011
The disti::Vertex class. A class for manipulating 3D vertices.