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-2020 BY FEI S.A.S, *** 00017 *** BORDEAUX, FRANCE *** 00018 *** ALL RIGHTS RESERVED *** 00019 **=======================================================================*/ 00020 /*======================================================================= 00021 ** Author : R.ALBOU (Dec 2003) 00022 **=======================================================================*/ 00023 00024 #ifndef _SO_VBO_MGR_ 00025 #define _SO_VBO_MGR_ 00026 00027 #include <Inventor/STL/vector> 00028 #include <Inventor/threads/SbThreadLocalStorage.h> 00029 #include <Inventor/sys/SoGLType.h> 00030 00031 #define SO_MAX_VBO_IN_MGR 36 00032 00033 #ifdef _MSC_VER 00034 #pragma warning( push ) 00035 #pragma warning(disable:4251) 00036 #endif 00037 00038 class SoVBOContext; 00039 00040 /*----------------------------------------------------------------------------*/ 00041 00042 SoVBOMgr 00043 { 00044 public: 00045 // Possible buffer type. 00046 // TEX_COORDS_BUFFER+n 0<n<31 : specifies the buffer for storing 00047 // texture coordinate of the nth unit. 00048 enum BufferType { 00049 VERTEX_BUFFER, 00050 NORMAL_BUFFER, 00051 COLOR_BUFFER, 00052 INDEX_BUFFER, 00053 TEX_COORDS_BUFFER 00054 } ; 00055 00056 // Returns an instance of SoVBOMgr if the VBO extension is available, 00057 // NULL otherwise. 00058 static SoVBOMgr *createInstance() ; 00059 00060 // Should be called to delete an instance 00061 void unref(SoState *state=NULL) ; 00062 00063 00064 // Creates, if not already created by a previous call, and loads, one of the buffer specified 00065 // by bufferType, with data. 00066 // Returns TRUE if the loading is successful, FALSE otherwise. 00067 // If the buffer is locked, data are not reloaded. 00068 // After this call, this buffer becomes active whatever the lock status. 00069 // context is the OpenGL context used by this buffer. 00070 SbBool loadData(int context, BufferType bufferType, size_t size, void *data) ; 00071 00072 // Loads sub-data of the buffer specified by bufferType with data. 00073 // Considers that the buffer is active (bind called). 00074 // If the buffer is locked nothing is done. 00075 // context is the OpenGL context used by this buffer. 00076 SbBool loadSubData(int context, BufferType bufferType, size_t offset, size_t size, void *data) ; 00077 00078 //**************** Lock/Unlock a buffer *************** 00079 // context is the OpenGL context used by a buffer. 00080 // If context=-1, all buffers of bufferType will be unlocked 00081 // -1 is ignored by lock(). 00082 00083 void lock(int context, BufferType bufferType) ; 00084 00085 void unlock(BufferType bufferType, int context=-1) ; 00086 00087 SbBool isLocked(int context, BufferType bufferType) ; 00088 00089 // Unlock all texture buffers 00090 void unlockTextureBuffers(int context=-1) ; 00091 //***************************************************** 00092 00093 // Binds one of the buffer specified by bufferType. 00094 // Returns the OpenGL target which could be GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER. 00095 GLenum bind(int context, BufferType bufferType) ; 00096 00097 // Desactivate the VBO usage. 00098 static void desactivate() ; 00099 00100 // Indicates if VBO could be used. 00101 // If state is different from NULL, SoShapeHintsElement is used to 00102 // check if VBO should be use (cf SoShapeHints::useVBO). 00103 // If state is NULL, only the graphic board capabilities are checked. 00104 static SbBool canUseVBO(SoState *state=NULL) ; 00105 00106 // Delete all vertex buffer objects which have not been deleted 00107 // when the destructor was called because the context associated 00108 // was different from the context at destruction time. 00109 static void deleteWaitingToBeFreed (int context) ; 00110 00111 // bind and map buffer in Write mode 00112 void* map(int context, BufferType bufferType); 00113 00114 // bind and unamp buffer 00115 void unmap(int context, BufferType bufferType); 00116 00117 private: 00118 static void initClass(); 00119 static void exitClass(); 00120 00121 void unlockIgnoreContext(BufferType bufferType) ; 00122 00123 SB_THREAD_TLS_HEADER(); 00124 00125 private: 00126 // Constructor 00127 SoVBOMgr() ; 00128 00129 // Destructor 00130 ~SoVBOMgr() ; 00131 00132 // List of contexts containing vertex buffer objects 00133 typedef std::vector<SoVBOContext*> SoVBOContextsList ; 00134 SoVBOContextsList m_VBOContextsList ; 00135 00136 // Retreives a SoVBOContext associates to context. 00137 // Creates one if not found. 00138 SoVBOContext* getVBOContext(int context) ; 00139 00140 // Per thread static storage. 00141 struct MTstruct 00142 { 00143 // List of all vertex buffer objects which have not been deleted 00144 // when the destructor was called because the context associated 00145 // was different from the context at destruction time. 00146 SoVBOContextsList* m_waitingToBeFreed ; 00147 }; 00148 };/*----------------------------------------------------------------------------*/ 00149 00150 #ifdef _MSC_VER 00151 #pragma warning( pop ) 00152 #endif 00153 00154 #endif // _SO_VBO_MGR_ 00155 00156 00157