00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined SOBUFFEREDSHAPE_H
00024 #define SOBUFFEREDSHAPE_H
00025
00026 #include <Inventor/fields/SoSFEnum.h>
00027 #include <Inventor/fields/SoMFEnum.h>
00028 #include <Inventor/fields/SoSFInt32.h>
00029 #include <Inventor/fields/SoMFInt32.h>
00030 #include <Inventor/fields/SoSFShort.h>
00031 #include <Inventor/fields/SoSFBox3f.h>
00032 #include <Inventor/fields/SoSFBufferObject.h>
00033 #include <Inventor/fields/SoMFBufferObject.h>
00034
00035 #include <Inventor/nodes/SoNode.h>
00036 #include <Inventor/nodes/SoVertexProperty.h>
00037 #include <Inventor/nodes/SoShape.h>
00038
00039 #include <Inventor/caches/SoContextedObjectCache.h>
00040 #include <Inventor/threads/SbThreadRWMutex.h>
00041 #include <Inventor/elements/SoDrawStyleElement.h>
00042
00043
00044 class SoBufferObject;
00045 class SoGLBufferObject;
00046 class SoCube;
00047 class SoDetail;
00048 class SoAction;
00049 class SoGLDevice;
00050
00052 namespace inventor
00053 {
00054 namespace cache
00055 {
00056 class VertexProperty;
00057 }
00058 }
00059
00060 namespace OpenInventorInternal {
00061 class GLBufferedShapeCache;
00062 }
00414 class SoBufferedShape : public SoShape
00415 {
00416 SO_NODE_HEADER( SoBufferedShape );
00417
00418
00419
00420 public:
00421
00425 enum Type
00426 {
00428 POINTS,
00429
00432 LINE_STRIP,
00433
00436 LINE_LOOP,
00437
00440 LINES,
00441
00444 TRIANGLE_STRIP,
00445
00448 TRIANGLE_FAN,
00449
00452 TRIANGLES,
00453
00456 QUAD_STRIP,
00457
00460 QUADS,
00461
00463 POLYGON
00464 };
00465
00470 enum Usage
00471 {
00475 STATIC,
00481 DYNAMIC
00482 };
00483
00487 SoBufferedShape();
00488
00505 SoSFEnum shapeUsage;
00506
00521 SoSFBool primitiveRestartEnabled;
00522
00529 SoSFInt32 primitiveRestartValue;
00530
00543 SoSFBool useNormalsGenerator;
00544
00549 SoSFEnum shapeType;
00550
00562 SoMFInt32 numVertices;
00563
00570 SoSFBufferObject vertexBuffer;
00571
00576 SoSFShort vertexComponentsCount;
00577
00582 SoSFEnum vertexComponentsType;
00583
00594 SoSFShort vertexStride;
00595
00600 SoSFInt32 vertexOffset;
00601
00608 SoSFBufferObject normalBuffer;
00609
00614 SoSFEnum normalComponentsType;
00615
00626 SoSFShort normalStride;
00627
00632 SoSFInt32 normalOffset;
00633
00640 SoSFBufferObject indexBuffer;
00641
00646 SoSFEnum indexType;
00647
00652 SoSFInt32 indexOffset;
00653
00660 SoSFBufferObject colorBuffer;
00661
00666 SoSFEnum colorComponentsType;
00667
00678 SoSFInt32 colorStride;
00679
00684 SoSFInt32 colorOffset;
00685
00690 SoSFInt32 colorComponentsCount;
00691
00698 SoMFBufferObject texCoordsBuffer;
00699
00704 SoMFEnum texCoordsComponentsType;
00705
00716 SoMFInt32 texCoordsStride;
00717
00722 SoMFInt32 texCoordsOffset;
00723
00728 SoMFInt32 texCoordsComponentsCount;
00729
00730 private:
00736 virtual void GLRender(SoGLRenderAction *action );
00737
00743 virtual void getBoundingBox( SoGetBoundingBoxAction *action );
00744
00748 virtual void computeBBox( SoAction *action, SbBox3f &box, SbVec3f ¢er );
00749
00753 virtual void computeBBox(SoAction *action, SbXfBox3d &box, SbVec3d ¢er);
00754
00760 virtual void rayPick(SoRayPickAction *action );
00761
00767 virtual void getPrimitiveCount(SoGetPrimitiveCountAction *action );
00768
00769
00770
00771 private:
00772 virtual SbMatrix3* computeVtxTangentSpaceMat( const float *bumpTexCoords, int &numMat ) const;
00773
00775 static void initClass();
00776
00778 static void exitClass();
00779
00781 virtual SbBool readInstance(SoInput *in, unsigned short flags );
00782
00783 void notify( SoNotList* list );
00784
00785 inline inventor::cache::VertexProperty* getVpCache();
00786
00787 inline void lockVpCacheMutex() const;
00788
00789 inline void unlockVpCacheMutex() const;
00790
00791
00792
00793 private:
00794
00796 virtual ~SoBufferedShape();
00797
00798 virtual SbBool shouldCheckShapeHints();
00799
00800 virtual SbBool shouldGLRender( SoGLRenderAction *action, SbBool isPointsOrLines = FALSE );
00801
00812 virtual SbBool isLightingUsable( const SoState* state, const void* normalBufferPtr );
00813
00817 virtual SbBool isTransparent(SoState* state) const;
00818
00819 virtual void generatePrimitives( SoAction *action );
00820
00821
00827 virtual void GLRenderBoundingBox( SoGLRenderAction *action );
00828
00829 virtual int getNumPrim();
00830
00831 virtual SbBool numPrimInvalid();
00832
00833
00834 virtual SoDetail* createTriangleDetail( SoRayPickAction *action,
00835 const SoPrimitiveVertex *v1,
00836 const SoPrimitiveVertex *v2,
00837 const SoPrimitiveVertex *v3,
00838 SoPickedPoint *pp );
00839
00840 virtual SoDetail* createLineSegmentDetail( SoRayPickAction *action,
00841 const SoPrimitiveVertex *v1,
00842 const SoPrimitiveVertex *v2,
00843 SoPickedPoint *pp );
00844
00845 virtual SoDetail* createPointDetail( SoRayPickAction *action,
00846 const SoPrimitiveVertex *v,
00847 SoPickedPoint *pp );
00848
00849
00850
00851
00852
00853 void renderExtraData( SoGLRenderAction* );
00854 void renderExtra_NonIndexed_TriangleStrip( SoGLRenderAction* );
00855 void renderExtra_NonIndexed_QuadStrip( SoGLRenderAction* );
00856 void renderExtra_NonIndexed_Triangles( SoGLRenderAction* );
00857 void renderExtra_NonIndexed_Quads( SoGLRenderAction* );
00858 void renderExtra_NonIndexed_TriangleFan( SoGLRenderAction* );
00859 void renderExtra_Indexed_TriangleStrip( SoGLRenderAction* );
00860 void renderExtra_Indexed_QuadStrip( SoGLRenderAction* );
00861 void renderExtra_Indexed_Triangles( SoGLRenderAction* );
00862 void renderExtra_Indexed_Quads( SoGLRenderAction* );
00863 void renderExtra_Indexed_TriangleFan( SoGLRenderAction* );
00864
00865
00866
00867 private:
00869 struct InstancesInfos
00870 {
00871 unsigned int numInstances;
00872 unsigned int numBatches;
00873 unsigned int smallestBatchSize;
00874 unsigned int instancesPerBatch;
00875 unsigned int instancesInLastBatch;
00876 };
00877
00878 void getInstanceInfos( SoState* state, InstancesInfos& instancesInfo );
00879
00881 void drawElementsInstanced(SoGLRenderAction* action, const InstancesInfos& instanceInfos,
00882 GLenum mode, GLsizei count, GLenum type,
00883 const void * indices);
00884
00886 void drawArraysInstanced(SoGLRenderAction* action, const InstancesInfos& instanceInfos,
00887 GLenum mode, GLint first, GLsizei count);
00888
00892 unsigned int computeSmallestBatchSize(const SoNodeList* vertexAttribsList, unsigned int numInstances);
00893
00897 SbBool isPointsOrLines() const;
00898
00899
00900
00901 bool arePointsNeededAsPrimitives( SoDrawStyleElement::Style drawStyle ) const;
00902
00913 bool isTargetValid( SoBufferObject* bufferObject, int expectedTarget ) const;
00914
00920 int getOpenGLShapeType( SoAction* ) const;
00921
00925 bool setupVertices( SoState* state, SoBufferObject* vertexBufferPtr );
00926
00930 bool setupNormals( SoState* state, SoBufferObject* normalBufferPtr );
00931
00935 bool setupColors( SoState* state, SoBufferObject* colorBufferPtr );
00936
00940 void setupTexCoords( SoState* state, SoBufferObject* texCoordsBufferPtr, int unit );
00941
00945 void setupVertexAttribs( SoState* state, const InstancesInfos& instancesInfo, int curBatch );
00946
00950 void disableVertexAttribs( SoState* state );
00951
00955 void generateDefaultNormals( SoAction* action );
00956
00957 template< class T > void generateDefaultNormalsTemplate( SoState* state );
00958 template< class T > void generateDefaultNormalsTemplate_BASE( SoState* state, const int vertPerPrim );
00959 template< class T > void generateDefaultNormalsTemplate_STRIP( SoState* state, const int vertPerPrim );
00960
00961 unsigned int getIndex( const void* indicesBuffer, const unsigned int index ) const;
00962 template< class T > unsigned int getIndexTemplate( const void* indicesBuffer, const unsigned int index ) const;
00963
00964 SbVec3f getNormal( const void* normalsBuffer, const unsigned int index ) const;
00965 template< class T > SbVec3f getNormalTemplate( const void* normalsBuffer, const unsigned int index, const unsigned int stride ) const;
00966
00967 SbVec4f getTexCoord( const void* texCoordsBuffer, const int unit, const unsigned int index ) const;
00968 template< class T > SbVec4f getTexCoordTemplate( const void* texCoordsBuffer, const unsigned int index, const unsigned int stride, const unsigned int componentsCount ) const;
00969
00970 template< class T > void getVertex( const void* verticesBuffer, const short componentsCount, const unsigned int stride, const unsigned int index, T& x, T& y, T& z ) const;
00971 template< class T > SbVec3f getVertex( const void* verticesBuffer, const short componentsCount, const unsigned int stride, const unsigned int index ) const;
00972
00973 template< class T > void computeBBoxTemplate( SoAction *action, SbBox3f &box, SbVec3f ¢er );
00974
00975 template< class T > void computeBBoxTemplate_POINTS( SoAction *action, SbBox3f &box, SbVec3f ¢er );
00976
00977 template< class T > void computeBBoxTemplate( SoAction *action, SbBox3f &box, SbVec3f ¢er, const SbVec2d &psize );
00978
00979 template< class T > void computeBBoxTemplateSP( SoAction *action, SbBox3f &box, SbVec3f ¢er, const SbVec2d &psize );
00980
00981 template< class T, int MODE > void computeBBoxTemplate_( SoAction *, SbBox3f &box, SbVec3f ¢er, const SbVec2d &pSize );
00982
00983 template< class T > void rayPickQuad( void* indicesPtr, void* verticesPtr, int verticesStride, SoRayPickAction *action, bool isStrip );
00984
00985 template< class T > void rayPickTriangle( void* indicesPtr, void* verticesPtr, int verticesStride, SoRayPickAction *action, bool isStrip, bool isFan );
00986
00987 template< class T > void rayPickLine( void* indicesPtr, void* verticesPtr, int verticesStride, SoRayPickAction *action, bool isStrip, bool isLoop );
00988
00989 template< class T > void rayPickPoint( void* indicesPtr, void* verticesPtr, int verticesStride, SoRayPickAction *action );
00990
00991 template< class T > void pointPicking( void* indicesPtr, void* verticesPtr, SoRayPickAction* action );
00992
00993 template< class T > void generatePrimitives(size_t verticesCount, SoAction *action);
00994
00995 template< class T > void generatePrimitives_POLYGONS(size_t verticesCount, SoAction *action);
00996
00997
00998 SbBool checkFieldsContent(bool forGLRender);
00999
01000 int getGLShapeUsage() const;
01001
01002
01003 bool isRenderExtraDataNeededInCurrentContext() const;
01004
01005
01006 bool isRenderExtraDataNeededByGraphicCardInCurrentContext() const;
01007
01008
01009
01010 bool isRenderExtraDataNeededByShapeType() const;
01011
01012
01013 static void mapToCache(SoBufferObject* source, SoGLBufferObject* target, uint64_t& modificationsCounter);
01014
01015
01016 static void unmapFromCache(SoBufferObject* source, SoGLBufferObject* target);
01017
01018 static void initNumGraphicCards();
01019 static void initUseShapeOptim();
01020
01021
01022
01023
01024
01025 static bool isRenderExtraDataNeededByGraphicCard( const SbString& graphicCardName );
01026
01027
01028
01029 private:
01034 static bool canBeMapped(SoDeviceContext* context, SoBufferObject* bufferObject);
01035
01037 SbBox3f m_computedBoundingBox;
01038
01040 void** m_primitivesOffset;
01041 int* m_primitivesOffsetInt;
01042
01046 int m_primitivesOffsetArraySize;
01047
01049 int m_vertexCount;
01050
01051 float m_usedCreaseAngle;
01052
01053
01054
01055 inventor::cache::VertexProperty* m_vpCache;
01056
01057
01058 SbThreadRWMutex* m_vpCacheMutex;
01059
01060
01061 SoContextedObjectCache<OpenInventorInternal::GLBufferedShapeCache> *m_cacheList;
01062
01063 GLint* m_indicesArray;
01064 GLsizei* m_countArray;
01065 GLvoid** m_indicesElement;
01066 int m_numPrimitives;
01067
01068 bool m_checkFields;
01069 bool m_lastFieldsCheckResult;
01070
01071 static bool s_useShapeOptim;
01072 static unsigned int s_numGraphicCards;
01073 };
01074
01075
01076
01077 inline inventor::cache::VertexProperty*
01078 SoBufferedShape::getVpCache()
01079 {
01080 return m_vpCache;
01081 }
01082
01083
01084 inline void
01085 SoBufferedShape::lockVpCacheMutex() const
01086 {
01087 m_vpCacheMutex->writelock();
01088 }
01089
01090
01091 inline void
01092 SoBufferedShape::unlockVpCacheMutex() const
01093 {
01094 m_vpCacheMutex->writeunlock();
01095 }
01096
01097
01098 inline int
01099 SoBufferedShape::getNumPrim()
01100 {
01101 return m_vertexCount;
01102 }
01103
01104
01105 inline SbBool
01106 SoBufferedShape::numPrimInvalid()
01107 {
01108 return (m_vertexCount<0)?TRUE:FALSE;
01109 }
01110
01111
01112
01113 inline SbBool
01114 SoBufferedShape::shouldCheckShapeHints()
01115 {
01116 return TRUE;
01117 }
01118
01119
01120
01121
01122 #endif // SOBUFFEREDSHAPE_H
01123
01124