summaryrefslogtreecommitdiff
path: root/src/renderer/render.c
blob: f73578e9062884c940d3ab845a6dc22425819aa4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "render.h"
#include <glfw3.h>
#include "camera.h"
#include "log.h"
#include "ral.h"

/** @brief Creates the pipelines built into Celeritas such as rendering static opaque geometry,
           debug visualisations, immediate mode UI, etc */
void default_pipelines_init(renderer* ren);

bool renderer_init(renderer* ren) {
  // INFO("Renderer init");

  // NOTE: all platforms use GLFW at the moment but thats subject to change
  glfwInit();

#if defined(CEL_REND_BACKEND_OPENGL)
  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);
#elif defined(CEL_REND_BACKEND_VULKAN)
  glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
#endif

  // glfw window creation
  GLFWwindow* window = glfwCreateWindow(ren->config.scr_width, ren->config.scr_height,
                                        ren->config.window_name, NULL, NULL);
  if (window == NULL) {
    // ERROR("Failed to create GLFW window\n");
    glfwTerminate();
    return false;
  }
  ren->window = window;

  glfwMakeContextCurrent(ren->window);

  DEBUG("Start backend init");

  gpu_backend_init("Celeritas Engine - Vulkan", window);
  gpu_device_create(&ren->device);  // TODO: handle errors
  gpu_swapchain_create(&ren->swapchain);

  // DEBUG("init graphics api backend");
  // if (!gfx_backend_init(ren)) {
  // FATAL("Couldnt load graphics api backend");
  // return false;
  // }

  default_pipelines_init(ren);

  // ren->blinn_phong =
  //     shader_create_separate("assets/shaders/blinn_phong.vert",
  //     "assets/shaders/blinn_phong.frag");

  // ren->skinned =
  //     shader_create_separate("assets/shaders/skinned.vert", "assets/shaders/blinn_phong.frag");

  // default_material_init();

  return true;
}
void renderer_shutdown(renderer* ren) {
  gpu_swapchain_destroy(&ren->swapchain);
  gpu_pipeline_destroy(&ren->static_opaque_pipeline);
  gpu_backend_shutdown();
}

void default_pipelines_init(renderer* ren) {
  // Static opaque geometry
  // graphics_pipeline_desc gfx = {
  // };
  // ren->static_opaque_pipeline = gpu_graphics_pipeline_create();
}

void render_frame_begin(renderer* ren) {}
void render_frame_end(renderer* ren) {}
void render_frame_draw(renderer* ren) {}

void gfx_backend_draw_frame(renderer* ren, camera* camera, mat4 model, texture* tex) {}

void geo_set_vertex_colours(geometry_data* geo, vec4 colour) {}