/usr/include/oce/OpenGl_VertexBufferEditor.hxx is in liboce-visualization-dev 0.18.2-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | // Created by: Kirill GAVRILOV
// Copyright (c) 2013-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _OpenGl_VertexBufferEditor_H__
#define _OpenGl_VertexBufferEditor_H__
#include <OpenGl_VertexBuffer.hxx>
#include <OpenGl_Context.hxx>
#include <NCollection_Array1.hxx>
//! Auxiliary class to iteratively modify data of existing VBO.
//! It provides iteration interface with delayed CPU->GPU memory transfer to avoid slow per-element data transfer.
//! User should explicitly call Flush() method to ensure that all data is transferred to VBO.
//! Temporary buffer on CPU side can be initialized with lesser capacity than VBO
//! to allow re-usage of shared buffer with fixed size between VBOs.
//!
//! You should use NCollection_Vec2/NCollection_Vec3/NCollection_Vec4 with appropriate length
//! to instantiate this template and access elements in VBO.
//!
//! Notice that this technique designed for VBO streaming scenarios (when VBO is modified from time to time).
//! Also this class doesn't retrieve existing data from VBO - data transferred only in one direction!
//! In case of static data this is preferred to upload it within one call during VBO initialization.
template<typename theVec_t>
class OpenGl_VertexBufferEditor
{
public:
//! Creates empty editor
//! theTmpBufferLength - temporary buffer length
OpenGl_VertexBufferEditor (const Standard_Integer theTmpBufferLength = 0)
: myElemFrom (0),
myElemsNb (0),
myTmpBuffer (0, theTmpBufferLength > 0 ? (theTmpBufferLength - 1) : 2047) {}
//! Creates empty editor
//! theTmpBuffer - pointer to temporary buffer
//! theTmpBufferLength - temporary buffer length
OpenGl_VertexBufferEditor (theVec_t* theTmpBuffer,
const Standard_Integer theTmpBufferLength)
: myElemFrom (0),
myElemsNb (0),
myTmpBuffer (theTmpBuffer[0], 0, theTmpBufferLength - 1) {}
//! Initialize editor for specified VBO.
//! theGlCtx - bound OpenGL context to edit VBO
//! theVbo - VBO to edit
Standard_Boolean Init (const Handle(OpenGl_Context)& theGlCtx,
const Handle(OpenGl_VertexBuffer)& theVbo)
{
myGlCtx = theGlCtx;
myVbo = theVbo;
if (myGlCtx.IsNull() || myVbo.IsNull() || !myVbo->IsValid() || myVbo->GetComponentsNb() != GLuint (theVec_t::Length()))
{
return Standard_False;
}
myElemFrom = myElemsNb = 0;
return Standard_True;
}
//! Modify current element in VBO.
theVec_t& Value()
{
return myTmpBuffer.ChangeValue (myElemsNb);
}
//! Move to the next position in VBO.
Standard_Boolean Next()
{
if (++myElemsNb > myTmpBuffer.Upper())
{
return Flush();
}
return Standard_True;
}
//! Push current data from local buffer to VBO.
Standard_Boolean Flush()
{
if (myElemsNb <= 0)
{
return Standard_True;
}
if (myVbo.IsNull()
|| !myVbo->SubData (myGlCtx, myElemFrom, myElemsNb, &myTmpBuffer.Value (0)[0]))
{
// should never happens
return Standard_False;
}
myElemFrom += myElemsNb;
myElemsNb = 0;
return Standard_True;
}
//! @return assigned VBO
inline const Handle(OpenGl_VertexBuffer)& GetVBO() const
{
return myVbo;
}
private:
Handle(OpenGl_Context) myGlCtx; //!< handle to current OpenGL context
Handle(OpenGl_VertexBuffer) myVbo; //!< edited VBO
Standard_Integer myElemFrom; //!< element in VBO to upload from
Standard_Integer myElemsNb; //!< current element in temporary buffer
NCollection_Array1<theVec_t> myTmpBuffer; //!< temporary array
};
#endif // _OpenGl_VertexBufferEditor_H__
|