2 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4 The Weather Channel (TM) funded Tungsten Graphics to develop the
5 initial release of the Radeon 8500 driver under the XFree86 license.
6 This notice must be preserved.
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial
18 portions of the Software.
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
32 * Keith Whitwell <keith@tungstengraphics.com>
35 #include "main/glheader.h"
36 #include "main/imports.h"
37 #include "main/colormac.h"
38 #include "swrast/swrast.h"
40 #include "r200_context.h"
41 #include "radeon_buffer.h"
42 #include "r200_ioctl.h"
43 #include "r200_state.h"
44 #include "r200_span.h"
50 * Note that all information needed to access pixels in a renderbuffer
51 * should be obtained through the gl_renderbuffer parameter, not per-context
55 struct radeon_renderbuffer *rrb = (void *) rb; \
56 const __DRIdrawablePrivate *dPriv = rrb->dPriv; \
57 const GLuint bottom = dPriv->h - 1; \
61 #define LOCAL_DEPTH_VARS \
62 struct radeon_renderbuffer *rrb = (void *) rb; \
63 const __DRIdrawablePrivate *dPriv = rrb->dPriv; \
64 const GLuint bottom = dPriv->h - 1; \
65 GLuint xo = dPriv->x; \
68 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
70 #define Y_FLIP(Y) (bottom - (Y))
78 /* ================================================================
82 /* 16 bit, RGB565 color spanline and pixel functions
84 #define SPANTMP_PIXEL_FMT GL_RGB
85 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
87 #define TAG(x) radeon##x##_RGB565
88 #define TAG2(x,y) radeon##x##_RGB565##y
89 #define GET_PTR(X,Y) radeon_ptr16(rrb, (X), (Y))
92 /* 32 bit, ARGB8888 color spanline and pixel functions
94 #define SPANTMP_PIXEL_FMT GL_BGRA
95 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
97 #define TAG(x) radeon##x##_ARGB8888
98 #define TAG2(x,y) radeon##x##_ARGB8888##y
99 #define GET_PTR(X,Y) radeon_ptr32(rrb, (X), (Y))
100 #include "spantmp2.h"
103 /* ================================================================
107 /* The Radeon family has depth tiling on all the time, so we have to convert
108 * the x,y coordinates into the memory bus address (mba) in the same
109 * manner as the engine. In each case, the linear block address (ba)
110 * is calculated, and then wired with x and y to produce the final
112 * The chip will do address translation on its own if the surface registers
113 * are set up correctly. It is not quite enough to get it working with hyperz too...
116 /* 16-bit depth buffer functions
118 #define VALUE_TYPE GLushort
120 #define WRITE_DEPTH( _x, _y, d ) \
121 *(GLushort *)radeon_ptr(rrb, _x + xo, _y + yo) = d
123 #define READ_DEPTH( d, _x, _y ) \
124 d = *(GLushort *)radeon_ptr(rrb, _x + xo, _y + yo)
126 #define TAG(x) radeon##x##_z16
127 #include "depthtmp.h"
130 /* 24 bit depth, 8 bit stencil depthbuffer functions
132 #define VALUE_TYPE GLuint
134 #define WRITE_DEPTH( _x, _y, d ) \
136 GLuint *_ptr = (GLuint*)radeon_ptr32(rrb, _x + xo, _y + yo); \
137 GLuint tmp = *_ptr; \
139 tmp |= ((d) & 0x00ffffff); \
143 #define READ_DEPTH( d, _x, _y ) \
145 d = (*(GLuint*)(radeon_ptr32(rrb, _x + xo, _y + yo)) & 0x00ffffff); \
148 #define TAG(x) radeon##x##_z24_s8
149 #include "depthtmp.h"
152 /* ================================================================
156 /* 24 bit depth, 8 bit stencil depthbuffer functions
158 #define WRITE_STENCIL( _x, _y, d ) \
160 GLuint *_ptr = (GLuint*)radeon_ptr32(rrb, _x + xo, _y + yo); \
161 GLuint tmp = *_ptr; \
163 tmp |= (((d) & 0xff) << 24); \
167 #define READ_STENCIL( d, _x, _y ) \
169 GLuint *_ptr = (GLuint*)radeon_ptr32(rrb, _x + xo, _y + yo); \
170 GLuint tmp = *_ptr; \
175 #define TAG(x) radeon##x##_z24_s8
176 #include "stenciltmp.h"
179 void r200InitSpanFuncs( GLcontext
*ctx
)
181 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
182 swdd
->SpanRenderStart
= radeonSpanRenderStart
;
183 swdd
->SpanRenderFinish
= radeonSpanRenderFinish
;
189 * Plug in the Get/Put routines for the given driRenderbuffer.
191 void radeonSetSpanFunctions(struct radeon_renderbuffer
*rrb
)
193 if (rrb
->base
.InternalFormat
== GL_RGB5
) {
194 radeonInitPointers_RGB565(&rrb
->base
);
195 } else if (rrb
->base
.InternalFormat
== GL_RGBA8
) {
196 radeonInitPointers_ARGB8888(&rrb
->base
);
197 } else if (rrb
->base
.InternalFormat
== GL_DEPTH_COMPONENT16
) {
198 radeonInitDepthPointers_z16(&rrb
->base
);
199 } else if (rrb
->base
.InternalFormat
== GL_DEPTH_COMPONENT24
) {
200 radeonInitDepthPointers_z24_s8(&rrb
->base
);
201 } else if (rrb
->base
.InternalFormat
== GL_STENCIL_INDEX8_EXT
) {
202 radeonInitStencilPointers_z24_s8(&rrb
->base
);