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.
29 #include "via_context.h"
31 #include "via_ioctl.h"
32 #include "swrast/swrast.h"
36 #define Y_FLIP(_y) (height - _y - 1)
44 struct via_renderbuffer *vrb = (struct via_renderbuffer *) rb; \
45 __DRIdrawablePrivate *dPriv = vrb->dPriv; \
46 GLuint pitch = vrb->pitch; \
47 GLuint height = dPriv->h; \
49 char *buf = (char *)(vrb->origMap + vrb->drawXoff * vrb->bpp); \
52 /* ================================================================
56 /* 16 bit, RGB565 color spanline and pixel functions
58 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
59 #define SPANTMP_PIXEL_FMT GL_RGB
60 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
62 #define TAG(x) via##x##_565
63 #define TAG2(x,y) via##x##_565##y
67 /* 32 bit, ARGB8888 color spanline and pixel functions
69 #define GET_PTR(_x, _y) (buf + (_x) * 4 + (_y) * pitch)
70 #define SPANTMP_PIXEL_FMT GL_BGRA
71 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
73 #define TAG(x) via##x##_8888
74 #define TAG2(x,y) via##x##_8888##y
78 /* 16 bit depthbuffer functions.
80 #define LOCAL_DEPTH_VARS \
81 struct via_renderbuffer *vrb = (struct via_renderbuffer *) rb; \
82 __DRIdrawablePrivate *dPriv = vrb->dPriv; \
83 GLuint depth_pitch = vrb->pitch; \
84 GLuint height = dPriv->h; \
85 char *buf = (char *)(vrb->map + (vrb->drawXoff * vrb->bpp/8))
87 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
90 #define WRITE_DEPTH(_x, _y, d) \
91 *(GLushort *)(buf + (_x) * 2 + (_y) * depth_pitch) = d;
93 #define READ_DEPTH(d, _x, _y) \
94 d = *(volatile GLushort *)(buf + (_x) * 2 + (_y) * depth_pitch);
96 #define TAG(x) via##x##_z16
99 /* 32 bit depthbuffer functions.
101 #define WRITE_DEPTH(_x, _y, d) \
102 *(GLuint *)(buf + (_x) * 4 + (_y) * depth_pitch) = d;
104 #define READ_DEPTH(d, _x, _y) \
105 d = *(volatile GLuint *)(buf + (_x) * 4 + (_y) * depth_pitch);
107 #define TAG(x) via##x##_z32
108 #include "depthtmp.h"
112 /* 24/8 bit interleaved depth/stencil functions
114 #define WRITE_DEPTH( _x, _y, d ) { \
115 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch); \
118 *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) = tmp; \
121 #define READ_DEPTH( d, _x, _y ) \
122 d = (*(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch)) >> 8;
125 #define TAG(x) via##x##_z24_s8
126 #include "depthtmp.h"
128 #define WRITE_STENCIL( _x, _y, d ) { \
129 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch); \
132 *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) = tmp; \
135 #define READ_STENCIL( d, _x, _y ) \
136 d = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) & 0xff;
138 #define TAG(x) via##x##_z24_s8
139 #include "stenciltmp.h"
144 /* Move locking out to get reasonable span performance.
146 void viaSpanRenderStart( GLcontext
*ctx
)
148 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
149 viaWaitIdle(vmesa
, GL_FALSE
);
150 LOCK_HARDWARE(vmesa
);
153 void viaSpanRenderFinish( GLcontext
*ctx
)
155 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
156 _swrast_flush( ctx
);
157 UNLOCK_HARDWARE( vmesa
);
160 void viaInitSpanFuncs(GLcontext
*ctx
)
162 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
163 swdd
->SpanRenderStart
= viaSpanRenderStart
;
164 swdd
->SpanRenderFinish
= viaSpanRenderFinish
;
170 * Plug in the Get/Put routines for the given driRenderbuffer.
173 viaSetSpanFunctions(struct via_renderbuffer
*vrb
, const GLvisual
*vis
)
175 if (vrb
->Base
.InternalFormat
== GL_RGBA
) {
176 if (vis
->redBits
== 5 && vis
->greenBits
== 6 && vis
->blueBits
== 5) {
177 viaInitPointers_565(&vrb
->Base
);
180 viaInitPointers_8888(&vrb
->Base
);
183 else if (vrb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT16
) {
184 viaInitDepthPointers_z16(&vrb
->Base
);
186 else if (vrb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT24
) {
187 viaInitDepthPointers_z24_s8(&vrb
->Base
);
189 else if (vrb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT32
) {
190 viaInitDepthPointers_z32(&vrb
->Base
);
192 else if (vrb
->Base
.InternalFormat
== GL_STENCIL_INDEX8_EXT
) {
193 viaInitStencilPointers_z24_s8(&vrb
->Base
);