Caching vertex array object in Haskell on rendering

Ok, the title is awful, but I'm not sure how else to convey the problem at a glance.

Currently, in my display callback when rendering using OpenGL, it is possible to call a function called render

for different types of geometry, which are stored as lists of vertices, normals and / or texture coordinates (as one pair or triple, whichever of which is used).

When I do the rendering, I align this like [GLfloat]

to pass it to VBO and VAO. Then I store the VAO and do this. This is usually done during the initialization phase and then the transformation, etc. Applied in the display callback, but if the user wanted to do it in the display callback, it aligns the geometry EVERY time, and I tweak the VBO, VAO and attribute variables that the pass ever threw. This obviously makes it very slow if there are any objects (geometry) in the display callback.

What I want to do is if it is an object, flatten it, etc. in VAO and then next time it is encountered use VAO. I have a constructor that takes VAOs as an argument of the same type, so it can be conveniently replaced.

compile

does the same as render, except it returns a CompiledDrawable

which contains a VAO.

I want to use something like:

getObject :: Drawable -> IORef Drawable
getObject drawable = unsafePerformIO $ compile drawable  

      

The only problem is that not only one of them, I have to be able to do this for all my objects and have my own links. Any ideas?

+3


source to share





All Articles