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 template<typename theVec_t>
0036 class OpenGl_VertexBufferEditor
0037 {
0038
0039 public:
0040
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 OpenGl_VertexBufferEditor (theVec_t* theTmpBuffer,
0052 const Standard_Integer theTmpBufferLength)
0053 : myElemFrom (0),
0054 myElemsNb (0),
0055 myTmpBuffer (theTmpBuffer[0], 0, theTmpBufferLength - 1) {}
0056
0057
0058
0059
0060 Standard_Boolean Init (const Handle(OpenGl_Context)& theGlCtx,
0061 const Handle(OpenGl_Buffer)& theVbo)
0062 {
0063 myGlCtx = theGlCtx;
0064 myVbo = theVbo;
0065 if (myGlCtx.IsNull() || myVbo.IsNull() || !myVbo->IsValid() || myVbo->GetComponentsNb() != GLuint (theVec_t::Length()))
0066 {
0067 return Standard_False;
0068 }
0069
0070 myElemFrom = myElemsNb = 0;
0071 return Standard_True;
0072 }
0073
0074
0075 theVec_t& Value()
0076 {
0077 return myTmpBuffer.ChangeValue (myElemsNb);
0078 }
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()
0099 || !myVbo->SubData (myGlCtx, myElemFrom, myElemsNb, &myTmpBuffer.Value (0)[0]))
0100 {
0101
0102 return Standard_False;
0103 }
0104 myElemFrom += myElemsNb;
0105 myElemsNb = 0;
0106
0107 return Standard_True;
0108 }
0109
0110
0111 const Handle(OpenGl_Buffer)& GetVBO() const { return myVbo; }
0112
0113 private:
0114
0115 Handle(OpenGl_Context) myGlCtx;
0116 Handle(OpenGl_Buffer) myVbo;
0117 Standard_Integer myElemFrom;
0118 Standard_Integer myElemsNb;
0119 NCollection_Array1<theVec_t> myTmpBuffer;
0120
0121 };
0122
0123 #endif