summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/device.c24
-rw-r--r--src/core/rasterizer.c24
-rw-r--r--src/core/rasterizer.h6
-rw-r--r--src/core/shader.h20
4 files changed, 42 insertions, 32 deletions
diff --git a/src/core/device.c b/src/core/device.c
index 8284315..ce13c72 100644
--- a/src/core/device.c
+++ b/src/core/device.c
@@ -61,6 +61,8 @@ static struct {
} state;
+UniformCollection* g_uniforms = &state.uniforms;
+
#define MATRIXTOP state.matrix_top[state.matrix_mode]
#define MATRIX state.matrices[state.matrix_mode][MATRIXTOP]
#define MATRIXSTACK state.matrices[state.matrix_mode]
@@ -538,7 +540,7 @@ static void render_prims_triangle(uint varying_flag) {
reset_active_reg = FALSE;
ssrS_setactiveregr();
}
- ssrR_triangle(c0, c1, c2, i0, i1, i2, state.program, &state.uniforms, early_culled);
+ ssrR_triangle(c0, c1, c2, i0, i1, i2, state.program, early_culled);
}
else {
if (!reset_active_reg) {
@@ -552,7 +554,7 @@ static void render_prims_triangle(uint varying_flag) {
vt2 = &clip_buffer.vertices[i + 1];
c0 = &vt0->clip_coord; c1 = &vt1->clip_coord; c2 = &vt2->clip_coord;
i0 = vt0->index; i1 = vt1->index; i2 = vt2->index;
- ssrR_triangle(c0, c1, c2, i0, i1, i2, state.program, &state.uniforms, early_culled);
+ ssrR_triangle(c0, c1, c2, i0, i1, i2, state.program, early_culled);
}
}
}
@@ -578,7 +580,7 @@ static void render_prims_line(uint varying_flag) {
reset_active_reg = FALSE;
ssrS_setactiveregr();
}
- ssrR_line(c0, c1, i0, i1, state.program, &state.uniforms);
+ ssrR_line(c0, c1, i0, i1, state.program);
}
else {
if (!reset_active_reg) {
@@ -592,7 +594,7 @@ static void render_prims_line(uint varying_flag) {
vt1 = &clip_buffer.vertices[i + 1];
c0 = &vt0->clip_coord; c1 = &vt1->clip_coord;
i0 = vt0->index; i1 = vt1->index;
- ssrR_line(c0, c1, i0, i1, state.program, &state.uniforms);
+ ssrR_line(c0, c1, i0, i1, state.program);
}
}
}
@@ -612,7 +614,7 @@ static void render_prims_point(uint varying_flag) {
clipped = clip_point(c0, i0, varying_flag, &clip_buffer);
if (!clipped) {
- ssrR_point(c0, i0, state.program, &state.uniforms);
+ ssrR_point(c0, i0, state.program);
}
else {
/*clipped*/
@@ -628,11 +630,11 @@ void ssr_draw(ssr_PrimitiveType primitive) {
/*set built-in uniforms*/
ssr_getmvp(&mvp);
ssr_getmv(&mv);
- state.uniforms.model = &GETMATRIX(MATRIX_MODEL);
- state.uniforms.view = &GETMATRIX(MATRIX_VIEW);
- state.uniforms.projection = &GETMATRIX(MATRIX_PROJECTION);
- state.uniforms.mvp = &mvp;
- state.uniforms.mv = &mv;
+ g_uniforms->model = &GETMATRIX(MATRIX_MODEL);
+ g_uniforms->view = &GETMATRIX(MATRIX_VIEW);
+ g_uniforms->projection = &GETMATRIX(MATRIX_PROJECTION);
+ g_uniforms->mvp = &mvp;
+ g_uniforms->mv = &mv;
uint varying_flag = state.program->varying_flag;
bool use_extra_varyings = (varying_flag & VARYING_ANY) != 0;
@@ -663,7 +665,7 @@ void ssr_draw(ssr_PrimitiveType primitive) {
if (use_extra_varyings) {
ssrS_setupregisterpointers(vert->index);
}
- vert_shader(&state.uniforms, vert, &clip_coords.coords[i]);
+ vert_shader(vert, &clip_coords.coords[i]);
}
/*set register pointer to frag-in*/
diff --git a/src/core/rasterizer.c b/src/core/rasterizer.c
index c5745ba..55d4ad3 100644
--- a/src/core/rasterizer.c
+++ b/src/core/rasterizer.c
@@ -82,11 +82,12 @@ static void puttriangle(Vec2* A, Vec2* B, Vec2* C, Color c) {
ssrR_putline(C->x, C->y, B->x, B->y, c);
}
+extern UniformCollection* g_uniforms ;
+
void ssrR_triangle(
Vec4* CA, Vec4* CB, Vec4* CC,
uint IA, uint IB, uint IC,
Program* program,
- UniformCollection* uniforms,
bool early_culled
) {
ssr_assert(CA && CB && CC && program);
@@ -104,6 +105,8 @@ void ssrR_triangle(
}
}
+ UniformCollection* uniforms = g_uniforms;
+
Vec4 SA, SB, SC;
internal_vec4_dividewnoz(CA, &SA); ssrU_viewport(&SA, &SA);
internal_vec4_dividewnoz(CB, &SB); ssrU_viewport(&SB, &SB);
@@ -186,7 +189,7 @@ void ssrR_triangle(
/*interpolate varying variables*/ \
ssrS_solveregsbcp(&bc, IA, IB, IC); \
/*enter fragment shader*/ \
- discard = !frag_shader(uniforms, out_color[0]); \
+ discard = !frag_shader(out_color[0]); \
discardif(discard); \
/*put point*/ \
ssr_blendandputpoint(p.x, p.y, blend); \
@@ -242,10 +245,9 @@ void ssrR_triangle(
void ssrR_line(
Vec4* CA, Vec4* CB,
uint IA, uint IB,
- Program* program,
- UniformCollection* uniforms
+ Program* program
) {
- ssr_assert(CA && CB && program && uniforms);
+ ssr_assert(CA && CB && program);
Vec4 SA, SB;
internal_vec4_dividewnoz(CA, &SA); ssrU_viewport(&SA, &SA);
@@ -253,6 +255,8 @@ void ssrR_line(
FragmentShader frag_shader = program->fragmentshader;
+ UniformCollection* uniforms = g_uniforms;
+
int x0 = SA.x, y0 = SA.y;
int x1 = SB.x, y1 = SB.y;
float wA = SA.w, wB = SB.w;
@@ -318,7 +322,7 @@ void ssrR_line(
discardif(!pass_depth_test || !pass_stencil_test);
/*solve registers with lerp*/
ssrS_solveregslerp(t, IA, IB);
- discard = !frag_shader(uniforms, out_color[0]);
+ discard = !frag_shader(out_color[0]);
discardif(discard);
/*put point*/
ssr_blendandputpoint(px, py, blend);
@@ -333,11 +337,13 @@ void ssrR_line(
#undef discardif
}
-void ssrR_point(Vec4* CA, uint IA, Program* program, UniformCollection* uniforms) {
- ssr_assert(CA && program && uniforms);
+void ssrR_point(Vec4* CA, uint IA, Program* program) {
+ ssr_assert(CA && program);
FragmentShader frag_shader = program->fragmentshader;
+ UniformCollection* uniforms = g_uniforms;
+
Vec3 SA;
internal_vec4_dividew(CA, &SA); ssrU_viewport(&SA, &SA);
@@ -364,7 +370,7 @@ void ssrR_point(Vec4* CA, uint IA, Program* program, UniformCollection* uniforms
}
discardif(!pass_depth_test || !pass_stencil_test);
ssrS_solveregscopy(IA);
- discard = !frag_shader(uniforms, out_color[0]);
+ discard = !frag_shader(out_color[0]);
discardif(discard);
/*put point*/
ssr_blendandputpoint(px, py, blend);
diff --git a/src/core/rasterizer.h b/src/core/rasterizer.h
index a566329..fce8376 100644
--- a/src/core/rasterizer.h
+++ b/src/core/rasterizer.h
@@ -13,8 +13,8 @@ bool ssrR_barycentric(Vec2* A, Vec2* B, Vec2* C, Vec2* p, Vec3* out); /*计算重心
void ssrR_center(Vec2* A, Vec2* B, Vec2* C, Vec2* out); /*获得重心*/
bool ssrR_ispointintriangle(Vec2* A, Vec2* B, Vec2* C, Vec2* p);
-void ssrR_triangle(Vec4* CA, Vec4* CB, Vec4* CC, uint IA, uint IB, uint IC, Program* program, UniformCollection* uniforms);
-void ssrR_line(Vec4* CA, Vec4* CB, uint IA, uint IB, Program* program, UniformCollection* uniforms);
-void ssrR_point(Vec4* CA, uint IA, Program* program, UniformCollection* uniforms);
+void ssrR_triangle(Vec4* CA, Vec4* CB, Vec4* CC, uint IA, uint IB, uint IC, Program* program, bool early_called);
+void ssrR_line(Vec4* CA, Vec4* CB, uint IA, uint IB, Program* program);
+void ssrR_point(Vec4* CA, uint IA, Program* program);
#endif \ No newline at end of file
diff --git a/src/core/shader.h b/src/core/shader.h
index 043ba1e..be3819f 100644
--- a/src/core/shader.h
+++ b/src/core/shader.h
@@ -24,13 +24,15 @@ typedef struct {
void* userdata;
} UniformCollection;
-#define UTEX(i) (uniforms->var_tex[i])
-#define UM4(i) (&uniforms->var_mat4[i])
-#define UV2(i) (&uniforms->var_vec2[i])
-#define UV3(i) (&uniforms->var_vec3[i])
-#define UV4(i) (&uniforms->var_vec4[i])
-#define UN(i) (&uniforms->var_num[i])
-#define UU (uniforms->userdata)
+extern UniformCollection* g_uniforms;
+
+#define UTEX(i) (g_uniforms->var_tex[i])
+#define UM4(i) (&g_uniforms->var_mat4[i])
+#define UV2(i) (&g_uniforms->var_vec2[i])
+#define UV3(i) (&g_uniforms->var_vec3[i])
+#define UV4(i) (&g_uniforms->var_vec4[i])
+#define UN(i) (&g_uniforms->var_num[i])
+#define UU (g_uniforms->userdata)
#define REG_TOTAL 32
#define REG_NUM_COUNT 4
@@ -42,7 +44,7 @@ typedef struct {
// Vertex* vertex;
//} Vertex;
-typedef void(*VertexShader)(UniformCollection* uniforms, Vertex* in, Vec4* homocoord);
+typedef void(*VertexShader)(Vertex* in, Vec4* homocoord);
typedef struct {
float num[REG_NUM_COUNT];
@@ -51,7 +53,7 @@ typedef struct {
Vec4 v4[REG_V4_COUNT];
} FragmentShaderIn;
-typedef bool(*FragmentShader)(UniformCollection* uniforms, Color32* color);
+typedef bool(*FragmentShader)(Color32* color);
typedef struct {
VertexShader vertexshader;