Game Development Community

Replace GFX with BGFX

by Andrew Mac · in Torque 3D Professional · 10/29/2014 (4:53 pm) · 3 replies

It's time for another one of those threads where I give you all half finished code that I most likely won't continue to work on. Who doesn't love that?

Story Time
I was looking for a lightweight rendering library to try to build a little experiment I wanted to do and I stumbled across a library called bgfx (link: github.com/bkaradzic/bgfx). When I started playing around with it I actually found it was too lightweight for what I needed. Then it occurred to me that this would be a fantastic library to replace GFX in torque with. It would pave the way for Torque to hit all kinds of platforms. Bonus: it offloads the work of maintaining the graphics API support onto the creator of bgfx, Branimir Karadzic.

Advantages
To quote the github page:
Quote:
Supported rendering backends:

Direct3D 9
Direct3D 11
OpenGL 2.1
OpenGL 3.1+
OpenGL ES 2
OpenGL ES 3.1

Supported platforms:

Android (14+)
asm.js/Emscripten (1.25.0)
iOS
Linux
Native Client (37)
OSX (10.9)
RaspberryPi
Windows (XP, Vista, 7, 8, 10)

Its internally multithreaded (when it's viable on the platform) allowing it to run freely without being stalled by torque.

It has a glsl-like universal shader language that compiles into whatever platform you need it for. Write once for shaders. This removes the need for shadergen. Less code to maintain.

Disadvantages
There's a lot of work to do, and all the shaders would have to be rewritten. There are also a few hurdles in matching up torques rendering methods with how bgfx likes things done. Nothing that can't be overcome, but some things will have to be adapted or rewritten.

The material system relies pretty heavily on shadergen so it would basically have to be gutted, or shadergen would have to be adapted to tie directly into his shader compiler.

Status
I got it in there. I built it as a GFX device though I planned to eventually make it become GFX. It works for all the 2D and GUI stuff, but I shelved the project before I got very far into the 3D side of things. I did get support for his shader compiler working too. The shaders used to display the GUI are written in his shader language and compile on build.

One interesting thing I did was start to integrate a vector graphics library he has working in bgfx called nanovg. This allowed me to do anti-aliased fonts and a few other neat GUI tricks. I replaced torques font renderer with calls to nanovg and the console runs much faster :D I like the smooth anti-aliased fonts too (though some people I showed didn't like them.. I'm lookin' at you TRON). I planned to eventually replace all the DrawUtil calls with calls to nanovg, and expand it with further vector graphics functionality.

Screenshots
The little colored thing was me starting to test 3D projection stuff:
i.imgur.com/sVkclrd.pngi.imgur.com/QV5wtP6.png


Links
The Code: github.com/andr3wmac/Torque3D/tree/bgfx
bgfx: github.com/bkaradzic/bgfx

What do we do with this?
It's not usable for a project at the moment, so probably nothing. I do hope someone is brave enough to pick up the project. I may still try to work on it from time to time, but I can't really put in the hours on it anymore. I figured the least I could do is show you all what I found and release the code in case anyone wants to pursue it. I was exchanging emails with the author during development, he's a real nice guy. He wanted to me let you all know if anyone decides to continue it he's available to offer any advice/assistance that he can.

#1
10/29/2014 (7:59 pm)
Having Vector graphics for Gui (and more!) seems to me like a good thing to pursue.
#2
10/30/2014 (1:58 am)
Very interesting Andrew. If I had the time (which I unfortunately don't)I would give it a crack. Hopefully someone does.
#3
10/30/2014 (8:27 am)
it is impressive but I shamelessly ignorant to help the though as that is realize into reality :(