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_renderer Library


Description
gh_renderer is the module that talks directly with the graphics hardware.

Number of functions: 50

gh_renderer.set_vsync

Description
Enables or disables the vertical synchronization.

Languages: Lua - Python

Parameters
  • state [INTEGER]: enabled (1) or disabled (0).

    Code sample :

    gh_renderer.set_vsync(0)


    gh_renderer.get_opengl_error

    Description
    Returns the OpenGL error code or 0 if no error.

    Languages: Lua - Python

    Return Values
  • error [INTEGER]: error code.

    Code sample :

    err_code = gh_renderer.get_opengl_error()


    gh_renderer.set_viewport

    Description
    Sets the viewport.

    Languages: Lua - Python

    Parameters
  • x, y [INTEGER]: viewport offsets.
  • width, height [INTEGER]: viewport size.

    Code sample :

    gh_renderer.set_viewport(0, 0, width, height)


    gh_renderer.set_scissor

    Description
    Sets the scissor rectangle.

    Languages: Lua - Python

    Parameters
  • x, y [INTEGER]: scissor rectangle offsets.
  • width, height [INTEGER]: scissor rectangle size.

    Code sample :

    gh_renderer.set_scissor(0, 0, width, height)


    gh_renderer.set_viewport_scissor

    Description
    Sets the viewport and the scissor rectangle in the same call.

    Languages: Lua - Python

    Parameters
  • x, y [INTEGER]: offsets.
  • width, height [INTEGER]: viewport and scissor rectangle size.

    Code sample :

    gh_renderer.set_viewport_scissor(0, 0, width, height)


    gh_renderer.set_viewport_scissor_ptr

    Description
    Sets the viewport and the scissor rectangle in the same call.

    Languages: Lua - Python

    Parameters
  • R_ptr [POINTER]: pointer on the current renderer.
  • x, y [INTEGER]: offsets.
  • width, height [INTEGER]: viewport and scissor rectangle size.

    Code sample :

    gh_renderer.set_viewport_scissor_ptr(R_ptr, 0, 0, width, height)


    gh_renderer.set_scissor_state

    Description
    Enables or disable the scissor test.

    Languages: Lua - Python

    Parameters
  • state [INTEGER]: enabled (1) or disabled (0).

    Code sample :

    gh_renderer.set_scissor_state(1)


    gh_renderer.clear_color_buffer

    Description
    Clear the color buffer with a RGBA color.

    Languages: Lua - Python

    Parameters
  • r, g, b, a [CLAMPED_REAL]: RGBA clear color.

    Code sample :

    gh_renderer.clear_color_buffer(0, 0, 0, 1)


    gh_renderer.clear_color_buffer_ptr

    Description
    Clear the color buffer with a RGBA color.

    Languages: Lua - Python

    Parameters
  • R_ptr [POINTER]: pointer on the current renderer.
  • r, g, b, a [CLAMPED_REAL]: RGBA clear color.

    Code sample :

    gh_renderer.clear_color_buffer_ptr(R_ptr, 0, 0, 0, 1)


    gh_renderer.clear_depth_buffer

    Description
    Clear the depth buffer.

    Languages: Lua - Python

    Parameters
  • z [CLAMPED_REAL]: z buffer value.

    Code sample :

    z = 1.0
    gh_renderer.clear_depth_buffer(z)


    gh_renderer.clear_depth_buffer_ptr

    Description
    Clear the depth buffer.

    Languages: Lua - Python

    Parameters
  • R_ptr [POINTER]: pointer on the current renderer.
  • z [CLAMPED_REAL]: z buffer value.

    Code sample :

    z = 1.0
    gh_renderer.clear_depth_buffer_ptr(R_ptr, z)


    gh_renderer.clear_color_depth_buffers

    Description
    Clear the color and depth buffers in the same call.

    Languages: Lua - Python

    Parameters
  • r, g, b, a [CLAMPED_REAL]: RGBA clear color.
  • z [CLAMPED_REAL]: z buffer value.

    Code sample :

    gh_renderer.clear_color_depth_buffers(r, g, b, a, z)


    gh_renderer.clear_color_depth_buffers_ptr

    Description
    Clear the color and depth buffers in the same call.

    Languages: Lua - Python

    Parameters
  • R_ptr [POINTER]: pointer on the current renderer.
  • r, g, b, a [CLAMPED_REAL]: RGBA clear color.
  • z [CLAMPED_REAL]: z buffer value.

    Code sample :

    gh_renderer.clear_color_depth_buffers_ptr(R_ptr, r, g, b, a, z)


    gh_renderer.set_depth_test_state

    Description
    Enables or disable the depth test.

    Languages: Lua - Python

    Parameters
  • state [INTEGER]: enabled (1) or disabled (0).

    Code sample :

    gh_renderer.set_depth_test_state(1)


    gh_renderer.set_depth_test_state_ptr

    Description
    Enables or disable the depth test.

    Languages: Lua - Python

    Parameters
  • R_ptr [POINTER]: pointer on the current renderer.
  • state [INTEGER]: enabled (1) or disabled (0).

    Code sample :

    gh_renderer.set_depth_test_state_ptr(R_ptr, 1)


    gh_renderer.set_depth_test_func

    Description
    Sets the depth test function.

    Languages: Lua - Python

    Parameters
  • func_type [INTEGER]: depth test comparison function:
    • CMP_FUNC_NEVER = 0
    • CMP_FUNC_LESS = 1
    • CMP_FUNC_LESS_OR_EQUAL = 2
    • CMP_FUNC_GREATER = 3
    • CMP_FUNC_GREATER_OR_EQUAL = 4
    • CMP_FUNC_EQUAL = 5
    • CMP_FUNC_NOT_EQUAL = 6
    • CMP_FUNC_ALWAYS = 7


    Code sample :

    local CMP_FUNC_LESS = 1
    gh_renderer.set_depth_test_func(CMP_FUNC_LESS)


    gh_renderer.rasterizer_set_cull_state

    Description
    Enables or disable the face culling state.

    Languages: Lua - Python

    Parameters
  • state [INTEGER]: enabled (1) or disabled (0).

    Code sample :

    gh_renderer.rasterizer_set_cull_state(1)


    gh_renderer.rasterizer_set_cull_face

    Description
    Sets the face type to be culled.

    Languages: Lua - Python

    Parameters
  • face [INTEGER]: type of face: back (0), front (1) or back_and_front (2).

    Code sample :

    local BACK_FACE = 0
    gh_renderer.rasterizer_set_cull_face(BACK_FACE)
    gh_renderer.rasterizer_set_cull_state(1)


    gh_renderer.rasterizer_set_polygon_mode

    Description
    Sets the polygon rendering mode.

    Languages: Lua - Python

    Parameters
  • face [INTEGER]: type of face: back (0), front (1) or back_and_front (2).
  • mode [INTEGER]: polygon rendering mode: point (0), line (1) or solid (2).

    Code sample :

    local BACK_FRONT_FACE = 2
    local LINE = 1
    gh_renderer.rasterizer_set_polygon_mode(BACK_FRONT_FACE, LINE)


    gh_renderer.rasterizer_set_polygon_mode_ptr

    Description
    Sets the polygon rendering mode.

    Languages: Lua - Python

    Parameters
  • R_ptr [POINTER]: pointer on the current renderer.
  • face [INTEGER]: type of face: back (0), front (1) or back_and_front (2).
  • mode [INTEGER]: polygon rendering mode: point (0), line (1) or solid (2).

    Code sample :

    local BACK_FRONT_FACE = 2
    local LINE = 1
    gh_renderer.rasterizer_set_polygon_mode_ptr(R_ptr, BACK_FRONT_FACE, LINE)


    gh_renderer.rasterizer_apply_states

    Description
    Applies all states modified with gh_renderer.rasterizer_xxxx() functions.

    Languages: Lua - Python

    Code sample :

    local BACK_FACE = 0
    gh_renderer.rasterizer_set_cull_face(BACK_FACE)
    gh_renderer.rasterizer_set_cull_state(0)
    local BACK_FRONT_FACE = 2
    local LINE = 1
    gh_renderer.rasterizer_set_polygon_mode(BACK_FRONT_FACE, LINE)
    gh_renderer.rasterizer_apply_states()


    gh_renderer.rasterizer_apply_states_ptr

    Description
    Applies all states modified with gh_renderer.rasterizer_xxxx() functions.

    Languages: Lua - Python

    Parameters
  • R_ptr [POINTER]: pointer on the current renderer.

    Code sample :

    local BACK_FRONT_FACE = 2
    local LINE = 1
    gh_renderer.rasterizer_set_polygon_mode_ptr(R_ptr, BACK_FRONT_FACE, LINE)
    gh_renderer.rasterizer_apply_states_ptr(R_ptr)


    gh_renderer.set_blending_state

    Description
    Enables or disables the color blending.

    Languages: Lua - Python

    Parameters
  • state [INTEGER]: enabled (1) or disabled (0).

    Code sample :

    gh_renderer.set_blending_state(1)


    gh_renderer.set_blending_state_ptr

    Description
    Enables or disables the color blending.

    Languages: Lua - Python

    Parameters
  • R_ptr [POINTER]: pointer on the current renderer.
  • state [INTEGER]: enabled (1) or disabled (0).

    Code sample :

    gh_renderer.set_blending_state_ptr(R_ptr, 1)


    gh_renderer.set_blending_factors

    Description
    Sets the source and destination blending factors.

    Languages: Lua - Python

    Parameters
  • src [INTEGER]: source factor. Possible values for source and destination factors:
    • RENDERER_BLEND_FACTOR_ZERO = 0
    • BLEND_FACTOR_ONE = 1
    • BLEND_FACTOR_SRC_ALPHA = 2
    • BLEND_FACTOR_ONE_MINUS_DST_ALPHA = 3
    • BLEND_FACTOR_ONE_MINUS_DST_COLOR = 4
    • BLEND_FACTOR_ONE_MINUS_SRC_ALPHA = 5
    • BLEND_FACTOR_DST_COLOR = 6
    • BLEND_FACTOR_DST_ALPHA = 7
    • BLEND_FACTOR_SRC_COLOR = 8
    • BLEND_FACTOR_ONE_MINUS_SRC_COLOR = 9
  • dst [INTEGER]: destination factor. For possible values, see the source factor.

    Code sample :

    local BLEND_FACTOR_ONE = 1
    gh_renderer.set_blending_factors(BLEND_FACTOR_ONE, BLEND_FACTOR_ONE)
    gh_renderer.set_blending_state(1)


    gh_renderer.set_blending_factors_ptr

    Description
    Sets the source and destination blending factors.

    Languages: Lua - Python

    Parameters
  • R_ptr [POINTER]: pointer on the current renderer.
  • src [INTEGER]: source factor. Possible values for source and destination factors:
    • RENDERER_BLEND_FACTOR_ZERO = 0
    • BLEND_FACTOR_ONE = 1
    • BLEND_FACTOR_SRC_ALPHA = 2
    • BLEND_FACTOR_ONE_MINUS_DST_ALPHA = 3
    • BLEND_FACTOR_ONE_MINUS_DST_COLOR = 4
    • BLEND_FACTOR_ONE_MINUS_SRC_ALPHA = 5
    • BLEND_FACTOR_DST_COLOR = 6
    • BLEND_FACTOR_DST_ALPHA = 7
    • BLEND_FACTOR_SRC_COLOR = 8
    • BLEND_FACTOR_ONE_MINUS_SRC_COLOR = 9
  • dst [INTEGER]: destination factor. For possible values, see the source factor.

    Code sample :

    local BLEND_FACTOR_ONE = 1
    gh_renderer.set_blending_factors_ptr(R_ptr, BLEND_FACTOR_ONE, BLEND_FACTOR_ONE)
    gh_renderer.set_blending_state_ptr(R_ptr, 1)


    gh_renderer.update_fixed_mvp_matrices

    Description
    Updates the fixed modelview and projection matrices from a camera and an object. No GPU program is required for the rendering of the object.

    Languages: Lua - Python

    Parameters
  • camera_id [INTEGER]: camera identifier.
  • object_id [INTEGER]: object identifier.

    Code sample :

    gh_renderer.update_fixed_mvp_matrices(camera_id, object_id)


    gh_renderer.update_fixed_mvp_matrices_ptr

    Description
    Updates the fixed modelview and projection matrices from a camera and an object. No GPU program is required for the rendering of the object.

    Languages: Lua - Python

    Parameters
  • R_ptr [POINTER]: pointer on the current renderer.
  • camera_ptr [POINTER]: pointer on the camera node.
  • object_ptr [POINTER]: pointer on the object node.

    Code sample :

    gh_renderer.update_fixed_mvp_matrices_ptr(R_ptr, camera_ptr, object_ptr)


    gh_renderer.get_api_version_major

    Description
    Gets OpenGL major version number.

    Languages: Lua - Python

    Return Values
  • major [INTEGER]: major version

    Code sample :

    glmajor = gh_renderer.get_api_version_major()
    if (glmajor < 4) then
    -- Tessellation not supported
    end


    gh_renderer.get_api_version_minor

    Description
    Gets OpenGL minor version number.

    Languages: Lua - Python

    Return Values
  • minor [INTEGER]: minor version

    Code sample :

    glminor = gh_renderer.get_api_version_minor()


    gh_renderer.get_api_version

    Description
    Gets the OpenGL version.

    Languages: Lua - Python

    Return Values
  • version [STRING]: OpenGL version

    Code sample :

    glversion = gh_renderer.get_api_version()


    gh_renderer.get_renderer_model

    Description
    Gets the model of the renderer (the name of the graphics card).

    Languages: Lua - Python

    Return Values
  • model [STRING]: Renderer model

    Code sample :

    glrenderer = gh_renderer.get_renderer_model()


    gh_renderer.get_renderer_vendor

    Description
    Gets the vendor of the renderer (the name of the graphics card GPU maker).

    Languages: Lua - Python

    Return Values
  • vendor [STRING]: Renderer vendor

    Code sample :

    glvendor = gh_renderer.get_renderer_vendor()


    gh_renderer.get_shading_language_version

    Description
    Gets the GLSL version.

    Languages: Lua - Python

    Return Values
  • version [STRING]: GLSL version

    Code sample :

    glsl_version = gh_renderer.get_shading_language_version()


    gh_renderer.get_num_opengl_extensions

    Description
    Returns the number of OpenGL extensions.

    Languages: Lua - Python

    Return Values
  • num [INTEGER]: number of OpenGL extensions

    Code sample :

    num_extensions = gh_renderer.get_num_opengl_extensions()


    gh_renderer.get_opengl_extension

    Description
    Returns the name of a particular OpenGL extension.

    Languages: Lua - Python

    Parameters
  • index [INTEGER]: index of the OpenGL extension: from 0 to get_num_opengl_extensions()-1.

    Return Values
  • name [STRING]: OpenGL extension name

    Code sample :

    index = 0
    gl_extension = gh_renderer.get_opengl_extension(index)


    gh_renderer.check_opengl_extension

    Description
    Checks if a particular OpenGL extension is exposed.

    Languages: Lua - Python

    Parameters
  • extension_name [STRING]: name of the extension.

    Return Values
  • name [STRING]: OpenGL extension name

    Code sample :

    if (gh_renderer.check_opengl_extension("GL_ARB_compute_shader") == 1) then
    -- OpenGL 4.3 compute shaders are supported.
    end


    gh_renderer.set_texture2d_state

    Description
    Enables or disable the texturing state of the fixed pipeline.

    Languages: Lua - Python

    Parameters
  • state [INTEGER]: enabled (1) or disabled (0).

    Code sample :

    gh_renderer.set_texture2d_state(state)


    gh_renderer.set_texture2d_state_ptr

    Description
    Enables or disable the texturing state of the fixed pipeline.

    Languages: Lua - Python

    Parameters
  • R_ptr [POINTER]: pointer on the current renderer.
  • state [INTEGER]: enabled (1) or disabled (0).

    Code sample :

    gh_renderer.set_texture2d_state_ptr(R_ptr, state)


    gh_renderer.display_progress_bar

    Description
    Renders a progress bar. The progress bar percent is set with gh_utils.set_progress_bar_percent(). Both functions can be used in an INIT script to draw a progress bar while loading data.

    Languages: Lua - Python

    Parameters
  • percent [REAL]: size of the progress bar: 100% means the window width.

    Code sample :

    gh_utils.set_progress_bar_percent(20)
    gh_renderer.display_progress_bar()
    ...
    ... do some stuff
    ...
    gh_utils.set_progress_bar_percent(60)
    gh_renderer.display_progress_bar()
    ...
    ... do some stuff
    ...
    gh_utils.set_progress_bar_percent(100)
    gh_renderer.display_progress_bar()



    gh_renderer.atomic_counter_create_buffer

    Description


    Languages: Lua - Python

    Parameters
  • num_counters [INTEGER]: number of counters.
  • buffer_usage [INTEGER]: buffer usage.
  • binding_point_index [INTEGER]: binding point index in OpenGL buffers pool.

    Return Values
  • ac_buffer [INTEGER]: atomic counter buffer

    Code sample :

    if (gh_renderer.check_opengl_extension("GL_ARB_shader_atomic_counters") == 1) then
    -- OpenGL 4.2 atomic counters are supported.

    local BUFFER_OBJECT_USAGE_STATIC_READ = 2
    local BUFFER_OBJECT_USAGE_DYNAMIC_WRITE = 3
    local BUFFER_OBJECT_USAGE_DYNAMIC_READ = 4
    local BUFFER_OBJECT_USAGE_STREAM_WRITE = 5
    local BUFFER_OBJECT_USAGE_STREAM_READ = 6
    local ac_buffer_usage = BUFFER_OBJECT_USAGE_DYNAMIC_WRITE
    local ac_binding_point_index = 0
    ac_buffer = gh_renderer.atomic_counter_create_buffer(1, ac_buffer_usage, ac_binding_point_index)

    gh_renderer.atomic_counter_buffer_bind(ac_buffer)
    gh_renderer.atomic_counter_set_value(ac_buffer, 0, 0)

    end


    gh_renderer.atomic_counter_create_buffer

    Description


    Languages: Lua - Python

    Parameters
  • num_counters [INTEGER]: number of counters.
  • buffer_usage [INTEGER]: buffer usage.
  • binding_point_index [INTEGER]: binding point index in OpenGL buffers pool.

    Return Values
  • ac_buffer [INTEGER]: atomic counter buffer

    Code sample :

    if (gh_renderer.check_opengl_extension("GL_ARB_shader_atomic_counters") == 1) then
    -- OpenGL 4.2 atomic counters are supported.

    local BUFFER_OBJECT_USAGE_STATIC_READ = 2
    local BUFFER_OBJECT_USAGE_DYNAMIC_WRITE = 3
    local BUFFER_OBJECT_USAGE_DYNAMIC_READ = 4
    local BUFFER_OBJECT_USAGE_STREAM_WRITE = 5
    local BUFFER_OBJECT_USAGE_STREAM_READ = 6
    local ac_buffer_usage = BUFFER_OBJECT_USAGE_DYNAMIC_WRITE
    local ac_binding_point_index = 0
    ac_buffer = gh_renderer.atomic_counter_create_buffer(1, ac_buffer_usage, ac_binding_point_index)

    gh_renderer.atomic_counter_buffer_bind(ac_buffer)
    gh_renderer.atomic_counter_set_value(ac_buffer, 0, 0)

    --
    -- do some rendering
    --

    gh_renderer.atomic_counter_buffer_bind(ac_buffer)
    local counter_value = gh_renderer.atomic_counter_get_value(ac_buffer, 0)
    end


    gh_renderer.atomic_counter_kill_buffer

    Description


    Languages: Lua - Python

    Parameters
  • ac_buffer [INTEGER]: atomic counter buffer identifier.

    Code sample :

    gh_renderer.atomic_counter_kill_buffer(ac_buffer)


    gh_renderer.atomic_counter_buffer_bind

    Description


    Languages: Lua - Python

    Parameters
  • ac_buffer [INTEGER]: atomic counter buffer identifier.

    Code sample :

    gh_renderer.atomic_counter_buffer_bind(ac_buffer)


    gh_renderer.atomic_counter_set_value

    Description


    Languages: Lua - Python

    Parameters
  • ac_buffer [INTEGER]: atomic counter buffer identifier.
  • value [INTEGER]: new counter value.
  • index [INTEGER]: index of the value in the atomic counter buffer.

    Code sample :

    gh_renderer.atomic_counter_set_value(ac_buffer, value, index)


    gh_renderer.atomic_counter_get_value

    Description


    Languages: Lua - Python

    Parameters
  • ac_buffer [INTEGER]: atomic counter buffer identifier.
  • index [INTEGER]: index of the value in the atomic counter buffer.

    Return Values
  • value [INTEGER]: value of the atomic counter

    Code sample :

    value = gh_renderer.atomic_counter_get_value(ac_buffer, index)


    gh_renderer.set_virtual_screen

    Description
    Sets the current virtual screen (Mac OS X only).

    Languages: Lua - Python

    Parameters
  • screen [INTEGER]: current virtual screen

    Code sample :

    gh_renderer.set_virtual_screen(screen)


    gh_renderer.get_virtual_screen

    Description
    Gets the current virtual screen (Mac OS X only).

    Languages: Lua - Python

    Return Values
  • screen [INTEGER]: current virtual screen

    Code sample :

    screen = gh_renderer.get_virtual_screen(ac_buffer, index)


    gh_renderer.get_num_virtual_screens

    Description
    Gets the number of virtual screens (Mac OS X only).

    Languages: Lua - Python

    Return Values
  • num_screens [INTEGER]: number of virtual screens

    Code sample :

    num_screens = gh_renderer.get_num_virtual_screens()


    gh_renderer.update_virtual_screen

    Description
    Updates the virtual screen. Call this function after a change of virtual screen (Mac OS X only).

    Languages: Lua - Python

    Code sample :

    gh_renderer.update_virtual_screen()





  • (C)2012-2013 Geeks3D