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