
This file was automatically generated from diguyOsgGraphicsState.cpp. Do not edit this file directly; the changes will be lost.
Graphics state objects mostly serve as containers for other sub-objects, such as matrials and textures, that control the visual state of geometry. At times renderer-specific objects need to be created in this level, as well.
The class diguyOsgGraphicsState is an example of a diguyGraphicsState subclass for a scene graph renderer using the DI-Guy Loader. The example subclass shows how to use the accessors of the diguyGraphicsState class and which virtual functions should be overridden for a scene graph renderer such as OSG.
| Header files and forward declarations |
#include "diguyOsgGraphicsState.h" #include "diguyOsgGraphicsMaterial.h" #include "diguyOsgGraphicsTexture.h" #include <libbdilog.h>
| Constructor |
This constructor initializes 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.
diguyOsgGraphicsState::diguyOsgGraphicsState(void* internal_data) : diguyGraphicsState(internal_data), m_state_set(NULL) { }
| build |
Build Stage
Description:
Override of diguyGraphicsState::build().
The build() function should create the necessary objects that will combine the state's material and texture data.
This implementation creates an osg::StateSet from the data in this diguyGraphicsState. This will entail combining the state data from this state's material and texture objects.
void diguyOsgGraphicsState::build() { m_state_set = new osg::StateSet; /* * Get a pointer to the diguyGraphicsMaterial, and cast it * to a diguyOsgGraphicsMaterial. */ diguyGraphicsMaterial* diguy_material = get_material(); diguyOsgGraphicsMaterial* diguy_osg_material = (diguyOsgGraphicsMaterial*) diguy_material; if (diguy_osg_material) { osg::Material* mtl = diguy_osg_material->get_material(); if (mtl) { m_state_set->setAttribute(mtl); /* * Note: This doesn't work yet for skinned meshes; not sure why. */ int is_unlit = get_is_unlit(); if (is_unlit) m_state_set->setMode(GL_LIGHTING, osg::StateAttribute::PROTECTED | osg::StateAttribute::OFF); else m_state_set->setMode(GL_LIGHTING, osg::StateAttribute::PROTECTED | osg::StateAttribute::ON); } } /* * Get a pointer to the list of diguyGraphicsTexture, and cast it to a * diguyOsgGraphicsTexture. */ int i; for (i = 0; i < get_num_textures(); i++) { diguyGraphicsTexture* diguy_texture = get_texture(i); diguyOsgGraphicsTexture* diguy_osg_texture = (diguyOsgGraphicsTexture*) diguy_texture; if (diguy_osg_texture) { osg::Texture2D* texture = diguy_osg_texture->get_texture(); /* * Setup the texture unit and turn the texture on. */ osg::StateSet* texture_state_set = new osg::StateSet; texture_state_set->setTextureAttribute(get_texture_type(i), diguy_osg_texture->get_texture()); texture_state_set->setTextureMode(get_texture_type(i), GL_TEXTURE_2D, osg::StateAttribute::PROTECTED | osg::StateAttribute::ON); if (texture_state_set && texture) { /* * Combine the texture state set with the material state set. */ m_state_set->merge(*texture_state_set); } } } int textures_available_mask = get_textures_available(); /* * Set the associated uniform that turns on bump mapping part of the * shader. */ osg::Uniform* ufrm_bump_map_enabled = new osg::Uniform("ufrm_bump_map_enabled", !!(textures_available_mask & DIGUY_TEXTURE_MAP_MASK_BUMP)); m_state_set->addUniform(ufrm_bump_map_enabled); /* * Set the associated uniform that turns on specular mapping part of the * shader. */ osg::Uniform* ufrm_spec_map_enabled = new osg::Uniform("ufrm_specular_map_enabled", !!(textures_available_mask & DIGUY_TEXTURE_MAP_MASK_SPECULAR)); m_state_set->addUniform(ufrm_spec_map_enabled); /* * Set the associated uniform that turns on texture variation mapping part of the * shader. */ osg::Uniform* ufrm_comp_map_enabled = new osg::Uniform("ufrm_component_map_enabled", !!(textures_available_mask & DIGUY_TEXTURE_MAP_MASK_COMPONENTS)); m_state_set->addUniform(ufrm_comp_map_enabled); /* * Set the default rendering bin for objects with this state. States * that contain a material or texture with an alpha component, which * controls transparency, should be placed in the TRANSPARENT_BIN, * those without in the OPAQUE_BIN. */ if (get_contains_alpha_component()) m_state_set->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); else m_state_set->setRenderingHint(osg::StateSet::OPAQUE_BIN); }
| unbuild |
Unbuild Stage
Description:
Override of diguyGraphicsState::unbuild().
The unbuild() function should destroy the objects created in the build() function.
This implementation dereferences the osg::StateSet created in build().
void diguyOsgGraphicsState::unbuild() { /* * Setting the m_state_set ref_ptr to NULL dereferences the * StateSet object it points to, possibly deleting it. */ m_state_set = NULL; }
| Create function definition |
Create and return an object of a subclass of diguyGraphicsState. This function will be called whenever DI-Guy requires a state object.
diguyGraphicsState* diguyOsgGraphicsState_create_func(void* internal_data) { return new diguyOsgGraphicsState(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.