Warning, file /include/opencascade/OpenGl_VertexBufferEditor.hxx was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef OpenGl_VertexBufferEditor_HeaderFile
0016 #define OpenGl_VertexBufferEditor_HeaderFile
0017
0018 #include <OpenGl_Buffer.hxx>
0019 #include <OpenGl_Context.hxx>
0020
0021 #include <NCollection_Array1.hxx>
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 template <typename theVec_t>
0037 class OpenGl_VertexBufferEditor
0038 {
0039
0040 public:
0041
0042
0043 explicit OpenGl_VertexBufferEditor(const Standard_Integer theTmpBufferLength = 0)
0044 : myElemFrom(0),
0045 myElemsNb(0),
0046 myTmpBuffer(0, theTmpBufferLength > 0 ? (theTmpBufferLength - 1) : 2047)
0047 {
0048 }
0049
0050
0051
0052
0053 OpenGl_VertexBufferEditor(theVec_t* theTmpBuffer, const Standard_Integer theTmpBufferLength)
0054 : myElemFrom(0),
0055 myElemsNb(0),
0056 myTmpBuffer(theTmpBuffer[0], 0, theTmpBufferLength - 1)
0057 {
0058 }
0059
0060
0061
0062
0063 Standard_Boolean Init(const Handle(OpenGl_Context)& theGlCtx, const Handle(OpenGl_Buffer)& theVbo)
0064 {
0065 myGlCtx = theGlCtx;
0066 myVbo = theVbo;
0067 if (myGlCtx.IsNull() || myVbo.IsNull() || !myVbo->IsValid()
0068 || myVbo->GetComponentsNb() != GLuint(theVec_t::Length()))
0069 {
0070 return Standard_False;
0071 }
0072
0073 myElemFrom = myElemsNb = 0;
0074 return Standard_True;
0075 }
0076
0077
0078 theVec_t& Value() { return myTmpBuffer.ChangeValue(myElemsNb); }
0079
0080
0081 Standard_Boolean Next()
0082 {
0083 if (++myElemsNb > myTmpBuffer.Upper())
0084 {
0085 return Flush();
0086 }
0087 return Standard_True;
0088 }
0089
0090
0091 Standard_Boolean Flush()
0092 {
0093 if (myElemsNb <= 0)
0094 {
0095 return Standard_True;
0096 }
0097
0098 if (myVbo.IsNull() || !myVbo->SubData(myGlCtx, myElemFrom, myElemsNb, &myTmpBuffer.Value(0)[0]))
0099 {
0100
0101 return Standard_False;
0102 }
0103 myElemFrom += myElemsNb;
0104 myElemsNb = 0;
0105
0106 return Standard_True;
0107 }
0108
0109
0110 const Handle(OpenGl_Buffer)& GetVBO() const { return myVbo; }
0111
0112 private:
0113 Handle(OpenGl_Context) myGlCtx;
0114 Handle(OpenGl_Buffer) myVbo;
0115 Standard_Integer myElemFrom;
0116 Standard_Integer myElemsNb;
0117 NCollection_Array1<theVec_t> myTmpBuffer;
0118 };
0119
0120 #endif