
This file was automatically generated from diguyOsgGraphicsTexture.cpp. Do not edit this file directly; the changes will be lost.
| Introduction |
Textures modify the visible appearance of meshes. They work in concert with materials to determine the final appearance of visible geometry.
The class diguyOsgGraphicsTexture is an example of a diguyGraphicsTexture subclass for a scene graph renderer using the DI-Guy Loader. The example subclass shows how to use the accessors of the diguyGraphicsTexture class and which virtual functions should be overridden for a scene graph renderer such as OSG.
| Header files and forward declarations |
#include "diguyOsgGraphicsTexture.h" #include <osg/TexEnv> #include <osgDB/ReadFile> #include <libbdilog.h> #include <stdlib.h> #include <string.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.
diguyOsgGraphicsTexture::diguyOsgGraphicsTexture(void* internal_data) : diguyGraphicsTexture(internal_data) { /* * Nothing else to do after calling base class constructor and * initializing data members. */ }
| build |
Build Stage
Description:
Override of diguyGraphicsTexture::build().
The build() function should create renderer objects that will set the proper texture state in the scene graph traversal.
This implementation creates an osg::Texture2D object and a companion osg::StateSet. The state set of this texture will be combined with the state set of a material in the diguyOsgGraphicsState class.
void diguyOsgGraphicsTexture::build() { /* * Get the texture map data buffer. */ unsigned char* texture_map_data = get_texture_map_data(); /* * If there is texture data, create a mip-mapped texture object. */ if (texture_map_data) { int width = get_width(); int height = get_height(); GLenum pixel_format; int pixel_format_as_int = get_gl_format(); if (pixel_format_as_int == -1) { bdi_log_printf(BDI_LOG_WARN, "WARNING: Failed to obtain legal " "pixel format for texture '%s'.\n", get_name()); return; } pixel_format = (GLenum) pixel_format_as_int; GLint internal_texture_format = pixel_format; /* * Make a copy of the texture map data. The osg image will take * ownership of it. */ unsigned char* texture_map_data = get_texture_map_data(); int texture_size = get_texture_map_data_size(); unsigned char* texture_map_data_copy = new unsigned char [texture_size]; memcpy(texture_map_data_copy, texture_map_data, texture_size); /* * Create an osg image. */ osg::Image* osg_image = new osg::Image(); osg_image->setImage(width, height, 1, internal_texture_format, pixel_format, GL_UNSIGNED_BYTE, texture_map_data_copy, osg::Image::USE_NEW_DELETE, // osg will deallocate texture_map_data_copy with call to delete 4); // pack/unpack alignment osg_image->setFileName(get_filename()); /* * Mipmaps are generated automatically by OSG for non-compressed * textures. * * Compressed textures might already have them; if so, we have * to set the mipmap offsets manually. */ int num_included_mipmaps = get_num_included_mipmaps(); if (num_included_mipmaps > 1) { /* * Get mipmap offsets. * * The number of mipmap offsets in osg is one less than the * number of mipmaps, as the offset of "mipmap 0" (the * original, base image) is assumed to be 0. */ osg::Image::MipmapDataType mipmaps; mipmaps.resize(num_included_mipmaps - 1); int k; for (k=1; k<num_included_mipmaps; k++) mipmaps[k-1] = get_mipmap_data_offset(k); osg_image->setMipmapLevels(mipmaps); } /* * Create a texture object, and load it with the osg::Image created * above. */ m_texture = new osg::Texture2D(); // not sure this is needed m_texture->setUnRefImageDataAfterApply(true); if (get_clamp_s()) m_texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP); else m_texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT); if (get_clamp_t()) m_texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP); else m_texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT); m_texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR); m_texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST_MIPMAP_LINEAR); m_texture->setResizeNonPowerOfTwoHint(true); m_texture->setImage(osg_image); /* * Create a state set for the texture. */ /* * THIS MIGHT Not make sense with multi-texturing now and is unused.. * this state is created now in the diguyOsgState */ m_texture_state_set = new osg::StateSet; m_texture_state_set->setTextureAttribute(0, m_texture); m_texture_state_set->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::PROTECTED | osg::StateAttribute::ON); } else { /* * This should probably do more to create a "null" texture * that is, say, white. */ m_texture = NULL; } /* * Free memory allocated by the loader. */ free_loader_memory(); }
| unbuild |
Unbuild Stage
Description:
Override of diguyGraphicsTexture::unbuild().
The unbuild() function should destroy the objects created in the build() function.
This implementation dereference the objects created in build().
void diguyOsgGraphicsTexture::unbuild() { /* * Setting the m_texture ref_ptr to NULL dereferences the Texture2D * object it points to, possibly deleting it. */ m_texture = NULL; m_texture_state_set = NULL; }
| Create function definition |
Create and return an object of a subclass of diguyGraphicsTexture. This function will be called whenever DI-Guy requires a texture object.
diguyGraphicsTexture* diguyOsgGraphicsTexture_create_func(void* internal_data) { return new diguyOsgGraphicsTexture(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.