summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/22-windows/windows.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/examples/22-windows/windows.cpp')
-rw-r--r--3rdparty/bgfx/examples/22-windows/windows.cpp70
1 files changed, 47 insertions, 23 deletions
diff --git a/3rdparty/bgfx/examples/22-windows/windows.cpp b/3rdparty/bgfx/examples/22-windows/windows.cpp
index cd2be08852e..da1742079a1 100644
--- a/3rdparty/bgfx/examples/22-windows/windows.cpp
+++ b/3rdparty/bgfx/examples/22-windows/windows.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2011-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
+ * Copyright 2011-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
*/
#include "common.h"
@@ -26,17 +26,17 @@ struct PosColorVertex
static void init()
{
- ms_decl
+ ms_layout
.begin()
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true)
.end();
};
- static bgfx::VertexDecl ms_decl;
+ static bgfx::VertexLayout ms_layout;
};
-bgfx::VertexDecl PosColorVertex::ms_decl;
+bgfx::VertexLayout PosColorVertex::ms_layout;
static PosColorVertex s_cubeVertices[8] =
{
@@ -69,8 +69,8 @@ static const uint16_t s_cubeIndices[36] =
class ExampleWindows : public entry::AppI
{
public:
- ExampleWindows(const char* _name, const char* _description)
- : entry::AppI(_name, _description)
+ ExampleWindows(const char* _name, const char* _description, const char* _url)
+ : entry::AppI(_name, _description, _url)
{
}
@@ -86,6 +86,9 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
+ init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
+ init.platformData.ndt = entry::getNativeDisplayHandle();
+ init.platformData.type = entry::getNativeWindowHandleType(entry::kDefaultWindowHandle);
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;
@@ -126,7 +129,7 @@ public:
m_vbh = bgfx::createVertexBuffer(
// Static data can be passed with bgfx::makeRef
bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) )
- , PosColorVertex::ms_decl
+ , PosColorVertex::ms_layout
);
// Create static index buffer.
@@ -157,6 +160,7 @@ public:
}
}
+ inputRemoveBindings("22-windows");
BX_FREE(entry::getAllocator(), m_bindings);
// Cleanup.
@@ -176,20 +180,6 @@ public:
{
entry::MouseState mouseState = m_state.m_mouse;
- imguiBeginFrame(mouseState.m_mx
- , mouseState.m_my
- , (mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0)
- | (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
- | (mouseState.m_buttons[entry::MouseButton::Middle] ? IMGUI_MBUT_MIDDLE : 0)
- , mouseState.m_mz
- , uint16_t(m_width)
- , uint16_t(m_height)
- );
-
- showExampleDialog(this);
-
- imguiEndFrame();
-
if (isValid(m_state.m_handle) )
{
if (0 == m_state.m_handle.idx)
@@ -214,6 +204,20 @@ public:
m_fbh[viewId].idx = bgfx::kInvalidHandle;
}
+ // Before we reattach a SwapChain to the window
+ // we must actually free up the previous one.
+ // The DestroyFrameBuffer command goes in the
+ // cmdPost CommandBuffer, which happens after
+ // the frame. The CreateFrameBuffer command goes
+ // int the cmdPre CommandBuffer, which happens
+ // at the beginning of the frame. Without this
+ // bgfx::frame() call, the creation would happen
+ // before it's destroyed, which would cause
+ // the platform window to have two SwapChains
+ // associated with it.
+ // Ideally, we have an operation of ResizeFrameBuffer.
+ bgfx::frame();
+
win.m_nwh = m_state.m_nwh;
win.m_width = m_state.m_width;
win.m_height = m_state.m_height;
@@ -230,6 +234,20 @@ public:
}
}
+ imguiBeginFrame(mouseState.m_mx
+ , mouseState.m_my
+ , (mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0)
+ | (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
+ | (mouseState.m_buttons[entry::MouseButton::Middle] ? IMGUI_MBUT_MIDDLE : 0)
+ , mouseState.m_mz
+ , uint16_t(m_width)
+ , uint16_t(m_height)
+ );
+
+ showExampleDialog(this);
+
+ imguiEndFrame();
+
const bx::Vec3 at = { 0.0f, 0.0f, 0.0f };
const bx::Vec3 eye = { 0.0f, 0.0f, -35.0f };
@@ -272,6 +290,7 @@ public:
int64_t now = bx::getHPCounter();
float time = (float)( (now-m_timeOffset)/double(bx::getHPFrequency() ) );
+ bgfx::dbgTextClear();
if (NULL != m_bindings)
{
bgfx::dbgTextPrintf(0, 1, 0x2f, "Press 'c' to create or 'd' to destroy window.");
@@ -377,7 +396,12 @@ public:
} // namespace
-ENTRY_IMPLEMENT_MAIN(ExampleWindows, "22-windows", "Rendering into multiple windows.");
+ENTRY_IMPLEMENT_MAIN(
+ ExampleWindows
+ , "22-windows"
+ , "Rendering into multiple windows."
+ , "https://bkaradzic.github.io/bgfx/examples.html#windows"
+ );
void cmdCreateWindow(const void* _userData)
{