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/glheader.h"
26 #include "main/macros.h"
27 #include "main/mtypes.h"
28 #include "main/colormac.h"
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); \
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)
87 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
89 #define VALUE_TYPE GLushort
91 #define WRITE_DEPTH(_x, _y, d) \
92 *(GLushort *)(buf + (_x) * 2 + (_y) * depth_pitch) = d;
94 #define READ_DEPTH(d, _x, _y) \
95 d = *(volatile GLushort *)(buf + (_x) * 2 + (_y) * depth_pitch);
97 #define TAG(x) via##x##_z16
100 /* 32 bit depthbuffer functions.
102 #define VALUE_TYPE GLuint
104 #define WRITE_DEPTH(_x, _y, d) \
105 *(GLuint *)(buf + (_x) * 4 + (_y) * depth_pitch) = d;
107 #define READ_DEPTH(d, _x, _y) \
108 d = *(volatile GLuint *)(buf + (_x) * 4 + (_y) * depth_pitch);
110 #define TAG(x) via##x##_z32
111 #include "depthtmp.h"
115 /* 24/8 bit interleaved depth/stencil functions
117 #define VALUE_TYPE GLuint
119 #define WRITE_DEPTH( _x, _y, d ) { \
120 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch); \
123 *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) = tmp; \
126 #define READ_DEPTH( d, _x, _y ) \
127 d = (*(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch)) >> 8;
130 #define TAG(x) via##x##_z24_s8
131 #include "depthtmp.h"
133 #define WRITE_STENCIL( _x, _y, d ) { \
134 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch); \
137 *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) = tmp; \
140 #define READ_STENCIL( d, _x, _y ) \
141 d = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) & 0xff;
143 #define TAG(x) via##x##_z24_s8
144 #include "stenciltmp.h"
149 /* Move locking out to get reasonable span performance.
151 void viaSpanRenderStart( GLcontext
*ctx
)
153 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
154 viaWaitIdle(vmesa
, GL_FALSE
);
155 LOCK_HARDWARE(vmesa
);
158 void viaSpanRenderFinish( GLcontext
*ctx
)
160 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
161 _swrast_flush( ctx
);
162 UNLOCK_HARDWARE( vmesa
);
165 void viaInitSpanFuncs(GLcontext
*ctx
)
167 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
168 swdd
->SpanRenderStart
= viaSpanRenderStart
;
169 swdd
->SpanRenderFinish
= viaSpanRenderFinish
;
175 * Plug in the Get/Put routines for the given driRenderbuffer.
178 viaSetSpanFunctions(struct via_renderbuffer
*vrb
, const GLvisual
*vis
)
180 if (vrb
->Base
.InternalFormat
== GL_RGBA
) {
181 if (vis
->redBits
== 5 && vis
->greenBits
== 6 && vis
->blueBits
== 5) {
182 viaInitPointers_565(&vrb
->Base
);
185 viaInitPointers_8888(&vrb
->Base
);
188 else if (vrb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT16
) {
189 viaInitDepthPointers_z16(&vrb
->Base
);
191 else if (vrb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT24
) {
192 viaInitDepthPointers_z24_s8(&vrb
->Base
);
194 else if (vrb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT32
) {
195 viaInitDepthPointers_z32(&vrb
->Base
);
197 else if (vrb
->Base
.InternalFormat
== GL_STENCIL_INDEX8_EXT
) {
198 viaInitStencilPointers_z24_s8(&vrb
->Base
);