📄 r128_state.c
字号:
{ r128ContextPtr rmesa = R128_CONTEXT(ctx); FALLBACK( rmesa, R128_FALLBACK_RENDER_MODE, (mode != GL_RENDER) );}/* ============================================================= * State enable/disable */static void r128DDEnable( GLcontext *ctx, GLenum cap, GLboolean state ){ r128ContextPtr rmesa = R128_CONTEXT(ctx); if ( R128_DEBUG & DEBUG_VERBOSE_API ) { fprintf( stderr, "%s( %s = %s )\n", __FUNCTION__, _mesa_lookup_enum_by_nr( cap ), state ? "GL_TRUE" : "GL_FALSE" ); } switch ( cap ) { case GL_ALPHA_TEST: FLUSH_BATCH( rmesa ); rmesa->new_state |= R128_NEW_ALPHA; break; case GL_BLEND: FLUSH_BATCH( rmesa ); rmesa->new_state |= R128_NEW_ALPHA; /* For some reason enable(GL_BLEND) affects ColorLogicOpEnabled. */ FALLBACK( rmesa, R128_FALLBACK_LOGICOP, (ctx->Color.ColorLogicOpEnabled && ctx->Color.LogicOp != GL_COPY)); break; case GL_CULL_FACE: FLUSH_BATCH( rmesa ); rmesa->new_state |= R128_NEW_CULL; break; case GL_DEPTH_TEST: FLUSH_BATCH( rmesa ); rmesa->new_state |= R128_NEW_DEPTH; break; case GL_DITHER: do { GLuint t = rmesa->setup.tex_cntl_c; FLUSH_BATCH( rmesa ); if ( ctx->Color.DitherFlag ) { t |= R128_DITHER_ENABLE; } else { t &= ~R128_DITHER_ENABLE; } if ( rmesa->setup.tex_cntl_c != t ) { rmesa->setup.tex_cntl_c = t; rmesa->dirty |= R128_UPLOAD_CONTEXT; } } while (0); break; case GL_FOG: FLUSH_BATCH( rmesa ); rmesa->new_state |= R128_NEW_FOG; break; case GL_COLOR_LOGIC_OP: FLUSH_BATCH( rmesa ); FALLBACK( rmesa, R128_FALLBACK_LOGICOP, state && ctx->Color.LogicOp != GL_COPY ); break; case GL_LIGHTING: case GL_COLOR_SUM_EXT: updateSpecularLighting(ctx); break; case GL_SCISSOR_TEST: FLUSH_BATCH( rmesa ); rmesa->scissor = state; rmesa->new_state |= R128_NEW_CLIP; break; case GL_STENCIL_TEST: FLUSH_BATCH( rmesa ); if ( ctx->Visual.stencilBits > 0 && ctx->Visual.depthBits == 24 ) { if ( state ) { rmesa->setup.tex_cntl_c |= R128_STENCIL_ENABLE; /* Reset the fallback (if any) for bad stencil funcs */ r128DDStencilOpSeparate( ctx, 0, ctx->Stencil.FailFunc[0], ctx->Stencil.ZFailFunc[0], ctx->Stencil.ZPassFunc[0] ); } else { rmesa->setup.tex_cntl_c &= ~R128_STENCIL_ENABLE; FALLBACK( rmesa, R128_FALLBACK_STENCIL, GL_FALSE ); } rmesa->dirty |= R128_UPLOAD_CONTEXT; } else { FALLBACK( rmesa, R128_FALLBACK_STENCIL, state ); } break; case GL_TEXTURE_1D: case GL_TEXTURE_2D: case GL_TEXTURE_3D: FLUSH_BATCH( rmesa ); break; case GL_POLYGON_STIPPLE: if ( rmesa->render_primitive == GL_TRIANGLES ) { FLUSH_BATCH( rmesa ); rmesa->setup.dp_gui_master_cntl_c &= ~R128_GMC_BRUSH_NONE; if ( state ) { rmesa->setup.dp_gui_master_cntl_c |= R128_GMC_BRUSH_32x32_MONO_FG_LA; } else { rmesa->setup.dp_gui_master_cntl_c |= R128_GMC_BRUSH_SOLID_COLOR; } rmesa->new_state |= R128_NEW_CONTEXT; rmesa->dirty |= R128_UPLOAD_CONTEXT; } break; default: return; }}/* ============================================================= * State initialization, management */static void r128DDPrintDirty( const char *msg, GLuint state ){ fprintf( stderr, "%s: (0x%x) %s%s%s%s%s%s%s%s%s\n", msg, state, (state & R128_UPLOAD_CORE) ? "core, " : "", (state & R128_UPLOAD_CONTEXT) ? "context, " : "", (state & R128_UPLOAD_SETUP) ? "setup, " : "", (state & R128_UPLOAD_TEX0) ? "tex0, " : "", (state & R128_UPLOAD_TEX1) ? "tex1, " : "", (state & R128_UPLOAD_MASKS) ? "masks, " : "", (state & R128_UPLOAD_WINDOW) ? "window, " : "", (state & R128_UPLOAD_CLIPRECTS) ? "cliprects, " : "", (state & R128_REQUIRE_QUIESCENCE) ? "quiescence, " : "" );}/* * Load the current context's state into the hardware. * * NOTE: Be VERY careful about ensuring the context state is marked for * upload, the only place it shouldn't be uploaded is when the setup * state has changed in ReducedPrimitiveChange as this comes right after * a state update. * * Blits of any type should always upload the context and masks after * they are done. */void r128EmitHwStateLocked( r128ContextPtr rmesa ){ drm_r128_sarea_t *sarea = rmesa->sarea; drm_r128_context_regs_t *regs = &(rmesa->setup); const r128TexObjPtr t0 = rmesa->CurrentTexObj[0]; const r128TexObjPtr t1 = rmesa->CurrentTexObj[1]; if ( R128_DEBUG & DEBUG_VERBOSE_MSG ) { r128DDPrintDirty( "r128EmitHwStateLocked", rmesa->dirty ); } if ( rmesa->dirty & (R128_UPLOAD_CONTEXT | R128_UPLOAD_SETUP | R128_UPLOAD_MASKS | R128_UPLOAD_WINDOW | R128_UPLOAD_CORE) ) { memcpy( &sarea->context_state, regs, sizeof(sarea->context_state) ); if( rmesa->dirty & R128_UPLOAD_CONTEXT ) { /* One possible side-effect of uploading a new context is the * setting of the R128_GMC_AUX_CLIP_DIS bit, which causes all * auxilliary cliprects to be disabled. So the next command must * upload them again. */ rmesa->dirty |= R128_UPLOAD_CLIPRECTS; } } if ( (rmesa->dirty & R128_UPLOAD_TEX0) && t0 ) { drm_r128_texture_regs_t *tex = &sarea->tex_state[0]; tex->tex_cntl = t0->setup.tex_cntl; tex->tex_combine_cntl = rmesa->tex_combine[0]; tex->tex_size_pitch = t0->setup.tex_size_pitch; memcpy( &tex->tex_offset[0], &t0->setup.tex_offset[0], sizeof(tex->tex_offset ) ); tex->tex_border_color = t0->setup.tex_border_color; } if ( (rmesa->dirty & R128_UPLOAD_TEX1) && t1 ) { drm_r128_texture_regs_t *tex = &sarea->tex_state[1]; tex->tex_cntl = t1->setup.tex_cntl; tex->tex_combine_cntl = rmesa->tex_combine[1]; tex->tex_size_pitch = t1->setup.tex_size_pitch; memcpy( &tex->tex_offset[0], &t1->setup.tex_offset[0], sizeof(tex->tex_offset ) ); tex->tex_border_color = t1->setup.tex_border_color; } sarea->vertsize = rmesa->vertex_size; sarea->vc_format = rmesa->vertex_format; /* Turn off the texture cache flushing */ rmesa->setup.tex_cntl_c &= ~R128_TEX_CACHE_FLUSH; sarea->dirty |= rmesa->dirty; rmesa->dirty &= R128_UPLOAD_CLIPRECTS;}static void r128DDPrintState( const char *msg, GLuint flags ){ fprintf( stderr, "%s: (0x%x) %s%s%s%s%s%s%s%s\n", msg, flags, (flags & R128_NEW_CONTEXT) ? "context, " : "", (flags & R128_NEW_ALPHA) ? "alpha, " : "", (flags & R128_NEW_DEPTH) ? "depth, " : "", (flags & R128_NEW_FOG) ? "fog, " : "", (flags & R128_NEW_CLIP) ? "clip, " : "", (flags & R128_NEW_CULL) ? "cull, " : "", (flags & R128_NEW_MASKS) ? "masks, " : "", (flags & R128_NEW_WINDOW) ? "window, " : "" );}void r128DDUpdateHWState( GLcontext *ctx ){ r128ContextPtr rmesa = R128_CONTEXT(ctx); int new_state = rmesa->new_state; if ( new_state || rmesa->NewGLState & _NEW_TEXTURE ) { FLUSH_BATCH( rmesa ); rmesa->new_state = 0; if ( R128_DEBUG & DEBUG_VERBOSE_MSG ) r128DDPrintState( "r128UpdateHwState", new_state ); /* Update the various parts of the context's state. */ if ( new_state & R128_NEW_ALPHA ) r128UpdateAlphaMode( ctx ); if ( new_state & R128_NEW_DEPTH ) r128UpdateZMode( ctx ); if ( new_state & R128_NEW_FOG ) r128UpdateFogAttrib( ctx ); if ( new_state & R128_NEW_CLIP ) r128UpdateClipping( ctx ); if ( new_state & R128_NEW_CULL ) r128UpdateCull( ctx ); if ( new_state & R128_NEW_MASKS ) r128UpdateMasks( ctx ); if ( new_state & R128_NEW_WINDOW ) { r128UpdateWindow( ctx ); r128CalcViewport( ctx ); } if ( rmesa->NewGLState & _NEW_TEXTURE ) { r128UpdateTextureState( ctx ); } }}static void r128DDInvalidateState( GLcontext *ctx, GLuint new_state ){ _swrast_InvalidateState( ctx, new_state ); _swsetup_InvalidateState( ctx, new_state ); _vbo_InvalidateState( ctx, new_state ); _tnl_InvalidateState( ctx, new_state ); R128_CONTEXT(ctx)->NewGLState |= new_state;}/* Initialize the context's hardware state. */void r128DDInitState( r128ContextPtr rmesa ){ int dst_bpp, depth_bpp; switch ( rmesa->r128Screen->cpp ) { case 2: dst_bpp = R128_GMC_DST_16BPP; break; case 4: dst_bpp = R128_GMC_DST_32BPP; break; default: fprintf( stderr, "Error: Unsupported pixel depth... exiting\n" ); exit( -1 ); } rmesa->ClearColor = 0x00000000; switch ( rmesa->glCtx->Visual.depthBits ) { case 16: rmesa->ClearDepth = 0x0000ffff; depth_bpp = R128_Z_PIX_WIDTH_16; rmesa->depth_scale = 1.0 / (GLfloat)0xffff; break; case 24: rmesa->ClearDepth = 0x00ffffff; depth_bpp = R128_Z_PIX_WIDTH_24; rmesa->depth_scale = 1.0 / (GLfloat)0xffffff; break; default: fprintf( stderr, "Error: Unsupported depth %d... exiting\n", rmesa->glCtx->Visual.depthBits ); exit( -1 ); } rmesa->Fallback = 0; /* Hardware state: */ rmesa->setup.dp_gui_master_cntl_c = (R128_GMC_DST_PITCH_OFFSET_CNTL | R128_GMC_DST_CLIPPING | R128_GMC_BRUSH_SOLID_COLOR | dst_bpp | R128_GMC_SRC_DATATYPE_COLOR | R128_GMC_BYTE_MSB_TO_LSB | R128_GMC_CONVERSION_TEMP_6500 | R128_ROP3_S | R128_DP_SRC_SOURCE_MEMORY | R128_GMC_3D_FCN_EN | R128_GMC_CLR_CMP_CNTL_DIS | R128_GMC_AUX_CLIP_DIS | R128_GMC_WR_MSK_DIS); rmesa->setup.sc_top_left_c = 0x00000000; rmesa->setup.sc_bottom_right_c = 0x1fff1fff; rmesa->setup.z_offset_c = rmesa->r128Screen->depthOffset; rmesa->setup.z_pitch_c = ((rmesa->r128Screen->depthPitch >> 3) | R128_Z_TILE); rmesa->setup.z_sten_cntl_c = (depth_bpp | R128_Z_TEST_LESS | R128_STENCIL_TEST_ALWAYS | R128_STENCIL_S_FAIL_KEEP | R128_STENCIL_ZPASS_KEEP | R128_STENCIL_ZFAIL_KEEP); rmesa->setup.tex_cntl_c = (R128_Z_WRITE_ENABLE | R128_SHADE_ENABLE | R128_DITHER_ENABLE | R128_ALPHA_IN_TEX_COMPLETE_A | R128_LIGHT_DIS | R128_ALPHA_LIGHT_DIS | R128_TEX_CACHE_FLUSH | (0x3f << R128_LOD_BIAS_SHIFT)); rmesa->setup.misc_3d_state_cntl_reg = (R128_MISC_SCALE_3D_TEXMAP_SHADE | R128_MISC_SCALE_PIX_REPLICATE | R128_ALPHA_COMB_ADD_CLAMP | R128_FOG_VERTEX | (R128_ALPHA_BLEND_ONE << R128_ALPHA_BLEND_SRC_SHIFT) | (R128_ALPHA_BLEND_ZERO << R128_ALPHA_BLEND_DST_SHIFT) | R128_ALPHA_TEST_ALWAYS); rmesa->setup.texture_clr_cmp_clr_c = 0x00000000; rmesa->setup.texture_clr_cmp_msk_c = 0xffffffff; rmesa->setup.fog_color_c = 0x00000000; rmesa->setup.pm4_vc_fpu_setup = (R128_FRONT_DIR_CCW | R128_BACKFACE_SOLID | R128_FRONTFACE_SOLID | R128_FPU_COLOR_GOURAUD | R128_FPU_SUB_PIX_4BITS | R128_FPU_MODE_3D | R128_TRAP_BITS_DISABLE | R128_XFACTOR_2 | R128_YFACTOR_2 | R128_FLAT_SHADE_VERTEX_OGL | R128_FPU_ROUND_TRUNCATE | R128_WM_SEL_8DW); rmesa->setup.setup_cntl = (R128_COLOR_GOURAUD | R128_PRIM_TYPE_TRI | R128_TEXTURE_ST_MULT_W | R128_STARTING_VERTEX_1 | R128_ENDING_VERTEX_3 | R128_SU_POLY_LINE_NOT_LAST | R128_SUB_PIX_4BITS); rmesa->setup.tex_size_pitch_c = 0x00000000; rmesa->setup.constant_color_c = 0x00ffffff; rmesa->setup.dp_write_mask = 0xffffffff; rmesa->setup.sten_ref_mask_c = 0xffff0000; rmesa->setup.plane_3d_mask_c = 0xffffffff; rmesa->setup.window_xy_offset = 0x00000000; rmesa->setup.scale_3d_cntl = (R128_SCALE_DITHER_TABLE | R128_TEX_CACHE_SIZE_FULL | R128_DITHER_INIT_RESET | R128_SCALE_3D_TEXMAP_SHADE | R128_SCALE_PIX_REPLICATE | R128_ALPHA_COMB_ADD_CLAMP | R128_FOG_VERTEX | (R128_ALPHA_BLEND_ONE << R128_ALPHA_BLEND_SRC_SHIFT) | (R128_ALPHA_BLEND_ZERO << R128_ALPHA_BLEND_DST_SHIFT) | R128_ALPHA_TEST_ALWAYS | R128_COMPOSITE_SHADOW_CMP_EQUAL | R128_TEX_MAP_ALPHA_IN_TEXTURE | R128_TEX_CACHE_LINE_SIZE_4QW); rmesa->new_state = R128_NEW_ALL;}/* Initialize the driver's state functions. */void r128DDInitStateFuncs( GLcontext *ctx ){ ctx->Driver.UpdateState = r128DDInvalidateState; ctx->Driver.ClearIndex = NULL; ctx->Driver.ClearColor = r128DDClearColor; ctx->Driver.ClearStencil = r128DDClearStencil; ctx->Driver.DrawBuffer = r128DDDrawBuffer; ctx->Driver.ReadBuffer = r128DDReadBuffer; ctx->Driver.IndexMask = NULL; ctx->Driver.ColorMask = r128DDColorMask; ctx->Driver.AlphaFunc = r128DDAlphaFunc; ctx->Driver.BlendEquationSeparate = r128DDBlendEquationSeparate; ctx->Driver.BlendFuncSeparate = r128DDBlendFuncSeparate; ctx->Driver.ClearDepth = r128DDClearDepth; ctx->Driver.CullFace = r128DDCullFace; ctx->Driver.FrontFace = r128DDFrontFace; ctx->Driver.DepthFunc = r128DDDepthFunc; ctx->Driver.DepthMask = r128DDDepthMask; ctx->Driver.Enable = r128DDEnable; ctx->Driver.Fogfv = r128DDFogfv; ctx->Driver.Hint = NULL; ctx->Driver.Lightfv = NULL; ctx->Driver.LightModelfv = r128DDLightModelfv; ctx->Driver.LogicOpcode = r128DDLogicOpCode; ctx->Driver.PolygonMode = NULL; ctx->Driver.PolygonStipple = r128DDPolygonStipple; ctx->Driver.RenderMode = r128DDRenderMode; ctx->Driver.Scissor = r128DDScissor; ctx->Driver.ShadeModel = r128DDShadeModel; ctx->Driver.StencilFuncSeparate = r128DDStencilFuncSeparate; ctx->Driver.StencilMaskSeparate = r128DDStencilMaskSeparate; ctx->Driver.StencilOpSeparate = r128DDStencilOpSeparate; ctx->Driver.DepthRange = r128DepthRange; ctx->Driver.Viewport = r128Viewport;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -