📄 s3v_state.c
字号:
/* * Author: Max Lingua <sunmax@libero.it> */#include <X11/Xlibint.h>#include "s3v_context.h"#include "s3v_macros.h"#include "macros.h"#include "s3v_dri.h"#include "colormac.h"#include "swrast/swrast.h"#include "swrast_setup/swrast_setup.h"#include "vbo/vbo.h"#include "tnl/tnl.h"/* #define DEBUG(str) printf str */#define ENABLELIGHTING 0/* ============================================================= * Alpha blending */static void s3vUpdateAlphaMode( GLcontext *ctx ){ s3vContextPtr vmesa = S3V_CONTEXT(ctx); CARD32 cmd = vmesa->CMD; cmd &= ~ALPHA_BLEND_MASK; if ( ctx->Color.BlendEnabled ) { DEBUG(("ctx->Color.AlphaEnabled = 1")); vmesa->_alpha[0] = ALPHA_SRC; vmesa->_alpha[1] = vmesa->_alpha_tex; /* FIXME: not all tex modes support alpha */ } else { DEBUG(("ctx->Color.AlphaEnabled = 0")); vmesa->_alpha[0] = vmesa->_alpha[1] = ALPHA_OFF; }#if 1 if ((cmd & DO_MASK) & DO_3D_LINE) { /* we are drawing 3d lines */ /* which don't support tex */ cmd |= vmesa->_alpha[0]; } else { cmd |= vmesa->_alpha[vmesa->_3d_mode]; } vmesa->CMD = cmd; /* FIXME: enough? */#else vmesa->restore_primitive = -1;#endif }static void s3vDDAlphaFunc( GLcontext *ctx, GLenum func, GLfloat ref ){ s3vContextPtr vmesa = S3V_CONTEXT(ctx); DEBUG(("s3vDDAlphaFunc\n")); vmesa->new_state |= S3V_NEW_ALPHA;}static void s3vDDBlendFunc( GLcontext *ctx, GLenum sfactor, GLenum dfactor ){ s3vContextPtr vmesa = S3V_CONTEXT(ctx); DEBUG(("s3vDDBlendFunc\n")); vmesa->new_state |= S3V_NEW_ALPHA;}/* ================================================================ * Buffer clear */static void s3vDDClear( GLcontext *ctx, GLbitfield mask ){ s3vContextPtr vmesa = S3V_CONTEXT(ctx); unsigned int _stride; GLint cx = ctx->DrawBuffer->_Xmin; GLint cy = ctx->DrawBuffer->_Ymin; GLint cw = ctx->DrawBuffer->_Xmax - cx; GLint ch = ctx->DrawBuffer->_Ymax - cy; /* XXX FIX ME: the cx,cy,cw,ch vars are currently ignored! */ vmesa->restore_primitive = -1; /* Update and emit any new state. We need to do this here to catch * changes to the masks. * FIXME: Just update the masks? */ if ( vmesa->new_state ) s3vDDUpdateHWState( ctx );/* s3vUpdateMasks( ctx ); *//* s3vUpdateClipping( ctx ); *//* s3vEmitHwState( vmesa ); */ #if 1 /* soft (0)/hw (1)*/ DEBUG(("*** s3vDDClear ***\n")); DMAOUT_CHECK(BITBLT_SRC_BASE, 15); DMAOUT(vmesa->SrcBase); DMAOUT(vmesa->DestBlit); DMAOUT( vmesa->ScissorLR ); DMAOUT( vmesa->ScissorTB ); DMAOUT( (vmesa->SrcStride << 16) | vmesa->SrcStride ); /* FIXME: unify */ DMAOUT( (~(0)) ); /* masks */ DMAOUT( (~(0)) ); DMAOUT(0); DMAOUT(vmesa->ClearColor); DMAOUT(0); DMAOUT(0); /* FIXME */ DMAOUT(0x16000122 | 0x5 | (0xF0 << 17)); /* black magic to me */ DMAOUT(vmesa->ScissorWH); DMAOUT(vmesa->SrcXY); DMAOUT(vmesa->DestXY); DMAFINISH(); if (mask & BUFFER_BIT_DEPTH) { /* depth */ DEBUG(("BUFFER_BIT_DEPTH\n")); _stride = ((cw+31)&~31) * 2; /* XXX cw or Buffer->Width??? */ DMAOUT_CHECK(BITBLT_SRC_BASE, 15); DMAOUT(0); DMAOUT(vmesa->s3vScreen->depthOffset); DMAOUT( (0 << 16) | cw ); DMAOUT( (0 << 16) | ch ); DMAOUT( (vmesa->SrcStride << 16) | vmesa->DestStride ); DMAOUT( (~(0)) ); /* masks */ DMAOUT( (~(0)) ); DMAOUT(0); DMAOUT(vmesa->ClearDepth); /* 0x7FFF */ /* FIXME */ DMAOUT(0); DMAOUT(0); DMAOUT(0x16000122 | 0x5 | (0xF0 << 17)); DMAOUT( ((cw-1) << 16) | (ch-1) ); DMAOUT(0); DMAOUT( (0 << 16) | 0 ); DMAFINISH(); DEBUG(("vmesa->ClearDepth = 0x%x\n", vmesa->ClearDepth)); mask &= ~BUFFER_BIT_DEPTH; } if (!vmesa->NotClipped) { DEBUG(("vmesa->NotClipped\n")); /* yes */ } if (!(vmesa->EnabledFlags & S3V_BACK_BUFFER)) { DEBUG(("!S3V_BACK_BUFFER -> flush\n")); DMAFLUSH(); }/* if ( mask ) DEBUG(("still masked ;3(\n")); */ /* yes */#else _swrast_Clear( ctx, mask );#endif}/* ============================================================= * Depth testing */static void s3vUpdateZMode( GLcontext *ctx ){ s3vContextPtr vmesa = S3V_CONTEXT(ctx); CARD32 cmd = vmesa->CMD; DEBUG(("Depth.Test = %i\n", ctx->Depth.Test)); DEBUG(("CMD was = 0x%x ", cmd));/* printf("depth --- CMD was = 0x%x \n", cmd); */ cmd &= ~Z_MASK; /* 0xfc0fffff; */ /* Z_BUFFER */ /* 000 mode */ /* Z_UPDATE_OFF */ if (!ctx->Depth.Test) cmd |= Z_OFF; if ( ctx->Depth.Mask ) cmd |= Z_UPDATE_ON; switch ( ctx->Depth.Func ) { case GL_NEVER: cmd |= Z_NEVER; break; case GL_ALWAYS: cmd |= Z_ALWAYS; break; case GL_LESS: cmd |= Z_LESS; break; case GL_LEQUAL: cmd |= Z_LEQUAL; break; case GL_EQUAL: cmd |= Z_EQUAL; break; case GL_GEQUAL: cmd |= Z_GEQUAL; break; case GL_GREATER: cmd |= Z_GREATER; break; case GL_NOTEQUAL: cmd |= Z_NOTEQUAL; break; } DEBUG(("CMD is 0x%x\n", cmd)); vmesa->dirty |= S3V_UPLOAD_DEPTH; vmesa->CMD = cmd;}static void s3vDDDepthFunc( GLcontext *ctx, GLenum func ){ s3vContextPtr vmesa = S3V_CONTEXT(ctx);/* FLUSH_BATCH( vmesa ); */ DEBUG(("s3vDDDepthFunc\n")); vmesa->new_state |= S3V_NEW_DEPTH;}static void s3vDDDepthMask( GLcontext *ctx, GLboolean flag ){ s3vContextPtr vmesa = S3V_CONTEXT(ctx); /* FLUSH_BATCH( vmesa ); */ DEBUG(("s3vDDDepthMask\n")); vmesa->new_state |= S3V_NEW_DEPTH;}static void s3vDDClearDepth( GLcontext *ctx, GLclampd d ){ s3vContextPtr vmesa = S3V_CONTEXT(ctx); switch ( vmesa->DepthSize ) { case 15: case 16: vmesa->ClearDepth = d * 0x0000ffff; /* 65536 */ DEBUG(("GLclampd d = %f\n", d)); DEBUG(("ctx->Depth.Clear = %f\n", ctx->Depth.Clear)); DEBUG(("(They should be the same)\n")); break; case 24: vmesa->ClearDepth = d * 0x00ffffff; break; case 32: vmesa->ClearDepth = d * 0xffffffff; break; }}static void s3vDDFinish( GLcontext *ctx ){ s3vContextPtr vmesa = S3V_CONTEXT(ctx); DMAFLUSH(); }static void s3vDDFlush( GLcontext *ctx ){ s3vContextPtr vmesa = S3V_CONTEXT(ctx); DMAFLUSH();}/* ============================================================= * Fog */static void s3vUpdateFogAttrib( GLcontext *ctx ){/* s3vContextPtr vmesa = S3V_CONTEXT(ctx); */ if (ctx->Fog.Enabled) { } else { } switch (ctx->Fog.Mode) { case GL_LINEAR: break; case GL_EXP: break; case GL_EXP2: break; }}static void s3vDDFogfv( GLcontext *ctx, GLenum pname, const GLfloat *param ){ s3vContextPtr vmesa = S3V_CONTEXT(ctx); vmesa->new_state |= S3V_NEW_FOG;}/* ============================================================= * Lines */static void s3vDDLineWidth( GLcontext *ctx, GLfloat width ){ /* FIXME: on virge you only have one size of 3d lines * * if we wanted more, we should start using tris instead * * but virge has problem with some tris when all of the * * vertices stay on a line */}/* ============================================================= * Points */static void s3vDDPointSize( GLcontext *ctx, GLfloat size ){ /* FIXME: we use 3d line to fake points. So same limitations * as above apply */}/* ============================================================= * Polygon */static void s3vUpdatePolygon( GLcontext *ctx ){ /* FIXME: I don't think we could do much here */ s3vContextPtr vmesa = S3V_CONTEXT(ctx); vmesa->dirty |= S3V_UPLOAD_POLYGON;}/* ============================================================= * Clipping */static void s3vUpdateClipping( GLcontext *ctx ){ s3vContextPtr vmesa = S3V_CONTEXT(ctx); __DRIdrawablePrivate *dPriv = vmesa->driDrawable; int x0,y0,x1,y1; DEBUG((">>> s3vUpdateClipping <<<\n"));/* if ( vmesa->driDrawable ) { DEBUG(("s3vUpdateClipping\n"));*/ if (vmesa->EnabledFlags & S3V_BACK_BUFFER) { DEBUG(("S3V_BACK_BUFFER\n")); x0 = 0; y0 = 0; x1 = dPriv->w - 1; y1 = dPriv->h - 1; vmesa->SrcBase = 0; vmesa->DestBase = vmesa->s3vScreen->backOffset; vmesa->DestBlit = vmesa->DestBase; vmesa->ScissorLR = ( (0 << 16) | (dPriv->w-1) ); vmesa->ScissorTB = ( (0 << 16) | (dPriv->h-1) );/* vmesa->ScissorLR = ( (x0 << 16) | x1 ); vmesa->ScissorTB = ( (y0 << 16) | y1 );*/ vmesa->SrcStride = ( ((dPriv->w+31)&~31) * vmesa->s3vScreen->cpp ); vmesa->DestStride = vmesa->driScreen->fbWidth*vmesa->s3vScreen->cpp; vmesa->ScissorWH = ( (dPriv->w << 16) | dPriv->h ); vmesa->SrcXY = 0;/* vmesa->DestXY = ( (dPriv->x << 16) | dPriv->y ); */ vmesa->DestXY = ( (0 << 16) | 0 ); } else { DEBUG(("S3V_FRONT_BUFFER\n")); x0 = dPriv->x; y0 = dPriv->y; x1 = x0 + dPriv->w - 1; y1 = y0 + dPriv->h - 1; vmesa->SrcBase = 0; vmesa->DestBase = 0; vmesa->ScissorLR = ( (x0 << 16) | x1 ); vmesa->ScissorTB = ( (y0 << 16) | y1 ); vmesa->DestStride = vmesa->driScreen->fbWidth*vmesa->s3vScreen->cpp; vmesa->SrcStride = vmesa->DestStride; vmesa->DestBase = (y0 * vmesa->DestStride) + x0*vmesa->s3vScreen->cpp; vmesa->DestBlit = 0; vmesa->ScissorWH = ( (x1 << 16) | y1 ); vmesa->SrcXY = 0; vmesa->DestXY = ( (0 << 16) | 0 );/* vmesa->DestXY = ( (dPriv->x << 16) | dPriv->y ); */ } DEBUG(("x0=%i y0=%i x1=%i y1=%i\n", x0, y0, x1, y1)); DEBUG(("stride=%i rectWH=0x%x\n\n", vmesa->DestStride, vmesa->ScissorWH)); /* FIXME: how could we use the following info? */ /* if (ctx->Scissor.Enabled) {} */ vmesa->dirty |= S3V_UPLOAD_CLIP; /* } */}static void s3vDDScissor( GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h ){ s3vContextPtr vmesa = S3V_CONTEXT(ctx); DEBUG((">>> s3vDDScissor <<<")); /* FLUSH_BATCH( vmesa ); */ vmesa->new_state |= S3V_NEW_CLIP;}/* ============================================================= * Culling */static void s3vUpdateCull( GLcontext *ctx ){ s3vContextPtr vmesa = S3V_CONTEXT(ctx); GLfloat backface_sign = 1; DEBUG(("s3vUpdateCull\n")); /* FIXME: GL_FRONT_AND_BACK */ switch ( ctx->Polygon.CullFaceMode ) { case GL_BACK: if (ctx->Polygon.FrontFace == GL_CCW) backface_sign = -1; break; case GL_FRONT: if (ctx->Polygon.FrontFace != GL_CCW) backface_sign = -1; break; default: break; } vmesa->backface_sign = backface_sign;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -