Base refactor

This commit is contained in:
2023-11-14 09:16:48 -06:00
parent 214082d00f
commit 1817dcaf3a
410 changed files with 749 additions and 20823 deletions

View File

@ -0,0 +1,10 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
RenderHost.cpp
)

View File

@ -0,0 +1,95 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "RenderHost.hpp"
#include "assert/assertgl.hpp"
#include "assert/assert.hpp"
using namespace Dawn;
RenderHost::RenderHost() {
}
void RenderHost::init() {
// Init GLFW
if(!glfwInit()) {
throw std::runtime_error("Failed to initialize GLFW!");
}
// Set the error callback for error handling.
glfwSetErrorCallback([](int error, const char *description) {
throw std::runtime_error(description);
});
// Setup window hints
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, false);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
// Create the window
window = glfwCreateWindow(
DAWN_GLFW_WINDOW_WIDTH_DEFAULT,
DAWN_GLFW_WINDOW_HEIGHT_DEFAULT,
"Dawn",
NULL,
NULL
);
// Validate window exists
if(!window) {
throw std::runtime_error("Failed to create GLFW window!");
}
// Load GLAD
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
assertNoGLError();
// Get the resolution and scale/dpi
int32_t fbWidth, fbHeight;
int32_t windowWidth, windowHeight;
glfwGetFramebufferSize(window, &fbWidth, &fbHeight);
glfwGetWindowSize(window, &windowWidth, &windowHeight);
assertTrue(fbWidth > 0, "Detected framebuffer width is too small?");
assertTrue(fbWidth > 0, "Detected framebuffer height is too small?");
assertTrue(windowWidth > 0, "Detected window width is too small?");
assertTrue(windowHeight > 0, "Detected window height is too small?");
// Framebuffer callback
// glfwSetFramebufferSizeCallback(window, [&](
// GLFWwindow *window,
// int32_t width,
// int32_t height
// ) {
// if(this->window == nullptr || window != this->window) return;
// std::cout << "Resize" << std::endl;
// });
}
void RenderHost::update() {
// Tick the engine.
glfwSwapBuffers(window);
// Update events
glfwPollEvents();
}
bool_t RenderHost::isCloseRequested() {
if(this->window == nullptr) return false;
return glfwWindowShouldClose(this->window);
}
RenderHost::~RenderHost() {
if(this->window != nullptr) {
glfwDestroyWindow(this->window);
this->window = nullptr;
}
glfwTerminate();
}

View File

@ -0,0 +1,46 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#define DAWN_GLFW_WINDOW_WIDTH_DEFAULT 1280
#define DAWN_GLFW_WINDOW_HEIGHT_DEFAULT 720
namespace Dawn {
class RenderHost {
public:
GLFWwindow *window = nullptr;
/**
* Initializes the GLFW RenderHost.
*/
RenderHost();
/**
* Initializes GLFW and creates the window.
*/
void init();
/**
* Performs an update and renders the frame.
*/
void update();
/**
* Returns whether or not GLFW has been requested to close.
*
* @return True if GLFW has been requested to close.
*/
bool_t isCloseRequested();
/**
* Cleans up GLFW.
*/
virtual ~RenderHost();
};
}