📄 pixelflinger.cpp
字号:
(param == GGL_LINEAR_MIPMAP_NEAREST) || (param == GGL_LINEAR_MIPMAP_LINEAR)) { what = &c->activeTMU->min_filter; param = GGL_LINEAR; } break; case GGL_TEXTURE_MAG_FILTER: if ((param == GGL_NEAREST) || (param == GGL_LINEAR)) { what = &c->activeTMU->mag_filter; } break; } if (!what) { ggl_error(c, GGL_INVALID_ENUM); return; } if (*what != param) { *what = param; ggl_state_changed(c, GGL_TMU_STATE); }}static void ggl_texCoordGradScale8xv(void* con, GGLint tmu, const int32_t* grad){ GGL_CONTEXT(c, con); texture_t& u = c->state.texture[tmu]; u.shade.is0 = grad[0]; u.shade.idsdx = grad[1]; u.shade.idsdy = grad[2]; u.shade.it0 = grad[3]; u.shade.idtdx = grad[4]; u.shade.idtdy = grad[5]; u.shade.sscale= grad[6]; u.shade.tscale= grad[7];}static void ggl_texCoord2x(void* con, GGLfixed s, GGLfixed t){ GGL_CONTEXT(c, con); c->activeTMU->shade.is0 = s; c->activeTMU->shade.it0 = t; c->activeTMU->shade.sscale= 0; c->activeTMU->shade.tscale= 0;}static void ggl_texCoord2i(void* con, GGLint s, GGLint t){ ggl_texCoord2x(con, s<<16, t<<16);}static void ggl_texGeni(void* con, GGLenum coord, GGLenum pname, GGLint param){ GGL_CONTEXT(c, con); if (pname != GGL_TEXTURE_GEN_MODE) { ggl_error(c, GGL_INVALID_ENUM); return; } uint32_t* coord_ptr = 0; if (coord == GGL_S) coord_ptr = &(c->activeTMU->s_coord); else if (coord == GGL_T) coord_ptr = &(c->activeTMU->t_coord); if (coord_ptr) { if (*coord_ptr != uint32_t(param)) { *coord_ptr = uint32_t(param); ggl_state_changed(c, GGL_TMU_STATE); } } else { ggl_error(c, GGL_INVALID_ENUM); }}static void ggl_activeTexture(void* con, GGLuint tmu){ GGL_CONTEXT(c, con); if (tmu >= GGLuint(GGL_TEXTURE_UNIT_COUNT)) { ggl_error(c, GGL_INVALID_ENUM); return; } c->activeTMUIndex = tmu; c->activeTMU = &(c->state.texture[tmu]);}// ----------------------------------------------------------------------------static void ggl_colorMask(void* con, GGLboolean r, GGLboolean g, GGLboolean b, GGLboolean a){ GGL_CONTEXT(c, con); int mask = 0; if (a) mask |= 1 << GGLFormat::ALPHA; if (r) mask |= 1 << GGLFormat::RED; if (g) mask |= 1 << GGLFormat::GREEN; if (b) mask |= 1 << GGLFormat::BLUE; if (c->state.mask.color != mask) { c->state.mask.color = mask; ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE); }}static void ggl_depthMask(void* con, GGLboolean flag){ GGL_CONTEXT(c, con); if (c->state.mask.depth != flag?1:0) { c->state.mask.depth = flag?1:0; ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE); }}static void ggl_stencilMask(void* con, GGLuint mask){ GGL_CONTEXT(c, con); if (c->state.mask.stencil != mask) { c->state.mask.stencil = mask; ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE); }}// ----------------------------------------------------------------------------static void ggl_alphaFuncx(void* con, GGLenum func, GGLclampx ref){ GGL_CONTEXT(c, con); if ((func < GGL_NEVER) || (func > GGL_ALWAYS)) { ggl_error(c, GGL_INVALID_ENUM); return; } c->state.alpha_test.ref = gglFixedToIteratedColor(gglClampx(ref)); if (c->state.alpha_test.func != func) { c->state.alpha_test.func = func; ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE); }}// ----------------------------------------------------------------------------static void ggl_depthFunc(void* con, GGLenum func){ GGL_CONTEXT(c, con); if ((func < GGL_NEVER) || (func > GGL_ALWAYS)) { ggl_error(c, GGL_INVALID_ENUM); return; } if (c->state.depth_test.func != func) { c->state.depth_test.func = func; ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE); }}// ----------------------------------------------------------------------------static void ggl_logicOp(void* con, GGLenum opcode){ GGL_CONTEXT(c, con); if ((opcode < GGL_CLEAR) || (opcode > GGL_SET)) { ggl_error(c, GGL_INVALID_ENUM); return; } if (c->state.logic_op.opcode != opcode) { c->state.logic_op.opcode = opcode; ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE); }}// ----------------------------------------------------------------------------void ggl_set_scissor(context_t* c){ if (c->state.enables & GGL_ENABLE_SCISSOR_TEST) { const int32_t l = c->state.scissor.user_left; const int32_t t = c->state.scissor.user_top; const int32_t r = c->state.scissor.user_right; const int32_t b = c->state.scissor.user_bottom; c->state.scissor.left = max(0, l); c->state.scissor.right = min(c->state.buffers.color.width, r); c->state.scissor.top = max(0, t); c->state.scissor.bottom = min(c->state.buffers.color.height, b); } else { c->state.scissor.left = 0; c->state.scissor.top = 0; c->state.scissor.right = c->state.buffers.color.width; c->state.scissor.bottom = c->state.buffers.color.height; }}void ggl_enable_blending(context_t* c, int enable){ const int e = (c->state.enables & GGL_ENABLE_BLENDING)?1:0; if (e != enable) { if (enable) c->state.enables |= GGL_ENABLE_BLENDING; else c->state.enables &= ~GGL_ENABLE_BLENDING; ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE); }}void ggl_enable_scissor_test(context_t* c, int enable){ const int e = (c->state.enables & GGL_ENABLE_SCISSOR_TEST)?1:0; if (e != enable) { if (enable) c->state.enables |= GGL_ENABLE_SCISSOR_TEST; else c->state.enables &= ~GGL_ENABLE_SCISSOR_TEST; ggl_set_scissor(c); }}void ggl_enable_alpha_test(context_t* c, int enable){ const int e = (c->state.enables & GGL_ENABLE_ALPHA_TEST)?1:0; if (e != enable) { if (enable) c->state.enables |= GGL_ENABLE_ALPHA_TEST; else c->state.enables &= ~GGL_ENABLE_ALPHA_TEST; ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE); }}void ggl_enable_logic_op(context_t* c, int enable){ const int e = (c->state.enables & GGL_ENABLE_LOGIC_OP)?1:0; if (e != enable) { if (enable) c->state.enables |= GGL_ENABLE_LOGIC_OP; else c->state.enables &= ~GGL_ENABLE_LOGIC_OP; ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE); }}void ggl_enable_dither(context_t* c, int enable){ const int e = (c->state.enables & GGL_ENABLE_DITHER)?1:0; if (e != enable) { if (enable) c->state.enables |= GGL_ENABLE_DITHER; else c->state.enables &= ~GGL_ENABLE_DITHER; ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE); }}void ggl_enable_stencil_test(context_t* c, int enable){}void ggl_enable_depth_test(context_t* c, int enable){ if (c->state.buffers.depth.format == 0) enable = 0; const int e = (c->state.enables & GGL_ENABLE_DEPTH_TEST)?1:0; if (e != enable) { if (enable) c->state.enables |= GGL_ENABLE_DEPTH_TEST; else c->state.enables &= ~GGL_ENABLE_DEPTH_TEST; ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE); }}void ggl_enable_aa(context_t* c, int enable){ const int e = (c->state.enables & GGL_ENABLE_AA)?1:0; if (e != enable) { if (enable) c->state.enables |= GGL_ENABLE_AA; else c->state.enables &= ~GGL_ENABLE_AA; ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE); }}void ggl_enable_point_aa_nice(context_t* c, int enable){ const int e = (c->state.enables & GGL_ENABLE_POINT_AA_NICE)?1:0; if (e != enable) { if (enable) c->state.enables |= GGL_ENABLE_POINT_AA_NICE; else c->state.enables &= ~GGL_ENABLE_POINT_AA_NICE; ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE); }}void ggl_enable_w_lerp(context_t* c, int enable){ const int e = (c->state.enables & GGL_ENABLE_W)?1:0; if (e != enable) { if (enable) c->state.enables |= GGL_ENABLE_W; else c->state.enables &= ~GGL_ENABLE_W; ggl_state_changed(c, GGL_PIXEL_PIPELINE_STATE); }}void ggl_enable_texture2d(context_t* c, int enable){ if (c->activeTMU->enable != enable) { const uint32_t tmu = c->activeTMUIndex; c->activeTMU->enable = enable; const uint32_t mask = 1UL << tmu; if (enable) c->state.enabled_tmu |= mask; else c->state.enabled_tmu &= ~mask; if (c->state.enabled_tmu) c->state.enables |= GGL_ENABLE_TMUS; else c->state.enables &= ~GGL_ENABLE_TMUS; ggl_state_changed(c, GGL_TMU_STATE); }} // ----------------------------------------------------------------------------int64_t ggl_system_time(){#if defined(HAVE_POSIX_CLOCKS) struct timespec t; t.tv_sec = t.tv_nsec = 0; clock_gettime(CLOCK_THREAD_CPUTIME_ID, &t); return int64_t(t.tv_sec)*1000000000LL + t.tv_nsec;#else // we don't support the clocks here. struct timeval t; t.tv_sec = t.tv_usec = 0; gettimeofday(&t, NULL); return int64_t(t.tv_sec)*1000000000LL + int64_t(t.tv_usec)*1000LL;#endif}// ----------------------------------------------------------------------------void ggl_init_procs(context_t* c){ GGLContext& procs = *(GGLContext*)c; GGL_INIT_PROC(procs, scissor); GGL_INIT_PROC(procs, activeTexture); GGL_INIT_PROC(procs, bindTexture); GGL_INIT_PROC(procs, bindTextureLod); GGL_INIT_PROC(procs, colorBuffer); GGL_INIT_PROC(procs, readBuffer); GGL_INIT_PROC(procs, depthBuffer); GGL_INIT_PROC(procs, enable); GGL_INIT_PROC(procs, disable); GGL_INIT_PROC(procs, enableDisable); GGL_INIT_PROC(procs, shadeModel); GGL_INIT_PROC(procs, color4xv); GGL_INIT_PROC(procs, colorGrad12xv); GGL_INIT_PROC(procs, zGrad3xv); GGL_INIT_PROC(procs, wGrad3xv); GGL_INIT_PROC(procs, fogGrad3xv); GGL_INIT_PROC(procs, fogColor3xv); GGL_INIT_PROC(procs, blendFunc); GGL_INIT_PROC(procs, blendFuncSeparate); GGL_INIT_PROC(procs, texEnvi); GGL_INIT_PROC(procs, texEnvxv); GGL_INIT_PROC(procs, texParameteri); GGL_INIT_PROC(procs, texCoord2i); GGL_INIT_PROC(procs, texCoord2x); GGL_INIT_PROC(procs, texCoordGradScale8xv); GGL_INIT_PROC(procs, texGeni); GGL_INIT_PROC(procs, colorMask); GGL_INIT_PROC(procs, depthMask); GGL_INIT_PROC(procs, stencilMask); GGL_INIT_PROC(procs, alphaFuncx); GGL_INIT_PROC(procs, depthFunc); GGL_INIT_PROC(procs, logicOp); ggl_init_clear(c);}void ggl_init_context(context_t* c){ memset(c, 0, sizeof(context_t)); ggl_init_procs(c); ggl_init_trap(c); ggl_init_scanline(c); ggl_init_texture(c); ggl_init_picker(c); ggl_init_raster(c); c->formats = gglGetPixelFormatTable(); c->state.blend.src = GGL_ONE; c->state.blend.dst = GGL_ZERO; c->state.blend.src_alpha = GGL_ONE; c->state.blend.dst_alpha = GGL_ZERO; c->state.mask.color = 0xF; c->state.mask.depth = 0; c->state.mask.stencil = 0xFFFFFFFF; c->state.logic_op.opcode = GGL_COPY; c->state.alpha_test.func = GGL_ALWAYS; c->state.depth_test.func = GGL_LESS; c->state.depth_test.clearValue = FIXED_ONE; c->shade.w0 = FIXED_ONE; memcpy(c->ditherMatrix, gDitherMatrix, sizeof(gDitherMatrix));}void ggl_uninit_context(context_t* c){ ggl_uninit_scanline(c);}// ----------------------------------------------------------------------------}; // namespace android// ----------------------------------------------------------------------------using namespace android;ssize_t gglInit(GGLContext** context){ void* const base = malloc(sizeof(context_t) + 32); if (base) { // always align the context on cache lines context_t *c = (context_t *)((ptrdiff_t(base)+31) & ~0x1FL); ggl_init_context(c); c->base = base; *context = (GGLContext*)c; } else { return -1; } return 0;}ssize_t gglUninit(GGLContext* con){ GGL_CONTEXT(c, (void*)con); ggl_uninit_context(c); free(c->base); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -