00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #ifndef _SO_TEXTURE_COORDINATE_ELEMENT
00051 #define _SO_TEXTURE_COORDINATE_ELEMENT
00052
00053 #include <Inventor/SbLinear.h>
00054 #include <Inventor/elements/SoReplacedTextureElement.h>
00055 #include <Inventor/SbEnums.h>
00056 #include <memory>
00057
00058 #include <Inventor/STL/vector>
00059
00065 typedef const SbVec4f &
00066 SoTextureCoordinateFunctionCB(void *userdata, const SbVec3f &point,
00067 const SbVec3f &normal);
00068
00069
00081 SoEXTENDER_Documented class SoTextureCoordinateElement : public SoReplacedTextureElement {
00082
00083 SO_ELEMENT_HEADER(SoTextureCoordinateElement);
00084
00085 public:
00090 enum CoordType {
00091 EXPLICIT = 1,
00092 FUNCTION = 2
00093 };
00094
00099 static void setDefault(SoState *state, SoNode *node);
00100
00101
00102 static void setFunction(SoState *state, SoNode *node,
00103 SoTextureCoordinateFunctionCB *func,
00104 void *userData,
00105 SbBool frcSend = FALSE);
00106
00110 static void set2(SoState *state, SoNode *node,
00111 int32_t numCoords, const SbVec2f *coords,
00112 SbBool frcSend = FALSE);
00113
00117 static void set4(SoState *state, SoNode *node,
00118 int32_t numCoords, const SbVec4f *coords,
00119 SbBool frcSend = FALSE);
00120
00125 static CoordType getType(SoState *state, int unit=0);
00126
00127 virtual CoordType getType(int unit=0) const;
00128
00135 static const SoTextureCoordinateElement * getInstance(SoState *state);
00136
00137
00138
00144 const SbVec4f & get(const SbVec3f &point, const SbVec3f &normal,
00145 int unit=0) const;
00146
00147
00148
00152 int32_t getNum(int unit=0) const ;
00153
00154 SbBool is2D(int unit=0) const ;
00155
00156 SbBool isForceSending(int unit=0) const ;
00157
00162 const SbVec2f & get2(int index, int unit=0) const;
00163 const SbVec4f & get4(int index, int unit=0) const;
00164
00168 virtual void print(FILE *fp) const;
00169
00173 virtual void push(SoState *) ;
00174
00175 private:
00176
00178 virtual void commonInit();
00179
00181 virtual void init(SoState *state);
00182
00183 private:
00188 class TexGenEvaluator
00189 {
00190 public:
00191 virtual const SbVec4f& eval(const SbVec3f &point, const SbVec3f &normal) = 0;
00192 };
00193
00195 static void setTextureCoordType(SoState *state, SoNode *node, CoordType coordType);
00196
00197
00198 static void initClass();
00199 static void exitClass();
00200
00201 private:
00202
00203 virtual ~SoTextureCoordinateElement();
00204
00205 struct SoTexCoordData
00206 {
00207
00208 CoordType whatKind;
00209
00210
00211 std::shared_ptr<TexGenEvaluator> m_texGenEvaluatorUserDefined;
00212
00213
00214 int32_t numCoords;
00215 const SbVec2f *coords2;
00216 const SbVec4f *coords4;
00217 SbBool coordsAre2D;
00218 SbBool forceSend;
00219
00220 SoTexCoordData() :
00221 whatKind(EXPLICIT),
00222 numCoords(0),
00223 coords2(NULL),
00224 coords4(NULL),
00225 coordsAre2D(FALSE),
00226 forceSend(FALSE)
00227 {
00228 }
00229
00230 void initValues( const CoordType &type )
00231 {
00232 whatKind = type;
00233 numCoords = 0;
00234 coords2 = NULL;
00235 coords4 = NULL;
00236 coordsAre2D = FALSE;
00237 forceSend = FALSE;
00238 m_texGenEvaluatorUserDefined.reset();
00239 }
00240
00241 SoTexCoordData& operator=(const SoTexCoordData& data)
00242 {
00243 if ( &data != this )
00244 {
00245 whatKind = data.whatKind ;
00246 numCoords = data.numCoords ;
00247 coords2 = data.coords2 ;
00248 coords4 = data.coords4 ;
00249 coordsAre2D = data.coordsAre2D ;
00250 forceSend = data.forceSend;
00251 }
00252 return *this ;
00253 }
00254 } ;
00255
00256 SoTexCoordData& getTexCoordData( const int unit ) const;
00257
00258 private:
00259 SbVec2f m_convert2;
00260 SbVec4f m_convert4;
00261
00262
00263 SoState* m_state;
00264
00265 typedef std::vector<SoTexCoordData> SoTexCoordDataList;
00266
00267 mutable SoTexCoordDataList m_texCoordData ;
00268 };
00269
00270
00271 #endif
00272