elm-explorations / webgl

Functional rendering with WebGL in Elm
https://package.elm-lang.org/packages/elm-explorations/webgl/latest/
BSD 3-Clause "New" or "Revised" License
116 stars 17 forks source link

Dynamic mesh support #7

Closed MartinSStewart closed 5 years ago

MartinSStewart commented 5 years ago

Hi, I'm interested in rendering circuit boards similar to this https://3c1703fe8d.site.internapcdn.net/newman/gfx/news/hires/2009/runningelect.jpg

Ideally I'd generate one large mesh for the entire circuit board. The layout of the circuit board isn't known at compile time though and as I understand it, all meshes need to be known at compile time, as generating them in the view causes a memory leak.

It seems like currently the best I can do then is have a rectangle and circle mesh at compile time and use a bunch of them to render the entire circuit board.

As a test to see if it would be feasible to do this I ran a quick benchmark by drawing the same circle mesh with varying transformation matrices. Around 600 circles per frame was the limit before the frame rate would start to drop. This seems too low to achieve what I'm aiming for.

So if possible, it would be great to support creating new meshes after compile time.

Edit: I realized that meshes can still be created during runtime so long as they are stored in the model and not modified. This works well enough for my purposes though it would still be nice to have some way to free/modify existing meshes.

w0rm commented 5 years ago

Hi @MartinSStewart I just opened a PR https://github.com/elm-explorations/webgl/pull/9 that should free the meshes if they are not referenced anymore.

I don't think we can easily allow modifications, because Elm is a pure language.

MartinSStewart commented 5 years ago

Thanks, fixing the memory leak is the most important part for me.

w0rm commented 5 years ago

The change is in master, hopefully will be published in a few days.

w0rm commented 5 years ago

@MartinSStewart according to https://stackoverflow.com/questions/31250052/are-webgltextures-garbage-collected this is not fully fixed. This approach should be fine for occasional changes but not for constantly creating new meshes/textures every frame which is something that you probably shouldn't be doing anyway.

MartinSStewart commented 5 years ago

Ah, that's a shame. Still, being able to create new meshes occasionally is useful.