Skip to content

Commit

Permalink
fix visible_precise initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
kannoneer committed Sep 23, 2023
1 parent 4a07b6f commit dc093dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
4 changes: 0 additions & 4 deletions examples/occlusion/occdemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ void render()
matrix_t cube_model;

matrix_mult_full(&cube_model, &cube_translate, &cube_rotate);
// debugf("cube model\n");
// print_matrix(&cube_model);

// Occlusion culling

Expand All @@ -252,8 +250,6 @@ void render()
box.hitX = raster_query.x;
box.hitY = raster_query.y;
box.udepth = raster_query.depth;
debugf("raster_query_result: %s, (%d, %d)\n", raster_query.visible ? "visible" : "hidden", raster_query.x, raster_query.y);
// debugf("cube_visible: %d at depth: %u\n",cube_visible, box.udepth);
occ_draw_indexed_mesh(culler, sw_zbuffer, &cube_model, cube_vertices, cube_indices, sizeof(cube_indices) / sizeof(cube_indices[0]));

if (cube_visible || config_show_wireframe) {
Expand Down
19 changes: 11 additions & 8 deletions examples/occlusion/occlusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ const float inv_subpixel_scale = 1.0f / SUBPIXEL_SCALE;
#define OCC_MAX_Z (0xffff)

#define ZBUFFER_UINT_PTR_AT(zbuffer, x, y) ((u_uint16_t *)(zbuffer->buffer + (zbuffer->stride * y + x * sizeof(uint16_t))))
// u_uint16_t* buf = (u_uint16_t*)(zbuffer->buffer + (zbuffer->stride * p.y + p.x * sizeof(uint16_t)))

bool g_verbose_setup = false;
bool g_measure_error = false;
bool g_verbose_raster = false; // print depth at vertex pixels
bool g_verbose_early_out = false; // print coordinates of pixels that pass the depth test
bool config_discard_based_on_tr_code = false;

enum {
Expand Down Expand Up @@ -346,7 +346,9 @@ void draw_tri3(
result->x = p.x;
result->y = p.y;
result->depth = depth;
debugf("visible at (%d, %d), v0=(%d,%d)\n", p.x, p.y, v0.x>>SUBPIXEL_BITS, v0.y>>SUBPIXEL_BITS);
if (g_verbose_early_out) {
debugf("visible at (%d, %d), v0=(%d,%d)\n", p.x, p.y, v0.x>>SUBPIXEL_BITS, v0.y>>SUBPIXEL_BITS);
}
return; // early out was requested
} else {
*buf = depth;
Expand Down Expand Up @@ -558,11 +560,12 @@ bool occ_check_mesh_visible_rough(occ_culler_t *occ, surface_t *zbuffer, matrix_
}

bool occ_check_mesh_visible_precise(occ_culler_t *occ, surface_t *zbuffer, const matrix_t *model_xform,
const vertex_t *vertices, const uint16_t *indices, uint32_t num_indices, occ_raster_query_result_t *out_result)
const vertex_t *vertices, const uint16_t *indices, uint32_t num_indices, occ_raster_query_result_t *out_result)
{
assert(out_result);
//occ_raster_query_result_t result;
occ_draw_indexed_mesh_flags(occ, zbuffer, model_xform, vertices, indices, num_indices, OCC_RASTER_FLAGS_QUERY, out_result);
//if (out_result) *out_result = result;
return out_result->visible;
occ_raster_query_result_t result = {};
occ_draw_indexed_mesh_flags(occ, zbuffer, model_xform, vertices, indices, num_indices, OCC_RASTER_FLAGS_QUERY, &result);
if (out_result) {
*out_result = result;
}
return result.visible;
}

0 comments on commit dc093dc

Please sign in to comment.