DI-Guy SDK Documentation  13.1
diguyGraphicsMesh.h
Go to the documentation of this file.
1 
2 /*********************************************************************
3  ** Copyright (c) 1992-2015 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 
28 class diguyGraphicsMeshInternalData;
29 class diguyGraphicsMesh;
32 class diguyGraphicsState;
33 
34 
35 #endif
36 
37 /****************************************************************************/
38 class BDI_DECLSPEC_diguy diguyGraphicsMesh
39 {
40 
41 public:
42 
43 /*****************************************************************************/
52  /*l
53  *b Description:
54  **
55  ** Returns the name of the mesh. This pointer will
56  ** never be NULL.
57  **
58  *b Returns:
59  **
60  ** name of the mesh
61  */
62  const char* get_name();
63 
64  /*l
65  *b Description:
66  **
67  ** All meshs are assigned a unique identifer (uid).
68  ** This function returns the uid of the mesh.
69  **
70  ** *Note*: uids will change between DI-Guy runs.
71  **
72  *b Returns:
73  **
74  ** unique identifier of the object
75  */
76  long get_uid();
77 
78  /*l
79  *b Description:
80  **
81  ** This function returns the graphics state with which faces in this
82  ** mesh should be drawn. Specific information about material and
83  ** texture can then be accessed from this object.
84  **
85  ** Some meshes may have multiple possible graphics states associated
86  ** with them. In effect this means that depending on a character's
87  ** appearance, different textures or material settings may be used.
88  **
89  ** Call get_num_switched_graphics_states() to get the number of
90  ** graphics states that are associated with this mesh.
91  **
92  ** This function is typically called during the Build stage for
93  ** scene graph renderers, when geoset/mesh objects are being
94  ** created and their graphics states set.
95  **
96  *b Returns:
97  **
98  ** object of type diguyGraphicsState; NULL on failure
99  */
100  diguyGraphicsState* get_state(int graphics_state_switch_index = 0);
101 
102  /*l
103  *b Description:
104  **
105  ** This function returns the last bound graphic state object this mesh
106  ** used. There should always be at least one. This can be used by
107  ** immediate mode renderers during draw calls to find out more about
108  ** the properties of the mesh.
109  **
110  ** See get_state() for more information on switched graphics states.
111  **
112  *b Returns:
113  **
114  ** object of type diguyGraphicsState; NULL on failure
115  */
116  diguyGraphicsState* get_current_graphics_state();
117 
118  /*l
119  *b Description:
120  **
121  ** This function returns the number of switched graphics states
122  ** this mesh has. There should always be at least one.
123  **
124  ** See get_state() for more information on switched graphics states.
125  **
126  *b Returns:
127  **
128  ** number of switched graphics states this mesh has
129  */
130  int get_num_switched_graphics_states();
131 
132  /*l
133  *b Description:
134  **
135  ** This function returns whether or not the mesh is "skinned".
136  **
137  ** The position of vertices in a skinned mesh are determined
138  ** at run-time by transforming them with multiple link transforms.
139  **
140  ** It is likely that some type of shader is required to render
141  ** the mesh correctly. The shader recommended for this mesh can be
142  ** obtained by calling get_shader_program().
143  **
144  ** Though they sound similar, skinned meshes and deformable meshes
145  ** are different. The vertices in a deformable mesh have already
146  ** been transformed when the draw() function is called; nothing
147  ** more needs to be done. The vertices in a skinned are not ready
148  ** to be drawn, as they must first be transformed by a shader.
149  **
150  *b Returns:
151  **
152  ** 1 if mesh is skinned, 0 if not, -1 on failure
153  */
154  int get_is_skinned_mesh();
155 
156  /*l
157  *b Description:
158  **
159  ** This function returns whether or not the mesh is deformable.
160  **
161  ** The position of vertices in a deformable mesh may shift from
162  ** frame to frame and therefore should not be put into a
163  ** renderer-specific object that cannot be updated. (For example,
164  ** vertex buffer objects in OpenGL.)
165  **
166  ** The position of vertices in a non-deformable, non-skinned mesh
167  ** remain fixed from frame to frame.
168  **
169  ** Though they sound similar, skinned meshes and deformable meshes
170  ** are different. The vertices in a deformable mesh have already
171  ** been transformed when the draw() function is called; nothing
172  ** more needs to be done. The vertices in a skinned mesh are not
173  ** ready to be drawn, as they must first be transformed by a
174  ** shader.
175  **
176  *b Returns:
177  **
178  ** 1 if mesh is deformable, 0 if not, -1 on failure
179  */
180  int get_is_deformable();
181 
182  /*l
183  *b Description:
184  **
185  ** This function frees most memory allocated by the DI-Guy geometry
186  ** loader for this object.
187  **
188  ** This function should only be called during or after the object's
189  ** build() function has been called. After it has been called, calls
190  ** to many accessor functions will fail.
191  */
192  void free_loader_memory();
193 
194 
195 /*****************************************************************************/
221 /*********************************************************************/
227  /*l
228  *b Description:
229  **
230  ** This function returns a pointer to the shader program designated
231  ** for this mesh, if any. Shader programs are shared objects usable
232  ** by many meshes.
233  **
234  *b Returns:
235  **
236  ** pointer to diguyGraphicsShaderProgram, or NULL if this mesh
237  ** does not have a shader specified
238  */
239  diguyGraphicsShaderProgram* get_shader_program();
240 
241  /*l
242  *b Description:
243  **
244  ** If this mesh has a shader program specified (see
245  ** get_shader_program()), this function returns a pointer to the
246  ** shader instance object specific to this mesh.
247  **
248  *b Returns:
249  **
250  ** pointer to diguyGraphicsShaderInstance, or NULL if this mesh
251  ** does not have a shader specified
252  */
253  diguyGraphicsShaderInstance* get_shader_instance();
254 
255 
256 /*********************************************************************/
262  /*l
263  *b Returns:
264  **
265  ** vertex format that describes the format of the data returned
266  ** by the get_vertex_buffer_data() function
267  */
268  diguyGraphicsVertexFormat get_vertex_format();
269 
270  /*l
271  *b Returns:
272  **
273  ** how many vertices this mesh has
274  */
275  int get_vertex_count();
276 
277  /*l
278  *b Returns:
279  **
280  ** size, in bytes, of the data buffer returned by
281  ** get_vertex_buffer_data()
282  */
283  int get_vertex_buffer_size();
284 
285 #ifdef CPLUSPLUS_ONLY
286 
287  /*l
288  *b Description:
289  **
290  ** This function returns a pointer to the raw vertex buffer data
291  ** of this mesh. The format of the data can be obtained by calling
292  ** get_vertex_format().
293  **
294  ** Type-correct pointers into the data can be obtained by calling
295  ** get_first_vertex(), get_first_normal(), etc.
296  **
297  *b Returns:
298  **
299  ** pointer to raw vertex buffer data
300  */
301  void* get_vertex_buffer_data();
302 
303  /*l
304  *b Description:
305  **
306  ** This function returns a pointer to vertex position data of the
307  ** first vertex in the raw vertex buffer data returned by
308  ** get_vertex_buffer_data().
309  **
310  ** The XYZ position of the first vertex is stored in the first three
311  ** values of the returned pointer. The XYZ positions of subsequent
312  ** vertices need to be obtained by consecutively adding the
313  ** vertex stride to this returned pointer, as returned by
314  ** get_vertex_stride().
315  **
316  ** *NOTE*: get_vertex_stride() returns a value in *bytes*, not
317  ** sizeof(float), so be careful about pointer arithmetic.
318  **
319  ** This approach is also used for the first normal, texture indices,
320  ** link index, and link weight of the vertex data.
321  **
322  ** An alternative approach to getting a pointer to the first vertex
323  ** position is to use get_vertex_offset(). See that function for
324  ** more information.
325  **
326  *b Returns:
327  **
328  ** pointer to vertex position of first vertex in vertex buffer data
329  */
330  float* get_first_vertex();
331 
332  /*l
333  *b Description:
334  **
335  ** This function returns how many bytes the first vertex position
336  ** is into the raw vertex buffer data returned by
337  ** get_vertex_buffer_data().
338  **
339  ** The XYZ positions of subsequent vertices need to be obtained by
340  ** consecutively adding the vertex stride to this offset, as
341  ** returned by get_vertex_stride().
342  **
343  ** *NOTE*: get_vertex_stride() returns a value in *bytes*, not
344  ** sizeof(float), so be careful about pointer arithmetic.
345  **
346  ** This approach is also used for the first normal, texture indices,
347  ** link index, and link weight offsets into the vertex data.
348  **
349  ** An alternative approach to getting a pointer to the first vertex
350  ** position is to use get_first_vertex() to get a type-correct
351  ** pointer.
352  **
353  *b Returns:
354  **
355  ** offset in bytes of the first vertex position in raw vertex buffer
356  ** data
357  */
358  int get_vertex_offset();
359 
360  /*l
361  *b Description:
362  **
363  ** This function returns how many bytes there are between each
364  ** vertex position in the raw data returned by
365  ** get_vertex_buffer_data().
366  **
367  ** See get_first_vertex() and get_vertex_offset() for more
368  ** information.
369  **
370  ** *NOTE*: this function returns a value in *bytes*, not
371  ** sizeof(float), so be careful about pointer arithmetic.
372  **
373  *b Returns:
374  **
375  ** stride in bytes between each vertex position in raw vertex buffer
376  ** data
377  */
378  int get_vertex_stride();
379 
380  /*l
381  *b Returns:
382  **
383  ** pointer to normal of first vertex in vertex buffer data; see
384  ** get_first_vertex() for more information
385  */
386  float* get_first_normal();
387 
388  /*l
389  *b Returns:
390  **
391  ** offset in bytes of the first normal in raw vertex buffer data;
392  ** see get_vertex_offset() for more information
393  */
394  int get_normal_offset();
395 
396  /*l
397  *b Returns:
398  **
399  ** stride in bytes between each normal in raw vertex buffer
400  ** data; see get_vertex_stride() for more information
401  */
402  int get_normal_stride();
403 
404  /*l
405  *b Returns:
406  **
407  ** pointer to texture indices of first vertex in vertex buffer data
408  */
409  float* get_first_texture_indices();
410 
411  /*l
412  *b Returns:
413  **
414  ** offset in bytes of the first texture indices in raw vertex buffer
415  ** data; see get_vertex_offset() for more information
416  */
417  int get_texture_indices_offset();
418 
419  /*l
420  *b Returns:
421  **
422  ** stride in bytes between each texture indices pair in raw vertex
423  ** buffer data; see get_vertex_stride() for more information
424  */
425  int get_texture_indices_stride();
426 
427  /*l
428  *b Returns:
429  **
430  ** pointer to link index of first vertex in vertex buffer data, in
431  ** float form
432  */
433  float* get_first_link_index();
434 
435  /*l
436  *b Returns:
437  **
438  ** offset in bytes of the first link index in raw vertex buffer data;
439  ** see get_vertex_offset() for more information
440  */
441  int get_link_index_offset();
442 
443  /*l
444  *b Returns:
445  **
446  ** stride in bytes between each link index in raw vertex buffer
447  ** data; see get_vertex_stride() for more information
448  */
449  int get_link_index_stride();
450 
451  /*l
452  *b Returns:
453  **
454  ** pointer to link weight of first vertex in vertex buffer data
455  */
456  float* get_first_link_weight();
457 
458  /*l
459  *b Returns:
460  **
461  ** offset in bytes of the first link offset in raw vertex buffer data;
462  ** see get_vertex_offset() for more information
463  */
464  int get_link_weight_offset();
465 
466  /*l
467  *b Returns:
468  **
469  ** stride in bytes between each link weight in raw vertex buffer data;
470  ** see get_vertex_stride() for more information
471  */
472  int get_link_weight_stride();
473 
474  /*l
475  *b Description:
476  **
477  ** Returns a pointer to the UV tangent and flip bit of first vertex in
478  ** the vertex buffer data.
479  **
480  ** There are 3 floats representing the tangent, and one for UV
481  ** mirroring. See
482  ** http://www.dhpoware.com/demos/glslNormalMapping.html for an outline
483  ** of how tangents are calculated. Binormals are calculated in the
484  ** vertex shader making their storage unnecessary. Tangents should
485  ** exist for all skinned/dae models.
486  **
487  ** See get_first_vertex() for more information about how to interpret
488  ** tangent pointers and strides.
489  */
490  float* get_first_tangent();
491 
492  /*l
493  *b Returns:
494  **
495  ** offset in bytes of the first tangent in raw vertex buffer data;
496  ** see get_vertex_offset() for more information
497  */
498  int get_tangent_offset();
499 
500  /*l
501  *b Returns:
502  **
503  ** stride in bytes between each tangent in raw vertex buffer data; see
504  ** get_vertex_stride() for more information
505  */
506  int get_tangent_stride();
507 
508 #endif
509 
510 
511  /*********************************************************************/
518  /*l
519  *b Returns:
520  **
521  ** index type used in data returned by the get_index_buffer_data()
522  ** function
523  */
524  diguyGraphicsIndexType get_index_type();
525 
526  /*l
527  *b Description:
528  **
529  ** This function returns how many indices there are in this mesh.
530  ** The number of triangles in this mesh can be derived by dividing
531  ** this value by 3.
532  **
533  ** Note that indices in index buffer data are different than the
534  ** indices contained in vertex buffer data. Index buffer indices
535  ** specify which *vertices* in vertex buffer data are used to create
536  ** polygons in a mesh (e.g., for the first triangle, use vertices 0,
537  ** 1, and 2), while indices stored in vertex buffer data specify
538  ** which *links* affect the final position of the vertex.
539  **
540  *b Returns:
541  **
542  ** number of indices in index buffer data returned by
543  ** get_index_buffer_data()
544  */
545  int get_index_count();
546 
547 #ifdef CPLUSPLUS_ONLY
548 
549  /*l
550  *b Returns:
551  **
552  ** size, in bytes, of the data buffer returned by
553  ** get_index_buffer_data()
554  */
555  int get_index_buffer_size();
556 
557  /*l
558  *b Description:
559  **
560  ** This function returns a pointer to the raw index buffer data of
561  ** this mesh. The format of the data can be obtained by calling
562  ** get_index_type().
563  **
564  *b Returns:
565  **
566  ** pointer to raw index buffer data
567  */
568  void* get_index_buffer_data();
569 
570 #endif
571 
572 
573 /*****************************************************************************/
585 #ifdef CPLUSPLUS_ONLY
586 
587  /*l
588  *b Description:
589  **
590  ** This function will be called by DI-Guy when it is time for a
591  ** renderer-specific mesh object to be created. All information
592  ** necessary to build the mesh should be available via the
593  ** Accessor Functions above when this function is called.
594  **
595  *i Immediate Mode:
596  **
597  ** Immediate mode renderers may override this function, to
598  ** create an object that may be invoked by draw().
599  **
600  *i Scene Graph:
601  **
602  ** Scene graph renderers usually do override this function, to
603  ** create a geometry object that gets associated with a
604  ** diguyGraphicsState object obtained by calling get_state().
605  **
606  *b Callable From:
607  **
608  *- - N/A (automatically called by DI-Guy Graphics API during
609  *- the Build Stage)
610  */
611  virtual void build();
612 
613  /*l
614  *b Description:
615  **
616  ** This function will be called by DI-Guy when it is time for a
617  ** renderer-specific mesh object to be destroyed.
618  **
619  *i Immediate Mode:
620  **
621  ** Immediate mode renderers may override this function, to
622  ** destroy any object that may have been created by build().
623  **
624  *i Scene Graph:
625  **
626  ** Scene graph renderers usually do override this function, to
627  ** destroy any object that may have been created by build().
628  **
629  *b Callable From:
630  **
631  *- - N/A (automatically called by DI-Guy Graphics API during
632  *- the Unbuild Stage)
633  */
634  virtual void unbuild();
635 
636  /*l
637  *b Description:
638  **
639  ** This function will be called by DI-Guy when the mesh should
640  ** be drawn. For scene graph renderers, most likely nothing
641  ** more needs to be done by this function.
642  **
643  *b Callable From:
644  **
645  *- - N/A (automatically called by DI-Guy Graphics API during
646  *- Draw Stage)
647  */
648  virtual void draw();
649 
650 
651 
652 #endif
653 
654 /****************************************************************************/
655 /*****************************************************************************/
666 /****************************************************************************/
667 /****************************************************************************/
668 
669 #ifdef CPLUSPLUS_ONLY
670 
671  /*l
672  *b Description:
673  **
674  ** Deprecated as of 10.0.0; use Geometry Data Accessor Functions
675  ** instead. This function can't provide data for all vertex formats
676  ** or index formats that DI-Guy now supports. This function assumes
677  ** that vertex buffer data is in array format, and that indices in
678  ** index buffer data are unsigned shorts. Data for skinned meshes
679  ** can't be represented with this function.
680  */
681  int get_vertex_info(int* num_vertices,
682  float** vertex_array,
683  float** normal_array,
684  float** texture_array,
685  int* index_array_size,
686  unsigned short** index_array);
687 
688 #endif
689 
690 /****************************************************************************/
691 /*****************************************************************************/
699 /****************************************************************************/
700 /****************************************************************************/
701  /*l
702  *b Description:
703  **
704  ** This function will be called by DI-Guy when the mesh for
705  ** and instance group should be drawn. For scene graph
706  ** renderers, most likely nothing more needs to be done
707  ** by this function.
708  **
709  *b Callable From:
710  **
711  *- - N/A (automatically called by DI-Guy Graphics API during
712  *- Draw Stage)
713  */
714  virtual void draw_instance_group(int num_instances);
715 
716 /****************************************************************************/
717 /****************************************************************************/
718 
723 #ifdef CPLUSPLUS_ONLY
724 
725  diguyGraphicsMeshInternalData* get_internal_data() {return m_internal_data;}
726 
727 protected:
728 
729  /*l
730  ** A protected constructor. Constructors are called automatically
731  ** by DI-Guy.
732  */
733  diguyGraphicsMesh(void* internal_data);
735  /*l
736  ** A protected destructor. Destructors are called automatically
737  ** by DI-Guy.
738  */
739  virtual ~diguyGraphicsMesh();
740 
741 private:
742 
743  /*l
744  ** A pointer to internal data.
745  */
746  diguyGraphicsMeshInternalData* m_internal_data;
747 
748  friend class bdiGeometryGeosetMesh;
749  friend class bdiGeometryGeoset;
750  friend class bdiGeometryFactory;
751  friend class diguyGraphicsMeshArray;
752  friend class diguyGraphicsMeshInternalData;
753 
754 
755 #endif
756 };
757 
758 
759 #endif /* __diguyGraphicsMesh_H */
760 
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:37
A class that represents a shared texture. Can be subclassed by filling out the diguy_graphics_set_tex...
Definition: diguyGraphicsTexture.h:124
A class that represents a shared mesh object.
Definition: diguyGraphicsMesh.h:36
diguyGraphicsIndexType
This enumeration lists the types that indices stored in index buffer data might have.
Definition: diguyGraphicsVertexFormats.h:138
This class implements shader programs for use with DI-Guy character graphics.
Definition: diguyGraphicsShaderProgram.h:94
diguyGraphicsVertexFormat
This enumeration lists types of vertex data formats DI-Guy may use.
Definition: diguyGraphicsVertexFormats.h:95