H3D API  2.4.1
X3DTexture2DNode.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 __X3DTEXTURE2DNODE_H__
30 #define __X3DTEXTURE2DNODE_H__
31 
33 #include <H3D/H3DImageObject.h>
34 #include <H3D/TextureProperties.h>
36 
37 namespace H3D {
44  class H3DAPI_API X3DTexture2DNode :
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 
53  virtual string getValueAsString(const string& separator = " ");
54 
55  virtual X3DTypes::X3DType getX3DType() { return X3DTypes::SFIMAGE; }
56  };
57 
58  class H3DAPI_API UpdateTextureProperties: public Field{
59  public:
60  virtual void update();
61  };
62 
65  typedef DependentSFNode< FieldRef<TextureProperties,
66  Field,
69 
71  X3DTexture2DNode( Inst< DisplayList > _displayList = 0,
72  Inst< SFNode > _metadata = 0,
73  Inst< SFBool > _repeatS = 0,
74  Inst< SFBool > _repeatT = 0,
75  Inst< SFBool > _scaleToP2 = 0,
76  Inst< SFImage > _image = 0,
77  Inst< SFTextureProperties > _textureProperties = 0 );
78 
81  virtual void render();
82 
84  virtual void renderTextureProperties();
85 
87  virtual GLuint64 getTextureHandle();
88 
92  virtual void enableTexturing();
93 
97  virtual void disableTexturing();
98 
100  virtual GLint glInternalFormat( Image *_image );
101 
108  virtual void glTexImage( Image *_image, GLenum _texture_target,
109  bool scale_to_power_of_two );
110 
112  virtual void renderSubImage( Image *_image, GLenum _texture_target,
113  int xoffset, int yoffset,
114  int width, int height );
115 
118  virtual Image* renderToImage ( H3DInt32 _width, H3DInt32 _height, bool output_float_texture = false );
119 
120  virtual void setTextureWidth( int _width );
121 
122  virtual void setTextureHeight( int _height );
123 
132  H3DUniquePtr< SFBool > repeatS;
133 
142  H3DUniquePtr< SFBool > repeatT;
143 
157  H3DUniquePtr< SFBool > scaleToPowerOfTwo;
158 
165  H3DUniquePtr< SFTextureProperties > textureProperties;
166 
170  H3DUniquePtr< UpdateTextureProperties > updateTextureProperties;
171 
174  protected:
175 
179  virtual std::pair<H3DInt32,H3DInt32> getDefaultSaveDimensions ();
180 
183  H3DUniquePtr< Field > imageUpdated;
184 
188  H3DUniquePtr< Field > textureUpdated;
189 
190  public:
192  virtual GLenum glPixelFormat( Image *_image );
193 
194  protected:
195  // Needed to correctly fall back in case the TextureProperties settings are not matching the mip map settings
196  // or mip mapping can not be used (compressed image).
197  bool mip_mapping_used;
198  };
199 }
200 
201 #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.
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: X3DTexture2DNode.h:49
virtual X3DTypes::X3DType getX3DType()
Returns the X3DType of the field.
Definition: X3DTexture2DNode.h:55
This abstract node type is the base type for all node types which specify 2D sources for texture imag...
Definition: X3DTexture2DNode.h:46
H3DUniquePtr< SFBool > repeatT
If true the texture will repeat itself when the t texture coordinate is outside the range [0,...
Definition: X3DTexture2DNode.h:142
H3DUniquePtr< UpdateTextureProperties > updateTextureProperties
Field that will make sure that the texture properties changes are transferred to the texture when cha...
Definition: X3DTexture2DNode.h:170
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: X3DTexture2DNode.h:157
H3DUniquePtr< SFBool > repeatS
If true the texture will repeat itself when the s texture coordinate is outside the range [0,...
Definition: X3DTexture2DNode.h:132
H3DUniquePtr< SFTextureProperties > textureProperties
The textureProperties field contains a TextureProperties node which allows fine control over a textur...
Definition: X3DTexture2DNode.h:165
DependentSFNode< FieldRef< TextureProperties, Field, &TextureProperties::propertyChanged > > SFTextureProperties
The SFTextureProperties is dependent on the propertyChanged field of the contained TextureProperties.
Definition: X3DTexture2DNode.h:68
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: X3DTexture2DNode.h:173
H3DUniquePtr< Field > textureUpdated
Field which is used to trigger an update of the texture when it has been modified through some functi...
Definition: X3DTexture2DNode.h:188
H3DUniquePtr< Field > imageUpdated
Field to indicate image is modified C++ only field.
Definition: X3DTexture2DNode.h:183
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