polar-engine / hs-polar

Polar Game Engine is a modern, safe game engine written in Haskell.

Home Page:http://polarengine.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Store vertices in efficient data structure

ori-sky opened this issue · comments

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 of Storable.
  • 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 and free or perhaps even with the Foreign.Marshal.Pool module could provide a significant performance boost in this area, as well as other areas of the engine.

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.