Open Inventor Release 2024.1.1
 
Loading...
Searching...
No Matches
SoTextureCoordinate3Bundle.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-2017 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : Patrick Vigneras (Nov 1999)
22**=======================================================================*/
23
24#ifndef _SO_TEXTURE_COORDINATE3_BUNDLE
25#define _SO_TEXTURE_COORDINATE3_BUNDLE
26
27#include <Inventor/bundles/SoBundle.h>
28#include <Inventor/elements/SoTextureCoordinate3Element.h>
29#include <Inventor/misc/SoState.h>
30#include <memory>
31
32class TexGenEvaluatorBundle3;
33
35//
36// Class: SoTextureCoordinate3Bundle
37//
38// Bundle that allows shapes to deal with texture coordinates more
39// easily. This class provides a fairly simple interface to texture
40// coordinate handling, including default texture coordinate
41// generation. This can be used during either rendering or primitive
42// generation.
43//
44// This class can be used during either rendering or primitive
45// generation. For primitive generation, there are two cases,
46// distinguished by the flag returned by isFunction(). If this
47// flag is TRUE, the texture coordinates are to be generated using
48// the get(point, normal) method, which uses a software texture
49// coordinate function. (This process is also used for texture
50// coordinates that are generated by default when necessary - in this
51// case, the function does a linear map across two sides of the
52// bounding box of the shape.) If the isFunction() flag is FALSE, the
53// coordinates are accessed directly from the element using the
54// get(index) method.
55//
56// For GL rendering, there is an additional case. If
57// needCoordinates() returns FALSE, no texture coordinates need to be
58// sent at all, and the bundle does not have to be used for anything
59// else. Otherwise, send(index) should be used.
60//
62
63{
64
65public:
66 // Constructor - takes the action the bundle is used for and a
67 // flag to indicate whether the bundle is being used for
68 // rendering. If this is TRUE, the bundle can be used to send
69 // texture coordinates to GL. If it is FALSE, the setUpDefault
70 // flag (default TRUE) indicates whether to set up a texture
71 // coordinate function if the binding is DEFAULT. Shapes can pass
72 // FALSE here if they are picking and want to delay computation of
73 // the texture coordinates until an intersection is found.
74 SoTextureCoordinate3Bundle(SoAction *action, SbBool forRendering,
75 SbBool setUpDefault = TRUE);
76
77 // This constructor is used for meshes such as QuadMesh.
78 // The constructor calls different methods to insure
79 // that the texture doesn't get mapped edgeon. The last argument is
80 // just to make the methods unique.
81 SoTextureCoordinate3Bundle(SoAction *action, SbBool forRendering,
82 SbBool setUpDefault, SbBool forMesh);
83 // Destructor
84 ~SoTextureCoordinate3Bundle();
85
86 // Returns TRUE if texture coordinates are needed at all
87 SbBool needCoordinates() const { return needCoords; }
88
89 // return value to determine which get() to use.
90 SbBool isFunction() const { return isFunc; }
91
92 // Returns texture coordinate computed by function during
93 // primitive generation or rendering
94 SbVec4f get(const SbVec3f &point, const SbVec3f &normal) const
95 { return texCoordElt->get(point, normal); }
96
97 // Returns indexed texture coordinate during primitive generation
98 // or rendering
99 SbVec4f get(int index) const
100 { if (tCoords) return(SbVec4f(tCoords[index][0],tCoords[index][1],
101 0.0, 1.0));
102 else return texCoordElt->get4(index); }
103
104 // Sends indexed texture coordinate to GL during rendering
105 void send(int index) const;
106
107private:
108 // TextureCoordinate3 elements:
109 const SoTextureCoordinate3Element *texCoordElt;
110 const SoTextureCoordinate3Element *GLTexCoordElt;
111
112 SbBool needCoords; // Texture coordinates are needed
113 SbBool isFunc; // Coordinates generated by function
114 SbBool isRendering; // Bundle being used for rendering
115 SbBool setFunction; // We set default coord func in state
116
117 // These indicate the dimensions used for S, T and R for default
118 // texture coordinate generation
119 int coordS, coordT, coordR;
120 // These hold the vectors used for default texture coordinate generation
121 SbVec4f sVector, tVector, rVector;
122 // This holds the texture coords from a vertexProperty node:
123 const SbVec3f * tCoords;
124
125 // Sets up bundle for primitive generation or rendering
126 void setUpForPrimGen(SoAction *action,
127 SbBool setUpDefault);
128 void setUpForGLRender(SoAction *action);
129
130 // Sets up for default texture coordinate generation
131 void setUpDefaultCoordSpace(SoAction *action);
132
133 // Sets up bundle for primitive generation or rendering for meshes
134 void setUpForPrimGenMesh(SoAction *action,
135 SbBool setUpDefault);
136 void setUpForGLRenderMesh(SoAction *action);
137
138 // Sets up for default texture coordinate generation for meshes
139 void setUpDefaultCoordSpaceMesh(SoAction *action);
140
141 void setupTextureCoordinateElement(SoState* state, SoNode* currentNode) const;
142
143 std::unique_ptr<TexGenEvaluatorBundle3> m_texGenEvaluator;
144};
145
146#endif /* _SO_TEXTURE_COORDINATE3_BUNDLE */
147
148
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
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Stores the curre...
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.
int SbBool
Boolean type.
Definition SbBase.h:87