Open Inventor Release 2024.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-2023 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#ifdef _WIN32
41#pragma warning(push)
42#pragma warning(disable:4251)
43#endif
44
45#ifndef GL_TEXTURE_CUBE_MAP
46#define GL_TEXTURE_CUBE_MAP 0x8513
47#endif
48#ifndef GL_TEXTURE_2D
49#define GL_TEXTURE_2D 0x0DE1
50#endif
51
52#ifdef _WIN32
53#pragma warning( push )
54#pragma warning(disable:4251)
55#endif
56
57
59class SoBufferObject;
60class SoGLTexture;
61class SoTexture;
62
63SO_PIMPL_BASE_PUBLIC_DECLARATION(SoTextureImageElementBase)
64
65
77SoEXTENDER_Documented class SoTextureImageElementBase : public SoReplacedTextureElement
78{
79 SO_PIMPL_BASE_PUBLIC_HEADER(SoTextureImageElementBase);
80
81 SO_ELEMENT_ABSTRACT_HEADER(SoTextureImageElementBase);
82
83 public:
84
86 enum Target {
88 TEXTURE2D = GL_TEXTURE_2D,
90 TEXTURECUBEMAP = GL_TEXTURE_CUBE_MAP
91 };
92
96 virtual void print(FILE *fp) const;
97
101 virtual void push(SoState *state) ;
102
103private:
105 virtual void commonInit();
106
108 virtual void init(SoState *state);
109
110 private:
111 // Initializes the class
112 static void initClass();
113 static void exitClass();
114
115 SoTextureImageElementBase::Target getTargetTexture(){return m_target;}
116
117 struct TextureDataConfiguration
118 {
119 uint32_t xOffset;
120 uint32_t yOffset;
121 uint32_t zOffset;
122
123 uint32_t width;
124 uint32_t height;
125 uint32_t depth;
126 uint8_t face;
127
128 uint8_t imgFormat;
129 SbDataType imgDataType;
130
131 uint32_t rowLength;
132 uint32_t imageHeight;
133
134 int mipLevel;
135 void* imgData;
136
142 bool copyData : 1;
143
148 bool deleteData : 1;
149
150 TextureDataConfiguration()
151 {
152 xOffset = 0;
153 yOffset = 0;
154 zOffset = 0;
155 width = 0;
156 height = 0;
157 depth = 0;
158 face = 0;
159 rowLength = 0;
160 imageHeight = 0;
161 mipLevel = 0;
162 imgFormat = 0;
163 imgDataType = SbDataType::UNKNOWN;
164 imgData = NULL;
165 copyData = true;
166 deleteData = true;
167 }
168
170 size_t subImageSize() const;
171 };
172
173 class SamplerConfiguration : public SoRefCounter
174 {
175 RENDERER_RESOURCE(SamplerConfiguration);
176 public:
177 SbVec4f borderColor;
178 float maxAnisotropy;
179
180 uint32_t sAddressMode;
181 uint32_t tAddressMode;
182 uint32_t rAddressMode;
183
184 uint32_t model;
185
186 uint8_t minFilter;
187 uint8_t magFilter;
188 uint8_t mipmapFilter;
189
191 static uint8_t getAutoMagFilter(float quality);
192 static void getAutoMinFilter(uint8_t& minFilter, uint8_t& mipmapFilter, float quality);
193
194 bool isUsingMipmaps() const;
195 bool operator== (const SamplerConfiguration& sc) const;
196 bool operator!=( const SamplerConfiguration& sc ) const
197 {
198 return !operator==( sc );
199 }
200
201 SamplerConfiguration();
202 ~SamplerConfiguration() { destroyRendererResource(); }
203
204 private:
205 SamplerConfiguration( const SamplerConfiguration& )
206 : SoRefCounter()
207 {}
208 };
209
210 // store information about the texture Image element data
211 struct SoTexImageData
212 {
213 SoTexture* texture;
214 SoRef<SamplerConfiguration> samplerConfiguration;
215
216 // Constructor
217 SoTexImageData();
218
219 uint8_t texType;
220 SoGLTexture* gltexture;
221 SbVec3i32 size;
222 int numComponents;
223 const void* buffer[MAX_TEXTURE_NBR];
224 SoBufferObject* bufferObjects[MAX_TEXTURE_NBR];
225 SbColor blendColor;
226 bool enableBorder;
227
228 uint8_t imgFormat;
229 SoSFImage::DataType dataType;
230 GLint GLInternalFormat;
231 SoRenderToTextureProperty* renderToTextureProperty;
232 bool renderToTexturePropertyFirstPass;
233 // Does texture image contain any alpha values less than one?
234 // -1 = unknown, 0 = no, 1 = yes
235 int hasTransparency;
236 bool isCompressed;
237 int numCompressedMipmaps;
238 float quality;
239 int currentTexture;
240
241
249 std::vector<SubTexture> subtextures;
250
251 //True if the texture is active
252 bool enabled;
253
254 int32_t wrapS;
255 int32_t wrapR;
256 int32_t wrapT;
257 int32_t model;
258 float maxAnisotropy;
259 SbVec4f borderColor;
260 uint8_t texFormat;
261
262 };
263
264 // return texture Image element data for the given texture unit
265 SoTexImageData& getTexImageData(const int unit) const;
266
267 private:
269
270 SbBool hasTransparency(SoState *state, int unit) const;
271 void getElt(SoState *state, int &_minFilter,int &_magFilter, float &_maxAnisotropy, int unit) const;
272
273 const void * getElt(SoState *state, SbVec2i32 &_size,
274 int &_numComponents, SoSFImage::DataType &_dataType,
275 GLint &_GLInternalFormat, int &_wrapS, int &_wrapT,
276 int &_model, SbColor &_blendColor, int unit, int currentTexture = -1) const;
277
278 virtual void setElt(const SbVec2i32 &s, int nc,
279 const void *buffer, SoBufferObject* bufferObject, SoSFImage::DataType dataType,
280 GLint GLInternalFormat, SoRenderToTextureProperty* renderToTex,
281 int wrapS, int wrapT, int wrapR, int model,
282 const SbColor &blendColor, float _maxAnisotropy,
283 SbBool _enableBorder, const SbVec4f &_borderColor,
284 SbBool isCompressed, int numCompressedMipmaps,
285 int hasTransparency = -1 /* default unknown */,
286 int unit=0, int currentTexture=-1);
287
288 virtual void setElt(SoState *state, SoNode *node, const SoTexImageData& config);
289
290 virtual void setSubElt(const SbVec2i32 &subSize,
291 int xoffset, int yoffset,
292 const void *buffer, int texname,
293 int unit=0);
294
295 virtual void setFilterElt(int _minFilter, int _magFilter, int currUnit);
296
297
299
300 // This stores the list of node id's as pointers associated to
301 // each texture unit.
302 typedef std::vector<SoTexImageData> SoTexImageDataList;
303 mutable SoTexImageDataList m_texImageDataList;
304
305 friend class SoVRMLAppearance;
306};
307
308#ifdef _WIN32
309#pragma warning( pop )
310#endif
311
312#endif /* _SO_TEXTURE_IMAGE_ELEMENT */
313
314
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...
Abstract base class for all database nodes.
Definition SoNode.h:145
Base class for ref-counted objects.
Smart pointer for any class inheriting SoRefCounter.
Definition SoRef.h:90
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Class for creati...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
DataType
Encoding data type.
Definition SoSFImage.h:147
Traversal state.
Definition SoState.h:74
Abstract base class for texture mapping nodes.
Definition SoTexture.h:155
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