LwProgram

LwProgram — OpenGL program wrapper

Functions

Types and Values

enum LwGLSLType
struct LwProgram
struct LwProgramClass

Object Hierarchy

    GObject
    ╰── LwProgram

Description

LwProgram is an easy way to use GLSL shaders in a LiveWallpaper plugin.

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

Example 9. Using LwProgram

GError *error = NULL;
LwProgram *prog = g_object_new(LW_TYPE_PROGRAM, NULL);

lw_program_create_and_attach_shader(prog, "/path/to/shader.glsl", GL_VERTEX_SHADER, &error);
if(error != NULL)
{
    g_warning("Could not load vertex shader: %s", error->message);
    g_error_free(error);
    return;
}

lw_program_link(prog);

...

lw_prog_enable(prog);

// The program is enabled for all following drawing operations
...

lw_prog_disable(prog);

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

Functions

lw_program_attach_shader ()

void
lw_program_attach_shader (LwProgram *self,
                          LwShader *shader);

Attaches the shader to the program. This function uses glAttachShader to attach the shader. The LwShader can be freed after attaching it to a LwProgram.

Parameters

self

A LwProgram

 

shader

A LwShader

 

Since: 0.4


lw_program_create_and_attach_shader ()

gboolean
lw_program_create_and_attach_shader (LwProgram *self,
                                     const gchar *path,
                                     guint type);

This function creates, compiles and attaches a shader to the program. It is easier to use this function instead of creating, compiling and attaching the shader by yourself.

Parameters

self

A LwProgram

 

path

The file containing the shader's source code

 

type

GL_VERTEX_SHADER or GL_FRAGMENT_SHADER

 

Returns

TRUE on success, FALSE otherwise

Since: 0.4


lw_program_create_and_attach_shader_from_resource ()

gboolean
lw_program_create_and_attach_shader_from_resource
                               (LwProgram *self,
                                const gchar *path,
                                guint type);

This function creates, compiles and attaches a shader to the program. It is easier to use this function instead of creating, compiling and attaching the shader by yourself.

Parameters

self

A LwProgram

 

path

The file containing the shader's source code

 

type

GL_VERTEX_SHADER or GL_FRAGMENT_SHADER

 

Returns

TRUE on success, FALSE otherwise

Since: 0.5


lw_program_get_attrib_location ()

gint
lw_program_get_attrib_location (LwProgram *self,
                                const gchar *name);

Calls glGetAttribLocation to get the location of an attribute variable.

Parameters

self

A LwProgram

 

name

Name of an attribute variable

 

Returns

The location of an attribute variable or -1 if attribute is not found

Since: 0.4


lw_program_get_uniform_location ()

gint
lw_program_get_uniform_location (LwProgram *self,
                                 const gchar *name);

Calls glGetUniformLocation to get the location of an uniform variable.

Parameters

self

A LwProgram

 

name

Name of an uniform variable

 

Returns

The location of an uniform variable or -1 if uniform is not found

Since: 0.4


lw_program_disable ()

void
lw_program_disable (LwProgram *self);

Disables this program.

Parameters

self

A LwProgram

 

Since: 0.4


lw_program_enable ()

void
lw_program_enable (LwProgram *self);

Enables the program.

Parameters

self

A LwProgram

 

Since: 0.4


lw_program_get_name ()

guint
lw_program_get_name (LwProgram *self);

Parameters

self

A LwProgram

 

Returns

The program name returned by glCreateProgram

Since: 0.4


lw_program_link ()

gboolean
lw_program_link (LwProgram *self);

Links the program using glLinkProgram. If an error occurs, this function returns FALSE and prints a warning.

Parameters

self

A LwProgram

 

Returns

TRUE on success, FALSE if an error occured

Since: 0.4


lw_program_set_attribute ()

void
lw_program_set_attribute (LwProgram *self,
                          const gchar *name,
                          LwGLSLType type,
                          LwBuffer *buffer);

Binds buffer to the attribute variable name . Internally this function uses

glVertexAttribPointer

to define the vertex attribute array and

glEnableVertexAttribArray

to enable it.

This function assumes that the data stored in the buffer is tightly packed (stride is 0) and there is no offset for the first component (pointer is 0, see parameters of glVertexAttribPointer).

Parameters

self

A LwProgram

 

name

The name of an attribute variable

 

type

The LwGLSLType which represents the attribute's type

 

buffer

A LwBuffer

 

Since: 0.5


lw_program_set_matrix ()

void
lw_program_set_matrix (LwProgram *self,
                       const gchar *name,
                       LwMatrix *matrix);

Specifies the value of the matrix uniform variable name .

Parameters

self

A LwProgram

 

name

The name of an uniform variable of type mat4

 

matrix

A LwMatrix

 

Since: 0.5


lw_program_set_texture ()

void
lw_program_set_texture (LwProgram *self,
                        const gchar *name,
                        LwTexture *texture);

Binds the uniform variable name to texture . This function automatically binds the texture to the next free texture unit and so it is able to handle multiple textures for one LwProgram.

This functions calls lw_texture_bind_to(), so you just have to call lw_texture_unbind() or lw_texture_disable() if necessary. If you do not unbind the texture after every paint, make sure to unbind it in lw_wallpaper_restore_viewport().

Parameters

self

A LwProgram

 

name

The name of an uniform variable of type sampler2D

 

texture

A LwTexture

 

Since: 0.5

Types and Values

enum LwGLSLType

Members

LW_GLSL_TYPE_FLOAT

Represents the GLSL type float

 

LW_GLSL_TYPE_VEC2

Represents the GLSL type vec2

 

LW_GLSL_TYPE_VEC3

Represents the GLSL type vec3

 

LW_GLSL_TYPE_VEC4

Represents the GLSL type vec4

 

LW_GLSL_TYPE_INT

Represents the GLSL type int

 

LW_GLSL_TYPE_IVEC2

Represents the GLSL type ivec2

 

LW_GLSL_TYPE_IVEC3

Represents the GLSL type ivec3

 

LW_GLSL_TYPE_IVEC4

Represents the GLSL type ivec4

 

LW_GLSL_TYPE_BOOL

Represents the GLSL type bool

 

LW_GLSL_TYPE_BVEC2

Represents the GLSL type bvec2

 

LW_GLSL_TYPE_BVEC3

Represents the GLSL type bvec3

 

LW_GLSL_TYPE_BVEC4

Represents the GLSL type bvec4

 

Since: 0.5


struct LwProgram

struct LwProgram;

A structure for easier OpenGL program handling.

Since: 0.4


struct LwProgramClass

struct LwProgramClass {
};