NAME

OpenGL::Sandbox::Buffer - Wrapper object for OpenGL Buffer Object

VERSION

version 0.049_001

DESCRIPTION

OpenGL Buffers represent a named block of memory on the graphics hardware which can be used for various purposes, mostly serving to deliver large quantities of data from the application to be used repeatedly by the shaders.

Creating a buffer simply reserves an ID, which can then later be bound to a buffer target and loaded with data.

Loading this module requires OpenGL 2.0 or higher.

ATTRIBUTES

name

Human-readable name of object (not GL's integer "name")

target

OpenGL buffer target which this buffer object should be bound to, when necessary. This attribute will be updated by "bind" if you bind to a different target.

usage

Default data usage hint for OpenGL, when loading data into this buffer. If this is undef, the default when loading data will be GL_STATIC_DRAW. If you call load with a different usage value, it will update this attribute.

id

The OpenGL integer "name" of this buffer. This is a lazy-built attribute, and will call glGenBuffers the first time you access it. Use has_id to find out whether this has happened yet.

has_id

True if the id attribute is allocated.

autoload

If this field is defined at the time of the next call to "bind", this data will be immediately be loaded into the buffer with glBufferData. The field will then be cleared, to avoid holding onto large blobs of data.

filename

If passed to the constructor, this implies an "autoload" from the file. Else it is just for informational purposes.

METHODS

new

This is a standard Moo constructor, accepting any of the attributes, however it also accepts an alias 'data' for the "autoload" attribute.

bind

$buffer->bind;
$buffer->bind(GL_ARRAY_BUFFER);

Bind this buffer to a target, using "target" as the default. If autoload is set, this will also load that data into the buffer.

Returns $self for convenient chaining.

load

$buffer->load( $data, $usage_hint );

Load data into this buffer object. You may pass a scalar, scalar ref, memory map (which is just a special scalar ref) or an OpenGL::Array. This performs an automatic glBindBuffer to the value of "target". If "target" is not defined, this dies.

load_at

$buffer->load_at( $offset, $data );
$buffer->load_at( $offset, $data, $src_offset, $src_length );

Load some data into the buffer at an offset. If the $src_offset and/or $src_length values are given, this will use a substring of $data. The buffer will be bound to "target" first, if it wasn't already. This performs an automatic glBindBuffer to the value of "target". If "target" is not defined, this dies. Additionally, if "load" has not been called before this dies.

Returns $self for convenient chaining.

AUTHOR

Michael Conrad <mike@nrdvana.net>

COPYRIGHT AND LICENSE

This software is copyright (c) 2019 by Michael Conrad.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.