diff options
-rw-r--r-- | examples/cube/ex_cube.c | 10 | ||||
-rw-r--r-- | src/defines.h | 5 | ||||
-rw-r--r-- | src/renderer/archive/old_backend_vulkan.c | 6 | ||||
-rw-r--r-- | src/renderer/backends/backend_vulkan.c | 2 | ||||
-rw-r--r-- | src/renderer/backends/opengl/backend_opengl.c | 37 | ||||
-rw-r--r-- | src/renderer/backends/opengl/backend_opengl.h | 4 | ||||
-rw-r--r-- | src/renderer/render_types.h | 2 | ||||
-rw-r--r-- | xmake.lua | 7 |
8 files changed, 51 insertions, 22 deletions
diff --git a/examples/cube/ex_cube.c b/examples/cube/ex_cube.c index b87071f..7b0ab48 100644 --- a/examples/cube/ex_cube.c +++ b/examples/cube/ex_cube.c @@ -68,8 +68,14 @@ int main() { gpu_renderpass_desc pass_description = {}; gpu_renderpass* renderpass = gpu_renderpass_create(&pass_description); - str8 vert_path = str8lit("build/linux/x86_64/debug/cube.vert.spv"); - str8 frag_path = str8lit("build/linux/x86_64/debug/cube.frag.spv"); + str8 vert_path, frag_path; +#ifdef CEL_REND_BACKEND_OPENGL + vert_path = str8lit("assets/shaders/blinn_phong.vert"); + frag_path = str8lit("assets/shaders/blinn_phong.frag"); +#else + vert_path = str8lit("build/linux/x86_64/debug/cube.vert.spv"); + frag_path = str8lit("build/linux/x86_64/debug/cube.frag.spv"); +#endif str8_opt vertex_shader = str8_from_file(&scratch, vert_path); str8_opt fragment_shader = str8_from_file(&scratch, frag_path); if (!vertex_shader.has_value || !fragment_shader.has_value) { diff --git a/src/defines.h b/src/defines.h index 4b6f8c7..a35dbf4 100644 --- a/src/defines.h +++ b/src/defines.h @@ -64,10 +64,11 @@ Renderer backend defines: #define CEL_REND_BACKEND_METAL 1 */ +// NOTE: The below is now handled in xmake.lua // Platform will inform renderer backend (unless user overrides) #if defined(CEL_PLATFORM_LINUX) -// #define CEL_REND_BACKEND_OPENGL 1 -#define CEL_REND_BACKEND_VULKAN 1 +#define CEL_REND_BACKEND_OPENGL 1 +// #define CEL_REND_BACKEND_VULKAN 1 #endif #if defined(CEL_PLATFORM_WINDOWS) diff --git a/src/renderer/archive/old_backend_vulkan.c b/src/renderer/archive/old_backend_vulkan.c index a18ca70..0dfba98 100644 --- a/src/renderer/archive/old_backend_vulkan.c +++ b/src/renderer/archive/old_backend_vulkan.c @@ -1,8 +1,8 @@ -#include "camera.h" -#include "primitives.h" #define CDEBUG -#define CEL_REND_BACKEND_VULKAN 1 +// #define CEL_REND_BACKEND_VULKAN 1 #if CEL_REND_BACKEND_VULKAN +#include "camera.h" +#include "primitives.h" // ^ Temporary #include <assert.h> diff --git a/src/renderer/backends/backend_vulkan.c b/src/renderer/backends/backend_vulkan.c index 10358f1..c3fad75 100644 --- a/src/renderer/backends/backend_vulkan.c +++ b/src/renderer/backends/backend_vulkan.c @@ -1,4 +1,4 @@ -#if defined (CEL_REND_BACKEND_VULKAN) +#if defined(CEL_REND_BACKEND_VULKAN) #include <assert.h> #include <glfw3.h> diff --git a/src/renderer/backends/opengl/backend_opengl.c b/src/renderer/backends/opengl/backend_opengl.c index 4ceba8f..cbc90f2 100644 --- a/src/renderer/backends/opengl/backend_opengl.c +++ b/src/renderer/backends/opengl/backend_opengl.c @@ -1,19 +1,22 @@ +#include "colours.h" #define CEL_REND_BACKEND_OPENGL #if defined(CEL_REND_BACKEND_OPENGL) #include <stdlib.h> #include "camera.h" +#include "backend_opengl.h" #include "defines.h" #include "file.h" #include "log.h" #include "maths_types.h" #include "ral.h" -#include "backend_opengl.h" #include <glad/glad.h> #include <glfw3.h> -typedef struct opengl_context {} opengl_context; +typedef struct opengl_context { + GLFWwindow* window; +} opengl_context; static opengl_context context; @@ -21,11 +24,23 @@ struct GLFWwindow; bool gpu_backend_init(const char* window_name, struct GLFWwindow* window) { INFO("loading OpenGL backend"); - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); + + memset(&context, 0, sizeof(opengl_context)); + context.window = window; + + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); + // glad: load all OpenGL function pointers + if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { + ERROR("Failed to initialise GLAD \n"); + return false; + } + + glEnable(GL_DEPTH_TEST); + return true; } @@ -48,10 +63,17 @@ bool gpu_swapchain_create(gpu_swapchain* out_swapchain) {} void gpu_swapchain_destroy(gpu_swapchain* swapchain) {} // --- Command buffer -gpu_cmd_encoder gpu_cmd_encoder_create(); +gpu_cmd_encoder gpu_cmd_encoder_create() { + gpu_cmd_encoder encoder = { 0 }; + return encoder; +} void gpu_cmd_encoder_destroy(gpu_cmd_encoder* encoder) {} void gpu_cmd_encoder_begin(gpu_cmd_encoder encoder) {} -void gpu_cmd_encoder_begin_render(gpu_cmd_encoder* encoder, gpu_renderpass* renderpass) {} +void gpu_cmd_encoder_begin_render(gpu_cmd_encoder* encoder, gpu_renderpass* renderpass) { + rgba clear_colour = STONE_900; + glClearColor(clear_colour.r, clear_colour.g, clear_colour.b, 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +} void gpu_cmd_encoder_end_render(gpu_cmd_encoder* encoder) {} void gpu_cmd_encoder_begin_compute() {} gpu_cmd_encoder* gpu_get_default_cmd_encoder() {} @@ -104,10 +126,11 @@ bytebuffer vertices_as_bytebuffer(arena* a, vertex_format format, vertex_darray* // --- TEMP bool gpu_backend_begin_frame() { return true; } -void gpu_backend_end_frame() {} +void gpu_backend_end_frame() { + glfwSwapBuffers(context.window); +} void gpu_temp_draw(size_t n_verts) {} - // /** @brief Internal backend state */ // typedef struct opengl_state { // } opengl_state; diff --git a/src/renderer/backends/opengl/backend_opengl.h b/src/renderer/backends/opengl/backend_opengl.h index 3bc742d..649bc7b 100644 --- a/src/renderer/backends/opengl/backend_opengl.h +++ b/src/renderer/backends/opengl/backend_opengl.h @@ -1,8 +1,6 @@ #pragma once -#define CEL_REND_BACKEND_OPENGL - -#if defined(CEL_REND_BACKEND_OPENGL) +#ifdef CEL_REND_BACKEND_OPENGL #include "defines.h" #include "maths_types.h" diff --git a/src/renderer/render_types.h b/src/renderer/render_types.h index ed5c6e1..aeedf85 100644 --- a/src/renderer/render_types.h +++ b/src/renderer/render_types.h @@ -21,6 +21,8 @@ #include "backend_opengl.h" #endif +#include "backend_opengl.h" + struct GLFWwindow; /** @brief configuration passed to the renderer at init time */ @@ -17,11 +17,10 @@ elseif is_mode("release") then add_defines("CRELEASE") end - -- Platform defines and system packages if is_plat("linux") then add_defines("CEL_PLATFORM_LINUX") - add_syslinks("vulkan", "dl", "X11", "pthread") + add_syslinks("dl", "X11", "pthread") elseif is_plat("windows") then add_defines("CEL_PLATFORM_WINDOWS") add_syslinks("user32", "gdi32", "kernel32", "shell32") @@ -95,12 +94,11 @@ rule("compile_glsl_frag_shaders") end) -- TODO: Metal shaders compilation --- - -- common configuration for both static and shared libraries target("core_config") set_kind("static") -- kind is required but you can ignore it since it's just for common settings add_packages("local_glfw") + add_defines("CEL_REND_BACKEND_OPENGL") add_includedirs("deps/cgltf", {public = true}) add_includedirs("deps/glfw-3.3.8/include/GLFW", {public = true}) add_includedirs("deps/glad/include", {public = true}) @@ -172,6 +170,7 @@ target("tri") target("cube") set_kind("binary") set_group("examples") + -- add_defines("CEL_REND_BACKEND_OPENGL") add_deps("core_static") add_files("examples/cube/ex_cube.c") set_rundir("$(projectdir)") |