DI-Guy SDK Documentation  13.2
diguyGraphicsShaderProgram.h
Go to the documentation of this file.
1 
2 /*********************************************************************
3  ** Copyright (c) 1992-2019 VT MAK
4  ** All rights reserved.
5  *********************************************************************/
6 
7 /*********************************************************************/
14 #ifndef __diguyGraphicsShaderProgram_H
15 #define __diguyGraphicsShaderProgram_H
16 
17 
18 #ifdef SWIG
20 #else
21 #define CPLUSPLUS_ONLY
22 #endif
23 
24 #ifdef CPLUSPLUS_ONLY
25 #include <declspec_diguy.h>
26 #endif
27 #include <diguy_constants.h>
28 #include <stdlib.h>
29 
30 class diguyGraphicsLink;
33 class bdiShaderProgram;
35 class diguyViewFog;
38 
39 
40 
41 /****************************************************************************/
42 /*l
43  *b Description:
44  **
45  ** This enumeration lists the quality level of various shader programs
46  ** that DI-Guy might create.
47  **
48  ** int diguyApp::set_max_character_shader_quality_level(int quality_level);
49  ** int diguyApp::set_max_scene_object_shader_quality_level(int quality_level);
50  */
51 typedef enum
52 {
60 
61 
62 /****************************************************************************/
63 /*l
64  *b Description:
65  **
66  ** This enumeration lists the types of shader programs that DI-Guy
67  ** might request.
68  **
69  *i DIGUY_GRAPHICS_SHADER_PROGRAM_TYPE_GENERAL
70  **
71  *i DIGUY_GRAPHICS_SHADER_PROGRAM_TYPE_SKIN
72  **
73  *i DIGUY_GRAPHICS_SHADER_PROGRAM_TYPE_REFLECTOR
74  **
75  */
76 typedef enum
77 {
82 
84 
85 
104 class BDI_DECLSPEC_diguy diguyGraphicsShaderProgram
105 {
106 
107 public:
108 
109 /*****************************************************************************/
122  /*l
123  *b Returns:
124  **
125  ** name of the shader This pointer will never be NULL.
126  */
127  const char* get_name();
128 
129  /*l
130  *b Returns:
131  **
132  ** the vertex filename of the shader This pointer will never be NULL.
133  */
134  const char* get_vertex_shader_filename();
135 
136  /*l
137  *b Returns:
138  **
139  ** the pixel shader filename of the shader This pointer will never be NULL.
140  */
141  const char* get_pixel_shader_filename();
142 
143  /*l
144  *b Returns:
145  **
146  ** program type of the shader; see diguyGraphicsShaderProgramType
147  */
148  diguyGraphicsShaderProgramType get_shader_type();
149 
150  /*l
151  *b Returns:
152  **
153  ** shader version
154  */
155  const char* get_shader_version();
156 
157  /*l
158  *b Returns:
159  **
160  ** the quality level type of the shader; see
161  ** diguyGraphicsShaderQualityLevel
162  */
163  diguyGraphicsShaderQualityLevel get_quality_level();
164 
165  /*l
166  *b Description:
167  **
168  ** This function derives filenames for shader programs from the
169  ** provided information.
170  **
171  *b Arguments:
172  **
173  *a result - string buffer in which result should be placed
174  *a result_max_len - size of supplied string buffer; too small will
175  *a result in a truncated filename
176  *a shader_base_name - base name of shader program; e.g. "diguy_character"
177  *a shader_language - language of shader program; e.g. "glsl" or
178  *a "hlsl"
179  *a shader_type - shader program type; e.g. "vert" or "frag"
180  *a include_diguy_default_shader_directory - pass 1 to include the
181  *a default DI-Guy shader directory in the filename;
182  *a pass 0 to return the filename only with no path
183  **
184  ** The constructed filename has the format
185  ** "(shader_base_name)_(shader_language).(shader_type)"; e.g.,
186  ** "diguy_character_glsl.vert".
187  **
188  ** The DI-Guy shader directory defaults to $DIGUY/geometry/shaders.
189  **
190  *b Returns:
191  **
192  ** filename result in the result argument
193  */
194  void derive_diguy_shader_source_filename(char* result,
195  int result_max_len,
196  const char* shader_base_name,
197  const char* shader_language,
198  const char* shader_type,
199  int include_diguy_default_shader_directory,
200  const char* shader_subdirectory = NULL);
201 
202  /*l
203  *b Description:
204  **
205  ** Prints information about the shader to the log.
206  */
207  void print_shader_info_to_log();
208 
209 /*****************************************************************************/
214  /*l
215  *b Description:
216  ** Forces the underlying shader to load. Returns 0 on success.
217  */
218  int load();
219 
221  virtual int reload();
222 
226  int get_use_shared_library();
227  void set_use_shared_library(int value);
228 
231  void set_vertex_shader_source_code(const char * shader_source);
232 
235  void set_pixel_shader_source_code(const char * shader_source);
236 
237 /*****************************************************************************/
242  /*l
243  *b Description:
244  **
245  ** Sets a bit mask consisting of diguyTextureMapMasks or'd together
246  ** to specify what textures should bind when this shader is active.
247  **
248  ** See $DIGUY/programming_examples/diguy_graphics_api/ogl_examples/common/diguyOglGraphicsShaderProgram.cpp
249  ** for an example of usage. By default in the graphics API we attempt
250  ** to bind all textures.
251  */
252  int set_textures_used_bitmask(int texture_bitmask);
253 
254  /*l
255  *b Returns:
256  **
257  ** the current or'd together list of diguyTextureMapMasks that this
258  ** shader attempts to bind. Defaults to
259  ** DIGUY_TEXTURES_MAP_MASK_ALL (0xffffffff)
260  */
261  int get_textures_used_bitmask();
262 
263 
264 /*****************************************************************************/
276 #ifdef CPLUSPLUS_ONLY
277 
278  /*l
279  *b Description:
280  **
281  ** This function will be called by DI-Guy when it is time for the
282  ** vertex part of this shader to be loaded and compiled. The utility
283  ** function derive_diguy_shader_source_filename() can be used to
284  ** convert the passed filename_base to an actual filename.
285  **
286  ** For example, assume that m_vertex_shader_filename is a character
287  ** array of 512 bytes. The following function call would derive an
288  ** appropriate vertex shader filename:
289  **
290  *e derive_diguy_shader_source_filename(m_vertex_shader_filename,
291  *e 511,
292  *e filename_base,
293  *e "glsl",
294  *e "vert",
295  *e 1);
296  **
297  ** This function is called during the Build Stage.
298  **
299  *b Returns:
300  **
301  ** 0 to indicate load was successful, -1 otherwise
302  **
303  *i Immediate Mode:
304  **
305  ** Immediate mode renderers usually do override this function.
306  **
307  *i Scene Graph:
308  **
309  ** Scene graph renderers usually do override this function.
310  **
311  *b Callable From:
312  **
313  *- - N/A (automatically called by DI-Guy Graphics API during
314  *- the Build Stage)
315  */
316  virtual int load_vertex_shader_source(const char* filename_base);
317 
318  /*l
319  *b Description:
320  **
321  ** This function is the pixel shader (AKA fragment shader in OpenGL)
322  ** equivalent of load_vertex_shader_source().
323  */
324  virtual int load_pixel_shader_source(const char* filename_base);
325 
326 
327  /*l
328  *b Description:
329  **
330  ** This function will be called by DI-Guy when it is time for the
331  ** shader program to be linked.
332  **
333  ** This function is called during the Build Stage after the
334  ** load_vertex_shader_source() and load_pixel_shader_source()
335  ** functions.
336  **
337  ** Once the link has successfully completed shader variable bind
338  ** indices can be looked up.
339  **
340  *b Returns:
341  **
342  ** 0 to indicate link was successful, -1 otherwise
343  **
344  *i Immediate Mode:
345  **
346  ** Immediate mode renderers usually do override this function.
347  **
348  *i Scene Graph:
349  **
350  ** Scene graph renderers can override this function.
351  **
352  *b Callable From:
353  **
354  *- - N/A (automatically called by DI-Guy Graphics API during
355  *- the Build Stage)
356  */
357  virtual int link();
358 
359  /*l
360  *b Description:
361  **
362  ** Returns whether the shader has been loaded. Note that because a
363  ** shader has been loaded doesn't mean that it is valid. See
364  ** get_valid().
365  **
366  *b Returns:
367  **
368  ** 1 if shader has been loaded; 0 if not
369  */
370  virtual int get_loaded();
371 
372  /*l
373  *b Description:
374  **
375  ** Returns whether the shader has been linked. Note that this only
376  ** means that it is been attempted to link the shader. The link may
377  ** have failed, and the shader not be valid. See get_valid().
378  **
379  *b Returns:
380  **
381  ** 1 if shader has been linked; 0 if not
382  */
383  virtual int get_linked();
384 
385  /*l
386  *b Description:
387  **
388  ** Returns whether shader is valid. An invalid shader will not work
389  ** correctly, leaving graphics that use this shader unshaded. What
390  ** this will look like visually in undetermined.
391  **
392  *b Returns:
393  **
394  ** 1 if shader is valid; 0 if not
395  */
396  virtual int get_valid();
397 
398  /*l
399  *b Description:
400  **
401  ** This function will be called by DI-Guy when this program is being
402  ** bound for rendering.
403  **
404  ** It is during this function call that program level shader
405  ** variables should be set. Program level variables will affect
406  ** *all* shader operations in which this program is active.
407  ** Variables that should affect specific instances of a shader should
408  ** be set in diguyGraphicsShaderInstance::bind().
409  **
410  ** One example in the DI-Guy reference shaders is the
411  ** ufrm_textures_enabled variable. Setting it to 0 will prevent
412  ** textures from being applied during the shader program run.
413  **
414  ** This happens during the Draw Stage.
415  **
416  *i Immediate Mode:
417  **
418  ** Immediate mode renderers can override this function.
419  **
420  *i Scene Graph:
421  **
422  ** Scene graph renderers usually do not override this function; the
423  ** renderer will typically do this internally. If shader variables
424  ** need to be bound, however, this function should be overridden.
425  **
426  *b Callable From:
427  **
428  *- - N/A (automatically called by DI-Guy Graphics API during
429  *- the Draw Stage)
430  */
431  virtual int bind();
432 
433  /*l
434  *b Description:
435  **
436  ** In general variables that were set in bind() should be unset or
437  ** unbound here.
438  **
439  ** This happens during the Draw Stage.
440  **
441  *i Immediate Mode:
442  **
443  ** Immediate mode renderers can override this function.
444  **
445  *i Scene Graph:
446  **
447  ** Scene graph renderers usually do not override this function; the
448  ** renderer will typically do this internally. If the bind()
449  ** function was overridden, however, this function probably should
450  ** be, too.
451  **
452  *b Callable From:
453  **
454  *- - N/A (automatically called by DI-Guy Graphics API during
455  *- the Draw Stage)
456  */
457  virtual int unbind();
458 
459 
460  /*l
461  *b Description:
462  **
463  ** This function will be called by DI-Guy when the matrix data of
464  ** a character's links needs to be sent to the graphics card.
465  **
466  ** For GLSL-based shaders, these values are typically passed into
467  ** the vertex shader via uniform variables.
468  **
469  ** Note that the format of the data in mat_data will be affected by
470  ** the bdiGraphicsInitGraphicsAPI variable
471  ** transpose_shader_matrices value.
472  **
473  *i Immediate Mode:
474  **
475  ** Immediate mode renderers usually do override this function.
476  **
477  *i Scene Graph:
478  **
479  ** Scene graph renderers usually do not override this function,
480  ** but instead use diguyGraphicsShape::get_shader_matrix_data() during the Update Stage.
481  **
482  *b Callable From:
483  **
484  *- - N/A (automatically called by DI-Guy Graphics API during
485  *- the Draw Stage)
486  */
487  virtual int bind_link_matrices(int num_matrices,
488  const float* mat_data);
489 
490  /*l
491  *b Description:
492  **
493  ** This function will be called by DI-Guy when the color data of
494  ** a character's links needs to be sent to the graphics card.
495  **
496  ** For GLSL-based shaders, these values are typically passed into
497  ** the vertex shader via uniform variables.
498  **
499  *b Callable From:
500  **
501  *- - N/A (automatically called by DI-Guy Graphics API during
502  *- the Draw Stage)
503  */
504  virtual int bind_color_array(int num_colors,
505  const float* color_data);
506 
507  /*l
508  *b Description:
509  **
510  ** These functions will be called by DI-Guy when there is a shader
511  ** uniform that needs to be updated and sent to the graphics card.
512  **
513  ** For GLSL-based shaders, these values are typically passed into the
514  ** shader via uniform variables. This function will get repeatedly
515  ** invoked if a character is using per shape materials. See
516  ** diguyGraphicsShape::set_material_parameter_4f() for more
517  ** details.
518  **
519  *b Callable From:
520  **
521  *- - N/A (automatically called by DI-Guy Graphics API during
522  *- the Draw Stage)
523  **
524  *b Arguments:
525  **
526  *a location - the shader uniform to feed this data to, this is the
527  *a value that was retrieved via a call to get_ufrm_bind_location()
528  *a name - string representation of the uniform, useful for debugging
529  *a value_size - number of ints or floats to send to the video card
530  *a values - pointer to ints or floats to send to the video card
531  */
532  virtual int bind_uniform_with_location(int location,
533  const char* name,
534  int value_size,
535  float* float_values);
536 
537  virtual int bind_uniform_with_location(int location,
538  const char* name,
539  int value_size,
540  int* int_values);
541 
542 
543  /*l
544  *b Description:
545  **
546  ** This function will be called by DI-Guy when core code is attempting
547  ** to identify the capabilities of the end users shader. Currently
548  ** attribute locations are unused. Return -1 to disable any
549  ** functionality.
550  **
551  */
552  virtual int get_attrib_bind_location(const char* name);
553 
554  /*l
555  *b Description:
556  **
557  ** This function will be called by DI-Guy when core code is attempting
558  ** to identify the capabilities of the end users shader. This needs
559  ** to be implemented to enable per shape advanced materials. Return
560  ** -1 to disable any functionality.
561  **
562  */
563  virtual int get_uniform_bind_location(const char* name);
564 
565 
566  /*l
567  *b Description:
568  **
569  ** This function will be called by DI-Guy when core code is attempting
570  ** to identify send shader low level data Return
571  ** -1 to disable any functionality.
572  **
573  */
574  virtual int get_gl_program_object();
575 
577  virtual int get_vertex_attrib_location() const;
578  virtual int get_color_attrib_location() const;
579  virtual int get_normal_attrib_location() const;
580  virtual int get_texture_attrib_location() const;
581 
582 
583 #endif
584 
585 
586 /*****************************************************************************/
595  int get_num_additional_feature_names();
596 
598  const char * get_additional_feature_name(int index);
599 
601  int has_additional_feature(const char * name);
602 
603 /*****************************************************************************/
608  /*l
609  *b Returns:
610  **
611  ** The value specified in bdiGraphicsInitGraphicsAPI.transpose_shader_matrices.
612  ** Indicates if DI-Guy will attempt to transpose 4x4 matrices before sending to
613  ** video card.
614  */
615  static int get_transposed_matrix_data();
616 
617  /*l
618  *b Returns:
619  **
620  ** The value specified in bdiGraphicsInitGraphicsAPI.use_4x3_shader_matrices.
621  ** Indicates if DI-Guy is sending 4x3 matrix data instead of 4x4 data.
622  */
623  static int get_use_4x3_shader_matrix_data();
624 
625 /*****************************************************************************/
641  int get_num_variables();
642  const char* get_variable_name_at_index(int index);
643  int has_variable(const char* name);
644  const char* get_variable_type(const char* name);
646  int set_variable_float(const char* name, float value, int set_current = 1, int set_initial = 0, int create = 0);
647  int set_variable_vec2(const char* name, float x, float y, int set_current = 1, int set_initial = 0, int create = 0);
648  int set_variable_vec3(const char* name, float x, float y, float z, int set_current = 1, int set_initial = 0, int create = 0);
649  int set_variable_vec4(const char* name, float x, float y, float z, float w, int set_current = 1, int set_initial = 0, int create = 0);
650  int set_variable_int(const char* name, int value, int set_current = 1, int set_initial = 0, int create = 0);
651 
652  int get_variable_float(const char* name, float* value, int get_current = 1);
653  int get_variable_vec2(const char* name, float* x, float* y, int get_current = 1);
654  int get_variable_vec3(const char* name, float* x, float* y, float* z, int get_current = 1);
655  int get_variable_vec4(const char* name, float* r, float* g, float* b, float* a, int get_current = 1);
656  int get_variable_int(const char* name, int* value, int get_current = 1);
657 
658 
659 /****************************************************************************/
660 /****************************************************************************/
661 /****************************************************************************/
668 /****************************************************************************/
669  virtual void set_apply_matrices_flag(int apply_matrices_flag){;}
670  virtual void set_textures_enabled(int enabled){;}
671 
672  virtual int bind_matrix(int bind_location, const float* mat){ return 0; }
673 
674 /****************************************************************************/
675 /****************************************************************************/
676 
677 /****************************************************************************/
678 /****************************************************************************/
679 
685 #ifdef CPLUSPLUS_ONLY
686 
687  bdiShaderProgram* get_internal_data() {return m_internal_data;}
688 
689 protected:
690 
691  /*l
692  ** A protected constructor. Constructors are called automatically
693  ** by DI-Guy.
694  */
695  diguyGraphicsShaderProgram(void* internal_data);
696 
697  /*l
698  ** A protected destructor. Destructors are called automatically
699  ** by DI-Guy.
700  */
701  virtual ~diguyGraphicsShaderProgram();
702 
703 private:
704 
705  /*l
706  ** A pointer to internal data.
707  */
708  bdiShaderProgram* m_internal_data;
709 
710  friend class bdiShaderProgram;
711  friend class bdiGeometryFactory;
712 #endif
713 };
714 
715 
716 #endif /* __diguyGraphicsShaderProgram_H */
717 
This class is an abstract wrapper around shader constants for use with DI-Guy rendering.
Definition: diguyUniformBufferUpdater.h:61
A class that represents the unique per-character shader object.
Definition: diguyGraphicsShaderInstance.h:55
Definition: diguyGraphicsShaderProgram.h:49
Definition: diguyGraphicsShaderProgram.h:52
Definition: diguyGraphicsShaderProgram.h:48
Definition: diguyGraphicsShaderProgram.h:72
Definition: diguyGraphicsShaderProgram.h:53
Definition: diguyGraphicsShaderProgram.h:71
Definition: diguyGraphicsShaderProgram.h:50
A class that represents a shared material.
Definition: diguyGraphicsMaterial.h:42
Definition: diguyGraphicsShaderProgram.h:73
diguyGraphicsShaderProgramType
This enumeration lists the types of shader programs that DI-Guy might request.
Definition: diguyGraphicsShaderProgram.h:69
diguyGraphicsShaderQualityLevel
This enumeration lists the quality level of various shader programs that DI-Guy might create...
Definition: diguyGraphicsShaderProgram.h:46
This class is a simple structure for transmitting diguy lights down to the uniform buffer system this...
Definition: diguyViewLight.h:36
Definition: diguyViewFog.h:35
This class implements shader programs for use with DI-Guy character graphics.
Definition: diguyGraphicsShaderProgram.h:96
Definition: diguyGraphicsShaderProgram.h:74
Definition: diguyGraphicsShaderProgram.h:51