DI-Guy SDK Documentation  13.2
diguyGraphicsMesh.h
Go to the documentation of this file.
1 
2 /*********************************************************************
3  ** Copyright (c) 1992-2016 VT MAK
4  ** All rights reserved.
5  *********************************************************************/
6 
7 /*********************************************************************/
14 #ifndef __diguyGraphicsMesh_H
15 #define __diguyGraphicsMesh_H
16 
17 #ifdef SWIG
19 #else
20 #define CPLUSPLUS_ONLY
21 #endif
22 
23 #ifdef CPLUSPLUS_ONLY
24 #include <diguy_constants.h>
26 #include <declspec_diguy.h>
27 #include <stdlib.h>
28 
29 class diguyGraphicsMesh;
32 class diguyGraphicsState;
33 class diguyGraphicsShape;
34 class bdiGeometryMesh;
35 
36 #endif
37 
38 
44 struct BDI_DECLSPEC_diguy diguyDrawCallData
45 {
46  diguyDrawCallData() : m_state_override(NULL),
47  m_shape(NULL),
48  m_num_instances(1),
49  m_allow_instancing(1),
50  m_skip_vao_bind(0)
51  { ; }
52 
55  diguyGraphicsState * m_state_override;
56 
58  diguyGraphicsShape * m_shape;
59 
61  int m_num_instances;
62 
64  int m_render_pass;
65 
68  int m_allow_instancing;
69 
71  int m_skip_vao_bind;
72 };
73 
74 
75 /****************************************************************************/
83 class BDI_DECLSPEC_diguy diguyGraphicsMesh
84 {
85 
86 public:
87 
88 /*****************************************************************************/
97  /*l
98  *b Description:
99  **
100  ** Returns the name of the mesh. This pointer will
101  ** never be NULL.
102  **
103  *b Returns:
104  **
105  ** name of the mesh
106  */
107  const char* get_name();
108 
109  /*l
110  *b Description:
111  **
112  ** All meshes are assigned a unique identifier (uid)
113  ** This function returns the uid of the mesh.
114  **
115  ** *Note*: uids will change between DI-Guy runs.
116  **
117  *b Returns:
118  **
119  ** unique identifier of the object
120  */
121  long get_uid();
122 
123  /*l
124  *b Description:
125  **
126  ** This function returns the graphics state with which faces in this
127  ** mesh should be drawn. Specific information about material and
128  ** texture can then be accessed from this object.
129  **
130  ** Some meshes may have multiple possible graphics states associated
131  ** with them. In effect this means that depending on a character's
132  ** appearance, different textures or material settings may be used.
133  **
134  ** Call get_num_switched_graphics_states() to get the number of
135  ** graphics states that are associated with this mesh.
136  **
137  ** This function is typically called during the Build stage for
138  ** scene graph renderers, when geoset/mesh objects are being
139  ** created and their graphics states set.
140  **
141  *b Returns:
142  **
143  ** object of type diguyGraphicsState; NULL on failure
144  */
145  diguyGraphicsState* get_state(int graphics_state_switch_index = 0);
146 
147 
148  /*l
149  *b Description:
150  **
151  ** This function returns the number of switched graphics states
152  ** this mesh has. There should always be at least one.
153  **
154  ** See get_state() for more information on switched graphics states.
155  **
156  *b Returns:
157  **
158  ** number of switched graphics states this mesh has
159  */
160  int get_num_switched_graphics_states();
161 
162  /*l
163  *b Description:
164  **
165  ** This function returns whether or not the mesh is "skinned".
166  **
167  ** The position of vertices in a skinned mesh are determined
168  ** at run-time by transforming them with multiple link transforms.
169  **
170  ** It is likely that some type of shader is required to render
171  ** the mesh correctly. The shader recommended for this mesh can be
172  ** obtained by calling get_shader_program().
173  **
174  ** Though they sound similar, skinned meshes and deformable meshes
175  ** are different. The vertices in a deformable mesh have already
176  ** been transformed when the draw() function is called; nothing
177  ** more needs to be done. The vertices in a skinned are not ready
178  ** to be drawn, as they must first be transformed by a shader.
179  **
180  *b Returns:
181  **
182  ** 1 if mesh is skinned, 0 if not, -1 on failure
183  */
184  int get_is_skinned_mesh();
185 
186  /*l
187  *b Description:
188  **
189  ** This function returns whether or not the mesh is actually a morph object.
190  ** the pos,normals and tangents will then just be the deltas from the base mesh.
191  */
192  int get_is_blend_shape();
193 
194  /*l
195  *b Description:
196  **
197  ** This function frees most memory allocated by the DI-Guy geometry
198  ** loader for this object.
199  **
200  ** This function should only be called during or after the object's
201  ** build() function has been called. After it has been called, calls
202  ** to many accessor functions will fail.
203  */
204  void free_loader_memory();
205 
206 
207 /*****************************************************************************/
233 /*********************************************************************/
239  /*l
240  *b Description:
241  **
242  ** This function returns a pointer to the shader program designated
243  ** for this mesh, if any. Shader programs are shared objects usable
244  ** by many meshes.
245  **
246  *b Returns:
247  **
248  ** pointer to diguyGraphicsShaderProgram, or NULL if this mesh
249  ** does not have a shader specified
250  */
251  diguyGraphicsShaderProgram* get_shader_program();
252 
253  /*l
254  *b Description:
255  **
256  ** If this mesh has a shader program specified (see
257  ** get_shader_program()), this function returns a pointer to the
258  ** shader instance object specific to this mesh.
259  **
260  *b Returns:
261  **
262  ** pointer to diguyGraphicsShaderInstance, or NULL if this mesh
263  ** does not have a shader specified
264  */
265  diguyGraphicsShaderInstance* get_shader_instance();
266 
267 
268 /*********************************************************************/
274  /*l
275  *b Returns:
276  **
277  ** vertex format that describes the format of the data returned
278  ** by the get_vertex_buffer_data() function
279  */
280  diguyGraphicsVertexFormat get_vertex_format();
281 
282  /*l
283  *b Returns:
284  **
285  ** how many vertices this mesh has
286  */
287  int get_vertex_count();
288 
289  /*l
290  *b Returns:
291  **
292  ** size, in bytes, of the data buffer returned by
293  ** get_vertex_buffer_data()
294  */
295  int get_vertex_buffer_size();
296 
297 
298  /*l
299  *b Returns:
300  **
301  ** Pointer to a blend shape mesh that represents the offsets from this mesh, currently
302  ** we only have 1 of these which we use to adjust the weight of the character.
303  */
304  diguyGraphicsMesh * get_blend_shape(int index);
305 
307  int get_num_blend_shapes();
308 
309 #ifdef CPLUSPLUS_ONLY
310 
311  /*l
312  *b Description:
313  **
314  ** This function returns a pointer to the raw vertex buffer data
315  ** of this mesh. The format of the data can be obtained by calling
316  ** get_vertex_format().
317  **
318  ** Type-correct pointers into the data can be obtained by calling
319  ** get_first_vertex(), get_first_normal(), etc.
320  **
321  *b Returns:
322  **
323  ** pointer to raw vertex buffer data
324  */
325  void* get_vertex_buffer_data();
326 
327  /*l
328  *b Description:
329  **
330  ** This function returns a pointer to vertex position data of the
331  ** first vertex in the raw vertex buffer data returned by
332  ** get_vertex_buffer_data().
333  **
334  ** The XYZ position of the first vertex is stored in the first three
335  ** values of the returned pointer. The XYZ positions of subsequent
336  ** vertices need to be obtained by consecutively adding the
337  ** vertex stride to this returned pointer, as returned by
338  ** get_vertex_stride().
339  **
340  ** *NOTE*: get_vertex_stride() returns a value in *bytes*, not
341  ** sizeof(float), so be careful about pointer arithmetic.
342  **
343  ** This approach is also used for the first normal, texture indices,
344  ** link index, and link weight of the vertex data.
345  **
346  ** An alternative approach to getting a pointer to the first vertex
347  ** position is to use get_vertex_offset(). See that function for
348  ** more information.
349  **
350  *b Returns:
351  **
352  ** pointer to vertex position of first vertex in vertex buffer data
353  */
354  float* get_first_vertex();
355 
356  /*l
357  *b Description:
358  **
359  ** This function returns how many bytes the first vertex position
360  ** is into the raw vertex buffer data returned by
361  ** get_vertex_buffer_data().
362  **
363  ** The XYZ positions of subsequent vertices need to be obtained by
364  ** consecutively adding the vertex stride to this offset, as
365  ** returned by get_vertex_stride().
366  **
367  ** *NOTE*: get_vertex_stride() returns a value in *bytes*, not
368  ** sizeof(float), so be careful about pointer arithmetic.
369  **
370  ** This approach is also used for the first normal, texture indices,
371  ** link index, and link weight offsets into the vertex data.
372  **
373  ** An alternative approach to getting a pointer to the first vertex
374  ** position is to use get_first_vertex() to get a type-correct
375  ** pointer.
376  **
377  *b Returns:
378  **
379  ** offset in bytes of the first vertex position in raw vertex buffer
380  ** data
381  */
382  int get_vertex_offset();
383 
384  /*l
385  *b Description:
386  **
387  ** This function returns how many bytes there are between each
388  ** vertex position in the raw data returned by
389  ** get_vertex_buffer_data().
390  **
391  ** See get_first_vertex() and get_vertex_offset() for more
392  ** information.
393  **
394  ** *NOTE*: this function returns a value in *bytes*, not
395  ** sizeof(float), so be careful about pointer arithmetic.
396  **
397  *b Returns:
398  **
399  ** stride in bytes between each vertex position in raw vertex buffer
400  ** data
401  */
402  int get_vertex_stride();
403 
404  /*l
405  *b Returns:
406  **
407  ** pointer to normal of first vertex in vertex buffer data; see
408  ** get_first_vertex() for more information
409  */
410  float* get_first_normal();
411 
412  /*l
413  *b Returns:
414  **
415  ** offset in bytes of the first normal in raw vertex buffer data;
416  ** see get_vertex_offset() for more information
417  */
418  int get_normal_offset();
419 
420 
421  /*l
422  *b Returns:
423  **
424  ** pointer to texture indices of first vertex in vertex buffer data
425  */
426  float* get_first_texture_indices();
427 
428  /*l
429  *b Returns:
430  **
431  ** offset in bytes of the first texture indices in raw vertex buffer
432  ** data; see get_vertex_offset() for more information
433  */
434  int get_texture_indices_offset();
435 
436 
437  /*l
438  *b Returns:
439  **
440  ** pointer to link index of first vertex in vertex buffer data, in
441  ** float form
442  */
443  float* get_first_link_index();
444 
445  /*l
446  *b Returns:
447  **
448  ** offset in bytes of the first link index in raw vertex buffer data;
449  ** see get_vertex_offset() for more information
450  */
451  int get_link_index_offset();
452 
453 
454 
455  /*l
456  *b Returns:
457  **
458  ** pointer to link weight of first vertex in vertex buffer data
459  */
460  float* get_first_link_weight();
461 
462  /*l
463  *b Returns:
464  **
465  ** offset in bytes of the first link offset in raw vertex buffer data;
466  ** see get_vertex_offset() for more information
467  */
468  int get_link_weight_offset();
469 
470  /*l
471  *b Description:
472  **
473  ** Returns a pointer to the UV tangent and flip bit of first vertex in
474  ** the vertex buffer data.
475  **
476  ** There are 3 floats representing the tangent, and one for UV
477  ** mirroring. See
478  ** http://www.dhpoware.com/demos/glslNormalMapping.html for an outline
479  ** of how tangents are calculated. Binormals are calculated in the
480  ** vertex shader making their storage unnecessary. Tangents should
481  ** exist for all skinned/dae models.
482  **
483  ** See get_first_vertex() for more information about how to interpret
484  ** tangent pointers and strides.
485  */
486  float* get_first_tangent();
487 
488  /*l
489  *b Returns:
490  **
491  ** offset in bytes of the first tangent in raw vertex buffer data;
492  ** see get_vertex_offset() for more information
493  */
494  int get_tangent_offset();
495 
496 
497 #endif
498 
499 
500  /*********************************************************************/
507  /*l
508  *b Returns:
509  **
510  ** index type used in data returned by the get_index_buffer_data()
511  ** function
512  */
513  diguyGraphicsIndexType get_index_type();
514 
515  /*l
516  *b Description:
517  **
518  ** This function returns how many indices there are in this mesh.
519  ** The number of triangles in this mesh can be derived by dividing
520  ** this value by 3.
521  **
522  ** Note that indices in index buffer data are different than the
523  ** indices contained in vertex buffer data. Index buffer indices
524  ** specify which *vertices* in vertex buffer data are used to create
525  ** polygons in a mesh (e.g., for the first triangle, use vertices 0,
526  ** 1, and 2), while indices stored in vertex buffer data specify
527  ** which *links* affect the final position of the vertex.
528  **
529  *b Returns:
530  **
531  ** number of indices in index buffer data returned by
532  ** get_index_buffer_data()
533  */
534  int get_index_count();
535 
536 #ifdef CPLUSPLUS_ONLY
537 
538  /*l
539  *b Returns:
540  **
541  ** size, in bytes, of the data buffer returned by
542  ** get_index_buffer_data()
543  */
544  int get_index_buffer_size();
545 
546  /*l
547  *b Description:
548  **
549  ** This function returns a pointer to the raw index buffer data of
550  ** this mesh. The format of the data can be obtained by calling
551  ** get_index_type().
552  **
553  *b Returns:
554  **
555  ** pointer to raw index buffer data
556  */
557  void* get_index_buffer_data();
558 
559 #endif
560 
561 
562 /*****************************************************************************/
574 #ifdef CPLUSPLUS_ONLY
575 
576  /*l
577  *b Description:
578  **
579  ** This function will be called by DI-Guy when it is time for a
580  ** renderer-specific mesh object to be created. All information
581  ** necessary to build the mesh should be available via the
582  ** Accessor Functions above when this function is called.
583  **
584  *i Immediate Mode:
585  **
586  ** Immediate mode renderers may override this function, to
587  ** create an object that may be invoked by draw().
588  **
589  *i Scene Graph:
590  **
591  ** Scene graph renderers usually do override this function, to
592  ** create a geometry object that gets associated with a
593  ** diguyGraphicsState object obtained by calling get_state().
594  **
595  *b Callable From:
596  **
597  *- - N/A (automatically called by DI-Guy Graphics API during
598  *- the Build Stage)
599  */
600  virtual void build();
601 
602  /*l
603  *b Description:
604  **
605  ** This function will be called by DI-Guy when it is time for a
606  ** renderer-specific mesh object to be destroyed.
607  **
608  *i Immediate Mode:
609  **
610  ** Immediate mode renderers may override this function, to
611  ** destroy any object that may have been created by build().
612  **
613  *i Scene Graph:
614  **
615  ** Scene graph renderers usually do override this function, to
616  ** destroy any object that may have been created by build().
617  **
618  *b Callable From:
619  **
620  *- - N/A (automatically called by DI-Guy Graphics API during
621  *- the Unbuild Stage)
622  */
623  virtual void unbuild();
624 
625  /*l
626  *b Description:
627  **
628  ** This function will be called by DI-Guy when the mesh should
629  ** be drawn. For scene graph renderers, most likely nothing
630  ** more needs to be done by this function.
631  **
632  *b Callable From:
633  **
634  *- - N/A (automatically called by DI-Guy Graphics API during
635  *- Draw Stage)
636  */
637  virtual void draw(diguyDrawCallData * draw_data);
638 
639 
640 
641 #endif
642 
643 /****************************************************************************/
644 /*****************************************************************************/
655 /****************************************************************************/
656 /****************************************************************************/
657 
658  // This seems like a mistake in retrospect. Please let MaK support know if you needed
659  // it's functionality
660  /*l
661  *b Description:
662  **
663  ** This function returns the last bound graphic state object this mesh
664  ** used. There should always be at least one. This can be used by
665  ** immediate mode renderers during draw calls to find out more about
666  ** the properties of the mesh.
667  **
668  ** See get_state() for more information on switched graphics states.
669  **
670  *b Returns:
671  **
672  ** object of type diguyGraphicsState; NULL on failure
673  */
674  //diguyGraphicsState* get_current_graphics_state();
675 
676 /****************************************************************************/
677 /*****************************************************************************/
685  int get_bounding_box(float * bbox_min_x, float * bbox_min_y, float * bbox_min_z,
687  float * bbox_max_x, float * bbox_max_y, float * bbox_max_z);
689 /****************************************************************************/
690 /****************************************************************************/
691 
692 
693 
694 
695 /****************************************************************************/
696 /****************************************************************************/
697 
698  //** Deprecated as of 13.2.0
701 
704  int get_normal_stride(){ return get_vertex_stride(); }
705  int get_texture_indices_stride(){ return get_vertex_stride(); }
706  int get_tangent_stride(){ return get_vertex_stride(); }
707  int get_link_weight_stride(){ return get_vertex_stride(); }
708  int get_link_index_stride(){ return get_vertex_stride(); }
710  /*l
711  ** GNP we don't currently ever have deformable meshes... and you'd
712  ** still need to stream them to the videocard
713  *b Description:
714  **
715  ** This function returns whether or not the mesh is deformable.
716  **
717  ** The position of vertices in a deformable mesh may shift from
718  ** frame to frame and therefore should not be put into a
719  ** renderer-specific object that cannot be updated. (For example,
720  ** vertex buffer objects in OpenGL.)
721  **
722  ** The position of vertices in a non-deformable, non-skinned mesh
723  ** remain fixed from frame to frame.
724  **
725  ** Though they sound similar, skinned meshes and deformable meshes
726  ** are different. The vertices in a deformable mesh have already
727  ** been transformed when the draw() function is called; nothing
728  ** more needs to be done. The vertices in a skinned mesh are not
729  ** ready to be drawn, as they must first be transformed by a
730  ** shader.
731  **
732  *b Returns:
733  **
734  ** 1 if mesh is deformable, 0 if not, -1 on failure
735  */
736  int get_is_deformable();
741 #ifdef CPLUSPLUS_ONLY
742 
743  bdiGeometryMesh* get_internal_data() {return m_mesh;}
744 
745 protected:
746 
747  /*l
748  ** A protected constructor. Constructors are called automatically
749  ** by DI-Guy.
750  */
751  diguyGraphicsMesh(void* internal_data);
752 
753  /*l
754  ** A protected destructor. Destructors are called automatically
755  ** by DI-Guy.
756  */
757  virtual ~diguyGraphicsMesh();
758 
759 private:
760 
761  /*l
762  ** A pointer to internal data.
763  */
764  bdiGeometryMesh* m_mesh;
765 
766  friend class bdiGeometryGeosetMesh;
767  friend class bdiGeometryMesh;
768  friend class bdiGeometryFactory;
769  friend class diguyGraphicsMeshArray;
770 
771 
772 #endif
773 };
774 
775 
776 #endif /* __diguyGraphicsMesh_H */
777 
A class that represents the unique per-character shader object.
Definition: diguyGraphicsShaderInstance.h:55
A class that represents a shared material/textures combination.
Definition: diguyGraphicsState.h:44
A class that represents a shared texture.
Definition: diguyGraphicsTexture.h:122
A class that represents a shared mesh object.
Definition: diguyGraphicsMesh.h:80
diguyGraphicsIndexType
This enumeration lists the type that indices stored in index buffer data might have.
Definition: diguyGraphicsVertexFormats.h:114
A struct that represents the information that diguy puts together for an immediate mode draw call...
Definition: diguyGraphicsMesh.h:42
A class that represents the unique per-character non-shared mesh object. DI-Guy encapsulates its text...
Definition: diguyGraphicsShape.h:51
This class implements shader programs for use with DI-Guy character graphics.
Definition: diguyGraphicsShaderProgram.h:96
diguyGraphicsVertexFormat
This enumeration lists types of vertex data formats DI-Guy may use.
Definition: diguyGraphicsVertexFormats.h:78