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.
27 #include "savagespan.h"
28 #include "savageioctl.h"
29 #include "savage_bci.h"
30 #include "savage_3d_reg.h"
31 #include "swrast/swrast.h"
36 driRenderbuffer *drb = (driRenderbuffer *) rb; \
37 __DRIdrawablePrivate *const dPriv = drb->dPriv; \
38 GLuint cpp = drb->cpp; \
39 GLuint pitch = drb->pitch; \
40 GLuint height = dPriv->h; \
41 GLubyte *buf = drb->Base.Data + dPriv->x * cpp + dPriv->y * pitch; \
45 #define LOCAL_DEPTH_VARS \
46 driRenderbuffer *drb = (driRenderbuffer *) rb; \
47 __DRIdrawablePrivate *const dPriv = drb->dPriv; \
48 GLuint zpp = drb->cpp; \
49 GLuint pitch = drb->pitch; \
50 GLuint height = dPriv->h; \
51 GLubyte *buf = drb->Base.Data + dPriv->x * zpp + dPriv->y * pitch;
53 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
55 #define Y_FLIP(_y) (height - _y - 1)
61 #define HW_WRITE_LOCK()
63 #define HW_READ_LOCK()
66 /* 16 bit, 565 rgb color spanline and pixel functions
68 #define SPANTMP_PIXEL_FMT GL_RGB
69 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
71 #define TAG(x) savage##x##_565
72 #define TAG2(x,y) savage##x##_565##y
76 /* 32 bit, 8888 ARGB color spanline and pixel functions
78 #define SPANTMP_PIXEL_FMT GL_BGRA
79 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
81 #define TAG(x) savage##x##_8888
82 #define TAG2(x,y) savage##x##_8888##y
87 #define HW_WRITE_LOCK()
89 #define HW_READ_LOCK()
93 /* 16 bit integer depthbuffer functions
94 * Depth range is reversed. See also savageCalcViewport.
96 #define WRITE_DEPTH( _x, _y, d ) \
97 *(GLushort *)(buf + ((_x)<<1) + (_y)*pitch) = 0xFFFF - d
99 #define READ_DEPTH( d, _x, _y ) \
100 d = 0xFFFF - *(GLushort *)(buf + ((_x)<<1) + (_y)*pitch)
102 #define TAG(x) savage##x##_z16
103 #include "depthtmp.h"
108 /* 16 bit float depthbuffer functions
110 #define WRITE_DEPTH( _x, _y, d ) \
111 *(GLushort *)(buf + ((_x)<<1) + (_y)*pitch) = \
112 savageEncodeFloat16( 1.0 - (GLfloat)d/65535.0 )
114 #define READ_DEPTH( d, _x, _y ) \
116 savageDecodeFloat16( *(GLushort *)(buf + ((_x)<<1) + (_y)*pitch) ) * \
119 #define TAG(x) savage##x##_z16f
120 #include "depthtmp.h"
125 /* 8-bit stencil /24-bit integer depth depthbuffer functions.
126 * Depth range is reversed. See also savageCalcViewport.
128 #define WRITE_DEPTH( _x, _y, d ) do { \
129 GLuint tmp = *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch); \
131 tmp |= 0x00FFFFFF - d; \
132 *(GLuint *)(buf + (_x<<2) + _y*pitch) = tmp; \
135 #define READ_DEPTH( d, _x, _y ) \
136 d = 0x00FFFFFF - (*(GLuint *)(buf + ((_x)<<2) + (_y)*pitch) & 0x00FFFFFF)
138 #define TAG(x) savage##x##_s8_z24
139 #include "depthtmp.h"
144 /* 24 bit float depthbuffer functions
146 #define WRITE_DEPTH( _x, _y, d ) do { \
147 GLuint tmp = *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch); \
149 tmp |= savageEncodeFloat24( 1.0 - (GLfloat)d/16777215.0 ); \
150 *(GLuint *)(buf + (_x<<2) + _y*pitch) = tmp; \
153 #define READ_DEPTH( d, _x, _y ) \
154 d = 16777215 - savageDecodeFloat24( \
155 *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch) & 0x00FFFFFF) \
158 #define TAG(x) savage##x##_s8_z24f
159 #include "depthtmp.h"
162 #define WRITE_STENCIL( _x, _y, d ) do { \
163 GLuint tmp = *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch); \
165 tmp |= (((GLuint)d)<<24) & 0xFF000000; \
166 *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch) = tmp; \
169 #define READ_STENCIL( d, _x, _y ) \
170 d = (GLstencil)((*(GLuint *)(buf + ((_x)<<2) + (_y)*pitch) & 0xFF000000) >> 24)
172 #define TAG(x) savage##x##_s8_z24
173 #include "stenciltmp.h"
178 * Wrappers around _swrast_Copy/Draw/ReadPixels that make sure all
179 * primitives are flushed and the hardware is idle before accessing
183 savageCopyPixels( GLcontext
*ctx
,
184 GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
185 GLint destx
, GLint desty
,
188 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
190 WAIT_IDLE_EMPTY(imesa
);
191 _swrast_CopyPixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
);
194 savageDrawPixels( GLcontext
*ctx
,
196 GLsizei width
, GLsizei height
,
197 GLenum format
, GLenum type
,
198 const struct gl_pixelstore_attrib
*packing
,
199 const GLvoid
*pixels
)
201 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
203 WAIT_IDLE_EMPTY(imesa
);
204 _swrast_DrawPixels(ctx
, x
, y
, width
, height
, format
, type
, packing
, pixels
);
207 savageReadPixels( GLcontext
*ctx
,
208 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
209 GLenum format
, GLenum type
,
210 const struct gl_pixelstore_attrib
*packing
,
213 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
215 WAIT_IDLE_EMPTY(imesa
);
216 _swrast_ReadPixels(ctx
, x
, y
, width
, height
, format
, type
, packing
, pixels
);
220 * Make sure the hardware is idle when span-rendering.
222 static void savageSpanRenderStart( GLcontext
*ctx
)
224 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
226 WAIT_IDLE_EMPTY(imesa
);
230 void savageDDInitSpanFuncs( GLcontext
*ctx
)
232 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
233 swdd
->SpanRenderStart
= savageSpanRenderStart
;
235 /* XXX these should probably be plugged in elsewhere */
236 ctx
->Driver
.CopyPixels
= savageCopyPixels
;
237 ctx
->Driver
.DrawPixels
= savageDrawPixels
;
238 ctx
->Driver
.ReadPixels
= savageReadPixels
;
244 * Plug in the Get/Put routines for the given driRenderbuffer.
247 savageSetSpanFunctions(driRenderbuffer
*drb
, const GLvisual
*vis
,
248 GLboolean float_depth
)
250 if (drb
->Base
.InternalFormat
== GL_RGBA
) {
251 if (vis
->redBits
== 5 && vis
->greenBits
== 6 && vis
->blueBits
== 5) {
252 savageInitPointers_565(&drb
->Base
);
255 savageInitPointers_8888(&drb
->Base
);
258 else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT16
) {
260 savageInitDepthPointers_z16f(&drb
->Base
);
263 savageInitDepthPointers_z16(&drb
->Base
);
266 else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT24
) {
268 savageInitDepthPointers_s8_z24f(&drb
->Base
);
271 savageInitDepthPointers_s8_z24(&drb
->Base
);
274 else if (drb
->Base
.InternalFormat
== GL_STENCIL_INDEX8_EXT
) {
275 savageInitStencilPointers_s8_z24(&drb
->Base
);