Class GlslShaderGenerator

java.lang.Object
com.codename1.gpu.GlslShaderGenerator

public final class GlslShaderGenerator extends Object

Generates portable GLSL ES 1.00 vertex and fragment shader source for a given Material and VertexFormat. This is the "engine-managed shader" code path shared by every OpenGL ES class backend (Android OpenGL ES and the browser's WebGL, which share the same shading language). Applications never call this directly; it exists so the platform backends do not each reimplement shader emission. The iOS backend has an equivalent Metal generator.

The generated programs use a fixed naming contract that backends rely on when binding attributes and uniforms:

  • attributes: a_position (vec3), a_normal (vec3), a_texcoord (vec2)
  • uniforms: u_mvp, u_model, u_normalMatrix (mat4); u_color (vec4); u_texture (sampler2D); u_lightDir, u_lightColor, u_ambient, u_eye (vec3); u_shininess (float)
  • Field Details

  • Constructor Details

    • GlslShaderGenerator

      public GlslShaderGenerator(Material material, VertexFormat format)

      Generates the shader pair for a material and vertex layout.

      Parameters
      • material: the material describing the lighting model and inputs

      • format: the mesh vertex layout

  • Method Details

    • getVertexSource

      public String getVertexSource()
      Returns the generated vertex shader source.
    • getFragmentSource

      public String getFragmentSource()
      Returns the generated fragment shader source.