Skip to content

Commit 4c9c833

Browse files
committed
Refine code
1 parent c4d50ec commit 4c9c833

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

renderer/core/graphics.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,10 @@ static int is_back_facing(vec3_t ndc_coords[3]) {
326326
* for viewport transformation, see subsection 2.12.1 of
327327
* https://www.khronos.org/registry/OpenGL/specs/es/2.0/es_full_spec_2.0.pdf
328328
*/
329-
static vec3_t viewport_transform(int width_, int height_, vec3_t ndc_coord) {
330-
float width = (float)width_;
331-
float height = (float)height_;
332-
float x = (ndc_coord.x + 1) * 0.5f * width; /* [-1, 1] -> [0, w] */
333-
float y = (ndc_coord.y + 1) * 0.5f * height; /* [-1, 1] -> [0, h] */
334-
float z = (ndc_coord.z + 1) * 0.5f; /* [-1, 1] -> [0, 1] */
329+
static vec3_t viewport_transform(int width, int height, vec3_t ndc_coord) {
330+
float x = (ndc_coord.x + 1) * 0.5f * (float)width; /* [-1, 1] -> [0, w] */
331+
float y = (ndc_coord.y + 1) * 0.5f * (float)height; /* [-1, 1] -> [0, h] */
332+
float z = (ndc_coord.z + 1) * 0.5f; /* [-1, 1] -> [0, 1] */
335333
return vec3_new(x, y, z);
336334
}
337335

@@ -346,11 +344,8 @@ static int max_integer(int a, int b) {
346344
}
347345

348346
static bbox_t find_bounding_box(vec2_t abc[3], int width, int height) {
349-
vec2_t a = abc[0];
350-
vec2_t b = abc[1];
351-
vec2_t c = abc[2];
352-
vec2_t min = vec2_min(vec2_min(a, b), c);
353-
vec2_t max = vec2_max(vec2_max(a, b), c);
347+
vec2_t min = vec2_min(vec2_min(abc[0], abc[1]), abc[2]);
348+
vec2_t max = vec2_max(vec2_max(abc[0], abc[1]), abc[2]);
354349
bbox_t bbox;
355350
bbox.min_x = max_integer((int)ceil(min.x), 0);
356351
bbox.min_y = max_integer((int)ceil(min.y), 0);
@@ -397,10 +392,10 @@ static vec3_t calculate_weights(vec2_t abc[3], vec2_t p) {
397392
* https://www.khronos.org/registry/OpenGL/specs/es/2.0/es_full_spec_2.0.pdf
398393
*/
399394
static float interpolate_depth(float screen_depths[3], vec3_t weights) {
400-
float depth0 = screen_depths[0];
401-
float depth1 = screen_depths[1];
402-
float depth2 = screen_depths[2];
403-
return depth0 * weights.x + depth1 * weights.y + depth2 * weights.z;
395+
float depth0 = screen_depths[0] * weights.x;
396+
float depth1 = screen_depths[1] * weights.y;
397+
float depth2 = screen_depths[2] * weights.z;
398+
return depth0 + depth1 + depth2;
404399
}
405400

406401
/*

0 commit comments

Comments
 (0)