1 /* libs/pixelflinger/pixelflinger.cpp
3 ** Copyright 2006, The Android Open Source Project
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
9 ** http://www.apache.org/licenses/LICENSE-2.0
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
25 #include <pixelflinger/pixelflinger.h>
26 #include <private/pixelflinger/ggl_context.h>
35 #include "codeflinger/GGLAssembler.h"
36 #include "codeflinger/CodeCache.h"
43 // ----------------------------------------------------------------------------
45 // 8x8 Bayer dither matrix
46 static const uint8_t gDitherMatrix[GGL_DITHER_SIZE] = {
47 0, 32, 8, 40, 2, 34, 10, 42,
48 48, 16, 56, 24, 50, 18, 58, 26,
49 12, 44, 4, 36, 14, 46, 6, 38,
50 60, 28, 52, 20, 62, 30, 54, 22,
51 3, 35, 11, 43, 1, 33, 9, 41,
52 51, 19, 59, 27, 49, 17, 57, 25,
53 15, 47, 7, 39, 13, 45, 5, 37,
54 63, 31, 55, 23, 61, 29, 53, 21
57 static void ggl_init_procs(context_t* c);
58 static void ggl_set_scissor(context_t* c);
60 static void ggl_enable_blending(context_t* c, int enable);
61 static void ggl_enable_scissor_test(context_t* c, int enable);
62 static void ggl_enable_alpha_test(context_t* c, int enable);
63 static void ggl_enable_logic_op(context_t* c, int enable);
64 static void ggl_enable_dither(context_t* c, int enable);
65 static void ggl_enable_stencil_test(context_t* c, int enable);
66 static void ggl_enable_depth_test(context_t* c, int enable);
67 static void ggl_enable_aa(context_t* c, int enable);
68 static void ggl_enable_point_aa_nice(context_t* c, int enable);
69 static void ggl_enable_texture2d(context_t* c, int enable);
70 static void ggl_enable_w_lerp(context_t* c, int enable);
71 static void ggl_enable_fog(context_t* c, int enable);
73 static inline int min(int a, int b) CONST;
74 static inline int min(int a, int b) {
78 static inline int max(int a, int b) CONST;
79 static inline int max(int a, int b) {
83 // ----------------------------------------------------------------------------
85 void ggl_error(context_t* c, GGLenum error)
87 if (c->error == GGL_NO_ERROR)
91 // ----------------------------------------------------------------------------
93 static void ggl_bindTexture(void* con, const GGLSurface* surface)
96 if (surface->format != c->activeTMU->surface.format)
97 ggl_state_changed(c, GGL_TMU_STATE);
98 ggl_set_surface(c, &(c->activeTMU->surface), surface);
102 static void ggl_bindTextureLod(void* con, GGLuint tmu,const GGLSurface* surface)
105 // All LODs must have the same format
106 ggl_set_surface(c, &c->state.texture[tmu].surface, surface);
109 static void ggl_colorBuffer(void* con, const GGLSurface* surface)
112 if (surface->format != c->state.buffers.color.format)
113 ggl_state_changed(c, GGL_CB_STATE);
115 if (surface->width > c->state.buffers.coverageBufferSize) {
116 // allocate the coverage factor buffer
117 free(c->state.buffers.coverage);
118 c->state.buffers.coverage = (int16_t*)malloc(surface->width * 2);
119 c->state.buffers.coverageBufferSize =
120 c->state.buffers.coverage ? surface->width : 0;
122 ggl_set_surface(c, &(c->state.buffers.color), surface);
123 if (c->state.buffers.read.format == 0) {
124 ggl_set_surface(c, &(c->state.buffers.read), surface);
129 static void ggl_readBuffer(void* con, const GGLSurface* surface)
132 ggl_set_surface(c, &(c->state.buffers.read), surface);
135 static void ggl_depthBuffer(void* con, const GGLSurface* surface)
138 if (surface->format == GGL_PIXEL_FORMAT_Z_16) {
139 ggl_set_surface(c, &(c->state.buffers.depth), surface);
141 c->state.buffers.depth.format = GGL_PIXEL_FORMAT_NONE;
142 ggl_enable_depth_test(c, 0);
146 static void ggl_scissor(void* con, GGLint x, GGLint y,
147 GGLsizei width, GGLsizei height)
150 c->state.scissor.user_left = x;
151 c->state.scissor.user_top = y;
152 c->state.scissor.user_right = x + width;
153 c->state.scissor.user_bottom = y + height;
157 // ----------------------------------------------------------------------------
159 static void enable_disable(context_t* c, GGLenum name, int en)
162 case GGL_BLEND: ggl_enable_blending(c, en); break;
163 case GGL_SCISSOR_TEST: ggl_enable_scissor_test(c, en); break;
164 case GGL_ALPHA_TEST: ggl_enable_alpha_test(c, en); break;
165 case GGL_COLOR_LOGIC_OP: ggl_enable_logic_op(c, en); break;
166 case GGL_DITHER: ggl_enable_dither(c, en); break;
167 case GGL_STENCIL_TEST: ggl_enable_stencil_test(c, en); break;
168 case GGL_DEPTH_TEST: ggl_enable_depth_test(c, en); break;
169 case GGL_AA: ggl_enable_aa(c, en); break;
170 case GGL_TEXTURE_2D: ggl_enable_texture2d(c, en); break;
171 case GGL_W_LERP: ggl_enable_w_lerp(c, en); break;
172 case GGL_FOG: ggl_enable_fog(c, en); break;
173 case GGL_POINT_SMOOTH_NICE: ggl_enable_point_aa_nice(c, en); break;
177 static void ggl_enable(void* con, GGLenum name)
180 enable_disable(c, name, 1);
183 static void ggl_disable(void* con, GGLenum name)
186 enable_disable(c, name, 0);
189 static void ggl_enableDisable(void* con, GGLenum name, GGLboolean en)
192 enable_disable(c, name, en ? 1 : 0);
195 // ----------------------------------------------------------------------------
197 static void ggl_shadeModel(void* con, GGLenum mode)
202 if (c->state.enables & GGL_ENABLE_SMOOTH) {
203 c->state.enables &= ~GGL_ENABLE_SMOOTH;
204 ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE);
208 if (!(c->state.enables & GGL_ENABLE_SMOOTH)) {
209 c->state.enables |= GGL_ENABLE_SMOOTH;
210 ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE);
214 ggl_error(c, GGL_INVALID_ENUM);
218 static void ggl_color4xv(void* con, const GGLclampx* color)
221 c->shade.r0 = gglFixedToIteratedColor(color[0]);
222 c->shade.g0 = gglFixedToIteratedColor(color[1]);
223 c->shade.b0 = gglFixedToIteratedColor(color[2]);
224 c->shade.a0 = gglFixedToIteratedColor(color[3]);
227 static void ggl_colorGrad12xv(void* con, const GGLcolor* grad)
230 // it is very important to round the iterated value here because
231 // the rasterizer doesn't clamp them, therefore the iterated value
232 //must absolutely be correct.
233 // GGLColor is encoded as 8.16 value
234 const int32_t round = 0x8000;
235 c->shade.r0 = grad[ 0] + round;
236 c->shade.drdx = grad[ 1];
237 c->shade.drdy = grad[ 2];
238 c->shade.g0 = grad[ 3] + round;
239 c->shade.dgdx = grad[ 4];
240 c->shade.dgdy = grad[ 5];
241 c->shade.b0 = grad[ 6] + round;
242 c->shade.dbdx = grad[ 7];
243 c->shade.dbdy = grad[ 8];
244 c->shade.a0 = grad[ 9] + round;
245 c->shade.dadx = grad[10];
246 c->shade.dady = grad[11];
249 static void ggl_zGrad3xv(void* con, const GGLfixed32* grad)
252 // z iterators are encoded as 0.32 fixed point and the z-buffer
253 // holds 16 bits, the rounding value is 0x8000.
254 const uint32_t round = 0x8000;
255 c->shade.z0 = grad[0] + round;
256 c->shade.dzdx = grad[1];
257 c->shade.dzdy = grad[2];
260 static void ggl_wGrad3xv(void* con, const GGLfixed* grad)
263 c->shade.w0 = grad[0];
264 c->shade.dwdx = grad[1];
265 c->shade.dwdy = grad[2];
268 // ----------------------------------------------------------------------------
270 static void ggl_fogGrad3xv(void* con, const GGLfixed* grad)
273 c->shade.f0 = grad[0];
274 c->shade.dfdx = grad[1];
275 c->shade.dfdy = grad[2];
278 static void ggl_fogColor3xv(void* con, const GGLclampx* color)
281 const int32_t r = gglClampx(color[0]);
282 const int32_t g = gglClampx(color[1]);
283 const int32_t b = gglClampx(color[2]);
284 c->state.fog.color[GGLFormat::ALPHA]= 0xFF; // unused
285 c->state.fog.color[GGLFormat::RED] = (r - (r>>8))>>8;
286 c->state.fog.color[GGLFormat::GREEN]= (g - (g>>8))>>8;
287 c->state.fog.color[GGLFormat::BLUE] = (b - (b>>8))>>8;
290 static void ggl_enable_fog(context_t* c, int enable)
292 const int e = (c->state.enables & GGL_ENABLE_FOG)?1:0;
294 if (enable) c->state.enables |= GGL_ENABLE_FOG;
295 else c->state.enables &= ~GGL_ENABLE_FOG;
296 ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE);
300 // ----------------------------------------------------------------------------
302 static void ggl_blendFunc(void* con, GGLenum src, GGLenum dst)
305 c->state.blend.src = src;
306 c->state.blend.src_alpha = src;
307 c->state.blend.dst = dst;
308 c->state.blend.dst_alpha = dst;
309 c->state.blend.alpha_separate = 0;
310 if (c->state.enables & GGL_ENABLE_BLENDING) {
311 ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE);
315 static void ggl_blendFuncSeparate(void* con,
316 GGLenum src, GGLenum dst,
317 GGLenum srcAlpha, GGLenum dstAplha)
320 c->state.blend.src = src;
321 c->state.blend.src_alpha = srcAlpha;
322 c->state.blend.dst = dst;
323 c->state.blend.dst_alpha = dstAplha;
324 c->state.blend.alpha_separate = 1;
325 if (c->state.enables & GGL_ENABLE_BLENDING) {
326 ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE);
330 // ----------------------------------------------------------------------------
332 static void ggl_texEnvi(void* con, GGLenum target,
337 if (target != GGL_TEXTURE_ENV || pname != GGL_TEXTURE_ENV_MODE) {
338 ggl_error(c, GGL_INVALID_ENUM);
347 if (c->activeTMU->env != param) {
348 c->activeTMU->env = param;
349 ggl_state_changed(c, GGL_TMU_STATE);
353 ggl_error(c, GGL_INVALID_ENUM);
357 static void ggl_texEnvxv(void* con, GGLenum target,
358 GGLenum pname, const GGLfixed* params)
361 if (target != GGL_TEXTURE_ENV) {
362 ggl_error(c, GGL_INVALID_ENUM);
366 case GGL_TEXTURE_ENV_MODE:
367 ggl_texEnvi(con, target, pname, params[0]);
369 case GGL_TEXTURE_ENV_COLOR: {
370 uint8_t* const color = c->activeTMU->env_color;
371 const GGLclampx r = gglClampx(params[0]);
372 const GGLclampx g = gglClampx(params[1]);
373 const GGLclampx b = gglClampx(params[2]);
374 const GGLclampx a = gglClampx(params[3]);
375 color[0] = (a-(a>>8))>>8;
376 color[1] = (r-(r>>8))>>8;
377 color[2] = (g-(g>>8))>>8;
378 color[3] = (b-(b>>8))>>8;
382 ggl_error(c, GGL_INVALID_ENUM);
388 static void ggl_texParameteri(void* con,
394 if (target != GGL_TEXTURE_2D) {
395 ggl_error(c, GGL_INVALID_ENUM);
399 if (param == GGL_CLAMP_TO_EDGE)
404 case GGL_TEXTURE_WRAP_S:
405 if ((param == GGL_CLAMP) ||
406 (param == GGL_REPEAT)) {
407 what = &c->activeTMU->s_wrap;
410 case GGL_TEXTURE_WRAP_T:
411 if ((param == GGL_CLAMP) ||
412 (param == GGL_REPEAT)) {
413 what = &c->activeTMU->t_wrap;
416 case GGL_TEXTURE_MIN_FILTER:
417 if ((param == GGL_NEAREST) ||
418 (param == GGL_NEAREST_MIPMAP_NEAREST) ||
419 (param == GGL_NEAREST_MIPMAP_LINEAR)) {
420 what = &c->activeTMU->min_filter;
423 if ((param == GGL_LINEAR) ||
424 (param == GGL_LINEAR_MIPMAP_NEAREST) ||
425 (param == GGL_LINEAR_MIPMAP_LINEAR)) {
426 what = &c->activeTMU->min_filter;
430 case GGL_TEXTURE_MAG_FILTER:
431 if ((param == GGL_NEAREST) ||
432 (param == GGL_LINEAR)) {
433 what = &c->activeTMU->mag_filter;
439 ggl_error(c, GGL_INVALID_ENUM);
443 if (*what != param) {
445 ggl_state_changed(c, GGL_TMU_STATE);
449 static void ggl_texCoordGradScale8xv(void* con, GGLint tmu, const int32_t* grad)
452 texture_t& u = c->state.texture[tmu];
453 u.shade.is0 = grad[0];
454 u.shade.idsdx = grad[1];
455 u.shade.idsdy = grad[2];
456 u.shade.it0 = grad[3];
457 u.shade.idtdx = grad[4];
458 u.shade.idtdy = grad[5];
459 u.shade.sscale= grad[6];
460 u.shade.tscale= grad[7];
463 static void ggl_texCoord2x(void* con, GGLfixed s, GGLfixed t)
466 c->activeTMU->shade.is0 = s;
467 c->activeTMU->shade.it0 = t;
468 c->activeTMU->shade.sscale= 0;
469 c->activeTMU->shade.tscale= 0;
472 static void ggl_texCoord2i(void* con, GGLint s, GGLint t)
474 ggl_texCoord2x(con, s<<16, t<<16);
477 static void ggl_texGeni(void* con, GGLenum coord, GGLenum pname, GGLint param)
480 if (pname != GGL_TEXTURE_GEN_MODE) {
481 ggl_error(c, GGL_INVALID_ENUM);
485 uint32_t* coord_ptr = 0;
486 if (coord == GGL_S) coord_ptr = &(c->activeTMU->s_coord);
487 else if (coord == GGL_T) coord_ptr = &(c->activeTMU->t_coord);
490 if (*coord_ptr != uint32_t(param)) {
491 *coord_ptr = uint32_t(param);
492 ggl_state_changed(c, GGL_TMU_STATE);
495 ggl_error(c, GGL_INVALID_ENUM);
499 static void ggl_activeTexture(void* con, GGLuint tmu)
502 if (tmu >= GGLuint(GGL_TEXTURE_UNIT_COUNT)) {
503 ggl_error(c, GGL_INVALID_ENUM);
506 c->activeTMUIndex = tmu;
507 c->activeTMU = &(c->state.texture[tmu]);
510 // ----------------------------------------------------------------------------
512 static void ggl_colorMask(void* con, GGLboolean r,
519 if (a) mask |= 1 << GGLFormat::ALPHA;
520 if (r) mask |= 1 << GGLFormat::RED;
521 if (g) mask |= 1 << GGLFormat::GREEN;
522 if (b) mask |= 1 << GGLFormat::BLUE;
523 if (c->state.mask.color != mask) {
524 c->state.mask.color = mask;
525 ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE);
529 static void ggl_depthMask(void* con, GGLboolean flag)
532 if (c->state.mask.depth != flag?1:0) {
533 c->state.mask.depth = flag?1:0;
534 ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE);
538 static void ggl_stencilMask(void* con, GGLuint mask)
541 if (c->state.mask.stencil != mask) {
542 c->state.mask.stencil = mask;
543 ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE);
547 // ----------------------------------------------------------------------------
549 static void ggl_alphaFuncx(void* con, GGLenum func, GGLclampx ref)
552 if ((func < GGL_NEVER) || (func > GGL_ALWAYS)) {
553 ggl_error(c, GGL_INVALID_ENUM);
556 c->state.alpha_test.ref = gglFixedToIteratedColor(gglClampx(ref));
557 if (c->state.alpha_test.func != func) {
558 c->state.alpha_test.func = func;
559 ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE);
563 // ----------------------------------------------------------------------------
565 static void ggl_depthFunc(void* con, GGLenum func)
568 if ((func < GGL_NEVER) || (func > GGL_ALWAYS)) {
569 ggl_error(c, GGL_INVALID_ENUM);
572 if (c->state.depth_test.func != func) {
573 c->state.depth_test.func = func;
574 ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE);
578 // ----------------------------------------------------------------------------
580 static void ggl_logicOp(void* con, GGLenum opcode)
583 if ((opcode < GGL_CLEAR) || (opcode > GGL_SET)) {
584 ggl_error(c, GGL_INVALID_ENUM);
587 if (c->state.logic_op.opcode != opcode) {
588 c->state.logic_op.opcode = opcode;
589 ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE);
594 // ----------------------------------------------------------------------------
596 void ggl_set_scissor(context_t* c)
598 if (c->state.enables & GGL_ENABLE_SCISSOR_TEST) {
599 const int32_t l = c->state.scissor.user_left;
600 const int32_t t = c->state.scissor.user_top;
601 const int32_t r = c->state.scissor.user_right;
602 const int32_t b = c->state.scissor.user_bottom;
603 c->state.scissor.left = max(0, l);
604 c->state.scissor.right = min(c->state.buffers.color.width, r);
605 c->state.scissor.top = max(0, t);
606 c->state.scissor.bottom = min(c->state.buffers.color.height, b);
608 c->state.scissor.left = 0;
609 c->state.scissor.top = 0;
610 c->state.scissor.right = c->state.buffers.color.width;
611 c->state.scissor.bottom = c->state.buffers.color.height;
615 void ggl_enable_blending(context_t* c, int enable)
617 const int e = (c->state.enables & GGL_ENABLE_BLENDING)?1:0;
619 if (enable) c->state.enables |= GGL_ENABLE_BLENDING;
620 else c->state.enables &= ~GGL_ENABLE_BLENDING;
621 ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE);
625 void ggl_enable_scissor_test(context_t* c, int enable)
627 const int e = (c->state.enables & GGL_ENABLE_SCISSOR_TEST)?1:0;
629 if (enable) c->state.enables |= GGL_ENABLE_SCISSOR_TEST;
630 else c->state.enables &= ~GGL_ENABLE_SCISSOR_TEST;
635 void ggl_enable_alpha_test(context_t* c, int enable)
637 const int e = (c->state.enables & GGL_ENABLE_ALPHA_TEST)?1:0;
639 if (enable) c->state.enables |= GGL_ENABLE_ALPHA_TEST;
640 else c->state.enables &= ~GGL_ENABLE_ALPHA_TEST;
641 ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE);
645 void ggl_enable_logic_op(context_t* c, int enable)
647 const int e = (c->state.enables & GGL_ENABLE_LOGIC_OP)?1:0;
649 if (enable) c->state.enables |= GGL_ENABLE_LOGIC_OP;
650 else c->state.enables &= ~GGL_ENABLE_LOGIC_OP;
651 ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE);
655 void ggl_enable_dither(context_t* c, int enable)
657 const int e = (c->state.enables & GGL_ENABLE_DITHER)?1:0;
659 if (enable) c->state.enables |= GGL_ENABLE_DITHER;
660 else c->state.enables &= ~GGL_ENABLE_DITHER;
661 ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE);
665 void ggl_enable_stencil_test(context_t* c, int enable)
669 void ggl_enable_depth_test(context_t* c, int enable)
671 if (c->state.buffers.depth.format == 0)
673 const int e = (c->state.enables & GGL_ENABLE_DEPTH_TEST)?1:0;
675 if (enable) c->state.enables |= GGL_ENABLE_DEPTH_TEST;
676 else c->state.enables &= ~GGL_ENABLE_DEPTH_TEST;
677 ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE);
681 void ggl_enable_aa(context_t* c, int enable)
683 const int e = (c->state.enables & GGL_ENABLE_AA)?1:0;
685 if (enable) c->state.enables |= GGL_ENABLE_AA;
686 else c->state.enables &= ~GGL_ENABLE_AA;
687 ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE);
691 void ggl_enable_point_aa_nice(context_t* c, int enable)
693 const int e = (c->state.enables & GGL_ENABLE_POINT_AA_NICE)?1:0;
695 if (enable) c->state.enables |= GGL_ENABLE_POINT_AA_NICE;
696 else c->state.enables &= ~GGL_ENABLE_POINT_AA_NICE;
697 ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE);
701 void ggl_enable_w_lerp(context_t* c, int enable)
703 const int e = (c->state.enables & GGL_ENABLE_W)?1:0;
705 if (enable) c->state.enables |= GGL_ENABLE_W;
706 else c->state.enables &= ~GGL_ENABLE_W;
707 ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE);
711 void ggl_enable_texture2d(context_t* c, int enable)
713 if (c->activeTMU->enable != enable) {
714 const uint32_t tmu = c->activeTMUIndex;
715 c->activeTMU->enable = enable;
716 const uint32_t mask = 1UL << tmu;
717 if (enable) c->state.enabled_tmu |= mask;
718 else c->state.enabled_tmu &= ~mask;
719 if (c->state.enabled_tmu) c->state.enables |= GGL_ENABLE_TMUS;
720 else c->state.enables &= ~GGL_ENABLE_TMUS;
721 ggl_state_changed(c, GGL_TMU_STATE);
726 // ----------------------------------------------------------------------------
728 int64_t ggl_system_time()
730 #if defined(HAVE_POSIX_CLOCKS)
732 t.tv_sec = t.tv_nsec = 0;
733 clock_gettime(CLOCK_THREAD_CPUTIME_ID, &t);
734 return int64_t(t.tv_sec)*1000000000LL + t.tv_nsec;
736 // we don't support the clocks here.
738 t.tv_sec = t.tv_usec = 0;
739 gettimeofday(&t, NULL);
740 return int64_t(t.tv_sec)*1000000000LL + int64_t(t.tv_usec)*1000LL;
744 // ----------------------------------------------------------------------------
746 void ggl_init_procs(context_t* c)
748 GGLContext& procs = *(GGLContext*)c;
749 GGL_INIT_PROC(procs, scissor);
750 GGL_INIT_PROC(procs, activeTexture);
751 GGL_INIT_PROC(procs, bindTexture);
752 GGL_INIT_PROC(procs, bindTextureLod);
753 GGL_INIT_PROC(procs, colorBuffer);
754 GGL_INIT_PROC(procs, readBuffer);
755 GGL_INIT_PROC(procs, depthBuffer);
756 GGL_INIT_PROC(procs, enable);
757 GGL_INIT_PROC(procs, disable);
758 GGL_INIT_PROC(procs, enableDisable);
759 GGL_INIT_PROC(procs, shadeModel);
760 GGL_INIT_PROC(procs, color4xv);
761 GGL_INIT_PROC(procs, colorGrad12xv);
762 GGL_INIT_PROC(procs, zGrad3xv);
763 GGL_INIT_PROC(procs, wGrad3xv);
764 GGL_INIT_PROC(procs, fogGrad3xv);
765 GGL_INIT_PROC(procs, fogColor3xv);
766 GGL_INIT_PROC(procs, blendFunc);
767 GGL_INIT_PROC(procs, blendFuncSeparate);
768 GGL_INIT_PROC(procs, texEnvi);
769 GGL_INIT_PROC(procs, texEnvxv);
770 GGL_INIT_PROC(procs, texParameteri);
771 GGL_INIT_PROC(procs, texCoord2i);
772 GGL_INIT_PROC(procs, texCoord2x);
773 GGL_INIT_PROC(procs, texCoordGradScale8xv);
774 GGL_INIT_PROC(procs, texGeni);
775 GGL_INIT_PROC(procs, colorMask);
776 GGL_INIT_PROC(procs, depthMask);
777 GGL_INIT_PROC(procs, stencilMask);
778 GGL_INIT_PROC(procs, alphaFuncx);
779 GGL_INIT_PROC(procs, depthFunc);
780 GGL_INIT_PROC(procs, logicOp);
784 void ggl_init_context(context_t* c)
786 memset(c, 0, sizeof(context_t));
789 ggl_init_scanline(c);
793 c->formats = gglGetPixelFormatTable();
794 c->state.blend.src = GGL_ONE;
795 c->state.blend.dst = GGL_ZERO;
796 c->state.blend.src_alpha = GGL_ONE;
797 c->state.blend.dst_alpha = GGL_ZERO;
798 c->state.mask.color = 0xF;
799 c->state.mask.depth = 0;
800 c->state.mask.stencil = 0xFFFFFFFF;
801 c->state.logic_op.opcode = GGL_COPY;
802 c->state.alpha_test.func = GGL_ALWAYS;
803 c->state.depth_test.func = GGL_LESS;
804 c->state.depth_test.clearValue = FIXED_ONE;
805 c->shade.w0 = FIXED_ONE;
806 memcpy(c->ditherMatrix, gDitherMatrix, sizeof(gDitherMatrix));
809 void ggl_uninit_context(context_t* c)
811 ggl_uninit_scanline(c);
814 // ----------------------------------------------------------------------------
815 }; // namespace android
816 // ----------------------------------------------------------------------------
820 using namespace android;
822 ssize_t gglInit(GGLContext** context)
824 void* const base = malloc(sizeof(context_t) + 32);
826 // always align the context on cache lines
827 context_t *c = (context_t *)((ptrdiff_t(base)+31) & ~0x1FL);
830 *context = (GGLContext*)c;
837 ssize_t gglUninit(GGLContext* con)
839 GGL_CONTEXT(c, (void*)con);
840 ggl_uninit_context(c);