X3DTexture2DNode.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 //
00027 //
00029 #ifndef __X3DTEXTURE2DNODE_H__
00030 #define __X3DTEXTURE2DNODE_H__
00031 
00032 #include "X3DTextureNode.h"
00033 #include "H3DImageObject.h"
00034 #include "TextureProperties.h"
00035 #include "DependentNodeFields.h"
00036 
00037 namespace H3D {
00044   class H3DAPI_API X3DTexture2DNode : 
00045     public X3DTextureNode,
00046     public H3DImageObject {
00047   public:
00049     class H3DAPI_API SFImage: public H3DImageObject::SFImage {
00050       virtual void setValueFromString( const string &s ) {
00051         setValue( X3D::X3DStringTo2DImage( s ) );
00052       }
00053     };
00054         
00057     typedef  DependentSFNode< FieldRef<TextureProperties,
00058                                        Field,
00059                                        &TextureProperties::propertyChanged > > 
00060     SFTextureProperties;
00061     
00063     X3DTexture2DNode( Inst< DisplayList > _displayList = 0,
00064                       Inst< SFNode  > _metadata  = 0,
00065                       Inst< SFBool  > _repeatS   = 0,
00066                       Inst< SFBool  > _repeatT   = 0,
00067                       Inst< SFBool  > _scaleToP2 = 0,
00068                       Inst< SFImage > _image     = 0,
00069                       Inst< SFTextureProperties > _textureProperties = 0 );
00070 
00072     ~X3DTexture2DNode() {
00073       if( texture_id ) glDeleteTextures( 1, &texture_id );
00074     }
00075 
00078     virtual void render();
00079 
00081     virtual void renderTextureProperties();
00082 
00084     inline GLuint getTextureId() {
00085       return texture_id;
00086     }
00087 
00089     inline GLuint getTextureUnit() {
00090       return texture_unit;
00091     }
00092 
00096     inline virtual void enableTexturing() {
00097       glEnable( GL_TEXTURE_2D );
00098       Image * i = static_cast< Image * >(image->getValue());
00099       if( i && 
00100           ( i->pixelType() == Image::LUMINANCE_ALPHA || 
00101             i->pixelType() == Image::RGBA ||
00102             i->pixelType() == Image::BGRA ) ) {
00103         glEnable( GL_BLEND );
00104         glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00105       }
00106     }
00107       
00111     inline virtual void disableTexturing() {
00112       glDisable( GL_TEXTURE_2D );
00113       Image * i = static_cast< Image * >(image->getValue());
00114       if( i && 
00115           ( i->pixelType() == Image::LUMINANCE_ALPHA || 
00116             i->pixelType() == Image::RGBA ||
00117             i->pixelType() == Image::BGRA ) ) {
00118         glDisable( GL_BLEND );
00119       }
00120     }
00121 
00123     virtual GLint glInternalFormat( Image *image );
00124 
00131     virtual void glTexImage( Image *image, GLenum texture_target, 
00132                              bool scale_to_power_of_two );
00133       
00142     auto_ptr< SFBool >  repeatS;
00143 
00152     auto_ptr< SFBool >  repeatT;
00153 
00164     auto_ptr< SFBool > scaleToPowerOfTwo;
00165     
00172     auto_ptr< SFTextureProperties >  textureProperties;
00173 
00175     static H3DNodeDatabase database;
00176   protected:
00178     GLuint texture_id;
00180     GLint texture_unit;
00181     
00182   };
00183 }
00184 
00185 #endif

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