Skip to content

Commit

Permalink
Use alignas for zbuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Daft-Freak committed Aug 4, 2023
1 parent 51b551c commit 04a37cb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions engine/render_rasterize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

uint8_t shader_override = 0;

static int16_t zbuffer[SCREEN_WIDTH * SCREEN_HEIGHT] __attribute__ ((aligned (4))) = { };
alignas(4) static int16_t zbuffer[SCREEN_WIDTH * SCREEN_HEIGHT] = { };

color_t sky;

Expand Down Expand Up @@ -153,8 +153,18 @@ void RASTERIZE_SECTION render_rasterize(uint32_t num_triangle, color_t *fb) {

//precalculate area of triangle for later to find barycentric coordinates
int32_t area = (x3 - x1) * (y2 - y1) - (y3 - y1) * (x2 - x1);

//if(area == 0) area = 1;

//inverse Z coordinates
/*int32_t zi1 = triangle_list_current[current_triangle].vertex1.z;
int32_t zi2 = triangle_list_current[current_triangle].vertex2.z;
int32_t zi3 = triangle_list_current[current_triangle].vertex3.z;
zi1 = zi1 == 0 ? INT32_MAX : ((FIXED_POINT_FACTOR * FIXED_POINT_FACTOR) / zi1);
zi2 = zi2 == 0 ? INT32_MAX : ((FIXED_POINT_FACTOR * FIXED_POINT_FACTOR) / zi2);
zi3 = zi3 == 0 ? INT32_MAX : ((FIXED_POINT_FACTOR * FIXED_POINT_FACTOR) / zi3);
*/
int32_t zi1 = ((FIXED_POINT_FACTOR * FIXED_POINT_FACTOR) / triangle_list_current[current_triangle].vertex1.z);
int32_t zi2 = ((FIXED_POINT_FACTOR * FIXED_POINT_FACTOR) / triangle_list_current[current_triangle].vertex2.z);
int32_t zi3 = ((FIXED_POINT_FACTOR * FIXED_POINT_FACTOR) / triangle_list_current[current_triangle].vertex3.z);
Expand Down Expand Up @@ -199,7 +209,7 @@ void RASTERIZE_SECTION render_rasterize(uint32_t num_triangle, color_t *fb) {

int32_t w1 = (FIXED_POINT_FACTOR * edge1) / area;
int32_t w2 = (FIXED_POINT_FACTOR * edge2) / area;
int32_t w3 = (FIXED_POINT_FACTOR * edge3) / area;
int32_t w3 = /*FIXED_POINT_FACTOR - (w1 + w2);*/(FIXED_POINT_FACTOR * edge3) / area;

//interpolated Z coordinate
int32_t z = ((FIXED_POINT_FACTOR * FIXED_POINT_FACTOR * FIXED_POINT_FACTOR) / (w1 * zi1 + w2 * zi2 + w3 * zi3));
Expand Down

0 comments on commit 04a37cb

Please sign in to comment.