Interface IntShader

  • All Superinterfaces:
    com.badlogic.gdx.utils.Disposable
    All Known Implementing Classes:
    AtmosphereShader, BaseIntShader, DefaultIntShader, DepthIntShader, GroundShader, RelativisticShader, TessellationShader

    public interface IntShader
    extends com.badlogic.gdx.utils.Disposable
    Interface which is used to render one or more IntRenderables.

    A IntShader is responsible for the actual rendering of an IntRenderable. Typically, when using OpenGL ES 2.0 or higher, it encapsulates a ShaderProgram and takes care of all OpenGL calls necessary to render the IntRenderable. When using OpenGL ES 1.x it takes care of the fixed pipeline.

    To start rendering the begin(Camera, RenderContext) method must be called. After which the end() method must be called to stop rendering. In between one or more calls to the render(IntRenderable) method can be made to render a IntRenderable. The render(IntRenderable) method must not be called before a call to begin(Camera, RenderContext) or after a call to end(). Each IntShader needs exclusive access to the OpenGL state and RenderContext between the begin(Camera, RenderContext) and end() methods, therefore only one shader can be used at a time (they must not be nested).

    A specific IntShader instance might be (and usually is) dedicated to a specific type of IntRenderable. For example it might use a ShaderProgram that is compiled with uniforms (shader input) for specific Attribute types. Therefore the canRender(IntRenderable) method can be used to check if the IntShader instance can be used for a specific IntRenderable . Rendering a IntRenderable using a IntShader for which canRender(IntRenderable) returns false might result in unpredicted behavior or crash the application.

    To manage multiple shaders and create a new shader when required, a ShaderProvider can be used. Therefore, in practice, a specific IntShader implementation is usually accompanied by a specific ShaderProvider implementation (usually extending BaseShaderProvider).

    When a IntShader is constructed, the init() method must be called before it can be used. Most commonly, the init() method compiles the ShaderProgram, fetches uniform locations and performs other preparations for usage of the IntShader. When the shader is no longer needed, it must disposed using the Disposable.dispose() method. This, for example, disposed (unloads for memory) the used ShaderProgram.

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void begin​(com.badlogic.gdx.graphics.Camera camera, com.badlogic.gdx.graphics.g3d.utils.RenderContext context)
      Initializes the context for exclusive rendering by this shader.
      boolean canRender​(IntRenderable instance)
      Checks whether this shader is intended to render the IntRenderable.
      int compareTo​(IntShader other)
      Compare this shader against the other, used for sorting, light weight shaders are rendered first.
      void end()
      Cleanup the context so other shaders can render.
      void init()
      Initializes the IntShader, must be called before the IntShader can be used.
      void render​(IntRenderable renderable)
      Renders the IntRenderable, must be called between begin(Camera, RenderContext) and end().
      • Methods inherited from interface com.badlogic.gdx.utils.Disposable

        dispose
    • Method Detail

      • init

        void init()
        Initializes the IntShader, must be called before the IntShader can be used. This typically compiles a ShaderProgram, fetches uniform locations and performs other preparations for usage of the IntShader.
      • compareTo

        int compareTo​(IntShader other)
        Compare this shader against the other, used for sorting, light weight shaders are rendered first.
      • canRender

        boolean canRender​(IntRenderable instance)
        Checks whether this shader is intended to render the IntRenderable. Use this to make sure a call to the render(IntRenderable) method will succeed. This is expected to be a fast, non-blocking method. Note that this method will only return true if it is intended to be used. Even when it returns false the IntShader might still be capable of rendering, but it's not preferred to do so.
        Parameters:
        instance - The renderable to check against this shader.
        Returns:
        true if this shader is intended to render the IntRenderable, false otherwise.
      • begin

        void begin​(com.badlogic.gdx.graphics.Camera camera,
                   com.badlogic.gdx.graphics.g3d.utils.RenderContext context)
        Initializes the context for exclusive rendering by this shader. Use the render(IntRenderable) method to render a IntRenderable. When done rendering the end() method must be called.
        Parameters:
        camera - The camera to use when rendering
        context - The context to be used, which must be exclusive available for the shader until the call to the end() method.