00001 /*======================================================================= 00002 * Copyright 1991-1996, Silicon Graphics, Inc. 00003 * ALL RIGHTS RESERVED 00004 * 00005 * UNPUBLISHED -- Rights reserved under the copyright laws of the United 00006 * States. Use of a copyright notice is precautionary only and does not 00007 * imply publication or disclosure. 00008 * 00009 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: 00010 * Use, duplication or disclosure by the Government is subject to restrictions 00011 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights 00012 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or 00013 * in similar or successor clauses in the FAR, or the DOD or NASA FAR 00014 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., 00015 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. 00016 * 00017 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY 00018 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, 00019 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY 00020 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON 00021 * GRAPHICS, INC. 00022 **=======================================================================*/ 00023 /*======================================================================= 00024 ** Author : Paul S. Strauss (MMM yyyy) 00025 **=======================================================================*/ 00026 /*======================================================================= 00027 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00028 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00029 *** *** 00030 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00031 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00032 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00033 *** *** 00034 *** RESTRICTED RIGHTS LEGEND *** 00035 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00036 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00037 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00038 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00039 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00040 *** *** 00041 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, *** 00042 *** BORDEAUX, FRANCE *** 00043 *** ALL RIGHTS RESERVED *** 00044 **=======================================================================*/ 00045 /*======================================================================= 00046 ** Modified by : VSG (MMM YYYY) 00047 **=======================================================================*/ 00048 00049 00050 #ifndef _SO_TEXTURE_COORDINATE_BUNDLE 00051 #define _SO_TEXTURE_COORDINATE_BUNDLE 00052 00053 #include <Inventor/bundles/SoBundle.h> 00054 #include <Inventor/elements/SoTextureCoordinateElement.h> 00055 #include <Inventor/misc/SoState.h> 00056 #include <memory> 00057 00058 class TexGenEvaluatorBundle; 00059 00061 // 00062 // Class: SoTextureCoordinateBundle 00063 // 00064 // Bundle that allows shapes to deal with texture coordinates more 00065 // easily. This class provides a fairly simple interface to texture 00066 // coordinate handling, including default texture coordinate 00067 // generation. This can be used during either rendering or primitive 00068 // generation. 00069 // 00070 // This class can be used during either rendering or primitive 00071 // generation. For primitive generation, there are two cases, 00072 // distinguished by the flag returned by isFunction(). If this 00073 // flag is TRUE, the texture coordinates are to be generated using 00074 // the get(point, normal) method, which uses a software texture 00075 // coordinate function. (This process is also used for texture 00076 // coordinates that are generated by default when necessary - in this 00077 // case, the function does a linear map across two sides of the 00078 // bounding box of the shape.) If the isFunction() flag is FALSE, the 00079 // coordinates are accessed directly from the element using the 00080 // get(index) method. 00081 // 00082 // For GL rendering, there is an additional case. If 00083 // needCoordinates() returns FALSE, no texture coordinates need to be 00084 // sent at all, and the bundle does not have to be used for anything 00085 // else. Otherwise, send(index) should be used. 00086 // 00088 00089 { 00090 00091 public: 00092 // Constructor - takes the action the bundle is used for and a 00093 // flag to indicate whether the bundle is being used for 00094 // rendering. If this is TRUE, the bundle can be used to send 00095 // texture coordinates to GL. If it is FALSE, the setUpDefault 00096 // flag (default TRUE) indicates whether to set up a texture 00097 // coordinate function if the binding is DEFAULT. Shapes can pass 00098 // FALSE here if they are picking and want to delay computation of 00099 // the texture coordinates until an intersection is found. 00100 // texUnits is the eventual list of texture units where texture 00101 // coordinates should be generated. If not set the current texture unit is used. 00102 SoTextureCoordinateBundle(SoAction *action, SbBool forRendering, 00103 SbBool setUpDefault = TRUE, const SbIntList *texUnits=NULL); 00104 00105 // This constructor is used for meshes such as VEMLElevationGrid or 00106 // QuadMesh. The constructor calls different methods to insure 00107 // that the texture doesn't get mapped edgeon. The last argument is 00108 // just to make the methods unique. 00109 // texUnits is the eventual list of texture units where texture 00110 // coordinates should be generated. If not set the current texture unit is used. 00111 SoTextureCoordinateBundle(SoAction *action, SbBool forRendering, 00112 SbBool setUpDefault, SbBool forMesh, 00113 const SbIntList *texUnits=NULL); 00114 // Destructor 00115 ~SoTextureCoordinateBundle(); 00116 00117 // Returns TRUE if texture coordinates are needed at all 00118 SbBool needCoordinates() const { return needCoords; } 00119 00120 // return value to determine which get() to use. 00121 SbBool isFunction() const { return isFunc; } 00122 00123 // Returns texture coordinate computed by function during 00124 // primitive generation or rendering 00125 SbVec4f get(const SbVec3f &point, const SbVec3f &normal) const 00126 { return texCoordElt->get(point, normal, m_curUnit); } 00127 00128 // Returns indexed texture coordinate during primitive generation 00129 // or rendering 00130 SbVec4f get(int index) const 00131 { if (tCoords) 00132 return(SbVec4f(tCoords[index][0],tCoords[index][1], 00133 0.0, 1.0)); 00134 else 00135 return texCoordElt->get4(index, m_curUnit); 00136 } 00137 00138 // Sends indexed texture coordinate to GL during rendering 00139 void send(int index) const; 00140 00141 private: 00142 // TextureCoordinate elements: 00143 const SoTextureCoordinateElement *texCoordElt; 00144 const SoTextureCoordinateElement *GLTexCoordElt; 00145 00146 SbBool needCoords; // Texture coordinates are needed 00147 SbBool isFunc; // Coordinates generated by function 00148 SbBool isRendering; // Bundle being used for rendering 00149 SbBool m_statePushed ; // Indicate if the state has been pushed 00150 00151 // These indicate the dimensions used for S and T for default 00152 // texture coordinate generation 00153 int coordS, coordT; 00154 // These hold the vectors used for default texture coordinate generation 00155 SbVec4f sVector, tVector; 00156 // This holds the texture coords from a vertexProperty node: 00157 const SbVec2f * tCoords; 00158 00159 // The eventual list of texture units where texture 00160 // coordinates should be generated. If not set the current texture unit is used. 00161 const SbIntList *m_texUnits ; 00162 00163 // First texture image unit 00164 int m_unitImage ; 00165 00166 // Current texture unit 00167 int m_curUnit ; 00168 00169 // Sets up bundle for primitive generation or rendering 00170 void setUpForPrimGen(SoAction *action, SbBool setUpDefault); 00171 void setUpForGLRender(SoAction *action); 00172 00173 // Sets up for default texture coordinate generation 00174 void setUpDefaultCoordSpace(SoAction *action); 00175 00176 // Sets up bundle for primitive generation or rendering for meshes 00177 void setUpForPrimGenMesh(SoAction *action, SbBool setUpDefault, SbBool forMesh); 00178 void setUpForGLRenderMesh(SoAction *action, SbBool forMesh); 00179 00180 // Sets up for default texture coordinate generation for meshes 00181 void setUpDefaultCoordSpaceMesh(SoAction *action, SbBool forMesh); 00182 00183 // Update texture units used 00184 void updateTexUnits(const SbIntList *texUnits) ; 00185 00187 void setupTextureCoordinateElement(SoState* state, SoNode* currentNode) const; 00188 00189 std::unique_ptr<TexGenEvaluatorBundle> m_texGenEvaluator; 00190 }; 00191 00192 #endif /* _SO_TEXTURE_COORDINATE_BUNDLE */ 00193 00194 00195