SetBuffer, renderbuffer changes
[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 __DRIdrawablePrivate *dPriv = mmesa->mesa_drawable; \
40 __DRIscreenPrivate *sPriv = mmesa->driScreen; \
41 driRenderbuffer *drb = (driRenderbuffer *) rb; \
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 char *read_buf = buf; \
49 GLuint p; \
50 (void) read_buf; (void) buf; (void) p
51
52
53
54 #define LOCAL_DEPTH_VARS \
55 mgaContextPtr mmesa = MGA_CONTEXT(ctx); \
56 __DRIdrawablePrivate *dPriv = mmesa->mesa_drawable; \
57 __DRIscreenPrivate *sPriv = mmesa->driScreen; \
58 driRenderbuffer *drb = (driRenderbuffer *) rb; \
59 GLuint pitch = drb->pitch; \
60 GLuint height = dPriv->h; \
61 char *buf = (char *)(sPriv->pFB + \
62 drb->offset + \
63 dPriv->x * drb->cpp + \
64 dPriv->y * pitch)
65
66 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
67
68 #define HW_LOCK()
69
70 /* FIXME could/should we use dPriv->numClipRects like the other drivers? */
71 #define HW_CLIPLOOP() \
72 do { \
73 int _nc = mmesa->numClipRects; \
74 while (_nc--) { \
75 int minx = mmesa->pClipRects[_nc].x1 - mmesa->drawX; \
76 int miny = mmesa->pClipRects[_nc].y1 - mmesa->drawY; \
77 int maxx = mmesa->pClipRects[_nc].x2 - mmesa->drawX; \
78 int maxy = mmesa->pClipRects[_nc].y2 - mmesa->drawY;
79
80 #define HW_ENDCLIPLOOP() \
81 } \
82 } while (0)
83
84 #define HW_UNLOCK()
85
86
87
88 #define Y_FLIP(_y) (height - _y - 1)
89
90 /* 16 bit, RGB565 color spanline and pixel functions
91 */
92 #define SPANTMP_PIXEL_FMT GL_RGB
93 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
94
95 #define TAG(x) mga##x##_565
96 #define TAG2(x,y) mga##x##_565##y
97 #include "spantmp2.h"
98
99 /* 32 bit, ARGB8888 color spanline and pixel functions
100 */
101 #define SPANTMP_PIXEL_FMT GL_BGRA
102 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
103
104 #define TAG(x) mga##x##_8888
105 #define TAG2(x,y) mga##x##_8888##y
106 #include "spantmp2.h"
107
108
109 /* 16 bit depthbuffer functions.
110 */
111 #define WRITE_DEPTH( _x, _y, d ) \
112 *(GLushort *)(buf + (_x)*2 + (_y)*pitch) = d;
113
114 #define READ_DEPTH( d, _x, _y ) \
115 d = *(GLushort *)(buf + (_x)*2 + (_y)*pitch);
116
117 #define TAG(x) mga##x##_z16
118 #include "depthtmp.h"
119
120
121
122
123 /* 32 bit depthbuffer functions.
124 */
125 #define WRITE_DEPTH( _x, _y, d ) \
126 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = d;
127
128 #define READ_DEPTH( d, _x, _y ) \
129 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch);
130
131 #define TAG(x) mga##x##_z32
132 #include "depthtmp.h"
133
134
135
136 /* 24/8 bit interleaved depth/stencil functions
137 */
138 #define WRITE_DEPTH( _x, _y, d ) { \
139 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*pitch); \
140 tmp &= 0xff; \
141 tmp |= (d) << 8; \
142 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = tmp; \
143 }
144
145 #define READ_DEPTH( d, _x, _y ) { \
146 d = (*(GLuint *)(buf + (_x)*4 + (_y)*pitch) & ~0xff) >> 8; \
147 }
148
149 #define TAG(x) mga##x##_z24_s8
150 #include "depthtmp.h"
151
152 #define WRITE_STENCIL( _x, _y, d ) { \
153 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*pitch); \
154 tmp &= 0xffffff00; \
155 tmp |= d & 0xff; \
156 *(GLuint *)(buf + _x*4 + _y*pitch) = tmp; \
157 }
158
159 #define READ_STENCIL( d, _x, _y ) \
160 d = *(GLuint *)(buf + _x*4 + _y*pitch) & 0xff;
161
162 #define TAG(x) mga##x##_z24_s8
163 #include "stenciltmp.h"
164
165
166 void mgaSpanRenderStart( GLcontext *ctx )
167 {
168 mgaContextPtr mmesa = MGA_CONTEXT(ctx);
169 FLUSH_BATCH( mmesa );
170 LOCK_HARDWARE_QUIESCENT( mmesa );
171 }
172
173 void mgaSpanRenderFinish( GLcontext *ctx )
174 {
175 mgaContextPtr mmesa = MGA_CONTEXT(ctx);
176 _swrast_flush( ctx );
177 UNLOCK_HARDWARE( mmesa );
178 }
179
180 /**
181 * Initialize the driver callbacks for the read / write span functions.
182 *
183 * \bug
184 * To really support RGB888 and RGBA8888 visuals, we need separate read and
185 * write routines for 888 and 8888. We also need to determine whether or not
186 * the visual has destination alpha.
187 */
188 void mgaDDInitSpanFuncs( GLcontext *ctx )
189 {
190 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
191 swdd->SpanRenderStart = mgaSpanRenderStart;
192 swdd->SpanRenderFinish = mgaSpanRenderFinish;
193 }
194
195
196 /**
197 * Plug in the Get/Put routines for the given driRenderbuffer.
198 */
199 void
200 mgaSetSpanFunctions(driRenderbuffer *drb, const GLvisual *vis)
201 {
202 if (drb->Base.InternalFormat == GL_RGBA) {
203 if (vis->redBits == 5 && vis->greenBits == 6 && vis->blueBits == 5) {
204 mgaInitPointers_565(&drb->Base);
205 }
206 else {
207 mgaInitPointers_8888(&drb->Base);
208 }
209 }
210 else if (drb->Base.InternalFormat == GL_DEPTH_COMPONENT16) {
211 mgaInitDepthPointers_z16(&drb->Base);
212 }
213 else if (drb->Base.InternalFormat == GL_DEPTH_COMPONENT24) {
214 mgaInitDepthPointers_z24_s8(&drb->Base);
215 }
216 else if (drb->Base.InternalFormat == GL_DEPTH_COMPONENT32) {
217 mgaInitDepthPointers_z32(&drb->Base);
218 }
219 else if (drb->Base.InternalFormat == GL_STENCIL_INDEX8_EXT) {
220 mgaInitStencilPointers_z24_s8(&drb->Base);
221 }
222 }