Major check-in of changes for GL_EXT_framebuffer_object extension.
[mesa.git] / src / mesa / drivers / dri / i810 / i810span.c
1 #include "glheader.h"
2 #include "macros.h"
3 #include "mtypes.h"
4 #include "colormac.h"
5
6 #include "i810screen.h"
7 #include "i810_dri.h"
8
9 #include "i810span.h"
10 #include "i810ioctl.h"
11 #include "swrast/swrast.h"
12
13
14 #define DBG 0
15
16 #define LOCAL_VARS \
17 i810ContextPtr imesa = I810_CONTEXT(ctx); \
18 __DRIdrawablePrivate *dPriv = imesa->driDrawable; \
19 i810ScreenPrivate *i810Screen = imesa->i810Screen; \
20 GLuint pitch = i810Screen->backPitch; \
21 GLuint height = dPriv->h; \
22 GLushort p; \
23 char *buf = (char *)(imesa->drawMap + \
24 dPriv->x * 2 + \
25 dPriv->y * pitch); \
26 char *read_buf = (char *)(imesa->readMap + \
27 dPriv->x * 2 + \
28 dPriv->y * pitch); \
29 (void) read_buf; (void) buf; (void) p
30
31 #define LOCAL_DEPTH_VARS \
32 i810ContextPtr imesa = I810_CONTEXT(ctx); \
33 __DRIdrawablePrivate *dPriv = imesa->driDrawable; \
34 i810ScreenPrivate *i810Screen = imesa->i810Screen; \
35 GLuint pitch = i810Screen->backPitch; \
36 GLuint height = dPriv->h; \
37 char *buf = (char *)(i810Screen->depth.map + \
38 dPriv->x * 2 + \
39 dPriv->y * pitch)
40
41 #define INIT_MONO_PIXEL(p, color) \
42 p = PACK_COLOR_565( color[0], color[1], color[2] )
43
44 #define CLIPPIXEL(_x,_y) (_x >= minx && _x < maxx && \
45 _y >= miny && _y < maxy)
46
47
48 #define CLIPSPAN( _x, _y, _n, _x1, _n1, _i ) \
49 if ( _y < miny || _y >= maxy ) { \
50 _n1 = 0, _x1 = x; \
51 } else { \
52 _n1 = _n; \
53 _x1 = _x; \
54 if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
55 if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx); \
56 }
57
58 #define Y_FLIP(_y) (height - _y - 1)
59
60 #define HW_LOCK()
61
62 #define HW_CLIPLOOP() \
63 do { \
64 __DRIdrawablePrivate *dPriv = imesa->driDrawable; \
65 int _nc = dPriv->numClipRects; \
66 while (_nc--) { \
67 int minx = dPriv->pClipRects[_nc].x1 - dPriv->x; \
68 int miny = dPriv->pClipRects[_nc].y1 - dPriv->y; \
69 int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x; \
70 int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y;
71
72
73 #define HW_ENDCLIPLOOP() \
74 } \
75 } while (0)
76
77 #define HW_UNLOCK()
78
79 /* 16 bit, 565 rgb color spanline and pixel functions
80 */
81 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
82 *(GLushort *)(buf + _x*2 + _y*pitch) = ( (((int)r & 0xf8) << 8) | \
83 (((int)g & 0xfc) << 3) | \
84 (((int)b & 0xf8) >> 3))
85 #define WRITE_PIXEL( _x, _y, p ) \
86 *(GLushort *)(buf + _x*2 + _y*pitch) = p
87
88 #define READ_RGBA( rgba, _x, _y ) \
89 do { \
90 GLushort p = *(GLushort *)(read_buf + _x*2 + _y*pitch); \
91 rgba[0] = ((p >> 8) & 0xf8) * 255 / 0xf8; \
92 rgba[1] = ((p >> 3) & 0xfc) * 255 / 0xfc; \
93 rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \
94 rgba[3] = 255; \
95 } while(0)
96
97 #define TAG(x) i810##x##_565
98 #include "spantmp.h"
99
100
101
102 /* 16 bit depthbuffer functions.
103 */
104 #define WRITE_DEPTH( _x, _y, d ) \
105 *(GLushort *)(buf + (_x)*2 + (_y)*pitch) = d;
106
107 #define READ_DEPTH( d, _x, _y ) \
108 d = *(GLushort *)(buf + (_x)*2 + (_y)*pitch);
109
110 #define TAG(x) i810##x##_16
111 #include "depthtmp.h"
112
113
114 /*
115 * This function is called to specify which buffer to read and write
116 * for software rasterization (swrast) fallbacks. This doesn't necessarily
117 * correspond to glDrawBuffer() or glReadBuffer() calls.
118 */
119 static void i810SetBuffer(GLcontext *ctx, GLframebuffer *buffer,
120 GLuint bufferBit )
121 {
122 i810ContextPtr imesa = I810_CONTEXT(ctx);
123 (void) buffer;
124
125 switch(bufferBit) {
126 case BUFFER_BIT_FRONT_LEFT:
127 if ( imesa->sarea->pf_current_page == 1)
128 imesa->readMap = imesa->i810Screen->back.map;
129 else
130 imesa->readMap = (char*)imesa->driScreen->pFB;
131 break;
132 case BUFFER_BIT_BACK_LEFT:
133 if ( imesa->sarea->pf_current_page == 1)
134 imesa->readMap = (char*)imesa->driScreen->pFB;
135 else
136 imesa->readMap = imesa->i810Screen->back.map;
137 break;
138 default:
139 ASSERT(0);
140 break;
141 }
142 imesa->drawMap = imesa->readMap;
143 }
144
145 /* Move locking out to get reasonable span performance.
146 */
147 void i810SpanRenderStart( GLcontext *ctx )
148 {
149 i810ContextPtr imesa = I810_CONTEXT(ctx);
150 I810_FIREVERTICES(imesa);
151 LOCK_HARDWARE(imesa);
152 i810RegetLockQuiescent( imesa );
153 }
154
155 void i810SpanRenderFinish( GLcontext *ctx )
156 {
157 i810ContextPtr imesa = I810_CONTEXT( ctx );
158 _swrast_flush( ctx );
159 UNLOCK_HARDWARE( imesa );
160 }
161
162 void i810InitSpanFuncs( GLcontext *ctx )
163 {
164 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
165
166 swdd->SetBuffer = i810SetBuffer;
167
168 #if 0
169 swdd->WriteRGBASpan = i810WriteRGBASpan_565;
170 swdd->WriteRGBSpan = i810WriteRGBSpan_565;
171 swdd->WriteMonoRGBASpan = i810WriteMonoRGBASpan_565;
172 swdd->WriteRGBAPixels = i810WriteRGBAPixels_565;
173 swdd->WriteMonoRGBAPixels = i810WriteMonoRGBAPixels_565;
174 swdd->ReadRGBASpan = i810ReadRGBASpan_565;
175 swdd->ReadRGBAPixels = i810ReadRGBAPixels_565;
176 #endif
177
178 #if 0
179 swdd->ReadDepthSpan = i810ReadDepthSpan_16;
180 swdd->WriteDepthSpan = i810WriteDepthSpan_16;
181 swdd->ReadDepthPixels = i810ReadDepthPixels_16;
182 swdd->WriteDepthPixels = i810WriteDepthPixels_16;
183 #endif
184
185 swdd->SpanRenderStart = i810SpanRenderStart;
186 swdd->SpanRenderFinish = i810SpanRenderFinish;
187 }
188
189
190
191 /**
192 * Plug in the Get/Put routines for the given driRenderbuffer.
193 */
194 void
195 i810SetSpanFunctions(driRenderbuffer *drb, const GLvisual *vis)
196 {
197 if (drb->Base.InternalFormat == GL_RGBA) {
198 /* always 565 RGB */
199 drb->Base.GetRow = i810ReadRGBASpan_565;
200 drb->Base.GetValues = i810ReadRGBAPixels_565;
201 drb->Base.PutRow = i810WriteRGBASpan_565;
202 drb->Base.PutRowRGB = i810WriteRGBSpan_565;
203 drb->Base.PutMonoRow = i810WriteMonoRGBASpan_565;
204 drb->Base.PutValues = i810WriteRGBAPixels_565;
205 drb->Base.PutMonoValues = i810WriteMonoRGBAPixels_565;
206 }
207 else if (drb->Base.InternalFormat == GL_DEPTH_COMPONENT16) {
208 drb->Base.GetRow = i810ReadDepthSpan_16;
209 drb->Base.GetValues = i810ReadDepthPixels_16;
210 drb->Base.PutRow = i810WriteDepthSpan_16;
211 drb->Base.PutMonoRow = i810WriteMonoDepthSpan_16;
212 drb->Base.PutValues = i810WriteDepthPixels_16;
213 drb->Base.PutMonoValues = NULL;
214 }
215 else if (drb->Base.InternalFormat == GL_DEPTH_COMPONENT24) {
216 /* should never get here */
217 drb->Base.GetRow = NULL;
218 drb->Base.GetValues = NULL;
219 drb->Base.PutRow = NULL;
220 drb->Base.PutMonoRow = NULL;
221 drb->Base.PutValues = NULL;
222 drb->Base.PutMonoValues = NULL;
223 }
224 else if (drb->Base.InternalFormat == GL_STENCIL_INDEX8_EXT) {
225 drb->Base.GetRow = NULL;
226 drb->Base.GetValues = NULL;
227 drb->Base.PutRow = NULL;
228 drb->Base.PutMonoRow = NULL;
229 drb->Base.PutValues = NULL;
230 drb->Base.PutMonoValues = NULL;
231 }
232 }