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