GL Studio C++ Runtime API
gls_geometry_resource_mesh.h
Go to the documentation of this file.
1/*! \file
2 \brief The disti::GlsGeometryResourceMesh class.
3
4 \par Copyright Information
5
6 Copyright (c) 2017 by The DiSTI Corporation.<br>
7 11301 Corporate Blvd; Suite 100<br>
8 Orlando, Florida 32817<br>
9 USA<br>
10 <br>
11 All rights reserved.<br>
12
13 This Software contains proprietary trade secrets of DiSTI and may not be
14reproduced, in whole or part, in any form, or by any means of electronic,
15mechanical, or otherwise, without the written permission of DiSTI. Said
16permission may be derived through the purchase of applicable DiSTI product
17licenses which detail the distribution rights of this content and any
18Derivative Works based on this or other copyrighted DiSTI Software.
19
20 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26
27 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34EXCEED FIVE DOLLARS (US$5.00).
35
36 The aforementioned terms and restrictions are governed by the laws of the
37State of Florida and the United States of America.
38
39*/
40
41#ifndef INCLUDED_GLS_GEOMETRY_RESOURCE_MESH_H
42#define INCLUDED_GLS_GEOMETRY_RESOURCE_MESH_H
43
44#include "display.h"
47#include "gls_render_effect.h"
48#include <cstddef>
49
50/// Provides support for creating DLLs.
51#if( defined( GLSGEN_EXPORT_GLSADVANCEDMESH ) || defined( GLSGEN_IMPORT_GLSADVANCEDMESH ) || defined( GLS_EXPORT_GENERATED ) || defined( GLS_IMPORT_GENERATED ) ) \
52 && defined( _MSC_VER )
53# if defined( GLSGEN_EXPORT_GLSADVANCEDMESH ) || defined( GLS_EXPORT_GENERATED )
54# define GLSGEN_GlsAdvancedMesh_EXPORT __declspec( dllexport )
55# else
56# define GLSGEN_GlsAdvancedMesh_EXPORT __declspec( dllimport )
57# endif
58#else
59# define GLSGEN_GlsAdvancedMesh_EXPORT
60#endif
61///////////////////////////////////////////////////////////////////////////////
62
63namespace disti
64{
65// Forward Declaration
66class GlsSortedDrawable;
67
68#ifdef GLES
69// Forward Declaration
70class GlsGloFileAttribute;
71#endif
72
73/**
74 This is an abstrace base class for objects that use a GlsGeometryResource for rendering (e.g. GlsAdvancedMesh)
75 This class implements Draw / Pick routines that use a RenderMesh provided by the derived classes. The appearance of the mesh is affected by the IndexBufferEffectsArray.
76 This class also implements Translate, Rotate, and Scale through a GeometryTransform matrix.
77*/
80{
81#if !defined( GLES )
82 friend class GlsGeometryResourceMesh_SortedDrawable;
83#endif
84
85public:
86 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
87 typedef DisplayObject _BaseClass; ///< Deprecated typedef for the base class.
88 typedef DisplayObject BaseClass; ///< Typedef for the base class.
89 friend class GlsGeometryResourceMeshEditor;
90
91 /** Create a new GlsGeometryResourceMesh */
93
94 /** Create a copy of a GlsGeometryResourceMesh
95 * \param that The GlsGeometryResourceMesh to copy from
96 * \param generateNames Whether or not to generate a new instance name for the copy
97 */
99
100 /** GlsGeometryResourceMesh destructor */
102
103 //////////////////////////////////////////////////
104 // Overridden base class methods
105 //////////////////////////////////////////////////
106
107 /* Callback for when a resource could invalidate the scene */
109 {
111 }
112
117
118#ifndef GLES
121#endif
122
125
126 virtual GLSGEN_GlsAdvancedMesh_EXPORT void GetTransformedExtents( Vector& min, Vector& max, const GlsMatrixType& matrix, bool resetMinMax = true ) DISTI_METHOD_OVERRIDE;
127 virtual GLSGEN_GlsAdvancedMesh_EXPORT void GetExtents( float& minx, float& miny, float& minz, float& maxx, float& maxy, float& maxz ) DISTI_METHOD_OVERRIDE;
128
129 virtual GLSGEN_GlsAdvancedMesh_EXPORT DisplayObject* Pick3D( const Vector& winLoc, const Vector& logicalCoords, float scale, const Vector& directionVector, Vector& collisionWinLoc, const OpenGLMatrices& drawnMatrices ) DISTI_METHOD_OVERRIDE;
130
131 virtual GLSGEN_GlsAdvancedMesh_EXPORT bool Hit( float x, float y, float z, float scale, const Vector& directionVector, Vector* collisionPoint ) DISTI_METHOD_OVERRIDE;
132
133 virtual GLSGEN_GlsAdvancedMesh_EXPORT void Scale( float px, float py, float pz, Vertex* anchor, int handleBar = 0 ) DISTI_METHOD_OVERRIDE;
134 virtual GLSGEN_GlsAdvancedMesh_EXPORT void Rotate( const Vector& orig, float angle, const Vector& axis ) DISTI_METHOD_OVERRIDE;
136
137 /// Override base class since a mesh can have multiple textures.
138 /// \return -2 if multiple textures applied to object, -1 if no texture
139 /// otherwise if all faces use same texture, returns the texture
140 /// index that is shared by the faces.
142
143 /* Override base class since a mesh can have multiple textures */
145
146 /// Override base class since a mesh can have multiple textures.
147 /// \return Whether or not the OpenGL state changed.
149
150 /// Override base class since a mesh can have multiple materials.
151 /// \param index The material index to set.
152 virtual GLSGEN_GlsAdvancedMesh_EXPORT void MaterialIndex( unsigned int index );
153
154 /// Override base class since a mesh can have multiple materials.
155 /// \return The first index in the _materialIndices array.
157
158 /// Set the _materialIndices array for this object.
159 /// \param indices The new indices to set.
161
162 /* Override base class since a mesh can have multiple materials */
164
165 //////////////////////////////////////////////////
166 // GlsGeometryResourceMesh specific operations
167 //////////////////////////////////////////////////
168
169 /// Set the matrix that is applied before the geometry resource is drawn.
170 /// \param value The transform value to set.
172
173 /// Set the matrix that is applied before the geometry resource is drawn.
174 /// \param matrix Array of 16 doubles that make up the new transform matrix.
176
177 /**
178 * \returns The matrix that is applied before the geometry resource is drawn.
179 * Lifetime is guaranteed to coincide with the GlsGeometryResourceMesh's lifetime.
180 */
182
183 /**
184 * \returns The number of IndexBuffers in the current render mesh
185 */
186 unsigned int NumIndexBuffers()
187 {
188 return GetRenderMesh()->NumIndexBuffers();
189 }
190
191 /**
192 * \returns The size of the IndexBufferEffects array
193 */
195 {
196 return _indexBufferEffects.Count();
197 }
198
199 /// \return Whether or not the draw order of the mesh can be modified for performance.
200 bool ReorderAtWill() { return _reorderAtWill; }
201
202 /// Sets whether or not the draw order of the mesh can be modified for performance.
203 /// \param reorderAtWill The new reorder flag.
204 void ReorderAtWill( bool reorderAtWill ) { _reorderAtWill = reorderAtWill; }
205
206 /// Set the size of the IndexBufferEffects array.
207 /// This will release any effects that are no longer referenced.
208 /// \param newSize The new number of effects to set.
210
211 /** Access the GlsRenderEffect that is used to render the specified index buffer (may be NULL)
212 * \param bufferNum The IndexBuffer to get the effect for. Must be between 0 and NumIndexBuffers().
213 * \returns Pointer to the index buffer effect used when rendering the specified GlsGeometryResource IndexBuffer
214 */
215 GlsRenderEffect* GetIndexBufferEffect( unsigned int bufferNum )
216 {
217 if( bufferNum >= _indexBufferEffects.Count() )
218 {
219 return NULL;
220 }
221
222 return _indexBufferEffects[ bufferNum ];
223 }
224
225 /** Set the GlsRenderEffect to use when rendering the given index buffer.
226 * If this value is NULL, the geometry will be rendered with a default effect.
227 * Note: the GlsGeometryResourceMesh will increment the reference count on the new effect and release any effect that was previously referenced.
228 * \param bufferNum The IndexBuffer to get the effect for. Should be between 0 and NumIndexBuffers().
229 * \param newEffect [out] Pointer to the index buffer effect to use when rendering the specified GlsGeometryResource IndexBuffer.
230 */
231 void SetIndexBufferEffect( unsigned int bufferNum, GlsRenderEffect* newEffect )
232 {
233 if( bufferNum >= _indexBufferEffects.Count() )
234 {
235 ResizeIndexBufferEffectsArray( bufferNum + 1 );
236 }
237
238 GlsRenderEffect* oldEffect = _indexBufferEffects[ bufferNum ];
239 _indexBufferEffects[ bufferNum ] = newEffect;
240
241 if( newEffect )
242 {
243 newEffect->AddRef();
244 }
245 if( oldEffect )
246 {
247 oldEffect->Release();
248 }
249 }
250
251 /// Implemented by the derived class.
252 /// \return The mesh that should be rendered / picked.
254
255#ifdef GLES
256 /** Set a single attribute from the GLO file.
257 * \param data The attribute to set and its associated data.
258 */
260#endif
261
262protected:
263 GlsMatrixType _geometryTransform; ///< Transformation matrix to be applied to all geometry in this mesh.
264
265 DynamicArray<int> _newMaterialIndices; ///< Intermediate data storage to make the setting of new material indices through the Faces simpler.
266
267 bool _reorderAtWill; ///< Determines whether or not the draw order of this mesh can be modified to increase performance.
268
269 typedef DynamicArray<GlsRenderEffect*> IndexBufferEffectArrayT; ///< Typedef for a list of effects (shaders).
270 IndexBufferEffectArrayT _indexBufferEffects; ///< The effect to use for each index buffer.
271
272 class DistiAttributeIndexBufferEffectArray;
273
274#if !defined( GLES )
275 typedef DynamicArray<GlsSortedDrawable*> SortedDrawableArrayT; ///< Typedef for a list of sorted drawables.
276 SortedDrawableArrayT _indexBufferDrawables; ///< GlsSortedDrawable for each index buffer.
277#endif
278
279 /// Draw the given mesh object, used by internal draw code.
280 /// \note Not normally called by users.
281 /// \param renderMesh The mesh to draw.
283
284 /// Sets up the default shader program for mesh drawing.
285 /// \note Not normally called by users.
287
288 /// Resets the shader program state after mesh drawing.
289 /// \note Not normally called by users.
291
292 /// Draw all underlying mesh objects, used by internal draw code.
293 /// \note Not normally called by users.
295
296#ifdef GLES
297 // Used by SetFromGloData().
298 bool SetGloIndexBufferEffect( GlsGloFileAttribute& data );
299 GlsGeometry_Generic* LoadGloGeometryResourceData( GlsGloFileAttribute& data );
300#endif
301
302private:
303 // Cache for the extents to prevent re-calculation when nothing has changed.
304 struct LastExtents
305 {
306 unsigned int id;
307 GlsMatrixType transformMatrix;
308 Vector min;
309 Vector max;
310
311 LastExtents()
312 : id( GlsGeometryResource::s_invalidDataChangedCounter )
313 {}
314 } _lastExtents;
315
316 // Disable implicit generated Members
319
320 void CopyGeometryInternal( const GlsGeometryResourceMesh& src );
321 /* Utility routines used to detect when the material indices has changed */
322 void OnMatChanged();
323 void OnMatChanged( DynamicArray<int>& a, DynamicArray<int>& b );
324 void ReplaceMaterial( unsigned int oldIndex, unsigned int newIndex );
325};
326
327// Used by code generator.
328/// \cond INTERNAL
329GLSGEN_GlsAdvancedMesh_EXPORT GlsRenderEffect* CreateRenderEffect_DiffNormSpecRefl(
330 unsigned int material_index,
331 int diffuse_texture_index,
332 int normal_texture_index,
333 int specular_texture_index,
334 int reflection_texture_index,
335 float diffuse_amount,
336 float normal_amount,
337 float specular_amount,
338 float reflection_amount,
339 bool useVertexColors,
340 bool normalFlipGreen,
341 float diff_map_offset_v = 0.0f,
342 float diff_map_offset_u = 0.0f,
343 float diff_map_tiling_u = 1.0f,
344 float diff_map_tiling_v = 1.0f,
345 float diff_map_angle_w = 0.0f,
346 float norm_map_offset_v = 0.0f,
347 float norm_map_offset_u = 0.0f,
348 float norm_map_tiling_u = 1.0f,
349 float norm_map_tiling_v = 1.0f,
350 float norm_map_angle_w = 0.0f,
351 float spec_map_offset_v = 0.0f,
352 float spec_map_offset_u = 0.0f,
353 float spec_map_tiling_u = 1.0f,
354 float spec_map_tiling_v = 1.0f,
355 float spec_map_angle_w = 0.0f );
356/// \endcond
357} // namespace disti
358
359#endif
Definition: cull.h:50
Definition: display.h:96
Definition: dynamic_array.h:79
unsigned Count() const
Definition: dynamic_array.h:218
Definition: gls_geometry_resource_mesh.h:80
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL) DISTI_METHOD_OVERRIDE
virtual DynamicArray< int > & MaterialIndices() DISTI_METHOD_OVERRIDE
unsigned int NumIndexBufferEffects()
Definition: gls_geometry_resource_mesh.h:194
virtual void SetAvailableAttributes(unsigned int value) DISTI_METHOD_OVERRIDE
virtual void Draw() DISTI_METHOD_OVERRIDE
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array) DISTI_METHOD_OVERRIDE
bool ReorderAtWill()
Definition: gls_geometry_resource_mesh.h:200
virtual void ResizeIndexBufferEffectsArray(unsigned int newSize)
virtual int MaterialIndex() DISTI_METHOD_OVERRIDE
virtual void GetTransformedExtents(Vector &min, Vector &max, const GlsMatrixType &matrix, bool resetMinMax=true) DISTI_METHOD_OVERRIDE
void SetGeometryTransform(const GlsMatrixType &value)
SortedDrawableArrayT _indexBufferDrawables
GlsSortedDrawable for each index buffer.
Definition: gls_geometry_resource_mesh.h:276
virtual bool Hit(float x, float y, float z, float scale, const Vector &directionVector, Vector *collisionPoint) DISTI_METHOD_OVERRIDE
virtual void PreDraw(const OpenGLMatrices &parentMatrices, Culler &culler) DISTI_METHOD_OVERRIDE
bool _reorderAtWill
Determines whether or not the draw order of this mesh can be modified to increase performance.
Definition: gls_geometry_resource_mesh.h:267
virtual GlsGeometryResource * GetRenderMesh()=0
IndexBufferEffectArrayT _indexBufferEffects
The effect to use for each index buffer.
Definition: gls_geometry_resource_mesh.h:270
GlsRenderEffect * GetIndexBufferEffect(unsigned int bufferNum)
Definition: gls_geometry_resource_mesh.h:215
virtual void TranslateVertices(float x, float y, float z) DISTI_METHOD_OVERRIDE
virtual void Rotate(const Vector &orig, float angle, const Vector &axis) DISTI_METHOD_OVERRIDE
virtual int TextureIndex() DISTI_METHOD_OVERRIDE
DynamicArray< GlsRenderEffect * > IndexBufferEffectArrayT
Typedef for a list of effects (shaders).
Definition: gls_geometry_resource_mesh.h:269
void DrawIndexBuffers(GlsGeometryResource *renderMesh)
DynamicArray< GlsSortedDrawable * > SortedDrawableArrayT
Typedef for a list of sorted drawables.
Definition: gls_geometry_resource_mesh.h:275
GlsMatrixType _geometryTransform
Transformation matrix to be applied to all geometry in this mesh.
Definition: gls_geometry_resource_mesh.h:263
virtual void GetExtents(float &minx, float &miny, float &minz, float &maxx, float &maxy, float &maxz) DISTI_METHOD_OVERRIDE
virtual void CopyGeometry(DisplayObject *src) DISTI_METHOD_OVERRIDE
void ReorderAtWill(bool reorderAtWill)
Definition: gls_geometry_resource_mesh.h:204
DynamicArray< int > _newMaterialIndices
Intermediate data storage to make the setting of new material indices through the Faces simpler.
Definition: gls_geometry_resource_mesh.h:265
unsigned int NumIndexBuffers()
Definition: gls_geometry_resource_mesh.h:186
virtual DisplayObject * Pick3D(const Vector &winLoc, const Vector &logicalCoords, float scale, const Vector &directionVector, Vector &collisionWinLoc, const OpenGLMatrices &drawnMatrices) DISTI_METHOD_OVERRIDE
virtual void CopyProperties(DisplayObject *src) DISTI_METHOD_OVERRIDE
virtual void Scale(float px, float py, float pz, Vertex *anchor, int handleBar=0) DISTI_METHOD_OVERRIDE
virtual void OnGeometryResourceChanged() DISTI_METHOD_OVERRIDE
Callback method to be called by this observer.
Definition: gls_geometry_resource_mesh.h:108
virtual void UpdateBoundingVolume() DISTI_METHOD_OVERRIDE
void SetIndexBufferEffect(unsigned int bufferNum, GlsRenderEffect *newEffect)
Definition: gls_geometry_resource_mesh.h:231
const GlsMatrixType & GetGeometryTransform()
Definition: gls_geometry_resource_mesh.h:181
Definition: gls_geometry_resource.h:288
Definition: gls_geometry_resource.h:87
unsigned int NumIndexBuffers() const
Definition: gls_geometry_resource.h:471
Definition: gls_geometry_resource.h:507
Definition: gls_glo_file.h:1243
Definition: gls_render_effect.h:116
virtual void Release()=0
Release a reference to this object.
virtual void AddRef()=0
Add to this object's reference count.
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:544
Definition: vertex.h:85
Definition: vertex.h:420
The disti::DisplayObject class and global enumerations.
Macros and helper code to determine what subset of C++11/14/17 is available.
#define DISTI_SPECIAL_MEM_FUN_DELETE
Macro to wrap function deletion, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:235
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:457
#define DISTI_METHOD_OVERRIDE
Macro to wrap the override keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:214
The disti::GlsGeometryResource class.
#define GLSGEN_GlsAdvancedMesh_EXPORT
Provides support for creating DLLs.
Definition: gls_geometry_resource_mesh.h:59
The disti::GlsRenderEffect class.
Force inclusion of the DirectShow library.
Definition: bmpimage.h:47