Open Inventor Release 2025.2.0
 
Loading...
Searching...
No Matches
SoTextureImageElementBase.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2025 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20
21
22#ifndef _SO_TEXTURE_IMAGE_ELEMENT_BASE
23#define _SO_TEXTURE_IMAGE_ELEMENT_BASE
24
25#if defined(_WIN32)
26#pragma warning(push)
27#pragma warning(disable:4251) // 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
28#endif
29
30#define MAX_TEXTURE_NBR 6
31// Texture1D, texture and texture3D use one texturename
32// But we need 6 for textureCubeMap
33
34#include <Inventor/SbColor.h>
35#include <Inventor/elements/SoReplacedTextureElement.h>
36#include <Inventor/fields/SoSFImage.h>
37#include <Inventor/SbPImpl.h>
38#include <Inventor/renderer/RendererResourceMacro.h>
39
40
41#ifndef GL_TEXTURE_CUBE_MAP
42#define GL_TEXTURE_CUBE_MAP 0x8513
43#endif
44#ifndef GL_TEXTURE_2D
45#define GL_TEXTURE_2D 0x0DE1
46#endif
47
48
50class SoBufferObject;
51class SoGLTexture;
52class SoTexture;
53
54SO_PIMPL_BASE_PUBLIC_DECLARATION(SoTextureImageElementBase)
55
56
67
68SoEXTENDER_Documented class SoTextureImageElementBase : public SoReplacedTextureElement
69{
70 SO_PIMPL_BASE_PUBLIC_HEADER(SoTextureImageElementBase);
71
72 SO_ELEMENT_ABSTRACT_HEADER(SoTextureImageElementBase);
73
74 public:
75
77 enum Target {
79 TEXTURE2D = GL_TEXTURE_2D,
81 TEXTURECUBEMAP = GL_TEXTURE_CUBE_MAP
82 };
83
87 virtual void print(FILE *fp) const;
88
92 virtual void push(SoState *state) ;
93
94private:
96 virtual void commonInit();
97
99 virtual void init(SoState *state);
100
101 private:
102 // Initializes the class
103 static void initClass();
104 static void exitClass();
105
106 SoTextureImageElementBase::Target getTargetTexture(){return m_target;}
107
108 struct TextureDataConfiguration
109 {
110 uint32_t xOffset;
111 uint32_t yOffset;
112 uint32_t zOffset;
113
114 uint32_t width;
115 uint32_t height;
116 uint32_t depth;
117 uint8_t face;
118
119 uint8_t imgFormat;
120 SbDataType imgDataType;
121
122 uint32_t rowLength;
123 uint32_t imageHeight;
124
125 int mipLevel;
126 void* imgData;
127
133 bool copyData : 1;
134
139 bool deleteData : 1;
140
141 TextureDataConfiguration()
142 {
143 xOffset = 0;
144 yOffset = 0;
145 zOffset = 0;
146 width = 0;
147 height = 0;
148 depth = 0;
149 face = 0;
150 rowLength = 0;
151 imageHeight = 0;
152 mipLevel = 0;
153 imgFormat = 0;
154 imgDataType = SbDataType::UNKNOWN;
155 imgData = NULL;
156 copyData = true;
157 deleteData = true;
158 }
159
161 size_t subImageSize() const;
162 };
163
164 class SamplerConfiguration : public SoRefCounter
165 {
166 RENDERER_RESOURCE(SamplerConfiguration);
167 public:
168 SbVec4f borderColor;
169 float maxAnisotropy;
170
171 uint32_t sAddressMode;
172 uint32_t tAddressMode;
173 uint32_t rAddressMode;
174
175 uint32_t model;
176
177 uint8_t minFilter;
178 uint8_t magFilter;
179 uint8_t mipmapFilter;
180
182 static uint8_t getAutoMagFilter(float quality);
183 static void getAutoMinFilter(uint8_t& minFilter, uint8_t& mipmapFilter, float quality);
184
185 bool isUsingMipmaps() const;
186 bool operator== (const SamplerConfiguration& sc) const;
187 bool operator!=( const SamplerConfiguration& sc ) const
188 {
189 return !operator==( sc );
190 }
191
192 SamplerConfiguration();
193 ~SamplerConfiguration() { destroyRendererResource(); }
194
195 private:
196 SamplerConfiguration( const SamplerConfiguration& )
197 : SoRefCounter()
198 {}
199 };
200
201 // store information about the texture Image element data
202 struct SoTexImageData
203 {
204 SoTexture* texture;
205 SoRef<SamplerConfiguration> samplerConfiguration;
206
207 // Constructor
208 SoTexImageData();
209
210 uint8_t texType;
211 SoGLTexture* gltexture;
212 SbVec3i32 size;
213 int numComponents;
214 const void* buffer[MAX_TEXTURE_NBR];
215 SoBufferObject* bufferObjects[MAX_TEXTURE_NBR];
216 SbColor blendColor;
217 bool enableBorder;
218
219 uint8_t imgFormat;
220 SoSFImage::DataType dataType;
221 GLint GLInternalFormat;
222 SoRenderToTextureProperty* renderToTextureProperty;
223 bool renderToTexturePropertyFirstPass;
224 // Does texture image contain any alpha values less than one?
225 // -1 = unknown, 0 = no, 1 = yes
226 int hasTransparency;
227 bool isCompressed;
228 int numCompressedMipmaps;
229 float quality;
230 int currentTexture;
231
232
240 std::vector<SubTexture> subtextures;
241
242 //True if the texture is active
243 bool enabled;
244
245 int32_t wrapS;
246 int32_t wrapR;
247 int32_t wrapT;
248 int32_t model;
249 float maxAnisotropy;
250 SbVec4f borderColor;
251 uint8_t texFormat;
252
253 };
254
255 // return texture Image element data for the given texture unit
256 SoTexImageData& getTexImageData(const int unit) const;
257
258 private:
260
261 SbBool hasTransparency(SoState *state, int unit) const;
262 void getElt(SoState *state, int &_minFilter,int &_magFilter, float &_maxAnisotropy, int unit) const;
263
264 const void * getElt(SoState *state, SbVec2i32 &_size,
265 int &_numComponents, SoSFImage::DataType &_dataType,
266 GLint &_GLInternalFormat, int &_wrapS, int &_wrapT,
267 int &_model, SbColor &_blendColor, int unit, int currentTexture = -1) const;
268
269 virtual void setElt(const SbVec2i32 &s, int nc,
270 const void *buffer, SoBufferObject* bufferObject, SoSFImage::DataType dataType,
271 GLint GLInternalFormat, SoRenderToTextureProperty* renderToTex,
272 int wrapS, int wrapT, int wrapR, int model,
273 const SbColor &blendColor, float _maxAnisotropy,
274 SbBool _enableBorder, const SbVec4f &_borderColor,
275 SbBool isCompressed, int numCompressedMipmaps,
276 int hasTransparency = -1 /* default unknown */,
277 int unit=0, int currentTexture=-1);
278
279 virtual void setElt(SoState *state, SoNode *node, const SoTexImageData& config);
280
281 virtual void setSubElt(const SbVec2i32 &subSize,
282 int xoffset, int yoffset,
283 const void *buffer, int texname,
284 int unit=0);
285
286 virtual void setFilterElt(int _minFilter, int _magFilter, int currUnit);
287
288
289 virtual ~SoTextureImageElementBase();
290
291 // This stores the list of node id's as pointers associated to
292 // each texture unit.
293 typedef std::vector<SoTexImageData> SoTexImageDataList;
294 mutable SoTexImageDataList m_texImageDataList;
295
296 friend class SoVRMLAppearance;
297};
298
299#ifdef _WIN32
300#pragma warning( pop )
301#endif
302
303#endif /* _SO_TEXTURE_IMAGE_ELEMENT */
304
305
Color vector class.
Definition SbColor.h:82
Class encoding a data type.
Definition SbDataType.h:58
@ UNKNOWN
unknown data type
Definition SbDataType.h:82
2D vector class.
Definition SbVec.h:517
3D vector class.
Definition SbVec.h:1517
4D vector class.
Definition SbVec.h:2214
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
friend class SoState
Definition SoElement.h:406
Abstract base class for all database nodes.
Definition SoNode.h:145
Base class for ref-counted objects.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Class for creati...
DataType
Encoding data type.
Definition SoSFImage.h:147
Abstract base class for texture mapping nodes.
Definition SoTexture.h:156
Stores the current texture image.
virtual void push(SoState *state)
Overrides push() method to copy values from next instance in the stack.
virtual void print(FILE *fp) const
Print info about image for debugging.
int SbBool
Boolean type.
Definition SbBase.h:87
int GLint
Definition SoGLType.h:33