Store vertices in efficient data structure
ori-sky opened this issue · comments
Ori Sky commented
The example vertices, hard-coded in the renderer, are currently implemented with the type [GLfloat]
. Whilst this makes it easy to work with the vertices, it also makes it more difficult in general for a number of reasons.
- The ideal data structure should represent a sequence of vertices and not a sequence of vertex components. For example,
[(GLfloat, GLfloat, GLfloat)]
would be better in this regard. - OpenGL requires the vertices to be passed by
Ptr
so their data structure must implement an instance ofStorable
. - Using pure data structures such as a list will result in terrible upload performance for the previous reason, as they will require the data to be marshalled whenever it needs to be passed to OpenGL (i.e. whenever it needs to be uploaded or reuploaded). Allocating dynamic memory using
malloc
andfree
or perhaps even with theForeign.Marshal.Pool
module could provide a significant performance boost in this area, as well as other areas of the engine.
Ori Sky commented
The pooledNew
function looks pretty useful; however, I'll need to check whether or not data can easily be freed from the pool using free
or a similar function.