1 /* $XFree86*/ /* -*- c-basic-offset: 3 -*- */
3 * Copyright 2005 Eric Anholt
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * Eric Anholt <anholt@FreeBSD.org>
27 * Jim Duchek <jim@linuxpimps.com> -- Utah GLX 6326 code
28 * Alan Cox <alan@redhat.com> -- 6326 Debugging
32 static void TAG(sis_draw_tri_mmio
)(sisContextPtr smesa
, char *verts
)
34 sisVertexPtr v0
= (sisVertexPtr
)verts
;
35 sisVertexPtr v1
= (sisVertexPtr
)(verts
+ smesa
->vertex_size
* 4);
36 sisVertexPtr v2
= (sisVertexPtr
)(verts
+ smesa
->vertex_size
* 4 * 2);
38 mWait3DCmdQueue (MMIO_VERT_REG_COUNT
* 3);
39 SIS_MMIO_WRITE_VERTEX(v0
, 0, 0);
40 SIS_MMIO_WRITE_VERTEX(v1
, 1, 0);
41 SIS_MMIO_WRITE_VERTEX(v2
, 2, 1);
44 static void TAG(sis_draw_line_mmio
)(sisContextPtr smesa
, char *verts
)
46 sisVertexPtr v0
= (sisVertexPtr
)verts
;
47 sisVertexPtr v1
= (sisVertexPtr
)(verts
+ smesa
->vertex_size
* 4);
49 mWait3DCmdQueue (MMIO_VERT_REG_COUNT
* 2);
50 SIS_MMIO_WRITE_VERTEX(v0
, 0, 0);
51 SIS_MMIO_WRITE_VERTEX(v1
, 1, 1);
54 static void TAG(sis_draw_point_mmio
)(sisContextPtr smesa
, char *verts
)
56 sisVertexPtr v0
= (sisVertexPtr
)verts
;
58 mWait3DCmdQueue (MMIO_VERT_REG_COUNT
* 1);
59 SIS_MMIO_WRITE_VERTEX(v0
, 1, 1);
62 #if !(SIS_STATES & VERT_UV1)
63 static void TAG(sis6326_draw_tri_mmio
)(sisContextPtr smesa
, char *verts
)
65 sisVertexPtr v0
= (sisVertexPtr
)verts
;
66 sisVertexPtr v1
= (sisVertexPtr
)(verts
+ smesa
->vertex_size
* 4);
67 sisVertexPtr v2
= (sisVertexPtr
)(verts
+ smesa
->vertex_size
* 4 * 2);
70 GLfloat delt02
, diffx02
, diffy02
, diffy12
;
71 GLint dwPrimitiveSet
= smesa
->dwPrimitiveSet
;
72 sisVertex tv0
, tv1
, tv2
;
79 tv0
.v
.y
= Y_FLIP(tv0
.v
.y
);
80 tv1
.v
.y
= Y_FLIP(tv1
.v
.y
);
81 tv2
.v
.y
= Y_FLIP(tv2
.v
.y
);
86 /* Cull polygons we won't draw. The hardware draws funky things if it
88 if((((v1
->v
.x
- v0
->v
.x
) * (v0
->v
.y
- v2
->v
.y
)) +
89 ((v1
->v
.y
- v0
->v
.y
) * (v2
->v
.x
- v0
->v
.x
))) < 0)
101 dwPrimitiveSet
|= OP_6326_3D_ATOP
| OP_6326_3D_BMID
| OP_6326_3D_CBOT
;
102 if ((SIS_STATES
& VERT_SMOOTH
) == 0)
103 dwPrimitiveSet
|= OP_6326_3D_SHADE_FLAT_BOT
;
109 dwPrimitiveSet
|= OP_6326_3D_ATOP
| OP_6326_3D_CMID
|
111 if ((SIS_STATES
& VERT_SMOOTH
) == 0)
112 dwPrimitiveSet
|= OP_6326_3D_SHADE_FLAT_MID
;
118 dwPrimitiveSet
|= OP_6326_3D_CTOP
| OP_6326_3D_AMID
|
120 if ((SIS_STATES
& VERT_SMOOTH
) == 0)
121 dwPrimitiveSet
|= OP_6326_3D_SHADE_FLAT_TOP
;
133 dwPrimitiveSet
|= OP_6326_3D_BTOP
| OP_6326_3D_AMID
| OP_6326_3D_CBOT
;
134 if ((SIS_STATES
& VERT_SMOOTH
) == 0)
135 dwPrimitiveSet
|= OP_6326_3D_SHADE_FLAT_BOT
;
142 dwPrimitiveSet
|= OP_6326_3D_BTOP
| OP_6326_3D_CMID
|
144 if ((SIS_STATES
& VERT_SMOOTH
) == 0)
145 dwPrimitiveSet
|= OP_6326_3D_SHADE_FLAT_MID
;
150 dwPrimitiveSet
|= OP_6326_3D_CTOP
| OP_6326_3D_BMID
|
152 if ((SIS_STATES
& VERT_SMOOTH
) == 0)
153 dwPrimitiveSet
|= OP_6326_3D_SHADE_FLAT_TOP
;
160 if (x1
<= x0
&& x1
<= x2
) {
161 dwPrimitiveSet
|= OP_3D_DIRECTION_LEFT
;
162 } else if (x1
< x0
|| x1
< x2
) {
169 delt02
= diffx02
/ diffy02
;
170 tmp
= x1
- (diffy12
* delt02
+ x2
);
173 dwPrimitiveSet
|= OP_3D_DIRECTION_LEFT
;
179 tv0
.v
.y
= Y_FLIP(tv0
.v
.y
);
180 tv1
.v
.y
= Y_FLIP(tv1
.v
.y
);
181 tv2
.v
.y
= Y_FLIP(tv2
.v
.y
);
190 /* fprintf(stderr, "Vertex0 %f %f %f\n", v0->v.x, v0->v.y, v0->v.z);
191 fprintf(stderr, "Vertex1 %f %f %f\n", v1->v.x, v1->v.y, v1->v.z);
192 fprintf(stderr, "Vertex2 %f %f %f\n", v2->v.x, v2->v.y, v2->v.z);*/
193 mWait3DCmdQueue(MMIO_VERT_REG_COUNT
* 3 + 1);
194 MMIO(REG_3D_PrimitiveSet
, dwPrimitiveSet
);
195 SIS_MMIO_WRITE_VERTEX(v0
, 0, 0);
196 SIS_MMIO_WRITE_VERTEX(v1
, 1, 0);
197 SIS_MMIO_WRITE_VERTEX(v2
, 2, 1);
201 static void TAG(sis6326_draw_line_mmio
)(sisContextPtr smesa
, char *verts
)
203 sisVertexPtr v0
= (sisVertexPtr
)verts
;
204 sisVertexPtr v1
= (sisVertexPtr
)(verts
+ smesa
->vertex_size
* 4);
205 GLint dwPrimitiveSet
= smesa
->dwPrimitiveSet
;
207 if (abs(v0
->v
.y
- v1
->v
.y
) > abs(v0
->v
.x
- v1
->v
.x
))
209 dwPrimitiveSet
|= OP_3D_DIRECTION_VERTICAL
;
210 if (v0
->v
.y
> v1
->v
.y
)
211 dwPrimitiveSet
|= OP_6326_3D_ATOP
| OP_6326_3D_BBOT
;
213 dwPrimitiveSet
|= OP_6326_3D_BTOP
| OP_6326_3D_ABOT
;
215 if (v0
->v
.y
> v1
->v
.y
)
216 dwPrimitiveSet
|= OP_6326_3D_BTOP
| OP_6326_3D_ABOT
;
218 dwPrimitiveSet
|= OP_6326_3D_ATOP
| OP_6326_3D_BBOT
;
221 mWait3DCmdQueue (MMIO_VERT_REG_COUNT
* 2 + 1);
222 MMIO(REG_3D_PrimitiveSet
, dwPrimitiveSet
);
223 SIS_MMIO_WRITE_VERTEX(v0
, 0, 0);
224 SIS_MMIO_WRITE_VERTEX(v1
, 1, 1);
227 static void TAG(sis6326_draw_point_mmio
)(sisContextPtr smesa
, char *verts
)
229 sisVertexPtr v0
= (sisVertexPtr
)verts
;
231 mWait3DCmdQueue (MMIO_VERT_REG_COUNT
* 1 + 1);
232 MMIO(REG_3D_PrimitiveSet
, smesa
->dwPrimitiveSet
| OP_6326_3D_ATOP
);
233 SIS_MMIO_WRITE_VERTEX(v0
, 1, 1);
237 static INLINE
void TAG(sis_vert_init
)( void )
239 sis_tri_func_mmio
[SIS_STATES
] = TAG(sis_draw_tri_mmio
);
240 sis_line_func_mmio
[SIS_STATES
] = TAG(sis_draw_line_mmio
);
241 sis_point_func_mmio
[SIS_STATES
] = TAG(sis_draw_point_mmio
);
242 #if !(SIS_STATES & VERT_UV1)
243 sis_tri_func_mmio
[SIS_STATES
| VERT_6326
] = TAG(sis6326_draw_tri_mmio
);
244 sis_line_func_mmio
[SIS_STATES
| VERT_6326
] = TAG(sis6326_draw_line_mmio
);
245 sis_point_func_mmio
[SIS_STATES
| VERT_6326
] = TAG(sis6326_draw_point_mmio
);