summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-07-28 00:30:33 +0800
committerchai <chaifix@163.com>2020-07-28 00:30:33 +0800
commit5dfdb6b58b2dc7bbd3348004c1fcd17e23fea48b (patch)
treea03f1a01382595ed50cc4780a728b22013f6d5a0 /src/core
parent690f20cdbe8dad3fce7a547934a5a8322303342d (diff)
*embed resource in exeHEADmaster
Diffstat (limited to 'src/core')
-rw-r--r--src/core/device.c34
-rw-r--r--src/core/shader.h1
2 files changed, 19 insertions, 16 deletions
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) {
diff --git a/src/core/shader.h b/src/core/shader.h
index be3819f..335eead 100644
--- a/src/core/shader.h
+++ b/src/core/shader.h
@@ -160,6 +160,7 @@ ActiveReg active_regs[REG_TOTAL];
int open_regsi[REG_TOTAL]; /*active registers during a draw call*/
+/*reference pointers*/
float *reg_num_00, *reg_num_01, *reg_num_02, *reg_num_03;
Vec2 *reg_v2_00, *reg_v2_01, *reg_v2_02, *reg_v2_03, *reg_v2_04, *reg_v2_05, *reg_v2_06, *reg_v2_07;
Vec3 *reg_v3_00, *reg_v3_01, *reg_v3_02, *reg_v3_03, *reg_v3_04, *reg_v3_05, *reg_v3_06, *reg_v3_07, *reg_v3_08, *reg_v3_09, *reg_v3_10, *reg_v3_11;