2012-04-04 07:30:07 +04:00
|
|
|
bgfx
|
|
|
|
====
|
|
|
|
|
2012-11-26 06:24:50 +04:00
|
|
|
What is it?
|
|
|
|
-----------
|
|
|
|
|
2012-06-28 07:49:45 +04:00
|
|
|
Cross-platform rendering library.
|
2012-06-02 21:59:47 +04:00
|
|
|
|
2012-11-11 07:59:23 +04:00
|
|
|
Supported rendering backends:
|
2012-06-02 21:59:47 +04:00
|
|
|
|
2012-11-11 07:59:23 +04:00
|
|
|
* OpenGL 2.1
|
|
|
|
* OpenGL ES 2
|
|
|
|
* OpenGL ES 3
|
|
|
|
* Direct3D 9
|
|
|
|
* Direct3D 11
|
|
|
|
|
|
|
|
Platforms:
|
|
|
|
|
|
|
|
* Windows
|
|
|
|
* Linux
|
|
|
|
* Android
|
|
|
|
* Native Client
|
|
|
|
* JavaScript (via Emscripten)
|
2012-04-04 07:30:07 +04:00
|
|
|
|
2012-06-28 07:49:45 +04:00
|
|
|
Dependencies
|
|
|
|
------------
|
|
|
|
|
|
|
|
[https://github.com/bkaradzic/bx](https://github.com/bkaradzic/bx)
|
|
|
|
|
|
|
|
Optional:
|
|
|
|
[https://github.com/mendsley/tinystl](https://github.com/mendsley/tinystl)
|
|
|
|
|
2012-11-05 03:26:27 +04:00
|
|
|
Building
|
|
|
|
--------
|
|
|
|
|
2012-11-12 06:25:47 +04:00
|
|
|
### Prerequisites
|
2012-11-12 06:19:42 +04:00
|
|
|
|
2012-11-12 06:25:47 +04:00
|
|
|
Premake 4.4 beta4
|
2012-11-12 06:19:42 +04:00
|
|
|
[http://industriousone.com/premake/download](http://industriousone.com/premake/download)
|
|
|
|
|
2012-11-12 06:25:47 +04:00
|
|
|
GNU make
|
|
|
|
Windows users download GNU make utility from:
|
2012-11-12 06:19:42 +04:00
|
|
|
[http://gnuwin32.sourceforge.net/packages/make.htm](http://gnuwin32.sourceforge.net/packages/make.htm)
|
|
|
|
|
|
|
|
### Getting source
|
2012-11-05 03:26:27 +04:00
|
|
|
|
|
|
|
git clone git://github.com/bkaradzic/bx.git
|
|
|
|
git clone git://github.com/bkaradzic/bgfx.git
|
|
|
|
cd bgfx
|
|
|
|
make
|
|
|
|
|
2012-11-12 06:19:42 +04:00
|
|
|
After calling make, .build/projects/* directory will be generated. All
|
|
|
|
intermediate files generated by compiler will be inside .build directory
|
|
|
|
structure. Deleting .build directory at any time is safe.
|
|
|
|
|
2012-11-26 07:21:15 +04:00
|
|
|
### Building for Linux
|
|
|
|
|
|
|
|
sudo apt-get install libgl1-mesa-dev
|
|
|
|
|
2012-11-12 06:19:42 +04:00
|
|
|
### Building for Windows
|
|
|
|
|
|
|
|
When building on Windows, you have to set DXSDK_DIR environment variable to
|
|
|
|
point to DirectX SDK directory.
|
|
|
|
|
|
|
|
setx DXSDK_DIR <path to DirectX SDK directory>
|
|
|
|
|
|
|
|
If you're building with MinGW/TDM compiler on Windows make DirectX SDK
|
|
|
|
directory link to directory without spaces in the path.
|
|
|
|
|
|
|
|
mklink /D <path to DirectX SDK directory> c:\dxsdk
|
|
|
|
setx DXSDK_DIR c:\dxsdk
|
|
|
|
|
|
|
|
### Building for Native Client (Pepper 22) on Windows
|
|
|
|
|
2012-11-26 06:24:50 +04:00
|
|
|
Download Native Client SDK from:
|
2012-11-12 06:19:42 +04:00
|
|
|
[https://developers.google.com/native-client/sdk/download](https://developers.google.com/native-client/sdk/download)
|
|
|
|
|
2012-11-12 06:25:47 +04:00
|
|
|
setx NACL <path to Native Client SDK directory>\toolchain\win_x86_newlib
|
2012-11-12 06:19:42 +04:00
|
|
|
|
|
|
|
### Building
|
2012-11-05 03:26:27 +04:00
|
|
|
|
|
|
|
Visual Studio 2008:
|
|
|
|
|
|
|
|
start .build/projects/vs2008/bgfx.sln
|
|
|
|
|
|
|
|
Linux 64-bit:
|
|
|
|
|
|
|
|
make -R linux-release64
|
|
|
|
|
|
|
|
Other platforms:
|
|
|
|
|
|
|
|
make -R <configuration>
|
|
|
|
|
2012-11-26 06:24:50 +04:00
|
|
|
Configuration is `<platform>-<debug/release><32/64>`. For example:
|
2012-11-05 03:26:27 +04:00
|
|
|
|
|
|
|
linux-release32, nacl-debug64, android-release32, etc.
|
|
|
|
|
2012-11-11 07:59:23 +04:00
|
|
|
Examples
|
|
|
|
--------
|
|
|
|
|
|
|
|
### 00-helloworld
|
|
|
|
Initialization and debug text.
|
|
|
|
|
|
|
|
### 01-cubes
|
|
|
|
Rendering simple static mesh.
|
|
|
|
|
2012-12-03 08:55:27 +04:00
|
|
|
![example-01-cubes](https://github.com/bkaradzic/bgfx/raw/master/examples/01-cubes/screenshot.png)
|
2012-12-03 08:49:04 +04:00
|
|
|
|
2012-11-11 07:59:23 +04:00
|
|
|
### 02-metaballs
|
|
|
|
Rendering with transient buffers.
|
|
|
|
|
2012-12-03 08:55:27 +04:00
|
|
|
![example-02-metaballs](https://github.com/bkaradzic/bgfx/raw/master/examples/02-metaballs/screenshot.png)
|
2012-12-03 08:49:04 +04:00
|
|
|
|
2012-11-11 07:59:23 +04:00
|
|
|
### 03-raymarch
|
|
|
|
Updating shader uniforms.
|
|
|
|
|
2012-12-03 08:55:27 +04:00
|
|
|
![example-03-raymarch](https://github.com/bkaradzic/bgfx/raw/master/examples/03-raymarch/screenshot.png)
|
2012-12-03 08:49:04 +04:00
|
|
|
|
2012-11-11 07:59:23 +04:00
|
|
|
### 04-mesh
|
2012-12-29 05:20:28 +04:00
|
|
|
Loading meshes.
|
2012-11-11 07:59:23 +04:00
|
|
|
|
2012-12-03 08:55:27 +04:00
|
|
|
![example-04-mesh](https://github.com/bkaradzic/bgfx/raw/master/examples/04-mesh/screenshot.png)
|
2012-12-03 08:49:04 +04:00
|
|
|
|
2012-11-11 07:59:23 +04:00
|
|
|
### 05-instancing
|
|
|
|
Geometry instancing.
|
|
|
|
|
2012-12-03 08:55:27 +04:00
|
|
|
![example-05-instancing](https://github.com/bkaradzic/bgfx/raw/master/examples/05-instancing/screenshot.png)
|
2012-12-03 08:49:04 +04:00
|
|
|
|
2012-11-11 07:59:23 +04:00
|
|
|
### 06-bump
|
|
|
|
Loading textures.
|
|
|
|
|
2012-12-03 08:55:27 +04:00
|
|
|
![example-06-bump](https://github.com/bkaradzic/bgfx/raw/master/examples/06-bump/screenshot.png)
|
2012-12-03 08:49:04 +04:00
|
|
|
|
2012-12-31 08:52:47 +04:00
|
|
|
### 07-callback
|
|
|
|
Implementing application specific callbacks for taking screen shots, caching
|
|
|
|
OpenGL binary shaders, and video capture.
|
|
|
|
|
2013-01-07 05:53:45 +04:00
|
|
|
### 08-update
|
|
|
|
Updating textures.
|
|
|
|
|
2012-11-26 06:24:50 +04:00
|
|
|
Internals
|
|
|
|
---------
|
|
|
|
|
|
|
|
bgfx is using sort-based draw call bucketing. This means that submition order
|
2013-01-01 09:45:05 +04:00
|
|
|
doesn't necessarily matches the rendering order, but on the low-level they
|
|
|
|
will be sorted and ordered correctly. On the high level this allows
|
|
|
|
more optimal way of submitting draw calls for all passes at one place, and on
|
|
|
|
the low-level this allows better optimization of rendering order. This sometimes
|
|
|
|
creates undesired results usually for GUI rendering, where draw order should
|
|
|
|
usually match submit order. bgfx provides way to enable sequential rendering for
|
|
|
|
these cases (see `bgfx::setViewSeq`).
|
2012-11-26 06:24:50 +04:00
|
|
|
|
2012-12-16 01:24:15 +04:00
|
|
|
Internally all low-level rendering draw calls are issued inside single function
|
2012-11-26 06:24:50 +04:00
|
|
|
`Context::rendererSubmit`. This function exist inside each renderer backend
|
|
|
|
implementation.
|
|
|
|
|
|
|
|
More detailed description of sort-based draw call bucketing can be found at:
|
|
|
|
[Order your graphics draw calls around!](http://realtimecollisiondetection.net/blog/?p=86)
|
|
|
|
|
|
|
|
Customization
|
|
|
|
-------------
|
|
|
|
|
|
|
|
By default each platform has sane default values. For example on Windows default
|
|
|
|
renderer is DirectX9, and on Linux it is OpenGL 2.1. On Windows platform all
|
|
|
|
rendering backends are available. For OpenGL ES on desktop you can find more
|
2012-12-16 01:24:15 +04:00
|
|
|
information at:-
|
|
|
|
[OpenGL ES 2.0 and EGL on desktop](http://www.g-truc.net/post-0457.html)
|
|
|
|
|
|
|
|
If you're targeting specific mobile hardware, you can find GLES support in their
|
|
|
|
official SDKs:
|
|
|
|
[Adreno SDK](http://developer.qualcomm.com/mobile-development/mobile-technologies/gaming-graphics-optimization-adreno/tools-and-resources),
|
|
|
|
[Mali SDK](http://www.malideveloper.com/),
|
|
|
|
[PowerVR SDK](http://www.imgtec.com/powervr/insider/sdkdownloads/).
|
2012-11-26 06:24:50 +04:00
|
|
|
|
2012-11-26 11:15:16 +04:00
|
|
|
All configuration settings are located inside [src/config.h](https://github.com/bkaradzic/bgfx/blob/master/src/config.h).
|
2012-11-26 06:24:50 +04:00
|
|
|
|
|
|
|
Every `BGFX_CONFIG_*` setting can be changed by passing defines thru compiler
|
|
|
|
switches. For example setting preprocessor define `BGFX_CONFIG_RENDERER_OPENGL=1`
|
|
|
|
on Windows will change backend renderer to OpenGL 2.1. on Windows. Since
|
|
|
|
rendering APIs are platform specific, this obviously won't work nor make sense
|
|
|
|
in all cases. Certain platforms have only single choice, for example the Native
|
|
|
|
Client works only with OpenGL ES 2.0 renderer, using anything other than that
|
|
|
|
will result in build errors.
|
|
|
|
|
|
|
|
Tools
|
|
|
|
-----
|
|
|
|
|
|
|
|
### Shader Compiler (shaderc)
|
|
|
|
|
|
|
|
bgfx cross-platform shader language is based on GLSL syntax. It's uses ANSI C
|
|
|
|
preprocessor to transform GLSL like language syntax into HLSL. This technique
|
|
|
|
has certain drawbacks, but overall it's simple and allows quick authoring of
|
|
|
|
cross-platform shaders.
|
|
|
|
|
|
|
|
### Texture Compiler (texturec)
|
|
|
|
|
|
|
|
### Geometry Compiler (geometryc)
|
|
|
|
|
|
|
|
Todo
|
|
|
|
----
|
|
|
|
|
|
|
|
- Multiple render targets.
|
|
|
|
- BlendFuncSeparate and BlendEquationSeparate.
|
|
|
|
- Copy from texture to texture.
|
|
|
|
- Occlusion queries.
|
|
|
|
- OSX and iOS platforms.
|
|
|
|
- DX11: MSAA.
|
|
|
|
- GL: MSAA.
|
|
|
|
- GL: ARB_vertex_array_object + OES_vertex_array_object.
|
|
|
|
|
2012-06-23 22:44:22 +04:00
|
|
|
Notice
|
|
|
|
------
|
|
|
|
|
|
|
|
This is alpha software, and it lacks documentation and examples. If you're
|
|
|
|
interested to use it in your project, please let me know.
|
|
|
|
|
2012-04-04 07:30:07 +04:00
|
|
|
Contact
|
|
|
|
-------
|
|
|
|
|
2012-06-02 21:59:47 +04:00
|
|
|
[@bkaradzic](https://twitter.com/bkaradzic)
|
|
|
|
http://www.stuckingeometry.com
|
2012-04-04 07:30:07 +04:00
|
|
|
|
2012-06-02 21:59:47 +04:00
|
|
|
Project page
|
|
|
|
https://github.com/bkaradzic/bgfx
|
2012-04-04 07:30:07 +04:00
|
|
|
|
2012-11-26 06:24:50 +04:00
|
|
|
3rd Party Libraries
|
|
|
|
-------------------
|
|
|
|
|
2013-01-01 09:45:05 +04:00
|
|
|
All required 3rd party libraries are included in bgfx repository in [3rdparty/](https://github.com/bkaradzic/bgfx/tree/master/3rdparty)
|
2012-11-26 06:24:50 +04:00
|
|
|
directory.
|
|
|
|
|
|
|
|
### edtaa3 (MIT)
|
|
|
|
|
|
|
|
Contour Rendering by Distance Fields
|
|
|
|
|
|
|
|
https://github.com/OpenGLInsights/OpenGLInsightsCode/tree/master/Chapter%2012%202D%20Shape%20Rendering%20by%20Distance%20Fields
|
|
|
|
|
|
|
|
### fcpp (BSD)
|
|
|
|
|
|
|
|
Frexx C preprocessor
|
|
|
|
|
|
|
|
https://github.com/bagder/fcpp
|
|
|
|
|
2012-12-29 05:09:34 +04:00
|
|
|
### Forsyth Triangle Order Optimizer (Public Domain)
|
|
|
|
|
|
|
|
http://gameangst.com/?p=9
|
|
|
|
|
2012-11-26 06:24:50 +04:00
|
|
|
### glsl-optimizer (MIT)
|
|
|
|
|
|
|
|
GLSL optimizer based on Mesa's GLSL compiler. Used in Unity for mobile shader
|
|
|
|
optimization.
|
|
|
|
|
|
|
|
https://github.com/aras-p/glsl-optimizer
|
|
|
|
|
|
|
|
### stb_image (Public Domain)
|
|
|
|
|
|
|
|
http://nothings.org/stb_image.c
|
|
|
|
|
|
|
|
License (BSD 2-clause)
|
|
|
|
----------------------
|
2012-04-04 07:30:07 +04:00
|
|
|
|
|
|
|
Copyright 2010-2012 Branimir Karadzic. All rights reserved.
|
|
|
|
|
2012-11-12 06:19:42 +04:00
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
2012-04-04 07:30:07 +04:00
|
|
|
|
2012-11-12 06:19:42 +04:00
|
|
|
1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
this list of conditions and the following disclaimer.
|
2012-04-04 07:30:07 +04:00
|
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
2012-11-12 06:19:42 +04:00
|
|
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
|
|
EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
|
|
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
|
|
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|