EAGL.Shader (eagl v0.2.0)

View Source

Module for OpenGL shader management. Handles shader creation, compilation, and program linking.

Summary

Functions

Convenience function to cache uniform locations for repeated use. Returns a map of uniform names to their locations.

Checks if a shader compiled successfully.

Cleans up a shader program and all its attached shaders.

Cleans up a shader.

Creates a program, attaches shaders, links, and returns the link status.

Creates and compiles a shader of the specified type with the given source code. Returns the shader ID.

Get uniform location for a program. Similar to wings_gl:uloc/2. Returns the uniform location or -1 if not found.

Set uniform value with automatic type detection. Similar to wings_gl:set_uloc/3. Supports various EAGL.Math types and basic values.

Set uniform value at a specific location with automatic type detection.

Convenience function to set multiple uniforms at once. Takes a program and a keyword list of uniform_name -> value pairs.

Types

mat2()

@type mat2() :: EAGL.Math.mat2()

mat3()

@type mat3() :: EAGL.Math.mat3()

mat4()

@type mat4() :: EAGL.Math.mat4()

quat()

@type quat() :: EAGL.Math.quat()

uniform_value()

@type uniform_value() ::
  vec2()
  | vec3()
  | vec4()
  | mat2()
  | mat3()
  | mat4()
  | quat()
  | float()
  | integer()
  | boolean()

vec2()

@type vec2() :: EAGL.Math.vec2()

vec3()

@type vec3() :: EAGL.Math.vec3()

vec4()

@type vec4() :: EAGL.Math.vec4()

Functions

cache_uniform_locations(program, uniform_names)

@spec cache_uniform_locations(non_neg_integer(), [String.t() | atom()]) :: %{
  required(String.t()) => integer()
}

Convenience function to cache uniform locations for repeated use. Returns a map of uniform names to their locations.

check_compile_status(shader)

Checks if a shader compiled successfully.

cleanup_program(program)

Cleans up a shader program and all its attached shaders.

cleanup_shader(shader)

Cleans up a shader.

create_attach_link(shaders)

Creates a program, attaches shaders, links, and returns the link status.

create_shader(shader_type, filename)

@spec create_shader(non_neg_integer(), String.t()) ::
  {:ok, non_neg_integer()} | {:error, String.t()}

Creates and compiles a shader of the specified type with the given source code. Returns the shader ID.

get_uniform_location(program, uniform_name)

@spec get_uniform_location(non_neg_integer(), String.t() | charlist()) :: integer()

Get uniform location for a program. Similar to wings_gl:uloc/2. Returns the uniform location or -1 if not found.

set_uniform(program, uniform_name, value)

@spec set_uniform(non_neg_integer(), String.t() | charlist(), uniform_value()) :: :ok

Set uniform value with automatic type detection. Similar to wings_gl:set_uloc/3. Supports various EAGL.Math types and basic values.

set_uniform_at_location(location, matrix)

@spec set_uniform_at_location(integer(), uniform_value()) :: :ok
@spec set_uniform_at_location(integer(), vec3()) :: :ok
@spec set_uniform_at_location(integer(), vec2()) :: :ok
@spec set_uniform_at_location(integer(), vec4() | quat()) :: :ok
@spec set_uniform_at_location(integer(), mat4()) :: :ok
@spec set_uniform_at_location(integer(), mat3()) :: :ok
@spec set_uniform_at_location(integer(), mat2()) :: :ok
@spec set_uniform_at_location(integer(), integer()) :: :ok
@spec set_uniform_at_location(integer(), float()) :: :ok
@spec set_uniform_at_location(integer(), boolean()) :: :ok

Set uniform value at a specific location with automatic type detection.

set_uniforms(program, uniforms)

@spec set_uniforms(non_neg_integer(), [{atom(), uniform_value()}]) :: :ok

Convenience function to set multiple uniforms at once. Takes a program and a keyword list of uniform_name -> value pairs.