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_SHAPE_
00051 #define  _SO_SHAPE_
00052 
00053 #include <Inventor/SbLinear.h>
00054 #include <Inventor/SbMatrix.h>
00055 #include <Inventor/nodes/SoNode.h>
00056 #include <Inventor/fields/SoSFBool.h>
00057 
00058 #include <Inventor/sys/SoGLType.h>
00059 
00060 class SoCube;
00061 class SoDetail;
00062 class SoFaceDetail;
00063 class SoMaterialBundle;
00064 class SoPickedPoint;
00065 class SoPointDetail;
00066 class SoPrimitiveVertex;
00067 class SoState;
00068 class SoMFInt32;
00069 class SoMultiPassManagerOld ;
00070 class GLUtesselator;
00071 
00072 class SbBoxPartition;
00073 class SbBoxPartitionIntersectionInfo;
00074 class SoBBoxShapeCache;
00075 
00076 typedef SoPrimitiveVertex *jySoPrimitiveVertexPtr;
00077 typedef SoDetail *jySoDetailPtr;
00078 
00080 
00081 
00082 
00083 
00084 
00085 
00087 
00120 class  SoShape : public SoNode {
00121 
00122   SO_NODE_ABSTRACT_HEADER(SoShape);
00123 
00124  public:
00128   SoSFBool boundingBoxIgnoring;
00129 
00133   virtual SbBool affectsState() const;
00134 
00140   enum ShapeType {
00142     POINTS,
00144     LINES,
00146     POLYGONS,
00148     TEXT
00149   };
00150 
00154   ShapeType getShapeType();
00155 
00164   static SbBool isPrimitiveRestartAvailable(SoState* state = NULL);
00165 
00166  private:
00167 
00172   enum TriangleShape {
00173     TRIANGLE_STRIP,
00174     TRIANGLE_FAN,
00175     TRIANGLES,
00176     POLYGON
00177   };
00178 
00201   void beginShape(SoAction *action, TriangleShape shapeType,
00202     SoFaceDetail *faceDetail = NULL);
00203 
00208   void shapeVertex(const SoPrimitiveVertex *v);
00209 
00213   void endShape();
00214 
00215  private:
00220   virtual void getBoundingBox(SoGetBoundingBoxAction *action);
00221 
00226   virtual void GLRender(SoGLRenderAction *action);
00227 
00233   virtual void rayPick(SoRayPickAction *action);
00234 
00239   virtual void callback(SoCallbackAction *action);
00240 
00247   static void getScreenSize(SoState *state, const SbBox3f &boundingBox, SbVec2s &rectSize);
00248 
00257   static float getDecimatedComplexity(SoState *state, float complexity);
00258 
00266   virtual void computeBBox(SoAction *action, SbBox3f &box, SbVec3f ¢er) = 0;
00267 
00284   virtual void computeBBox(SoAction *action, SbXfBox3d &box, SbVec3d ¢er)
00285   {
00286     
00287     SbBox3f boxf;
00288     SbVec3f centerf;
00289     computeBBox(action, boxf, centerf);
00290 
00291     box.setTransform(SbMatrixd::identity());
00292     box.makeEmpty();
00293     box.setBounds(SbVec3d(boxf.getMin().getValue()),SbVec3d(boxf.getMax().getValue()));
00294     center.setValue(centerf);
00295   }
00296 
00302   virtual void getPrimitiveCount(SoGetPrimitiveCountAction *action);
00303 
00311   static void setRasterPos( SbVec3f &pos, SoState *state );
00312 
00316   virtual SbMatrix3* computeVtxTangentSpaceMat(const float *, int &) const
00317     {return NULL ;}
00318 
00319   
00320   
00321   
00322   
00323   static SbBool getMultiTextureInfo(SoState *state, SbIntList &imageTextUnitList) ;
00324                                    
00328   void setShapeType(SoShape::ShapeType st);
00329 
00330   
00331   
00332   
00333   
00334   
00335   
00336   void invokeTriangleCallbacks(SoAction *action,
00337                                const SoPrimitiveVertex *v1,
00338                                const SoPrimitiveVertex *v2,
00339                                const SoPrimitiveVertex *v3);
00340   void invokeLineSegmentCallbacks(SoAction *action,
00341                                   const SoPrimitiveVertex *v1,
00342                                   const SoPrimitiveVertex *v2);
00343   void invokePointCallbacks(SoAction *action,
00344                             const SoPrimitiveVertex *v);
00345 
00346  private:
00347   static void initClass();
00348   static void exitClass();
00349 
00350   
00351   virtual void GLRenderP(SoGLRenderAction *action);
00352 
00353   SB_THREAD_TLS_HEADER();
00354 
00360   inline virtual SbBool isBoundingBoxIgnoring() const
00361   { return boundingBoxIgnoring.getValue(); }
00362 
00363   
00364   SbBool m_forceDisableProjection;
00365 
00366   void setForceDisableProjection( SbBool disable ){m_forceDisableProjection = disable;}
00367 
00368   SbBool getTTSA();
00369   
00370   void setTTSA(SbBool enable);
00371 
00372   static bool isVertexArrayAvailable(SoState* state=NULL);
00373   static bool isMultiDrawArrayAvailable(SoState* state=NULL);
00374   static bool isVertexBufferAvailable(SoState* state=NULL);
00375 
00376   
00377   
00378   static bool shouldUseVertexArray(SoState* state, size_t numVertices);
00379 
00380   
00381   static void setupCacheForVertexArray(SoState* state, size_t numVertices);
00382 
00383   
00384   static int getPrimitiveRestartMode(SoState* state = NULL);
00385 
00386   bool renderTransparentSortedTriangles( SoGLRenderAction* );
00387 
00388  private:
00389 
00390   
00391   SoShape();
00392 
00393   virtual SbBool checkShapeHints(SoGLRenderAction *action,SbThreadAutoWriteLock *autolock=0);
00394 
00395   virtual void countPrim(){}
00396 
00397   virtual int getNumPrim(){return 0;}
00398 
00399   virtual SbBool checkTransparency(SoGLRenderAction *action, SbBool isPointsOrLines);
00400 
00401   virtual int getNumVert(){return getNumPrim();}
00402 
00403   virtual SbBool numPrimInvalid(){return FALSE;}
00404 
00405   virtual SbBool isRenderingPointsOrLines(SoGLRenderAction *action);
00406 
00407   virtual SbBool shouldRenderNow(SoGLRenderAction *action,SbBool &isPointsOrLines);
00408 
00409   
00410 
00411   
00412   
00413   
00414   virtual void generatePrimitives(SoAction *action) = 0;
00415 
00416   
00417   
00418   
00419   virtual SbBool shouldGLRender(SoGLRenderAction *action,
00420                                 SbBool isPointsOrLines = FALSE);
00421 
00422   
00423   
00424   
00425   
00426   
00427   SbBool shouldGLRenderCore(SoGLRenderAction *action,
00428                       SbBool isPointsOrLines = FALSE,
00429                       SbBool hasTessellationShader = FALSE);
00430 
00431   
00432   
00433   
00434   SbBool handleInvisibleOrBBox(SoGLRenderAction *action,
00435                                 SbBool isPointsOrLines = FALSE);
00436 
00437   
00438   
00439   SbBool shouldRayPick(SoRayPickAction *action);
00440 
00441   
00442   
00443   
00444   SbBool shouldPrimitiveCount(SoGetPrimitiveCountAction *action);
00445 
00447   
00448   
00449   
00450   void beginSolidShape(SoGLRenderAction *action);
00451   void endSolidShape(SoGLRenderAction *action);
00452 
00453   
00454   
00455   
00456   
00457   
00458   
00459   void computeObjectSpaceRay(SoRayPickAction *action);
00460   void computeObjectSpaceRay(SoRayPickAction *action,
00461                              const SbMatrix &matrix);
00462 
00463   
00464   
00465   
00466   
00467   
00468   
00469   
00470   virtual SoDetail *createTriangleDetail(SoRayPickAction *action,
00471                                          const SoPrimitiveVertex *v1,
00472                                          const SoPrimitiveVertex *v2,
00473                                          const SoPrimitiveVertex *v3,
00474                                          SoPickedPoint *pp);
00475   virtual SoDetail *createLineSegmentDetail(SoRayPickAction *action,
00476                                             const SoPrimitiveVertex *v1,
00477                                             const SoPrimitiveVertex *v2,
00478                                             SoPickedPoint *pp);
00479   virtual SoDetail *createPointDetail(SoRayPickAction *action,
00480                                       const SoPrimitiveVertex *v,
00481                                       SoPickedPoint *pp);
00482   
00483   
00484   
00485   
00486   void endShape( int wt, SoMFInt32* indexes );
00487 
00488   virtual ~SoShape();
00489     
00490   
00491   
00492   virtual void GLRenderBoundingBox(SoGLRenderAction *action);
00493 
00494   
00495   
00496   void fillOneVtxTangentSpaceMat(const SbVec3f &s, SbVec3f &normal, SbMatrix3 &tgtSpaceMat) const ;
00497 
00498   
00499   
00500   virtual void applyFullSceneAntialiasingFilter(SoState* state);
00501 
00502  private:
00503    
00504    
00505    typedef SbPList SoApplyingList;
00506    struct MTstruct
00507    {
00508      unsigned int *vaIndices;
00509      float *vaVertex;
00510      float *vaNormal;
00511      float *vaTexture;
00512      unsigned char *vaColor1;
00513      int *vaColor2;
00514 
00515      int vaIndicesSize;
00516      int vaVertexSize;
00517      int vaNormalSize;
00518      int vaTextureSize;
00519      int vaColor1Size;
00520      int vaColor2Size;
00521 
00522      GLUtesselator *tobj;        
00523      SoPrimitiveVertex *polyVerts;        
00524      SoPointDetail     *polyDetails;
00525      SoPrimitiveVertex *primVerts;        
00526      SoPointDetail     *vertDetails;
00527      int numPolyVertsAllocated;        
00528 
00529      TriangleShape       primShapeType;        
00530      SoFaceDetail        *faceDetail;        
00531      int         nestLevel;        
00532      SoAction    *primAction;        
00533      SoApplyingList* applyingList;
00534      int         primVertNum;        
00535      int         polyVertNum;        
00536      SoShape     *primShape;        
00537 
00538      jySoPrimitiveVertexPtr *jy_v;
00539      jySoPrimitiveVertexPtr *jy_v_tmp;
00540      int jy_v_count;
00541      int jy_v_count_max;
00542 
00543      jySoDetailPtr *jy_dp;
00544      jySoDetailPtr *jy_dp_tmp;
00545 
00546      SbBool sendTexCoords;        
00547      SoMaterialBundle *matlBundle; 
00548    };
00549   static int s_keepReset;
00550   static int s_forceSend;
00551   static SbBool s_noClip;
00552 
00553   
00554   static int autoCacheMinValue;
00555   static int autoCacheMaxValue;
00556 
00557   SoMultiPassManagerOld *m_multiPassMgr ;
00558 
00559   
00560   static int getMaxPrimitiveLoop()
00561   {return s_maxPrimitiveLoop; };
00562 
00563   static int getMinVertexNumForVA()
00564   { return s_minVertexNumForVA; }
00565 
00566   static int getMinVertexNumForVBO()
00567   { return s_minVertexNumForVBO; }
00568 
00569   static int getMinVertexNumForVAVBONoCache()
00570   { return s_minVertexNumForVAVBONoCache; }
00571 
00572   static bool isDesindexingAllowed()
00573   { return s_allowDesIndexing; }
00574 
00575   static float getForceDesindexingReuseFactor()
00576   { return s_forceDesindexingReuseFactor; }
00577 
00578 
00579   static bool isTrisStripAllowedForQuadMesh()
00580   { return s_useTriangleForQuadMesh; }
00581 
00582   static SbBool isDetailDebugEnabled()
00583   { return s_detailDebug; }
00584 
00585   static SbThreadRWMutex *getSharedMutex()
00586   { return s_sharedCacheMutex; }
00587 
00588   static bool isCreaseAngleFixSet()
00589   { return s_creaseAngleFix; }
00590 
00591 SoINTERNAL private:
00592 
00593   
00594   static bool useBBoxPartioning(size_t numPoints);
00595 
00596   
00597   
00598   
00599   SbBool checkLocalBBox(SoRayPickAction* action);
00600 
00601   
00602   void getPartitionIntersection(SoRayPickAction* action, SbBoxPartitionIntersectionInfo* partitionIntersection);
00603 
00604   
00605   SbBoxPartition* createBBoxPartitionCache(SoState* state, size_t numPoints, const SbBox3f& bbox, const SbVec3f& center);
00606   void deleteBBoxPartitionCache();
00607   SoBBoxShapeCache* m_bboxPartitionCache;
00608 
00609 private:
00610   ShapeType m_shapeType;
00611   SbBool m_TriTranspSort;
00612 
00613   
00614   
00615   
00616   
00617   static SoGetBoundingBoxAction *bboxAct;
00618   static SoCube *bboxCube;
00619 
00620   
00621   
00622   void GLRenderTriangle(SoGLRenderAction *action,
00623                         const SoPrimitiveVertex *v1,
00624                         const SoPrimitiveVertex *v2,
00625                         const SoPrimitiveVertex *v3);
00626   void GLRenderLineSegment(SoGLRenderAction *action,
00627                            const SoPrimitiveVertex *v1,
00628                            const SoPrimitiveVertex *v2);
00629   void GLRenderPoint(SoGLRenderAction *action,
00630                      const SoPrimitiveVertex *v);
00631 
00632   
00633   
00634   void rayPickTriangle(SoRayPickAction *action,
00635                        const SoPrimitiveVertex *v1,
00636                        const SoPrimitiveVertex *v2,
00637                        const SoPrimitiveVertex *v3);
00638   void rayPickLineSegment(SoRayPickAction *action,
00639                           const SoPrimitiveVertex *v1,
00640                           const SoPrimitiveVertex *v2);
00641   void rayPickPoint(SoRayPickAction *action,
00642                     const SoPrimitiveVertex *v);
00643 
00644 
00645   
00646   
00647   void rayPickBoundingBox(SoRayPickAction *action);
00648 
00649   
00650   void triangleVertex(struct SoShape::MTstruct *mtstruct, const SoPrimitiveVertex *v, int vertToReplace);
00651 
00652   
00653   void allocateVerts();
00654 
00655   
00656   void addIntersectedPoint(SoRayPickAction *action, const SoPrimitiveVertex *v);
00657 
00658   
00659   const SoShape* getExternalShape(SoAction* action) const;
00660 
00661   
00662   static  void CALLBACK beginCB(GLenum primType);
00663   static void CALLBACK vtxCB(void *vertex);
00664   static void CALLBACK endCB();
00665   static void CALLBACK errorCB(GLenum err);
00666   static void CALLBACK combineCB(GLdouble coords[3], SoPrimitiveVertex *vd[4],
00667                                  GLfloat wt[4], SoPrimitiveVertex **data);
00668 
00669   
00670   
00671   static void transformForwardTraversedVertices(const SbMatrix& model, size_t numVertices, SoPrimitiveVertex** vertices);
00672 
00673   static SbMatrix computeInternalSceneGraphTransforms(SoState *state, const SoPath* path);
00674 
00675   
00676   static int s_useSharedCacheMutex;
00677 
00678   
00679   static SbThreadRWMutex *s_sharedCacheMutex;
00680 
00681   static int    s_maxPrimitiveLoop;
00682   static int    s_minVertexNumForVA;
00683   static int    s_minVertexNumForVBO;
00684   static int    s_minVertexNumForVAVBONoCache;
00685   static float  s_forceDesindexingReuseFactor;
00686   static bool   s_allowDesIndexing;
00687   static bool   s_useTriangleForQuadMesh;
00688   static SbBool s_detailDebug;
00689   static bool   s_creaseAngleFix;
00690   static int    s_vertex_array_extensionID;
00691   static int    s_vertex_buffer_extensionID;
00692   static int    s_multi_draw_array_extensionID;
00693   static int    s_primitive_restart_extensionID;
00694   static int    s_primitive_restartNV_extensionID;
00695   static int    s_opengl_30_extensionID;
00696   static size_t s_numPointsForBBoxPartioning;
00697 };
00698 
00699 inline SbBool 
00700 SoShape::checkShapeHints(SoGLRenderAction *,SbThreadAutoWriteLock *)
00701 {
00702   return FALSE;
00703 }
00704 
00705 
00706 #endif 
00707 
00708