 Reference Guide Host-API Lua / Python
» Back to Homepage
» Back to Developer's Guide Index
gh_gpu_program Library
gh_gpu_program is the module that manages GPU programs based on the GLSL language: creation, destruction, binding, uniforms settings.
Number of functions: 18
gh_gpu_program.create
Creates a GLSL program from vertex (vs), pixel (ps), geometry (gs), tessellation control and evaluation (tcs and tes) or compute (cs) shaders.
: Lua - Python
vs [STRING]: vertex shader source code string.
ps [STRING]: pixel shader source code string.
gs [STRING]: geometry shader source code string.
tcs [STRING]: tessellation control shader source code string.
tes [STRING]: tessellation eval shader source code string.
cs [STRING]: compute shader source code string.
gpu_program [INTEGER]: gpu program identifier
:
vs = "......"
ps = "......"
gpu_prog = gh_gpu_program.create(vs, ps, "", "", "", "")
gh_gpu_program.create_from_file
Loads a GLSL source code from file and creates a new GPU program node (actually a resource).
: Lua - Python
filename [STRING]: GPU program source code filename.
absolute_path [INTEGER]: Specifies if the path to the filename is relative (0) or absolute (1).
gpu_program [INTEGER]: gpu program identifier
:
abs_path = 0 -- relative path
gpu_prog = gh_gpu_program.create_from_file("data/shader.glsl", abs_path)
gh_gpu_program.bind
Binds (makes it active) the GPU program to the renderer. To unbind a GPU program, just pass 0 as gpu program identifier.
: Lua - Python
gpu_program [INTEGER]: gpu program identifier.
:
gh_gpu_program.bind(gpu_prog) -- Binding
...
gh_gpu_program.bind(0) -- Unbinding
gh_gpu_program.run_compute
Runs a compute program (OpenGL 4.3+ feature). See also: OpenGL 4.3: Compute Shaders Details (GL_ARB_compute_shader)
: Lua - Python
gpu_program [INTEGER]: gpu program identifier.
num_groups_x, num_groups_y, num_groups_z [INTEGER]: Specifies the number of local work groups that will be dispatched in the X, Y and Z dimensions.
:
gh_gpu_program.bind(gpu_prog)
gh_gpu_program.run_compute(gpu_prog, 16, 16, 16)
gh_gpu_program.uniform1i
Sets the value of an uniform variable.
: Lua - Python
gpu_program [INTEGER]: gpu program identifier.
uniform_name [STRING]: Uniform name.
x [INTEGER]: Uniform value.
:
gh_gpu_program.bind(gpu_prog)
gh_gpu_program.uniform1i(gpu_prog, "index", 2)
gh_gpu_program.uniform2i
Sets the value of an uniform variable.
: Lua - Python
gpu_program [INTEGER]: gpu program identifier.
uniform_name [STRING]: Uniform name.
x, y [INTEGER]: Uniform value.
:
gh_gpu_program.bind(gpu_prog)
gh_gpu_program.uniform2i(gpu_prog, "rg", 250, 25)
gh_gpu_program.uniform3i
Sets the value of an uniform variable.
: Lua - Python
gpu_program [INTEGER]: gpu program identifier.
uniform_name [STRING]: Uniform name.
x, y, z [INTEGER]: Uniform value.
:
gh_gpu_program.bind(gpu_prog)
gh_gpu_program.uniform3i(gpu_prog, "rgb", 250, 25, 45)
gh_gpu_program.uniform4i
Sets the value of an uniform variable.
: Lua - Python
gpu_program [INTEGER]: gpu program identifier.
uniform_name [STRING]: Uniform name.
x, y, z, w [INTEGER]: Uniform value.
:
gh_gpu_program.bind(gpu_prog)
gh_gpu_program.uniform4i(gpu_prog, "rgba", 250, 25, 45, 100)
gh_gpu_program.uniform1f
Sets the value of an uniform variable.
: Lua - Python
gpu_program [INTEGER]: gpu program identifier.
uniform_name [STRING]: Uniform name.
x [REAL]: Uniform value.
:
elapsed_time = gh_utils.get_elapsed_time()
gh_gpu_program.bind(gpu_prog)
gh_gpu_program.uniform1f(gpu_prog, "time", elapsed_time)
gh_gpu_program.uniform2f
Sets the value of an uniform variable.
: Lua - Python
gpu_program [INTEGER]: gpu program identifier.
uniform_name [STRING]: Uniform name.
x, y [REAL]: Uniform value.
:
gh_gpu_program.bind(gpu_prog)
gh_gpu_program.uniform2f(gpu_prog, "uv", 0.1, 1.0)
gh_gpu_program.uniform3f
Sets the value of an uniform variable.
: Lua - Python
gpu_program [INTEGER]: gpu program identifier.
uniform_name [STRING]: Uniform name.
x, y, z [REAL]: Uniform value.
:
gh_gpu_program.bind(gpu_prog)
gh_gpu_program.uniform3f(gpu_prog, "rgb", 0.25, 0.25, 0.45)
gh_gpu_program.uniform4f
Sets the value of an uniform variable.
: Lua - Python
gpu_program [INTEGER]: gpu program identifier.
uniform_name [STRING]: Uniform name.
x, y, z, w [REAL]: Uniform value.
:
gh_gpu_program.bind(gpu_prog)
gh_gpu_program.uniform4f(gpu_prog, "rgba", 0.25, 0.25, 0.45, 1.0)
gh_gpu_program.uniform4i_array
Sets the value of an uniform array of vec4i. Currently limited to one vec4i.
: Lua - Python
gpu_program [INTEGER]: gpu program identifier.
uniform_name [STRING]: Uniform name.
x, y, z, w [INTEGER]: Uniform value. The four elements of an uniform array: int xyzw[4]
:
gh_gpu_program.bind(gpu_prog)
gh_gpu_program.uniform4i_array(gpu_prog, "all_textures", 0, 1, 2, 3)
gh_gpu_program.uniform4f_array
Sets the value of an uniform array of vec4. Currently limited to one vec4.
: Lua - Python
gpu_program [INTEGER]: gpu program identifier.
uniform_name [STRING]: Uniform name.
x, y, z, w [REAL]: Uniform value. The four elements of an uniform array: float xyzw[4]
:
gh_gpu_program.bind(gpu_prog)
gh_gpu_program.uniform4f_array(gpu_prog, "all_params", 0.2, 10.4, 0.003, 0.001)
gh_gpu_program.update_mvp_matrix
Updates the model view projection (MVP) matrix from a camera and an object.
: Lua - Python
gpu_program [INTEGER]: gpu program identifier.
mvp_uniform_name [STRING]: Uniform name of the MVP matrix.
camera [INTEGER]: camera identifier.
object [INTEGER]: object identifier.
:
gh_gpu_program.bind(gpu_prog)
gh_gpu_program.update_mvp_matrix(gpu_prog, "MVP", camera, object)
gh_gpu_program.update_modelviewproj_matrices
Updates the model, view and projection matrices from a camera and an object.
: Lua - Python
gpu_program [INTEGER]: gpu program identifier.
camera_id [INTEGER]: camera identifier.
view_mat_uniform_name [STRING]: Uniform name of the view matrix.
proj_mat_uniform_name [STRING]: Uniform name of the projection matrix.
object_id [INTEGER]: object identifier.
model_mat_uniform_name [STRING]: Uniform name of the model matrix.
:
gh_gpu_program.bind(gpu_program)
gh_gpu_program.update_modelviewproj_matrices(gpu_program, camera_id, "ViewMat", "ProjMat", object_id, "ModelMat")
gh_gpu_program.set_vertex_attrib_name
Sets the name of a vertex attribute.
: Lua - Python
gpu_program [INTEGER]: gpu program identifier.
vertex_index [INTEGER]: vertex attribute index.
name [STRING]: vertex attrib name.
:
gh_gpu_program.bind(gpu_prog)
gh_gpu_program.set_vertex_attrib_name(gpu_prog, 0, "gxl3d_Position")
gh_gpu_program.get_vertex_attrib_name
Gets the name of a vertex attribute.
: Lua - Python
gpu_program [INTEGER]: gpu program identifier.
vertex_index [INTEGER]: vertex attribute index.
name [STRING]: vertex attrib name.
:
gh_gpu_program.bind(gpu_prog)
name = gh_gpu_program.get_vertex_attrib_name(gpu_prog, 0)
|