H3D API  2.4.1
X3DTextureNode.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
28 //
30 #ifndef __X3DTEXTURENODE_H__
31 #define __X3DTEXTURENODE_H__
32 
34 #include <H3D/SFString.h>
35 #include <H3D/SFInt32.h>
36 #include <H3DUtil/Image.h>
37 #include <H3D/FieldTemplates.h>
38 #include "GL/glew.h"
39 
40 namespace H3D {
41 
47  class H3DAPI_API X3DTextureNode : public X3DAppearanceChildNode {
48  public:
49 
53 
57 
61 
63  class H3DAPI_API UpdateSaveToURL : public OnNewValueSField < AutoUpdate < SFString > > {
64  protected:
65  virtual void onNewValue( const std::string &v );
66  };
67 
69  X3DTextureNode( Inst< DisplayList > _displayList = 0,
70  Inst< SFNode> _metadata = 0,
71  Inst< UpdateSaveToURL > _saveToUrl = 0,
72  Inst< SFBool > _saveSuccess = 0,
73  Inst< SFInt32 > _saveHeight = 0,
74  Inst< SFInt32 > _saveWidth = 0
75  );
76 
80  virtual void enableTexturing() = 0;
81 
85  virtual void disableTexturing() = 0;
86 
90  virtual string defaultXMLContainerField() {
91  return "texture";
92  }
93 
96  virtual void preRender() {
97  setActiveTexture( this );
98  }
99 
103  virtual void postRender() {
104  setActiveTexture( NULL );
105  }
106 
110  virtual GLbitfield getAffectedGLAttribs() {
111  return GL_TEXTURE_BIT | GL_LIGHTING_BIT;
112  }
113 
117  virtual Vec3f textureSize() { return Vec3f( 0, 0, 0 ); }
118 
121  static X3DTextureNode *getActiveTexture() { return active_texture; }
122 
128  static void setActiveTexture( X3DTextureNode *t ) { active_texture = t; }
129 
140  virtual GLuint renderImage( Image *image,
141  GLenum texture_target,
142  bool scale_to_power_of_two );
143 
144  // Below are help functions for getting OpenGL constants from an Image.
145 
149  virtual GLint glInternalFormat( Image *image );
150 
154  virtual GLenum glPixelFormat( Image *image );
155 
159  virtual GLenum glPixelComponentType( Image *image );
160 
169  virtual void glTexImage( Image * /*image*/,
170  GLenum /*texture_target*/,
171  bool /*scale_to_power_of_two*/ ){
173  }
174 
186  virtual Image* renderToImage ( H3DInt32 _width, H3DInt32 _height, bool output_float_texture = false );
187 
198 
208  H3DUniquePtr < UpdateSaveToURL > saveToUrl;
209 
216  H3DUniquePtr < SFBool > saveSuccess;
217 
226  H3DUniquePtr < SFInt32 > saveHeight;
227 
236  H3DUniquePtr < SFInt32 > saveWidth;
237 
240 
241  protected:
247  virtual std::pair<H3DInt32,H3DInt32> getDefaultSaveDimensions ();
248 
252  GLint glCompressedInternalFormat( GLint _format, const std::string& _compression );
253 
254  private:
255  static X3DTextureNode *active_texture;
256  };
257 }
258 
259 #endif
#define H3D_FULL_LOCATION
Contains different templates to modify field behaviour.
Contains the SFInt32 field class.
Contains the SFString field class.
Header file for X3DAppearanceChildNode, X3D scene-graph node.
Template for adding the virtual function onNewValue that can be overridden in subclasses in order to ...
Definition: FieldTemplates.h:79
This is the base node type for the child nodes of the X3DAppearanceNode type.
Definition: X3DAppearanceChildNode.h:44
Thrown by renderImage () if the dimensions of an image are invalid, e.g.
Definition: X3DTextureNode.h:52
Thrown when an OpenGL error occurs while setting up the texture.
Definition: X3DTextureNode.h:56
A field used to execute the save to URL operation when the URL is set.
Definition: X3DTextureNode.h:63
Thrown when a subclass to X3DTextureNode calls renderImage without defining the glTexImage () functio...
Definition: X3DTextureNode.h:60
This abstract node type is the base type for all node types which specify sources for texture images.
Definition: X3DTextureNode.h:47
static bool load_images_in_separate_thread
This is the default value for the GlobalSettings::loadTexturesInThread field.
Definition: X3DTextureNode.h:197
H3DUniquePtr< SFInt32 > saveHeight
The height of the image to write to file when the saveToUrl field is used.
Definition: X3DTextureNode.h:226
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: X3DTextureNode.h:239
static void setActiveTexture(X3DTextureNode *t)
Set the active texture.
Definition: X3DTextureNode.h:128
virtual GLbitfield getAffectedGLAttribs()
Returns a bitmask of the OpenGL attrib bits that will be affected by this node.
Definition: X3DTextureNode.h:110
H3DUniquePtr< SFInt32 > saveWidth
The width of the image to write to file when the saveToUrl field is used.
Definition: X3DTextureNode.h:236
virtual void glTexImage(Image *, GLenum, bool)
Install the given image as a OpenGL texture with a call to a glTexImage function.
Definition: X3DTextureNode.h:169
virtual Vec3f textureSize()
Sometimes the texture represents a volume in space, e.g.
Definition: X3DTextureNode.h:117
virtual void postRender()
This function will be called by the X3DShapeNode after the geometry has been rendered to restore the ...
Definition: X3DTextureNode.h:103
H3DUniquePtr< UpdateSaveToURL > saveToUrl
When a new value is specified for saveToUrl the current texture is rendered to a buffer and saved to ...
Definition: X3DTextureNode.h:208
static X3DTextureNode * getActiveTexture()
Gets the currently active texture, i.e.
Definition: X3DTextureNode.h:121
virtual void enableTexturing()=0
Virtual function for making all OpenGL calls that are needed to enable texturing for the texture.
virtual void preRender()
This function will be called by the X3DShapeNode before any rendering of geometry and before the call...
Definition: X3DTextureNode.h:96
virtual void disableTexturing()=0
Virtual function for making all OpenGL calls that are needed to disable texturing for the texture.
virtual string defaultXMLContainerField()
Returns the default xml containerField attribute value.
Definition: X3DTextureNode.h:90
H3DUniquePtr< SFBool > saveSuccess
Contains the result of the last save operation.
Definition: X3DTextureNode.h:216
H3D_API_EXCEPTION(Vec2dNormalizeError)
int H3DInt32
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194