00001 /*======================================================================= 00002 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00003 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00004 *** *** 00005 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00006 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00007 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00008 *** *** 00009 *** RESTRICTED RIGHTS LEGEND *** 00010 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00011 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00012 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00013 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00014 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00015 *** *** 00016 *** COPYRIGHT (C) 1996-2017 BY FEI S.A.S, *** 00017 *** BORDEAUX, FRANCE *** 00018 *** ALL RIGHTS RESERVED *** 00019 **=======================================================================*/ 00020 /*======================================================================= 00021 ** Author : Patrick Vigneras (Nov 1999) 00022 **=======================================================================*/ 00023 00024 #ifndef _SO_TEXTURE_COORDINATE3_BUNDLE 00025 #define _SO_TEXTURE_COORDINATE3_BUNDLE 00026 00027 #include <Inventor/bundles/SoBundle.h> 00028 #include <Inventor/elements/SoTextureCoordinate3Element.h> 00029 #include <Inventor/misc/SoState.h> 00030 #include <memory> 00031 00032 class TexGenEvaluatorBundle3; 00033 00035 // 00036 // Class: SoTextureCoordinate3Bundle 00037 // 00038 // Bundle that allows shapes to deal with texture coordinates more 00039 // easily. This class provides a fairly simple interface to texture 00040 // coordinate handling, including default texture coordinate 00041 // generation. This can be used during either rendering or primitive 00042 // generation. 00043 // 00044 // This class can be used during either rendering or primitive 00045 // generation. For primitive generation, there are two cases, 00046 // distinguished by the flag returned by isFunction(). If this 00047 // flag is TRUE, the texture coordinates are to be generated using 00048 // the get(point, normal) method, which uses a software texture 00049 // coordinate function. (This process is also used for texture 00050 // coordinates that are generated by default when necessary - in this 00051 // case, the function does a linear map across two sides of the 00052 // bounding box of the shape.) If the isFunction() flag is FALSE, the 00053 // coordinates are accessed directly from the element using the 00054 // get(index) method. 00055 // 00056 // For GL rendering, there is an additional case. If 00057 // needCoordinates() returns FALSE, no texture coordinates need to be 00058 // sent at all, and the bundle does not have to be used for anything 00059 // else. Otherwise, send(index) should be used. 00060 // 00062 00063 { 00064 00065 public: 00066 // Constructor - takes the action the bundle is used for and a 00067 // flag to indicate whether the bundle is being used for 00068 // rendering. If this is TRUE, the bundle can be used to send 00069 // texture coordinates to GL. If it is FALSE, the setUpDefault 00070 // flag (default TRUE) indicates whether to set up a texture 00071 // coordinate function if the binding is DEFAULT. Shapes can pass 00072 // FALSE here if they are picking and want to delay computation of 00073 // the texture coordinates until an intersection is found. 00074 SoTextureCoordinate3Bundle(SoAction *action, SbBool forRendering, 00075 SbBool setUpDefault = TRUE); 00076 00077 // This constructor is used for meshes such as QuadMesh. 00078 // The constructor calls different methods to insure 00079 // that the texture doesn't get mapped edgeon. The last argument is 00080 // just to make the methods unique. 00081 SoTextureCoordinate3Bundle(SoAction *action, SbBool forRendering, 00082 SbBool setUpDefault, SbBool forMesh); 00083 // Destructor 00084 ~SoTextureCoordinate3Bundle(); 00085 00086 // Returns TRUE if texture coordinates are needed at all 00087 SbBool needCoordinates() const { return needCoords; } 00088 00089 // return value to determine which get() to use. 00090 SbBool isFunction() const { return isFunc; } 00091 00092 // Returns texture coordinate computed by function during 00093 // primitive generation or rendering 00094 SbVec4f get(const SbVec3f &point, const SbVec3f &normal) const 00095 { return texCoordElt->get(point, normal); } 00096 00097 // Returns indexed texture coordinate during primitive generation 00098 // or rendering 00099 SbVec4f get(int index) const 00100 { if (tCoords) return(SbVec4f(tCoords[index][0],tCoords[index][1], 00101 0.0, 1.0)); 00102 else return texCoordElt->get4(index); } 00103 00104 // Sends indexed texture coordinate to GL during rendering 00105 void send(int index) const; 00106 00107 private: 00108 // TextureCoordinate3 elements: 00109 const SoTextureCoordinate3Element *texCoordElt; 00110 const SoTextureCoordinate3Element *GLTexCoordElt; 00111 00112 SbBool needCoords; // Texture coordinates are needed 00113 SbBool isFunc; // Coordinates generated by function 00114 SbBool isRendering; // Bundle being used for rendering 00115 SbBool setFunction; // We set default coord func in state 00116 00117 // These indicate the dimensions used for S, T and R for default 00118 // texture coordinate generation 00119 int coordS, coordT, coordR; 00120 // These hold the vectors used for default texture coordinate generation 00121 SbVec4f sVector, tVector, rVector; 00122 // This holds the texture coords from a vertexProperty node: 00123 const SbVec3f * tCoords; 00124 00125 // Sets up bundle for primitive generation or rendering 00126 void setUpForPrimGen(SoAction *action, 00127 SbBool setUpDefault); 00128 void setUpForGLRender(SoAction *action); 00129 00130 // Sets up for default texture coordinate generation 00131 void setUpDefaultCoordSpace(SoAction *action); 00132 00133 // Sets up bundle for primitive generation or rendering for meshes 00134 void setUpForPrimGenMesh(SoAction *action, 00135 SbBool setUpDefault); 00136 void setUpForGLRenderMesh(SoAction *action); 00137 00138 // Sets up for default texture coordinate generation for meshes 00139 void setUpDefaultCoordSpaceMesh(SoAction *action); 00140 00141 void setupTextureCoordinateElement(SoState* state, SoNode* currentNode) const; 00142 00143 std::unique_ptr<TexGenEvaluatorBundle3> m_texGenEvaluator; 00144 }; 00145 00146 #endif /* _SO_TEXTURE_COORDINATE3_BUNDLE */ 00147 00148 00149