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