mirror of https://github.com/bkaradzic/bgfx
Cleanup.
This commit is contained in:
parent
034a91162d
commit
6572351298
|
@ -315,13 +315,13 @@ class ExampleCallback : public entry::AppI
|
||||||
void init(int _argc, char** _argv) BX_OVERRIDE
|
void init(int _argc, char** _argv) BX_OVERRIDE
|
||||||
{
|
{
|
||||||
Args args(_argc, _argv);
|
Args args(_argc, _argv);
|
||||||
|
|
||||||
m_width = 1280;
|
m_width = 1280;
|
||||||
m_height = 720;
|
m_height = 720;
|
||||||
|
|
||||||
// Enumerate supported backend renderers.
|
// Enumerate supported backend renderers.
|
||||||
m_numRenderers = bgfx::getSupportedRenderers(BX_COUNTOF(m_renderers), m_renderers);
|
m_numRenderers = bgfx::getSupportedRenderers(BX_COUNTOF(m_renderers), m_renderers);
|
||||||
|
|
||||||
bgfx::init(bgfx::RendererType::Count == args.m_type
|
bgfx::init(bgfx::RendererType::Count == args.m_type
|
||||||
? m_renderers[bx::getHPCounter() % m_numRenderers] /* randomize renderer */
|
? m_renderers[bx::getHPCounter() % m_numRenderers] /* randomize renderer */
|
||||||
: args.m_type
|
: args.m_type
|
||||||
|
@ -331,13 +331,13 @@ class ExampleCallback : public entry::AppI
|
||||||
, &m_allocator // custom allocator
|
, &m_allocator // custom allocator
|
||||||
);
|
);
|
||||||
bgfx::reset(m_width, m_height, BGFX_RESET_CAPTURE|BGFX_RESET_MSAA_X16);
|
bgfx::reset(m_width, m_height, BGFX_RESET_CAPTURE|BGFX_RESET_MSAA_X16);
|
||||||
|
|
||||||
// Enable debug text.
|
// Enable debug text.
|
||||||
bgfx::setDebug(BGFX_DEBUG_TEXT);
|
bgfx::setDebug(BGFX_DEBUG_TEXT);
|
||||||
|
|
||||||
// Set view 0 default viewport.
|
// Set view 0 default viewport.
|
||||||
bgfx::setViewRect(0, 0, 0, 1280, 720);
|
bgfx::setViewRect(0, 0, 0, 1280, 720);
|
||||||
|
|
||||||
// Set view 0 clear state.
|
// Set view 0 clear state.
|
||||||
bgfx::setViewClear(0
|
bgfx::setViewClear(0
|
||||||
, BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
|
, BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
|
||||||
|
@ -345,22 +345,22 @@ class ExampleCallback : public entry::AppI
|
||||||
, 1.0f
|
, 1.0f
|
||||||
, 0
|
, 0
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create vertex stream declaration.
|
// Create vertex stream declaration.
|
||||||
PosColorVertex::init();
|
PosColorVertex::init();
|
||||||
|
|
||||||
// Create static vertex buffer.
|
// Create static vertex buffer.
|
||||||
m_vbh = bgfx::createVertexBuffer(
|
m_vbh = bgfx::createVertexBuffer(
|
||||||
bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) )
|
bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) )
|
||||||
, PosColorVertex::ms_decl
|
, PosColorVertex::ms_decl
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create static index buffer.
|
// Create static index buffer.
|
||||||
m_ibh = bgfx::createIndexBuffer(bgfx::makeRef(s_cubeIndices, sizeof(s_cubeIndices) ) );
|
m_ibh = bgfx::createIndexBuffer(bgfx::makeRef(s_cubeIndices, sizeof(s_cubeIndices) ) );
|
||||||
|
|
||||||
// Create program from shaders.
|
// Create program from shaders.
|
||||||
m_program = loadProgram("vs_callback", "fs_callback");
|
m_program = loadProgram("vs_callback", "fs_callback");
|
||||||
|
|
||||||
m_time = 0.0f;
|
m_time = 0.0f;
|
||||||
m_frame = 0;
|
m_frame = 0;
|
||||||
}
|
}
|
||||||
|
@ -371,43 +371,43 @@ class ExampleCallback : public entry::AppI
|
||||||
bgfx::destroyIndexBuffer(m_ibh);
|
bgfx::destroyIndexBuffer(m_ibh);
|
||||||
bgfx::destroyVertexBuffer(m_vbh);
|
bgfx::destroyVertexBuffer(m_vbh);
|
||||||
bgfx::destroyProgram(m_program);
|
bgfx::destroyProgram(m_program);
|
||||||
|
|
||||||
// Shutdown bgfx.
|
// Shutdown bgfx.
|
||||||
bgfx::shutdown();
|
bgfx::shutdown();
|
||||||
|
|
||||||
m_allocator.dumpStats();
|
m_allocator.dumpStats();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool update() BX_OVERRIDE
|
bool update() BX_OVERRIDE
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
// 5 second 60Hz video
|
// 5 second 60Hz video
|
||||||
if ( m_frame < 300)
|
if ( m_frame < 300)
|
||||||
{
|
{
|
||||||
++m_frame;
|
++m_frame;
|
||||||
const bgfx::RendererType::Enum rendererType = bgfx::getRendererType();
|
const bgfx::RendererType::Enum rendererType = bgfx::getRendererType();
|
||||||
|
|
||||||
// This dummy draw call is here to make sure that view 0 is cleared
|
// This dummy draw call is here to make sure that view 0 is cleared
|
||||||
// if no other draw calls are submitted to view 0.
|
// if no other draw calls are submitted to view 0.
|
||||||
bgfx::touch(0);
|
bgfx::touch(0);
|
||||||
|
|
||||||
int64_t now = bx::getHPCounter();
|
int64_t now = bx::getHPCounter();
|
||||||
static int64_t last = now;
|
static int64_t last = now;
|
||||||
const int64_t frameTime = now - last;
|
const int64_t frameTime = now - last;
|
||||||
last = now;
|
last = now;
|
||||||
const double freq = double(bx::getHPFrequency() );
|
const double freq = double(bx::getHPFrequency() );
|
||||||
const double toMs = 1000.0/freq;
|
const double toMs = 1000.0/freq;
|
||||||
|
|
||||||
// Use debug font to print information about this example.
|
// Use debug font to print information about this example.
|
||||||
bgfx::dbgTextClear();
|
bgfx::dbgTextClear();
|
||||||
bgfx::dbgTextPrintf( 0, 1, 0x4f, "bgfx/examples/07-callback");
|
bgfx::dbgTextPrintf( 0, 1, 0x4f, "bgfx/examples/07-callback");
|
||||||
bgfx::dbgTextPrintf( 0, 2, 0x6f, "Description: Implementing application specific callbacks for taking screen shots,");
|
bgfx::dbgTextPrintf( 0, 2, 0x6f, "Description: Implementing application specific callbacks for taking screen shots,");
|
||||||
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:");
|
bgfx::dbgTextPrintf( 2, 6, 0x0e, "Supported renderers:");
|
||||||
for (uint8_t ii = 0; ii < m_numRenderers; ++ii)
|
for (uint8_t ii = 0; ii < m_numRenderers; ++ii)
|
||||||
{
|
{
|
||||||
|
@ -416,20 +416,20 @@ class ExampleCallback : public entry::AppI
|
||||||
, bgfx::getRendererName(m_renderers[ii])
|
, bgfx::getRendererName(m_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 };
|
||||||
|
|
||||||
float view[16];
|
float view[16];
|
||||||
float proj[16];
|
float proj[16];
|
||||||
bx::mtxLookAt(view, eye, at);
|
bx::mtxLookAt(view, eye, at);
|
||||||
bx::mtxProj(proj, 60.0f, float(m_width)/float(m_height), 0.1f, 100.0f, bgfx::getCaps()->homogeneousDepth);
|
bx::mtxProj(proj, 60.0f, float(m_width)/float(m_height), 0.1f, 100.0f, bgfx::getCaps()->homogeneousDepth);
|
||||||
|
|
||||||
// Set view and projection matrix for view 0.
|
// Set view and projection matrix for view 0.
|
||||||
bgfx::setViewTransform(0, view, proj);
|
bgfx::setViewTransform(0, view, proj);
|
||||||
|
|
||||||
m_time += 1.0f/60.0f;
|
m_time += 1.0f/60.0f;
|
||||||
|
|
||||||
// Submit 11x11 cubes.
|
// Submit 11x11 cubes.
|
||||||
for (uint32_t yy = 0; yy < 11; ++yy)
|
for (uint32_t yy = 0; yy < 11; ++yy)
|
||||||
{
|
{
|
||||||
|
@ -440,48 +440,48 @@ class ExampleCallback : public entry::AppI
|
||||||
mtx[12] = -15.0f + float(xx)*3.0f;
|
mtx[12] = -15.0f + float(xx)*3.0f;
|
||||||
mtx[13] = -15.0f + float(yy)*3.0f;
|
mtx[13] = -15.0f + float(yy)*3.0f;
|
||||||
mtx[14] = 0.0f;
|
mtx[14] = 0.0f;
|
||||||
|
|
||||||
// Set model matrix for rendering.
|
// Set model matrix for rendering.
|
||||||
bgfx::setTransform(mtx);
|
bgfx::setTransform(mtx);
|
||||||
|
|
||||||
// Set vertex and index buffer.
|
// Set vertex and index buffer.
|
||||||
bgfx::setVertexBuffer(0, m_vbh);
|
bgfx::setVertexBuffer(0, m_vbh);
|
||||||
bgfx::setIndexBuffer(m_ibh);
|
bgfx::setIndexBuffer(m_ibh);
|
||||||
|
|
||||||
// Set render states.
|
// Set render states.
|
||||||
bgfx::setState(BGFX_STATE_DEFAULT);
|
bgfx::setState(BGFX_STATE_DEFAULT);
|
||||||
|
|
||||||
// Submit primitive for rendering to view 0.
|
// Submit primitive for rendering to view 0.
|
||||||
bgfx::submit(0, m_program);
|
bgfx::submit(0, m_program);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take screen shot at frame 150.
|
// Take screen shot at frame 150.
|
||||||
if (150 == m_frame)
|
if (150 == m_frame)
|
||||||
{
|
{
|
||||||
bgfx::FrameBufferHandle fbh = BGFX_INVALID_HANDLE;
|
bgfx::FrameBufferHandle fbh = BGFX_INVALID_HANDLE;
|
||||||
bgfx::requestScreenShot(fbh, "temp/frame150");
|
bgfx::requestScreenShot(fbh, "temp/frame150");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advance to next frame. Rendering thread will be kicked to
|
// Advance to next frame. Rendering thread will be kicked to
|
||||||
// process submitted rendering primitives.
|
// process submitted rendering primitives.
|
||||||
bgfx::frame();
|
bgfx::frame();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BgfxCallback m_callback;
|
BgfxCallback m_callback;
|
||||||
BgfxAllocator m_allocator;
|
BgfxAllocator m_allocator;
|
||||||
|
|
||||||
uint32_t m_width;
|
uint32_t m_width;
|
||||||
uint32_t m_height;
|
uint32_t m_height;
|
||||||
|
|
||||||
bgfx::RendererType::Enum m_renderers[bgfx::RendererType::Count];
|
bgfx::RendererType::Enum m_renderers[bgfx::RendererType::Count];
|
||||||
uint8_t m_numRenderers;
|
uint8_t m_numRenderers;
|
||||||
|
|
||||||
bgfx::VertexBufferHandle m_vbh;
|
bgfx::VertexBufferHandle m_vbh;
|
||||||
bgfx::IndexBufferHandle m_ibh;
|
bgfx::IndexBufferHandle m_ibh;
|
||||||
bgfx::ProgramHandle m_program;
|
bgfx::ProgramHandle m_program;
|
||||||
|
|
Loading…
Reference in New Issue