-
I am writing a small 2D game framework just for fun and I'm implementing the core game loop. I am considering switching from pure OpenGL to bgfx because I want to be able to target multiple rendering backends easily, so I'm a beginner and sorry for the noob question. I need some clarification on how threads are working in bgfx and if my idea can be implemented in bgfx. I'll explain what I mean. Right now my application is single threaded and consists of 150k bunnies (a 2d texture) that move and bounce inside a 800x450 rectangle. The game loop goes like this:
The two costly operations are the bunny update logic and rendering. What I want to do is to parallelize those operations in two different threads like this:
So basically, both render and logic threads run independently, but they sync when the logic has produced a new vertex buffer or the render tells the logic he's done (depending on who completes its task first) Of course I won't create a new vertex buffer for the bunnies every frame, I was thinking like swapping between two preallocated buffers and use only one at a time. Is something like this feasible in bgfx? If so, how? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
It already works like this. See: https://bkaradzic.github.io/bgfx/internals.html bgfx API is declarative, when you call it, it just records what needs to be done. Once you call If you want to submit from multiple threads you need to use |
Beta Was this translation helpful? Give feedback.
-
It's created automatically if you don't call |
Beta Was this translation helpful? Give feedback.
It already works like this. See: https://bkaradzic.github.io/bgfx/internals.html
bgfx API is declarative, when you call it, it just records what needs to be done. Once you call
bgfx::frame
work is getting done on other thread.If you want to submit from multiple threads you need to use
bgfx::Encoder
API: https://bkaradzic.github.io/bgfx/bgfx.html#encoder