Qt: ImGui support
This commit is contained in:
parent
9de0bf0aaf
commit
bea15c97cd
|
@ -7,10 +7,13 @@
|
||||||
static void InitLogging()
|
static void InitLogging()
|
||||||
{
|
{
|
||||||
// set log flags
|
// set log flags
|
||||||
// g_pLog->SetConsoleOutputParams(true);
|
#ifdef Y_BUILD_CONFIG_DEBUG
|
||||||
g_pLog->SetConsoleOutputParams(true, nullptr, LOGLEVEL_PROFILE);
|
g_pLog->SetConsoleOutputParams(true, nullptr, LOGLEVEL_DEBUG);
|
||||||
g_pLog->SetFilterLevel(LOGLEVEL_PROFILE);
|
g_pLog->SetFilterLevel(LOGLEVEL_DEBUG);
|
||||||
// g_pLog->SetDebugOutputParams(true);
|
#else
|
||||||
|
g_pLog->SetConsoleOutputParams(true, nullptr, LOGLEVEL_INFO);
|
||||||
|
g_pLog->SetFilterLevel(LOGLEVEL_INFO);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
|
|
|
@ -371,6 +371,7 @@ bool OpenGLDisplayWindow::createImGuiContext()
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
|
ImGui::NewFrame();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -464,13 +465,13 @@ void OpenGLDisplayWindow::Render()
|
||||||
|
|
||||||
renderDisplay();
|
renderDisplay();
|
||||||
|
|
||||||
ImDrawData* draw_data = ImGui::GetDrawData();
|
ImGui::Render();
|
||||||
if (draw_data)
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
ImGui_ImplOpenGL3_RenderDrawData(draw_data);
|
|
||||||
|
|
||||||
m_gl_context->makeCurrent(this);
|
m_gl_context->makeCurrent(this);
|
||||||
m_gl_context->swapBuffers(this);
|
m_gl_context->swapBuffers(this);
|
||||||
|
|
||||||
|
ImGui::NewFrame();
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
|
|
||||||
GL::Program::ResetLastProgram();
|
GL::Program::ResetLastProgram();
|
||||||
|
|
|
@ -37,6 +37,11 @@ void QtDisplayWindow::destroyDeviceContext()
|
||||||
bool QtDisplayWindow::createImGuiContext()
|
bool QtDisplayWindow::createImGuiContext()
|
||||||
{
|
{
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
|
|
||||||
|
auto& io = ImGui::GetIO();
|
||||||
|
io.DisplaySize.x = static_cast<float>(width());
|
||||||
|
io.DisplaySize.y = static_cast<float>(height());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,6 +59,17 @@ void QtDisplayWindow::destroyDeviceResources() {}
|
||||||
|
|
||||||
void QtDisplayWindow::Render() {}
|
void QtDisplayWindow::Render() {}
|
||||||
|
|
||||||
|
void QtDisplayWindow::onWindowResized(int width, int height)
|
||||||
|
{
|
||||||
|
// imgui may not have been initialized yet
|
||||||
|
if (!ImGui::GetCurrentContext())
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto& io = ImGui::GetIO();
|
||||||
|
io.DisplaySize.x = static_cast<float>(width);
|
||||||
|
io.DisplaySize.y = static_cast<float>(height);
|
||||||
|
}
|
||||||
|
|
||||||
void QtDisplayWindow::keyPressEvent(QKeyEvent* event)
|
void QtDisplayWindow::keyPressEvent(QKeyEvent* event)
|
||||||
{
|
{
|
||||||
m_host_interface->handleKeyEvent(event->key(), true);
|
m_host_interface->handleKeyEvent(event->key(), true);
|
||||||
|
@ -63,3 +79,9 @@ void QtDisplayWindow::keyReleaseEvent(QKeyEvent* event)
|
||||||
{
|
{
|
||||||
m_host_interface->handleKeyEvent(event->key(), false);
|
m_host_interface->handleKeyEvent(event->key(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QtDisplayWindow::resizeEvent(QResizeEvent* event)
|
||||||
|
{
|
||||||
|
QWindow::resizeEvent(event);
|
||||||
|
emit windowResizedEvent(event->size().width(), event->size().height());
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <QtGui/QWindow>
|
#include <QtGui/QWindow>
|
||||||
|
|
||||||
class QKeyEvent;
|
class QKeyEvent;
|
||||||
|
class QResizeEvent;
|
||||||
|
|
||||||
class HostDisplay;
|
class HostDisplay;
|
||||||
|
|
||||||
|
@ -23,14 +24,21 @@ public:
|
||||||
|
|
||||||
virtual void Render();
|
virtual void Render();
|
||||||
|
|
||||||
|
// this comes back on the emu thread
|
||||||
|
virtual void onWindowResized(int width, int height);
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void windowResizedEvent(int width, int height);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool createImGuiContext();
|
virtual bool createImGuiContext();
|
||||||
virtual void destroyImGuiContext();
|
virtual void destroyImGuiContext();
|
||||||
virtual bool createDeviceResources();
|
virtual bool createDeviceResources();
|
||||||
virtual void destroyDeviceResources();
|
virtual void destroyDeviceResources();
|
||||||
|
|
||||||
void keyPressEvent(QKeyEvent* event) override;
|
virtual void keyPressEvent(QKeyEvent* event) override;
|
||||||
void keyReleaseEvent(QKeyEvent* event) override;
|
virtual void keyReleaseEvent(QKeyEvent* event) override;
|
||||||
|
virtual void resizeEvent(QResizeEvent* event) override;
|
||||||
|
|
||||||
QtHostInterface* m_host_interface;
|
QtHostInterface* m_host_interface;
|
||||||
};
|
};
|
||||||
|
|
|
@ -130,6 +130,8 @@ void QtHostInterface::refreshGameList(bool invalidate_cache /*= false*/)
|
||||||
QWidget* QtHostInterface::createDisplayWidget(QWidget* parent)
|
QWidget* QtHostInterface::createDisplayWidget(QWidget* parent)
|
||||||
{
|
{
|
||||||
m_display_window = new OpenGLDisplayWindow(this, nullptr);
|
m_display_window = new OpenGLDisplayWindow(this, nullptr);
|
||||||
|
connect(m_display_window, &QtDisplayWindow::windowResizedEvent, this, &QtHostInterface::onDisplayWindowResized);
|
||||||
|
|
||||||
m_display.release();
|
m_display.release();
|
||||||
m_display = std::unique_ptr<HostDisplay>(m_display_window->getHostDisplayInterface());
|
m_display = std::unique_ptr<HostDisplay>(m_display_window->getHostDisplayInterface());
|
||||||
return QWidget::createWindowContainer(m_display_window, parent);
|
return QWidget::createWindowContainer(m_display_window, parent);
|
||||||
|
@ -176,6 +178,11 @@ void QtHostInterface::doHandleKeyEvent(int key, bool pressed)
|
||||||
iter->second(pressed);
|
iter->second(pressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QtHostInterface::onDisplayWindowResized(int width, int height)
|
||||||
|
{
|
||||||
|
m_display_window->onWindowResized(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
void QtHostInterface::updateInputMap()
|
void QtHostInterface::updateInputMap()
|
||||||
{
|
{
|
||||||
if (!isOnWorkerThread())
|
if (!isOnWorkerThread())
|
||||||
|
@ -352,16 +359,17 @@ void QtHostInterface::threadEntryPoint()
|
||||||
|
|
||||||
// rendering
|
// rendering
|
||||||
{
|
{
|
||||||
// DrawImGui();
|
|
||||||
|
|
||||||
if (m_system)
|
if (m_system)
|
||||||
|
{
|
||||||
|
DrawDebugWindows();
|
||||||
m_system->GetGPU()->ResetGraphicsAPIState();
|
m_system->GetGPU()->ResetGraphicsAPIState();
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawFPSWindow();
|
||||||
|
DrawOSDMessages();
|
||||||
|
|
||||||
// ImGui::Render();
|
|
||||||
m_display->Render();
|
m_display->Render();
|
||||||
|
|
||||||
// ImGui::NewFrame();
|
|
||||||
|
|
||||||
if (m_system)
|
if (m_system)
|
||||||
{
|
{
|
||||||
m_system->GetGPU()->RestoreGraphicsAPIState();
|
m_system->GetGPU()->RestoreGraphicsAPIState();
|
||||||
|
|
|
@ -67,6 +67,7 @@ private Q_SLOTS:
|
||||||
void doBootSystem(QString initial_filename, QString initial_save_state_filename);
|
void doBootSystem(QString initial_filename, QString initial_save_state_filename);
|
||||||
void doUpdateInputMap();
|
void doUpdateInputMap();
|
||||||
void doHandleKeyEvent(int key, bool pressed);
|
void doHandleKeyEvent(int key, bool pressed);
|
||||||
|
void onDisplayWindowResized(int width, int height);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class Thread : public QThread
|
class Thread : public QThread
|
||||||
|
|
Loading…
Reference in New Issue