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