io7m
io7m-jcanephora 0.45.0
1.1
Orientation
1.1.1
Overview
1
The jcanephora package implements a set of abstractions over OpenGL with the intention of providing an API that enforces program correctness statically. The OpenGL API is extremely error prone, but thankfully many of the problems can be alleviated with the simple application of static types. Where the Java type system is too weak to give static guarantees, dynamic checks are used to prevent silent failure.
1.1.2
Correctness
1
Most functions in OpenGL return integers (type int). The glCreateShader() function, for example, returns an int regardless of whether the function is creating a fragment shader or a vertex shader. Obviously, returning a different type depending on whether a fragment shader or a vertex shader was requested would require a dependent type system. As Java clearly does not have dependent types, the jcanephora package provides a shaderCompileVertex() function that returns a value of type JCGLVertexShaderType and a shaderCompileFragment() function that returns a value of type JCGLFragmentShaderType, eliminating at compile-time the possibility of confusing the two. The package takes a similar approach to static safety throughout.
2
All implementations of the jcanephora API are run through a large battery of tests to ensure consistent semantics.
1.1.3
Simplicity
1
The jcanephora package attempts to provide abstractions that are as minimal as possible. It should be possible for any experienced OpenGL programmer to use the package without having to learn new concepts or fight a complicated class hierarchy. The idea is to provide static type safety in as simple a manner as possible.
1.1.4
Compatibility
1
The jcanephora exposes interfaces that represent the OpenGL 3.3 core API.
1.1.5
Performance
1
OpenGL programs often have high performance requirements. The jcanephora API abstractions attempt to be as cheap as possible. Operations that allocate memory or perform potentially expensive operations are clearly marked. Emphasis is placed on writing code paths that generate little in the way of garbage to be collected, reducing GC pressure and improving realtime performance. Many potentially expensive queries (such as a request for the available number of texture units) are requested eagerly and cached, in order to reduce the number of OpenGL calls required at "render time". The package tracks OpenGL state locally to avoid redundant OpenGL calls.