00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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