Updated 07-callback example.

This commit is contained in:
Branimir Karadžić 2014-05-27 20:05:13 -07:00
parent 02e549bfec
commit 4f908ee911
4 changed files with 64 additions and 34 deletions

View file

@ -366,7 +366,15 @@ int _main_(int /*_argc*/, char** /*_argv*/)
uint32_t width = 1280; uint32_t width = 1280;
uint32_t height = 720; uint32_t height = 720;
bgfx::init(bgfx::RendererType::Count /* initialize with default renderer */, &callback, &allocator); // Enumerate supported backend renderers.
bgfx::RendererType::Enum renderers[bgfx::RendererType::Count];
uint8_t numRenderers = bgfx::getSupportedRenderers(renderers);
bgfx::init(
renderers[bx::getHPCounter() % numRenderers] /* randomize renderer */
, &callback // custom callback handler
, &allocator // custom allocator
);
bgfx::reset(width, height, BGFX_RESET_CAPTURE|BGFX_RESET_MSAA_X16); bgfx::reset(width, height, BGFX_RESET_CAPTURE|BGFX_RESET_MSAA_X16);
// Enable debug text. // Enable debug text.
@ -400,6 +408,8 @@ int _main_(int /*_argc*/, char** /*_argv*/)
float time = 0.0f; float time = 0.0f;
const bgfx::RendererType::Enum rendererType = bgfx::getRendererType();
// 5 second 60Hz video // 5 second 60Hz video
for (uint32_t frame = 0; frame < 300; ++frame) for (uint32_t frame = 0; frame < 300; ++frame)
{ {
@ -421,6 +431,15 @@ int _main_(int /*_argc*/, char** /*_argv*/)
bgfx::dbgTextPrintf(13, 3, 0x6f, "caching OpenGL binary shaders, and video capture."); bgfx::dbgTextPrintf(13, 3, 0x6f, "caching OpenGL binary shaders, and video capture.");
bgfx::dbgTextPrintf( 0, 4, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs); bgfx::dbgTextPrintf( 0, 4, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs);
bgfx::dbgTextPrintf( 2, 6, 0x0e, "Supported renderers:");
for (uint8_t ii = 0; ii < numRenderers; ++ii)
{
bgfx::dbgTextPrintf( 2, 7+ii, 0x0c, "[%c] %s"
, renderers[ii] == rendererType ? '\xfe' : ' '
, bgfx::getRendererName(renderers[ii])
);
}
float at[3] = { 0.0f, 0.0f, 0.0f }; float at[3] = { 0.0f, 0.0f, 0.0f };
float eye[3] = { 0.0f, 0.0f, -35.0f }; float eye[3] = { 0.0f, 0.0f, -35.0f };

View file

@ -680,6 +680,9 @@ namespace bgfx
/// Returns supported backend API renderers. /// Returns supported backend API renderers.
uint8_t getSupportedRenderers(RendererType::Enum _enum[RendererType::Count]); uint8_t getSupportedRenderers(RendererType::Enum _enum[RendererType::Count]);
/// Returns name of renderer.
const char* getRendererName(RendererType::Enum _type);
/// Initialize bgfx library. /// Initialize bgfx library.
/// ///
/// @param _type Select rendering backend. When set to RendererType::Count /// @param _type Select rendering backend. When set to RendererType::Count

View file

@ -1249,16 +1249,17 @@ namespace bgfx
{ {
RendererCreateFn createFn; RendererCreateFn createFn;
RendererDestroyFn destroyFn; RendererDestroyFn destroyFn;
const char* name;
bool supported; bool supported;
}; };
static const RendererCreator s_rendererCreator[RendererType::Count] = static const RendererCreator s_rendererCreator[RendererType::Count] =
{ {
{ rendererCreateNULL, rendererDestroyNULL, !!BGFX_CONFIG_RENDERER_NULL }, // Null { rendererCreateNULL, rendererDestroyNULL, BGFX_RENDERER_NULL_NAME, !!BGFX_CONFIG_RENDERER_NULL }, // Null
{ rendererCreateD3D9, rendererDestroyD3D9, !!BGFX_CONFIG_RENDERER_DIRECT3D9 }, // Direct3D9 { rendererCreateD3D9, rendererDestroyD3D9, BGFX_RENDERER_DIRECT3D9_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D9 }, // Direct3D9
{ rendererCreateD3D11, rendererDestroyD3D11, !!BGFX_CONFIG_RENDERER_DIRECT3D11 }, // Direct3D11 { rendererCreateD3D11, rendererDestroyD3D11, BGFX_RENDERER_DIRECT3D11_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D11 }, // Direct3D11
{ rendererCreateGL, rendererDestroyGL, !!BGFX_CONFIG_RENDERER_OPENGLES }, // OpenGLES { rendererCreateGL, rendererDestroyGL, BGFX_RENDERER_OPENGL_NAME, !!BGFX_CONFIG_RENDERER_OPENGLES }, // OpenGLES
{ rendererCreateGL, rendererDestroyGL, !!BGFX_CONFIG_RENDERER_OPENGL }, // OpenGL { rendererCreateGL, rendererDestroyGL, BGFX_RENDERER_OPENGL_NAME, !!BGFX_CONFIG_RENDERER_OPENGL }, // OpenGL
}; };
RendererContextI* rendererCreate(RendererType::Enum _type) RendererContextI* rendererCreate(RendererType::Enum _type)
@ -1747,6 +1748,12 @@ again:
return num; return num;
} }
const char* getRendererName(RendererType::Enum _type)
{
BX_CHECK(_type < RendererType::Count, "Invalid renderer type %d.", _type);
return s_rendererCreator[_type].name;
}
void init(RendererType::Enum _type, CallbackI* _callback, bx::ReallocatorI* _allocator) void init(RendererType::Enum _type, CallbackI* _callback, bx::ReallocatorI* _allocator)
{ {
BX_TRACE("Init..."); BX_TRACE("Init...");

View file

@ -18,41 +18,42 @@
# ifndef BGFX_CONFIG_RENDERER_DIRECT3D9 # ifndef BGFX_CONFIG_RENDERER_DIRECT3D9
# define BGFX_CONFIG_RENDERER_DIRECT3D9 (0 \ # define BGFX_CONFIG_RENDERER_DIRECT3D9 (0 \
| (BX_PLATFORM_WINDOWS && BX_PLATFORM_WINDOWS < 0x0602 /*_WIN32_WINNT_WIN8*/) \ || (BX_PLATFORM_WINDOWS && BX_PLATFORM_WINDOWS < 0x0602 /*_WIN32_WINNT_WIN8*/) \
| BX_PLATFORM_XBOX360 \ || BX_PLATFORM_XBOX360 \
) ? 1 : 0)
# endif // BGFX_CONFIG_RENDERER_DIRECT3D9 # endif // BGFX_CONFIG_RENDERER_DIRECT3D9
# ifndef BGFX_CONFIG_RENDERER_DIRECT3D11 # ifndef BGFX_CONFIG_RENDERER_DIRECT3D11
# define BGFX_CONFIG_RENDERER_DIRECT3D11 (0 \ # define BGFX_CONFIG_RENDERER_DIRECT3D11 (0 \
| (BX_PLATFORM_WINDOWS && BX_PLATFORM_WINDOWS >= 0x0602 /*_WIN32_WINNT_WIN8*/) \ || (BX_PLATFORM_WINDOWS && BX_PLATFORM_WINDOWS >= 0x0602 /*_WIN32_WINNT_WIN8*/) \
) ? 1 : 0)
# endif // BGFX_CONFIG_RENDERER_DIRECT3D11 # endif // BGFX_CONFIG_RENDERER_DIRECT3D11
# ifndef BGFX_CONFIG_RENDERER_OPENGL # ifndef BGFX_CONFIG_RENDERER_OPENGL
# define BGFX_CONFIG_RENDERER_OPENGL (0 \ # define BGFX_CONFIG_RENDERER_OPENGL (0 \
| BX_PLATFORM_LINUX \ || BX_PLATFORM_WINDOWS \
| BX_PLATFORM_OSX \ || BX_PLATFORM_LINUX \
) || BX_PLATFORM_OSX \
? 1 : 0)
# endif // BGFX_CONFIG_RENDERER_OPENGL # endif // BGFX_CONFIG_RENDERER_OPENGL
# ifndef BGFX_CONFIG_RENDERER_OPENGLES # ifndef BGFX_CONFIG_RENDERER_OPENGLES
# define BGFX_CONFIG_RENDERER_OPENGLES (0 \ # define BGFX_CONFIG_RENDERER_OPENGLES (0 \
| BX_PLATFORM_EMSCRIPTEN \ || BX_PLATFORM_EMSCRIPTEN \
| BX_PLATFORM_NACL \ || BX_PLATFORM_NACL \
| BX_PLATFORM_ANDROID \ || BX_PLATFORM_ANDROID \
| BX_PLATFORM_IOS \ || BX_PLATFORM_IOS \
| BX_PLATFORM_QNX \ || BX_PLATFORM_QNX \
) ? 1 : 0)
# endif // BGFX_CONFIG_RENDERER_OPENGLES # endif // BGFX_CONFIG_RENDERER_OPENGLES
# ifndef BGFX_CONFIG_RENDERER_NULL # ifndef BGFX_CONFIG_RENDERER_NULL
# define BGFX_CONFIG_RENDERER_NULL (!(0 \ # define BGFX_CONFIG_RENDERER_NULL (!(0 \
| BGFX_CONFIG_RENDERER_DIRECT3D9 \ || BGFX_CONFIG_RENDERER_DIRECT3D9 \
| BGFX_CONFIG_RENDERER_DIRECT3D11 \ || BGFX_CONFIG_RENDERER_DIRECT3D11 \
| BGFX_CONFIG_RENDERER_OPENGL \ || BGFX_CONFIG_RENDERER_OPENGL \
| BGFX_CONFIG_RENDERER_OPENGLES \ || BGFX_CONFIG_RENDERER_OPENGLES \
) ) ? 1 : 0) )
# endif // BGFX_CONFIG_RENDERER_NULL # endif // BGFX_CONFIG_RENDERER_NULL
#else #else
# ifndef BGFX_CONFIG_RENDERER_DIRECT3D9 # ifndef BGFX_CONFIG_RENDERER_DIRECT3D9
@ -110,15 +111,15 @@
#ifndef BGFX_CONFIG_MULTITHREADED #ifndef BGFX_CONFIG_MULTITHREADED
# define BGFX_CONFIG_MULTITHREADED ( (!BGFX_CONFIG_RENDERER_NULL)&&(0 \ # define BGFX_CONFIG_MULTITHREADED ( (!BGFX_CONFIG_RENDERER_NULL)&&(0 \
| BX_PLATFORM_ANDROID \ || BX_PLATFORM_ANDROID \
| BX_PLATFORM_IOS \ || BX_PLATFORM_IOS \
| BX_PLATFORM_LINUX \ || BX_PLATFORM_LINUX \
| BX_PLATFORM_NACL \ || BX_PLATFORM_NACL \
| BX_PLATFORM_OSX \ || BX_PLATFORM_OSX \
| BX_PLATFORM_QNX \ || BX_PLATFORM_QNX \
| BX_PLATFORM_WINDOWS \ || BX_PLATFORM_WINDOWS \
| BX_PLATFORM_XBOX360 \ || BX_PLATFORM_XBOX360 \
) ) ? 1 : 0) )
#endif // BGFX_CONFIG_MULTITHREADED #endif // BGFX_CONFIG_MULTITHREADED
#ifndef BGFX_CONFIG_MAX_DRAW_CALLS #ifndef BGFX_CONFIG_MAX_DRAW_CALLS