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 __X3DTEXTURE3DNODE_H__
00030 #define __X3DTEXTURE3DNODE_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 X3DTexture3DNode :
00045 public X3DTextureNode,
00046 public H3DImageObject {
00047 public:
00048
00051 typedef DependentSFNode< FieldRef<TextureProperties,
00052 Field,
00053 &TextureProperties::propertyChanged > >
00054 SFTextureProperties;
00055
00057 X3DTexture3DNode( Inst< DisplayList > _displayList = 0,
00058 Inst< SFNode > _metadata = 0,
00059 Inst< SFBool > _repeatS = 0,
00060 Inst< SFBool > _repeatT = 0,
00061 Inst< SFBool > _repeatR = 0,
00062 Inst< SFBool > _scaleToP2 = 0,
00063 Inst< SFImage > _image = 0,
00064 Inst< SFTextureProperties > _textureProperties = 0 );
00065
00066
00068 ~X3DTexture3DNode() {
00069 if( texture_id ) glDeleteTextures( 1, &texture_id );
00070 }
00071
00074 virtual void render();
00075
00077 virtual void renderTextureProperties();
00078
00080 virtual GLint glInternalFormat( Image *image );
00081
00085 inline virtual void enableTexturing() {
00086 glEnable( GL_TEXTURE_3D );
00087 Image * i = static_cast< Image * >(image->getValue());
00088 if( i &&
00089 ( i->pixelType() == Image::LUMINANCE_ALPHA ||
00090 i->pixelType() == Image::RGBA ||
00091 i->pixelType() == Image::BGRA ) ) {
00092 glEnable( GL_BLEND );
00093 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00094 }
00095 }
00096
00100 inline virtual void disableTexturing() {
00101 glDisable( GL_TEXTURE_3D );
00102 Image * i = static_cast< Image * >(image->getValue());
00103 if( i &&
00104 ( i->pixelType() == Image::LUMINANCE_ALPHA ||
00105 i->pixelType() == Image::RGBA ||
00106 i->pixelType() == Image::BGRA ) ) {
00107 glDisable( GL_BLEND );
00108 }
00109 }
00110
00112 inline GLuint getTextureId() {
00113 return texture_id;
00114 }
00115
00117 inline GLuint getTextureUnit() {
00118 return texture_unit;
00119 }
00120
00124 virtual Vec3f textureSize() {
00125 Image *tex_image = image->getValue();
00126 if( tex_image ) {
00127 Vec3f size = tex_image->pixelSize();
00128 size.x *= tex_image->width();
00129 size.y *= tex_image->height();
00130 size.z *= tex_image->depth();
00131 return size;
00132 } else {
00133 return Vec3f( 0, 0, 0 );
00134 }
00135 }
00136
00143 virtual void glTexImage( Image *image, GLenum texture_target,
00144 bool scale_to_power_of_two );
00145
00154 auto_ptr< SFBool > repeatS;
00155
00164 auto_ptr< SFBool > repeatT;
00165
00174 auto_ptr< SFBool > repeatR;
00175
00186 auto_ptr< SFBool > scaleToPowerOfTwo;
00187
00194 auto_ptr< SFTextureProperties > textureProperties;
00195
00197 static H3DNodeDatabase database;
00198 protected:
00200 GLuint texture_id;
00202 GLint texture_unit;
00203 };
00204 }
00205
00206 #endif