Open Inventor Release 2024.1.1
 
Loading...
Searching...
No Matches
SoTextureCoordinateElement.h
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Gavin Bell (MMM yyyy)
25**=======================================================================*/
26/*=======================================================================
27 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
28 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
29 *** ***
30 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
31 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
32 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
33 *** ***
34 *** RESTRICTED RIGHTS LEGEND ***
35 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
36 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
37 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
38 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
39 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
40 *** ***
41 *** COPYRIGHT (C) 1996-2024 BY FEI S.A.S, ***
42 *** BORDEAUX, FRANCE ***
43 *** ALL RIGHTS RESERVED ***
44**=======================================================================*/
45/*=======================================================================
46** Modified by : VSG (MMM YYYY)
47**=======================================================================*/
48
49
50#ifndef _SO_TEXTURE_COORDINATE_ELEMENT
51#define _SO_TEXTURE_COORDINATE_ELEMENT
52
53#include <Inventor/SbLinear.h>
54#include <Inventor/elements/SoReplacedTextureElement.h>
55#include <Inventor/SbEnums.h>
56#include <memory>
57
58#include <Inventor/STL/vector>
59
68typedef const SbVec4f &
69SoTextureCoordinateFunctionCB(void *userdata, const SbVec3f &point,
70 const SbVec3f &normal);
71
72
84SoEXTENDER_Documented class SoTextureCoordinateElement : public SoReplacedTextureElement {
85
86 SO_ELEMENT_HEADER(SoTextureCoordinateElement);
87
88 public:
93 enum CoordType {
94 EXPLICIT = 1, // Coordinates stored in state
95 FUNCTION = 2 // Coordinates generated by software function
96 };
97
102 static void setDefault(SoState *state, SoNode *node);
103
104 // FUNCTION:
105 static void setFunction(SoState *state, SoNode *node,
107 void *userData,
108 SbBool frcSend = FALSE);
109 // EXPLICIT:
113 static void set2(SoState *state, SoNode *node,
114 int32_t numCoords, const SbVec2f *coords,
115 SbBool frcSend = FALSE);
116
120 static void set4(SoState *state, SoNode *node,
121 int32_t numCoords, const SbVec4f *coords,
122 SbBool frcSend = FALSE);
123
128 static CoordType getType(SoState *state, int unit=0);
129
130 virtual CoordType getType(int unit=0) const;
131
139
140 // Get routine for FUNCTION case:
141
147 const SbVec4f & get(const SbVec3f &point, const SbVec3f &normal,
148 int unit=0) const;
149
150 // Get routines for EXPLICIT case:
151
155 int32_t getNum(int unit=0) const ;
156
157 SbBool is2D(int unit=0) const ;
158
159 SbBool isForceSending(int unit=0) const ;
160
165 const SbVec2f & get2(int index, int unit=0) const;
166 const SbVec4f & get4(int index, int unit=0) const;
167
171 virtual void print(FILE *fp) const;
172
176 virtual void push(SoState *) ;
177
178private:
179
181 virtual void commonInit();
182
184 virtual void init(SoState *state);
185
186 private:
191 class TexGenEvaluator
192 {
193 public:
194 virtual const SbVec4f& eval(const SbVec3f &point, const SbVec3f &normal) = 0;
195 };
196
198 static void setTextureCoordType(SoState *state, SoNode *node, CoordType coordType);
199
200 // Initializes the SoTextureCoordinateElement class
201 static void initClass();
202 static void exitClass();
203
204 private:
205
207
208 struct SoTexCoordData
209 {
210 // What kind of coordinates will be done:
211 CoordType whatKind;
212
213 // Storage for FUNCTION:
214 std::shared_ptr<TexGenEvaluator> m_texGenEvaluatorUserDefined;
215
216 // Storage for EXPLICIT:
217 int32_t numCoords;
218 const SbVec2f *coords2;
219 const SbVec4f *coords4;
220 SbBool coordsAre2D;
221 SbBool forceSend;
222
223 SoTexCoordData() :
224 whatKind(EXPLICIT),
225 numCoords(0),
226 coords2(NULL),
227 coords4(NULL),
228 coordsAre2D(FALSE),
229 forceSend(FALSE)
230 {
231 }
232
233 void initValues( const CoordType &type )
234 {
235 whatKind = type;
236 numCoords = 0;
237 coords2 = NULL;
238 coords4 = NULL;
239 coordsAre2D = FALSE;
240 forceSend = FALSE;
241 m_texGenEvaluatorUserDefined.reset();
242 }
243
244 SoTexCoordData& operator=(const SoTexCoordData& data)
245 {
246 if ( &data != this )
247 {
248 whatKind = data.whatKind ;
249 numCoords = data.numCoords ;
250 coords2 = data.coords2 ;
251 coords4 = data.coords4 ;
252 coordsAre2D = data.coordsAre2D ;
253 forceSend = data.forceSend;
254 }
255 return *this ;
256 }
257 } ;
258
259 SoTexCoordData& getTexCoordData( const int unit ) const;
260
261 private:
262 SbVec2f m_convert2; // To convert from 4-D to 2-D
263 SbVec4f m_convert4; // To convert from 2-D to 4-D
264
265 //Neeed for get method which don't have state we need
266 SoState* m_state;
267
268 typedef std::vector<SoTexCoordData> SoTexCoordDataList;
269
270 mutable SoTexCoordDataList m_texCoordData ;
271};
272
273
274#endif /* _SO_TEXTURE_COORDINATE_ELEMENT */
2D vector class.
Definition SbVec.h:76
3D vector class.
Definition SbVec.h:932
4D vector class.
Definition SbVec.h:2214
Abstract base class for all database nodes.
Definition SoNode.h:145
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
Traversal state.
Definition SoState.h:74
Stores the current texture coordinates.
SbBool isForceSending(int unit=0) const
const SbVec4f & SoTextureCoordinateFunctionCB(void *userdata, const SbVec3f &point, const SbVec3f &normal)
Function that TextureCoordinateFunction nodes register to compute texture coordinates.
virtual CoordType getType(int unit=0) const
virtual void print(FILE *fp) const
Prints element (for debugging).
CoordType
The choice of values is for compatibility with Open Inventor 2.0 binary format files.
static const SoTextureCoordinateElement * getInstance(SoState *state)
Returns the top (current) instance of the element in the state.
virtual void push(SoState *)
Overrides push() method to copy values from next instance in the stack.
static void setDefault(SoState *state, SoNode *node)
Sets the current texture coordinates, in any of several ways: EXPLICIT, no coordinates (shapes will g...
static void set2(SoState *state, SoNode *node, int32_t numCoords, const SbVec2f *coords, SbBool frcSend=FALSE)
const SbVec4f & get4(int index, int unit=0) const
const SbVec2f & get2(int index, int unit=0) const
Returns the indexed coordinate from an element as a 2- or 4-vector, converting if necessary.
SbBool is2D(int unit=0) const
static void set4(SoState *state, SoNode *node, int32_t numCoords, const SbVec4f *coords, SbBool frcSend=FALSE)
static void setFunction(SoState *state, SoNode *node, SoTextureCoordinateFunctionCB *func, void *userData, SbBool frcSend=FALSE)
const SbVec4f & get(const SbVec3f &point, const SbVec3f &normal, int unit=0) const
Given point and normal, returns texture coordinate.
int32_t getNum(int unit=0) const
Returns the number of coordinate points in an instance.
static CoordType getType(SoState *state, int unit=0)
Returns code indicating what has been set in state/element.
int SbBool
Boolean type.
Definition SbBase.h:87