liquidev / aglet

A safe, high-level, optimized OpenGL wrapper and context manager.
MIT License
29 stars 2 forks source link

Uniform buffer objects/shader storage buffer objects #6

Open liquidev opened 4 years ago

liquidev commented 4 years ago

Pretty self-explanatory. The problem is that the in-memory layout is driver-specific, and the std140 layout does not match the alignment rules of Nim objects, which makes sending data to the graphics card quite inconvenient. This could probably be solved using macros and generics, but I'm not sure about the API. The current uniforms macro could play well with this, for example:

type
  MyData = object
    a, b, c: Vec3f

let
  ubo = win.newUniformBuffer(MyData())
  u = uniforms {
    MyUniformBlock: ubo,
  }

The problem I'm facing is that alignment problem; I would have to read the spec (which is not a problem) but generating all the code to align everything properly would be quite a challenge. Another thing is that uniform blocks support dynamic arrays. That's fine and dandy, but how would we solve this syntactically? Use a seq or some special storage type?

These are all things for extra consideration, and I will take care of that when I need it or somebody asks for it.