#include <ecbuffer.h>
Public Types | |
enum | eBufferUsage { Usage_Position, Usage_Texcoord, Usage_Index, Usage_Raw } |
Provides an identifier that declares the usage of data contained in a buffer. More... | |
Public Member Functions | |
Buffer (eBufferUsage a_nUsage, size_t a_nElements) | |
Explicit constructor. | |
void * | Lock (size_t a_nContentOffset=0, bool a_bDiscard=false) |
Provides access to our buffer. | |
void | Unlock () |
Releases access to our buffer. | |
eBufferUsage | GetUsage () const |
Returns our assigned buffer usage. | |
size_t | GetAllocatedSize () const |
Returns our total allocated size, in bytes. | |
size_t | GetElementCount () const |
Returns our total number of elements. | |
virtual PYOBJECT | PyAsString () |
Python text representation method. | |
Static Public Member Functions | |
static bool | PyTypeCheck (PYOBJECT a_pObject) |
Python type check Verifies that the provided python object encapsulates a buffer. | |
static void | AppendBufferUsageTypes (PYOBJECT a_pPyModule) |
Appends buffer usage identifiers to the module of the provided dictionary. | |
Protected Member Functions | |
virtual void | DeleteObject () |
Child message hook for reference-count based destruction. |
A generic memory buffer.
More specifically, you will want to create a vertex buffer and an index buffer to keep intermediate data while you define new meshes. This prevents memory fragmentation while still allowing you to have as many static buffers as needed, for example, if more than one thread is creating them.
Note that we don't define concrete objects as vertex, uvcoords, etc. Instead we keep an internal type manager based on the intended usage. It would have been simpler to use templates, but that would have required a new set of Python macros for its script declarations. We don't have that much time.
IMPORTANT: The format for index buffers is <vertex> <uv>, ...
About Python lists Vs EclipseRay buffers:
It would seem a better idea to directly use lists to create meshes, instead of having to create intermediate buffers. For one, using buffer objects as a static heap is a better way to manage memory internally; Also, meshes can do object-oriented validation of the data they receive; Finally, it may be that we implement ways of reading binary data (i.e., data that can be more easily processed from a binary source than parsed from text and placed into a Python list), and in those cases, having a buffer object to encapsulate the resulting data and being able to throw it around in Python will be very handy.
Definition at line 64 of file ecbuffer.h.
enum Buffer::eBufferUsage |
Provides an identifier that declares the usage of data contained in a buffer.
Definition at line 74 of file ecbuffer.h.
Buffer::Buffer | ( | eBufferUsage | a_nUsage, | |
size_t | a_nElements | |||
) |
Explicit constructor.
Specify the type and number of elements to allocate, NOT the size in bytes (unless the usage is Usage_Raw, then a_nElements will naturally be the buffer size in bytes)
a_nUsage | Buffer usage | |
a_nElements | Number of elements of type eBufferUsage to allocate (NOT number of bytes) |
static void Buffer::AppendBufferUsageTypes | ( | PYOBJECT | a_pPyModule | ) | [static] |
Appends buffer usage identifiers to the module of the provided dictionary.
a_pPyModule | A valid python module |
virtual void Buffer::DeleteObject | ( | ) | [protected, virtual] |
Child message hook for reference-count based destruction.
The child class is responsible for deleting any instance to which this this function is called.
Reimplemented from EclipseObject.
void* Buffer::Lock | ( | size_t | a_nContentOffset = 0 , |
|
bool | a_bDiscard = false | |||
) |
Provides access to our buffer.
If the discard flag is enabled, the whole heap is set to zero. Call Unlock after you are done accessing this buffer. The content offset must be on usage units, not in bytes. For example, if this is a position array, an offset of 1 will skip the first 12 bytes.
a_nContentOffset | Offset, in usage units, NOT bytes, from the start of the buffer. | |
a_bDiscard | If true, the buffer is cleaned before passing it to the caller |
virtual PYOBJECT Buffer::PyAsString | ( | ) | [virtual] |
Python text representation method.
Reimplemented from EclipseObject.
static bool Buffer::PyTypeCheck | ( | PYOBJECT | a_pObject | ) | [static] |
Python type check Verifies that the provided python object encapsulates a buffer.
Reimplemented from EclipseObject.
void Buffer::Unlock | ( | ) |
Releases access to our buffer.
You must call this function after modifying the contents of this buffer, otherwise, further calls to Lock will fail.