Added capabilties check to examples.
This commit is contained in:
parent
1a9a42bcda
commit
e4147a49be
@ -227,6 +227,12 @@ public:
|
||||
m_oldHeight = 0;
|
||||
m_oldReset = m_reset;
|
||||
|
||||
m_mrtSupported = true
|
||||
&& 2 <= caps->limits.maxFBAttachments
|
||||
&& bgfx::isTextureValid(0, false, 1, bgfx::TextureFormat::RGBA16F, BGFX_TEXTURE_RT)
|
||||
&& bgfx::isTextureValid(0, false, 1, bgfx::TextureFormat::R16F, BGFX_TEXTURE_RT)
|
||||
;
|
||||
|
||||
m_timeOffset = bx::getHPCounter();
|
||||
}
|
||||
|
||||
@ -235,7 +241,11 @@ public:
|
||||
// Cleanup.
|
||||
imguiDestroy();
|
||||
|
||||
if (bgfx::isValid(m_fbh) )
|
||||
{
|
||||
bgfx::destroy(m_fbh);
|
||||
}
|
||||
|
||||
bgfx::destroy(m_ibh);
|
||||
bgfx::destroy(m_vbh);
|
||||
bgfx::destroy(m_blend);
|
||||
@ -256,6 +266,24 @@ public:
|
||||
bool update() override
|
||||
{
|
||||
if (!entry::processEvents(m_width, m_height, m_debug, m_reset, &m_mouseState) )
|
||||
{
|
||||
imguiBeginFrame(m_mouseState.m_mx
|
||||
, m_mouseState.m_my
|
||||
, (m_mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0)
|
||||
| (m_mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
|
||||
| (m_mouseState.m_buttons[entry::MouseButton::Middle] ? IMGUI_MBUT_MIDDLE : 0)
|
||||
, m_mouseState.m_mz
|
||||
, uint16_t(m_width)
|
||||
, uint16_t(m_height)
|
||||
);
|
||||
|
||||
showExampleDialog(this
|
||||
, !m_mrtSupported
|
||||
? "MRT or frame buffer texture format are not supported."
|
||||
: NULL
|
||||
);
|
||||
|
||||
if (m_mrtSupported)
|
||||
{
|
||||
if (m_oldWidth != m_width
|
||||
|| m_oldHeight != m_height
|
||||
@ -277,18 +305,6 @@ public:
|
||||
m_fbh = bgfx::createFrameBuffer(BX_COUNTOF(m_fbtextures), m_fbtextures, true);
|
||||
}
|
||||
|
||||
imguiBeginFrame(m_mouseState.m_mx
|
||||
, m_mouseState.m_my
|
||||
, (m_mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0)
|
||||
| (m_mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
|
||||
| (m_mouseState.m_buttons[entry::MouseButton::Middle] ? IMGUI_MBUT_MIDDLE : 0)
|
||||
, m_mouseState.m_mz
|
||||
, uint16_t(m_width)
|
||||
, uint16_t(m_height)
|
||||
);
|
||||
|
||||
showExampleDialog(this);
|
||||
|
||||
ImGui::SetNextWindowPos(
|
||||
ImVec2(m_width - m_width / 5.0f - 10.0f, 10.0f)
|
||||
, ImGuiSetCond_FirstUseEver
|
||||
@ -313,7 +329,6 @@ public:
|
||||
ImGui::Checkbox("Fade in/out", &m_fadeInOut);
|
||||
|
||||
ImGui::End();
|
||||
imguiEndFrame();
|
||||
|
||||
// Set view 0 default viewport.
|
||||
bgfx::setViewRect(0, 0, 0, uint16_t(m_width), uint16_t(m_height) );
|
||||
@ -476,6 +491,9 @@ public:
|
||||
, 1 == m_mode ? m_wbSeparateBlit : m_wbBlit
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
imguiEndFrame();
|
||||
|
||||
// Advance to next frame. Rendering thread will be kicked to
|
||||
// process submitted rendering primitives.
|
||||
@ -495,6 +513,7 @@ public:
|
||||
int32_t m_mode;
|
||||
bool m_frontToBack;
|
||||
bool m_fadeInOut;
|
||||
bool m_mrtSupported;
|
||||
|
||||
uint32_t m_oldWidth;
|
||||
uint32_t m_oldHeight;
|
||||
|
@ -142,12 +142,12 @@ public:
|
||||
);
|
||||
|
||||
const bgfx::Caps* caps = bgfx::getCaps();
|
||||
const bool computeSupported = !!(caps->supported & BGFX_CAPS_COMPUTE);
|
||||
const bool indirectSupported = !!(caps->supported & BGFX_CAPS_DRAW_INDIRECT);
|
||||
m_computeSupported = !!(caps->supported & BGFX_CAPS_COMPUTE);
|
||||
m_indirectSupported = !!(caps->supported & BGFX_CAPS_DRAW_INDIRECT);
|
||||
|
||||
imguiCreate();
|
||||
|
||||
if (computeSupported)
|
||||
if (m_computeSupported)
|
||||
{
|
||||
bgfx::VertexDecl quadVertexDecl;
|
||||
quadVertexDecl.begin()
|
||||
@ -189,7 +189,7 @@ public:
|
||||
m_indirectProgram = BGFX_INVALID_HANDLE;
|
||||
m_indirectBuffer = BGFX_INVALID_HANDLE;
|
||||
|
||||
if (indirectSupported)
|
||||
if (m_indirectSupported)
|
||||
{
|
||||
m_indirectProgram = bgfx::createProgram(loadShader("cs_indirect"), true);
|
||||
m_indirectBuffer = bgfx::createIndirectBuffer(2);
|
||||
@ -219,7 +219,9 @@ public:
|
||||
cameraDestroy();
|
||||
imguiDestroy();
|
||||
|
||||
if (bgfx::isValid(m_indirectProgram) )
|
||||
if (m_computeSupported)
|
||||
{
|
||||
if (m_indirectSupported)
|
||||
{
|
||||
bgfx::destroy(m_indirectProgram);
|
||||
bgfx::destroy(m_indirectBuffer);
|
||||
@ -235,6 +237,7 @@ public:
|
||||
bgfx::destroy(m_ibh);
|
||||
bgfx::destroy(m_vbh);
|
||||
bgfx::destroy(m_particleProgram);
|
||||
}
|
||||
|
||||
// Shutdown bgfx.
|
||||
bgfx::shutdown();
|
||||
@ -257,14 +260,13 @@ public:
|
||||
, uint16_t(m_height)
|
||||
);
|
||||
|
||||
showExampleDialog(this);
|
||||
|
||||
const bgfx::Caps* caps = bgfx::getCaps();
|
||||
const bool computeSupported = !!(caps->supported & BGFX_CAPS_COMPUTE);
|
||||
const bool indirectSupported = !!(caps->supported & BGFX_CAPS_DRAW_INDIRECT);
|
||||
showExampleDialog(this
|
||||
, !m_computeSupported
|
||||
? "Compute is not supported."
|
||||
: NULL
|
||||
);
|
||||
|
||||
int64_t now = bx::getHPCounter();
|
||||
float time = (float)( (now - m_timeOffset)/double(bx::getHPFrequency() ) );
|
||||
static int64_t last = now;
|
||||
const int64_t frameTime = now - last;
|
||||
last = now;
|
||||
@ -274,7 +276,7 @@ public:
|
||||
// Set view 0 default viewport.
|
||||
bgfx::setViewRect(0, 0, 0, uint16_t(m_width), uint16_t(m_height) );
|
||||
|
||||
if (computeSupported)
|
||||
if (m_computeSupported)
|
||||
{
|
||||
ImGui::SetNextWindowPos(
|
||||
ImVec2(m_width - m_width / 5.0f - 10.0f, 10.0f)
|
||||
@ -318,7 +320,7 @@ public:
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
if (indirectSupported)
|
||||
if (m_indirectSupported)
|
||||
{
|
||||
ImGui::Checkbox("Use draw/dispatch indirect", &m_useIndirect);
|
||||
}
|
||||
@ -430,15 +432,6 @@ public:
|
||||
bgfx::submit(0, m_particleProgram);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bgfx::setViewRect(0, 0, 0, uint16_t(m_width), uint16_t(m_height) );
|
||||
|
||||
bool blink = uint32_t(time*3.0f)&1;
|
||||
bgfx::dbgTextPrintf(0, 0, blink ? 0x1f : 0x01, " Compute is not supported by GPU. ");
|
||||
|
||||
bgfx::touch(0);
|
||||
}
|
||||
|
||||
imguiEndFrame();
|
||||
|
||||
@ -459,6 +452,8 @@ public:
|
||||
uint32_t m_debug;
|
||||
uint32_t m_reset;
|
||||
bool m_useIndirect;
|
||||
bool m_computeSupported;
|
||||
bool m_indirectSupported;
|
||||
|
||||
ParamsData m_paramsData;
|
||||
|
||||
|
@ -119,10 +119,16 @@ public:
|
||||
// Create program from shaders.
|
||||
m_program = loadProgram("vs_cubes", "fs_cubes");
|
||||
|
||||
const bgfx::Caps* caps = bgfx::getCaps();
|
||||
m_occlusionQuerySupported = !!(caps->supported & BGFX_CAPS_OCCLUSION_QUERY);
|
||||
|
||||
if (m_occlusionQuerySupported)
|
||||
{
|
||||
for (uint32_t ii = 0; ii < BX_COUNTOF(m_occlusionQueries); ++ii)
|
||||
{
|
||||
m_occlusionQueries[ii] = bgfx::createOcclusionQuery();
|
||||
}
|
||||
}
|
||||
|
||||
cameraCreate();
|
||||
|
||||
@ -142,10 +148,13 @@ public:
|
||||
// Cleanup.
|
||||
cameraDestroy();
|
||||
|
||||
if (m_occlusionQuerySupported)
|
||||
{
|
||||
for (uint32_t ii = 0; ii < BX_COUNTOF(m_occlusionQueries); ++ii)
|
||||
{
|
||||
bgfx::destroy(m_occlusionQueries[ii]);
|
||||
}
|
||||
}
|
||||
|
||||
bgfx::destroy(m_ibh);
|
||||
bgfx::destroy(m_vbh);
|
||||
@ -171,10 +180,16 @@ public:
|
||||
, uint16_t(m_height)
|
||||
);
|
||||
|
||||
showExampleDialog(this);
|
||||
showExampleDialog(this
|
||||
, !m_occlusionQuerySupported
|
||||
? "Occlusion query is not supported."
|
||||
: NULL
|
||||
);
|
||||
|
||||
imguiEndFrame();
|
||||
|
||||
if (m_occlusionQuerySupported)
|
||||
{
|
||||
int64_t now = bx::getHPCounter();
|
||||
static int64_t last = now;
|
||||
const int64_t frameTime = now - last;
|
||||
@ -277,6 +292,7 @@ public:
|
||||
int32_t numPixels = 0;
|
||||
bgfx::getResult(m_occlusionQueries[0], &numPixels);
|
||||
bgfx::dbgTextPrintf(5, 5 + CUBES_DIM + 1, 0xf, "%d", numPixels);
|
||||
}
|
||||
|
||||
// Advance to next frame. Rendering thread will be kicked to
|
||||
// process submitted rendering primitives.
|
||||
@ -299,6 +315,7 @@ public:
|
||||
bgfx::IndexBufferHandle m_ibh;
|
||||
bgfx::ProgramHandle m_program;
|
||||
int64_t m_timeOffset;
|
||||
bool m_occlusionQuerySupported;
|
||||
|
||||
bgfx::OcclusionQueryHandle m_occlusionQueries[CUBES_DIM*CUBES_DIM];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user