summaryrefslogtreecommitdiff
path: root/src/mesa/drivers/dri/i915/intel_state.c
blob: 23e49553abdff48700e6fdc4bc01a09c20013700 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**************************************************************************
 * 
 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
 * All Rights Reserved.
 * 
 **************************************************************************/


#include "glheader.h"
#include "context.h"
#include "macros.h"
#include "enums.h"
#include "dd.h"

#include "intel_screen.h"
#include "intel_context.h"
#include "swrast/swrast.h"


static void intelDrawBuffer(GLcontext *ctx, GLenum mode )
{
   intelContextPtr intel = INTEL_CONTEXT(ctx);
   intelScreenPrivate *screen = intel->intelScreen;
   int front = 0;
 
   switch ( ctx->Color._DrawDestMask ) {
   case DD_FRONT_LEFT_BIT:
      front = 1;
      FALLBACK( intel, INTEL_FALLBACK_DRAW_BUFFER, GL_FALSE );
      break;
   case DD_BACK_LEFT_BIT:
      front = 0;
      FALLBACK( intel, INTEL_FALLBACK_DRAW_BUFFER, GL_FALSE );
      break;
   default:
      FALLBACK( intel, INTEL_FALLBACK_DRAW_BUFFER, GL_TRUE );
      return;
   }

   /* We want to update the s/w rast state too so that r200SetBuffer()
    * gets called.
    */
   _swrast_DrawBuffer(ctx, mode);

   if ( intel->sarea->pf_current_page == 1 ) 
      front ^= 1;
   
   intelSetFrontClipRects( intel );

   if (front) {
      intel->drawOffset = screen->frontOffset;
      intel->drawMap = (char *)intel->driScreen->pFB;
      intel->readMap = (char *)intel->driScreen->pFB;
   } else {
      intel->drawOffset = screen->backOffset;
      intel->drawMap = screen->back.map;
      intel->readMap = screen->back.map;
   }

   intel->vtbl.set_draw_offset( intel, intel->drawOffset );
}

static void intelReadBuffer( GLcontext *ctx, GLenum mode )
{
   /* nothing, until we implement h/w glRead/CopyPixels or CopyTexImage */
}


static void intelClearColor(GLcontext *ctx, const GLfloat color[4])
{
   intelContextPtr intel = INTEL_CONTEXT(ctx);
   intelScreenPrivate *screen = intel->intelScreen;

   CLAMPED_FLOAT_TO_UBYTE(intel->clear_red, color[0]);
   CLAMPED_FLOAT_TO_UBYTE(intel->clear_green, color[1]);
   CLAMPED_FLOAT_TO_UBYTE(intel->clear_blue, color[2]);
   CLAMPED_FLOAT_TO_UBYTE(intel->clear_alpha, color[3]);

   intel->ClearColor = INTEL_PACKCOLOR(screen->fbFormat,
				       intel->clear_red, 
				       intel->clear_green, 
				       intel->clear_blue, 
				       intel->clear_alpha);
}


static void intelCalcViewport( GLcontext *ctx )
{
   intelContextPtr intel = INTEL_CONTEXT(ctx);
   const GLfloat *v = ctx->Viewport._WindowMap.m;
   GLfloat *m = intel->ViewportMatrix.m;

   /* See also intel_translate_vertex.  SUBPIXEL adjustments can be done
    * via state vars, too.
    */
   m[MAT_SX] =   v[MAT_SX];
   m[MAT_TX] =   v[MAT_TX] + SUBPIXEL_X;
   m[MAT_SY] = - v[MAT_SY];
   m[MAT_TY] = - v[MAT_TY] + intel->driDrawable->h + SUBPIXEL_Y;
   m[MAT_SZ] =   v[MAT_SZ] * intel->depth_scale;
   m[MAT_TZ] =   v[MAT_TZ] * intel->depth_scale;
}

static void intelViewport( GLcontext *ctx,
			  GLint x, GLint y,
			  GLsizei width, GLsizei height )
{
   intelCalcViewport( ctx );
}

static void intelDepthRange( GLcontext *ctx,
			    GLclampd nearval, GLclampd farval )
{
   intelCalcViewport( ctx );
}

/* Fallback to swrast for select and feedback.
 */
static void intelRenderMode( GLcontext *ctx, GLenum mode )
{
   intelContextPtr intel = INTEL_CONTEXT(ctx);
   FALLBACK( intel, INTEL_FALLBACK_RENDERMODE, (mode != GL_RENDER) );
}


void intelInitStateFuncs( struct dd_function_table *functions )
{
   functions->DrawBuffer = intelDrawBuffer;
   functions->ReadBuffer = intelReadBuffer;
   functions->RenderMode = intelRenderMode;
   functions->Viewport = intelViewport;
   functions->DepthRange = intelDepthRange;
   functions->ClearColor = intelClearColor;
}