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