2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
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 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
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 * VIA, S3 GRAPHICS, 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 OTHER
22 * DEALINGS IN THE SOFTWARE.
25 #include "main/mtypes.h"
27 #include "savagespan.h"
28 #include "savageioctl.h"
29 #include "savage_3d_reg.h"
30 #include "swrast/swrast.h"
35 driRenderbuffer *drb = (driRenderbuffer *) rb; \
36 __DRIdrawable *const dPriv = drb->dPriv; \
37 GLuint cpp = drb->cpp; \
38 GLuint pitch = drb->pitch; \
39 GLuint height = dPriv->h; \
40 GLubyte *buf = drb->Base.Data + dPriv->x * cpp + dPriv->y * pitch; \
44 #define LOCAL_DEPTH_VARS \
45 driRenderbuffer *drb = (driRenderbuffer *) rb; \
46 __DRIdrawable *const dPriv = drb->dPriv; \
47 GLuint zpp = drb->cpp; \
48 GLuint pitch = drb->pitch; \
49 GLuint height = dPriv->h; \
50 GLubyte *buf = drb->Base.Data + dPriv->x * zpp + dPriv->y * pitch;
52 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
54 #define Y_FLIP(_y) (height - _y - 1)
60 #define HW_WRITE_LOCK()
62 #define HW_READ_LOCK()
65 /* 16 bit, 565 rgb color spanline and pixel functions
67 #define SPANTMP_PIXEL_FMT GL_RGB
68 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
70 #define TAG(x) savage##x##_565
71 #define TAG2(x,y) savage##x##_565##y
75 /* 32 bit, 8888 ARGB color spanline and pixel functions
77 #define SPANTMP_PIXEL_FMT GL_BGRA
78 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
80 #define TAG(x) savage##x##_8888
81 #define TAG2(x,y) savage##x##_8888##y
86 #define HW_WRITE_LOCK()
88 #define HW_READ_LOCK()
92 /* 16 bit integer depthbuffer functions
93 * Depth range is reversed. See also savageCalcViewport.
95 #define VALUE_TYPE GLushort
97 #define WRITE_DEPTH( _x, _y, d ) \
98 *(GLushort *)(buf + ((_x)<<1) + (_y)*pitch) = 0xFFFF - d
100 #define READ_DEPTH( d, _x, _y ) \
101 d = 0xFFFF - *(GLushort *)(buf + ((_x)<<1) + (_y)*pitch)
103 #define TAG(x) savage##x##_z16
104 #include "depthtmp.h"
109 /* 16 bit float depthbuffer functions
111 #define VALUE_TYPE GLushort
113 #define WRITE_DEPTH( _x, _y, d ) \
114 *(GLushort *)(buf + ((_x)<<1) + (_y)*pitch) = \
115 savageEncodeFloat16( 1.0 - (GLfloat)d/65535.0 )
117 #define READ_DEPTH( d, _x, _y ) \
119 savageDecodeFloat16( *(GLushort *)(buf + ((_x)<<1) + (_y)*pitch) ) * \
122 #define TAG(x) savage##x##_z16f
123 #include "depthtmp.h"
128 /* 8-bit stencil /24-bit integer depth depthbuffer functions.
129 * Depth range is reversed. See also savageCalcViewport.
131 #define VALUE_TYPE GLuint
133 #define WRITE_DEPTH( _x, _y, d ) do { \
134 GLuint tmp = *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch); \
136 tmp |= 0x00FFFFFF - d; \
137 *(GLuint *)(buf + (_x<<2) + _y*pitch) = tmp; \
140 #define READ_DEPTH( d, _x, _y ) \
141 d = 0x00FFFFFF - (*(GLuint *)(buf + ((_x)<<2) + (_y)*pitch) & 0x00FFFFFF)
143 #define TAG(x) savage##x##_s8_z24
144 #include "depthtmp.h"
149 /* 24 bit float depthbuffer functions
151 #define VALUE_TYPE GLuint
153 #define WRITE_DEPTH( _x, _y, d ) do { \
154 GLuint tmp = *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch); \
156 tmp |= savageEncodeFloat24( 1.0 - (GLfloat)d/16777215.0 ); \
157 *(GLuint *)(buf + (_x<<2) + _y*pitch) = tmp; \
160 #define READ_DEPTH( d, _x, _y ) \
161 d = 16777215 - savageDecodeFloat24( \
162 *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch) & 0x00FFFFFF) \
165 #define TAG(x) savage##x##_s8_z24f
166 #include "depthtmp.h"
169 #define WRITE_STENCIL( _x, _y, d ) do { \
170 GLuint tmp = *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch); \
172 tmp |= (((GLuint)d)<<24) & 0xFF000000; \
173 *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch) = tmp; \
176 #define READ_STENCIL( d, _x, _y ) \
177 d = (GLstencil)((*(GLuint *)(buf + ((_x)<<2) + (_y)*pitch) & 0xFF000000) >> 24)
179 #define TAG(x) savage##x##_s8_z24
180 #include "stenciltmp.h"
185 * Wrappers around _swrast_Copy/Draw/ReadPixels that make sure all
186 * primitives are flushed and the hardware is idle before accessing
190 savageCopyPixels( GLcontext
*ctx
,
191 GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
192 GLint destx
, GLint desty
,
195 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
197 WAIT_IDLE_EMPTY(imesa
);
198 _swrast_CopyPixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
);
201 savageDrawPixels( GLcontext
*ctx
,
203 GLsizei width
, GLsizei height
,
204 GLenum format
, GLenum type
,
205 const struct gl_pixelstore_attrib
*packing
,
206 const GLvoid
*pixels
)
208 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
210 WAIT_IDLE_EMPTY(imesa
);
211 _swrast_DrawPixels(ctx
, x
, y
, width
, height
, format
, type
, packing
, pixels
);
214 savageReadPixels( GLcontext
*ctx
,
215 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
216 GLenum format
, GLenum type
,
217 const struct gl_pixelstore_attrib
*packing
,
220 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
222 WAIT_IDLE_EMPTY(imesa
);
223 _swrast_ReadPixels(ctx
, x
, y
, width
, height
, format
, type
, packing
, pixels
);
227 * Make sure the hardware is idle when span-rendering.
229 static void savageSpanRenderStart( GLcontext
*ctx
)
231 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
233 WAIT_IDLE_EMPTY(imesa
);
237 void savageDDInitSpanFuncs( GLcontext
*ctx
)
239 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
240 swdd
->SpanRenderStart
= savageSpanRenderStart
;
242 /* XXX these should probably be plugged in elsewhere */
243 ctx
->Driver
.CopyPixels
= savageCopyPixels
;
244 ctx
->Driver
.DrawPixels
= savageDrawPixels
;
245 ctx
->Driver
.ReadPixels
= savageReadPixels
;
251 * Plug in the Get/Put routines for the given driRenderbuffer.
254 savageSetSpanFunctions(driRenderbuffer
*drb
, const GLvisual
*vis
,
255 GLboolean float_depth
)
257 if (drb
->Base
.Format
== MESA_FORMAT_RGB565
) {
258 savageInitPointers_565(&drb
->Base
);
260 else if (drb
->Base
.Format
== MESA_FORMAT_ARGB8888
) {
261 savageInitPointers_8888(&drb
->Base
);
263 else if (drb
->Base
.Format
== MESA_FORMAT_Z16
) {
265 savageInitDepthPointers_z16f(&drb
->Base
);
268 savageInitDepthPointers_z16(&drb
->Base
);
271 else if (drb
->Base
.Format
== MESA_FORMAT_S8_Z24
) {
273 savageInitDepthPointers_s8_z24f(&drb
->Base
);
276 savageInitDepthPointers_s8_z24(&drb
->Base
);
279 else if (drb
->Base
.Format
== MESA_FORMAT_S8
) {
280 savageInitStencilPointers_s8_z24(&drb
->Base
);