[WIP] Refactor project
There are many problems with the way the current version is provided and maintained. This commit or series of commits will fix this.
This commit is contained in:
1 parent
f5ab5f3f27
commit
173a82b9d1
63 files changed
+2663
-2239
No files matched your search
+89
-43
@@ -1,57 +1,65 @@
|
||||
#include "rse_graphics.h"
|
||||
#include "src/rse_text_renderer.h"
|
||||
#include "utilities/localization.h"
|
||||
#include "window.h"
|
||||
#include "vulkan_base.h"
|
||||
|
||||
#include "mesh_controller.h"
|
||||
#include "vulkan_commons.h"
|
||||
#include "rse_vulkan_image.h"
|
||||
#include "pipeline_builder.h"
|
||||
#include "utilities/logger.h"
|
||||
#include "utilities/rse_commons.h"
|
||||
#include "utilities/rse_errors_common.h"
|
||||
#include "utilities/commons.h"
|
||||
#include "utilities/errors_common.h"
|
||||
#include "graphics_context.h"
|
||||
|
||||
#include "rse_math.h"
|
||||
#include "math.h"
|
||||
|
||||
extern struct rse_vulkan_state_t g_vulkan_state;
|
||||
struct rse_graphics_context_t {
|
||||
struct graphics_context_t* context;
|
||||
};
|
||||
|
||||
|
||||
rse_err_t rse_graphics_init(void)
|
||||
rse_err_t rse_graphics_init(struct rse_graphics_context_t* context)
|
||||
{
|
||||
rse_err_t status = RSE_ERROR_NO_ERROR;
|
||||
g_vulkan_state.graphics_queue = VK_NULL_HANDLE;
|
||||
g_vulkan_state.physical_device = VK_NULL_HANDLE;
|
||||
g_vulkan_state.current_frame = 0U;
|
||||
g_vulkan_state.render_pass = VK_NULL_HANDLE;
|
||||
g_vulkan_state.descriptor_set_layout = VK_NULL_HANDLE;
|
||||
g_vulkan_state.graphics_pipeline = VK_NULL_HANDLE;
|
||||
g_vulkan_state.pipeline_layout = VK_NULL_HANDLE;
|
||||
g_vulkan_state.swapchain = VK_NULL_HANDLE;
|
||||
if (context != NULL) {
|
||||
LOGF(_("Graphics already initialized!\n"));
|
||||
return RSE_ERROR_ALREADY_INITIALIZED;
|
||||
}
|
||||
|
||||
STATUS_CHECK(window_init());
|
||||
STATUS_CHECK(preinit_vulkan());
|
||||
rse_malloc(context, sizeof(struct rse_graphics_context_t));
|
||||
rse_malloc(context->context, sizeof(struct graphics_context_t));
|
||||
rse_memset(context->context, 0, sizeof(struct graphics_context_t));
|
||||
|
||||
STATUS_CHECK(window_init(context->context->window_handle, &context->context->is_framebuffer_resized));
|
||||
STATUS_CHECK(init_vulkan(context->context));
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void rse_graphics_test_function(void)
|
||||
void rse_graphics_test_function(struct rse_graphics_context_t* rse_context)
|
||||
{
|
||||
rse_err_t status = RSE_ERROR_NO_ERROR;
|
||||
struct graphics_context_t* context = rse_context->context;
|
||||
// rse_err_t status = RSE_ERROR_NO_ERROR;
|
||||
uint16_t tex_id_2 = 0;
|
||||
size_t ubo_index = 0;
|
||||
size_t sampler_index = 0;
|
||||
struct pipeline_t* pipeline = NULL;
|
||||
struct binding_info_t binding_infos[2] = {0};
|
||||
struct pipeline_infos_list_t* pipeline_infos = NULL;
|
||||
|
||||
status = rse_load_texture_from_file("../../test_image.jpg", &tex_id_2);
|
||||
if (status != RSE_ERROR_NO_ERROR) {
|
||||
LOGE("Failed to do something. Check error messages. Error: %d", status);
|
||||
return;
|
||||
}
|
||||
rse_fonts_initialize();
|
||||
// status = load_texture_from_file("../../test_image.jpg", &tex_id_2);
|
||||
// if (status != RSE_ERROR_NO_ERROR) {
|
||||
// LOGE("Failed to do something. Check error messages. Error: %d", status);
|
||||
// return;
|
||||
// }
|
||||
// fonts_initialize();
|
||||
|
||||
// FIXME: Temporary array of vertices, for testing purposes
|
||||
struct rse_vertex_t vertices[] = {{{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}},
|
||||
struct vertex_t vertices[] = {{{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}},
|
||||
{{0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
|
||||
{{0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
|
||||
{{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}}};
|
||||
|
||||
struct rse_vertex_t vertices2[] = {{{-0.5f, -0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}},
|
||||
struct vertex_t vertices2[] = {{{-0.5f, -0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}},
|
||||
{{0.5f, -0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {1.0f, 0.0f}},
|
||||
{{0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {1.0f, 1.0f}},
|
||||
{{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}}};
|
||||
@@ -59,43 +67,81 @@ void rse_graphics_test_function(void)
|
||||
// FIXME: Temporary array of vertices, for testing purposes
|
||||
uint16_t indices[] = {0, 1, 2, 2, 3, 0};
|
||||
|
||||
uint16_t mesh_id = create_mesh(vertices, indices, 6, 6);
|
||||
create_mesh_instance(mesh_id, (struct rse_instance_data_t){
|
||||
uint16_t mesh_id = create_mesh(context, vertices, indices, 6, 6);
|
||||
create_mesh_instance(context, mesh_id, (struct instance_data_t){
|
||||
{0.0f, 0.0f, 2.4f},
|
||||
{0.0f, 0.0f, rse_math_deg_to_radians(45.0f)},
|
||||
{0.0f, 0.0f, math_deg_to_radians(45.0f)},
|
||||
1.0f,
|
||||
tex_id_2
|
||||
});
|
||||
|
||||
create_mesh_instance(mesh_id, (struct rse_instance_data_t){
|
||||
create_mesh_instance(context, mesh_id, (struct instance_data_t){
|
||||
{-0.5f, 0.0f, -1.0f},
|
||||
{0.0f, 0.0f, rse_math_deg_to_radians(10.0f)},
|
||||
{0.0f, 0.0f, math_deg_to_radians(10.0f)},
|
||||
1.0f,
|
||||
tex_id_2
|
||||
});
|
||||
|
||||
mesh_id = create_mesh(vertices2, indices, 6, 6);
|
||||
create_mesh_instance(mesh_id, (struct rse_instance_data_t){
|
||||
mesh_id = create_mesh(context, vertices2, indices, 6, 6);
|
||||
create_mesh_instance(context, mesh_id, (struct instance_data_t){
|
||||
{2.0f, 1.0f, 0.0f},
|
||||
{0.0f, 0.0f, rse_math_deg_to_radians(0.0f)},
|
||||
{0.0f, 0.0f, math_deg_to_radians(0.0f)},
|
||||
1.0f,
|
||||
tex_id_2
|
||||
});
|
||||
|
||||
rse_fonts_load_from_file("/usr/share/fonts/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-Medium.ttf");
|
||||
rse_print_text("Hello World!", (struct vec3_t){-1.0f, 0.0f, 0.9f}, 0.3f);
|
||||
// fonts_load_from_file("/usr/share/fonts/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-Medium.ttf");
|
||||
// print_text("Hello World!", (struct vec3_t){-1.0f, 0.0f, 0.9f}, 0.3f);
|
||||
|
||||
/* Initialize pipeline */
|
||||
pipeline_builder_init(pipeline);
|
||||
pipeline_add_shader_stage(context, pipeline, "../graphics/shaders/shader.vert.num", VK_SHADER_STAGE_VERTEX_BIT);
|
||||
pipeline_add_shader_stage(context, pipeline, "../graphics/shaders/solid_objects.frag.num", VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||
|
||||
pipeline_add_vertex_input_binding(pipeline, 0, sizeof(struct vertex_t), VK_VERTEX_INPUT_RATE_VERTEX);
|
||||
|
||||
pipeline_add_vertex_input_attribute(pipeline, 0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(struct vertex_t, pos));
|
||||
pipeline_add_vertex_input_attribute(pipeline, 1, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(struct vertex_t, color));
|
||||
pipeline_add_vertex_input_attribute(pipeline, 2, 0, VK_FORMAT_R32G32_SFLOAT, offsetof(struct vertex_t, tex_coords));
|
||||
pipeline_add_vertex_input_attribute(pipeline, 3, 1, VK_FORMAT_R32G32B32_SFLOAT, offsetof(struct instance_data_t, pos));
|
||||
pipeline_add_vertex_input_attribute(pipeline, 4, 1, VK_FORMAT_R32G32B32_SFLOAT, offsetof(struct instance_data_t, rot));
|
||||
pipeline_add_vertex_input_attribute(pipeline, 5, 1, VK_FORMAT_R32_SFLOAT, offsetof(struct instance_data_t, scale));
|
||||
pipeline_add_vertex_input_attribute(pipeline, 6, 1, VK_FORMAT_R32_SFLOAT, offsetof(struct instance_data_t, texture_id));
|
||||
|
||||
pipeline_add_dynamic_state(pipeline, VK_DYNAMIC_STATE_VIEWPORT);
|
||||
pipeline_add_dynamic_state(pipeline, VK_DYNAMIC_STATE_SCISSOR);
|
||||
|
||||
binding_infos[0].binding = 0;
|
||||
binding_infos[0].descriptor_type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||
binding_infos[0].stage_flags = VK_SHADER_STAGE_VERTEX_BIT;
|
||||
|
||||
binding_infos[1].binding = 1;
|
||||
binding_infos[1].descriptor_type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
binding_infos[1].stage_flags = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
|
||||
pipeline_add_descriptor_layout(context, &binding_infos[0], 1, &ubo_index);
|
||||
pipeline_add_descriptor_layout(context, &binding_infos[1], 1, &sampler_index);
|
||||
|
||||
add_pipeline(context, pipeline, pipeline_infos);
|
||||
|
||||
build_pipelines(context, pipeline_infos);
|
||||
|
||||
//TODO: Add a shader for text rendering
|
||||
// pipeline_add_shader_stage("../graphics/shaders/on_screen_text.frag.num", VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||
}
|
||||
|
||||
rse_err_t rse_graphics_run(void)
|
||||
rse_err_t rse_graphics_run(struct rse_graphics_context_t* rse_context)
|
||||
{
|
||||
rse_err_t status = RSE_ERROR_NO_ERROR;
|
||||
STATUS_CHECK(init_vulkan());
|
||||
struct graphics_context_t* context = rse_context->context;
|
||||
|
||||
STATUS_CHECK(window_loop());
|
||||
STATUS_CHECK(init_vulkan(context));
|
||||
|
||||
deinit_vulkan();
|
||||
STATUS_CHECK(window_loop(context));
|
||||
|
||||
window_terminate();
|
||||
deinit_vulkan(context);
|
||||
|
||||
window_terminate(context->window_handle);
|
||||
|
||||
return status;
|
||||
}
|
||||
Reference in new issue
Block a user