fix GL_LINE_LOOP with drivers using own render pipeline stage (#12410, #13527)
[mesa.git] / src / mesa / drivers / dri / mga / mgastate.c
index 72d5c9fb0829675e0d689f13815e380f87151e03..88f2175cc3e45ef3ad3008991513b3756814fdfb 100644 (file)
  * Authors:
  *    Keith Whitwell <keith@tungstengraphics.com>
  */
-/* $XFree86: xc/lib/GL/mesa/src/drv/mga/mgastate.c,v 1.13 2002/10/30 12:51:36 alanh Exp $ */
 
 
 #include "mtypes.h"
-#include "buffers.h"
 #include "colormac.h"
 #include "dd.h"
 
 #include "mgaregs.h"
 
 #include "swrast/swrast.h"
-#include "array_cache/acache.h"
+#include "vbo/vbo.h"
 #include "tnl/tnl.h"
 #include "tnl/t_context.h"
 #include "tnl/t_pipeline.h"
 #include "swrast_setup/swrast_setup.h"
 
 #include "xmlpool.h"
+#include "drirenderbuffer.h"
+
 
 static void updateSpecularLighting( GLcontext *ctx );
 
@@ -114,14 +114,15 @@ static void mgaDDAlphaFunc(GLcontext *ctx, GLenum func, GLfloat ref)
 static void updateBlendLogicOp(GLcontext *ctx)
 {
    mgaContextPtr mmesa = MGA_CONTEXT(ctx);
+   GLboolean logicOp = RGBA_LOGICOP_ENABLED(ctx);
 
    MGA_STATECHANGE( mmesa, MGA_UPLOAD_CONTEXT );
 
    mmesa->hw.blend_func_enable =
-      (ctx->Color.BlendEnabled && !ctx->Color._LogicOpEnabled) ? ~0 : 0;
+      (ctx->Color.BlendEnabled && !logicOp) ? ~0 : 0;
 
    FALLBACK( ctx, MGA_FALLBACK_BLEND,
-             ctx->Color.BlendEnabled && !ctx->Color._LogicOpEnabled &&
+             ctx->Color.BlendEnabled && !logicOp &&
              mmesa->hw.blend_func == (AC_src_src_alpha_sat | AC_dst_zero) );
 }
 
@@ -196,7 +197,7 @@ static void mgaDDBlendFuncSeparate( GLcontext *ctx, GLenum sfactorRGB,
    mmesa->hw.blend_func = (src | dst);
 
    FALLBACK( ctx, MGA_FALLBACK_BLEND,
-             ctx->Color.BlendEnabled && !ctx->Color._LogicOpEnabled &&
+             ctx->Color.BlendEnabled && !RGBA_LOGICOP_ENABLED(ctx) &&
              mmesa->hw.blend_func == (AC_src_src_alpha_sat | AC_dst_zero) );
 }
 
@@ -513,8 +514,9 @@ static void mgaDDLightModelfv(GLcontext *ctx, GLenum pname,
  */
 
 
-static void mgaDDStencilFunc(GLcontext *ctx, GLenum func, GLint ref,
-                            GLuint mask)
+static void
+mgaDDStencilFuncSeparate(GLcontext *ctx, GLenum face, GLenum func, GLint ref,
+                         GLuint mask)
 {
    mgaContextPtr mmesa = MGA_CONTEXT(ctx);
    GLuint  stencil;
@@ -557,7 +559,8 @@ static void mgaDDStencilFunc(GLcontext *ctx, GLenum func, GLint ref,
    mmesa->hw.stencilctl |= stencilctl;
 }
 
-static void mgaDDStencilMask(GLcontext *ctx, GLuint mask)
+static void
+mgaDDStencilMaskSeparate(GLcontext *ctx, GLenum face, GLuint mask)
 {
    mgaContextPtr mmesa = MGA_CONTEXT(ctx);
 
@@ -566,8 +569,9 @@ static void mgaDDStencilMask(GLcontext *ctx, GLuint mask)
    mmesa->hw.stencil |= MGA_FIELD( S_swtmsk, mask );
 }
 
-static void mgaDDStencilOp(GLcontext *ctx, GLenum fail, GLenum zfail,
-                          GLenum zpass)
+static void
+mgaDDStencilOpSeparate(GLcontext *ctx, GLenum face, GLenum fail, GLenum zfail,
+                       GLenum zpass)
 {
    mgaContextPtr mmesa = MGA_CONTEXT(ctx);
    GLuint  stencilctl;
@@ -696,8 +700,6 @@ static void mgaViewport( GLcontext *ctx,
                          GLint x, GLint y, 
                          GLsizei width, GLsizei height )
 {
-   /* update size of Mesa/software ancillary buffers */
-   _mesa_ResizeBuffersMESA();
    mgaCalcViewport( ctx );
 }
 
@@ -744,32 +746,12 @@ static void mgaDDLogicOp( GLcontext *ctx, GLenum opcode )
 }
 
 
-static void mgaXMesaSetFrontClipRects( mgaContextPtr mmesa )
-{
-   __DRIdrawablePrivate *driDrawable = mmesa->driDrawable;
-
-   if (driDrawable->numClipRects == 0) {
-       static drm_clip_rect_t zeroareacliprect = {0,0,0,0};
-       mmesa->numClipRects = 1;
-       mmesa->pClipRects = &zeroareacliprect;
-   } else {
-       mmesa->numClipRects = driDrawable->numClipRects;
-       mmesa->pClipRects = driDrawable->pClipRects;
-   }
-   mmesa->drawX = driDrawable->x;
-   mmesa->drawY = driDrawable->y;
-
-   mmesa->setup.dstorg = mmesa->drawOffset;
-   mmesa->dirty |= MGA_UPLOAD_CONTEXT | MGA_UPLOAD_CLIPRECTS;
-}
-
-
-static void mgaXMesaSetBackClipRects( mgaContextPtr mmesa )
+static void mga_set_cliprects(mgaContextPtr mmesa)
 {
    __DRIdrawablePrivate *driDrawable = mmesa->driDrawable;
 
-   if (driDrawable->numBackClipRects == 0)
-   {
+   if ((mmesa->draw_buffer != MGA_FRONT)
+       || (driDrawable->numBackClipRects == 0)) {
       if (driDrawable->numClipRects == 0) {
          static drm_clip_rect_t zeroareacliprect = {0,0,0,0};
          mmesa->numClipRects = 1;
@@ -794,25 +776,20 @@ static void mgaXMesaSetBackClipRects( mgaContextPtr mmesa )
 
 void mgaUpdateRects( mgaContextPtr mmesa, GLuint buffers )
 {
-   __DRIdrawablePrivate *driDrawable = mmesa->driDrawable;
-   drm_mga_sarea_t *sarea = mmesa->sarea;
+   __DRIdrawablePrivate *const driDrawable = mmesa->driDrawable;
+   __DRIdrawablePrivate *const driReadable = mmesa->driReadable;
 
-
-   DRI_VALIDATE_DRAWABLE_INFO(mmesa->driScreen, driDrawable); 
    mmesa->dirty_cliprects = 0; 
 
-   if (mmesa->draw_buffer == MGA_FRONT)
-      mgaXMesaSetFrontClipRects( mmesa );
-   else
-      mgaXMesaSetBackClipRects( mmesa );
+   driUpdateFramebufferSize(mmesa->glCtx, driDrawable);
+   if (driDrawable != driReadable) {
+      driUpdateFramebufferSize(mmesa->glCtx, driReadable);
+   }
 
-   sarea->req_drawable = driDrawable->draw;
-   sarea->req_draw_buffer = mmesa->draw_buffer;
+   mga_set_cliprects(mmesa);
 
    mgaUpdateClipping( mmesa->glCtx );
    mgaCalcViewport( mmesa->glCtx );
-
-   mmesa->dirty |= MGA_UPLOAD_CLIPRECTS;
 }
 
 
@@ -828,17 +805,11 @@ static void mgaDDDrawBuffer(GLcontext *ctx, GLenum mode )
    switch ( ctx->DrawBuffer->_ColorDrawBufferMask[0] ) {
    case BUFFER_BIT_FRONT_LEFT:
       mmesa->setup.dstorg = mmesa->mgaScreen->frontOffset;
-      mmesa->dirty |= MGA_UPLOAD_CONTEXT;
       mmesa->draw_buffer = MGA_FRONT;
-      mgaXMesaSetFrontClipRects( mmesa );
-      FALLBACK( ctx, MGA_FALLBACK_DRAW_BUFFER, GL_FALSE );
       break;
    case BUFFER_BIT_BACK_LEFT:
       mmesa->setup.dstorg = mmesa->mgaScreen->backOffset;
       mmesa->draw_buffer = MGA_BACK;
-      mmesa->dirty |= MGA_UPLOAD_CONTEXT;
-      mgaXMesaSetBackClipRects( mmesa );
-      FALLBACK( ctx, MGA_FALLBACK_DRAW_BUFFER, GL_FALSE );
       break;
    default:
       /* GL_NONE or GL_FRONT_AND_BACK or stereo left&right, etc */
@@ -846,10 +817,9 @@ static void mgaDDDrawBuffer(GLcontext *ctx, GLenum mode )
       return;
    }
 
-   /* We want to update the s/w rast state too so that r200SetBuffer()
-    * gets called.
-    */
-   _swrast_DrawBuffer(ctx, mode);
+   mmesa->dirty |= MGA_UPLOAD_CONTEXT;
+   mga_set_cliprects(mmesa);
+   FALLBACK(ctx, MGA_FALLBACK_DRAW_BUFFER, GL_FALSE);
 }
 
 
@@ -992,7 +962,7 @@ void mgaEmitHwStateLocked( mgaContextPtr mmesa )
          ? mmesa->hw.zmode : (DC_zmode_nozcmp | DC_atype_i);
 
       mmesa->setup.dwgctl &= DC_bop_MASK;
-      mmesa->setup.dwgctl |= (ctx->Color._LogicOpEnabled)
+      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
@@ -1067,7 +1037,7 @@ static void mgaDDInvalidateState( GLcontext *ctx, GLuint new_state )
 {
    _swrast_InvalidateState( ctx, new_state );
    _swsetup_InvalidateState( ctx, new_state );
-   _ac_InvalidateState( ctx, new_state );
+   _vbo_InvalidateState( ctx, new_state );
    _tnl_InvalidateState( ctx, new_state );
    MGA_CONTEXT(ctx)->NewGLState |= new_state;
 }
@@ -1215,9 +1185,9 @@ void mgaDDInitStateFuncs( GLcontext *ctx )
 
    ctx->Driver.PolygonStipple = mgaDDPolygonStipple;
 
-   ctx->Driver.StencilFunc = mgaDDStencilFunc;
-   ctx->Driver.StencilMask = mgaDDStencilMask;
-   ctx->Driver.StencilOp = mgaDDStencilOp;
+   ctx->Driver.StencilFuncSeparate = mgaDDStencilFuncSeparate;
+   ctx->Driver.StencilMaskSeparate = mgaDDStencilMaskSeparate;
+   ctx->Driver.StencilOpSeparate = mgaDDStencilOpSeparate;
 
    ctx->Driver.DepthRange = mgaDepthRange;
    ctx->Driver.Viewport = mgaViewport;
@@ -1226,12 +1196,5 @@ void mgaDDInitStateFuncs( GLcontext *ctx )
    ctx->Driver.ClearIndex = 0;
    ctx->Driver.IndexMask = 0;
 
-   /* Swrast hooks for imaging extensions:
-    */
-   ctx->Driver.CopyColorTable = _swrast_CopyColorTable;
-   ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable;
-   ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
-   ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
-
    TNL_CONTEXT(ctx)->Driver.RunPipeline = mgaRunPipeline;
 }