62c9a457c1 | ||
---|---|---|
3rdparty | ||
examples | ||
include | ||
premake | ||
src | ||
tools | ||
.gitattributes | ||
.gitignore | ||
LICENSE | ||
README.md | ||
makefile |
README.md
bgfx
https://github.com/bkaradzic/bgfx
What is it?
Cross-platform rendering library.
Supported rendering backends:
- OpenGL 2.1
- OpenGL 3.1
- OpenGL ES 2
- OpenGL ES 3
- Direct3D 9
- Direct3D 11
Platforms:
- Android
- JavaScript (via Emscripten)
- Linux
- Native Client
- OSX
- Windows
Dependencies
https://github.com/bkaradzic/bx
Optional:
https://github.com/mendsley/tinystl
Building
Prerequisites
Premake 4.4 beta4
http://industriousone.com/premake/download
GNU make
Windows users download GNU make utility from:
http://gnuwin32.sourceforge.net/packages/make.htm
Getting source
git clone git://github.com/bkaradzic/bx.git
git clone git://github.com/bkaradzic/bgfx.git
cd bgfx
make
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.
Prerequisites for Android
Download AndroidNDK from:
https://developer.android.com/tools/sdk/ndk/index.html
setx ANDROID_NDK_ROOT <path to AndroidNDK directory>
setx ANDROID_NDK_ARM <path to AndroidNDK directory>\toolchains\arm-linux-androideabi-4.7\prebuilt\windows-x86_64
Prerequisites for Linux
sudo apt-get install libgl1-mesa-dev
Prerequisites for Native Client (Pepper 22) on Windows
Download Native Client SDK from:
https://developers.google.com/native-client/sdk/download
setx NACL <path to Native Client SDK directory>\toolchain\win_x86_newlib
Prerequisites 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 Visual Studio 2008, you'll need TR1 support from:
Visual C++ 2008 Feature Pack Release
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
Visual Studio 2008 command line:
make vs2008-release64
Visual Studio 2008 IDE:
start .build/projects/vs2008/bgfx.sln
Linux 64-bit:
make linux-release64
Other platforms:
make <configuration>
Configuration is <platform>-<debug/release>[32/64]
. For example:
linux-release32, nacl-debug64, android-release, etc.
Examples
Most of the examples require shader/texture/mesh data to be loaded. When running examples your current directory should be examples/runtime.
<bgfx_path>/examples/runtime $ ../../.build/<config>/bin/example-00-helloworldDebug
00-helloworld
Initialization and debug text.
01-cubes
Rendering simple static mesh.
02-metaballs
Rendering with transient buffers.
03-raymarch
Updating shader uniforms.
04-mesh
Loading meshes.
05-instancing
Geometry instancing.
06-bump
Loading textures.
07-callback
Implementing application specific callbacks for taking screen shots, caching OpenGL binary shaders, and video capture.
08-update
Updating textures.
09-hdr
Using multiple views and render targets.
Internals
bgfx is using sort-based draw call bucketing. This means that submition order
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
).
Internally all low-level rendering draw calls are issued inside single function
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!
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 information at:- OpenGL ES 2.0 and EGL on desktop
If you're targeting specific mobile hardware, you can find GLES support in their official SDKs: Adreno SDK, Mali SDK, PowerVR SDK.
All configuration settings are located inside src/config.h.
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)
This tool doesn't currently exist. Use nvdxt, or any other tool that produces DDS textures for now.
Geometry Compiler (geometryc)
Converts Wavefront .obj mesh file to format optimal for using with bgfx.
Todo
- Multiple render targets.
- BlendFuncSeparate and BlendEquationSeparate.
- Blit between textures.
- Occlusion queries.
- iOS support.
- DX11: MSAA.
- Fullscreen mode.
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.
Contact
@bkaradzic
http://www.stuckingeometry.com
Project page
https://github.com/bkaradzic/bgfx
3rd Party Libraries
All required 3rd party libraries are included in bgfx repository in 3rdparty/ directory.
edtaa3 (MIT)
Contour Rendering by Distance Fields
fcpp (BSD)
Frexx C preprocessor
https://github.com/bagder/fcpp
Forsyth Triangle Order Optimizer (Public Domain)
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
Assets
Bunny
Stanford University Computer Graphics Laboratory
Uffizi
Light Probe Image Gallery
Contributors
Garett Bass (@gtbass) - OSX port.
License (BSD 2-clause)
Copyright 2010-2013 Branimir Karadzic. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-
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 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.