From 5dfdb6b58b2dc7bbd3348004c1fcd17e23fea48b Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 28 Jul 2020 00:30:33 +0800 Subject: *embed resource in exe --- src/core/device.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'src/core/device.c') diff --git a/src/core/device.c b/src/core/device.c index 5ff39ef..b810c04 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -500,7 +500,23 @@ static struct { extern ClippedBuffer clip_buffer; /*clipping result*/ static bool is_back_face(Vec4* c0, Vec4* c1, Vec4*c2) { +#define OPENGL_BACKFACE_CULLING 0 /*cull in ndc*/ +#if OPENGL_BACKFACE_CULLING + /*opengl backface culling algrithm*/ + float w0 = max(1 / c0->w, 0), w1 = 1 / c1->w, w2 = 1 / c2->w; + Vec2 a = { c0->x * w0, c0->y * w0 }; + Vec2 b = { c1->x * w1, c1->y * w1 }; + Vec2 c = { c2->x * w2, c2->y * w2 }; + float signed_area = 0; + signed_area += a.x * b.y - a.y * b.x; + signed_area += b.x * c.y - b.y * c.x; + signed_area += c.x * a.y - c.y * a.x; + if (signed_area <= 0) { + return TRUE; + } + return FALSE; +#else float w0 = 1 / c0->w, w1 = 1 / c1->w, w2 = 1 / c2->w; bool all_front = w0 > 0 && w1 > 0 && w2 > 0; if (all_front) @@ -511,25 +527,11 @@ static bool is_back_face(Vec4* c0, Vec4* c1, Vec4*c2) { ac.x = c2->x * w2 - c0->x * w0; ac.y = c2->y * w2 - c0->y * w0; if (ab.x * ac.y - ab.y * ac.x <= 0) { - return TRUE; + return TRUE; } } return FALSE; - /*OpenGL algrithm*/ - /* - float w0 = max(1 / c0->w, 0), w1 = 1 / c1->w, w2 = 1 / c2->w; - Vec2 a = { c0->x * w0, c0->y * w0 }; - Vec2 b = { c1->x * w1, c1->y * w1 }; - Vec2 c = { c2->x * w2, c2->y * w2 }; - float signed_area = 0; - signed_area += a.x * b.y - a.y * b.x; - signed_area += b.x * c.y - b.y * c.x; - signed_area += c.x * a.y - c.y * a.x; - if (signed_area <= 0) { - return TRUE; - } - return FALSE; - */ +#endif } static void render_prims_triangle(uint varying_flag) { -- cgit v1.1-26-g67d0