Skip to content

Commit

Permalink
GRAPHICS: Add additional ImGui rendering stage
Browse files Browse the repository at this point in the history
  • Loading branch information
Nostritius authored and DrMcCoy committed Aug 8, 2020
1 parent 9777279 commit d46fcc3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/graphics/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
#include "external/glm/gtc/type_ptr.hpp"
#include "external/glm/gtc/matrix_transform.hpp"

#include "external/imgui/imgui.h"
#include "external/imgui/imgui_freetype.h"
#include "external/imgui/imgui_impl_opengl2.h"
#include "external/imgui/imgui_impl_opengl3.h"

#include "src/version/version.h"

#include "src/common/util.h"
Expand Down Expand Up @@ -131,9 +136,28 @@ void GraphicsManager::init() {

_rendererExperimental = ConfigMan.getBool("rendernew", false);

IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGui::StyleColorsDark();

ImGui::GetIO().Fonts->AddFontDefault();
ImGuiFreeType::BuildFontAtlas(ImGui::GetIO().Fonts);

if (!setupSDLGL())
throw Common::Exception("Failed initializing the OpenGL renderer");

switch (_renderType) {
case WindowManager::kOpenGL21:
case WindowManager::kOpenGL21Core:
ImGui_ImplOpenGL2_Init();
break;
case WindowManager::kOpenGL32Compat:
ImGui_ImplOpenGL3_Init();
break;
default:
warning("Invalid Render system, ImGui will be disabled");
}

// Try to change the FSAA settings to the config value
if (_fsaa != ConfigMan.getInt("fsaa"))
if (!setFSAA(ConfigMan.getInt("fsaa")))
Expand Down Expand Up @@ -164,6 +188,16 @@ void GraphicsManager::init() {
void GraphicsManager::deinit() {
Common::enforceMainThread();

switch (_renderType) {
case WindowManager::kOpenGL21:
case WindowManager::kOpenGL21Core:
ImGui_ImplOpenGL2_Shutdown();
break;
case WindowManager::kOpenGL32Compat:
ImGui_ImplOpenGL3_Shutdown();
break;
}

if (!_ready)
return;

Expand Down Expand Up @@ -964,8 +998,20 @@ void GraphicsManager::buildNewTextures() {
}

void GraphicsManager::beginScene() {
switch (_renderType) {
case WindowManager::kOpenGL21:
case WindowManager::kOpenGL21Core:
ImGui_ImplOpenGL2_NewFrame();
break;
case WindowManager::kOpenGL32Compat:
ImGui_ImplOpenGL3_NewFrame();
break;
}

WindowMan.beginScene();

ImGui::NewFrame();

if (_fsaa > 0)
glEnable(GL_MULTISAMPLE_ARB);

Expand Down Expand Up @@ -1118,6 +1164,23 @@ bool GraphicsManager::renderGUI(ScalingType scalingType, QueueType guiQueue, boo
return true;
}

bool GraphicsManager::renderImGui() {
ImGui::SetMouseCursor(ImGuiMouseCursor_None);
ImGui::Render();

switch (_renderType) {
case WindowManager::kOpenGL21:
case WindowManager::kOpenGL21Core:
ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
break;
case WindowManager::kOpenGL32Compat:
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
break;
}

return true;
}

bool GraphicsManager::renderCursor() {
if (!_cursor)
return false;
Expand Down Expand Up @@ -1274,6 +1337,7 @@ void GraphicsManager::renderScene() {
beginScene();

if (playVideo()) {
renderImGui();
endScene();
return;
}
Expand All @@ -1283,12 +1347,14 @@ void GraphicsManager::renderScene() {
renderWorldShader();
renderGUIFrontShader();
renderGUIConsoleShader();
renderImGui();
renderCursorShader();
} else {
renderGUIBack();
renderWorld();
renderGUIFront();
renderGUIConsole();
renderImGui();
renderCursor();
}

Expand Down
1 change: 1 addition & 0 deletions src/graphics/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ class GraphicsManager : public Common::Singleton<GraphicsManager>, public Events
bool renderGUIBack();
bool renderGUIConsole();
bool renderGUI(ScalingType scalingType, QueueType guiQueue, bool disableDepthMask);
bool renderImGui();
bool renderCursor();

bool renderWorldShader();
Expand Down

0 comments on commit d46fcc3

Please sign in to comment.