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