Bug #4615: Fix the SiS driver for the renderbuffer changes. Previously, all
[mesa.git] / src / mesa / drivers / dri / sis / sis_span.c
1 /**************************************************************************
2
3 Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
4 Copyright 2003 Eric Anholt
5 All Rights Reserved.
6
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
16 Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **************************************************************************/
27 /* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_span.c,v 1.5 2001/03/21 16:14:26 dawes Exp $ */
28
29 /*
30 * Authors:
31 * Sung-Ching Lin <sclin@sis.com.tw>
32 * Eric Anholt <anholt@FreeBSD.org>
33 */
34
35 #include "sis_context.h"
36 #include "sis_span.h"
37 #include "sis_lock.h"
38 #include "sis_tris.h"
39
40 #include "swrast/swrast.h"
41
42 #define DBG 0
43
44 #define LOCAL_VARS \
45 sisContextPtr smesa = SIS_CONTEXT(ctx); \
46 __DRIdrawablePrivate *dPriv = smesa->driDrawable; \
47 struct sis_renderbuffer *srb = (struct sis_renderbuffer *) rb; \
48 GLuint pitch = srb->pitch; \
49 char *buf = srb->map; \
50 GLuint p; \
51 (void) buf; (void) p;
52
53
54 #define LOCAL_DEPTH_VARS \
55 sisContextPtr smesa = SIS_CONTEXT(ctx); \
56 __DRIdrawablePrivate *dPriv = smesa->driDrawable; \
57 struct sis_renderbuffer *srb = (struct sis_renderbuffer *) rb; \
58 char *buf = srb->map;
59
60 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
61
62 #define HW_LOCK() do {} while(0);
63
64 #define HW_UNLOCK() do {} while(0);
65
66 /* RGB565 */
67 #define SPANTMP_PIXEL_FMT GL_RGB
68 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
69
70 #define TAG(x) sis##x##_RGB565
71 #define TAG2(x,y) sis##x##_RGB565##y
72 #include "spantmp2.h"
73
74
75 /* ARGB8888 */
76 /* FIXME the old code always read back alpha as 0xff, i.e. fully opaque.
77 Was there a reason to do so ? If so that'll won't work with that template... */
78 #define SPANTMP_PIXEL_FMT GL_BGRA
79 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
80
81 #define TAG(x) sis##x##_ARGB8888
82 #define TAG2(x,y) sis##x##_ARGB8888##y
83 #include "spantmp2.h"
84
85
86 /* 16 bit depthbuffer functions.
87 */
88 #define WRITE_DEPTH( _x, _y, d ) \
89 *(GLushort *)(buf + (_x)*2 + (_y)*srb->pitch) = d;
90
91 #define READ_DEPTH( d, _x, _y ) \
92 d = *(GLushort *)(buf + (_x)*2 + (_y)*srb->pitch);
93
94 #define TAG(x) sis##x##_z16
95 #include "depthtmp.h"
96
97
98 /* 32 bit depthbuffer functions.
99 */
100 #define WRITE_DEPTH( _x, _y, d ) \
101 *(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch) = d;
102
103 #define READ_DEPTH( d, _x, _y ) \
104 d = *(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch);
105
106 #define TAG(x) sis##x##_z32
107 #include "depthtmp.h"
108
109
110 /* 8/24 bit interleaved depth/stencil functions
111 */
112 #define WRITE_DEPTH( _x, _y, d ) { \
113 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch); \
114 tmp &= 0xff000000; \
115 tmp |= (d & 0x00ffffff); \
116 *(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch) = tmp; \
117 }
118
119 #define READ_DEPTH( d, _x, _y ) { \
120 d = *(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch) & 0x00ffffff; \
121 }
122
123 #define TAG(x) sis##x##_z24_s8
124 #include "depthtmp.h"
125
126 #define WRITE_STENCIL( _x, _y, d ) { \
127 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*smesa->depth.pitch); \
128 tmp &= 0x00ffffff; \
129 tmp |= (d << 24); \
130 *(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch) = tmp; \
131 }
132
133 #define READ_STENCIL( d, _x, _y ) \
134 d = (*(GLuint *)(buf + (_x)*4 + (_y)*srb->pitch) & 0xff000000) >> 24;
135
136 #define TAG(x) sis##x##_z24_s8
137 #include "stenciltmp.h"
138
139
140
141 void sisSpanRenderStart( GLcontext *ctx )
142 {
143 sisContextPtr smesa = SIS_CONTEXT(ctx);
144
145 SIS_FIREVERTICES(smesa);
146 LOCK_HARDWARE();
147 WaitEngIdle( smesa );
148 }
149
150 void sisSpanRenderFinish( GLcontext *ctx )
151 {
152 sisContextPtr smesa = SIS_CONTEXT(ctx);
153
154 _swrast_flush( ctx );
155 UNLOCK_HARDWARE();
156 }
157
158 void
159 sisDDInitSpanFuncs( GLcontext *ctx )
160 {
161 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
162 swdd->SpanRenderStart = sisSpanRenderStart;
163 swdd->SpanRenderFinish = sisSpanRenderFinish;
164 }
165
166
167
168 /**
169 * Plug in the Get/Put routines for the given driRenderbuffer.
170 */
171 void
172 sisSetSpanFunctions(struct sis_renderbuffer *srb, const GLvisual *vis)
173 {
174 if (srb->Base.InternalFormat == GL_RGBA) {
175 if (vis->redBits == 5 && vis->greenBits == 6 && vis->blueBits == 5) {
176 sisInitPointers_RGB565( &srb->Base );
177 }
178 else {
179 sisInitPointers_ARGB8888( &srb->Base );
180 }
181 }
182 else if (srb->Base.InternalFormat == GL_DEPTH_COMPONENT16) {
183 sisInitDepthPointers_z16(&srb->Base);
184 }
185 else if (srb->Base.InternalFormat == GL_DEPTH_COMPONENT24) {
186 sisInitDepthPointers_z24_s8(&srb->Base);
187 }
188 else if (srb->Base.InternalFormat == GL_DEPTH_COMPONENT32) {
189 sisInitDepthPointers_z32(&srb->Base);
190 }
191 else if (srb->Base.InternalFormat == GL_STENCIL_INDEX8_EXT) {
192 sisInitStencilPointers_z24_s8(&srb->Base);
193 }
194 }