X3DTextureNode.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
00022 //
00023 //
00028 //
00030 #ifndef __X3DTEXTURENODE_H__
00031 #define __X3DTEXTURENODE_H__
00032 
00033 #include "X3DAppearanceChildNode.h"
00034 #include "Image.h"
00035 #include "GL/glew.h"
00036 
00037 namespace H3D {
00038 
00044   class H3DAPI_API X3DTextureNode : public X3DAppearanceChildNode {
00045   public:
00046         
00049     H3D_API_EXCEPTION( InvalidTextureDimensions );
00050 
00053     H3D_API_EXCEPTION( OpenGLTextureError );
00054 
00057     H3D_API_EXCEPTION( glTexImageFunctionNotDefined );
00058 
00060     X3DTextureNode( Inst< DisplayList > _displayList = 0,
00061                     Inst< SFNode>  _metadata = 0 );
00062         
00066     virtual void enableTexturing() = 0;
00067 
00071     virtual void disableTexturing() = 0;
00072         
00076     virtual string defaultXMLContainerField() {
00077       return "texture";
00078     }
00079 
00084     virtual void preRender() {
00085       glPushAttrib( GL_TEXTURE_BIT | GL_LIGHTING_BIT );
00086       setActiveTexture( this );
00087     }
00088 
00092     virtual void postRender() {
00093       glPopAttrib();
00094       setActiveTexture( NULL );
00095     }
00096 
00100     virtual Vec3f textureSize() { return Vec3f( 0, 0, 0 ); } 
00101 
00104     static X3DTextureNode *getActiveTexture() { return active_texture; }
00105 
00116     virtual GLuint renderImage( Image *image, 
00117                                 GLenum texture_target,
00118                                 bool scale_to_power_of_two );
00119 
00120     // Below are help functions for getting OpenGL constants from an Image.
00121 
00125     virtual GLint glInternalFormat( Image *image );
00126 
00130     virtual GLenum glPixelFormat( Image *image );
00131 
00135     virtual GLenum glPixelComponentType( Image *image );
00136 
00145     virtual void glTexImage( Image *image,
00146                              GLenum texture_target,
00147                              bool scale_to_power_of_two ){
00148       throw glTexImageFunctionNotDefined( "", H3D_FULL_LOCATION ); 
00149     }
00150 
00151   protected:
00152     // The glTexImage functions needs each line of image data to be 4 byte 
00153     // aligned. This function takes a pointer to image data and width,height
00154     // and bits per pixel for that data and returns a pointer to new image
00155     // data where the data has been padded with dummy values in order to
00156     // align it to the closest 4 byte position.
00157     static void *padTo4ByteAlignment( const void *data,
00158                                       unsigned int width,
00159                                       unsigned int height,
00160                                       unsigned int depth,
00161                                       unsigned int bits_per_pixel );
00162 
00168     static void setActiveTexture( X3DTextureNode *t ) { active_texture = t; }
00169   
00170   private:
00171     static X3DTextureNode *active_texture;
00172   };
00173 }
00174 
00175 #endif

Generated on Thu Aug 24 12:38:35 2006 for H3D API by  doxygen 1.4.5