fix GL_LINE_LOOP with drivers using own render pipeline stage (#12410, #13527)
[mesa.git] / src / mesa / drivers / dri / mga / mgaspan.c
1 /*
2 * Copyright 2000-2001 VA Linux Systems, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Keith Whitwell <keith@tungstengraphics.com>
26 */
27
28 #include "mtypes.h"
29 #include "mgadd.h"
30 #include "mgacontext.h"
31 #include "mgaspan.h"
32 #include "mgaioctl.h"
33 #include "swrast/swrast.h"
34
35 #define DBG 0
36
37 #define LOCAL_VARS \
38 mgaContextPtr mmesa = MGA_CONTEXT(ctx); \
39 __DRIscreenPrivate *sPriv = mmesa->driScreen; \
40 driRenderbuffer *drb = (driRenderbuffer *) rb; \
41 const __DRIdrawablePrivate *dPriv = drb->dPriv; \
42 GLuint pitch = drb->pitch; \
43 GLuint height = dPriv->h; \
44 char *buf = (char *)(sPriv->pFB + \
45 drb->offset + \
46 dPriv->x * drb->cpp + \
47 dPriv->y * pitch); \
48 GLuint p; \
49 (void) buf; (void) p
50
51
52
53 #define LOCAL_DEPTH_VARS \
54 mgaContextPtr mmesa = MGA_CONTEXT(ctx); \
55 __DRIscreenPrivate *sPriv = mmesa->driScreen; \
56 driRenderbuffer *drb = (driRenderbuffer *) rb; \
57 const __DRIdrawablePrivate *dPriv = drb->dPriv; \
58 GLuint pitch = drb->pitch; \
59 GLuint height = dPriv->h; \
60 char *buf = (char *)(sPriv->pFB + \
61 drb->offset + \
62 dPriv->x * drb->cpp + \
63 dPriv->y * pitch)
64
65 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
66
67 #define HW_LOCK()
68
69 /* FIXME could/should we use dPriv->numClipRects like the other drivers? */
70 #define HW_CLIPLOOP() \
71 do { \
72 int _nc = mmesa->numClipRects; \
73 while (_nc--) { \
74 int minx = mmesa->pClipRects[_nc].x1 - mmesa->drawX; \
75 int miny = mmesa->pClipRects[_nc].y1 - mmesa->drawY; \
76 int maxx = mmesa->pClipRects[_nc].x2 - mmesa->drawX; \
77 int maxy = mmesa->pClipRects[_nc].y2 - mmesa->drawY;
78
79 #define HW_ENDCLIPLOOP() \
80 } \
81 } while (0)
82
83 #define HW_UNLOCK()
84
85
86
87 #define Y_FLIP(_y) (height - _y - 1)
88
89 /* 16 bit, RGB565 color spanline and pixel functions
90 */
91 #define SPANTMP_PIXEL_FMT GL_RGB
92 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
93
94 #define TAG(x) mga##x##_565
95 #define TAG2(x,y) mga##x##_565##y
96 #include "spantmp2.h"
97
98 /* 32 bit, ARGB8888 color spanline and pixel functions
99 */
100 #define SPANTMP_PIXEL_FMT GL_BGRA
101 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
102
103 #define TAG(x) mga##x##_8888
104 #define TAG2(x,y) mga##x##_8888##y
105 #include "spantmp2.h"
106
107
108 /* 16 bit depthbuffer functions.
109 */
110 #define WRITE_DEPTH( _x, _y, d ) \
111 *(GLushort *)(buf + (_x)*2 + (_y)*pitch) = d;
112
113 #define READ_DEPTH( d, _x, _y ) \
114 d = *(GLushort *)(buf + (_x)*2 + (_y)*pitch);
115
116 #define TAG(x) mga##x##_z16
117 #include "depthtmp.h"
118
119
120
121
122 /* 32 bit depthbuffer functions.
123 */
124 #define WRITE_DEPTH( _x, _y, d ) \
125 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = d;
126
127 #define READ_DEPTH( d, _x, _y ) \
128 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch);
129
130 #define TAG(x) mga##x##_z32
131 #include "depthtmp.h"
132
133
134
135 /* 24/8 bit interleaved depth/stencil functions
136 */
137 #define WRITE_DEPTH( _x, _y, d ) { \
138 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*pitch); \
139 tmp &= 0xff; \
140 tmp |= (d) << 8; \
141 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = tmp; \
142 }
143
144 #define READ_DEPTH( d, _x, _y ) { \
145 d = (*(GLuint *)(buf + (_x)*4 + (_y)*pitch) & ~0xff) >> 8; \
146 }
147
148 #define TAG(x) mga##x##_z24_s8
149 #include "depthtmp.h"
150
151 #define WRITE_STENCIL( _x, _y, d ) { \
152 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*pitch); \
153 tmp &= 0xffffff00; \
154 tmp |= d & 0xff; \
155 *(GLuint *)(buf + _x*4 + _y*pitch) = tmp; \
156 }
157
158 #define READ_STENCIL( d, _x, _y ) \
159 d = *(GLuint *)(buf + _x*4 + _y*pitch) & 0xff;
160
161 #define TAG(x) mga##x##_z24_s8
162 #include "stenciltmp.h"
163
164
165 static void
166 mgaSpanRenderStart( GLcontext *ctx )
167 {
168 mgaContextPtr mmesa = MGA_CONTEXT(ctx);
169 FLUSH_BATCH( mmesa );
170 LOCK_HARDWARE_QUIESCENT( mmesa );
171 }
172
173 static void
174 mgaSpanRenderFinish( GLcontext *ctx )
175 {
176 mgaContextPtr mmesa = MGA_CONTEXT(ctx);
177 _swrast_flush( ctx );
178 UNLOCK_HARDWARE( mmesa );
179 }
180
181 /**
182 * Initialize the driver callbacks for the read / write span functions.
183 *
184 * \bug
185 * To really support RGB888 and RGBA8888 visuals, we need separate read and
186 * write routines for 888 and 8888. We also need to determine whether or not
187 * the visual has destination alpha.
188 */
189 void mgaDDInitSpanFuncs( GLcontext *ctx )
190 {
191 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
192 swdd->SpanRenderStart = mgaSpanRenderStart;
193 swdd->SpanRenderFinish = mgaSpanRenderFinish;
194 }
195
196
197 /**
198 * Plug in the Get/Put routines for the given driRenderbuffer.
199 */
200 void
201 mgaSetSpanFunctions(driRenderbuffer *drb, const GLvisual *vis)
202 {
203 if (drb->Base.InternalFormat == GL_RGBA) {
204 if (vis->redBits == 5 && vis->greenBits == 6 && vis->blueBits == 5) {
205 mgaInitPointers_565(&drb->Base);
206 }
207 else {
208 mgaInitPointers_8888(&drb->Base);
209 }
210 }
211 else if (drb->Base.InternalFormat == GL_DEPTH_COMPONENT16) {
212 mgaInitDepthPointers_z16(&drb->Base);
213 }
214 else if (drb->Base.InternalFormat == GL_DEPTH_COMPONENT24) {
215 mgaInitDepthPointers_z24_s8(&drb->Base);
216 }
217 else if (drb->Base.InternalFormat == GL_DEPTH_COMPONENT32) {
218 mgaInitDepthPointers_z32(&drb->Base);
219 }
220 else if (drb->Base.InternalFormat == GL_STENCIL_INDEX8_EXT) {
221 mgaInitStencilPointers_z24_s8(&drb->Base);
222 }
223 }