Module Lit.Prog

module Prog: sig .. end
GPU programs

A GPU program is a set of linked shaders. Each shader defines a transformation that is applied on the rendering pipeline that transforms the vertex stream to fragments. Programs can be shared among effects.



Source locations

Depending on the GPU driver a renderer should be able to report precise source file locations on compilation errors.

If shader sources are loaded from external sources, specify their provenance with the loc argument of Lit.Prog.insert and Lit.Prog.shader.

If they are written directly in the OCaml source code files, compile them with -g. For errors to be reported without offset miscalculations you need to open the source string on the line of the call to Lit.Prog.insert or Lit.Prog.shader. For example:

Prog.shader `Vertex " <--- This is important
  ... "

otherwise the reported lines may be off.

type loc = [ `Loc of string * int | `Unknown ] 
The type for source locations. File name and one-based line number or unknown.
val pp_loc : Format.formatter -> loc -> unit
pp_loc ppf loc prints an unspecified representation of loc on ppf.

Inserts

Inserts can be used for source level, verbatim, textual inclusion (they want to be called includes but that's an OCaml keyword). They are a very primitive form of code reuse.

type insert 
The type for textual source inserts.
val insert : ?loc:loc -> string -> insert
insert ~loc:(`Loc (f, l)) src is the insert made of src located in file f at line l. If loc is unspecified the location of the function call is used provided the program is compiled with -g.

Shaders


type lang = [ `GLSL of int | `GLSL_ES of int ] 
The type for shading language version and dialects. Use 150 for 1.50.
type shader_stage = [ `Compute
| `Fragment
| `Geometry
| `Tess_control
| `Tess_evaluation
| `Vertex ]
Shader stages. Note that not all renderers support all shaders stages, see Lit.Renderer.Cap.shader_stages.
val pp_shader_stage : Format.formatter -> shader_stage -> unit
pp_shader_stage ppf stage prints an unspecified representatino of stage on ppf.
type shader 
The type for shaders.
val shader : ?lang:lang ->
?loc:loc ->
?inserts:insert list ->
shader_stage -> string -> shader
shader ~loc:(`Loc (f, l)) ~inserts stage src is the shader for stage stage made by pre-concatening the inserts inserts to src located in file f at line l. If loc is unspecified the location of the function call is used provided the program is compiled with -g.
val stage : shader -> shader_stage
stage s is the shader stage of s.
val loc : shader -> loc
loc s is the location of shader s.
val lang : shader -> lang option
lang s is the shading language for shader s.
type source = string * (int * string) list 
The type for sources. The actual source and a map from file ids to file names to recognize the #line directives in the source.
val source : ?lang:lang -> shader -> source
source ?lang s is the source of shader s as will be given to the GPU.

Programs


type t = Lit.prog 
The type for programs.
val create : ?name:string -> ?uset:Lit.Uniform.set -> shader list -> Lit.prog
create uset shaders is the program made up of shaders, a list in which each shader_kind should appear at most once. uset define default uniform values (defaults to Lit.Uniform.empty).
val name : Lit.prog -> string
name p is the program name.
val uniforms : Lit.prog -> Lit.Uniform.set
uniforms p are the default uniforms of p.
val shaders : Lit.prog -> shader list
shaders p is the shaders of p.