[client] imgui: added imgui to the client and OpenGL/EGL renderers

This commit is contained in:
Geoffrey McRae
2021-07-08 11:45:54 +10:00
parent c9d469fb91
commit f08163fd72
10 changed files with 102 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.0)
project(renderer_EGL LANGUAGES C)
project(renderer_EGL LANGUAGES C CXX)
find_package(PkgConfig)
pkg_check_modules(RENDERER_EGL_PKGCONFIG REQUIRED
@@ -54,13 +54,19 @@ add_library(renderer_EGL STATIC
alert.c
${EGL_SHADER_OBJS}
"${EGL_SHADER_INCS}/desktop_rgb.def.h"
${PROJECT_TOP}/repos/cimgui/imgui/backends/imgui_impl_opengl3.cpp
)
target_compile_definitions(renderer_EGL PRIVATE CIMGUI_DEFINE_ENUMS_AND_STRUCTS=1)
target_link_libraries(renderer_EGL
${RENDERER_EGL_PKGCONFIG_LIBRARIES}
${RENDERER_EGL_OPT_PKGCONFIG_LIBRARIES}
lg_common
fonts
cimgui
GLEW
)
target_include_directories(renderer_EGL

View File

@@ -25,11 +25,16 @@
#include "common/sysinfo.h"
#include "common/time.h"
#include "common/locking.h"
#include "app.h"
#include "util.h"
#include "dynamic/fonts.h"
#include <GL/glew.h>
#include <EGL/egl.h>
#include "cimgui.h"
#include "generator/output/cimgui_impl.h"
#include <assert.h>
#include <math.h>
#include <string.h>
@@ -72,6 +77,7 @@ struct Inst
EGL_Splash * splash; // the splash screen
EGL_Alert * alert; // the alert display
EGL_Help * help; // the help display
bool imgui; // if imgui was initialized
LG_RendererFormat format;
bool formatValid;
@@ -279,6 +285,9 @@ void egl_deinitialize(void * opaque)
{
struct Inst * this = (struct Inst *)opaque;
if (this->imgui)
ImGui_ImplOpenGL3_Shutdown();
if (this->font)
{
if (this->fontObj)
@@ -288,7 +297,6 @@ void egl_deinitialize(void * opaque)
this->font->destroy(this->helpFontObj);
}
egl_desktop_free(&this->desktop);
egl_cursor_free (&this->cursor);
egl_fps_free (&this->fps );
@@ -766,6 +774,20 @@ bool egl_render_startup(void * opaque)
return false;
}
// glew is needed for imgui
if (!glewInit())
{
DEBUG_ERROR("GLEW failed to initialize");
return false;
}
if (!ImGui_ImplOpenGL3_Init("#version 100"))
{
DEBUG_ERROR("Failed to initialize ImGui");
return false;
}
this->imgui = true;
return true;
}
@@ -866,6 +888,13 @@ bool egl_render(void * opaque, LG_RendererRotate rotate)
egl_fps_render(this->fps, this->screenScaleX, this->screenScaleY);
egl_help_render(this->help, this->screenScaleX, this->screenScaleY);
if (app_renderImGui())
{
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplOpenGL3_RenderDrawData(igGetDrawData());
}
app_eglSwapBuffers(this->display, this->surface, damage, damageIdx);
return true;
}

View File

@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.0)
project(renderer_Opengl LANGUAGES C)
project(renderer_Opengl LANGUAGES C CXX)
find_package(PkgConfig)
pkg_check_modules(RENDERER_OPENGL_PKGCONFIG REQUIRED
@@ -8,12 +8,17 @@ pkg_check_modules(RENDERER_OPENGL_PKGCONFIG REQUIRED
add_library(renderer_OpenGL STATIC
opengl.c
${PROJECT_TOP}/repos/cimgui/imgui/backends/imgui_impl_opengl2.cpp
)
target_compile_definitions(renderer_OpenGL PRIVATE CIMGUI_DEFINE_ENUMS_AND_STRUCTS=1)
target_link_libraries(renderer_OpenGL
${RENDERER_OPENGL_PKGCONFIG_LIBRARIES}
lg_common
fonts
cimgui
)
target_include_directories(renderer_OpenGL

View File

@@ -29,6 +29,9 @@
#include <GL/gl.h>
#include <GL/glx.h>
#include "cimgui.h"
#include "generator/output/cimgui_impl.h"
#include "common/debug.h"
#include "common/option.h"
#include "common/framebuffer.h"
@@ -272,6 +275,8 @@ void opengl_deinitialize(void * opaque)
if (this->renderStarted)
{
ImGui_ImplOpenGL2_Shutdown();
glDeleteLists(this->texList , BUFFER_COUNT);
glDeleteLists(this->mouseList, 1);
glDeleteLists(this->fpsList , 1);
@@ -581,6 +586,13 @@ bool opengl_render_startup(void * opaque)
this->hasTextures = true;
app_glSetSwapInterval(this->opt.vsync ? 1 : 0);
if (!ImGui_ImplOpenGL2_Init())
{
DEBUG_ERROR("Failed to initialize ImGui");
return false;
}
this->renderStarted = true;
return true;
}
@@ -690,6 +702,12 @@ bool opengl_render(void * opaque, LG_RendererRotate rotate)
break;
}
if (app_renderImGui())
{
ImGui_ImplOpenGL2_NewFrame();
ImGui_ImplOpenGL2_RenderDrawData(igGetDrawData());
}
if (this->opt.preventBuffer)
{
app_glSwapBuffers();