GLSL Hacker
FEATURES DOWNLOAD GALLERY BLOG LEARN



» Back to Reference 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: 36



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.

    Return Values

    This function has no return value(s).

    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.

    Return Values

    This function has no return value(s).

    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.

    Return Values

    This function has no return value(s).

    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.

    Return Values

    This function has no return value(s).

    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.

    Return Values

    This function has no return value(s).

    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.

    Return Values

    This function has no return value(s).

    Code sample


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



    gh_gpu_program.uniform1iv

    Description

    Sets the value of an uniform array.

    Languages

    Lua

    Parameters

  • gpu_program [INTEGER]: gpu program identifier.
  • uniform_name [STRING]: Uniform name.
  • array_count [INTEGER]: number of entries of the uniform array.
  • array [TABLE]: uniform array.

    Return Values

    This function has no return value(s).

    Code sample


    material_ids = {}
    InitMaterialIDs(material_ids)
    gh_gpu_program.bind(gpu_prog)
    gh_gpu_program.uniform1iv(gpu_prog, "material_ids", material_ids, 10)



    gh_gpu_program.uniform1fv

    Description

    Sets the value of an uniform array.

    Languages

    Lua

    Parameters

  • gpu_program [INTEGER]: gpu program identifier.
  • uniform_name [STRING]: Uniform name.
  • array_count [INTEGER]: number of entries of the uniform array.
  • array [TABLE]: uniform array.

    Return Values

    This function has no return value(s).

    Code sample


    temperatures = {}
    InitTemperatures(temperatures)
    gh_gpu_program.bind(gpu_prog)
    gh_gpu_program.uniform1fv(gpu_prog, "temperatures", 10, temperatures)



    gh_gpu_program.uniform2fv

    Description

    Sets the value of an uniform array.

    Languages

    Lua

    Parameters

  • gpu_program [INTEGER]: gpu program identifier.
  • uniform_name [STRING]: Uniform name.
  • array_count [INTEGER]: number of entries of the uniform array.
  • array [TABLE]: uniform array.

    Return Values

    This function has no return value(s).

    Code sample


    uv = {} -- array element: {x=0, y=0}
    InitUV(uv)
    gh_gpu_program.bind(gpu_prog)
    gh_gpu_program.uniform2fv(gpu_prog, "uv", 10, uv)



    gh_gpu_program.uniform3fv

    Description

    Sets the value of an uniform array.

    Languages

    Lua

    Parameters

  • gpu_program [INTEGER]: gpu program identifier.
  • uniform_name [STRING]: Uniform name.
  • array_count [INTEGER]: number of entries of the uniform array.
  • array [TABLE]: uniform array.

    Return Values

    This function has no return value(s).

    Code sample


    xyz = {} -- array element: {x=0, y=0, z=0}
    InitXYZ(xyz)
    gh_gpu_program.bind(gpu_prog)
    gh_gpu_program.uniform3fv(gpu_prog, "xyz", 10, xyz)



    gh_gpu_program.uniform4fv

    Description

    Sets the value of an uniform array.

    Languages

    Lua

    Parameters

  • gpu_program [INTEGER]: gpu program identifier.
  • uniform_name [STRING]: Uniform name.
  • array_count [INTEGER]: number of entries of the uniform array.
  • array [TABLE]: uniform array.

    Return Values

    This function has no return value(s).

    Code sample


    xyzw = {} -- array element: {x=0, y=0, z=0, w=0}
    InitXYZW(xyzw)
    gh_gpu_program.bind(gpu_prog)
    gh_gpu_program.uniform4fv(gpu_prog, "xyzw", 10, xyzw)



    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.

    Return Values

    This function has no return value(s).

    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.

    Return Values

    This function has no return value(s).

    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.

    Return Values

    This function has no return value(s).

    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.

    Return Values

    This function has no return value(s).

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

    Description

    Sets the value of an uniform variable.

    Languages

    Lua - Python

    Parameters

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

    Return Values

    This function has no return value(s).

    Code sample


    gh_gpu_program.bind(gpu_prog)
    gh_gpu_program.uniform1d(gpu_prog, "r", 0.25)



    gh_gpu_program.uniform2d

    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 [DOUBLE]: Uniform value.

    Return Values

    This function has no return value(s).

    Code sample


    gh_gpu_program.bind(gpu_prog)
    gh_gpu_program.uniform2d(gpu_prog, "rg", 0.25, 0.22)



    gh_gpu_program.uniform3d

    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 [DOUBLE]: Uniform value.

    Return Values

    This function has no return value(s).

    Code sample


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



    gh_gpu_program.uniform4d

    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 [DOUBLE]: Uniform value.

    Return Values

    This function has no return value(s).

    Code sample


    gh_gpu_program.bind(gpu_prog)
    gh_gpu_program.uniform4d(gpu_prog, "rgba", 0.25, 0.25, 0.45, 1.0)



    gh_gpu_program.uniform1ui64

    Description

    Sets the value of an uniform variable. Useful with bindless texture (OpenGL 4.4)

    Languages

    Lua - Python

    Parameters

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

    Return Values

    This function has no return value(s).

    Code sample


    gh_gpu_program.bind(gpu_prog)
    gh_gpu_program.uniform1ui64(gpu_prog, "tex", bindless_texture_handle)



    gh_gpu_program.uniform1ui64v

    Description

    Sets the value of an uniform array. Useful with bindless texture (OpenGL 4.4)

    Languages

    Lua

    Parameters

  • gpu_program [INTEGER]: gpu program identifier.
  • uniform_name [STRING]: Uniform name.
  • array_count [INTEGER]: number of entries of the uniform array.
  • array [TABLE]: uniform array.

    Return Values

    This function has no return value(s).

    Code sample


    all_texture_handles = {}
    gh_gpu_program.bind(gpu_prog)
    gh_gpu_program.uniform1ui64v(gpu_prog, "all_textures", 32, all_texture_handles)



    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]

    Return Values

    This function has no return value(s).

    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]

    Return Values

    This function has no return value(s).

    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.

    Return Values

    This function has no return value(s).

    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)



    gh_gpu_program.uniform_subroutine

    Description

    Sets the matrices of a camera as uniforms.

    Languages

    Lua - Python

    Parameters

  • gpu_program [INTEGER]: gpu program identifier.
  • shader_type [INTEGER]: type of the shader.
  • subroutine_uniform_name [STRING]: uniform name of the subroutine.
  • subroutine_name [STRING]: name of the real subroutine.

    Return Values

    This function has no return value(s).

    Code sample


    GPU_SHADER_VERTEX = 0
    GPU_SHADER_PIXEL = 1
    GPU_SHADER_GEOMETRY = 2
    GPU_SHADER_TESS_CONTROL = 3
    GPU_SHADER_TESS_EVAL = 4
    GPU_SHADER_COMPUTE = 5
    gh_gpu_program.uniform_subroutine(gpu_prog, GPU_SHADER_PIXEL, "Color", "ColorBlue")



    gh_gpu_program.uniform_camera_matrices

    Description

    Sets the matrices of a camera as uniforms.

    Languages

    Lua - Python

    Parameters

  • gpu_program [INTEGER]: gpu program identifier.
  • camera [INTEGER]: camera identifier.
  • uniform_name_view_mat [STRING]: uniform name of the view matrix.
  • uniform_name_proj_mat [STRING]: uniform name of the projection matrix.

    Return Values

    This function has no return value(s).

    Code sample


    gh_gpu_program.uniform_camera_matrices(gpu_prog, camera, "ViewMat", "ProjMat")



    gh_gpu_program.set_uniform_object_matrix

    Description

    Sets the local matrix of an object as uniform.

    Languages

    Lua - Python

    Parameters

  • gpu_program [INTEGER]: gpu program identifier.
  • object [INTEGER]: camera identifier.
  • uniform_name_mat [STRING]: uniform name of the matrix.

    Return Values

    This function has no return value(s).

    Code sample


    gh_gpu_program.set_uniform_object_matrix(gpu_prog, object, "ModelMat")



    gh_gpu_program.get_interface_block_index

    Description

    Gets the index of an interface block.

    Languages

    Lua - Python

    Parameters

  • gpu_program [INTEGER]: gpu program identifier.
  • block_type [STRING]: type of the block: 'UNIFORM', 'SHADER_STORAGE'
  • block_name [STRING]: name of the block

    Return Values

  • block_index [INTEGER]: block index.

    Code sample


    index = gh_gpu_program.get_interface_block_index(gpu_prog, "UNIFORM", "CameraMatrix")



    gh_gpu_program.get_uniform_block_size

    Description

    Gets the size in bytes of an uniform block.

    Languages

    Lua - Python

    Parameters

  • gpu_program [INTEGER]: gpu program identifier.
  • block_index [INTEGER]: block index

    Return Values

  • block_size [INTEGER]: block size in bytes.

    Code sample


    index = gh_gpu_program.get_interface_block_index(gpu_prog, "UNIFORM", "CameraMatrix")
    size = gh_gpu_program.get_uniform_block_size(gpu_prog, index)



    gh_gpu_program.set_uniform_block_binding

    Description

    Sets the buffer binding point of an uniform block.

    Languages

    Lua - Python

    Parameters

  • gpu_program [INTEGER]: gpu program identifier.
  • block_index [INTEGER]: block index
  • binding_point_index [INTEGER]: index of a GPU buffer binding point

    Return Values

    This function has no return value(s).

    Code sample


    gh_gpu_program.set_uniform_block_binding(gpu_prog, index, 2)



    gh_gpu_program.get_uniform_size_and_offset

    Description

    Gets the size and offset in bytes of a variable inside an uniform block.

    Languages

    Lua - Python

    Parameters

  • gpu_program [INTEGER]: gpu program identifier.
  • variable_name [STRING]: name of the variable

    Return Values

  • size, offset [INTEGER]: size and offset in bytes.

    Code sample


    size, offset = gh_gpu_program.get_uniform_size_and_offset(gpu_prog, "positions")



    gh_gpu_program.get_uniform_array_stride

    Description

    Gets the stride in bytes of an array inside an uniform block.

    Languages

    Lua - Python

    Parameters

  • gpu_program [INTEGER]: gpu program identifier.
  • variable_name [STRING]: name of the variable

    Return Values

  • stride [INTEGER]: stride in bytes.

    Code sample


    stride = gh_gpu_program.get_uniform_array_stride(gpu_prog, "positions")



    gh_gpu_program.set_shader_storage_block_binding

    Description

    Sets the buffer binding point of a shader storage block.

    Languages

    Lua - Python

    Parameters

  • gpu_program [INTEGER]: gpu program identifier.
  • block_index [INTEGER]: block index
  • binding_point_index [INTEGER]: index of a GPU buffer binding point

    Return Values

    This function has no return value(s).

    Code sample


    gh_gpu_program.set_shader_storage_block_binding(gpu_prog, index, 3)





    2013-2015 Geeks3D. All Rights Reserved.

    .:- G3D Network -:.