Added ability to choose renderer backend in runtime.

This commit is contained in:
Branimir Karadžić 2014-05-26 14:09:26 -07:00
parent fcd828810e
commit b0d204c344
17 changed files with 2894 additions and 2677 deletions

View File

@ -366,7 +366,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
uint32_t width = 1280;
uint32_t height = 720;
bgfx::init(&callback, &allocator);
bgfx::init(bgfx::RendererType::Count /* initialize with default renderer */, &callback, &allocator);
bgfx::reset(width, height, BGFX_RESET_CAPTURE|BGFX_RESET_MSAA_X16);
// Enable debug text.

View File

@ -705,8 +705,11 @@ int _main_(int /*_argc*/, char** /*_argv*/)
cameraDestroy();
imguiDestroy();
if (bgfx::isValid(gbuffer) )
{
bgfx::destroyFrameBuffer(gbuffer);
bgfx::destroyFrameBuffer(lightBuffer);
}
bgfx::destroyIndexBuffer(ibh);
bgfx::destroyVertexBuffer(vbh);

View File

@ -677,11 +677,14 @@ namespace bgfx
///
void imageRgba8Downsample2x2(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst);
/// Returns renderer backend API type.
RendererType::Enum getRendererType();
/// Returns supported backend API renderers.
uint8_t getSupportedRenderers(RendererType::Enum _enum[RendererType::Count]);
/// Initialize bgfx library.
///
/// @param _type Select rendering backend. When set to RendererType::Count
/// default rendering backend will be selected.
///
/// @param _callback Provide application specific callback interface.
/// See: CallbackI
///
@ -689,7 +692,7 @@ namespace bgfx
/// specified, library uses default CRT allocator. The library assumes
/// custom allocator is thread safe.
///
void init(CallbackI* _callback = NULL, bx::ReallocatorI* _reallocator = NULL);
void init(RendererType::Enum _type = RendererType::Count, CallbackI* _callback = NULL, bx::ReallocatorI* _reallocator = NULL);
/// Shutdown bgfx library.
void shutdown();
@ -707,7 +710,18 @@ namespace bgfx
///
uint32_t frame();
/// Returns current renderer backend API type.
///
/// NOTE:
/// Library must be initialized.
///
RendererType::Enum getRendererType();
/// Returns renderer capabilities.
///
/// NOTE:
/// Library must be initialized.
///
const Caps* getCaps();
/// Allocate buffer to pass to bgfx calls. Data will be freed inside bgfx.

View File

@ -331,32 +331,36 @@ namespace bgfx
, mem
);
if (BX_ENABLED(BGFX_CONFIG_RENDERER_DIRECT3D9) )
switch (g_caps.rendererType)
{
case RendererType::Direct3D9:
mem = makeRef(vs_debugfont_dx9, sizeof(vs_debugfont_dx9) );
}
else if (BX_ENABLED(BGFX_CONFIG_RENDERER_DIRECT3D11) )
{
break;
case RendererType::Direct3D11:
mem = makeRef(vs_debugfont_dx11, sizeof(vs_debugfont_dx11) );
}
else
{
break;
default:
mem = makeRef(vs_debugfont_glsl, sizeof(vs_debugfont_glsl) );
break;
}
ShaderHandle vsh = createShader(mem);
if (BX_ENABLED(BGFX_CONFIG_RENDERER_DIRECT3D9) )
switch (g_caps.rendererType)
{
case RendererType::Direct3D9:
mem = makeRef(fs_debugfont_dx9, sizeof(fs_debugfont_dx9) );
}
else if (BX_ENABLED(BGFX_CONFIG_RENDERER_DIRECT3D11) )
{
break;
case RendererType::Direct3D11:
mem = makeRef(fs_debugfont_dx11, sizeof(fs_debugfont_dx11) );
}
else
{
break;
default:
mem = makeRef(fs_debugfont_glsl, sizeof(fs_debugfont_glsl) );
break;
}
ShaderHandle fsh = createShader(mem);
@ -377,7 +381,7 @@ namespace bgfx
s_ctx->destroyTransientIndexBuffer(m_ib);
}
void TextVideoMemBlitter::blit(const TextVideoMem& _mem)
void blit(RendererContextI* _renderCtx, TextVideoMemBlitter& _blitter, const TextVideoMem& _mem)
{
BGFX_CHECK_RENDER_THREAD();
struct Vertex
@ -417,21 +421,17 @@ namespace bgfx
const float texelWidth = 1.0f/2048.0f;
const float texelWidthHalf = texelWidth*0.5f;
const float texelHeight = 1.0f/24.0f;
#if BGFX_CONFIG_RENDERER_DIRECT3D9
const float texelHeightHalf = texelHeight*0.5f;
#else
const float texelHeightHalf = 0.0f;
#endif // BGFX_CONFIG_RENDERER_
const float texelHeightHalf = RendererType::Direct3D9 == g_caps.rendererType ? texelHeight*0.5f : 0.0f;
const float utop = (_mem.m_small ? 0.0f : 8.0f)*texelHeight + texelHeightHalf;
const float ubottom = (_mem.m_small ? 8.0f : 24.0f)*texelHeight + texelHeightHalf;
const float fontHeight = (_mem.m_small ? 8.0f : 16.0f);
setup();
_renderCtx->blitSetup(_blitter);
for (;yy < _mem.m_height;)
{
Vertex* vertex = (Vertex*)m_vb->data;
uint16_t* indices = (uint16_t*)m_ib->data;
Vertex* vertex = (Vertex*)_blitter.m_vb->data;
uint16_t* indices = (uint16_t*)_blitter.m_ib->data;
uint32_t startVertex = 0;
uint32_t numIndices = 0;
@ -484,7 +484,7 @@ namespace bgfx
}
}
render(numIndices);
_renderCtx->blitRender(_blitter, numIndices);
}
}
@ -492,7 +492,10 @@ namespace bgfx
{
BGFX_CHECK_MAIN_THREAD();
if (BX_ENABLED(BGFX_CONFIG_CLEAR_QUAD) )
if (BX_ENABLED(BGFX_CONFIG_CLEAR_QUAD)
&& RendererType::OpenGLES != g_caps.rendererType
&& RendererType::Direct3D9 != g_caps.rendererType
&& RendererType::Null != g_caps.rendererType)
{
m_decl
.begin()
@ -503,7 +506,7 @@ namespace bgfx
ShaderHandle vsh = BGFX_INVALID_HANDLE;
const Memory* fragMem[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS];
if (BX_ENABLED(BGFX_CONFIG_RENDERER_DIRECT3D11) )
if (RendererType::Direct3D11 == g_caps.rendererType)
{
vsh = createShader(makeRef(vs_clear_dx11, sizeof(vs_clear_dx11) ) );
fragMem[0] = makeRef(fs_clear0_dx11, sizeof(fs_clear0_dx11) );
@ -511,7 +514,7 @@ namespace bgfx
fragMem[2] = makeRef(fs_clear2_dx11, sizeof(fs_clear2_dx11) );
fragMem[3] = makeRef(fs_clear3_dx11, sizeof(fs_clear3_dx11) );
}
else if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) )
else if (RendererType::OpenGL == g_caps.rendererType)
{
vsh = createShader(makeRef(vs_clear_glsl, sizeof(vs_clear_glsl) ) );
fragMem[0] = makeRef(fs_clear0_glsl, sizeof(fs_clear0_glsl) );
@ -519,10 +522,6 @@ namespace bgfx
fragMem[2] = makeRef(fs_clear2_glsl, sizeof(fs_clear2_glsl) );
fragMem[3] = makeRef(fs_clear3_glsl, sizeof(fs_clear3_glsl) );
}
else
{
BX_CHECK(false, "You should not be here!");
}
for (uint32_t ii = 0, num = g_caps.maxFBAttachments; ii < num; ++ii)
{
@ -551,7 +550,10 @@ namespace bgfx
{
BGFX_CHECK_MAIN_THREAD();
if (BX_ENABLED(BGFX_CONFIG_CLEAR_QUAD) )
if (BX_ENABLED(BGFX_CONFIG_CLEAR_QUAD)
&& RendererType::OpenGLES != g_caps.rendererType
&& RendererType::Direct3D9 != g_caps.rendererType
&& RendererType::Null != g_caps.rendererType)
{
for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS; ++ii)
{
@ -725,113 +727,6 @@ namespace bgfx
bx::radixSort64(m_sortKeys, s_ctx->m_tempKeys, m_sortValues, s_ctx->m_tempValues, m_num);
}
const Caps* getCaps()
{
BGFX_CHECK_MAIN_THREAD();
return &g_caps;
}
RendererType::Enum getRendererType()
{
#if BGFX_CONFIG_RENDERER_DIRECT3D9
return RendererType::Direct3D9;
#elif BGFX_CONFIG_RENDERER_DIRECT3D11
return RendererType::Direct3D11;
#elif BGFX_CONFIG_RENDERER_OPENGL
return RendererType::OpenGL;
#elif BGFX_CONFIG_RENDERER_OPENGLES
return RendererType::OpenGLES;
#else
return RendererType::Null;
#endif // BGFX_CONFIG_RENDERER_
}
void init(CallbackI* _callback, bx::ReallocatorI* _allocator)
{
BX_TRACE("Init...");
memset(&g_caps, 0, sizeof(g_caps) );
g_caps.rendererType = getRendererType();
g_caps.supported = 0
| (BGFX_CONFIG_MULTITHREADED ? BGFX_CAPS_RENDERER_MULTITHREADED : 0)
;
g_caps.emulated = 0;
g_caps.maxDrawCalls = BGFX_CONFIG_MAX_DRAW_CALLS;
g_caps.maxFBAttachments = 1;
if (NULL != _allocator)
{
g_allocator = _allocator;
}
else
{
bx::CrtAllocator allocator;
g_allocator =
s_allocatorStub = BX_NEW(&allocator, AllocatorStub);
}
if (NULL != _callback)
{
g_callback = _callback;
}
else
{
g_callback =
s_callbackStub = BX_NEW(g_allocator, CallbackStub);
}
s_threadIndex = BGFX_MAIN_THREAD_MAGIC;
s_ctx = BX_ALIGNED_NEW(g_allocator, Context, 16);
s_ctx->init();
BX_TRACE("Init complete.");
}
void shutdown()
{
BX_TRACE("Shutdown...");
BGFX_CHECK_MAIN_THREAD();
Context* ctx = s_ctx; // it's going to be NULLd inside shutdown.
ctx->shutdown();
BX_ALIGNED_DELETE(g_allocator, ctx, 16);
if (NULL != s_callbackStub)
{
BX_DELETE(g_allocator, s_callbackStub);
s_callbackStub = NULL;
}
if (NULL != s_allocatorStub)
{
s_allocatorStub->checkLeaks();
bx::CrtAllocator allocator;
BX_DELETE(&allocator, s_allocatorStub);
s_allocatorStub = NULL;
}
s_threadIndex = 0;
g_callback = NULL;
g_allocator = NULL;
BX_TRACE("Shutdown complete.");
}
void reset(uint32_t _width, uint32_t _height, uint32_t _flags)
{
BGFX_CHECK_MAIN_THREAD();
s_ctx->reset(_width, _height, _flags);
}
uint32_t frame()
{
BGFX_CHECK_MAIN_THREAD();
return s_ctx->frame();
}
RenderFrame::Enum renderFrame()
{
if (NULL == s_ctx)
@ -933,7 +828,7 @@ namespace bgfx
static void dumpCaps()
{
BX_TRACE("Supported capabilities (" BGFX_RENDERER_NAME "):");
BX_TRACE("Supported capabilities (%s):", s_ctx->m_renderCtx->getRendererName() );
for (uint32_t ii = 0; ii < BX_COUNTOF(s_capsFlags); ++ii)
{
if (0 != (g_caps.supported & s_capsFlags[ii].m_flag) )
@ -954,7 +849,7 @@ namespace bgfx
BX_TRACE("Max FB attachments: %d", g_caps.maxFBAttachments);
}
void Context::init()
void Context::init(RendererType::Enum _type)
{
BX_CHECK(!m_rendererInitialized, "Already initialized?");
@ -998,7 +893,9 @@ namespace bgfx
m_declRef.init();
getCommandBuffer(CommandBuffer::RendererInit);
CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::RendererInit);
cmdbuf.write(_type);
frameNoRenderWait();
// Make sure renderer init is called from render thread.
@ -1018,6 +915,8 @@ namespace bgfx
;
g_caps.emulated |= emulatedCaps ^ (g_caps.supported & emulatedCaps);
g_caps.rendererType = m_renderCtx->getRendererType();
initAttribTypeSizeTable(g_caps.rendererType);
dumpCaps();
@ -1211,14 +1110,17 @@ namespace bgfx
bool Context::renderFrame()
{
rendererFlip();
if (m_rendererInitialized)
{
m_renderCtx->flip();
}
gameSemWait();
rendererExecCommands(m_render->m_cmdPre);
if (m_rendererInitialized)
{
rendererSubmit();
m_renderCtx->submit(m_render, m_clearQuad, m_textVideoMemBlitter);
}
rendererExecCommands(m_render->m_cmdPost);
@ -1227,7 +1129,7 @@ namespace bgfx
return m_exit;
}
void Context::rendererUpdateUniforms(ConstantBuffer* _constantBuffer, uint32_t _begin, uint32_t _end)
void rendererUpdateUniforms(RendererContextI* _renderCtx, ConstantBuffer* _constantBuffer, uint32_t _begin, uint32_t _end)
{
_constantBuffer->reset(_begin);
while (_constantBuffer->getPos() < _end)
@ -1251,16 +1153,16 @@ namespace bgfx
{
if (copy)
{
rendererUpdateUniform(loc, data, size);
_renderCtx->updateUniform(loc, data, size);
}
else
{
rendererUpdateUniform(loc, *(const char**)(data), size);
_renderCtx->updateUniform(loc, *(const char**)(data), size);
}
}
else
{
rendererSetMarker(data, size);
_renderCtx->setMarker(data, size);
}
}
}
@ -1306,20 +1208,20 @@ namespace bgfx
{
if (currentKey != UINT32_MAX)
{
rendererUpdateTextureEnd();
m_renderCtx->updateTextureEnd();
}
currentKey = key;
rendererUpdateTextureBegin(handle, side, mip);
m_renderCtx->updateTextureBegin(handle, side, mip);
}
rendererUpdateTexture(handle, side, mip, rect, zz, depth, pitch, mem);
m_renderCtx->updateTexture(handle, side, mip, rect, zz, depth, pitch, mem);
release(mem);
}
if (currentKey != UINT32_MAX)
{
rendererUpdateTextureEnd();
m_renderCtx->updateTextureEnd();
}
m_textureUpdateBatch.reset();
@ -1328,6 +1230,97 @@ namespace bgfx
}
}
typedef RendererContextI* (*RendererCreateFn)();
typedef void (*RendererDestroyFn)();
extern RendererContextI* rendererCreateNULL();
extern void rendererDestroyNULL();
extern RendererContextI* rendererCreateGL();
extern void rendererDestroyGL();
extern RendererContextI* rendererCreateD3D9();
extern void rendererDestroyD3D9();
extern RendererContextI* rendererCreateD3D11();
extern void rendererDestroyD3D11();
struct RendererCreator
{
RendererCreateFn createFn;
RendererDestroyFn destroyFn;
bool supported;
};
static const RendererCreator s_rendererCreator[RendererType::Count] =
{
{ rendererCreateNULL, rendererDestroyNULL, !!BGFX_CONFIG_RENDERER_NULL }, // Null
{ rendererCreateD3D9, rendererDestroyD3D9, !!BGFX_CONFIG_RENDERER_DIRECT3D9 }, // Direct3D9
{ rendererCreateD3D11, rendererDestroyD3D11, !!BGFX_CONFIG_RENDERER_DIRECT3D11 }, // Direct3D11
{ rendererCreateGL, rendererDestroyGL, !!BGFX_CONFIG_RENDERER_OPENGLES }, // OpenGLES
{ rendererCreateGL, rendererDestroyGL, !!BGFX_CONFIG_RENDERER_OPENGL }, // OpenGL
};
RendererContextI* rendererCreate(RendererType::Enum _type)
{
if (RendererType::Count == _type)
{
again:
if (BX_ENABLED(BX_PLATFORM_WINDOWS) )
{
if (s_rendererCreator[RendererType::Direct3D9].supported)
{
_type = RendererType::Direct3D9;
}
else if (s_rendererCreator[RendererType::Direct3D11].supported)
{
_type = RendererType::Direct3D11;
}
else if (s_rendererCreator[RendererType::OpenGL].supported)
{
_type = RendererType::OpenGL;
}
else if (s_rendererCreator[RendererType::OpenGLES].supported)
{
_type = RendererType::OpenGLES;
}
}
else if (BX_ENABLED(0
|| BX_PLATFORM_ANDROID
|| BX_PLATFORM_EMSCRIPTEN
|| BX_PLATFORM_IOS
|| BX_PLATFORM_NACL
) )
{
_type = RendererType::OpenGLES;
}
else
{
_type = RendererType::OpenGL;
}
if (!s_rendererCreator[_type].supported)
{
_type = RendererType::Null;
}
}
RendererContextI* renderCtx = s_rendererCreator[_type].createFn();
if (NULL == renderCtx)
{
goto again;
}
return renderCtx;
}
void rendererDestroy()
{
const RendererType::Enum type = getRendererType();
s_rendererCreator[type].destroyFn();
}
void Context::rendererExecCommands(CommandBuffer& _cmdbuf)
{
_cmdbuf.reset();
@ -1344,7 +1337,11 @@ namespace bgfx
case CommandBuffer::RendererInit:
{
BX_CHECK(!m_rendererInitialized, "This shouldn't happen! Bad synchronization?");
rendererInit();
RendererType::Enum type;
_cmdbuf.read(type);
m_renderCtx = rendererCreate(type);
m_rendererInitialized = true;
}
break;
@ -1359,7 +1356,8 @@ namespace bgfx
case CommandBuffer::RendererShutdownEnd:
{
BX_CHECK(!m_rendererInitialized && !m_exit, "This shouldn't happen! Bad synchronization?");
rendererShutdown();
rendererDestroy();
m_renderCtx = NULL;
m_exit = true;
}
break;
@ -1372,7 +1370,7 @@ namespace bgfx
Memory* mem;
_cmdbuf.read(mem);
rendererCreateIndexBuffer(handle, mem);
m_renderCtx->createIndexBuffer(handle, mem);
release(mem);
}
@ -1383,7 +1381,7 @@ namespace bgfx
IndexBufferHandle handle;
_cmdbuf.read(handle);
rendererDestroyIndexBuffer(handle);
m_renderCtx->destroyIndexBuffer(handle);
}
break;
@ -1395,7 +1393,7 @@ namespace bgfx
VertexDecl decl;
_cmdbuf.read(decl);
rendererCreateVertexDecl(handle, decl);
m_renderCtx->createVertexDecl(handle, decl);
}
break;
@ -1404,7 +1402,7 @@ namespace bgfx
VertexDeclHandle handle;
_cmdbuf.read(handle);
rendererDestroyVertexDecl(handle);
m_renderCtx->destroyVertexDecl(handle);
}
break;
@ -1419,7 +1417,7 @@ namespace bgfx
VertexDeclHandle declHandle;
_cmdbuf.read(declHandle);
rendererCreateVertexBuffer(handle, mem, declHandle);
m_renderCtx->createVertexBuffer(handle, mem, declHandle);
release(mem);
}
@ -1430,7 +1428,7 @@ namespace bgfx
VertexBufferHandle handle;
_cmdbuf.read(handle);
rendererDestroyVertexBuffer(handle);
m_renderCtx->destroyVertexBuffer(handle);
}
break;
@ -1442,7 +1440,7 @@ namespace bgfx
uint32_t size;
_cmdbuf.read(size);
rendererCreateDynamicIndexBuffer(handle, size);
m_renderCtx->createDynamicIndexBuffer(handle, size);
}
break;
@ -1460,7 +1458,7 @@ namespace bgfx
Memory* mem;
_cmdbuf.read(mem);
rendererUpdateDynamicIndexBuffer(handle, offset, size, mem);
m_renderCtx->updateDynamicIndexBuffer(handle, offset, size, mem);
release(mem);
}
@ -1471,7 +1469,7 @@ namespace bgfx
IndexBufferHandle handle;
_cmdbuf.read(handle);
rendererDestroyDynamicIndexBuffer(handle);
m_renderCtx->destroyDynamicIndexBuffer(handle);
}
break;
@ -1483,7 +1481,7 @@ namespace bgfx
uint32_t size;
_cmdbuf.read(size);
rendererCreateDynamicVertexBuffer(handle, size);
m_renderCtx->createDynamicVertexBuffer(handle, size);
}
break;
@ -1501,7 +1499,7 @@ namespace bgfx
Memory* mem;
_cmdbuf.read(mem);
rendererUpdateDynamicVertexBuffer(handle, offset, size, mem);
m_renderCtx->updateDynamicVertexBuffer(handle, offset, size, mem);
release(mem);
}
@ -1512,7 +1510,7 @@ namespace bgfx
VertexBufferHandle handle;
_cmdbuf.read(handle);
rendererDestroyDynamicVertexBuffer(handle);
m_renderCtx->destroyDynamicVertexBuffer(handle);
}
break;
@ -1524,7 +1522,7 @@ namespace bgfx
Memory* mem;
_cmdbuf.read(mem);
rendererCreateShader(handle, mem);
m_renderCtx->createShader(handle, mem);
release(mem);
}
@ -1535,7 +1533,7 @@ namespace bgfx
ShaderHandle handle;
_cmdbuf.read(handle);
rendererDestroyShader(handle);
m_renderCtx->destroyShader(handle);
}
break;
@ -1550,7 +1548,7 @@ namespace bgfx
ShaderHandle fsh;
_cmdbuf.read(fsh);
rendererCreateProgram(handle, vsh, fsh);
m_renderCtx->createProgram(handle, vsh, fsh);
}
break;
@ -1559,7 +1557,7 @@ namespace bgfx
ProgramHandle handle;
_cmdbuf.read(handle);
rendererDestroyProgram(handle);
m_renderCtx->destroyProgram(handle);
}
break;
@ -1577,7 +1575,7 @@ namespace bgfx
uint8_t skip;
_cmdbuf.read(skip);
rendererCreateTexture(handle, mem, flags, skip);
m_renderCtx->createTexture(handle, mem, flags, skip);
bx::MemoryReader reader(mem->data, mem->size);
@ -1637,7 +1635,7 @@ namespace bgfx
TextureHandle handle;
_cmdbuf.read(handle);
rendererDestroyTexture(handle);
m_renderCtx->destroyTexture(handle);
}
break;
@ -1655,7 +1653,7 @@ namespace bgfx
_cmdbuf.read(textureHandles[ii]);
}
rendererCreateFrameBuffer(handle, num, textureHandles);
m_renderCtx->createFrameBuffer(handle, num, textureHandles);
}
break;
@ -1664,7 +1662,7 @@ namespace bgfx
FrameBufferHandle handle;
_cmdbuf.read(handle);
rendererDestroyFrameBuffer(handle);
m_renderCtx->destroyFrameBuffer(handle);
}
break;
@ -1684,7 +1682,7 @@ namespace bgfx
const char* name = (const char*)_cmdbuf.skip(len);
rendererCreateUniform(handle, type, num, name);
m_renderCtx->createUniform(handle, type, num, name);
}
break;
@ -1693,7 +1691,7 @@ namespace bgfx
UniformHandle handle;
_cmdbuf.read(handle);
rendererDestroyUniform(handle);
m_renderCtx->destroyUniform(handle);
}
break;
@ -1704,7 +1702,7 @@ namespace bgfx
const char* filePath = (const char*)_cmdbuf.skip(len);
rendererSaveScreenShot(filePath);
m_renderCtx->saveScreenShot(filePath);
}
break;
@ -1718,7 +1716,7 @@ namespace bgfx
const char* name = (const char*)_cmdbuf.skip(len);
rendererUpdateViewName(id, name);
m_renderCtx->updateViewName(id, name);
}
break;
@ -1735,6 +1733,115 @@ namespace bgfx
flushTextureUpdateBatch(_cmdbuf);
}
uint8_t getSupportedRenderers(RendererType::Enum _enum[RendererType::Count])
{
uint8_t num = 0;
for (uint8_t ii = 0; ii < uint8_t(RendererType::Count); ++ii)
{
if (s_rendererCreator[ii].supported)
{
_enum[num++] = RendererType::Enum(ii);
}
}
return num;
}
void init(RendererType::Enum _type, CallbackI* _callback, bx::ReallocatorI* _allocator)
{
BX_TRACE("Init...");
memset(&g_caps, 0, sizeof(g_caps) );
g_caps.supported = 0
| (BGFX_CONFIG_MULTITHREADED ? BGFX_CAPS_RENDERER_MULTITHREADED : 0)
;
g_caps.emulated = 0;
g_caps.maxDrawCalls = BGFX_CONFIG_MAX_DRAW_CALLS;
g_caps.maxFBAttachments = 1;
if (NULL != _allocator)
{
g_allocator = _allocator;
}
else
{
bx::CrtAllocator allocator;
g_allocator =
s_allocatorStub = BX_NEW(&allocator, AllocatorStub);
}
if (NULL != _callback)
{
g_callback = _callback;
}
else
{
g_callback =
s_callbackStub = BX_NEW(g_allocator, CallbackStub);
}
s_threadIndex = BGFX_MAIN_THREAD_MAGIC;
s_ctx = BX_ALIGNED_NEW(g_allocator, Context, 16);
s_ctx->init(_type);
BX_TRACE("Init complete.");
}
void shutdown()
{
BX_TRACE("Shutdown...");
BGFX_CHECK_MAIN_THREAD();
Context* ctx = s_ctx; // it's going to be NULLd inside shutdown.
ctx->shutdown();
BX_ALIGNED_DELETE(g_allocator, ctx, 16);
if (NULL != s_callbackStub)
{
BX_DELETE(g_allocator, s_callbackStub);
s_callbackStub = NULL;
}
if (NULL != s_allocatorStub)
{
s_allocatorStub->checkLeaks();
bx::CrtAllocator allocator;
BX_DELETE(&allocator, s_allocatorStub);
s_allocatorStub = NULL;
}
s_threadIndex = 0;
g_callback = NULL;
g_allocator = NULL;
BX_TRACE("Shutdown complete.");
}
void reset(uint32_t _width, uint32_t _height, uint32_t _flags)
{
BGFX_CHECK_MAIN_THREAD();
s_ctx->reset(_width, _height, _flags);
}
uint32_t frame()
{
BGFX_CHECK_MAIN_THREAD();
return s_ctx->frame();
}
const Caps* getCaps()
{
return &g_caps;
}
RendererType::Enum getRendererType()
{
return g_caps.rendererType;
}
const Memory* alloc(uint32_t _size)
{
Memory* mem = (Memory*)BX_ALLOC(g_allocator, sizeof(Memory) + _size);

View File

@ -140,27 +140,25 @@ namespace stl
#define BGFX_SAMPLER_DEFAULT_FLAGS UINT32_C(0x10000000)
#if BGFX_CONFIG_RENDERER_DIRECT3D9
# define BGFX_RENDERER_NAME "Direct3D 9"
#elif BGFX_CONFIG_RENDERER_DIRECT3D11
# define BGFX_RENDERER_NAME "Direct3D 11"
#elif BGFX_CONFIG_RENDERER_OPENGL
#define BGFX_RENDERER_DIRECT3D9_NAME "Direct3D 9"
#define BGFX_RENDERER_DIRECT3D11_NAME "Direct3D 11"
#define BGFX_RENDERER_NULL_NAME "NULL"
#if BGFX_CONFIG_RENDERER_OPENGL
# if BGFX_CONFIG_RENDERER_OPENGL >= 31
# define BGFX_RENDERER_NAME "OpenGL 3.1"
# define BGFX_RENDERER_OPENGL_NAME "OpenGL 3.1"
# else
# define BGFX_RENDERER_NAME "OpenGL 2.1"
# define BGFX_RENDERER_OPENGL_NAME "OpenGL 2.1"
# endif // BGFX_CONFIG_RENDERER_OPENGL
#elif BGFX_CONFIG_RENDERER_OPENGLES
# if BGFX_CONFIG_RENDERER_OPENGLES == 30
# define BGFX_RENDERER_NAME "OpenGL ES 3.0"
# define BGFX_RENDERER_OPENGL_NAME "OpenGL ES 3.0"
# elif BGFX_CONFIG_RENDERER_OPENGLES >= 31
# define BGFX_RENDERER_NAME "OpenGL ES 3.1"
# define BGFX_RENDERER_OPENGL_NAME "OpenGL ES 3.1"
# else
# define BGFX_RENDERER_NAME "OpenGL ES 2.0"
# define BGFX_RENDERER_OPENGL_NAME "OpenGL ES 2.0"
# endif // BGFX_CONFIG_RENDERER_OPENGLES
#else
# define BGFX_RENDERER_NAME "NULL"
#endif // BGFX_CONFIG_RENDERER_
#endif //
namespace bgfx
{
@ -394,15 +392,6 @@ namespace bgfx
void init();
void shutdown();
void blit(const TextVideoMem* _mem)
{
blit(*_mem);
}
void blit(const TextVideoMem& _mem);
void setup();
void render(uint32_t _numIndices);
TextureHandle m_texture;
TransientVertexBuffer* m_vb;
TransientIndexBuffer* m_ib;
@ -411,6 +400,15 @@ namespace bgfx
bool m_init;
};
struct RendererContextI;
extern void blit(RendererContextI* _renderCtx, TextVideoMemBlitter& _blitter, const TextVideoMem& _mem);
inline void blit(RendererContextI* _renderCtx, TextVideoMemBlitter& _blitter, const TextVideoMem* _mem)
{
blit(_renderCtx, _blitter, *_mem);
}
template <uint32_t maxKeys>
struct UpdateBatchT
{
@ -466,7 +464,6 @@ namespace bgfx
void init();
void shutdown();
void clear(const Rect& _rect, const Clear& _clear, uint32_t _height = 0);
TransientVertexBuffer* m_vb;
IndexBufferHandle m_ib;
@ -861,7 +858,6 @@ namespace bgfx
void writeUniform(UniformType::Enum _type, uint16_t _loc, const void* _value, uint16_t _num = 1);
void writeUniformHandle(UniformType::Enum _type, uint16_t _loc, UniformHandle _handle, uint16_t _num = 1);
void writeMarker(const char* _marker);
void commit();
private:
ConstantBuffer(uint32_t _size)
@ -1558,10 +1554,56 @@ namespace bgfx
UsedList m_used;
};
struct BX_NO_VTABLE RendererContextI
{
virtual ~RendererContextI() = 0;
virtual RendererType::Enum getRendererType() const = 0;
virtual const char* getRendererName() const = 0;
virtual void flip() = 0;
virtual void createIndexBuffer(IndexBufferHandle _handle, Memory* _mem) = 0;
virtual void destroyIndexBuffer(IndexBufferHandle _handle) = 0;
virtual void createVertexDecl(VertexDeclHandle _handle, const VertexDecl& _decl) = 0;
virtual void destroyVertexDecl(VertexDeclHandle _handle) = 0;
virtual void createVertexBuffer(VertexBufferHandle _handle, Memory* _mem, VertexDeclHandle _declHandle) = 0;
virtual void destroyVertexBuffer(VertexBufferHandle _handle) = 0;
virtual void createDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _size) = 0;
virtual void updateDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _offset, uint32_t _size, Memory* _mem) = 0;
virtual void destroyDynamicIndexBuffer(IndexBufferHandle _handle) = 0;
virtual void createDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _size) = 0;
virtual void updateDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _offset, uint32_t _size, Memory* _mem) = 0;
virtual void destroyDynamicVertexBuffer(VertexBufferHandle _handle) = 0;
virtual void createShader(ShaderHandle _handle, Memory* _mem) = 0;
virtual void destroyShader(ShaderHandle _handle) = 0;
virtual void createProgram(ProgramHandle _handle, ShaderHandle _vsh, ShaderHandle _fsh) = 0;
virtual void destroyProgram(ProgramHandle _handle) = 0;
virtual void createTexture(TextureHandle _handle, Memory* _mem, uint32_t _flags, uint8_t _skip) = 0;
virtual void updateTextureBegin(TextureHandle _handle, uint8_t _side, uint8_t _mip) = 0;
virtual void updateTexture(TextureHandle _handle, uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem) = 0;
virtual void updateTextureEnd() = 0;
virtual void destroyTexture(TextureHandle _handle) = 0;
virtual void createFrameBuffer(FrameBufferHandle _handle, uint8_t _num, const TextureHandle* _textureHandles) = 0;
virtual void destroyFrameBuffer(FrameBufferHandle _handle) = 0;
virtual void createUniform(UniformHandle _handle, UniformType::Enum _type, uint16_t _num, const char* _name) = 0;
virtual void destroyUniform(UniformHandle _handle) = 0;
virtual void saveScreenShot(const char* _filePath) = 0;
virtual void updateViewName(uint8_t _id, const char* _name) = 0;
virtual void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) = 0;
virtual void setMarker(const char* _marker, uint32_t _size) = 0;
virtual void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) = 0;
virtual void blitSetup(TextVideoMemBlitter& _blitter) = 0;
virtual void blitRender(TextVideoMemBlitter& _blitter, uint32_t _numIndices) = 0;
};
inline RendererContextI::~RendererContextI()
{
}
void rendererUpdateUniforms(RendererContextI* _renderCtx, ConstantBuffer* _constantBuffer, uint32_t _begin, uint32_t _end);
#if BGFX_CONFIG_DEBUG
# define BGFX_API_FUNC(_api) BX_NO_INLINE _api
# define BGFX_API_FUNC(_func) BX_NO_INLINE _func
#else
# define BGFX_API_FUNC(_api) _api
# define BGFX_API_FUNC(_func) _func
#endif // BGFX_CONFIG_DEBUG
struct Context
@ -1593,7 +1635,7 @@ namespace bgfx
}
// game thread
void init();
void init(RendererType::Enum _type);
void shutdown();
CommandBuffer& getCommandBuffer(CommandBuffer::Enum _cmd)
@ -2670,42 +2712,8 @@ namespace bgfx
// render thread
bool renderFrame();
void rendererFlip();
void rendererInit();
void rendererShutdown();
void rendererCreateIndexBuffer(IndexBufferHandle _handle, Memory* _mem);
void rendererDestroyIndexBuffer(IndexBufferHandle _handle);
void rendererCreateVertexBuffer(VertexBufferHandle _handle, Memory* _mem, VertexDeclHandle _declHandle);
void rendererDestroyVertexBuffer(VertexBufferHandle _handle);
void rendererCreateDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _size);
void rendererUpdateDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _offset, uint32_t _size, Memory* _mem);
void rendererDestroyDynamicIndexBuffer(IndexBufferHandle _handle);
void rendererCreateDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _size);
void rendererUpdateDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _offset, uint32_t _size, Memory* _mem);
void rendererDestroyDynamicVertexBuffer(VertexBufferHandle _handle);
void rendererCreateVertexDecl(VertexDeclHandle _handle, const VertexDecl& _decl);
void rendererDestroyVertexDecl(VertexDeclHandle _handle);
void rendererCreateShader(ShaderHandle _handle, Memory* _mem);
void rendererDestroyShader(ShaderHandle _handle);
void rendererCreateProgram(ProgramHandle _handle, ShaderHandle _vsh, ShaderHandle _fsh);
void rendererDestroyProgram(ProgramHandle _handle);
void rendererCreateTexture(TextureHandle _handle, Memory* _mem, uint32_t _flags, uint8_t _skip);
void rendererUpdateTextureBegin(TextureHandle _handle, uint8_t _side, uint8_t _mip);
void rendererUpdateTexture(TextureHandle _handle, uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem);
void rendererUpdateTextureEnd();
void rendererDestroyTexture(TextureHandle _handle);
void rendererCreateFrameBuffer(FrameBufferHandle _handle, uint8_t _num, const TextureHandle* _textureHandles);
void rendererDestroyFrameBuffer(FrameBufferHandle _handle);
void rendererCreateUniform(UniformHandle _handle, UniformType::Enum _type, uint16_t _num, const char* _name);
void rendererDestroyUniform(UniformHandle _handle);
void rendererSaveScreenShot(const char* _filePath);
void rendererUpdateViewName(uint8_t _id, const char* _name);
void rendererUpdateUniform(uint16_t _loc, const void* _data, uint32_t _size);
void rendererSetMarker(const char* _marker, uint32_t _size);
void rendererUpdateUniforms(ConstantBuffer* _constantBuffer, uint32_t _begin, uint32_t _end);
void flushTextureUpdateBatch(CommandBuffer& _cmdbuf);
void rendererExecCommands(CommandBuffer& _cmdbuf);
void rendererSubmit();
#if BGFX_CONFIG_MULTITHREADED
void gameSemPost()
@ -2843,6 +2851,8 @@ namespace bgfx
TextVideoMemBlitter m_textVideoMemBlitter;
ClearQuad m_clearQuad;
RendererContextI* m_renderCtx;
bool m_rendererInitialized;
bool m_exit;

View File

@ -86,6 +86,10 @@
# define BGFX_CONFIG_RENDERER_OPENGLES 20
#endif // BGFX_CONFIG_RENDERER_OPENGLES && BGFX_CONFIG_RENDERER_OPENGLES < 20
#if BGFX_CONFIG_RENDERER_OPENGL && BGFX_CONFIG_RENDERER_OPENGLES
# error "Can't define both BGFX_CONFIG_RENDERER_OPENGL and BGFX_CONFIG_RENDERER_OPENGLES"
#endif // BGFX_CONFIG_RENDERER_OPENGL && BGFX_CONFIG_RENDERER_OPENGLES
#ifndef BGFX_CONFIG_DEBUG_PERFHUD
# define BGFX_CONFIG_DEBUG_PERFHUD 0
#endif // BGFX_CONFIG_DEBUG_NVPERFHUD

View File

@ -9,6 +9,9 @@
#if BGFX_USE_WGL
#include <wgl/wglext.h>
namespace bgfx
{
typedef PROC (APIENTRYP PFNWGLGETPROCADDRESSPROC) (LPCSTR lpszProc);
typedef BOOL (APIENTRYP PFNWGLMAKECURRENTPROC) (HDC hdc, HGLRC hglrc);
typedef HGLRC (APIENTRYP PFNWGLCREATECONTEXTPROC) (HDC hdc);
@ -48,8 +51,6 @@ typedef void (APIENTRYP PFNGLSTENCILFUNCPROC) (GLenum func, GLint ref, GLuint ma
typedef void (APIENTRYP PFNGLSTENCILMASKPROC) (GLuint mask);
typedef void (APIENTRYP PFNGLSTENCILOPPROC) (GLenum fail, GLenum zfail, GLenum zpass);
namespace bgfx
{
extern PFNWGLGETPROCADDRESSPROC wglGetProcAddress;
extern PFNWGLMAKECURRENTPROC wglMakeCurrent;
extern PFNWGLCREATECONTEXTPROC wglCreateContext;

View File

@ -65,9 +65,9 @@ namespace bgfx
typedef void (WINAPI *D3DPERF_SetOptionsFunc)(DWORD _options);
typedef DWORD (WINAPI *D3DPERF_GetStatusFunc)();
#define _PIX_SETMARKER(_col, _name) s_renderCtx->m_D3DPERF_SetMarker(_col, _name)
#define _PIX_BEGINEVENT(_col, _name) s_renderCtx->m_D3DPERF_BeginEvent(_col, _name)
#define _PIX_ENDEVENT() s_renderCtx->m_D3DPERF_EndEvent()
#define _PIX_SETMARKER(_col, _name) m_D3DPERF_SetMarker(_col, _name)
#define _PIX_BEGINEVENT(_col, _name) m_D3DPERF_BeginEvent(_col, _name)
#define _PIX_ENDEVENT() m_D3DPERF_EndEvent()
#if BGFX_CONFIG_DEBUG_PIX
# define PIX_SETMARKER(_color, _name) _PIX_SETMARKER(_color, _name)

File diff suppressed because it is too large Load Diff

View File

@ -70,9 +70,9 @@ namespace bgfx
HashMap m_hashMap;
};
struct IndexBuffer
struct IndexBufferD3D11
{
IndexBuffer()
IndexBufferD3D11()
: m_ptr(NULL)
, m_dynamic(false)
{
@ -95,9 +95,9 @@ namespace bgfx
bool m_dynamic;
};
struct VertexBuffer
struct VertexBufferD3D11
{
VertexBuffer()
VertexBufferD3D11()
: m_ptr(NULL)
, m_dynamic(false)
{
@ -121,9 +121,9 @@ namespace bgfx
bool m_dynamic;
};
struct Shader
struct ShaderD3D11
{
Shader()
ShaderD3D11()
: m_ptr(NULL)
, m_code(NULL)
, m_buffer(NULL)
@ -176,15 +176,15 @@ namespace bgfx
uint8_t m_numPredefined;
};
struct Program
struct ProgramD3D11
{
Program()
ProgramD3D11()
: m_vsh(NULL)
, m_fsh(NULL)
{
}
void create(const Shader& _vsh, const Shader& _fsh)
void create(const ShaderD3D11& _vsh, const ShaderD3D11& _fsh)
{
BX_CHECK(NULL != _vsh.m_ptr, "Vertex shader doesn't exist.");
m_vsh = &_vsh;
@ -204,27 +204,14 @@ namespace bgfx
m_fsh = NULL;
}
void commit()
{
if (NULL != m_vsh->m_constantBuffer)
{
m_vsh->m_constantBuffer->commit();
}
if (NULL != m_fsh->m_constantBuffer)
{
m_fsh->m_constantBuffer->commit();
}
}
const Shader* m_vsh;
const Shader* m_fsh;
const ShaderD3D11* m_vsh;
const ShaderD3D11* m_fsh;
PredefinedUniform m_predefined[PredefinedUniform::Count*2];
uint8_t m_numPredefined;
};
struct Texture
struct TextureD3D11
{
enum Enum
{
@ -233,7 +220,7 @@ namespace bgfx
TextureCube,
};
Texture()
TextureD3D11()
: m_ptr(NULL)
, m_srv(NULL)
, m_sampler(NULL)
@ -263,9 +250,9 @@ namespace bgfx
uint8_t m_numMips;
};
struct FrameBuffer
struct FrameBufferD3D11
{
FrameBuffer()
FrameBufferD3D11()
: m_num(0)
{
}

File diff suppressed because it is too large Load Diff

View File

@ -116,9 +116,9 @@ namespace bgfx
DWORD m_quality;
};
struct IndexBuffer
struct IndexBufferD3D9
{
IndexBuffer()
IndexBufferD3D9()
: m_ptr(NULL)
, m_dynamic(false)
{
@ -156,9 +156,9 @@ namespace bgfx
bool m_dynamic;
};
struct VertexBuffer
struct VertexBufferD3D9
{
VertexBuffer()
VertexBufferD3D9()
: m_ptr(NULL)
, m_dynamic(false)
{
@ -215,9 +215,9 @@ namespace bgfx
VertexDecl m_decl;
};
struct Shader
struct ShaderD3D9
{
Shader()
ShaderD3D9()
: m_ptr(NULL)
, m_constantBuffer(NULL)
, m_numPredefined(0)
@ -245,9 +245,9 @@ namespace bgfx
uint8_t m_numPredefined;
};
struct Program
struct ProgramD3D9
{
void create(const Shader& _vsh, const Shader& _fsh)
void create(const ShaderD3D9& _vsh, const ShaderD3D9& _fsh)
{
BX_CHECK(NULL != _vsh.m_ptr, "Vertex shader doesn't exist.");
m_vsh = &_vsh;
@ -267,27 +267,14 @@ namespace bgfx
m_fsh = NULL;
}
void commit()
{
if (NULL != m_vsh->m_constantBuffer)
{
m_vsh->m_constantBuffer->commit();
}
if (NULL != m_fsh->m_constantBuffer)
{
m_fsh->m_constantBuffer->commit();
}
}
const Shader* m_vsh;
const Shader* m_fsh;
const ShaderD3D9* m_vsh;
const ShaderD3D9* m_fsh;
PredefinedUniform m_predefined[PredefinedUniform::Count*2];
uint8_t m_numPredefined;
};
struct Texture
struct TextureD3D9
{
enum Enum
{
@ -296,7 +283,7 @@ namespace bgfx
TextureCube,
};
Texture()
TextureD3D9()
: m_ptr(NULL)
, m_surface(NULL)
, m_textureFormat(TextureFormat::Unknown)
@ -347,9 +334,9 @@ namespace bgfx
uint8_t m_textureFormat;
};
struct FrameBuffer
struct FrameBufferD3D9
{
FrameBuffer()
FrameBufferD3D9()
: m_num(0)
, m_needResolve(0)
{

File diff suppressed because it is too large Load Diff

View File

@ -370,6 +370,9 @@ typedef uint64_t GLuint64;
namespace bgfx
{
class ConstantBuffer;
void dumpExtensions(const char* _extensions);
const char* glEnumName(GLenum _enum);
#define _GL_CHECK(_check, _call) \
@ -395,10 +398,6 @@ namespace bgfx
#define GL_IMPORT(_optional, _proto, _func, _import) extern _proto _func
#include "glimports.h"
void dumpExtensions(const char* _extensions);
class ConstantBuffer;
class VaoStateCache
{
public:
@ -525,7 +524,7 @@ namespace bgfx
HashMap m_hashMap;
};
struct IndexBuffer
struct IndexBufferGL
{
void create(uint32_t _size, void* _data)
{
@ -566,7 +565,7 @@ namespace bgfx
VaoCacheRef m_vcref;
};
struct VertexBuffer
struct VertexBufferGL
{
void create(uint32_t _size, void* _data, VertexDeclHandle _declHandle)
{
@ -609,9 +608,9 @@ namespace bgfx
VaoCacheRef m_vcref;
};
struct Texture
struct TextureGL
{
Texture()
TextureGL()
: m_id(0)
, m_rbo(0)
, m_target(GL_TEXTURE_2D)
@ -644,9 +643,9 @@ namespace bgfx
uint8_t m_textureFormat;
};
struct Shader
struct ShaderGL
{
Shader()
ShaderGL()
: m_id(0)
, m_type(0)
, m_hash(0)
@ -661,9 +660,9 @@ namespace bgfx
uint32_t m_hash;
};
struct FrameBuffer
struct FrameBufferGL
{
FrameBuffer()
FrameBufferGL()
: m_num(0)
{
memset(m_fbo, 0, sizeof(m_fbo) );
@ -679,26 +678,21 @@ namespace bgfx
uint32_t m_height;
};
struct Program
struct ProgramGL
{
Program()
ProgramGL()
: m_id(0)
, m_constantBuffer(NULL)
, m_numPredefined(0)
{
}
void create(const Shader& _vsh, const Shader& _fsh);
void create(const ShaderGL& _vsh, const ShaderGL& _fsh);
void destroy();
void init();
void bindAttributes(const VertexDecl& _vertexDecl, uint32_t _baseVertex = 0) const;
void bindInstanceData(uint32_t _stride, uint32_t _baseVertex = 0) const;
void commit()
{
m_constantBuffer->commit();
}
void add(uint32_t _hash)
{
m_vcref.add(_hash);
@ -719,7 +713,7 @@ namespace bgfx
VaoCacheRef m_vcref;
};
struct Queries
struct QueriesGL
{
void create()
{

View File

@ -9,149 +9,186 @@
namespace bgfx
{
void ConstantBuffer::commit()
struct RendererContextNULL : public RendererContextI
{
RendererContextNULL()
{
}
void TextVideoMemBlitter::setup()
~RendererContextNULL()
{
}
void TextVideoMemBlitter::render(uint32_t /*_numIndices*/)
RendererType::Enum getRendererType() const BX_OVERRIDE
{
return RendererType::Null;
}
const char* getRendererName() const BX_OVERRIDE
{
return BGFX_RENDERER_NULL_NAME;
}
void flip() BX_OVERRIDE
{
}
void Context::rendererFlip()
void createIndexBuffer(IndexBufferHandle /*_handle*/, Memory* /*_mem*/) BX_OVERRIDE
{
}
void Context::rendererInit()
void destroyIndexBuffer(IndexBufferHandle /*_handle*/) BX_OVERRIDE
{
}
void Context::rendererShutdown()
void createVertexDecl(VertexDeclHandle /*_handle*/, const VertexDecl& /*_decl*/) BX_OVERRIDE
{
}
void Context::rendererCreateIndexBuffer(IndexBufferHandle /*_handle*/, Memory* /*_mem*/)
void destroyVertexDecl(VertexDeclHandle /*_handle*/) BX_OVERRIDE
{
}
void Context::rendererDestroyIndexBuffer(IndexBufferHandle /*_handle*/)
void createVertexBuffer(VertexBufferHandle /*_handle*/, Memory* /*_mem*/, VertexDeclHandle /*_declHandle*/) BX_OVERRIDE
{
}
void Context::rendererCreateVertexDecl(VertexDeclHandle /*_handle*/, const VertexDecl& /*_decl*/)
void destroyVertexBuffer(VertexBufferHandle /*_handle*/) BX_OVERRIDE
{
}
void Context::rendererDestroyVertexDecl(VertexDeclHandle /*_handle*/)
void createDynamicIndexBuffer(IndexBufferHandle /*_handle*/, uint32_t /*_size*/) BX_OVERRIDE
{
}
void Context::rendererCreateVertexBuffer(VertexBufferHandle /*_handle*/, Memory* /*_mem*/, VertexDeclHandle /*_declHandle*/)
void updateDynamicIndexBuffer(IndexBufferHandle /*_handle*/, uint32_t /*_offset*/, uint32_t /*_size*/, Memory* /*_mem*/) BX_OVERRIDE
{
}
void Context::rendererDestroyVertexBuffer(VertexBufferHandle /*_handle*/)
void destroyDynamicIndexBuffer(IndexBufferHandle /*_handle*/) BX_OVERRIDE
{
}
void Context::rendererCreateDynamicIndexBuffer(IndexBufferHandle /*_handle*/, uint32_t /*_size*/)
void createDynamicVertexBuffer(VertexBufferHandle /*_handle*/, uint32_t /*_size*/) BX_OVERRIDE
{
}
void Context::rendererUpdateDynamicIndexBuffer(IndexBufferHandle /*_handle*/, uint32_t /*_offset*/, uint32_t /*_size*/, Memory* /*_mem*/)
void updateDynamicVertexBuffer(VertexBufferHandle /*_handle*/, uint32_t /*_offset*/, uint32_t /*_size*/, Memory* /*_mem*/) BX_OVERRIDE
{
}
void Context::rendererDestroyDynamicIndexBuffer(IndexBufferHandle /*_handle*/)
void destroyDynamicVertexBuffer(VertexBufferHandle /*_handle*/) BX_OVERRIDE
{
}
void Context::rendererCreateDynamicVertexBuffer(VertexBufferHandle /*_handle*/, uint32_t /*_size*/)
void createShader(ShaderHandle /*_handle*/, Memory* /*_mem*/) BX_OVERRIDE
{
}
void Context::rendererUpdateDynamicVertexBuffer(VertexBufferHandle /*_handle*/, uint32_t /*_offset*/, uint32_t /*_size*/, Memory* /*_mem*/)
void destroyShader(ShaderHandle /*_handle*/) BX_OVERRIDE
{
}
void Context::rendererDestroyDynamicVertexBuffer(VertexBufferHandle /*_handle*/)
void createProgram(ProgramHandle /*_handle*/, ShaderHandle /*_vsh*/, ShaderHandle /*_fsh*/) BX_OVERRIDE
{
}
void Context::rendererCreateShader(ShaderHandle /*_handle*/, Memory* /*_mem*/)
void destroyProgram(ProgramHandle /*_handle*/) BX_OVERRIDE
{
}
void Context::rendererDestroyShader(ShaderHandle /*_handle*/)
void createTexture(TextureHandle /*_handle*/, Memory* /*_mem*/, uint32_t /*_flags*/, uint8_t /*_skip*/) BX_OVERRIDE
{
}
void Context::rendererCreateProgram(ProgramHandle /*_handle*/, ShaderHandle /*_vsh*/, ShaderHandle /*_fsh*/)
void updateTextureBegin(TextureHandle /*_handle*/, uint8_t /*_side*/, uint8_t /*_mip*/) BX_OVERRIDE
{
}
void Context::rendererDestroyProgram(ProgramHandle /*_handle*/)
void updateTexture(TextureHandle /*_handle*/, uint8_t /*_side*/, uint8_t /*_mip*/, const Rect& /*_rect*/, uint16_t /*_z*/, uint16_t /*_depth*/, uint16_t /*_pitch*/, const Memory* /*_mem*/) BX_OVERRIDE
{
}
void Context::rendererCreateTexture(TextureHandle /*_handle*/, Memory* /*_mem*/, uint32_t /*_flags*/, uint8_t /*_skip*/)
void updateTextureEnd() BX_OVERRIDE
{
}
void Context::rendererUpdateTextureBegin(TextureHandle /*_handle*/, uint8_t /*_side*/, uint8_t /*_mip*/)
void destroyTexture(TextureHandle /*_handle*/) BX_OVERRIDE
{
}
void Context::rendererUpdateTexture(TextureHandle /*_handle*/, uint8_t /*_side*/, uint8_t /*_mip*/, const Rect& /*_rect*/, uint16_t /*_z*/, uint16_t /*_depth*/, uint16_t /*_pitch*/, const Memory* /*_mem*/)
void createFrameBuffer(FrameBufferHandle /*_handle*/, uint8_t /*_num*/, const TextureHandle* /*_textureHandles*/) BX_OVERRIDE
{
}
void Context::rendererUpdateTextureEnd()
void destroyFrameBuffer(FrameBufferHandle /*_handle*/) BX_OVERRIDE
{
}
void Context::rendererDestroyTexture(TextureHandle /*_handle*/)
void createUniform(UniformHandle /*_handle*/, UniformType::Enum /*_type*/, uint16_t /*_num*/, const char* /*_name*/) BX_OVERRIDE
{
}
void Context::rendererCreateFrameBuffer(FrameBufferHandle /*_handle*/, uint8_t /*_num*/, const TextureHandle* /*_textureHandles*/)
void destroyUniform(UniformHandle /*_handle*/) BX_OVERRIDE
{
}
void Context::rendererDestroyFrameBuffer(FrameBufferHandle /*_handle*/)
void saveScreenShot(const char* /*_filePath*/) BX_OVERRIDE
{
}
void Context::rendererCreateUniform(UniformHandle /*_handle*/, UniformType::Enum /*_type*/, uint16_t /*_num*/, const char* /*_name*/)
void updateViewName(uint8_t /*_id*/, const char* /*_name*/) BX_OVERRIDE
{
}
void Context::rendererDestroyUniform(UniformHandle /*_handle*/)
void updateUniform(uint16_t /*_loc*/, const void* /*_data*/, uint32_t /*_size*/) BX_OVERRIDE
{
}
void Context::rendererSaveScreenShot(const char* /*_filePath*/)
void setMarker(const char* /*_marker*/, uint32_t /*_size*/) BX_OVERRIDE
{
}
void Context::rendererUpdateViewName(uint8_t /*_id*/, const char* /*_name*/)
void submit(Frame* /*_render*/, ClearQuad& /*_clearQuad*/, TextVideoMemBlitter& /*_textVideoMemBlitter*/) BX_OVERRIDE
{
}
void Context::rendererUpdateUniform(uint16_t /*_loc*/, const void* /*_data*/, uint32_t /*_size*/)
void blitSetup(TextVideoMemBlitter& /*_blitter*/) BX_OVERRIDE
{
}
void Context::rendererSetMarker(const char* /*_marker*/, uint32_t /*_size*/)
void blitRender(TextVideoMemBlitter& /*_blitter*/, uint32_t /*_numIndices*/) BX_OVERRIDE
{
}
};
static RendererContextNULL* s_renderNULL;
RendererContextI* rendererCreateNULL()
{
s_renderNULL = BX_NEW(g_allocator, RendererContextNULL);
return s_renderNULL;
}
void Context::rendererSubmit()
void rendererDestroyNULL()
{
BX_DELETE(g_allocator, s_renderNULL);
s_renderNULL = NULL;
}
} // namespace bgfx
#else
namespace bgfx
{
RendererContextI* rendererCreateNULL()
{
return NULL;
}
void rendererDestroyNULL()
{
}
}
} // namespace bgfx
#endif // BGFX_CONFIG_RENDERER_NULL

View File

@ -55,6 +55,11 @@ namespace bgfx
&s_attribTypeSizeGl,
};
void initAttribTypeSizeTable(RendererType::Enum _type)
{
s_attribTypeSize[0] = s_attribTypeSize[_type];
}
void dbgPrintfVargs(const char* _format, va_list _argList)
{
char temp[8192];

View File

@ -10,6 +10,9 @@
namespace bgfx
{
///
void initAttribTypeSizeTable(RendererType::Enum _type);
/// Returns attribute name.
const char* getAttribName(Attrib::Enum _attr);