LLGR, a Low-Level Graphics Library, is designed to be an output-only API for rendering with WebGL or OpenGL, and to support picking, selection highlights, and translucency. Shadows are also desirable but will be added later. Also support for various optimizations, e.g., instancing and level-of-detail, is provided. Except for the rendering code, it is a thin-layer over the underlying graphics library, and exposes shader programs, program uniforms, vertex attributes, and vertex attribute buffers. Additional OpenGL concepts, eg., uniform buffers, may be exposed later.
To display the contents of those buffers, a flat scene graph of objects is used. Objects contain references to a particular shader program, a transformation matrix, and the attributes needed to draw the object. All attributes refer to buffers, but should refer to a singleton buffer when the value of the attribute is constant within the object. Objects that only differ only by their singleton attributes can be automatically instanced for faster drawing.
The default rendering code expects various uniforms and attributes to be present, and they are documented below.
A reasonable scenario would be to:
- Instantiate the shader programs with create_program()
- Instantiate the vertex coordinate (and vertex index) buffers with create_buffer()
- Instantiate other vertex attributes, such as color, as buffers with create_buffer() or singletons with create_singleton()
- For each object create a std::vector describing its attributes with AttributeInfo and instantiate it with create_object()
- Set shader program uniforms with set_uniform() and set_uniform_matrix()
- render()
All data types are limited to 32-bit quantities or less. In the future, we might allow 64-bit quantities for desktop OpenGL.
For C++, Bytes is just ‘void *’. It is a separate type, so a Python wrapper generator can easily find byte arguments.
API client provided identifier. Negative values are reserved for internal use and should not appear in client code. Zero has special meaning depending on where it is used, so all user-generated content should have positive identifiers.
Buffer array types:
Buffer data types:
Shader variable types:
Drawing primitive types:
A std::vector of object identifiers
Shaders problems need to be compatible with the rendering code. Since the rendering code may change, or there might be more than one way to render objects, those requirements are documented below with the rendering code.
Managing shader programs is expected to be done by a library layered on top of llgr.
| Parameters: |
|
|---|
To reuse a program_id, just recreate it.
| Parameters program_id: | |
|---|---|
| existing program identifier | |
Remove resources associated with program identifier.
Remove all existing programs.
| Parameters: |
|
|---|
Template versions for all of the shader variable types, where the type and size are inferred from the data argument’s type.
Buffers contain coordinate and attribute data.
| Parameters: |
|
|---|
Create buffer data.
| Parameters: |
|
|---|
TODO: future function to update column of existing buffer
| Parameters buffer_id: | |
|---|---|
| existing buffer identifier | |
Remove resources associated with buffer identifier.
Remove all existing buffers.
A matrix_id of zero is always the identity matrix. Matrices are a separate kind of data
| Parameters: |
|
|---|
| Parameters matrix_id: | |
|---|---|
| existing matrix identifier | |
Remove resources associated with matrix identifier.
Remove all existing matrices.
name of attribute
Byte offset into data for first attribute value
Byte stride through data to next attribute value
Number of data type (1-4)
For integer types, true if attribute values should be normalized to 0.0-1.0
std::vector<AttributeInfo>
Create an alias for a vertex attribute name. This can be used to make common object creation code work with different shader programs, or hide differences between different versions of OpenGL. To remove an alias, either set it to itself or the empty string.
For example, the built-in primitives use “position” and “normal”, but for OpenGL 2, you should minimally:
llgr.set_attribute_alias("position", "gl_Vertex")
Since in OpenGL 2, glVertex has to be called instead of using a vertex attribute, but the normal could be be given either as a vertex attribute or with glNormal depending on the shader program.
| Parameters: |
|
|---|
| Parameters obj_id: | |
|---|---|
| existing object identifier | |
Remove resources associated with object identifier.
Remove all existing objects.
Don’t draw given objects.
Draw given objects (default).
Object is transparent, so draw it with extra code.
Object is opaque, so draw it normally (default).
Add objects to selection set.
Remove objects from selection set.
Clear selection set.
Level-of-detail primitives. TODO: implement LOD
Add sphere.
| Parameters: |
|
|---|
The default vertex attribute names are “position” and “normal”. See set_attribute_alias() to change them.
Add cylinder.
| Parameters: |
|
|---|
The default vertex attribute names are “position” and “normal”. See set_attribute_alias() to change them.
Remove all existing primitive objects and associated internal data.