⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mgastate.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 3 页
字号:
      /* GL_NONE or GL_FRONT_AND_BACK or stereo left&right, etc */      FALLBACK( ctx, MGA_FALLBACK_DRAW_BUFFER, GL_TRUE );      return;   }   switch ( ctx->DrawBuffer->_ColorDrawBufferIndexes[0] ) {   case BUFFER_FRONT_LEFT:      mmesa->setup.dstorg = mmesa->mgaScreen->frontOffset;      mmesa->draw_buffer = MGA_FRONT;      break;   case BUFFER_BACK_LEFT:      mmesa->setup.dstorg = mmesa->mgaScreen->backOffset;      mmesa->draw_buffer = MGA_BACK;      break;   default:      FALLBACK( ctx, MGA_FALLBACK_DRAW_BUFFER, GL_TRUE );      return;   }   mmesa->dirty |= MGA_UPLOAD_CONTEXT;   mga_set_cliprects(mmesa);   FALLBACK(ctx, MGA_FALLBACK_DRAW_BUFFER, GL_FALSE);}static void mgaDDReadBuffer(GLcontext *ctx, GLenum mode ){   /* nothing, until we implement h/w glRead/CopyPixels or CopyTexImage */}/* ============================================================= * State enable/disable */static void mgaDDEnable(GLcontext *ctx, GLenum cap, GLboolean state){   mgaContextPtr mmesa = MGA_CONTEXT( ctx );   switch(cap) {   case GL_DITHER:      MGA_STATECHANGE( mmesa, MGA_UPLOAD_CONTEXT );      if (!ctx->Color.DitherFlag)	 mmesa->setup.maccess |= MA_nodither_enable;      else	 mmesa->setup.maccess &= ~MA_nodither_enable;      break;   case GL_LIGHTING:   case GL_COLOR_SUM_EXT:      FLUSH_BATCH( mmesa );      updateSpecularLighting( ctx );      break;   case GL_ALPHA_TEST:      MGA_STATECHANGE( mmesa, MGA_UPLOAD_CONTEXT );      mmesa->hw.alpha_func_enable = (state) ? ~0 : 0;      break;   case GL_DEPTH_TEST:      MGA_STATECHANGE( mmesa, MGA_UPLOAD_CONTEXT );      FALLBACK (ctx, MGA_FALLBACK_DEPTH,		ctx->Depth.Func == GL_NEVER && ctx->Depth.Test);      break;   case GL_SCISSOR_TEST:      FLUSH_BATCH( mmesa );      mmesa->scissor = state;      mgaUpdateClipping( ctx );      break;   case GL_FOG:      MGA_STATECHANGE( mmesa, MGA_UPLOAD_CONTEXT );      if (ctx->Fog.Enabled) 	 mmesa->setup.maccess |= MA_fogen_enable;      else	 mmesa->setup.maccess &= ~MA_fogen_enable;      break;   case GL_CULL_FACE:      mgaDDCullFaceFrontFace( ctx, 0 );      break;   case GL_TEXTURE_1D:   case GL_TEXTURE_2D:   case GL_TEXTURE_3D:      break;   case GL_POLYGON_STIPPLE:      if (mmesa->haveHwStipple && mmesa->raster_primitive == GL_TRIANGLES) {	 MGA_STATECHANGE( mmesa, MGA_UPLOAD_CONTEXT );	 mmesa->setup.dwgctl &= ~(0xf<<20);	 if (state)	    mmesa->setup.dwgctl |= mmesa->poly_stipple;      }      break;   case GL_BLEND:   case GL_COLOR_LOGIC_OP:      updateBlendLogicOp( ctx );      break;   case GL_STENCIL_TEST:      MGA_STATECHANGE( mmesa, MGA_UPLOAD_CONTEXT );      if (mmesa->hw_stencil) {	 mmesa->hw.stencil_enable = ( state ) ? ~0 : 0;      }      else {	 FALLBACK( ctx, MGA_FALLBACK_STENCIL, state );      }   default:      break;   }}/* ============================================================= */static void mgaDDPrintDirty( const char *msg, GLuint state ){   fprintf(stderr, "%s (0x%03x): %s%s%s%s%s%s%s\n",	   msg,	   (unsigned int) state,	   (state & MGA_WAIT_AGE)          ? "wait-age " : "",	   (state & MGA_UPLOAD_TEX0IMAGE)  ? "upload-tex0-img " : "",	   (state & MGA_UPLOAD_TEX1IMAGE)  ? "upload-tex1-img " : "",	   (state & MGA_UPLOAD_CONTEXT)    ? "upload-ctx " : "",	   (state & MGA_UPLOAD_TEX0)       ? "upload-tex0 " : "",	   (state & MGA_UPLOAD_TEX1)       ? "upload-tex1 " : "",	   (state & MGA_UPLOAD_PIPE)       ? "upload-pipe " : ""      );}/* Push the state into the sarea and/or texture memory. */void mgaEmitHwStateLocked( mgaContextPtr mmesa ){   drm_mga_sarea_t *sarea = mmesa->sarea;   GLcontext * ctx = mmesa->glCtx;   if (MGA_DEBUG & DEBUG_VERBOSE_MSG)      mgaDDPrintDirty( __FUNCTION__, mmesa->dirty );   if (mmesa->dirty & MGA_UPLOAD_CONTEXT) {      mmesa->setup.wflag = _CULL_DISABLE;      if (mmesa->raster_primitive == GL_TRIANGLES) {	 if ((ctx->Texture.Unit[0]._ReallyEnabled == TEXTURE_2D_BIT &&	      ctx->Texture.Unit[1]._ReallyEnabled == TEXTURE_2D_BIT)) {	    mmesa->setup.wflag = mmesa->hw.cull_dualtex;	 }	 else {	    mmesa->setup.wflag = mmesa->hw.cull;	 }      }      mmesa->setup.stencil = mmesa->hw.stencil 	  & mmesa->hw.stencil_enable;      mmesa->setup.stencilctl = mmesa->hw.stencilctl	  & mmesa->hw.stencil_enable;      /* If depth testing is not enabled, then use the no Z-compare / no       * Z-write mode.  Otherwise, use whatever is set in hw.zmode.       */      mmesa->setup.dwgctl &= (DC_zmode_MASK & DC_atype_MASK);      mmesa->setup.dwgctl |= (ctx->Depth.Test)	  ? mmesa->hw.zmode : (DC_zmode_nozcmp | DC_atype_i);      mmesa->setup.dwgctl &= DC_bop_MASK;      mmesa->setup.dwgctl |= RGBA_LOGICOP_ENABLED(ctx)	  ? mmesa->hw.rop : mgarop_NoBLK[ GL_COPY & 0x0f ];      mmesa->setup.alphactrl &= AC_src_MASK & AC_dst_MASK & AC_atmode_MASK	 & AC_atref_MASK & AC_alphasel_MASK;      mmesa->setup.alphactrl |= 	 (mmesa->hw.alpha_func & mmesa->hw.alpha_func_enable) |	 (mmesa->hw.blend_func & mmesa->hw.blend_func_enable) |	 ((AC_src_one | AC_dst_zero) & ~mmesa->hw.blend_func_enable) |	 mmesa->hw.alpha_sel;      memcpy( &sarea->context_state, &mmesa->setup, sizeof(mmesa->setup));   }   if ((mmesa->dirty & MGA_UPLOAD_TEX0) && mmesa->CurrentTexObj[0]) {      memcpy(&sarea->tex_state[0],	     &mmesa->CurrentTexObj[0]->setup,	     sizeof(sarea->tex_state[0]));   }   if ((mmesa->dirty & MGA_UPLOAD_TEX1) && mmesa->CurrentTexObj[1]) {      memcpy(&sarea->tex_state[1],	     &mmesa->CurrentTexObj[1]->setup,	     sizeof(sarea->tex_state[1]));   }   if (mmesa->dirty & (MGA_UPLOAD_TEX0 | MGA_UPLOAD_TEX1)) {      sarea->tex_state[0].texctl2 &= ~TMC_specen_enable;      sarea->tex_state[1].texctl2 &= ~TMC_specen_enable;      sarea->tex_state[0].texctl2 |= mmesa->hw.specen;      sarea->tex_state[1].texctl2 |= mmesa->hw.specen;   }   if (mmesa->dirty & MGA_UPLOAD_PIPE) {/*        mmesa->sarea->wacceptseq = mmesa->hw_primitive; */      mmesa->sarea->warp_pipe = mmesa->vertex_format;      mmesa->sarea->vertsize = mmesa->vertex_size;   }   mmesa->sarea->dirty |= mmesa->dirty;   mmesa->dirty &= MGA_UPLOAD_CLIPRECTS;}/* ============================================================= */static void mgaDDValidateState( GLcontext *ctx ){   mgaContextPtr mmesa = MGA_CONTEXT( ctx );   FLUSH_BATCH( mmesa );   if (mmesa->NewGLState & _NEW_TEXTURE) {      mgaUpdateTextureState(ctx);   }   if (!mmesa->Fallback) {      if (mmesa->NewGLState & _MGA_NEW_RASTERSETUP) {         mgaChooseVertexState( ctx );      }      if (mmesa->NewGLState & _MGA_NEW_RENDERSTATE) {         mgaChooseRenderState( ctx );      }   }   mmesa->NewGLState = 0;}static void mgaDDInvalidateState( 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 );   MGA_CONTEXT(ctx)->NewGLState |= new_state;}static void mgaRunPipeline( GLcontext *ctx ){   mgaContextPtr mmesa = MGA_CONTEXT(ctx);   if (mmesa->NewGLState) {      mgaDDValidateState( ctx );   }   if (mmesa->dirty) {       mgaEmitHwStateLocked( mmesa );   }   _tnl_run_pipeline( ctx );}void mgaInitState( mgaContextPtr mmesa ){   mgaScreenPrivate *mgaScreen = mmesa->mgaScreen;   GLcontext *ctx = mmesa->glCtx;   if (ctx->Visual.doubleBufferMode) {      /* use back buffer by default */      mmesa->draw_buffer = MGA_BACK;      mmesa->drawOffset = mmesa->mgaScreen->backOffset;      mmesa->readOffset = mmesa->mgaScreen->backOffset;      mmesa->setup.dstorg = mgaScreen->backOffset;   } else {      /* use front buffer by default */      mmesa->draw_buffer = MGA_FRONT;      mmesa->drawOffset = mmesa->mgaScreen->frontOffset;      mmesa->readOffset = mmesa->mgaScreen->frontOffset;      mmesa->setup.dstorg = mgaScreen->frontOffset;   }   mmesa->setup.maccess = (MA_memreset_disable |			   MA_fogen_disable |			   MA_tlutload_disable |			   MA_nodither_disable |			   MA_dit555_disable);   if (driQueryOptioni (&mmesa->optionCache, "color_reduction") !=       DRI_CONF_COLOR_REDUCTION_DITHER)      mmesa->setup.maccess |= MA_nodither_enable;   switch (mmesa->mgaScreen->cpp) {   case 2:      mmesa->setup.maccess |= MA_pwidth_16;      break;   case 4:      mmesa->setup.maccess |= MA_pwidth_32;      break;   default:      fprintf( stderr, "Error: unknown cpp %d, exiting...\n",	       mmesa->mgaScreen->cpp );      exit( 1 );   }   switch (mmesa->glCtx->Visual.depthBits) {   case 16:      mmesa->setup.maccess |= MA_zwidth_16;      break;   case 24:      mmesa->setup.maccess |= MA_zwidth_24;      break;   case 32:      mmesa->setup.maccess |= MA_zwidth_32;      break;   }   mmesa->hw.blend_func = AC_src_one | AC_dst_zero;   mmesa->hw.blend_func_enable = 0;   mmesa->hw.alpha_func = AC_atmode_noacmp | MGA_FIELD( AC_atref, 0x00 );   mmesa->hw.alpha_func_enable = 0;   mmesa->hw.rop = mgarop_NoBLK[ GL_COPY & 0x0f ];   mmesa->hw.zmode = DC_zmode_zlt | DC_atype_zi;   mmesa->hw.stencil = MGA_FIELD( S_sref, 0x00) | MGA_FIELD( S_smsk, 0xff ) |      MGA_FIELD( S_swtmsk, 0xff );   mmesa->hw.stencilctl = SC_smode_salways | SC_sfailop_keep       | SC_szfailop_keep | SC_szpassop_keep;   mmesa->hw.stencil_enable = 0;   mmesa->hw.cull = _CULL_DISABLE;   mmesa->hw.cull_dualtex = _CULL_DISABLE;   mmesa->hw.specen = 0;   mmesa->hw.alpha_sel = AC_alphasel_diffused;   mmesa->setup.dwgctl = (DC_opcod_trap |			  DC_linear_xy |			  DC_solid_disable |			  DC_arzero_disable |			  DC_sgnzero_disable |			  DC_shftzero_enable |			  MGA_FIELD( DC_bop, 0xC ) |			  MGA_FIELD( DC_trans, 0x0 ) |			  DC_bltmod_bmonolef |			  DC_pattern_disable |			  DC_transc_disable |			  DC_clipdis_disable);   mmesa->setup.plnwt = ~0;   mmesa->setup.alphactrl = (AC_amode_alpha_channel |			     AC_astipple_disable |			     AC_aten_disable);   mmesa->setup.fogcolor = PACK_COLOR_888((GLubyte)(ctx->Fog.Color[0]*255.0F),					  (GLubyte)(ctx->Fog.Color[1]*255.0F),					  (GLubyte)(ctx->Fog.Color[2]*255.0F));   mmesa->setup.wflag = 0;   mmesa->setup.tdualstage0 = 0;   mmesa->setup.tdualstage1 = 0;   mmesa->setup.fcol = 0;   mmesa->dirty |= MGA_UPLOAD_CONTEXT;   mmesa->envcolor[0] = 0;   mmesa->envcolor[1] = 0;}void mgaDDInitStateFuncs( GLcontext *ctx ){   ctx->Driver.UpdateState = mgaDDInvalidateState;   ctx->Driver.Enable = mgaDDEnable;   ctx->Driver.LightModelfv = mgaDDLightModelfv;   ctx->Driver.AlphaFunc = mgaDDAlphaFunc;   ctx->Driver.BlendEquationSeparate = mgaDDBlendEquationSeparate;   ctx->Driver.BlendFuncSeparate = mgaDDBlendFuncSeparate;   ctx->Driver.DepthFunc = mgaDDDepthFunc;   ctx->Driver.DepthMask = mgaDDDepthMask;   ctx->Driver.Fogfv = mgaDDFogfv;   ctx->Driver.Scissor = mgaDDScissor;   ctx->Driver.CullFace = mgaDDCullFaceFrontFace;   ctx->Driver.FrontFace = mgaDDCullFaceFrontFace;   ctx->Driver.ColorMask = mgaDDColorMask;   ctx->Driver.DrawBuffer = mgaDDDrawBuffer;   ctx->Driver.ReadBuffer = mgaDDReadBuffer;   ctx->Driver.ClearColor = mgaDDClearColor;   ctx->Driver.ClearDepth = mgaDDClearDepth;   ctx->Driver.LogicOpcode = mgaDDLogicOp;   ctx->Driver.PolygonStipple = mgaDDPolygonStipple;   ctx->Driver.StencilFuncSeparate = mgaDDStencilFuncSeparate;   ctx->Driver.StencilMaskSeparate = mgaDDStencilMaskSeparate;   ctx->Driver.StencilOpSeparate = mgaDDStencilOpSeparate;   ctx->Driver.DepthRange = mgaDepthRange;   ctx->Driver.Viewport = mgaViewport;   ctx->Driver.RenderMode = mgaRenderMode;   ctx->Driver.ClearIndex = 0;   ctx->Driver.IndexMask = 0;   TNL_CONTEXT(ctx)->Driver.RunPipeline = mgaRunPipeline;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -