Browse Source

working on refactoring imgui code

vlod 3 years ago
parent
commit
7f47b0e21f

+ 2 - 2
Pika/core/pikaRuntime/dllLoader/dllLoader.h

@@ -4,12 +4,12 @@
 #include <imgui.h>
 #include <pikaImgui/pikaImgui.h>
 
-#define TESTSTART(x) void x(pika::ImguiAndGlfwContext pikaContext)
+#define TESTSTART(x) void x(pika::PikaContext pikaContext)
 typedef TESTSTART(testStart_t);
 //extern "C" __declspec(dllexport) TESTPRINT(gameLogic);
 #undef TESTSTART
 
-#define TESTUPDATE(x) void x(pika::ImguiAndGlfwContext pikaContext)
+#define TESTUPDATE(x) void x(pika::PikaContext pikaContext)
 typedef TESTUPDATE(testUpdate_t);
 #undef TESTUPDATE
 

+ 0 - 30
Pika/core/pikaRuntime/pikaImgui/pikaImgui.h

@@ -1,30 +0,0 @@
-#pragma once
-#include <pikaConfig.h>
-
-
-#include "imgui.h"
-#include "backends/imgui_impl_glfw.h"
-#include "backends/imgui_impl_opengl3.h"
-#include "imguiThemes.h"
-
-#include <GLFW/glfw3.h>
-
-namespace pika
-{
-
-	struct ImguiAndGlfwContext
-	{
-		using glfwMakeContextCurrent_t = decltype(glfwMakeContextCurrent);
-
-		glfwMakeContextCurrent_t *glfwMakeContextCurrentPtr = {};
-		GLFWwindow *wind = {};
-		ImGuiContext *ImGuiContext = {};
-	};
-
-	ImGuiContext *initImgui(ImguiAndGlfwContext imguiAndGlfwContext);
-	void setContext(ImguiAndGlfwContext imguiAndGlfwContext);
-	void imguiStartFrame(ImguiAndGlfwContext imguiAndGlfwContext);
-	void imguiEndFrame(ImguiAndGlfwContext imguiAndGlfwContext);
-
-
-};

+ 1 - 6
Pika/core/pikaRuntime/pikaMain.cpp

@@ -24,7 +24,7 @@ int main()
 
 	//glfwSetErrorCallback(error_callback); todo
 
-	pika::ImguiAndGlfwContext context = {};
+	pika::PikaContext context = {};
 
 	context.wind = glfwCreateWindow(640, 480, "Pika", NULL, NULL);
 	if (!context.wind)
@@ -53,11 +53,6 @@ int main()
 
 		pika::imguiEndFrame(context);
 
-		//pika::setContext(context);
-		//pika::imguiStartFrame();
-		//ImGui::Begin("test");
-		//ImGui::End();
-		//pika::imguiEndFrame(window);
 
 
 		glfwPollEvents();

+ 17 - 0
Pika/core/pikaSTD/pikaContext.h

@@ -0,0 +1,17 @@
+#pragma once
+
+//todo remove includes here
+#include "imgui.h"
+#include <GLFW/glfw3.h>
+
+namespace pika
+{
+	struct PikaContext
+	{
+		using glfwMakeContextCurrent_t = decltype(glfwMakeContextCurrent);
+
+		glfwMakeContextCurrent_t *glfwMakeContextCurrentPtr = {};
+		GLFWwindow *wind = {};
+		ImGuiContext *ImGuiContext = {};
+	};
+};

+ 10 - 11
Pika/core/pikaRuntime/pikaImgui/pikaImgui.cpp → Pika/core/pikaSTD/pikaImgui/pikaImgui.cpp

@@ -1,7 +1,7 @@
 #include <glad/glad.h>
 #include <pikaImgui/pikaImgui.h>
 
-ImGuiContext *pika::initImgui(ImguiAndGlfwContext imguiAndGlfwContext)
+ImGuiContext *pika::initImgui(PikaContext pikaContext)
 {
 	auto context = ImGui::CreateContext();
 	//ImGui::StyleColorsDark();
@@ -23,20 +23,20 @@ ImGuiContext *pika::initImgui(ImguiAndGlfwContext imguiAndGlfwContext)
 		style.Colors[ImGuiCol_DockingEmptyBg].w = 0.f;
 	}
 	
-	ImGui_ImplGlfw_InitForOpenGL(imguiAndGlfwContext.wind, true);
+	ImGui_ImplGlfw_InitForOpenGL(pikaContext.wind, true);
 	ImGui_ImplOpenGL3_Init("#version 330");
 
 	return context;
 }
 
-void pika::setContext(ImguiAndGlfwContext imguiAndGlfwContext)
+void pika::setContext(PikaContext pikaContext)
 {
-	ImGui::SetCurrentContext(imguiAndGlfwContext.ImGuiContext);
+	ImGui::SetCurrentContext(pikaContext.ImGuiContext);
 }
 
-void pika::imguiStartFrame(ImguiAndGlfwContext imguiAndGlfwContext)
+void pika::imguiStartFrame(PikaContext pikaContext)
 {
-	setContext(imguiAndGlfwContext);
+	setContext(pikaContext);
 	ImGui_ImplOpenGL3_NewFrame();
 	ImGui_ImplGlfw_NewFrame();
 	ImGui::NewFrame();
@@ -44,12 +44,12 @@ void pika::imguiStartFrame(ImguiAndGlfwContext imguiAndGlfwContext)
 }
 
 
-void pika::imguiEndFrame(ImguiAndGlfwContext imguiAndGlfwContext)
+void pika::imguiEndFrame(PikaContext pikaContext)
 {
-	setContext(imguiAndGlfwContext);
+	setContext(pikaContext);
 	ImGui::Render();
 	int display_w = 0, display_h = 0;
-	glfwGetFramebufferSize(imguiAndGlfwContext.wind, &display_w, &display_h);
+	glfwGetFramebufferSize(pikaContext.wind, &display_w, &display_h);
 	glViewport(0, 0, display_w, display_h);
 	ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
 
@@ -67,8 +67,7 @@ void pika::imguiEndFrame(ImguiAndGlfwContext imguiAndGlfwContext)
 
 		ImGui::UpdatePlatformWindows();
 		ImGui::RenderPlatformWindowsDefault();
-		imguiAndGlfwContext.glfwMakeContextCurrentPtr(imguiAndGlfwContext.wind); //idea create a class with some functions
-
+		pikaContext.glfwMakeContextCurrentPtr(pikaContext.wind); //idea create a class with some functions
 	
 	}
 }

+ 24 - 0
Pika/core/pikaSTD/pikaImgui/pikaImgui.h

@@ -0,0 +1,24 @@
+#pragma once
+#include <pikaConfig.h>
+
+
+#include "imgui.h"
+#include "backends/imgui_impl_glfw.h"
+#include "backends/imgui_impl_opengl3.h"
+#include "imguiThemes.h"
+
+#include <GLFW/glfw3.h>
+
+#include <pikaContext.h>
+
+namespace pika
+{
+
+
+	ImGuiContext *initImgui(PikaContext pikaContext);
+	void setContext(PikaContext pikaContext);
+	void imguiStartFrame(PikaContext pikaContext);
+	void imguiEndFrame(PikaContext pikaContext);
+
+
+};

+ 2 - 2
Pika/gameplay/dllMain.cpp

@@ -9,7 +9,7 @@
 gl2d::Renderer2D renderer;
 
 
-PIKA_API void testStart(pika::ImguiAndGlfwContext pikaContext)
+PIKA_API void testStart(pika::PikaContext pikaContext)
 {
 	
 	//PIKA_PERMA_ASSERT(glfwInit(), "Problem initializing glfw from dll");
@@ -35,7 +35,7 @@ void userFree(void *ptr, void *)
 	free(ptr);
 }
 
-PIKA_API void testUpdate(pika::ImguiAndGlfwContext pikaContext)
+PIKA_API void testUpdate(pika::PikaContext pikaContext)
 {
 	gl2d::enableNecessaryGLFeatures();
 	renderer.updateWindowMetrics(640, 480);

+ 2 - 2
Pika/gameplay/dllMain.h

@@ -4,5 +4,5 @@
 #include <imgui.h>
 #include <pikaImgui/pikaImgui.h>
 
-PIKA_API void testStart(pika::ImguiAndGlfwContext pikaContext);
-PIKA_API void testUpdate(pika::ImguiAndGlfwContext pikaContext);
+PIKA_API void testStart(pika::PikaContext pikaContext);
+PIKA_API void testUpdate(pika::PikaContext pikaContext);