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