move utils to include. utils implimentations should be headers

This commit is contained in:
2025-03-26 13:07:18 -05:00
parent 12c82a8327
commit fd6a774c73
15 changed files with 110 additions and 131 deletions

View File

@@ -24,8 +24,6 @@
src = ./.; src = ./.;
#imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [ nativeBuildInputs = with pkgs; [
gcc gcc
]; ];
@@ -38,8 +36,8 @@
buildPhase = '' buildPhase = ''
g++ \ g++ \
src/*.cpp \ src/*.cpp \
utils/Window/*.cpp utils/Window/WindowGLFW/*.cpp \ utils/Window/*.cpp \
utils/Renderer/*.cpp utils/Renderer/RendererOpenGL/*.cpp \ utils/Renderer/*.cpp \
-I src -I include -I utils \ -I src -I include -I utils \
-DRENDERER_OPENGL \ -DRENDERER_OPENGL \
-DWINDOW_GLFW \ -DWINDOW_GLFW \
@@ -278,7 +276,7 @@
apps.${system}.default = { apps.${system}.default = {
type = "app"; type = "app";
program = "${self.Archimedes}/bin/Archimedes ${self.TestImgui}/bin/TestImgui"; program = "${pkgs.writeShellScriptBin "RunArchimedes" "${self.Archimedes}/bin/Archimedes ${self.TestImgui}/bin/TestImgui"}";
}; };
}; };

View File

@@ -1,8 +1,8 @@
#ifndef ARCHIMEDES_H #ifndef ARCHIMEDES_H
#define ARCHIMEDES_H #define ARCHIMEDES_H
#include "Module.h" #include "utils/Module/Module.h"
#include "GuiModule.h" #include "utils/GuiModule/GuiModule.h"
#include "App.h" #include "App.h"
#endif #endif

View File

@@ -0,0 +1,39 @@
#ifdef RENDERER_OPENGL
#undef RENDERER_OPENGL
#include "pch.hpp"
#define GLEW_STATIC
#include <GL/glew.h>
namespace Archimedes {
class RendererOpenGL {
public:
typedef void renderCmd();
RendererOpenGL() {};
~RendererOpenGL() {};
void init() { glewInit(); };
void render(std::list<renderCmd*> cmdList, int& w, int& h) {
glViewport(0, 0, w, h);
glClear(GL_COLOR_BUFFER_BIT);
for(auto* f : cmdList)
f();
cmdList.clear();
}
};
typedef RendererOpenGL RendererImpl;
}
#endif

View File

@@ -0,0 +1,65 @@
#include "pch.hpp"
#ifdef WINDOW_GLFW
#undef WINDOW_GLFW
#include <GLFW/glfw3.h>
namespace Archimedes {
class WindowGLFW {
public:
WindowGLFW() {
glfwSetErrorCallback([](int e, const char* m){
std::cout << "GLFW Error: " << m << std::endl;
});
if(!glfwInit()) {
std::cout << "glfwInit failed!\n";
std::abort();
}
w = glfwCreateWindow(640, 480, "Archimedes", NULL, NULL);
if(!w) {
glfwTerminate();
std::abort();
}
std::cout << "Window Created!\n";
glfwMakeContextCurrent(w);
glfwSwapInterval(1);
}
~WindowGLFW() {
glfwTerminate();
}
bool shouldClose() {
return glfwWindowShouldClose(w);
}
void doFrame() { restoreContext(); glfwSwapBuffers(w); }
void pollEvents() { glfwPollEvents(); }
void restoreContext() { glfwMakeContextCurrent(w); }
void getSize(int& w, int& h) {
glfwGetFramebufferSize(this->w, &w, &h);
}
GLFWwindow* getWindow() { return w; }
private:
GLFWwindow* w;
};
typedef WindowGLFW WindowImpl;
}
#endif

View File

@@ -2,8 +2,7 @@
#define APP_H #define APP_H
#include "pch.hpp" #include "pch.hpp"
#include "Module.h" #include "Module/Module.h"
#include "GuiModule.h"
namespace Archimedes { namespace Archimedes {

View File

@@ -1,26 +0,0 @@
#include "RendererOpenGL.h"
#define GLEW_STATIC
#include <GL/glew.h>
namespace Archimedes {
RendererOpenGL::RendererOpenGL() {}
RendererOpenGL::~RendererOpenGL() {}
void RendererOpenGL::init() {
glewInit();
}
void RendererOpenGL::render(std::list<renderCmd*> cmdList, int& w, int& h) {
glViewport(0, 0, w, h);
glClear(GL_COLOR_BUFFER_BIT);
for(auto* f : cmdList)
f();
cmdList.clear();
}
}

View File

@@ -1,24 +0,0 @@
#ifdef RENDERER_OPENGL
#undef RENDERER_OPENGL
#include "pch.hpp"
namespace Archimedes {
class RendererOpenGL {
public:
typedef void renderCmd();
RendererOpenGL();
~RendererOpenGL();
void init();
void render(std::list<renderCmd*>, int&, int&);
};
typedef RendererOpenGL RendererImpl;
}
#endif

View File

@@ -1,38 +0,0 @@
#include "pch.hpp"
#include "WindowGLFW.h"
namespace Archimedes {
WindowGLFW::WindowGLFW() {
glfwSetErrorCallback([](int e, const char* m){
std::cout << "GLFW Error: " << m << std::endl;
});
if(!glfwInit()) {
std::cout << "glfwInit failed!\n";
std::abort();
}
w = glfwCreateWindow(640, 480, "Archimedes", NULL, NULL);
if(!w) {
glfwTerminate();
std::abort();
}
std::cout << "Window Created!\n";
glfwMakeContextCurrent(w);
glfwSwapInterval(1);
}
bool WindowGLFW::shouldClose() {
return glfwWindowShouldClose(w);
}
void WindowGLFW::getSize(int& w, int& h) {
glfwGetFramebufferSize(this->w, &w, &h);
}
WindowGLFW::~WindowGLFW() {
glfwTerminate();
}
}

View File

@@ -1,34 +0,0 @@
#ifdef WINDOW_GLFW
#undef WINDOW_GLFW
#include <GLFW/glfw3.h>
namespace Archimedes {
class WindowGLFW {
public:
WindowGLFW();
~WindowGLFW();
bool shouldClose();
void doFrame() { restoreContext(); glfwSwapBuffers(w); }
void pollEvents() { glfwPollEvents(); }
void restoreContext() { glfwMakeContextCurrent(w); }
void getSize(int&, int&);
GLFWwindow* getWindow() { return w; }
private:
GLFWwindow* w;
};
typedef WindowGLFW WindowImpl;
}
#endif