3bb6fbcc63c0839c99a98f8fb42b9a59abee3a3b
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_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 VALUE_TYPE GLushort
98 #define WRITE_DEPTH( _x, _y, d ) \
99 *(GLushort *)(buf + ((_x)<<1) + (_y)*pitch) = 0xFFFF - d
101 #define READ_DEPTH( d, _x, _y ) \
102 d = 0xFFFF - *(GLushort *)(buf + ((_x)<<1) + (_y)*pitch)
104 #define TAG(x) savage##x##_z16
105 #include "depthtmp.h"
110 /* 16 bit float depthbuffer functions
112 #define VALUE_TYPE GLushort
114 #define WRITE_DEPTH( _x, _y, d ) \
115 *(GLushort *)(buf + ((_x)<<1) + (_y)*pitch) = \
116 savageEncodeFloat16( 1.0 - (GLfloat)d/65535.0 )
118 #define READ_DEPTH( d, _x, _y ) \
120 savageDecodeFloat16( *(GLushort *)(buf + ((_x)<<1) + (_y)*pitch) ) * \
123 #define TAG(x) savage##x##_z16f
124 #include "depthtmp.h"
129 /* 8-bit stencil /24-bit integer depth depthbuffer functions.
130 * Depth range is reversed. See also savageCalcViewport.
132 #define VALUE_TYPE GLuint
134 #define WRITE_DEPTH( _x, _y, d ) do { \
135 GLuint tmp = *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch); \
137 tmp |= 0x00FFFFFF - d; \
138 *(GLuint *)(buf + (_x<<2) + _y*pitch) = tmp; \
141 #define READ_DEPTH( d, _x, _y ) \
142 d = 0x00FFFFFF - (*(GLuint *)(buf + ((_x)<<2) + (_y)*pitch) & 0x00FFFFFF)
144 #define TAG(x) savage##x##_s8_z24
145 #include "depthtmp.h"
150 /* 24 bit float depthbuffer functions
152 #define VALUE_TYPE GLuint
154 #define WRITE_DEPTH( _x, _y, d ) do { \
155 GLuint tmp = *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch); \
157 tmp |= savageEncodeFloat24( 1.0 - (GLfloat)d/16777215.0 ); \
158 *(GLuint *)(buf + (_x<<2) + _y*pitch) = tmp; \
161 #define READ_DEPTH( d, _x, _y ) \
162 d = 16777215 - savageDecodeFloat24( \
163 *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch) & 0x00FFFFFF) \
166 #define TAG(x) savage##x##_s8_z24f
167 #include "depthtmp.h"
170 #define WRITE_STENCIL( _x, _y, d ) do { \
171 GLuint tmp = *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch); \
173 tmp |= (((GLuint)d)<<24) & 0xFF000000; \
174 *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch) = tmp; \
177 #define READ_STENCIL( d, _x, _y ) \
178 d = (GLstencil)((*(GLuint *)(buf + ((_x)<<2) + (_y)*pitch) & 0xFF000000) >> 24)
180 #define TAG(x) savage##x##_s8_z24
181 #include "stenciltmp.h"
186 * Wrappers around _swrast_Copy/Draw/ReadPixels that make sure all
187 * primitives are flushed and the hardware is idle before accessing
191 savageCopyPixels( GLcontext
*ctx
,
192 GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
193 GLint destx
, GLint desty
,
196 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
198 WAIT_IDLE_EMPTY(imesa
);
199 _swrast_CopyPixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
);
202 savageDrawPixels( GLcontext
*ctx
,
204 GLsizei width
, GLsizei height
,
205 GLenum format
, GLenum type
,
206 const struct gl_pixelstore_attrib
*packing
,
207 const GLvoid
*pixels
)
209 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
211 WAIT_IDLE_EMPTY(imesa
);
212 _swrast_DrawPixels(ctx
, x
, y
, width
, height
, format
, type
, packing
, pixels
);
215 savageReadPixels( GLcontext
*ctx
,
216 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
217 GLenum format
, GLenum type
,
218 const struct gl_pixelstore_attrib
*packing
,
221 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
223 WAIT_IDLE_EMPTY(imesa
);
224 _swrast_ReadPixels(ctx
, x
, y
, width
, height
, format
, type
, packing
, pixels
);
228 * Make sure the hardware is idle when span-rendering.
230 static void savageSpanRenderStart( GLcontext
*ctx
)
232 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
234 WAIT_IDLE_EMPTY(imesa
);
238 void savageDDInitSpanFuncs( GLcontext
*ctx
)
240 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
241 swdd
->SpanRenderStart
= savageSpanRenderStart
;
243 /* XXX these should probably be plugged in elsewhere */
244 ctx
->Driver
.CopyPixels
= savageCopyPixels
;
245 ctx
->Driver
.DrawPixels
= savageDrawPixels
;
246 ctx
->Driver
.ReadPixels
= savageReadPixels
;
252 * Plug in the Get/Put routines for the given driRenderbuffer.
255 savageSetSpanFunctions(driRenderbuffer
*drb
, const GLvisual
*vis
,
256 GLboolean float_depth
)
258 if (drb
->Base
.Format
== MESA_FORMAT_RGB565
) {
259 savageInitPointers_565(&drb
->Base
);
261 else if (drb
->Base
.Format
== MESA_FORMAT_ARGB8888
) {
262 savageInitPointers_8888(&drb
->Base
);
264 else if (drb
->Base
.Format
== MESA_FORMAT_Z16
) {
266 savageInitDepthPointers_z16f(&drb
->Base
);
269 savageInitDepthPointers_z16(&drb
->Base
);
272 else if (drb
->Base
.Format
== MESA_FORMAT_S8_Z24
) {
274 savageInitDepthPointers_s8_z24f(&drb
->Base
);
277 savageInitDepthPointers_s8_z24(&drb
->Base
);
280 else if (drb
->Base
.Format
== MESA_FORMAT_S8
) {
281 savageInitStencilPointers_s8_z24(&drb
->Base
);