
This file was automatically generated from diguyOsgGraphicsShaderInstance.cpp. Do not edit this file directly; the changes will be lost.
| Introduction |
Unlike shader programs, which are shared by many characters, shader instances allow non-shared, character-specific shader state to be maintained. An example is having different uniform variable values for different characters, such as a highlight color that is applied during shading.
See oglGraphicsShaderProgram for information on shader programs.
diguyOsgGraphicsShaderInstance is an example of a diguyGraphicsShaderInstance subclass for a scene graph renderer using the DI-Guy Loader. The example subclass shows how to use the accessors of the diguyGraphicsShaderInstance class and which virtual functions should be overridden for a scene graph renderer such as OSG.
| Header files and forward declarations |
#include <stdlib.h> #include <stdio.h> #include <diguyApp.h> #include "diguyOsgGraphicsShaderInstance.h" #include "diguyOsgGraphicsShaderProgram.h" #include "diguyGraphicsTexture.h" #include <diguyGraphicsShaderTechnique.h> #include <diguyCharacter.h> #include <libbdilog.h> #include <osg/ShadeModel>
| Constructor |
Initialize data members of the class to a known state.
Most base class data will not be fully initialized until during the Build Stage, so most base class accessors should not be called here.
diguyOsgGraphicsShaderInstance::diguyOsgGraphicsShaderInstance(void* internal_data) : diguyGraphicsShaderInstance(internal_data), m_shader_state_set(NULL), m_ufrm_apply_matrices_flag(NULL), m_ufrm_textures_enabled(NULL) { /* * Delay creating state set and uniforms until the state set * is requested by get_state_set(). */ }
| Destructor |
diguyOsgGraphicsShaderInstance::~diguyOsgGraphicsShaderInstance() { /* * Dereference state set and uniforms. */ m_shader_state_set = NULL; m_ufrm_apply_matrices_flag = NULL; m_ufrm_textures_enabled = NULL; }
| get_state_set |
Class-local accessor function for OSG state set of the shader instance. The OSG state set is created if it doesn't yet exist.
osg::StateSet* diguyOsgGraphicsShaderInstance::get_state_set() { /* * If m_shader_state_set has already been created, return it. */ if (m_shader_state_set != NULL) return m_shader_state_set; /* * Create a new osg::StateSet. */ m_shader_state_set = new osg::StateSet; /* * Add some uniform variables. */ if (get_shader_program()->get_shader_type() == DIGUY_GRAPHICS_SHADER_PROGRAM_TYPE_SKIN) { /* * In order to use the same shader program for both skinned and * segmented meshes, we need a way to tell the shader whether or not * to apply the ufrm_link_matrices values. This provides a default * value that gets overridden on a per mesh basis. */ m_ufrm_apply_matrices_flag = new osg::Uniform("ufrm_apply_matrices_flag", 0.0f); m_shader_state_set->addUniform(m_ufrm_apply_matrices_flag); } m_ufrm_textures_enabled = new osg::Uniform("ufrm_textures_enabled", 1); m_shader_state_set->addUniform(m_ufrm_textures_enabled); /* * Set up texture uniforms. */ osg::Uniform* diffuse_map = new osg::Uniform("ufrm_diffuse_map", DIGUY_TEXTURE_MAP_TYPE_DIFFUSE); m_shader_state_set->addUniform(diffuse_map); osg::Uniform* bump_map = new osg::Uniform("ufrm_bump_map", DIGUY_TEXTURE_MAP_TYPE_BUMP); m_shader_state_set->addUniform(bump_map); osg::Uniform* specular_map = new osg::Uniform("ufrm_specular_map", DIGUY_TEXTURE_MAP_TYPE_SPECULAR); m_shader_state_set->addUniform(specular_map); osg::Uniform* component_map = new osg::Uniform("ufrm_component_map", DIGUY_TEXTURE_MAP_TYPE_COMPONENTS); m_shader_state_set->addUniform(component_map); osg::Uniform* component_ramp_map = new osg::Uniform("ufrm_component_ramp", DIGUY_TEXTURE_MAP_TYPE_COMPONENT_RAMP); m_shader_state_set->addUniform(component_ramp_map); /* * Attach shader_program to the state set. */ diguyGraphicsShaderTechnique* shader_technique = get_shader_technique(); if (!shader_technique) { bdi_log_printf(BDI_LOG_WARN, "WARNING: Shader instance created without a shader technique.\n"); } else { diguyCharacter* character = get_character(); diguyOsgGraphicsShaderProgram* shader_program = NULL; int render_flags = diguyApp::get_app()->get_render_pass_flags(); if (render_flags & DIGUY_RENDER_PASS_INTERSECTION) { shader_program = static_cast<diguyOsgGraphicsShaderProgram*>(shader_technique->get_intersection_shader()); osg::ref_ptr<osg::ShadeModel> shadeModel = new osg::ShadeModel(osg::ShadeModel::FLAT); m_shader_state_set->setAttributeAndModes(shadeModel.get(), osg::StateAttribute::ON); } else { shader_program = static_cast<diguyOsgGraphicsShaderProgram*>(shader_technique->get_shader_lod_program_at_index(0)); if (character) { /* * TODO implement shader LODs for now just bump down to the * non-bump mapped shader. */ if (!character->get_has_bump_maps() && (shader_program->get_quality_level() == DIGUY_GRAPHICS_SHADER_QUALITY_PER_PIXEL_BUMP_MAPPED) && (shader_technique->get_num_shader_lod_programs() > 1)) { shader_program = static_cast<diguyOsgGraphicsShaderProgram*>(shader_technique->get_shader_lod_program_at_index(0)); } } } m_shader_state_set->setAttributeAndModes(shader_program->get_program(), osg::StateAttribute::ON); } return m_shader_state_set.get(); }
| Create function definition |
Create and return an object of a subclass of diguyGraphicsShaderInstance. This function will be called whenever DI-Guy requires a shader instance object.
diguyGraphicsShaderInstance* diguyOsgGraphicsShaderInstance_create_func(void* internal_data) { return new diguyOsgGraphicsShaderInstance(internal_data); }
ALL RIGHTS RESERVED.
These coded instructions, statements, and computer programs contain unpublished proprietary information of Boston Dynamics and are protected by Copyright Laws of the United States. They may not be used, duplicated, or disclosed in any form, in whole or in part, without the prior written consent from Boston Dynamics.
RESTRICTED RIGHTS LEGEND
Use, duplication, or disclosure by the government is subject to restrictions as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Sofware clause at DFARS 252.227-7013 and/or in similar or successor clauses in the FAR, or the DOD or NASA FAR Supplement, or to subparagraphs (c)(1) and (c)(2) of the Commercial Computer Software--Restricted Rights at 48 CFR 52.227-19, as applicable. Unpublished-rights reserved under the Copyright Laws of the United States.
Contractor/Manufacturer is:
Boston Dynamics/78 Fourth Avenue/Waltham MA 02451.