Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SoTextureCoordinateBundle.h
Go to the documentation of this file.
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 : Paul S. Strauss (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-2020 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_BUNDLE
51#define _SO_TEXTURE_COORDINATE_BUNDLE
52
56#include <memory>
57
58class TexGenEvaluatorBundle;
59
61//
62// Class: SoTextureCoordinateBundle
63//
64// Bundle that allows shapes to deal with texture coordinates more
65// easily. This class provides a fairly simple interface to texture
66// coordinate handling, including default texture coordinate
67// generation. This can be used during either rendering or primitive
68// generation.
69//
70// This class can be used during either rendering or primitive
71// generation. For primitive generation, there are two cases,
72// distinguished by the flag returned by isFunction(). If this
73// flag is TRUE, the texture coordinates are to be generated using
74// the get(point, normal) method, which uses a software texture
75// coordinate function. (This process is also used for texture
76// coordinates that are generated by default when necessary - in this
77// case, the function does a linear map across two sides of the
78// bounding box of the shape.) If the isFunction() flag is FALSE, the
79// coordinates are accessed directly from the element using the
80// get(index) method.
81//
82// For GL rendering, there is an additional case. If
83// needCoordinates() returns FALSE, no texture coordinates need to be
84// sent at all, and the bundle does not have to be used for anything
85// else. Otherwise, send(index) should be used.
86//
88
89{
90
91 public:
92 // Constructor - takes the action the bundle is used for and a
93 // flag to indicate whether the bundle is being used for
94 // rendering. If this is TRUE, the bundle can be used to send
95 // texture coordinates to GL. If it is FALSE, the setUpDefault
96 // flag (default TRUE) indicates whether to set up a texture
97 // coordinate function if the binding is DEFAULT. Shapes can pass
98 // FALSE here if they are picking and want to delay computation of
99 // the texture coordinates until an intersection is found.
100 // texUnits is the eventual list of texture units where texture
101 // coordinates should be generated. If not set the current texture unit is used.
102 SoTextureCoordinateBundle(SoAction *action, SbBool forRendering,
103 SbBool setUpDefault = TRUE, const SbIntList *texUnits=NULL);
104
105 // This constructor is used for meshes such as VEMLElevationGrid or
106 // QuadMesh. The constructor calls different methods to insure
107 // that the texture doesn't get mapped edgeon. The last argument is
108 // just to make the methods unique.
109 // texUnits is the eventual list of texture units where texture
110 // coordinates should be generated. If not set the current texture unit is used.
112 SbBool setUpDefault, SbBool forMesh,
113 const SbIntList *texUnits=NULL);
114 // Destructor
116
117 // Returns TRUE if texture coordinates are needed at all
118 SbBool needCoordinates() const { return needCoords; }
119
120 // return value to determine which get() to use.
121 SbBool isFunction() const { return isFunc; }
122
123 // Returns texture coordinate computed by function during
124 // primitive generation or rendering
125 SbVec4f get(const SbVec3f &point, const SbVec3f &normal) const
126 { return texCoordElt->get(point, normal, m_curUnit); }
127
128 // Returns indexed texture coordinate during primitive generation
129 // or rendering
130 SbVec4f get(int index) const
131 { if (tCoords)
132 return(SbVec4f(tCoords[index][0],tCoords[index][1],
133 0.0, 1.0));
134 else
135 return texCoordElt->get4(index, m_curUnit);
136 }
137
138 // Sends indexed texture coordinate to GL during rendering
139 void send(int index) const;
140
141 private:
142 // TextureCoordinate elements:
143 const SoTextureCoordinateElement *texCoordElt;
144 const SoTextureCoordinateElement *GLTexCoordElt;
145
146 SbBool needCoords; // Texture coordinates are needed
147 SbBool isFunc; // Coordinates generated by function
148 SbBool isRendering; // Bundle being used for rendering
149 SbBool m_statePushed ; // Indicate if the state has been pushed
150
151 // These indicate the dimensions used for S and T for default
152 // texture coordinate generation
153 int coordS, coordT;
154 // These hold the vectors used for default texture coordinate generation
155 SbVec4f sVector, tVector;
156 // This holds the texture coords from a vertexProperty node:
157 const SbVec2f * tCoords;
158
159 // The eventual list of texture units where texture
160 // coordinates should be generated. If not set the current texture unit is used.
161 const SbIntList *m_texUnits ;
162
163 // First texture image unit
164 int m_unitImage ;
165
166 // Current texture unit
167 int m_curUnit ;
168
169 // Sets up bundle for primitive generation or rendering
170 void setUpForPrimGen(SoAction *action, SbBool setUpDefault);
171 void setUpForGLRender(SoAction *action);
172
173 // Sets up for default texture coordinate generation
174 void setUpDefaultCoordSpace(SoAction *action);
175
176 // Sets up bundle for primitive generation or rendering for meshes
177 void setUpForPrimGenMesh(SoAction *action, SbBool setUpDefault, SbBool forMesh);
178 void setUpForGLRenderMesh(SoAction *action, SbBool forMesh);
179
180 // Sets up for default texture coordinate generation for meshes
181 void setUpDefaultCoordSpaceMesh(SoAction *action, SbBool forMesh);
182
183 // Update texture units used
184 void updateTexUnits(const SbIntList *texUnits) ;
185
187 void setupTextureCoordinateElement(SoState* state, SoNode* currentNode) const;
188
189 std::unique_ptr<TexGenEvaluatorBundle> m_texGenEvaluator;
190};
191
192#endif /* _SO_TEXTURE_COORDINATE_BUNDLE */
193
194
#define TRUE
Possible value of SbBool.
Definition SbBase.h:77
SbIntList(int initSize)
Maintains a list of integer (int) values.
SbBool isFunction() const
void send(int index) const
~SoTextureCoordinateBundle()
SbBool needCoordinates() const
SbVec4f get(const SbVec3f &point, const SbVec3f &normal) const
SoTextureCoordinateBundle(SoAction *action, SbBool forRendering, SbBool setUpDefault, SbBool forMesh, const SbIntList *texUnits=NULL)
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 actions.
Definition SoAction.h:132
Abstract base class for all database nodes.
Definition SoNode.h:145
Traversal state.
Definition SoState.h:74
const SbVec4f & get4(int index, int unit=0) const
const SbVec4f & get(const SbVec3f &point, const SbVec3f &normal, int unit=0) const
Given point and normal, returns texture coordinate.
Stores the current texture coordinates.
int SbBool
Boolean type.
Definition SbBase.h:87