DI-Guy SDK Documentation  13.2
diguyOglGraphicsShaderProgram Class Reference

This class is part of the DI-Guy Graphics API. More...

#include <diguyOglGraphicsShaderProgram.h>

Inheritance diagram for diguyOglGraphicsShaderProgram:
diguyGraphicsShaderProgram

Public Member Functions

 diguyOglGraphicsShaderProgram (void *internal_data)
 
 ~diguyOglGraphicsShaderProgram ()
 
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 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 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 void set_apply_matrices_flag (int apply_matrices_flag)
 
virtual void set_textures_enabled (int enabled)
 
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_matrix (int bind_location, const float *mat_data)
 
virtual int bind_link_matrices (int num_mats, 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_uniform_with_location (int location, const char *name, int value_size, 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 *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...
 
diguyOglUniformBufferUpdaterget_ogl_uniform_buffer_updater ()
 
- Public Member Functions inherited from diguyGraphicsShaderProgram
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 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...
 
void print_shader_info_to_log ()
 Prints information about the shader to the log. More...
 
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...
 
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 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 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
 
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...
 
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)
 
bdiShaderProgramget_internal_data ()
 

Public Attributes

int m_bind_location_attr_color
 needed for IM and particle systems More...
 
int m_bind_location_attr_vertex
 base default attrib locations More...
 
int m_bind_location_attr_normal
 
int m_bind_location_attr_texture
 
int m_bind_location_attr_tangent
 Per vertex tangent for bump mapping. More...
 
int m_bind_location_attr_weight_array
 Skeletal animation bone weight. More...
 
int m_bind_location_attr_index_array
 Skeletal animation bone index. More...
 
int m_bind_location_attr_blend_vertex
 blend shape per vertex attributes More...
 
int m_bind_location_attr_blend_normal
 
int m_bind_location_attr_blend_tangent
 
int m_bind_location_ufrm_blend_weight
 uniform for controlling the amount of a blend shape More...
 
int m_bind_location_ufrm_emission_color
 uniform for controlling emission color More...
 
int m_bind_location_ufrm_apply_matrices_flag
 should bone matrices be used for this drawable, if 0 assumed to be a rigid drawable More...
 
int m_bind_location_ufrm_link_matrix
 matrix used to transform a rigid drawable More...
 
int m_bind_location_ufrm_link_matrices
 matrix array used to transform a skinned mesh More...
 
int m_bind_location_ufrm_link_colors
 Uniform for sending bone link colors, needed for per pixel intersection tests. More...
 
int m_bind_location_ufrm_link_matrices_tbo
 Instancing uniforms: More...
 
int m_bind_location_ufrm_base_matrices_start
 
int m_bind_location_ufrm_base_matrices_count
 
int m_bind_location_ufrm_link_matrices_start
 
int m_bind_location_ufrm_link_matrices_count
 
int m_bind_location_ufrm_extra_per_instance_data
 
int m_bind_location_ufrm_pbr_enabled
 General state variables. More...
 
int m_bind_location_ufrm_textures_enabled
 
int m_bind_location_ufrm_bump_map_enabled
 
int m_bind_location_ufrm_specular_map_enabled
 
int m_bind_location_ufrm_component_map_enabled
 
int m_bind_location_ufrm_misc_1_map_enabled
 
int m_bind_location_ufrm_misc_2_map_enabled
 
int m_bind_location_ufrm_component_row
 uniform to control which row of the shared variation texture to use for this draw call More...
 
int m_ubo_transform_block_index
 
int m_ubo_material_block_index
 
int m_ubo_per_frame_block_index
 
int m_include_point_lights
 

Static Public Attributes

static int s_bound = 0
 4 Header files and forward declarations More...
 

Protected Member Functions

int load_and_compile_shader (GLhandleARB shader_object, const char *shader_filename, int shader_type, bool &shader_loaded)
 
char * load_shader_source (const char *shader_filename)
 
void update_light_uniforms ()
 b Description: More...
 
- Protected Member Functions inherited from diguyGraphicsShaderProgram
 diguyGraphicsShaderProgram (void *internal_data)
 A protected constructor. More...
 
virtual ~diguyGraphicsShaderProgram ()
 A protected destructor. More...
 

Protected Attributes

GLhandleARB m_gl_program_object
 
char m_vertex_shader_filename [512]
 
bool m_vertex_shader_loaded
 
bool m_vertex_shader_valid
 
GLhandleARB m_gl_vertex_shader_object
 
char m_pixel_shader_filename [512]
 
bool m_pixel_shader_loaded
 
bool m_pixel_shader_valid
 
GLhandleARB m_gl_pixel_shader_object
 
bool m_linked
 
float m_last_light_update_time
 
const float * m_last_matrix_data
 
diguyOglUniformBufferUpdaterm_uniform_buffer_updater
 

Additional Inherited Members

- Static Public Member Functions inherited from diguyGraphicsShaderProgram
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...
 

Detailed Description

This class is part of the DI-Guy Graphics API.

It subclasses a diguyGraphicsShaderProgram. Most rendering environments use some type of shader system that offloads rendering operations from the CPU to a GPU. Terminology varies, but DI-Guy uses the term "shader" to refer to a pair of sub-programs: a vertex shader and a pixel shader (AKA fragment shader in OpenGL).

Shader programs are shared among characters; if two characters use the same shader, the same shader object is used for both. If character-specific data is needed it can be stored in a diguyGraphicsShaderInstance object.

The class diguyOglGraphicsShaderProgram is an example of a diguyGraphicsShaderProgram subclass for an immediate mode renderer using the DI-Guy Loader. The example subclass shows how to use the accessors of the diguyGraphicsShaderProgram class and which virtual functions should be overridden for an immediate mode renderer such as OpenGL.

Constructor & Destructor Documentation

diguyOglGraphicsShaderProgram::diguyOglGraphicsShaderProgram ( void *  internal_data)
diguyOglGraphicsShaderProgram::~diguyOglGraphicsShaderProgram ( )

Member Function Documentation

int diguyOglGraphicsShaderProgram::load_vertex_shader_source ( const char *  filename_base)
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:

511,
filename_base,
"glsl",
"vert",
1);

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:

  • N/A (automatically called by DI-Guy Graphics API during the Build Stage)

Reimplemented from diguyGraphicsShaderProgram.

int diguyOglGraphicsShaderProgram::load_pixel_shader_source ( const char *  filename_base)
virtual

This function is the pixel shader (AKA fragment shader in OpenGL) equivalent of load_vertex_shader_source().

Reimplemented from diguyGraphicsShaderProgram.

int diguyOglGraphicsShaderProgram::link ( )
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:

  • N/A (automatically called by DI-Guy Graphics API during the Build Stage)

Reimplemented from diguyGraphicsShaderProgram.

int diguyOglGraphicsShaderProgram::bind ( )
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:

  • N/A (automatically called by DI-Guy Graphics API during the Draw Stage)

Reimplemented from diguyGraphicsShaderProgram.

int diguyOglGraphicsShaderProgram::unbind ( )
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:

  • N/A (automatically called by DI-Guy Graphics API during the Draw Stage)

Reimplemented from diguyGraphicsShaderProgram.

virtual int diguyOglGraphicsShaderProgram::get_gl_program_object ( )
inlinevirtual

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 from diguyGraphicsShaderProgram.

void diguyOglGraphicsShaderProgram::set_apply_matrices_flag ( int  apply_matrices_flag)
virtual

Reimplemented from diguyGraphicsShaderProgram.

void diguyOglGraphicsShaderProgram::set_textures_enabled ( int  enabled)
virtual

Reimplemented from diguyGraphicsShaderProgram.

int diguyOglGraphicsShaderProgram::bind_color_array ( int  num_colors,
const float *  color_data 
)
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:

  • N/A (automatically called by DI-Guy Graphics API during the Draw Stage)

Reimplemented from diguyGraphicsShaderProgram.

int diguyOglGraphicsShaderProgram::bind_matrix ( int  bind_location,
const float *  mat_data 
)
virtual

Reimplemented from diguyGraphicsShaderProgram.

int diguyOglGraphicsShaderProgram::bind_link_matrices ( int  num_matrices,
const float *  mat_data 
)
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:

  • N/A (automatically called by DI-Guy Graphics API during the Draw Stage)

Reimplemented from diguyGraphicsShaderProgram.

int diguyOglGraphicsShaderProgram::bind_uniform_with_location ( int  location,
const char *  name,
int  value_size,
float *  float_values 
)
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:

  • N/A (automatically called by DI-Guy Graphics API during the Draw Stage)
Parameters
locationthe shader uniform to feed this data to, this is the value that was retrieved via a call to get_ufrm_bind_location()
namestring representation of the uniform, useful for debugging
value_sizenumber of ints or floats to send to the video card
valuespointer to ints or floats to send to the video card

Reimplemented from diguyGraphicsShaderProgram.

int diguyOglGraphicsShaderProgram::bind_uniform_with_location ( int  location,
const char *  name,
int  value_size,
int *  values 
)
virtual

Reimplemented from diguyGraphicsShaderProgram.

int diguyOglGraphicsShaderProgram::get_attrib_bind_location ( const char *  name)
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 from diguyGraphicsShaderProgram.

int diguyOglGraphicsShaderProgram::get_uniform_bind_location ( const char *  name)
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 from diguyGraphicsShaderProgram.

diguyOglUniformBufferUpdater* diguyOglGraphicsShaderProgram::get_ogl_uniform_buffer_updater ( )
inline
int diguyOglGraphicsShaderProgram::load_and_compile_shader ( GLhandleARB  shader_object,
const char *  shader_filename,
int  shader_type,
bool &  shader_loaded 
)
protected
char * diguyOglGraphicsShaderProgram::load_shader_source ( const char *  shader_filename)
protected
void diguyOglGraphicsShaderProgram::update_light_uniforms ( )
protected

b Description:

Demonstrates using weapon fire flashes to create dynamic point lights

Member Data Documentation

int diguyOglGraphicsShaderProgram::m_bind_location_attr_color

needed for IM and particle systems

int diguyOglGraphicsShaderProgram::m_bind_location_attr_vertex

base default attrib locations

int diguyOglGraphicsShaderProgram::m_bind_location_attr_normal
int diguyOglGraphicsShaderProgram::m_bind_location_attr_texture
int diguyOglGraphicsShaderProgram::m_bind_location_attr_tangent

Per vertex tangent for bump mapping.

int diguyOglGraphicsShaderProgram::m_bind_location_attr_weight_array

Skeletal animation bone weight.

int diguyOglGraphicsShaderProgram::m_bind_location_attr_index_array

Skeletal animation bone index.

int diguyOglGraphicsShaderProgram::m_bind_location_attr_blend_vertex

blend shape per vertex attributes

int diguyOglGraphicsShaderProgram::m_bind_location_attr_blend_normal
int diguyOglGraphicsShaderProgram::m_bind_location_attr_blend_tangent
int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_blend_weight

uniform for controlling the amount of a blend shape

int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_emission_color

uniform for controlling emission color

int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_apply_matrices_flag

should bone matrices be used for this drawable, if 0 assumed to be a rigid drawable

int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_link_matrix

matrix used to transform a rigid drawable

int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_link_matrices

matrix array used to transform a skinned mesh

int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_link_colors

Uniform for sending bone link colors, needed for per pixel intersection tests.

int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_link_matrices_tbo

Instancing uniforms:

int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_base_matrices_start
int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_base_matrices_count
int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_link_matrices_start
int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_link_matrices_count
int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_extra_per_instance_data
int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_pbr_enabled

General state variables.

int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_textures_enabled
int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_bump_map_enabled
int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_specular_map_enabled
int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_component_map_enabled
int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_misc_1_map_enabled
int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_misc_2_map_enabled
int diguyOglGraphicsShaderProgram::m_bind_location_ufrm_component_row

uniform to control which row of the shared variation texture to use for this draw call

int diguyOglGraphicsShaderProgram::m_ubo_transform_block_index
int diguyOglGraphicsShaderProgram::m_ubo_material_block_index
int diguyOglGraphicsShaderProgram::m_ubo_per_frame_block_index
int diguyOglGraphicsShaderProgram::m_include_point_lights
int diguyOglGraphicsShaderProgram::s_bound = 0
static

4 Header files and forward declarations

GLhandleARB diguyOglGraphicsShaderProgram::m_gl_program_object
protected
char diguyOglGraphicsShaderProgram::m_vertex_shader_filename[512]
protected
bool diguyOglGraphicsShaderProgram::m_vertex_shader_loaded
protected
bool diguyOglGraphicsShaderProgram::m_vertex_shader_valid
protected
GLhandleARB diguyOglGraphicsShaderProgram::m_gl_vertex_shader_object
protected
char diguyOglGraphicsShaderProgram::m_pixel_shader_filename[512]
protected
bool diguyOglGraphicsShaderProgram::m_pixel_shader_loaded
protected
bool diguyOglGraphicsShaderProgram::m_pixel_shader_valid
protected
GLhandleARB diguyOglGraphicsShaderProgram::m_gl_pixel_shader_object
protected
bool diguyOglGraphicsShaderProgram::m_linked
protected
float diguyOglGraphicsShaderProgram::m_last_light_update_time
protected
const float* diguyOglGraphicsShaderProgram::m_last_matrix_data
protected
diguyOglUniformBufferUpdater* diguyOglGraphicsShaderProgram::m_uniform_buffer_updater
protected

The documentation for this class was generated from the following files: