- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSWcore.c
More file actions
Latest commit
214 lines (167 loc) · 7.69 KB
/
Copy pathSWcore.c
File metadata and controls
214 lines (167 loc) · 7.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include"SWcore.h"
#include<assert.h>
#include<stdlib.h>
#include"SWcontext.h"
#include"SWcpu.h"
/***************************************************************************************/
SWcontext*sw_cur_context=NULL;
SWcontext*swCreateContext(constSWintw, constSWinth) {
SWcontext*ctx= (SWcontext*)calloc(1, sizeof(SWcontext));
swCtxInit(ctx, w, h);
if (!sw_cur_context) {
swMakeCurrent(ctx);
}
returnctx;
}
voidswMakeCurrent(SWcontext*ctx) { sw_cur_context=ctx; }
voidswDeleteContext(SWcontext*ctx) {
if (ctx==sw_cur_context) {
sw_cur_context=NULL;
}
swCtxDestroy(ctx);
free(ctx);
}
/***************************************************************************************/
SWintswCreateBuffer() { returnswCtxCreateBuffer(sw_cur_context); }
voidswDeleteBuffer(constSWintbuf) { swCtxDeleteBuffer(sw_cur_context, buf); }
voidswBindBuffer(constSWenumtype, constSWintbuf) {
swCtxBindBuffer(sw_cur_context, type, buf);
}
voidswBufferData(constSWenumtype, constSWuintsize, constvoid*data) {
swCtxBufferData(sw_cur_context, type, size, data);
}
voidswBufferSubData(constSWenumtype, constSWuintoffset, constSWuintsize,
constvoid*data) {
swCtxBufferSubData(sw_cur_context, type, offset, size, data);
}
voidswGetBufferSubData(constSWenumtype, constSWuintoffset, constSWuintsize,
void*data) {
swCtxGetBufferSubData(sw_cur_context, type, offset, size, data);
}
/***************************************************************************************/
SWintswCreateFramebuffer(constSWenumtype, constSWintw, constSWinth,
constSWintwith_depth) {
returnswCtxCreateFramebuffer(sw_cur_context, type, w, h, with_depth);
}
voidswDeleteFramebuffer(SWinti) { swCtxDeleteFramebuffer(sw_cur_context, i); }
voidswBindFramebuffer(SWinti) { swCtxBindFramebuffer(sw_cur_context, i); }
SWintswGetCurFramebuffer() { returnswCtxGetCurFramebuffer(sw_cur_context); }
constvoid*swGetPixelDataRef(SWinti) { returnswCtxGetPixelDataRef(sw_cur_context, i); }
constvoid*swGetDepthDataRef(SWinti) { returnswCtxGetDepthDataRef(sw_cur_context, i); }
voidswBlitPixels(constSWintx, constSWinty, constSWintpitch, constSWenumtype,
constSWenummode, constSWintw, constSWinth, constvoid*pixels,
constSWfloatscale) {
swCtxBlitPixels(sw_cur_context, x, y, pitch, type, mode, w, h, pixels, scale);
}
voidswBlitTexture(constSWintx, constSWinty, constSWfloatscale) {
swCtxBlitTexture(sw_cur_context, x, y, scale);
}
/***************************************************************************************/
SWintswCreateTexture() { returnswCtxCreateTexture(sw_cur_context); }
voidswDeleteTexture(constSWinttex) { swCtxDeleteTexture(sw_cur_context, tex); }
voidswActiveTexture(constSWintslot) { swCtxActiveTexture(sw_cur_context, slot); }
voidswBindTexture(constSWinttex) { swCtxBindTexture(sw_cur_context, tex); }
voidswTexImage2D(constSWenummode, constSWenumtype, constSWintw, constSWinth,
constvoid*pixels) {
swCtxTexImage2D(sw_cur_context, mode, type, w, h, pixels);
}
voidswTexImage2DMove_malloced(constSWenummode, constSWenumtype, constSWintw,
constSWinth, void*pixels) {
swCtxTexImage2DMove_malloced(sw_cur_context, mode, type, w, h, pixels);
}
voidswTexImage2DConst(constSWenummode, constSWenumtype, constSWintw, constSWinth,
void*pixels) {
swCtxTexImage2DConst(sw_cur_context, mode, type, w, h, pixels);
}
voidswTexture(constSWintslot, constSWfloat*uv, SWfloat*col) {
SWtexture*t=&sw_cur_context->textures[sw_cur_context->binded_textures[slot]];
swTexGetColorFloat_RGBA(t, uv[0], uv[1], col);
}
/***************************************************************************************/
SWintswCreateProgram() { returnswCtxCreateProgram(sw_cur_context); }
voidswInitProgram(vtx_shader_procv_proc, frag_shader_procf_proc, SWintv_out_floats) {
swCtxInitProgram(sw_cur_context, v_proc, f_proc, v_out_floats);
}
voidswDeleteProgram(constSWintprogram) { swCtxDeleteProgram(sw_cur_context, program); }
voidswUseProgram(constSWintprogram) { swCtxUseProgram(sw_cur_context, program); }
/***************************************************************************************/
voidswEnable(SWenumfunc) {
if (func==SW_DEPTH_TEST) {
sw_cur_context->render_flags |= DEPTH_TEST_ENABLED;
} elseif (func==SW_DEPTH_WRITE) {
sw_cur_context->render_flags |= DEPTH_WRITE_ENABLED;
} elseif (func==SW_BLEND) {
sw_cur_context->render_flags |= BLEND_ENABLED;
} elseif (func==SW_PERSPECTIVE_CORRECTION) {
sw_cur_context->render_flags |= PERSPECTIVE_CORRECTION_ENABLED;
} elseif (func==SW_FAST_PERSPECTIVE_CORRECTION) {
sw_cur_context->render_flags |= FAST_PERSPECTIVE_CORRECTION;
}
}
voidswDisable(constSWenumfunc) {
if (func==SW_DEPTH_TEST) {
sw_cur_context->render_flags &= ~DEPTH_TEST_ENABLED;
} elseif (func==SW_DEPTH_WRITE) {
sw_cur_context->render_flags &= ~DEPTH_WRITE_ENABLED;
} elseif (func==SW_BLEND) {
sw_cur_context->render_flags &= ~BLEND_ENABLED;
} elseif (func==SW_PERSPECTIVE_CORRECTION) {
sw_cur_context->render_flags &= ~PERSPECTIVE_CORRECTION_ENABLED;
} elseif (func==SW_FAST_PERSPECTIVE_CORRECTION) {
sw_cur_context->render_flags &= ~FAST_PERSPECTIVE_CORRECTION;
}
}
SWintswIsEnabled(constSWenumfunc) {
if (func==SW_DEPTH_TEST) {
returnsw_cur_context->render_flags&DEPTH_TEST_ENABLED;
} elseif (func==SW_DEPTH_WRITE) {
returnsw_cur_context->render_flags&DEPTH_WRITE_ENABLED;
} elseif (func==SW_BLEND) {
returnsw_cur_context->render_flags&BLEND_ENABLED;
} elseif (func==SW_PERSPECTIVE_CORRECTION) {
returnsw_cur_context->render_flags&PERSPECTIVE_CORRECTION_ENABLED;
} elseif (func==SW_FAST_PERSPECTIVE_CORRECTION) {
returnsw_cur_context->render_flags&FAST_PERSPECTIVE_CORRECTION;
}
return0;
}
voidswClearColor(constSWfloatr, constSWfloatg, constSWfloatb, constSWfloata) {
SWframebuffer*f=&sw_cur_context->framebuffers[sw_cur_context->cur_framebuffer];
swFbufClearColorFloat(f, r, g, b, a);
}
voidswClearDepth(constSWfloatval) {
SWframebuffer*f=&sw_cur_context->framebuffers[sw_cur_context->cur_framebuffer];
swFbufClearDepth(f, val);
}
SWintswGetInteger(constSWenumwhat) {
if (what==SW_MAX_VERTEX_UNIFORM_VECTORS) {
returnSW_UNIFORM_BUF_SIZE / (4*sizeof(SWfloat));
} elseif (what==SW_NUM_CPUS) {
returnsw_cur_context->cpu_info.num_cpus;
} elseif (what==SW_PHYSICAL_MEMORY) {
return (SWint)(sw_cur_context->cpu_info.physical_memory*1024);
} else {
return-1;
}
}
SWfloatswGetFloat(constSWenumwhat) {
if (what==SW_PHYSICAL_MEMORY) {
returnsw_cur_context->cpu_info.physical_memory;
} else {
return0;
}
}
constchar*swGetString(constSWenumwhat) {
if (what==SW_CPU_VENDOR) {
returnsw_cur_context->cpu_info.vendor;
} elseif (what==SW_CPU_MODEL) {
returnsw_cur_context->cpu_info.model;
} else {
return"Undefined";
}
}
voidswSetFloat(constSWenumwhat, constSWfloatval) {
if (what==SW_CURVE_TOLERANCE) {
sw_cur_context->curve_tolerance=val;
}
}