summaryrefslogtreecommitdiff
path: root/src/core/device.c
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-12-17 00:53:44 +0800
committerchai <chaifix@163.com>2019-12-17 00:53:44 +0800
commitc3f45735ecfab6e567be371758f21395e92dfef6 (patch)
treebb52668d69b2547faf114537e5e44940c3c25613 /src/core/device.c
parent6d5afcc8380ee9159d3e6c406c9184b22f14e81d (diff)
*misc
Diffstat (limited to 'src/core/device.c')
-rw-r--r--src/core/device.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/core/device.c b/src/core/device.c
index 92a893f..b5468cd 100644
--- a/src/core/device.c
+++ b/src/core/device.c
@@ -422,7 +422,7 @@ static struct {
uint length;
} clip_coords;
-static ClippedBuffer clipped_buffer; /*clipping result*/
+extern ClippedBuffer clip_buffer; /*clipping result*/
void ssr_draw(ssr_PrimitiveType primitive) {
ssr_assert(state.verts && state.indices);
@@ -480,6 +480,7 @@ void ssr_draw(ssr_PrimitiveType primitive) {
uint i0, i1, i2;
Vec4 *h0, *h1, *h2;
Vert *v0, *v1, *v2;
+ bool reset_active_reg = FALSE;
for (int i = 0; i < state.nprims; ++i) {
i0 = state.indices[i * 3];
i1 = state.indices[i * 3 + 1];
@@ -507,19 +508,25 @@ void ssr_draw(ssr_PrimitiveType primitive) {
}
/*clipping*/
- bool clipped = clip_triangle(h0, h1, h2, v0, v1, v2, varying_flag, &clipped_buffer);
+ bool clipped = clip_triangle(h0, h1, h2, v0, v1, v2, varying_flag, &clip_buffer);
/*rasterization*/
if (!clipped) {
- /*ssrS_setactiveregr();*/
+ if (reset_active_reg) {
+ reset_active_reg = FALSE;
+ ssrS_setactiveregr();
+ }
ssrR_triangle(h0, h1, h2, v0, v1, v2, state.program, &state.uniforms);
} else {
- ssrS_setactiveregc();
- if (clipped_buffer.count >= 3) {
- ClippedVert* vt0 = &clipped_buffer.vertices[0], *vt1, *vt2;
- for (int i = 1; i <= clipped_buffer.count - 2; ++i) {
- vt1 = &clipped_buffer.vertices[i];
- vt2 = &clipped_buffer.vertices[i + 1];
+ if (!reset_active_reg) {
+ reset_active_reg = TRUE;
+ ssrS_setactiveregc();
+ }
+ if (clip_buffer.count >= 3) {
+ ClippedVert* vt0 = &clip_buffer.vertices[0], *vt1, *vt2;
+ for (int i = 1; i <= clip_buffer.count - 2; ++i) {
+ vt1 = &clip_buffer.vertices[i];
+ vt2 = &clip_buffer.vertices[i + 1];
h0 = &vt0->clip_coord; h1 = &vt1->clip_coord; h2 = &vt2->clip_coord;
v0 = &vt0->vertex; v1 = &vt1->vertex; v2 = &vt2->vertex;
ssrR_triangle(h0, h1, h2, v0, v1, v2, state.program, &state.uniforms);
@@ -563,3 +570,7 @@ void ssr_setuniformtex(uint idx, Texture* tex) {
if (idx < 0 || idx > 11) return;
state.uniforms.var_tex[idx] = tex;
}
+
+void ssr_setuniformu(void* userdata) {
+ state.uniforms.userdata = userdata;
+}