H3D API  2.4.1
X3DTexture3DNode.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 //
27 //
29 #ifndef __X3DTEXTURE3DNODE_H__
30 #define __X3DTEXTURE3DNODE_H__
31 
33 #include <H3D/H3DImageObject.h>
34 #include <H3D/TextureProperties.h>
36 
37 namespace H3D {
44  class H3DAPI_API X3DTexture3DNode :
45  public H3DSingleTextureNode,
46  public H3DImageObject {
47  public:
49  class H3DAPI_API SFImage: public H3DImageObject::SFImage {
50  public:
51  virtual void setValueFromString( const string &s ) {
52  setValue( X3D::X3DStringTo3DImage( s ) );
53  }
54 
55  virtual string getValueAsString(const string& separator = " ");
56 
57  virtual X3DTypes::X3DType getX3DType() { return X3DTypes::SFIMAGE; }
58  };
59 
60  class UpdateTextureProperties : public Field{
61  public:
62  virtual void update();
63  };
64 
67  typedef DependentSFNode< FieldRef<TextureProperties,
68  Field,
71 
72  class H3DAPI_API UpdateSaveToURL : public H3DSingleTextureNode::UpdateSaveToURL {
73  protected:
74  virtual void onNewValue( const std::string &v );
75  };
76 
78  X3DTexture3DNode( Inst< DisplayList > _displayList = 0,
79  Inst< SFNode > _metadata = 0,
80  Inst< SFBool > _repeatS = 0,
81  Inst< SFBool > _repeatT = 0,
82  Inst< SFBool > _repeatR = 0,
83  Inst< SFBool > _scaleToP2 = 0,
84  Inst< SFImage > _image = 0,
85  Inst< SFTextureProperties > _textureProperties = 0,
86  Inst< UpdateSaveToURL > _saveToUrl = 0,
87  Inst< SFBool > _saveSuccess = 0,
88  Inst< SFInt32 > _saveHeight = 0,
89  Inst< SFInt32 > _saveWidth = 0 );
90 
91 
94  virtual void render();
95 
97  virtual void renderTextureProperties();
98 
100  virtual GLint glInternalFormat( Image *_image );
101 
105  virtual void enableTexturing();
106 
110  virtual void disableTexturing();
111 
113  virtual GLuint64 getTextureHandle();
114 
118  virtual Vec3f textureSize() {
119  Image *tex_image = image->getValue();
120  if( tex_image ) {
121  Vec3f size = tex_image->pixelSize();
122  size.x *= tex_image->width();
123  size.y *= tex_image->height();
124  size.z *= tex_image->depth();
125  return size;
126  } else {
127  return Vec3f( 0, 0, 0 );
128  }
129  }
130 
137  virtual void glTexImage( Image *_image, GLenum _texture_target,
138  bool scale_to_power_of_two );
139 
141  virtual void renderSubImage( Image *_image, GLenum _texture_target,
142  int xoffset, int yoffset, int z_offset,
143  int width, int height, int depth );
144 
145  virtual void setTextureWidth( int _width );
146 
147  virtual void setTextureHeight( int _height );
148 
149  virtual void setTextureDepth( int _depth );
150 
159  H3DUniquePtr< SFBool > repeatS;
160 
169  H3DUniquePtr< SFBool > repeatT;
170 
179  H3DUniquePtr< SFBool > repeatR;
180 
194  H3DUniquePtr< SFBool > scaleToPowerOfTwo;
195 
202  H3DUniquePtr< SFTextureProperties > textureProperties;
203 
206  protected:
207 
212  virtual std::pair<H3DInt32,H3DInt32> getDefaultSaveDimensions ();
213 
216  H3DUniquePtr< Field > imageUpdated;
217 
221  H3DUniquePtr< Field > textureUpdated;
222 
226  H3DUniquePtr< UpdateTextureProperties > updateTextureProperties;
227  public:
229  virtual GLenum glPixelFormat( Image *_image );
230 
231  protected:
232  // Needed to correctly fall back in case the TextureProperties settings are not matching the mip map settings
233  // or mip mapping can not be used (compressed image).
234  bool mip_mapping_used;
235  };
236 }
237 
238 #endif
Contains the DependentSFNode and DependentMFNode template classes.
Header file for H3DImageObject, X3D abstract texture scene-graph node.
Header file for H3DSingleTextureNode, X3D scene-graph node.
Header file for TextureProperties, X3D scene-graph node.
virtual Vec3f pixelSize()
virtual unsigned int depth()=0
virtual unsigned int width()=0
virtual unsigned int height()=0
The Field class.
Definition: Field.h:46
The SFImage field is a field containing an Image pointer.
Definition: H3DImageObject.h:50
This abstract interface is inherited by all nodes that contains an SFImage object with an Image conta...
Definition: H3DImageObject.h:45
This abstract node type is the base type for all texture nodes that is defined by a single texture.
Definition: H3DSingleTextureNode.h:45
H3DUniquePtr< Field > propertyChanged
Field that gets an event when any of the X3D fields in the TextureProperties generates an event.
Definition: TextureProperties.h:369
A SFNode encapsulating an Image class.
Definition: X3DTexture3DNode.h:49
virtual X3DTypes::X3DType getX3DType()
Returns the X3DType of the field.
Definition: X3DTexture3DNode.h:57
virtual void setValueFromString(const string &s)
Set the value of the field given a string.
Definition: X3DTexture3DNode.h:51
This abstract node type is the base type for all node types which specify 3D sources for texture imag...
Definition: X3DTexture3DNode.h:46
H3DUniquePtr< SFBool > repeatS
If true the texture will repeat itself when the s texture coordinate is outside the range [0,...
Definition: X3DTexture3DNode.h:159
DependentSFNode< FieldRef< TextureProperties, Field, &TextureProperties::propertyChanged > > SFTextureProperties
The SFTextureProperties is dependent on the propertyChanged field of the contained TextureProperties.
Definition: X3DTexture3DNode.h:70
H3DUniquePtr< SFBool > repeatT
If true the texture will repeat itself when the t texture coordinate is outside the range [0,...
Definition: X3DTexture3DNode.h:169
virtual Vec3f textureSize()
Sometimes the texture represents a volume in space, e.g.
Definition: X3DTexture3DNode.h:118
H3DUniquePtr< UpdateTextureProperties > updateTextureProperties
Field that will make sure that the texture properties changes are transferred to the texture when cha...
Definition: X3DTexture3DNode.h:226
H3DUniquePtr< Field > imageUpdated
Field to indicate image changed C++ only field.
Definition: X3DTexture3DNode.h:216
H3DUniquePtr< SFTextureProperties > textureProperties
The textureProperties field contains a TextureProperties node which allows fine control over a textur...
Definition: X3DTexture3DNode.h:202
H3DUniquePtr< SFBool > scaleToPowerOfTwo
If true the image used will be scaled so that the dimensions are a power of two if they are not.
Definition: X3DTexture3DNode.h:194
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: X3DTexture3DNode.h:205
H3DUniquePtr< SFBool > repeatR
If true the texture will repeat itself when the r texture coordinate is outside the range [0,...
Definition: X3DTexture3DNode.h:179
H3DUniquePtr< Field > textureUpdated
Field which is used to trigger an update of the texture when it has been modified through some functi...
Definition: X3DTexture3DNode.h:221
A field used to execute the save to URL operation when the URL is set.
Definition: X3DTextureNode.h:63
PixelImage * X3DStringTo3DImage(const string &x3d_string)
Convert a string to a 3D PixelImage according to the X3D spec for Pixel3DTexture.
Definition: X3DFieldConversion.cpp:36
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