rev |
line source |
nuclear@2
|
1 /*
|
nuclear@2
|
2 SaneGL - a small library to bring back sanity to OpenGL ES 2.x
|
nuclear@2
|
3 Copyright (C) 2011 John Tsiombikas <nuclear@member.fsf.org>
|
nuclear@2
|
4
|
nuclear@2
|
5 This program is free software: you can redistribute it and/or modify
|
nuclear@2
|
6 it under the terms of the GNU General Public License as published by
|
nuclear@2
|
7 the Free Software Foundation, either version 3 of the License, or
|
nuclear@2
|
8 (at your option) any later version.
|
nuclear@2
|
9
|
nuclear@2
|
10 This program is distributed in the hope that it will be useful,
|
nuclear@2
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
nuclear@2
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
nuclear@2
|
13 GNU General Public License for more details.
|
nuclear@2
|
14
|
nuclear@2
|
15 You should have received a copy of the GNU General Public License
|
nuclear@2
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
nuclear@2
|
17 */
|
nuclear@2
|
18
|
nuclear@2
|
19 #include <stdio.h>
|
nuclear@3
|
20 #include <stdlib.h>
|
nuclear@2
|
21 #include <string.h>
|
nuclear@1
|
22 #include <math.h>
|
nuclear@2
|
23 #include <assert.h>
|
nuclear@1
|
24 #include "sanegl.h"
|
nuclear@1
|
25
|
nuclear@1
|
26 #define MMODE_IDX(x) ((x) - GL_MODELVIEW)
|
nuclear@1
|
27 #define MAT_STACK_SIZE 32
|
nuclear@1
|
28 #define MAT_IDENT {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}
|
nuclear@1
|
29
|
nuclear@1
|
30 #define MAX_VERTS 512
|
nuclear@1
|
31
|
nuclear@2
|
32 static void gl_draw_immediate(void);
|
nuclear@2
|
33
|
nuclear@1
|
34 typedef struct { float x, y; } vec2_t;
|
nuclear@1
|
35 typedef struct { float x, y, z; } vec3_t;
|
nuclear@1
|
36 typedef struct { float x, y, z, w; } vec4_t;
|
nuclear@1
|
37
|
nuclear@1
|
38 static int mm_idx = 0;
|
nuclear@1
|
39 static float mat_stack[3][MAT_STACK_SIZE][16] = {{MAT_IDENT}, {MAT_IDENT}, {MAT_IDENT}};
|
nuclear@1
|
40 static int stack_top[3];
|
nuclear@1
|
41 static float mat_mvp[16];
|
nuclear@1
|
42 static int mvp_valid;
|
nuclear@1
|
43 static int prim = -1;
|
nuclear@1
|
44
|
nuclear@1
|
45 static vec3_t cur_normal;
|
nuclear@1
|
46 static vec4_t cur_color, cur_attrib;
|
nuclear@1
|
47 static vec2_t cur_texcoord;
|
nuclear@1
|
48
|
nuclear@1
|
49 static vec4_t *vert_arr, *col_arr, *attr_arr;
|
nuclear@1
|
50 static vec3_t *norm_arr;
|
nuclear@1
|
51 static vec2_t *texc_arr;
|
nuclear@2
|
52 /*static unsigned int vbuf, cbuf, nbuf, tbuf, abuf;*/
|
nuclear@2
|
53 static int vloc, nloc, cloc, tloc, aloc = -1;
|
nuclear@2
|
54
|
nuclear@2
|
55 static int num_verts, vert_calls;
|
nuclear@2
|
56 static int cur_prog;
|
nuclear@1
|
57
|
nuclear@1
|
58
|
nuclear@1
|
59 void gl_matrix_mode(int mm)
|
nuclear@1
|
60 {
|
nuclear@1
|
61 mm_idx = MMODE_IDX(mm);
|
nuclear@1
|
62 }
|
nuclear@1
|
63
|
nuclear@1
|
64 void gl_push_matrix(void)
|
nuclear@1
|
65 {
|
nuclear@1
|
66 int top = stack_top[mm_idx];
|
nuclear@1
|
67
|
nuclear@1
|
68 memcpy(mat_stack[mm_idx][top + 1], mat_stack[mm_idx][top], 16 * sizeof(float));
|
nuclear@1
|
69 stack_top[mm_idx]++;
|
nuclear@1
|
70 mvp_valid = 0;
|
nuclear@1
|
71 }
|
nuclear@1
|
72
|
nuclear@1
|
73 void gl_pop_matrix(void)
|
nuclear@1
|
74 {
|
nuclear@1
|
75 stack_top[mm_idx]--;
|
nuclear@1
|
76 mvp_valid = 0;
|
nuclear@1
|
77 }
|
nuclear@1
|
78
|
nuclear@1
|
79 void gl_load_identity(void)
|
nuclear@1
|
80 {
|
nuclear@1
|
81 static const float idmat[] = MAT_IDENT;
|
nuclear@1
|
82 int top = stack_top[mm_idx];
|
nuclear@1
|
83 float *mat = mat_stack[mm_idx][top];
|
nuclear@1
|
84
|
nuclear@1
|
85 memcpy(mat, idmat, sizeof idmat);
|
nuclear@1
|
86 mvp_valid = 0;
|
nuclear@1
|
87 }
|
nuclear@1
|
88
|
nuclear@1
|
89 void gl_load_matrixf(const float *m)
|
nuclear@1
|
90 {
|
nuclear@1
|
91 int top = stack_top[mm_idx];
|
nuclear@1
|
92 float *mat = mat_stack[mm_idx][top];
|
nuclear@1
|
93
|
nuclear@1
|
94 memcpy(mat, m, 16 * sizeof *mat);
|
nuclear@1
|
95 mvp_valid = 0;
|
nuclear@1
|
96 }
|
nuclear@1
|
97
|
nuclear@1
|
98 #define M(i, j) ((i << 2) + j)
|
nuclear@1
|
99
|
nuclear@1
|
100 void gl_mult_matrixf(const float *m2)
|
nuclear@1
|
101 {
|
nuclear@1
|
102 int i, j;
|
nuclear@1
|
103 int top = stack_top[mm_idx];
|
nuclear@1
|
104 float *m1 = mat_stack[mm_idx][top];
|
nuclear@1
|
105 float res[16];
|
nuclear@1
|
106
|
nuclear@1
|
107 for(i=0; i<4; i++) {
|
nuclear@1
|
108 for(j=0; j<4; j++) {
|
nuclear@1
|
109 res[M(i,j)] = m1[M(i,0)] * m2[M(0,j)] +
|
nuclear@1
|
110 m1[M(i,1)] * m2[M(1,j)] +
|
nuclear@1
|
111 m1[M(i,2)] * m2[M(2,j)] +
|
nuclear@1
|
112 m1[M(i,3)] * m2[M(3,j)];
|
nuclear@1
|
113 }
|
nuclear@1
|
114 }
|
nuclear@1
|
115
|
nuclear@1
|
116 memcpy(m1, res, sizeof res);
|
nuclear@1
|
117 mvp_valid = 0;
|
nuclear@1
|
118 }
|
nuclear@1
|
119
|
nuclear@1
|
120 void gl_translatef(float x, float y, float z)
|
nuclear@1
|
121 {
|
nuclear@1
|
122 float mat[] = MAT_IDENT;
|
nuclear@1
|
123
|
nuclear@1
|
124 mat[12] = x;
|
nuclear@1
|
125 mat[13] = y;
|
nuclear@1
|
126 mat[14] = z;
|
nuclear@1
|
127
|
nuclear@1
|
128 gl_mult_matrixf(mat);
|
nuclear@1
|
129 }
|
nuclear@1
|
130
|
nuclear@1
|
131 void gl_rotatef(float angle, float x, float y, float z)
|
nuclear@1
|
132 {
|
nuclear@1
|
133 float mat[] = MAT_IDENT;
|
nuclear@1
|
134
|
nuclear@1
|
135 float angle_rad = M_PI * angle / 180.0;
|
nuclear@1
|
136 float sina = sin(angle_rad);
|
nuclear@1
|
137 float cosa = cos(angle_rad);
|
nuclear@1
|
138 float one_minus_cosa = 1.0 - cosa;
|
nuclear@1
|
139 float nxsq = x * x;
|
nuclear@1
|
140 float nysq = y * y;
|
nuclear@1
|
141 float nzsq = z * z;
|
nuclear@1
|
142
|
nuclear@1
|
143 mat[0] = nxsq + (1.0 - nxsq) * cosa;
|
nuclear@1
|
144 mat[4] = x * y * one_minus_cosa - z * sina;
|
nuclear@1
|
145 mat[8] = x * z * one_minus_cosa + y * sina;
|
nuclear@1
|
146 mat[1] = x * y * one_minus_cosa + z * sina;
|
nuclear@1
|
147 mat[5] = nysq + (1.0 - nysq) * cosa;
|
nuclear@1
|
148 mat[9] = y * z * one_minus_cosa - x * sina;
|
nuclear@1
|
149 mat[2] = x * z * one_minus_cosa - y * sina;
|
nuclear@1
|
150 mat[6] = y * z * one_minus_cosa + x * sina;
|
nuclear@1
|
151 mat[10] = nzsq + (1.0 - nzsq) * cosa;
|
nuclear@1
|
152
|
nuclear@1
|
153 gl_mult_matrixf(mat);
|
nuclear@1
|
154 }
|
nuclear@1
|
155
|
nuclear@1
|
156 void gl_scalef(float x, float y, float z)
|
nuclear@1
|
157 {
|
nuclear@1
|
158 float mat[] = MAT_IDENT;
|
nuclear@1
|
159
|
nuclear@1
|
160 mat[0] = x;
|
nuclear@1
|
161 mat[5] = y;
|
nuclear@1
|
162 mat[10] = z;
|
nuclear@1
|
163
|
nuclear@1
|
164 gl_mult_matrixf(mat);
|
nuclear@1
|
165 }
|
nuclear@1
|
166
|
nuclear@1
|
167 void gl_ortho(float left, float right, float bottom, float top, float near, float far)
|
nuclear@1
|
168 {
|
nuclear@1
|
169 float mat[] = MAT_IDENT;
|
nuclear@1
|
170
|
nuclear@1
|
171 float dx = right - left;
|
nuclear@1
|
172 float dy = top - bottom;
|
nuclear@1
|
173 float dz = far - near;
|
nuclear@1
|
174
|
nuclear@1
|
175 float tx = -(right + left) / dx;
|
nuclear@1
|
176 float ty = -(top + bottom) / dy;
|
nuclear@1
|
177 float tz = -(far + near) / dz;
|
nuclear@1
|
178
|
nuclear@1
|
179 float sx = 2.0 / dx;
|
nuclear@1
|
180 float sy = 2.0 / dy;
|
nuclear@1
|
181 float sz = -2.0 / dz;
|
nuclear@1
|
182
|
nuclear@1
|
183 mat[0] = sx;
|
nuclear@1
|
184 mat[5] = sy;
|
nuclear@1
|
185 mat[10] = sz;
|
nuclear@1
|
186 mat[12] = tx;
|
nuclear@1
|
187 mat[13] = ty;
|
nuclear@1
|
188 mat[14] = tz;
|
nuclear@1
|
189
|
nuclear@1
|
190 gl_mult_matrixf(mat);
|
nuclear@1
|
191 }
|
nuclear@1
|
192
|
nuclear@1
|
193 void gl_frustum(float left, float right, float bottom, float top, float near, float far)
|
nuclear@1
|
194 {
|
nuclear@1
|
195 float mat[] = MAT_IDENT;
|
nuclear@1
|
196
|
nuclear@1
|
197 float dx = right - left;
|
nuclear@1
|
198 float dy = top - bottom;
|
nuclear@1
|
199 float dz = far - near;
|
nuclear@1
|
200
|
nuclear@1
|
201 float a = (right + left) / dx;
|
nuclear@1
|
202 float b = (top + bottom) / dy;
|
nuclear@1
|
203 float c = -(far + near) / dz;
|
nuclear@1
|
204 float d = -2.0 * far * near / dz;
|
nuclear@1
|
205
|
nuclear@1
|
206 mat[0] = 2.0 * near / dx;
|
nuclear@1
|
207 mat[5] = 2.0 * near / dy;
|
nuclear@1
|
208 mat[8] = a;
|
nuclear@1
|
209 mat[9] = b;
|
nuclear@1
|
210 mat[10] = c;
|
nuclear@1
|
211 mat[11] = -1.0;
|
nuclear@1
|
212 mat[14] = d;
|
nuclear@1
|
213
|
nuclear@1
|
214 gl_mult_matrixf(mat);
|
nuclear@1
|
215 }
|
nuclear@1
|
216
|
nuclear@1
|
217 void glu_perspective(float vfov, float aspect, float near, float far)
|
nuclear@1
|
218 {
|
nuclear@21
|
219 float vfov_rad = M_PI * vfov / 180.0;
|
nuclear@21
|
220 float x = near * tan(vfov_rad / 2.0);
|
nuclear@1
|
221 gl_frustum(-aspect * x, aspect * x, -x, x, near, far);
|
nuclear@1
|
222 }
|
nuclear@1
|
223
|
nuclear@1
|
224 void gl_apply_xform(unsigned int prog)
|
nuclear@1
|
225 {
|
nuclear@1
|
226 int loc, mvidx, pidx, tidx, mvtop, ptop, ttop;
|
nuclear@1
|
227
|
nuclear@1
|
228 mvidx = MMODE_IDX(GL_MODELVIEW);
|
nuclear@1
|
229 pidx = MMODE_IDX(GL_PROJECTION);
|
nuclear@1
|
230 tidx = MMODE_IDX(GL_TEXTURE);
|
nuclear@1
|
231
|
nuclear@1
|
232 mvtop = stack_top[mvidx];
|
nuclear@1
|
233 ptop = stack_top[pidx];
|
nuclear@1
|
234 ttop = stack_top[tidx];
|
nuclear@1
|
235
|
nuclear@2
|
236 assert(prog);
|
nuclear@2
|
237
|
nuclear@1
|
238 if((loc = glGetUniformLocation(prog, "matrix_modelview")) != -1) {
|
nuclear@2
|
239 glUniformMatrix4fv(loc, 1, 0, mat_stack[mvidx][mvtop]);
|
nuclear@1
|
240 }
|
nuclear@1
|
241
|
nuclear@1
|
242 if((loc = glGetUniformLocation(prog, "matrix_projection")) != -1) {
|
nuclear@2
|
243 glUniformMatrix4fv(loc, 1, 0, mat_stack[pidx][ptop]);
|
nuclear@1
|
244 }
|
nuclear@1
|
245
|
nuclear@1
|
246 if((loc = glGetUniformLocation(prog, "matrix_texture")) != -1) {
|
nuclear@2
|
247 glUniformMatrix4fv(loc, 1, 0, mat_stack[tidx][ttop]);
|
nuclear@1
|
248 }
|
nuclear@1
|
249
|
nuclear@1
|
250 if((loc = glGetUniformLocation(prog, "matrix_normal")) != -1) {
|
nuclear@1
|
251 float nmat[9];
|
nuclear@1
|
252
|
nuclear@1
|
253 nmat[0] = mat_stack[mvidx][mvtop][0];
|
nuclear@1
|
254 nmat[1] = mat_stack[mvidx][mvtop][1];
|
nuclear@1
|
255 nmat[2] = mat_stack[mvidx][mvtop][2];
|
nuclear@1
|
256 nmat[3] = mat_stack[mvidx][mvtop][4];
|
nuclear@1
|
257 nmat[4] = mat_stack[mvidx][mvtop][5];
|
nuclear@1
|
258 nmat[5] = mat_stack[mvidx][mvtop][6];
|
nuclear@1
|
259 nmat[6] = mat_stack[mvidx][mvtop][8];
|
nuclear@1
|
260 nmat[7] = mat_stack[mvidx][mvtop][9];
|
nuclear@1
|
261 nmat[8] = mat_stack[mvidx][mvtop][10];
|
nuclear@2
|
262 glUniformMatrix3fv(loc, 1, 0, nmat);
|
nuclear@1
|
263 }
|
nuclear@1
|
264
|
nuclear@1
|
265 if((loc = glGetUniformLocation(prog, "matrix_modelview_projection")) != -1) {
|
nuclear@1
|
266 if(!mvp_valid) {
|
nuclear@1
|
267 /* TODO calc mvp */
|
nuclear@1
|
268 }
|
nuclear@2
|
269 glUniformMatrix4fv(loc, 1, 0, mat_mvp);
|
nuclear@1
|
270 }
|
nuclear@1
|
271 }
|
nuclear@2
|
272
|
nuclear@2
|
273
|
nuclear@2
|
274 /* immediate mode rendering */
|
nuclear@2
|
275 void gl_begin(int p)
|
nuclear@2
|
276 {
|
nuclear@2
|
277 if(!vert_arr) {
|
nuclear@2
|
278 vert_arr = malloc(MAX_VERTS * sizeof *vert_arr);
|
nuclear@2
|
279 norm_arr = malloc(MAX_VERTS * sizeof *norm_arr);
|
nuclear@2
|
280 texc_arr = malloc(MAX_VERTS * sizeof *texc_arr);
|
nuclear@2
|
281 col_arr = malloc(MAX_VERTS * sizeof *col_arr);
|
nuclear@2
|
282 attr_arr = malloc(MAX_VERTS * sizeof *attr_arr);
|
nuclear@2
|
283 assert(vert_arr && norm_arr && texc_arr && col_arr && attr_arr);
|
nuclear@2
|
284 }
|
nuclear@2
|
285
|
nuclear@2
|
286 prim = p;
|
nuclear@2
|
287 num_verts = vert_calls = 0;
|
nuclear@2
|
288
|
nuclear@2
|
289 glGetIntegerv(GL_CURRENT_PROGRAM, &cur_prog);
|
nuclear@2
|
290 assert(cur_prog);
|
nuclear@2
|
291
|
nuclear@2
|
292 gl_apply_xform(cur_prog);
|
nuclear@2
|
293
|
nuclear@2
|
294 vloc = glGetAttribLocation(cur_prog, "attr_vertex");
|
nuclear@2
|
295 nloc = glGetAttribLocation(cur_prog, "attr_normal");
|
nuclear@2
|
296 cloc = glGetAttribLocation(cur_prog, "attr_color");
|
nuclear@2
|
297 tloc = glGetAttribLocation(cur_prog, "attr_texcoord");
|
nuclear@2
|
298 }
|
nuclear@2
|
299
|
nuclear@2
|
300 void gl_end(void)
|
nuclear@2
|
301 {
|
nuclear@2
|
302 if(num_verts > 0) {
|
nuclear@2
|
303 gl_draw_immediate();
|
nuclear@2
|
304 }
|
nuclear@2
|
305 aloc = -1;
|
nuclear@2
|
306 }
|
nuclear@2
|
307
|
nuclear@2
|
308 static void gl_draw_immediate(void)
|
nuclear@2
|
309 {
|
nuclear@2
|
310 int glprim;
|
nuclear@2
|
311
|
nuclear@2
|
312 if(vloc == -1) {
|
nuclear@2
|
313 fprintf(stderr, "gl_draw_immediate call with vloc == -1\n");
|
nuclear@2
|
314 return;
|
nuclear@2
|
315 }
|
nuclear@2
|
316
|
nuclear@2
|
317 glprim = prim == GL_QUADS ? GL_TRIANGLES : prim;
|
nuclear@2
|
318
|
nuclear@2
|
319 glVertexAttribPointer(vloc, 4, GL_FLOAT, 0, 0, vert_arr);
|
nuclear@2
|
320 glEnableVertexAttribArray(vloc);
|
nuclear@2
|
321
|
nuclear@2
|
322 if(nloc != -1) {
|
nuclear@2
|
323 glVertexAttribPointer(nloc, 3, GL_FLOAT, 0, 0, norm_arr);
|
nuclear@2
|
324 glEnableVertexAttribArray(nloc);
|
nuclear@2
|
325 }
|
nuclear@2
|
326
|
nuclear@2
|
327 if(cloc != -1) {
|
nuclear@27
|
328 glVertexAttribPointer(cloc, 4, GL_FLOAT, 1, 0, col_arr);
|
nuclear@2
|
329 glEnableVertexAttribArray(cloc);
|
nuclear@2
|
330 }
|
nuclear@2
|
331
|
nuclear@2
|
332 if(tloc != -1) {
|
nuclear@2
|
333 glVertexAttribPointer(tloc, 2, GL_FLOAT, 0, 0, texc_arr);
|
nuclear@2
|
334 glEnableVertexAttribArray(tloc);
|
nuclear@2
|
335 }
|
nuclear@2
|
336
|
nuclear@2
|
337 if(aloc != -1) {
|
nuclear@2
|
338 glVertexAttribPointer(aloc, 4, GL_FLOAT, 0, 0, attr_arr);
|
nuclear@2
|
339 glEnableVertexAttribArray(aloc);
|
nuclear@2
|
340 }
|
nuclear@2
|
341
|
nuclear@2
|
342 glDrawArrays(glprim, 0, num_verts);
|
nuclear@2
|
343
|
nuclear@2
|
344 glDisableVertexAttribArray(vloc);
|
nuclear@2
|
345 if(nloc != -1) {
|
nuclear@2
|
346 glDisableVertexAttribArray(nloc);
|
nuclear@2
|
347 }
|
nuclear@2
|
348 if(cloc != -1) {
|
nuclear@2
|
349 glDisableVertexAttribArray(cloc);
|
nuclear@2
|
350 }
|
nuclear@2
|
351 if(tloc != -1) {
|
nuclear@2
|
352 glDisableVertexAttribArray(tloc);
|
nuclear@2
|
353 }
|
nuclear@2
|
354 if(aloc != -1) {
|
nuclear@2
|
355 glDisableVertexAttribArray(aloc);
|
nuclear@2
|
356 }
|
nuclear@2
|
357 }
|
nuclear@2
|
358
|
nuclear@2
|
359
|
nuclear@2
|
360 void gl_vertex2f(float x, float y)
|
nuclear@2
|
361 {
|
nuclear@2
|
362 gl_vertex4f(x, y, 0.0f, 1.0f);
|
nuclear@2
|
363 }
|
nuclear@2
|
364
|
nuclear@2
|
365 void gl_vertex3f(float x, float y, float z)
|
nuclear@2
|
366 {
|
nuclear@2
|
367 gl_vertex4f(x, y, z, 1.0f);
|
nuclear@2
|
368 }
|
nuclear@2
|
369
|
nuclear@2
|
370 void gl_vertex4f(float x, float y, float z, float w)
|
nuclear@2
|
371 {
|
nuclear@2
|
372 int i, buffer_full;
|
nuclear@2
|
373
|
nuclear@2
|
374 if(prim == GL_QUADS && vert_calls % 4 == 3) {
|
nuclear@2
|
375 for(i=0; i<2; i++) {
|
nuclear@2
|
376 if(aloc != -1) {
|
nuclear@2
|
377 attr_arr[num_verts] = attr_arr[num_verts - 3 + i];
|
nuclear@2
|
378 }
|
nuclear@2
|
379 if(cloc != -1) {
|
nuclear@2
|
380 col_arr[num_verts] = col_arr[num_verts - 3 + i];
|
nuclear@2
|
381 }
|
nuclear@2
|
382 if(tloc != -1) {
|
nuclear@2
|
383 texc_arr[num_verts] = texc_arr[num_verts - 3 + i];
|
nuclear@2
|
384 }
|
nuclear@2
|
385 if(nloc != -1) {
|
nuclear@2
|
386 norm_arr[num_verts] = norm_arr[num_verts - 3 + i];
|
nuclear@2
|
387 }
|
nuclear@2
|
388 vert_arr[num_verts] = vert_arr[num_verts - 3 + i];
|
nuclear@2
|
389 num_verts++;
|
nuclear@2
|
390 }
|
nuclear@2
|
391 }
|
nuclear@2
|
392
|
nuclear@2
|
393 vert_arr[num_verts].x = x;
|
nuclear@2
|
394 vert_arr[num_verts].y = y;
|
nuclear@2
|
395 vert_arr[num_verts].z = z;
|
nuclear@2
|
396 vert_arr[num_verts].w = w;
|
nuclear@2
|
397
|
nuclear@2
|
398 if(cloc != -1) {
|
nuclear@2
|
399 col_arr[num_verts] = cur_color;
|
nuclear@2
|
400 }
|
nuclear@2
|
401 if(nloc != -1) {
|
nuclear@2
|
402 norm_arr[num_verts] = cur_normal;
|
nuclear@2
|
403 }
|
nuclear@2
|
404 if(tloc != -1) {
|
nuclear@2
|
405 texc_arr[num_verts] = cur_texcoord;
|
nuclear@2
|
406 }
|
nuclear@2
|
407 if(aloc != -1) {
|
nuclear@2
|
408 attr_arr[num_verts] = cur_attrib;
|
nuclear@2
|
409 }
|
nuclear@2
|
410
|
nuclear@2
|
411 vert_calls++;
|
nuclear@2
|
412 num_verts++;
|
nuclear@2
|
413
|
nuclear@2
|
414 if(prim == GL_QUADS) {
|
nuclear@2
|
415 /* leave space for 6 more worst-case and don't allow flushes mid-quad */
|
nuclear@2
|
416 buffer_full = num_verts >= MAX_VERTS - 6 && vert_calls % 4 == 0;
|
nuclear@2
|
417 } else {
|
nuclear@2
|
418 buffer_full = num_verts >= MAX_VERTS - prim;
|
nuclear@2
|
419 }
|
nuclear@2
|
420
|
nuclear@2
|
421 if(buffer_full) {
|
nuclear@2
|
422 gl_draw_immediate();
|
nuclear@3
|
423 gl_begin(prim); /* reset everything */
|
nuclear@2
|
424 }
|
nuclear@2
|
425 }
|
nuclear@2
|
426
|
nuclear@2
|
427
|
nuclear@2
|
428 void gl_normal3f(float x, float y, float z)
|
nuclear@2
|
429 {
|
nuclear@2
|
430 cur_normal.x = x;
|
nuclear@2
|
431 cur_normal.y = y;
|
nuclear@2
|
432 cur_normal.z = z;
|
nuclear@2
|
433 }
|
nuclear@2
|
434
|
nuclear@2
|
435
|
nuclear@2
|
436 void gl_color3f(float r, float g, float b)
|
nuclear@2
|
437 {
|
nuclear@2
|
438 cur_color.x = r;
|
nuclear@2
|
439 cur_color.y = g;
|
nuclear@2
|
440 cur_color.z = b;
|
nuclear@2
|
441 cur_color.w = 1.0f;
|
nuclear@2
|
442 }
|
nuclear@2
|
443
|
nuclear@2
|
444 void gl_color4f(float r, float g, float b, float a)
|
nuclear@2
|
445 {
|
nuclear@2
|
446 cur_color.x = r;
|
nuclear@2
|
447 cur_color.y = g;
|
nuclear@2
|
448 cur_color.z = b;
|
nuclear@2
|
449 cur_color.w = a;
|
nuclear@2
|
450 }
|
nuclear@2
|
451
|
nuclear@2
|
452
|
nuclear@2
|
453 void gl_texcoord1f(float s)
|
nuclear@2
|
454 {
|
nuclear@2
|
455 cur_texcoord.x = s;
|
nuclear@2
|
456 cur_texcoord.y = 0.0f;
|
nuclear@2
|
457 }
|
nuclear@2
|
458
|
nuclear@2
|
459 void gl_texcoord2f(float s, float t)
|
nuclear@2
|
460 {
|
nuclear@2
|
461 cur_texcoord.x = s;
|
nuclear@2
|
462 cur_texcoord.y = t;
|
nuclear@2
|
463 }
|
nuclear@2
|
464
|
nuclear@2
|
465 void gl_vertex_attrib2f(int loc, float x, float y)
|
nuclear@2
|
466 {
|
nuclear@2
|
467 aloc = loc;
|
nuclear@2
|
468 cur_attrib.x = x;
|
nuclear@2
|
469 cur_attrib.y = y;
|
nuclear@2
|
470 cur_attrib.z = 0.0f;
|
nuclear@2
|
471 cur_attrib.w = 1.0f;
|
nuclear@2
|
472 }
|
nuclear@2
|
473
|
nuclear@2
|
474 void gl_vertex_attrib3f(int loc, float x, float y, float z)
|
nuclear@2
|
475 {
|
nuclear@2
|
476 aloc = loc;
|
nuclear@2
|
477 cur_attrib.x = x;
|
nuclear@2
|
478 cur_attrib.y = y;
|
nuclear@2
|
479 cur_attrib.z = z;
|
nuclear@2
|
480 cur_attrib.w = 1.0f;
|
nuclear@2
|
481 }
|
nuclear@2
|
482
|
nuclear@2
|
483 void gl_vertex_attrib4f(int loc, float x, float y, float z, float w)
|
nuclear@2
|
484 {
|
nuclear@2
|
485 aloc = loc;
|
nuclear@2
|
486 cur_attrib.x = x;
|
nuclear@2
|
487 cur_attrib.y = y;
|
nuclear@2
|
488 cur_attrib.z = z;
|
nuclear@2
|
489 cur_attrib.w = w;
|
nuclear@2
|
490 }
|