Quick Links
> Homepage
|-- Overview
|-- Download
|-- Screenshots
|-- Community

> Code Sample Pack

> Reference Guide

> Changelog

> Overview of GLSL Hacker
> Live Coding
> Hack your first GLSL Code
> Moon3D


GLSL Hacker Articles

> Compute shaders on Radeon
> Distance functions in GLSL
> GLSL Interpolation Qualifiers
> Tessellation Spacing Modes
> Normal Visualizer with GS
> 3D Surface Plots
> Normal Mapping
> Circle and Disc in GLSL
> PhysX 3 Flag Demo
> GLSL Hacker on Raspberry Pi
GLSL Hacker

Reference Guide
Host-API Lua / Python



Back to Homepage
Back to Developer's Guide Index

gh_gpu_program Library


Description
gh_gpu_program is the module that manages GPU programs based on the GLSL language: creation, destruction, binding, uniforms settings.

Number of functions: 16

gh_gpu_program.create

Description
Creates a GLSL program from vertex (vs), pixel (ps), geometry (gs), tessellation control and evaluation (tcs and tes) or compute (cs) shaders.

Languages: Lua - Python

Parameters
  • 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.

    Return Values
  • gpu_program [INTEGER]: gpu program identifier

    Code sample :

    vs = "......"
    ps = "......"
    gpu_prog = gh_gpu_program.create(vs, ps, "", "", "", "")


    gh_gpu_program.create_from_file

    Description
    Loads a GLSL source code from file and creates a new GPU program node (actually a resource).

    Languages: Lua - Python

    Parameters
  • filename [STRING]: GPU program source code filename.
  • absolute_path [INTEGER]: Specifies if the path to the filename is relative (0) or absolute (1).

    Return Values
  • gpu_program [INTEGER]: gpu program identifier

    Code sample :

    abs_path = 0 -- relative path
    gpu_prog = gh_gpu_program.create_from_file("data/shader.glsl", abs_path)


    gh_gpu_program.bind

    Description
    Binds (makes it active) the GPU program to the renderer. To unbind a GPU program, just pass 0 as gpu program identifier.

    Languages: Lua - Python

    Parameters
  • gpu_program [INTEGER]: gpu program identifier.

    Code sample :

    gh_gpu_program.bind(gpu_prog) -- Binding
    ...
    gh_gpu_program.bind(0) -- Unbinding


    gh_gpu_program.run_compute

    Description
    Runs a compute program (OpenGL 4.3+ feature). See also: OpenGL 4.3: Compute Shaders Details (GL_ARB_compute_shader)

    Languages: Lua - Python

    Parameters
  • 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.

    Code sample :

    gh_gpu_program.bind(gpu_prog)
    gh_gpu_program.run_compute(gpu_prog, 16, 16, 16)


    gh_gpu_program.uniform1i

    Description
    Sets the value of an uniform variable.

    Languages: Lua - Python

    Parameters
  • gpu_program [INTEGER]: gpu program identifier.
  • uniform_name [STRING]: Uniform name.
  • x [INTEGER]: Uniform value.

    Code sample :

    gh_gpu_program.bind(gpu_prog)
    gh_gpu_program.uniform1i(gpu_prog, "index", 2)


    gh_gpu_program.uniform2i

    Description
    Sets the value of an uniform variable.

    Languages: Lua - Python

    Parameters
  • gpu_program [INTEGER]: gpu program identifier.
  • uniform_name [STRING]: Uniform name.
  • x, y [INTEGER]: Uniform value.

    Code sample :

    gh_gpu_program.bind(gpu_prog)
    gh_gpu_program.uniform2i(gpu_prog, "rg", 250, 25)


    gh_gpu_program.uniform3i

    Description
    Sets the value of an uniform variable.

    Languages: Lua - Python

    Parameters
  • gpu_program [INTEGER]: gpu program identifier.
  • uniform_name [STRING]: Uniform name.
  • x, y, z [INTEGER]: Uniform value.

    Code sample :

    gh_gpu_program.bind(gpu_prog)
    gh_gpu_program.uniform3i(gpu_prog, "rgb", 250, 25, 45)


    gh_gpu_program.uniform4i

    Description
    Sets the value of an uniform variable.

    Languages: Lua - Python

    Parameters
  • gpu_program [INTEGER]: gpu program identifier.
  • uniform_name [STRING]: Uniform name.
  • x, y, z, w [INTEGER]: Uniform value.

    Code sample :

    gh_gpu_program.bind(gpu_prog)
    gh_gpu_program.uniform4i(gpu_prog, "rgba", 250, 25, 45, 100)


    gh_gpu_program.uniform1f

    Description
    Sets the value of an uniform variable.

    Languages: Lua - Python

    Parameters
  • gpu_program [INTEGER]: gpu program identifier.
  • uniform_name [STRING]: Uniform name.
  • x [REAL]: Uniform value.

    Code sample :

    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

    Description
    Sets the value of an uniform variable.

    Languages: Lua - Python

    Parameters
  • gpu_program [INTEGER]: gpu program identifier.
  • uniform_name [STRING]: Uniform name.
  • x, y [REAL]: Uniform value.

    Code sample :

    gh_gpu_program.bind(gpu_prog)
    gh_gpu_program.uniform2f(gpu_prog, "uv", 0.1, 1.0)


    gh_gpu_program.uniform3f

    Description
    Sets the value of an uniform variable.

    Languages: Lua - Python

    Parameters
  • gpu_program [INTEGER]: gpu program identifier.
  • uniform_name [STRING]: Uniform name.
  • x, y, z [REAL]: Uniform value.

    Code sample :

    gh_gpu_program.bind(gpu_prog)
    gh_gpu_program.uniform3f(gpu_prog, "rgb", 0.25, 0.25, 0.45)


    gh_gpu_program.uniform4f

    Description
    Sets the value of an uniform variable.

    Languages: Lua - Python

    Parameters
  • gpu_program [INTEGER]: gpu program identifier.
  • uniform_name [STRING]: Uniform name.
  • x, y, z, w [REAL]: Uniform value.

    Code sample :

    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

    Description
    Sets the value of an uniform array of vec4i. Currently limited to one vec4i.

    Languages: Lua - Python

    Parameters
  • 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]

    Code sample :

    gh_gpu_program.bind(gpu_prog)
    gh_gpu_program.uniform4i_array(gpu_prog, "all_textures", 0, 1, 2, 3)


    gh_gpu_program.uniform4f_array

    Description
    Sets the value of an uniform array of vec4. Currently limited to one vec4.

    Languages: Lua - Python

    Parameters
  • 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]

    Code sample :

    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.set_vertex_attrib_name

    Description
    Sets the name of a vertex attribute.

    Languages: Lua - Python

    Parameters
  • gpu_program [INTEGER]: gpu program identifier.
  • vertex_index [INTEGER]: vertex attribute index.
  • name [STRING]: vertex attrib name.

    Code sample :

    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

    Description
    Gets the name of a vertex attribute.

    Languages: Lua - Python

    Parameters
  • gpu_program [INTEGER]: gpu program identifier.
  • vertex_index [INTEGER]: vertex attribute index.

    Return Values
  • name [STRING]: vertex attrib name.

    Code sample :

    gh_gpu_program.bind(gpu_prog)
    name = gh_gpu_program.get_vertex_attrib_name(gpu_prog, 0)





  • (C)2012-2013 Geeks3D