The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

OpenGL::Sandbox::Program - Wrapper object for OpenGL shader program pipeline

VERSION

version 0.120

DESCRIPTION

OpenGL shaders get combined into a pipeline. In older versions of OpenGL, there was only one program composed of a vertex shader and fragment shader, and attaching one of those shaders was a global change. In newer OpenGL, you may assemble multiple program pipelines and switch between them.

This class tries to support both APIs, by holding a set of shaders which you can then "bind". On newer OpenGL, this calls glUseProgram. On older OpenGL, this changes the global vertex and fragment shaders to the ones referenced by this object.

ATTRIBUTES

name

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

prepared

Boolean; whether the program is ready to run. This is always 'true' for older global-program OpenGL.

shaders

A hashref of shaders, each of which will be attached to the program when it is activated. The keys of the hashref are up to you, and simply to help diagnostics or merging shader configurations together with defaults.

shader_list

A convenient accessor for listing out the values of the "shader" hash.

id

The OpenGL integer 'name' of this program. On older OpenGL with the global program, this will always be undef. On newer OpenGL, this should always return a value because accessing it will call glCreateProgram.

has_id

True if the id attribute has been lazy-loaded already.

uniforms

Lazy-built hashref listing all uniforms of the compiled program.

has_uniforms

Whether this has been lazy-built yet

clear_uniforms

Remove the cache, to be rebuilt on next use

METHODS

bind

  $program->bind;

Begin using this program as the active GL pipeline.

Returns $self for convenient chaining.

prepare

For relevant implementations, this attaches the shaders and links the program. If it fails, this throws an exception. For OpenGL 4 implementation, this only happens once, and any changes to "shaders" afterward are ignored. Use "unprepare" to remove the compiled state and be able to rearrange the shaders.

Returns $self for convenient chaining.

unprepare

Release resources allocated by "prepare".

attr_by_name

Return the attribute ID of the given name, for the prepared program.

uniform_location

Return the uniform ID of the given name, for the prepared program.

set_uniform

  $prog->set_uniform( $name, \@values );
  $prog->set_uniform( $name, $opengl_array );

Set the value of a uniform. This attempts to guess at the size/geometry of the uniform based on the number or type of values given.

set

Alias for set_uniform.

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.