The Vish Visualization Shell 0.3
Vish
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
Wizt::BufferArray Class Referenceabstract

Base class for OpenGL buffer objects, which are the building blocks of Vertex Buffer Objects. More...

#include <ocean/GLvish/BufferArray.hpp>

Inheritance diagram for Wizt::BufferArray:
Wizt::RenderBasin::VertexAttribute Wizt::BufferID Wizt::Anemone::SpecializedTentacle< Anemone::Arraybuffer > Wizt::Anemone::Tentacle MemCore::ReferenceBase< Tentacle > Wizt::IndexBufferObject Wizt::TextureBuffer Wizt::TypedBufferArrayBase< Type > Wizt::TypedTextureBuffer< Type > Wizt::IndexBuffer< Type > Wizt::TypedTextureBuffer< Type > Wizt::TypedBufferArray< Type > Wizt::TypedTextureBuffer< Type > Wizt::IndexBuffer< Type > Wizt::TypedVertexBufferArray< Type > Wizt::ColorArray< Type > Wizt::SecondaryColorArray< Type > Wizt::TexCoordArray< Type > Wizt::TypedNormalArray< Type > Wizt::TypedVertexArray< Type > Wizt::VertexAttribArray< Type > Wizt::TypedColorArray< Type > Wizt::TypedSecondaryColorArray< Type > Wizt::TypedTexCoordArray< Type > Wizt::TypedVertexAttribArray< Type >

Classes

struct  Error
 Exception class that might happen during loading of buffer arrays. More...
 
struct  Inconsistency
 Exception class thrown when an array of incompatible number of elements is going to be added to a given VBO object. More...
 
class  MapMemory
 API For glMapBuffer. More...
 

Public Types

enum  type
 Possible types of buffer ID's. More...
 
enum  usage
 Specifies the expected usage pattern of the data store. More...
 
- Public Types inherited from MemCore::ReferenceBase< Tentacle >
using reference_domain_t = Tentacle
 The type of the base class.
 
using SelfPtr_t = WeakPtr< Tentacle, Tentacle >
 Type for a pointer to this object itself.
 

Public Member Functions

 BufferArray (type buffer_target, int AttributeClass=0)
 Construct an OpenGL buffer object (this call does NOT require an OpenGL Context)
 
virtual size_t getComponentSize () const =0
 Get size of a component in bytes.
 
virtual size_t getElementSize () const =0
 Return size of the type used for loading the data.
 
GLuint getId () const noexcept
 Get an Id without attempting to generate it.
 
GLsizei getStride () const
 A future version may use a stride that is shared among Buffers.
 
bool isIndexBuffer () const
 Check whether this is an index buffer.
 
bool isVertexArray () const
 Check whether this is a vertex array.
 
template<class Type >
bool load_typed (const ::std::vector< Type > &data, size_t start, size_t end)
 Load subset of data from a Standard Template Vector.
 
template<class Type >
bool load_typed (const ::std::vector< Type > &data, usage usage_hint=STATIC_DRAW)
 Load data from a Standard Template Vector.
 
size_t memsize () const
 Return the memory occupied by this buffer.
 
size_t NumberOfElements () const
 Returns the number of elements referenced via this BufferArray.
 
 ~BufferArray ()
 Destructor - MUST be called within an OpenGL Context.
 
- Public Member Functions inherited from Wizt::Anemone::Tentacle
virtual bool activate (const Anemone &)=0
 Activate this tentacle.
 
virtual bool deactivate (const Anemone &)=0
 Deactivate this tentacle.
 
virtual const char * getSamplerType () const
 If this tentacle refers to some texture sampler in a shader, then hereby return the type of this sampler is it occurs in the code.
 
virtual int getTextureUnit () const
 Get the texture unit number which was specified during construction, if positive then it refers to some texture unit that is used in an associated shader.
 
virtual bool updateValue (VRenderContext &Context)
 Possibly update a tentacle from settings in a context.
 
- Public Member Functions inherited from MemCore::ReferenceBase< Tentacle >
auto getObjectCountID () const noexcept
 Get a unique ID for this object in the given domain.
 
bool isIdentical (const WeakPtr< Tentacle, Tentacle > &PossibleSelf) const noexcept
 Check if this object is identical to the one used by the given pointer.
 
void mkAutoDestructive ()
 Marks this object as being automatically destructed, e.g.
 
refcount_t refcount () const noexcept
 The strong reference count.
 
 ReferenceBase (Tentacle *that) noexcept
 Constructor, initializes reference counter to zero.
 
const auto & self () const
 Return weak pointer to the object self.
 
refcount_t wrefcount () const noexcept
 The weak reference count.
 

Protected Member Functions

bool load_subset (int offset, const void *ptr, memsize_t sz) const
 Load a subset of the data on the graphics card, updating an existing buffer.
 
bool load_untyped (const void *ptr, memsize_t MemorySize, size_t nElements, usage usage_hint=STATIC_DRAW)
 Loads the given data on the graphix card.
 
- Protected Member Functions inherited from MemCore::ReferenceBase< Tentacle >
virtual void extremeUnction ()
 A virtual function that will be called just before the object is destroyed.
 
ReferenceBaseoperator= (const ReferenceBase &R)
 Protected assignment operator (should not be called).
 
void suicide ()
 Delete this.
 
virtual ~ReferenceBase ()
 Virtual destructor.
 
- Protected Member Functions inherited from Wizt::BufferID
bool bindBuffer () const
 const version of bind(), does not create a buffer ID.
 
bool bindBufferWithPossibleCreation ()
 Non-const version of bind().
 
 BufferID (const type bufferType) noexcept
 The constructor does not yet create openGL buffers yet.
 
GLuint createId () noexcept
 If no valid ID yet, call glCreateBuffers().
 
GLuint getId () const noexcept
 Get an Id without attempting to generate it.
 
bool isbound () const throw ()
 Verification function: buffer is bound?
 
bool isIndexBuffer () const
 Check whether this is an index buffer.
 
bool isVertexArray () const
 Check whether this is a vertex array.
 
GLuint makeId ()
 On first access, OpenGL buffers will be generated. This function must be called from within a valid OpenGL context.
 
GLuint operator() ()
 On first access, OpenGL buffers will be generated. This function must be called from within a valid OpenGL context.
 
 ~BufferID () noexcept
 Deletion of created OpenGL buffers. Note that this might be problematic here if called outside a valid OpenGL context.
 

Additional Inherited Members

- Public Attributes inherited from Wizt::RenderBasin::VertexAttribute
unsigned DoublePrecision:1
 Load data in double precision.
 
unsigned Integer:1
 Hint whether the attribute is an integer data type in the shader, in which case it will be loaded differently.
 
unsigned Normalized:1
 Indicate whether this buffer will be normalized to the range [0,1] if it is an integer type loaded to a floating point attribute.
 
unsigned Signed:1
 Indicate if this integer type is signed.
 
- Public Attributes inherited from Wizt::Anemone::Tentacle
Activity_t Activity
 A bit mask telling whether this tentacle should participate in the waving of an Anemone.
 
- Protected Types inherited from Wizt::BufferID
enum  type
 Possible types of buffer ID's. More...
 
- Protected Attributes inherited from Wizt::BufferID
const type target
 The target type of this buffer ID.
 

Detailed Description

Base class for OpenGL buffer objects, which are the building blocks of Vertex Buffer Objects.

A possible exception-save usage scenario is via the activateVB() macro:

activateVB(B)
{
... render code ..
}
Base class for OpenGL buffer objects, which are the building blocks of Vertex Buffer Objects.
Definition BufferArray.hpp:40
Definition RefPtrPerformance.cpp:24
See also
http://www.songho.ca/opengl/gl_vbo.html
Todo:
Need to specify the skeleton in the Anemone to which this attribute refers to.

Member Enumeration Documentation

◆ type

Possible types of buffer ID's.

See also
http://www.opengl.org/wiki/Buffer_Object

◆ usage

Specifies the expected usage pattern of the data store.

  1. STREAM The data store contents will be modified once and used at most a few times.
  2. STATIC The data store contents will be modified once and used many times.
  3. DYNAMIC The data store contents will be modified repeatedly and used many times.

The nature of access may be one of these:

  1. DRAW The data store contents are modified by the application, and used as the source for GL drawing and image specification commands.
  2. READ The data store contents are modified by reading data from the GL, and used to return that data when queried by the application.
  3. COPY The data store contents are modified by reading data from the GL, and used as the source for GL drawing and image specification commands.
See also
http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml

Constructor & Destructor Documentation

◆ ~BufferArray()

Wizt::BufferArray::~BufferArray ( )

Destructor - MUST be called within an OpenGL Context.

If called in an non-OpenGL context, segmentation faults in the OpenGL driver/library will most likely occur. The preferred way is to store BufferArray objects in a GLCache, but NOT in an user-defined structure. The GLCache is supposed to be destroyed by the application when the OpenGL Context is destroyed, which is NOT when the containing objects are destroyed. Rather it is when a windows is closed, but not yet the application.

This mechanism does require special care and is non-trivial.

References Wizt::GLContextChecker::invalidContext().

Member Function Documentation

◆ getId()

GLuint Wizt::BufferID::getId ( ) const
noexcept

Get an Id without attempting to generate it.

This function is safe to be called from a non-OpenGL context.

◆ load_subset()

bool Wizt::BufferArray::load_subset ( int  offset,
const void *  ptr,
memsize_t  sz 
) const
protected

Load a subset of the data on the graphics card, updating an existing buffer.

Calls glBufferSubData() . http://www.opengl.org/sdk/docs/man/xhtml/glBufferSubData.xml

When replacing the entire data store, consider using glBufferSubData rather than completely recreating the data store with glBufferData. This avoids the cost of reallocating the data store.

Consider using multiple buffer objects to avoid stalling the rendering pipeline during data store updates. If any rendering in the pipeline makes reference to data in the buffer object being updated by glBufferSubData, especially from the specific region being updated, that rendering must drain from the pipeline before the data store can be updated.

Clients must align data elements consistent with the requirements of the client platform, with an additional base-level requirement that an offset within a buffer to a datum comprising N bytes be a multiple of N.

References Wizt::BufferID::bindBuffer(), and Wizt::BufferID::target.

◆ load_untyped()

bool Wizt::BufferArray::load_untyped ( const void *  ptr,
memsize_t  MemorySize,
size_t  nElements,
usage  usage_hint = STATIC_DRAW 
)
protected

Loads the given data on the graphix card.

Binds the current target and calls glBufferData().

Parameters
MemorySizeHow much memory will this call occupy on the GPU? This value will be used in conjunction with the GLCache.
nElementsHow much elements will be used in this array? This value will be used to check the consistency of Vertex Buffer Arrays, if an array with different number of elements is added, then an Inconsistency exception will be thrown.
Note
Clients must align data elements consistent with the requirements of the client platform, with an additional base-level requirement that an offset within a buffer to a datum comprising N bytes be a multiple of N.
See also
http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml
Todo:
Call does unbind() internally. Think if that is a problem and/or should be optimized.

References Wizt::BufferID::bindBuffer(), Wizt::BufferID::createId(), load_untyped(), Wizt::BufferID::makeId(), MemCore::Timer::secs(), and Wizt::BufferID::target.

Referenced by load_untyped().

◆ NumberOfElements()

size_t Wizt::BufferArray::NumberOfElements ( ) const
inlinevirtual

Returns the number of elements referenced via this BufferArray.

It will be zero at construction and only be set using a \i typed load() call.

Reimplemented from Wizt::Anemone::Tentacle.