Skip to content

Commit

Permalink
Fixed the flat pipeline and split out being and end pass from the
Browse files Browse the repository at this point in the history
rendering function
  • Loading branch information
tanis2000 committed Oct 16, 2024
1 parent 9cef91f commit 831ad72
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 17 deletions.
53 changes: 36 additions & 17 deletions src/binocle/core/binocle_gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,17 +410,32 @@ void binocle_gd_render_screen(binocle_gd *gd, struct binocle_window *window, flo

gd->display.bind.fs.images[0] = gd->offscreen.render_target;

sg_begin_pass(&(sg_pass){
.action = gd->display.action,
.swapchain = binocle_window_get_swapchain(window),
});
// sg_begin_pass(&(sg_pass){
// .action = gd->display.action,
// .swapchain = binocle_window_get_swapchain(window),
// });
sg_apply_pipeline(gd->display.pip);
sg_apply_bindings(&gd->display.bind);
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(screen_vs_params));
sg_apply_uniforms(SG_SHADERSTAGE_FS, 0, &SG_RANGE(screen_fs_params));
sg_draw(0, 6, 1);
// sg_end_pass();

// sg_commit();
}

void binocle_gd_begin_screen_pass(binocle_gd *gd, binocle_window *window) {
sg_begin_pass(&(sg_pass){
.action = gd->display.action,
.swapchain = binocle_window_get_swapchain(window),
});
}

void binocle_gd_end_screen_pass() {
sg_end_pass();
}

void binocle_gd_commit() {
sg_commit();
}

Expand All @@ -438,10 +453,9 @@ void binocle_gd_setup_flat_pipeline(binocle_gd *gd, const char *vs_src, const ch
#endif
.vs.uniform_blocks[0] = {
.size = sizeof(struct binocle_gd_flat_shader_vs_params_t),
.layout = SG_UNIFORMLAYOUT_STD140,
.uniforms = {
[0] = { .name = "projectionMatrix", .type = SG_UNIFORMTYPE_MAT4 },
[1] = { .name = "viewMatrix", .type = SG_UNIFORMTYPE_MAT4 },
[2] = { .name = "modelMatrix", .type = SG_UNIFORMTYPE_MAT4 },
[0] = { .name = "vs_params", .type = SG_UNIFORMTYPE_FLOAT4, .array_count = 12 },
},
},
.attrs = {
Expand All @@ -466,8 +480,9 @@ void binocle_gd_setup_flat_pipeline(binocle_gd *gd, const char *vs_src, const ch

sg_pass_action action = {
.colors[0] = {
.load_action = SG_LOADACTION_DONTCARE,
.load_action = SG_LOADACTION_LOAD,
.clear_value = {0.0f, 1.0f, 0.0f, 1.0f},
.store_action = SG_STOREACTION_STORE,
}
};
gd->flat.action = action;
Expand All @@ -486,15 +501,15 @@ void binocle_gd_setup_flat_pipeline(binocle_gd *gd, const char *vs_src, const ch
},
},
.shader = shader,
.index_type = SG_INDEXTYPE_NONE,
.depth = {
.pixel_format = SG_PIXELFORMAT_NONE,
.compare = SG_COMPAREFUNC_NEVER,
.write_enabled = false,
},
.stencil = {
.enabled = false,
},
// .index_type = SG_INDEXTYPE_NONE,
// .depth = {
// .pixel_format = SG_PIXELFORMAT_NONE,
// .compare = SG_COMPAREFUNC_NEVER,
// .write_enabled = false,
// },
// .stencil = {
// .enabled = false,
// },
.colors = {
[0] = {
#ifdef BINOCLE_GL
Expand All @@ -506,6 +521,10 @@ void binocle_gd_setup_flat_pipeline(binocle_gd *gd, const char *vs_src, const ch
.enabled = true,
.src_factor_rgb = SG_BLENDFACTOR_SRC_ALPHA,
.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
.op_rgb = SG_BLENDOP_ADD,
.src_factor_alpha = SG_BLENDFACTOR_SRC_ALPHA,
.dst_factor_alpha = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
.op_alpha = SG_BLENDOP_ADD,
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/binocle/core/binocle_gd.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,23 @@ void binocle_gd_draw_circle(binocle_gd *gd, kmVec2 center, float radius, struct
void binocle_gd_draw_with_state(binocle_gd *gd, const struct binocle_vpct *vertices, size_t vertex_count,
struct binocle_render_state *render_state, float depth);

/**
* /brief Begins the screen pass. Multiple pipelines can be applied during this pass.
* @param gd the graphics device instance
* @param window the window instance
*/
void binocle_gd_begin_screen_pass(binocle_gd *gd, struct binocle_window *window);

/**
* /brief Ends the screen pass.
*/
void binocle_gd_end_screen_pass();

/**
* /brief Commits all the buffers after the screen pass is done
*/
void binocle_gd_commit();

void binocle_gd_draw_mesh(binocle_gd *gd, const struct binocle_mesh *mesh, kmAABB2 viewport, struct binocle_camera_3d *camera);
void binocle_gd_draw_test_triangle(struct sg_shader *shader);
void binocle_gd_draw_test_cube(struct sg_shader *shader);
Expand Down
21 changes: 21 additions & 0 deletions src/binocle/core/binocle_gd_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,24 @@ int l_binocle_gd_create_offscreen_pipeline(lua_State *L) {
return 0;
}

int l_binocle_gd_begin_screen_pass(lua_State *L) {
l_binocle_gd_t *gd = luaL_checkudata(L, 1, "binocle_gd");
l_binocle_window_t *window = luaL_checkudata(L, 2, "binocle_window");
binocle_gd_begin_screen_pass(gd->gd, window->window);

return 0;
}

int l_binocle_gd_end_screen_pass(lua_State *L) {
binocle_gd_end_screen_pass();
return 0;
}

int l_binocle_gd_commit(lua_State *L) {
binocle_gd_commit();
return 0;
}

static const struct luaL_Reg gd [] = {
{"new", l_binocle_gd_new},
{"init", l_binocle_gd_init},
Expand All @@ -254,6 +272,9 @@ static const struct luaL_Reg gd [] = {
{"add_uniform_to_shader_desc", l_binocle_gd_add_uniform_to_shader_desc},
{"create_shader", l_binocle_gd_create_shader},
{"create_pipeline", l_binocle_gd_create_offscreen_pipeline},
{"begin_screen_pass", l_binocle_gd_begin_screen_pass},
{"end_screen_pass", l_binocle_gd_end_screen_pass},
{"commit", l_binocle_gd_commit},
{NULL, NULL}
};

Expand Down

0 comments on commit 831ad72

Please sign in to comment.