C++ SDK Reference  12.5
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
diguyGraphicsShaderProgram.h
Go to the documentation of this file.
1 
2 /*
3  * Copyright (C) 1992-2013 Boston Dynamics
4  * ALL RIGHTS RESERVED.
5  *
6  * These coded instructions, statements, and computer programs
7  * contain unpublished proprietary information of Boston Dynamics
8  * and are protected by Copyright Laws of the United States.
9  * They may not be used, duplicated, or disclosed in any form, in
10  * whole or in part, without the prior written consent from Boston
11  * Dynamics.
12  *
13  * RESTRICTED RIGHTS LEGEND
14  * Use, duplication, or disclosure by the government is subject
15  * to restrictions as set forth in FAR 52.227.19(c)(2) or
16  * subparagraph (c)(1)(ii) of the Rights in Technical Data and
17  * Computer Software clause at DFARS 252.227-7013 and/or in
18  * similar or successor clauses in the FAR, or the DOD or NASA
19  * FAR Supplement, or to subparagraphs (c)(1) and (c)(2) of the
20  * Commercial Computer Software--Restricted Rights at 48 CFR
21  * 52.227-19, as applicable. Unpublished-rights reserved under
22  * the Copyright Laws of the United States.
23  * Contractor/Manufacturer is:
24  * Boston Dynamics/78 Fourth Avenue/Waltham MA 02451.
25  */
26 
27 /*********************************************************************/
34 #ifndef __diguyGraphicsShaderProgram_H
35 #define __diguyGraphicsShaderProgram_H
36 
37 
38 #ifdef SWIG
40 #else
41 #define CPLUSPLUS_ONLY
42 #endif
43 
44 #ifdef CPLUSPLUS_ONLY
45 #include <diguy_constants.h>
46 #include <declspec_diguy.h>
47 
48 class diguyGraphicsLink;
51 class bdiShaderProgram;
52 
53 /****************************************************************************/
54 
55 #endif
56 
57 
58 /****************************************************************************/
59 /*l
60  *b Description:
61  **
62  ** This enumeration lists the quality level of various shader programs
63  ** that DI-Guy might create.
64  **
65  ** int diguyApp::set_max_character_shader_quality_level(int quality_level);
66  ** int diguyApp::set_max_scene_object_shader_quality_level(int quality_level);
67  */
68 typedef enum
69 {
77 
78 
79 /****************************************************************************/
80 /*l
81  *b Description:
82  **
83  ** This enumeration lists the types of shader programs that DI-Guy
84  ** might request.
85  **
86  *i DIGUY_GRAPHICS_SHADER_PROGRAM_TYPE_GENERAL
87  **
88  *i DIGUY_GRAPHICS_SHADER_PROGRAM_TYPE_SKIN
89  **
90  *i DIGUY_GRAPHICS_SHADER_PROGRAM_TYPE_REFLECTOR
91  **
92  */
93 typedef enum
94 {
99 
101 
102 
103 /****************************************************************************/
119 class BDI_DECLSPEC_diguy diguyGraphicsShaderProgram
120 {
121 
122 public:
123 
124 /*****************************************************************************/
137  /*l
138  *b Returns:
139  **
140  ** name of the shader This pointer will never be NULL.
141  */
142  const char* get_name();
143 
144  /*l
145  *b Returns:
146  **
147  ** the vertex filename of the shader This pointer will never be NULL.
148  */
149  const char* get_vertex_shader_filename();
150 
151  /*l
152  *b Returns:
153  **
154  ** the pixel shader filename of the shader This pointer will never be NULL.
155  */
156  const char* get_pixel_shader_filename();
157 
158  /*l
159  *b Returns:
160  **
161  ** program type of the shader; see diguyGraphicsShaderProgramType
162  */
163  diguyGraphicsShaderProgramType get_shader_type();
164 
165  /*l
166  *b Returns:
167  **
168  ** the quality level type of the shader; see
169  ** diguyGraphicsShaderQualityLevel
170  */
171  diguyGraphicsShaderQualityLevel get_quality_level();
172 
173  /*l
174  *b Description:
175  **
176  ** This function derives filenames for shader programs from the
177  ** provided information.
178  **
179  *b Arguments:
180  **
181  *a result - string buffer in which result should be placed
182  *a result_max_len - size of supplied string buffer; too small will
183  *a result in a truncated filename
184  *a shader_base_name - base name of shader program; e.g. "diguy_character"
185  *a shader_language - language of shader program; e.g. "glsl" or
186  *a "hlsl"
187  *a shader_type - shader program type; e.g. "vert" or "frag"
188  *a include_diguy_default_shader_directory - pass 1 to include the
189  *a default DI-Guy shader directory in the filename;
190  *a pass 0 to return the filename only with no path
191  **
192  ** The constructed filename has the format
193  ** "(shader_base_name)_(shader_language).(shader_type)"; e.g.,
194  ** "diguy_character_glsl.vert".
195  **
196  ** The DI-Guy shader directory defaults to $DIGUY/geometry/shaders.
197  **
198  *b Returns:
199  **
200  ** filename result in the result argument
201  */
202  void derive_diguy_shader_source_filename(char* result,
203  int result_max_len,
204  const char* shader_base_name,
205  const char* shader_language,
206  const char* shader_type,
207  int include_diguy_default_shader_directory);
208 
209  /*l
210  *b Description:
211  **
212  ** Prints information about the shader to the log.
213  */
214  void print_shader_info_to_log();
215 
216 
217  /*l
218  *b Description:
219  **
220  ** Forces the underlying shader to load. Returns 0 on sucess.
221  */
222  int load();
223 
224 /*****************************************************************************/
229  /*l
230  *b Description:
231  **
232  ** Sets a bit mask consisting of diguyTextureMapMasks or'd together
233  ** to specify what textures should bind when this shader is active.
234  **
235  ** See %DIGUY%\programming_examples\diguy_graphics_api\ogl_examples\common\diguyOglGraphicsShaderProgram.cpp
236  ** for an example of usage. By default in the graphics API we attempt
237  ** to bind all textures.
238  */
239  int set_textures_used_bitmask(int texture_bitmask);
240 
241  /*l
242  *b Returns:
243  **
244  ** the current or'd together list of diguyTextureMapMasks that this
245  ** shader attempts to bind. Defaults to
246  ** DIGUY_TEXTURES_MAP_MASK_ALL (0xffffffff)
247  */
248  int get_textures_used_bitmask();
249 
250 
251 /*****************************************************************************/
263 #ifdef CPLUSPLUS_ONLY
264 
265  /*l
266  *b Description:
267  **
268  ** This function will be called by DI-Guy when it is time for the
269  ** vertex part of this shader to be loaded and compiled. The utility
270  ** function derive_diguy_shader_source_filename() can be used to
271  ** convert the passed filename_base to an actual filename.
272  **
273  ** For example, assume that m_vertex_shader_filename is a character
274  ** array of 512 bytes. The following function call would derive an
275  ** appropriate vertex shader filename:
276  **
277  *e derive_diguy_shader_source_filename(m_vertex_shader_filename,
278  *e 511,
279  *e filename_base,
280  *e "glsl",
281  *e "vert",
282  *e 1);
283  **
284  ** This function is called during the Build Stage.
285  **
286  *b Returns:
287  **
288  ** 0 to indicate load was successful, -1 otherwise
289  **
290  *i Immediate Mode:
291  **
292  ** Immediate mode renderers usually do override this function.
293  **
294  *i Scene Graph:
295  **
296  ** Scene graph renderers usually do override this function.
297  **
298  *b Callable From:
299  **
300  *- - N/A (automatically called by DI-Guy Graphics API during
301  *- the Build Stage)
302  */
303  virtual int load_vertex_shader_source(const char* filename_base);
304 
305  /*l
306  *b Description:
307  **
308  ** This function is the pixel shader (AKA fragment shader in OpenGL)
309  ** equivalent of load_vertex_shader_source().
310  */
311  virtual int load_pixel_shader_source(const char* filename_base);
312 
313  /*l
314  *b Description:
315  **
316  ** This function will be called by DI-Guy if this shader program
317  ** should be reloaded. The same filenames derived in the
318  ** load_vertex_shader_source() and load_pixel_shader_source()
319  ** functions should be used.
320  **
321  ** This function can be called during the Update Stage.
322  **
323  *b Returns:
324  **
325  ** 0 to indicate reload was successful, -1 otherwise
326  **
327  *i Immediate Mode:
328  **
329  ** Immediate mode renderers usually do override this function.
330  **
331  *i Scene Graph:
332  **
333  ** Scene graph renderers usually do override this function.
334  **
335  *b Callable From:
336  **
337  *- - N/A (automatically called by DI-Guy Graphics API during
338  *- the Build Stage)
339  */
340  virtual int reload();
341 
342  /*l
343  *b Description:
344  **
345  ** This function will be called by DI-Guy when it is time for the
346  ** shader program to be linked.
347  **
348  ** This function is called during the Build Stage after the
349  ** load_vertex_shader_source() and load_pixel_shader_source()
350  ** functions.
351  **
352  ** Once the link has successfully completed shader variable bind
353  ** indices can be looked up.
354  **
355  *b Returns:
356  **
357  ** 0 to indicate link was successful, -1 otherwise
358  **
359  *i Immediate Mode:
360  **
361  ** Immediate mode renderers usually do override this function.
362  **
363  *i Scene Graph:
364  **
365  ** Scene graph renderers can override this function.
366  **
367  *b Callable From:
368  **
369  *- - N/A (automatically called by DI-Guy Graphics API during
370  *- the Build Stage)
371  */
372  virtual int link();
373 
374  /*l
375  *b Description:
376  **
377  ** Returns whether the shader has been loaded. Note that because a
378  ** shader has been loaded doesn't mean that it is valid. See
379  ** get_valid().
380  **
381  *b Returns:
382  **
383  ** 1 if shader has been loaded; 0 if not
384  */
385  virtual int get_loaded();
386 
387  /*l
388  *b Description:
389  **
390  ** Returns whether the shader has been linked. Note that this only
391  ** means that it is been attempted to link the shader. The link may
392  ** have failed, and the shader not be valid. See get_valid().
393  **
394  *b Returns:
395  **
396  ** 1 if shader has been linked; 0 if not
397  */
398  virtual int get_linked();
399 
400  /*l
401  *b Description:
402  **
403  ** Returns whether shader is valid. An invalid shader will not work
404  ** correctly, leaving graphics that use this shader unshaded. What
405  ** this will look like visually in undetermined.
406  **
407  *b Returns:
408  **
409  ** 1 if shader is valid; 0 if not
410  */
411  virtual int get_valid();
412 
413  /*l
414  *b Description:
415  **
416  ** This function will be called by DI-Guy when this program is being
417  ** bound for rendering.
418  **
419  ** It is during this function call that program level shader
420  ** variables should be set. Program level variables will affect
421  ** *all* shader operations in which this program is active.
422  ** Variables that should affect specific instances of a shader should
423  ** be set in diguyGraphicsShaderInstance::bind().
424  **
425  ** One example in the DI-Guy reference shaders is the
426  ** ufrm_textures_enabled variable. Setting it to 0 will prevent
427  ** textures from being applied during the shader program run.
428  **
429  ** This happens during the Draw Stage.
430  **
431  *i Immediate Mode:
432  **
433  ** Immediate mode renderers can override this function.
434  **
435  *i Scene Graph:
436  **
437  ** Scene graph renderers usually do not override this function; the
438  ** renderer will typically do this internally. If shader variables
439  ** need to be bound, however, this function should be overridden.
440  **
441  *b Callable From:
442  **
443  *- - N/A (automatically called by DI-Guy Graphics API during
444  *- the Draw Stage)
445  */
446  virtual int bind();
447 
448  /*l
449  *b Description:
450  **
451  ** In general variables that were set in bind() should be unset or
452  ** unbound here.
453  **
454  ** This happens during the Draw Stage.
455  **
456  *i Immediate Mode:
457  **
458  ** Immediate mode renderers can override this function.
459  **
460  *i Scene Graph:
461  **
462  ** Scene graph renderers usually do not override this function; the
463  ** renderer will typically do this internally. If the bind()
464  ** function was overridden, however, this function probably should
465  ** be, too.
466  **
467  *b Callable From:
468  **
469  *- - N/A (automatically called by DI-Guy Graphics API during
470  *- the Draw Stage)
471  */
472  virtual int unbind();
473 
474 
475  /*l
476  *b Description:
477  **
478  ** This function will be called by DI-Guy when the matrix data of
479  ** a character's links needs to be sent to the graphics card.
480  **
481  ** For GLSL-based shaders, these values are typically passed into
482  ** the vertex shader via uniform variables.
483  **
484  ** Note that the format of the data in mat_data will be affected by
485  ** the bdiGraphicsInitGraphicsAPI variable
486  ** transpose_shader_matrices value.
487  **
488  *i Immediate Mode:
489  **
490  ** Immediate mode renderers usually do override this function.
491  **
492  *i Scene Graph:
493  **
494  ** Scene graph renderers usually do not override this function,
495  ** but instead use diguyGraphicsShape::get_shader_matrix_data() during the Update Stage.
496  **
497  *b Callable From:
498  **
499  *- - N/A (automatically called by DI-Guy Graphics API during
500  *- the Draw Stage)
501  */
502  virtual int bind_link_matrices(int num_matrices,
503  const float* mat_data);
504 
505  /*l
506  *b Description:
507  **
508  ** This function will be called by DI-Guy when the color data of
509  ** a character's links needs to be sent to the graphics card.
510  **
511  ** For GLSL-based shaders, these values are typically passed into
512  ** the vertex shader via uniform variables.
513  **
514  *b Callable From:
515  **
516  *- - N/A (automatically called by DI-Guy Graphics API during
517  *- the Draw Stage)
518  */
519  virtual int bind_color_array(int num_colors,
520  const float* color_data);
521 
522  /*l
523  *b Description:
524  **
525  ** These functions will be called by DI-Guy when there is a shader
526  ** uniform that needs to be updated and sent to the graphics card.
527  **
528  ** For GLSL-based shaders, these values are typically passed into the
529  ** shader via uniform variables. This function will get repeatedly
530  ** invoked if a character is using per shape materials. See
531  ** diguyGraphicsShape::set_material_parameter_4f() for more
532  ** details.
533  **
534  *b Callable From:
535  **
536  *- - N/A (automatically called by DI-Guy Graphics API during
537  *- the Draw Stage)
538  **
539  *b Arguments:
540  **
541  *a location - the shader uniform to feed this data to, this is the
542  *a value that was retrieved via a call to get_ufrm_bind_location()
543  *a name - string representation of the uniform, useful for debugging
544  *a value_size - number of ints or floats to send to the video card
545  *a values - pointer to ints or floats to send to the video card
546  */
547  virtual int bind_uniform_with_location(int location,
548  const char* name,
549  int value_size,
550  float* values);
551 
552  virtual int bind_uniform_with_location(int location,
553  const char* name,
554  int value_size,
555  int* values);
556 
557  /*l
558  *b Description:
559  **
560  ** This function will be called by DI-Guy when core code is attempting
561  ** to identify the capabilities of the end users shader. Currently
562  ** attribute locations are unused. Return -1 to disable any
563  ** functionality.
564  **
565  */
566  virtual int get_attrib_bind_location(const char* name);
567 
568  /*l
569  *b Description:
570  **
571  ** This function will be called by DI-Guy when core code is attempting
572  ** to identify the capabilities of the end users shader. This needs
573  ** to be implemented to enable per shape advanced materials. Return
574  ** -1 to disable any functionality.
575  **
576  */
577  virtual int get_uniform_bind_location(const char* name);
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);
644  int set_variable_vec2(const char* name, float x, float y, int set_current = 1, int set_initial = 0);
645  int set_variable_vec3(const char* name, float x, float y, float z, int set_current = 1, int set_initial = 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);
647  int set_variable_int(const char* name, int value, int set_current = 1, int set_initial = 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 
664 #ifdef CPLUSPLUS_ONLY
665 
666  bdiShaderProgram* get_internal_data() {return m_internal_data;}
667 
668 protected:
669 
670  /*l
671  ** A protected constructor. Constructors are called automatically
672  ** by DI-Guy.
673  */
674  diguyGraphicsShaderProgram(void* internal_data);
675 
676  /*l
677  ** A protected destructor. Destructors are called automatically
678  ** by DI-Guy.
679  */
681 
682 private:
683 
684  /*l
685  ** A pointer to internal data.
686  */
687  bdiShaderProgram* m_internal_data;
688 
689  friend class bdiShaderProgram;
690  friend class bdiGeometryFactory;
691 #endif
692 };
693 
694 
695 #endif /* __diguyGraphicsShaderProgram_H */
696