LwBuffer

LwBuffer — OpenGL buffer wrapper

Functions

Properties

guint target Read / Write / Construct Only
guint usage Read / Write / Construct Only

Types and Values

struct LwBuffer
struct LwBufferClass

Object Hierarchy

    GObject
    ╰── LwBuffer

Description

LwBuffer is not finished yet. It is possible that parts of this type will be changed in a future version of LiveWallpaper.

The LwBuffer class provides a wrapper for the OpenGL buffer functions. It takes care of different OpenGL versions and makes the usage of an OpenGL buffer easy.

Example 10. Using LwBuffer

1
2
3
4
5
6
7
8
9
10
11
12
float vertices_data[] = { ... };
int vertices_count = 3;
LwBuffer *vertices = lw_buffer_new(GL_STATIC_DRAW);
lw_buffer_set_data(vertices, 2 * vertices_count * sizeof(float), vertices_data);

// Use the vertices buffer as an attribute for a LwProgram prog
lw_program_enable(prog);
lw_program_set_attribute(prog, "vertices", LW_GLSL_TYPE_VEC2, vertices);

glDrawArrays(GL_TRIANGLES, 0, vertices_count);

lw_program_disable(prog);

The noise plugin makes use of the LwBuffer object. Take a look at the source code of that plugin to see a full working example for LwBuffer and LwProgram.

Functions

lw_buffer_bind ()

void
lw_buffer_bind (LwBuffer *self);

Binds this LwBuffer object to the target returned by lw_buffer_get_target(). This function calls glBindBuffer to bind the buffer.

Parameters

self

A LwBuffer

 

Since: 0.5


lw_buffer_get_data ()

gpointer
lw_buffer_get_data (LwBuffer *self,
                    guint offset,
                    guint size);

Internally this function uses glGetBufferSubData.

This method binds the buffer using lw_buffer_bind(), but does not unbind it. After this operation this LwBuffer is still bound to its target.

Parameters

self

A LwBuffer

 

offset

An offset from the beginning of the data store in bytes

 

size

The size in bytes of the data being returned

 

Returns

A part or all of the data currently stored in this LwBuffer. Use g_free() to free memory allocated for the data.

[transfer full]

Since: 0.5


lw_buffer_get_name ()

guint
lw_buffer_get_name (LwBuffer *self);

Parameters

self

A LwBuffer

 

Returns

The buffer name returned by glGenBuffers

Since: 0.5


lw_buffer_get_target ()

guint
lw_buffer_get_target (LwBuffer *self);

If this buffer is created by lw_buffer_new(), then the target will be GL_ARRAY_BUFFER.

Parameters

self

A LwBuffer

 

Returns

The target to which the buffer will be bound to when calling lw_buffer_bind()

Since: 0.5


lw_buffer_get_usage ()

guint
lw_buffer_get_usage (LwBuffer *self);

Parameters

self

A LwBuffer

 

Returns

The expected usage pattern of the buffer's data

Since: 0.5


lw_buffer_new ()

LwBuffer *
lw_buffer_new (guint usage);

Creates a new LwBuffer which uses the specified usage pattern. The buffer is created using the glGenBuffers function. The usage pattern can be one of the following: GL_STREAM_DRAW, GL_STREAM_READ, GL_STREAM_COPY, GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY, GL_DYNAMIC_DRAW, GL_DYNAMIC_READ, or GL_DYNAMIC_COPY.

Parameters

usage

The expected usage pattern of the buffer's data.

 

Returns

A new LwBuffer. You should use g_object_unref() to free the LwBuffer.

Since: 0.5


lw_buffer_set_data ()

void
lw_buffer_set_data (LwBuffer *self,
                    guint size,
                    gpointer data);

This method binds the buffer specified by self using lw_buffer_bind() and copies the data specified by data into the buffer. This operation creates a new data store for the buffer of the size size and also tells OpenGL about the desired usage pattern specified by lw_buffer_new(). To update the data in the buffer lw_buffer_set_sub_data() can be used.

This method binds the buffer using lw_buffer_bind(), but does not unbind it. After this operation this LwBuffer is still bound to its target.

This function uses glBufferData to copy the specified data to the buffer's data store.

Parameters

self

A LwBuffer

 

size

The size of the new data in bytes

 

data

A pointer to the data that will be copied into the buffer's data store or NULL.

[element-type char][array length=size]

Since: 0.5


lw_buffer_set_sub_data ()

void
lw_buffer_set_sub_data (LwBuffer *self,
                        guint offset,
                        guint size,
                        gpointer data);

Replaces size bytes of the buffer's data store with the memory found at data . The replacement starts after offset bytes from the beginning of the data store.

This method binds the buffer using lw_buffer_bind(), but does not unbind it. After this operation this LwBuffer is still bound to its target.

Internally this function uses glBufferSubData.

Parameters

self

A LwBuffer

 

offset

An offset from the beginning of the data store in bytes

 

size

The size in bytes of the data that will be copied

 

data

A pointer to the data that will be copied

 

Since: 0.5


lw_buffer_unbind ()

void
lw_buffer_unbind (LwBuffer *self);

Unbinds the LwBuffer previously bound by lw_buffer_bind(). This function calls

glBindBuffer

to bind 0 to the target returned by lw_buffer_get_target(). This unbinds every currently bound buffer even if it is not the one specified by self .

Parameters

self

A LwBuffer

 

Since: 0.5

Types and Values

struct LwBuffer

struct LwBuffer;

A OpenGL buffer wrapper object.

Since: 0.5


struct LwBufferClass

struct LwBufferClass {
};

Property Details

The “target” property

  “target”                   guint

The target to which the buffer will be bound to when calling lw_buffer_bind(). If this buffer is created by lw_buffer_new(), then the target will be GL_ARRAY_BUFFER.

Flags: Read / Write / Construct Only

Default value: 34962

Since: 0.5


The “usage” property

  “usage”                    guint

The expected usage pattern of the buffer's data.

Flags: Read / Write / Construct Only

Default value: 35040

Since: 0.5