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