![]() |
DI-Guy SDK Documentation
13.7
|
This class implements shader programs for use with DI-Guy character graphics. More...
#include <diguyGraphicsShaderProgram.h>
Public Member Functions | |
Loading functions | |
| int | load () |
| Forces the underlying shader to load. More... | |
| virtual int | reload () |
| Forces the underlying shader to reload. Returns 0 on success. More... | |
| int | get_use_shared_library () |
| Indicates that a shared library (typically diguy_shared_library.glsl) should be prepended to the current shader code. More... | |
| void | set_use_shared_library (int value) |
| void | set_vertex_shader_source_code (const char *shader_source) |
| Sets the source code to use for creating a diguy shader program, bypasses file loading. More... | |
| void | set_pixel_shader_source_code (const char *shader_source) |
| Sets the source code to use for creating a diguy shader program, bypasses file loading. More... | |
Texture Management | |
| int | set_textures_used_bitmask (int texture_bitmask) |
| Sets a bit mask consisting of diguyTextureMapMasks or'd together to specify what textures should bind when this shader is active. More... | |
| int | get_textures_used_bitmask () |
| Returns: the current or'd together list of diguyTextureMapMasks that this shader attempts to bind. More... | |
Virtual Functions | |
The functions in this section are all virtual functions that will be called by DI-Guy at various times during DI-Guy execution. Because the functions are all virtual, DI-Guy programmers can create a subclass of this class and override them. Unless otherwise stated, the base class functions do not need to be called. | |
| virtual int | load_vertex_shader_source (const char *filename_base) |
| This function will be called by DI-Guy when it is time for the vertex part of this shader to be loaded and compiled. More... | |
| virtual int | load_pixel_shader_source (const char *filename_base) |
| This function is the pixel shader (AKA fragment shader in OpenGL) equivalent of load_vertex_shader_source(). More... | |
| virtual int | link () |
| This function will be called by DI-Guy when it is time for the shader program to be linked. More... | |
| virtual int | get_loaded () |
| Returns whether the shader has been loaded. More... | |
| virtual int | get_linked () |
| Returns whether the shader has been linked. More... | |
| virtual int | get_valid () |
| Returns whether shader is valid. More... | |
| virtual int | bind () |
| This function will be called by DI-Guy when this program is being bound for rendering. More... | |
| virtual int | unbind () |
| In general variables that were set in bind() should be unset or unbound here. More... | |
| virtual int | bind_link_matrices (int num_matrices, const float *mat_data) |
| This function will be called by DI-Guy when the matrix data of a character's links needs to be sent to the graphics card. More... | |
| virtual int | bind_color_array (int num_colors, const float *color_data) |
| This function will be called by DI-Guy when the color data of a character's links needs to be sent to the graphics card. More... | |
| virtual int | bind_uniform_with_location (int location, const char *name, int value_size, float *float_values) |
| These functions will be called by DI-Guy when there is a shader uniform that needs to be updated and sent to the graphics card. More... | |
| virtual int | bind_uniform_with_location (int location, const char *name, int value_size, int *int_values) |
| virtual int | get_attrib_bind_location (const char *name) |
| This function will be called by DI-Guy when core code is attempting to identify the capabilities of the end users shader. More... | |
| virtual int | get_uniform_bind_location (const char *name) |
| This function will be called by DI-Guy when core code is attempting to identify the capabilities of the end users shader. More... | |
| virtual int | get_gl_program_object () |
| This function will be called by DI-Guy when core code is attempting to identify send shader low level data Return -1 to disable any functionality. More... | |
| virtual int | get_vertex_attrib_location () const |
| subclass to support particle rendering via abstract interface More... | |
| virtual int | get_color_attrib_location () const |
| virtual int | get_normal_attrib_location () const |
| virtual int | get_texture_attrib_location () const |
Shader Features | |
Shader config files have an optional list of additional features that can be used to data drive program loading. | |
| int | get_num_additional_feature_names () |
| Returns: Number of additional feature strings that this program can support. More... | |
| const char * | get_additional_feature_name (int index) |
| Returns: Name of feature at index in the list. More... | |
| int | has_additional_feature (const char *name) |
| Returns: 0 or 1 if the shader supports this feature. More... | |
Shader Variables | |
For GLSL shaders, these variables are represented internally as uniform variables. DI-Guy reference shaders commonly use the prefix "ufrm_" for their uniform variables. Program level shader variables are shared between all shader instances that use this program. Variables that should affect specific instances associated with individual objects (typically characters and scene objects) should be set at the shader instance level, using equivalent functions in diguyGraphicsShaderInstance. | |
| int | get_num_variables () |
| const char * | get_variable_name_at_index (int index) |
| int | has_variable (const char *name) |
| const char * | get_variable_type (const char *name) |
| int | set_variable_float (const char *name, float value, int set_current=1, int set_initial=0, int create=0) |
| int | set_variable_vec2 (const char *name, float x, float y, int set_current=1, int set_initial=0, int create=0) |
| int | set_variable_vec3 (const char *name, float x, float y, float z, int set_current=1, int set_initial=0, int create=0) |
| 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) |
| int | set_variable_int (const char *name, int value, int set_current=1, int set_initial=0, int create=0) |
| int | get_variable_float (const char *name, float *value, int get_current=1) |
| int | get_variable_vec2 (const char *name, float *x, float *y, int get_current=1) |
| int | get_variable_vec3 (const char *name, float *x, float *y, float *z, int get_current=1) |
| int | get_variable_vec4 (const char *name, float *r, float *g, float *b, float *a, int get_current=1) |
| int | get_variable_int (const char *name, int *value, int get_current=1) |
Experimental Functions | |
The following functions are experimental and may change or disappear with no warning. | |
| virtual void | set_apply_matrices_flag (int apply_matrices_flag) |
| virtual void | set_textures_enabled (int enabled) |
| virtual int | bind_matrix (int bind_location, const float *mat) |
Static Public Member Functions | |
Matrix Format Functions | |
| static int | get_transposed_matrix_data () |
| Returns: The value specified in bdiGraphicsInitGraphicsAPI.transpose_shader_matrices. More... | |
| static int | get_use_4x3_shader_matrix_data () |
| Returns: The value specified in bdiGraphicsInitGraphicsAPI.use_4x3_shader_matrices. More... | |
Accessor Functions | |
The functions in this section provide access to data in this object. They are designed to be called by DI-Guy programmers. All are Callable From:
| |
| const char * | get_name () |
| Returns: name of the shader This pointer will never be NULL. More... | |
| const char * | get_vertex_shader_filename () |
| Returns: the vertex filename of the shader This pointer will never be NULL. More... | |
| const char * | get_pixel_shader_filename () |
| Returns: the pixel shader filename of the shader This pointer will never be NULL. More... | |
| diguyGraphicsShaderProgramType | get_shader_type () |
| Returns: program type of the shader; see diguyGraphicsShaderProgramType. More... | |
| const char * | get_shader_version () |
| Returns: shader version. More... | |
| diguyGraphicsShaderQualityLevel | get_quality_level () |
| Returns: the quality level type of the shader; see diguyGraphicsShaderQualityLevel. More... | |
| void | print_shader_info_to_log () |
| Prints information about the shader to the log. More... | |
| static void | derive_diguy_shader_source_filename (char *result, int result_max_len, const char *shader_base_name, const char *shader_language, const char *shader_type, int include_diguy_default_shader_directory, const char *shader_subdirectory=NULL) |
| This function derives filenames for shader programs from the provided information. More... | |
Private Functions | |
The functions and variables past this point are for internal use only. No external access to them is expected or necessary. | |
| bdiShaderProgram * | m_internal_data |
| A pointer to internal data. More... | |
| class | bdiShaderProgram |
| class | bdiGeometryFactory |
| bdiShaderProgram * | get_internal_data () |
| diguyGraphicsShaderProgram (void *internal_data) | |
| A protected constructor. More... | |
| virtual | ~diguyGraphicsShaderProgram () |
| A protected destructor. More... | |
This class implements shader programs for use with DI-Guy character graphics.
Shader programs are shared among all characters that use the shader program. Any variables used in a shader program should therefore apply to all characters using the shader.
Shader instances are not shared. Each character that has a shader program assigned to it will have a private shader instance in which variables specific to the character or its instance can be stored. A common case for this is current values of shader uniform variables.
Can be subclassed by filling out the diguy_graphics_set_shader_program_create_func().
Also see diguyGraphicsShaderInstance.
|
protected |
A protected constructor.
Constructors are called automatically by DI-Guy.
|
protectedvirtual |
A protected destructor.
Destructors are called automatically by DI-Guy.
| const char* diguyGraphicsShaderProgram::get_name | ( | ) |
Returns: name of the shader This pointer will never be NULL.
| const char* diguyGraphicsShaderProgram::get_vertex_shader_filename | ( | ) |
Returns: the vertex filename of the shader This pointer will never be NULL.
| const char* diguyGraphicsShaderProgram::get_pixel_shader_filename | ( | ) |
Returns: the pixel shader filename of the shader This pointer will never be NULL.
| diguyGraphicsShaderProgramType diguyGraphicsShaderProgram::get_shader_type | ( | ) |
Returns: program type of the shader; see diguyGraphicsShaderProgramType.
| const char* diguyGraphicsShaderProgram::get_shader_version | ( | ) |
Returns: shader version.
| diguyGraphicsShaderQualityLevel diguyGraphicsShaderProgram::get_quality_level | ( | ) |
Returns: the quality level type of the shader; see diguyGraphicsShaderQualityLevel.
|
static |
This function derives filenames for shader programs from the provided information.
| result | string buffer in which result should be placed |
| result_max_len | size of supplied string buffer; too small will result in a truncated filename |
| shader_base_name | base name of shader program; e.g. "diguy_character" |
| shader_language | language of shader program; e.g. "glsl" or "hlsl" |
| shader_type | shader program type; e.g. "vert" or "frag" |
| include_diguy_default_shader_directory | pass 1 to include the |
| default | DI Guy shader directory in the filename; pass 0 to only return the filepath relative to the shader directory (this will include shader_subdirectory, if given). |
The constructed filename has the format "(shader_base_name)_(shader_language).(shader_type)"; e.g., "diguy_character_glsl.vert".
The DI-Guy shader directory defaults to $DIGUY/geometry/shaders. This can be overridden by setting the DIGUY_GEOMETRY_SHADERS environment variable.
Returns:
filename result in the result argument
| void diguyGraphicsShaderProgram::print_shader_info_to_log | ( | ) |
Prints information about the shader to the log.
| int diguyGraphicsShaderProgram::load | ( | ) |
Forces the underlying shader to load.
Returns 0 on success.
|
virtual |
Forces the underlying shader to reload. Returns 0 on success.
Reimplemented in diguyDx9GraphicsShaderProgram, and diguyDx11GraphicsShaderProgram.
| int diguyGraphicsShaderProgram::get_use_shared_library | ( | ) |
Indicates that a shared library (typically diguy_shared_library.glsl) should be prepended to the current shader code.
Currently the cleanest way to access the DI-Guy uniform buffer system.
| void diguyGraphicsShaderProgram::set_use_shared_library | ( | int | value | ) |
| void diguyGraphicsShaderProgram::set_vertex_shader_source_code | ( | const char * | shader_source | ) |
Sets the source code to use for creating a diguy shader program, bypasses file loading.
See sensor fusion example for demo of it's use in DI-Guy Scenario
| void diguyGraphicsShaderProgram::set_pixel_shader_source_code | ( | const char * | shader_source | ) |
Sets the source code to use for creating a diguy shader program, bypasses file loading.
See sensor fusion example for demo of it's use in DI-Guy Scenario.
| int diguyGraphicsShaderProgram::set_textures_used_bitmask | ( | int | texture_bitmask | ) |
Sets a bit mask consisting of diguyTextureMapMasks or'd together to specify what textures should bind when this shader is active.
See $DIGUY/programming_examples/diguy_graphics_api/ogl_examples/common/diguyOglGraphicsShaderProgram.cpp for an example of usage. By default in the graphics API we attempt to bind all textures.
| int diguyGraphicsShaderProgram::get_textures_used_bitmask | ( | ) |
Returns: the current or'd together list of diguyTextureMapMasks that this shader attempts to bind.
Defaults to DIGUY_TEXTURES_MAP_MASK_ALL (0xffffffff)
|
virtual |
This function will be called by DI-Guy when it is time for the vertex part of this shader to be loaded and compiled.
The utility function derive_diguy_shader_source_filename() can be used to convert the passed filename_base to an actual filename.
For example, assume that m_vertex_shader_filename is a character array of 512 bytes. The following function call would derive an appropriate vertex shader filename:
This function is called during the Build Stage.
Returns:
0 to indicate load was successful, -1 otherwise
Immediate Mode:
Immediate mode renderers usually do override this function.
Scene Graph:
Scene graph renderers usually do override this function.
Callable From:
Reimplemented in diguyOglGraphicsShaderProgram, diguyOsgGraphicsShaderProgram, diguyDx9GraphicsShaderProgram, and diguyDx11GraphicsShaderProgram.
|
virtual |
This function is the pixel shader (AKA fragment shader in OpenGL) equivalent of load_vertex_shader_source().
Reimplemented in diguyOglGraphicsShaderProgram, diguyOsgGraphicsShaderProgram, diguyDx9GraphicsShaderProgram, and diguyDx11GraphicsShaderProgram.
|
virtual |
This function will be called by DI-Guy when it is time for the shader program to be linked.
This function is called during the Build Stage after the load_vertex_shader_source() and load_pixel_shader_source() functions.
Once the link has successfully completed shader variable bind indices can be looked up.
Returns:
0 to indicate link was successful, -1 otherwise
Immediate Mode:
Immediate mode renderers usually do override this function.
Scene Graph:
Scene graph renderers can override this function.
Callable From:
Reimplemented in diguyOglGraphicsShaderProgram, diguyOsgGraphicsShaderProgram, diguyDx9GraphicsShaderProgram, and diguyDx11GraphicsShaderProgram.
|
virtual |
Returns whether the shader has been loaded.
Note that because a shader has been loaded doesn't mean that it is valid. See get_valid().
Returns:
1 if shader has been loaded; 0 if not
|
virtual |
Returns whether the shader has been linked.
Note that this only means that it is been attempted to link the shader. The link may have failed, and the shader not be valid. See get_valid().
Returns:
1 if shader has been linked; 0 if not
|
virtual |
Returns whether shader is valid.
An invalid shader will not work correctly, leaving graphics that use this shader unshaded. What this will look like visually in undetermined.
Returns:
1 if shader is valid; 0 if not
|
virtual |
This function will be called by DI-Guy when this program is being bound for rendering.
It is during this function call that program level shader variables should be set. Program level variables will affect all shader operations in which this program is active. Variables that should affect specific instances of a shader should be set in diguyGraphicsShaderInstance::bind().
One example in the DI-Guy reference shaders is the ufrm_textures_enabled variable. Setting it to 0 will prevent textures from being applied during the shader program run.
This happens during the Draw Stage.
Immediate Mode:
Immediate mode renderers can override this function.
Scene Graph:
Scene graph renderers usually do not override this function; the renderer will typically do this internally. If shader variables need to be bound, however, this function should be overridden.
Callable From:
Reimplemented in diguyOglGraphicsShaderProgram, diguyDx9GraphicsShaderProgram, and diguyDx11GraphicsShaderProgram.
|
virtual |
In general variables that were set in bind() should be unset or unbound here.
This happens during the Draw Stage.
Immediate Mode:
Immediate mode renderers can override this function.
Scene Graph:
Scene graph renderers usually do not override this function; the renderer will typically do this internally. If the bind() function was overridden, however, this function probably should be, too.
Callable From:
Reimplemented in diguyOglGraphicsShaderProgram, diguyDx9GraphicsShaderProgram, and diguyDx11GraphicsShaderProgram.
|
virtual |
This function will be called by DI-Guy when the matrix data of a character's links needs to be sent to the graphics card.
For GLSL-based shaders, these values are typically passed into the vertex shader via uniform variables.
Note that the format of the data in mat_data will be affected by the bdiGraphicsInitGraphicsAPI variable transpose_shader_matrices value.
Immediate Mode:
Immediate mode renderers usually do override this function.
Scene Graph:
Scene graph renderers usually do not override this function, but instead use diguyGraphicsShape::get_shader_matrix_data() during the Update Stage.
Callable From:
Reimplemented in diguyOglGraphicsShaderProgram, diguyDx9GraphicsShaderProgram, and diguyDx11GraphicsShaderProgram.
|
virtual |
This function will be called by DI-Guy when the color data of a character's links needs to be sent to the graphics card.
For GLSL-based shaders, these values are typically passed into the vertex shader via uniform variables.
Callable From:
Reimplemented in diguyOglGraphicsShaderProgram, diguyDx9GraphicsShaderProgram, and diguyDx11GraphicsShaderProgram.
|
virtual |
These functions will be called by DI-Guy when there is a shader uniform that needs to be updated and sent to the graphics card.
For GLSL-based shaders, these values are typically passed into the shader via uniform variables. This function will get repeatedly invoked if a character is using per shape materials. See diguyGraphicsShape::set_material_parameter_4f() for more details.
Callable From:
| location | the shader uniform to feed this data to, this is the value that was retrieved via a call to get_ufrm_bind_location() |
| name | string representation of the uniform, useful for debugging |
| value_size | number of ints or floats to send to the video card |
| values | pointer to ints or floats to send to the video card |
Reimplemented in diguyOglGraphicsShaderProgram.
|
virtual |
Reimplemented in diguyOglGraphicsShaderProgram.
|
virtual |
This function will be called by DI-Guy when core code is attempting to identify the capabilities of the end users shader.
Currently attribute locations are unused. Return -1 to disable any functionality.
Reimplemented in diguyOglGraphicsShaderProgram.
|
virtual |
This function will be called by DI-Guy when core code is attempting to identify the capabilities of the end users shader.
This needs to be implemented to enable per shape advanced materials. Return -1 to disable any functionality.
Reimplemented in diguyOglGraphicsShaderProgram.
|
virtual |
This function will be called by DI-Guy when core code is attempting to identify send shader low level data Return -1 to disable any functionality.
Reimplemented in diguyOglGraphicsShaderProgram.
|
virtual |
subclass to support particle rendering via abstract interface
|
virtual |
|
virtual |
|
virtual |
| int diguyGraphicsShaderProgram::get_num_additional_feature_names | ( | ) |
Returns: Number of additional feature strings that this program can support.
| const char* diguyGraphicsShaderProgram::get_additional_feature_name | ( | int | index | ) |
Returns: Name of feature at index in the list.
| int diguyGraphicsShaderProgram::has_additional_feature | ( | const char * | name | ) |
Returns: 0 or 1 if the shader supports this feature.
|
static |
Returns: The value specified in bdiGraphicsInitGraphicsAPI.transpose_shader_matrices.
Indicates if DI-Guy will attempt to transpose 4x4 matrices before sending to video card.
|
static |
Returns: The value specified in bdiGraphicsInitGraphicsAPI.use_4x3_shader_matrices.
Indicates if DI-Guy is sending 4x3 matrix data instead of 4x4 data.
| int diguyGraphicsShaderProgram::get_num_variables | ( | ) |
| const char* diguyGraphicsShaderProgram::get_variable_name_at_index | ( | int | index | ) |
| int diguyGraphicsShaderProgram::has_variable | ( | const char * | name | ) |
| const char* diguyGraphicsShaderProgram::get_variable_type | ( | const char * | name | ) |
| int diguyGraphicsShaderProgram::set_variable_float | ( | const char * | name, |
| float | value, | ||
| int | set_current = 1, |
||
| int | set_initial = 0, |
||
| int | create = 0 |
||
| ) |
| int diguyGraphicsShaderProgram::set_variable_vec2 | ( | const char * | name, |
| float | x, | ||
| float | y, | ||
| int | set_current = 1, |
||
| int | set_initial = 0, |
||
| int | create = 0 |
||
| ) |
| int diguyGraphicsShaderProgram::set_variable_vec3 | ( | const char * | name, |
| float | x, | ||
| float | y, | ||
| float | z, | ||
| int | set_current = 1, |
||
| int | set_initial = 0, |
||
| int | create = 0 |
||
| ) |
| int diguyGraphicsShaderProgram::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 |
||
| ) |
| int diguyGraphicsShaderProgram::set_variable_int | ( | const char * | name, |
| int | value, | ||
| int | set_current = 1, |
||
| int | set_initial = 0, |
||
| int | create = 0 |
||
| ) |
| int diguyGraphicsShaderProgram::get_variable_float | ( | const char * | name, |
| float * | value, | ||
| int | get_current = 1 |
||
| ) |
| int diguyGraphicsShaderProgram::get_variable_vec2 | ( | const char * | name, |
| float * | x, | ||
| float * | y, | ||
| int | get_current = 1 |
||
| ) |
| int diguyGraphicsShaderProgram::get_variable_vec3 | ( | const char * | name, |
| float * | x, | ||
| float * | y, | ||
| float * | z, | ||
| int | get_current = 1 |
||
| ) |
| int diguyGraphicsShaderProgram::get_variable_vec4 | ( | const char * | name, |
| float * | r, | ||
| float * | g, | ||
| float * | b, | ||
| float * | a, | ||
| int | get_current = 1 |
||
| ) |
| int diguyGraphicsShaderProgram::get_variable_int | ( | const char * | name, |
| int * | value, | ||
| int | get_current = 1 |
||
| ) |
|
inlinevirtual |
Reimplemented in diguyOglGraphicsShaderProgram, diguyDx9GraphicsShaderProgram, and diguyDx11GraphicsShaderProgram.
|
inlinevirtual |
Reimplemented in diguyOglGraphicsShaderProgram.
|
inlinevirtual |
Reimplemented in diguyOglGraphicsShaderProgram.
|
inline |
|
friend |
|
friend |
|
private |
A pointer to internal data.