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 ** Modified by : Gavin Bell (MMM yyyy) 00026 **=======================================================================*/ 00027 /*======================================================================= 00028 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00029 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00030 *** *** 00031 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00032 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00033 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00034 *** *** 00035 *** RESTRICTED RIGHTS LEGEND *** 00036 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00037 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00038 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00039 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00040 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00041 *** *** 00042 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, *** 00043 *** BORDEAUX, FRANCE *** 00044 *** ALL RIGHTS RESERVED *** 00045 **=======================================================================*/ 00046 /*======================================================================= 00047 ** Modified by : AJO (May 2011) 00048 **=======================================================================*/ 00049 00050 00051 #ifndef _SO_INDEXED_FACE_SET_ 00052 #define _SO_INDEXED_FACE_SET_ 00053 00054 #include <Inventor/nodes/SoIndexedShape.h> 00055 00057 // 00058 // Class: SoIndexedFaceSet 00059 // 00060 // Indexed set of faces. Each face consists of 3 or more vertices, 00061 // each of which is denoted by an integer index (from the coordIndex 00062 // field) into the current coordinates. Depending on the current 00063 // material and normal binding values, the materials and normals for 00064 // the faces or vertices may be accessed in order or indexed. If they 00065 // are indexed, the materialIndex and normalIndex fields are used. 00066 // 00068 00069 00070 // This coordinate index indicates that the current face ends and the 00071 // next face begins. Use this for simple (1 contour) polygons. 00072 #define SO_END_FACE_INDEX (-1) 00073 00074 // If SoShapeHints is used with a windingType other than NO_WINDING_TYPE, 00075 // this coordinate index indicates that the current contour ends 00076 // and the next contour begins. 00077 #define SO_END_CONTOUR_INDEX (-1) 00078 00079 // This coordinate index indicates that the current complex face (block 00080 // of contours) ends. 00081 #define SO_END_POLYGON_INDEX (-2) 00082 00083 class SoNormalBundle; 00084 class SoCoordinateElement; 00085 class SoShapeStyleElement; 00086 class SoVolumeIndexedFaceSet; 00087 00246 class SoIndexedFaceSet : public SoIndexedShape { 00247 00248 SO_NODE_HEADER(SoIndexedFaceSet); 00249 00250 public: 00251 // Inherits fields 00252 00256 SoIndexedFaceSet(); 00257 00258 private: 00259 // Implements actions 00260 virtual void GLRender(SoGLRenderAction *action); 00261 00262 // Generates default normals using the given normal bundle. 00263 // Returns TRUE. 00264 virtual void generateDefaultNormals(SoState *state, 00265 const SbVec3f *coords, 00266 int numCoords, 00267 SoNormalBundle *nb, 00268 SbBool storeRef = FALSE); 00269 00270 virtual void getPrimitiveCount(SoGetPrimitiveCountAction *action); 00271 00272 virtual void rayPick(SoRayPickAction *action); 00273 00274 private: 00275 static void initClass(); 00276 static void exitClass(); 00277 00278 virtual int getNumNeededNormals(SoState *state); 00279 00283 virtual SoVertexShaderParameterBufferObject* createPrimitiveIdentifierVertexShaderParameter(SoState* state); 00284 00285 private: 00286 // This enum is used to indicate the current material or normal binding 00287 enum Binding { 00288 OVERALL, PER_FACE, PER_FACE_INDEXED, PER_VERTEX, 00289 PER_VERTEX_INDEXED 00290 }; 00291 00292 //Wether to check or not shapeHints 00293 virtual SbBool shouldCheckShapeHints(){ return TRUE;} 00294 00295 virtual SbBool shouldGenerateTexture3DCoordinates(){return TRUE;} 00296 00297 virtual void callSetupIndices(const SoShapeStyleElement* shapeStyle,uint32_t useTexCoordsAnyway); 00298 00299 //Wether to check or not 3d tex coords 00300 virtual SbBool checkTex3Coords(){return TRUE;} 00301 00302 virtual SbBool shapeHintsTest(){ return (numQuads > 0 || numFaces > 0);} 00303 00304 // Compute the number of vertices. This is just an approximation, 00305 //so using 5 verts per unknown polygon is close enough. 00306 virtual int getNumPrim() 00307 { 00308 if (totalNumVertices==-1) 00309 setupNumTrisQuadsFaces(); 00310 return totalNumVertices; 00311 } 00312 00313 int getNumPrim(int& _numTris, int&_numQuads, int& _numFaces ) 00314 { 00315 if (totalNumVertices==-1) 00316 setupNumTrisQuadsFaces(); 00317 _numTris = numTris; 00318 _numQuads = numQuads; 00319 _numFaces = numFaces; 00320 return totalNumVertices; 00321 } 00322 00323 virtual void countPrim(){setupNumTrisQuadsFaces();} 00324 00325 virtual SbBool numPrimInvalid(){return numTris < 0 ;} 00326 00327 // Generates triangles representing faces 00328 virtual void generatePrimitives(SoAction *action); 00329 00330 // render function 00331 virtual void doRendering(SoGLRenderAction *action, const SoShapeStyleElement* shapeStyle); 00332 00333 // Overrides standard method to create an SoFaceDetail instance 00334 virtual SoDetail * createTriangleDetail(SoRayPickAction *action, 00335 const SoPrimitiveVertex *v1, 00336 const SoPrimitiveVertex *v2, 00337 const SoPrimitiveVertex *v3, 00338 SoPickedPoint *pp); 00339 00340 // set numTris/Quads/Faces to -1 when notified 00341 virtual void notify(SoNotList *list); 00342 00343 // destructor 00344 virtual ~SoIndexedFaceSet(); 00345 00346 private: 00347 00348 // used internally by doRendering 00349 // return true if shape was correctly drawn. 00350 bool doRenderingVBO(SoGLRenderAction *action, const SoShapeStyleElement* shapeStyle); 00351 bool doRenderingNonIndexedVBO(SoGLRenderAction *action, const SoShapeStyleElement* shapeStyle); 00352 00353 // Saves normal binding when generating primitives for picking 00354 Binding savedNormalBinding; 00355 00356 // Returns current material or normal binding from action's state 00357 static Binding getMaterialBinding(SoAction *action); 00358 Binding getNormalBinding(SoAction *action, SoNormalBundle *nb); 00359 00360 // Set number of triangles/quads/faces, based on coordIndex array. 00361 void setupNumTrisQuadsFaces(); 00362 00363 // Number of triangles, quads, (n>4)-vertex faces 00364 int numTris, numQuads, numFaces, totalNumVertices; 00365 00366 // used in desindexed VBO mode for polygons. 00367 GLsizei* m_countArray; 00368 GLint* m_offsetArray; 00369 00370 // optimized normal generation when no creaseAngle is defined. 00371 void buildPerFaceNormals(SoState *state,const SbVec3f *coords, const int numCoords, SoNormalBundle *nb); 00372 00373 // optimized version of connectivity computation when tolerance factor is 0.0 00374 int32_t *buildConnectivity(const SbVec3f *coords, const int numCoords); 00375 00376 static const int AUTO_CACHE_IFS_MIN_WITHOUT_VP; 00377 static const int AUTO_CACHE_IFS_MAX; 00378 00379 private: 00380 friend class SoVolumeIndexedFaceSet; 00381 }; 00382 00383 #endif /* _SO_INDEXED_FACE_SET_ */ 00384 00385 00386