some progress

This commit is contained in:
veclavtlica
2026-10-07 11:21:21 +03:00
parent 14062e9d00
commit 8d502173a2
26 changed files with 705 additions and 212 deletions
+20 -20
View File
@@ -5,13 +5,13 @@
#ifndef COM_GEM_H
#define COM_GEM_H
#include "cfg.h"
#include "fix.h"
#include "mat.h"
#include "pnt.h"
#include "vec.h"
#include "zord.h"
#include <stdint.h>
#include <stdio.h>
/* Projects vertex position to a clip space via reordered row-major MVP matrix.
It skips calculation of z depth component, as we assume to never use it.
@@ -24,10 +24,10 @@ static inline com_vec_t com_gem_vec_project_clip(com_mat_t a, com_vec_t b) {
com_vec_t result;
#define CASE(m_c, m_n) \
result.a[m_c] = (((int64_t)a.a[m_n * 4 + 0] * b.a[0]) + \
((int64_t)a.a[m_n * 4 + 1] * b.a[1]) + \
((int64_t)a.a[m_n * 4 + 2] * b.a[2]) + a.a[m_n * 4 + 3]) >> \
COM_FIX_FRACBITS;
result.a[m_c] = \
((com_fix_mul(a.a[m_n * 4 + 0], b.a[0])) + \
(com_fix_mul(a.a[m_n * 4 + 1], b.a[1])) + \
(com_fix_mul(a.a[m_n * 4 + 2], b.a[2])) + a.a[m_n * 4 + 3]);
CASE(0, 0);
CASE(1, 1);
@@ -59,18 +59,18 @@ static inline uint8_t com_gem_clip_vis_project(com_vec_t a, com_pnt_t *out) {
mask ^= COM_GEM_VERTEX_CLIPPED_Y;
// out->a[0] = com_fix_mul((com_fix_div(a.a[0], a.a[2]) + COM_FIX_FRACUNIT) >>
// 1,
// 640 * COM_FIX_FRACUNIT);
// COM_CFG_WIDTH * COM_FIX_FRACUNIT);
// out->a[1] = com_fix_mul((com_fix_div(a.a[1], a.a[2]) + COM_FIX_FRACUNIT) >>
// 1,
// 480 * COM_FIX_FRACUNIT);
out->a[0] =
(com_fix_mul(com_fix_div(a.a[0], a.a[2]), 640 * COM_FIX_FRACUNIT) >>
COM_FIX_FRACBITS) +
320;
out->a[1] =
(com_fix_mul(com_fix_div(a.a[1], a.a[2]), 480 * COM_FIX_FRACUNIT) >>
COM_FIX_FRACBITS) +
240;
// COM_CFG_HEIGHT * COM_FIX_FRACUNIT);
out->a[0] = (com_fix_mul(com_fix_div(a.a[0], a.a[2]),
COM_CFG_WIDTH * COM_FIX_FRACUNIT) >>
COM_FIX_FRACBITS) +
(COM_CFG_WIDTH / 2);
out->a[1] = (com_fix_mul(com_fix_div(a.a[1], a.a[2]),
COM_CFG_HEIGHT * COM_FIX_FRACUNIT) >>
COM_FIX_FRACBITS) +
(COM_CFG_HEIGHT / 2);
return mask;
}
@@ -91,9 +91,9 @@ static inline void com_gem_draw_triangle(com_pnt_t v0, com_pnt_t v1,
// If the point is inside or on all edges, draw the pixel
// (Assumes Counter Clockwise vertex ordering)
if (ws.a[0] >= 0 && ws.a[1] >= 0 && ws.a[2] >= 0) {
out[(y * 640 + x) * 4 + 0] = 125;
out[(y * 640 + x) * 4 + 1] = 125;
out[(y * 640 + x) * 4 + 2] = 125;
out[(y * COM_CFG_WIDTH + x) * 4 + 0] = 125;
out[(y * COM_CFG_WIDTH + x) * 4 + 1] = 125;
out[(y * COM_CFG_WIDTH + x) * 4 + 2] = 125;
}
}
}
@@ -145,7 +145,7 @@ com_gem_draw_triangle_textured_edge(com_pnt_t v0, com_pnt_t v1, com_pnt_t v2,
// uint32_t idx = com_zord_order(tx, ty);
uint32_t idx = ty * 32 + tx;
// uint32_t bidx = com_zord_order(x, y);
uint32_t bidx = y * 640 + x;
uint32_t bidx = y * COM_CFG_WIDTH + x;
out[bidx * 4 + 0] = tex[idx * 3 + 0];
out[bidx * 4 + 1] = tex[idx * 3 + 1];
@@ -169,7 +169,7 @@ static inline void draw_span(int32_t x_start_fp, int32_t x_end_fp, int y,
for (int x = x1; x < x2; x++) {
uint32_t idx = 0 * 32 + 0;
uint32_t bidx = y * 640 + x;
uint32_t bidx = y * COM_CFG_WIDTH + x;
out[bidx * 4 + 0] = tex[idx * 3 + 0];
out[bidx * 4 + 1] = tex[idx * 3 + 1];
out[bidx * 4 + 2] = tex[idx * 3 + 2];