3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Keith Whitwell <keith@tungstengraphics.com>
28 #include "math/m_translate.h"
30 #if (HAVE_HW_VIEWPORT)
31 #define UNVIEWPORT_VARS
32 #define UNVIEWPORT_X(x) x
33 #define UNVIEWPORT_Y(x) x
34 #define UNVIEWPORT_Z(x) x
41 #ifndef CHECK_HW_DIVIDE
42 #define CHECK_HW_DIVIDE 1
45 /* These don't need to be duplicated, but there's currently nowhere
46 * really convenient to put them. Need to build some actual .o files in
49 static void copy_pv_rgba4_spec5( GLcontext
*ctx
, GLuint edst
, GLuint esrc
)
52 GLubyte
*verts
= GET_VERTEX_STORE();
53 GLuint size
= GET_VERTEX_SIZE();
54 GLuint
*dst
= (GLuint
*)(verts
+ (edst
* size
));
55 GLuint
*src
= (GLuint
*)(verts
+ (esrc
* size
));
60 static void copy_pv_rgba4( GLcontext
*ctx
, GLuint edst
, GLuint esrc
)
63 GLubyte
*verts
= GET_VERTEX_STORE();
64 GLuint size
= GET_VERTEX_SIZE();
65 GLuint
*dst
= (GLuint
*)(verts
+ (edst
* size
));
66 GLuint
*src
= (GLuint
*)(verts
+ (esrc
* size
));
70 static void copy_pv_rgba3( GLcontext
*ctx
, GLuint edst
, GLuint esrc
)
73 GLubyte
*verts
= GET_VERTEX_STORE();
74 GLuint size
= GET_VERTEX_SIZE();
75 GLuint
*dst
= (GLuint
*)(verts
+ (edst
* size
));
76 GLuint
*src
= (GLuint
*)(verts
+ (esrc
* size
));
81 void TAG(translate_vertex
)(GLcontext
*ctx
,
86 GLuint format
= GET_VERTEX_FORMAT();
87 GLfloat
*s
= ctx
->Viewport
._WindowMap
.m
;
90 if (format
== TINY_VERTEX_FORMAT
) {
91 if (HAVE_HW_VIEWPORT
) {
92 dst
->attrib
[FRAG_ATTRIB_WPOS
][0] = s
[0] * src
->v
.x
+ s
[12];
93 dst
->attrib
[FRAG_ATTRIB_WPOS
][1] = s
[5] * src
->v
.y
+ s
[13];
94 dst
->attrib
[FRAG_ATTRIB_WPOS
][2] = s
[10] * src
->v
.z
+ s
[14];
95 dst
->attrib
[FRAG_ATTRIB_WPOS
][3] = 1.0;
97 dst
->attrib
[FRAG_ATTRIB_WPOS
][0] = UNVIEWPORT_X( src
->v
.x
);
98 dst
->attrib
[FRAG_ATTRIB_WPOS
][1] = UNVIEWPORT_Y( src
->v
.y
);
99 dst
->attrib
[FRAG_ATTRIB_WPOS
][2] = UNVIEWPORT_Z( src
->v
.z
);
100 dst
->attrib
[FRAG_ATTRIB_WPOS
][3] = 1.0;
103 dst
->color
[0] = src
->tv
.color
.red
;
104 dst
->color
[1] = src
->tv
.color
.green
;
105 dst
->color
[2] = src
->tv
.color
.blue
;
106 dst
->color
[3] = src
->tv
.color
.alpha
;
109 if (HAVE_HW_VIEWPORT
) {
110 if (HAVE_HW_DIVIDE
&& CHECK_HW_DIVIDE
) {
111 GLfloat oow
= 1.0 / src
->v
.w
;
112 dst
->attrib
[FRAG_ATTRIB_WPOS
][0] = s
[0] * src
->v
.x
* oow
+ s
[12];
113 dst
->attrib
[FRAG_ATTRIB_WPOS
][1] = s
[5] * src
->v
.y
* oow
+ s
[13];
114 dst
->attrib
[FRAG_ATTRIB_WPOS
][2] = s
[10] * src
->v
.z
* oow
+ s
[14];
115 dst
->attrib
[FRAG_ATTRIB_WPOS
][3] = oow
;
117 dst
->attrib
[FRAG_ATTRIB_WPOS
][0] = s
[0] * src
->v
.x
+ s
[12];
118 dst
->attrib
[FRAG_ATTRIB_WPOS
][1] = s
[5] * src
->v
.y
+ s
[13];
119 dst
->attrib
[FRAG_ATTRIB_WPOS
][2] = s
[10] * src
->v
.z
+ s
[14];
120 dst
->attrib
[FRAG_ATTRIB_WPOS
][3] = src
->v
.w
;
123 dst
->attrib
[FRAG_ATTRIB_WPOS
][0] = UNVIEWPORT_X( src
->v
.x
);
124 dst
->attrib
[FRAG_ATTRIB_WPOS
][1] = UNVIEWPORT_Y( src
->v
.y
);
125 dst
->attrib
[FRAG_ATTRIB_WPOS
][2] = UNVIEWPORT_Z( src
->v
.z
);
126 dst
->attrib
[FRAG_ATTRIB_WPOS
][3] = src
->v
.w
;
129 dst
->color
[0] = src
->v
.color
.red
;
130 dst
->color
[1] = src
->v
.color
.green
;
131 dst
->color
[2] = src
->v
.color
.blue
;
132 dst
->color
[3] = src
->v
.color
.alpha
;
134 dst
->attrib
[FRAG_ATTRIB_COL1
][0] = UBYTE_TO_FLOAT(src
->v
.specular
.red
);
135 dst
->attrib
[FRAG_ATTRIB_COL1
][1] = UBYTE_TO_FLOAT(src
->v
.specular
.green
);
136 dst
->attrib
[FRAG_ATTRIB_COL1
][2] = UBYTE_TO_FLOAT(src
->v
.specular
.blue
);
138 dst
->attrib
[FRAG_ATTRIB_FOGC
][0] = UBYTE_TO_FLOAT(src
->v
.specular
.alpha
);
140 if (HAVE_PTEX_VERTICES
&&
141 ((HAVE_TEX2_VERTICES
&& format
== PROJ_TEX3_VERTEX_FORMAT
) ||
142 (format
== PROJ_TEX1_VERTEX_FORMAT
))) {
144 dst
->attrib
[FRAG_ATTRIB_TEX0
][0] = src
->pv
.u0
;
145 dst
->attrib
[FRAG_ATTRIB_TEX0
][1] = src
->pv
.v0
;
146 dst
->attrib
[FRAG_ATTRIB_TEX0
][3] = src
->pv
.q0
;
148 dst
->attrib
[FRAG_ATTRIB_TEX1
][0] = src
->pv
.u1
;
149 dst
->attrib
[FRAG_ATTRIB_TEX1
][1] = src
->pv
.v1
;
150 dst
->attrib
[FRAG_ATTRIB_TEX1
][3] = src
->pv
.q1
;
152 if (HAVE_TEX2_VERTICES
) {
153 dst
->attrib
[FRAG_ATTRIB_TEX2
][0] = src
->pv
.u2
;
154 dst
->attrib
[FRAG_ATTRIB_TEX2
][1] = src
->pv
.v2
;
155 dst
->attrib
[FRAG_ATTRIB_TEX2
][3] = src
->pv
.q2
;
158 if (HAVE_TEX3_VERTICES
) {
159 dst
->attrib
[FRAG_ATTRIB_TEX3
][0] = src
->pv
.u3
;
160 dst
->attrib
[FRAG_ATTRIB_TEX3
][1] = src
->pv
.v3
;
161 dst
->attrib
[FRAG_ATTRIB_TEX3
][3] = src
->pv
.q3
;
165 dst
->attrib
[FRAG_ATTRIB_TEX0
][0] = src
->v
.u0
;
166 dst
->attrib
[FRAG_ATTRIB_TEX0
][1] = src
->v
.v0
;
167 dst
->attrib
[FRAG_ATTRIB_TEX0
][3] = 1.0;
169 dst
->attrib
[FRAG_ATTRIB_TEX1
][0] = src
->v
.u1
;
170 dst
->attrib
[FRAG_ATTRIB_TEX1
][1] = src
->v
.v1
;
171 dst
->attrib
[FRAG_ATTRIB_TEX1
][3] = 1.0;
173 if (HAVE_TEX2_VERTICES
) {
174 dst
->attrib
[FRAG_ATTRIB_TEX2
][0] = src
->v
.u2
;
175 dst
->attrib
[FRAG_ATTRIB_TEX2
][1] = src
->v
.v2
;
176 dst
->attrib
[FRAG_ATTRIB_TEX2
][3] = 1.0;
179 if (HAVE_TEX3_VERTICES
) {
180 dst
->attrib
[FRAG_ATTRIB_TEX3
][0] = src
->v
.u3
;
181 dst
->attrib
[FRAG_ATTRIB_TEX3
][1] = src
->v
.v3
;
182 dst
->attrib
[FRAG_ATTRIB_TEX3
][3] = 1.0;
187 dst
->pointSize
= ctx
->Point
.Size
;
191 /* prototype to silence warning */
192 void TAG(print_vertex
)( GLcontext
*ctx
, const VERTEX
*v
);
195 void TAG(print_vertex
)( GLcontext
*ctx
, const VERTEX
*v
)
198 GLuint format
= GET_VERTEX_FORMAT();
200 fprintf(stderr
, "(%x) ", format
);
203 #if HAVE_TINY_VERTICES
204 case TINY_VERTEX_FORMAT
:
205 fprintf(stderr
, "xyz %.4f,%.4f,%.4f rgba %x:%x:%x:%x\n",
206 v
->v
.x
, v
->v
.y
, v
->v
.z
,
213 #if HAVE_NOTEX_VERTICES
214 case NOTEX_VERTEX_FORMAT
:
215 fprintf(stderr
, "xyzw %.4f,%.4f,%.4f,%.4f rgba %x:%x:%x:%x spec %x:%x:%x:%x\n",
216 v
->v
.x
, v
->v
.y
, v
->v
.z
, v
->v
.w
,
224 v
->v
.specular
.alpha
);
227 #if HAVE_TEX0_VERTICES
228 case TEX0_VERTEX_FORMAT
:
229 fprintf(stderr
, "xyzw %.4f,%.4f,%.4f,%.4f rgba %x:%x:%x:%x st %.4f,%.4f\n",
230 v
->v
.x
, v
->v
.y
, v
->v
.z
, v
->v
.w
,
239 #if HAVE_TEX1_VERTICES
240 case TEX1_VERTEX_FORMAT
:
241 fprintf(stderr
, "xyzw %.4f,%.4f,%.4f,%.4f rgba %x:%x:%x:%x st %.4f,%.4f st %.4f,%.4f\n",
242 v
->v
.x
, v
->v
.y
, v
->v
.z
, v
->v
.w
,
253 #if HAVE_PTEX_VERTICES
254 case PROJ_TEX1_VERTEX_FORMAT
:
255 fprintf(stderr
, "xyzw %.4f,%.4f,%.4f,%.4f rgba %x:%x:%x:%x stq %.4f,%.4f,%.4f stq %.4f,%.4f,%.4f\n",
256 v
->v
.x
, v
->v
.y
, v
->v
.z
, v
->v
.w
,
270 fprintf(stderr
, "???\n");
274 fprintf(stderr
, "\n");
279 /* Interpolate the elements of the VB not included in typical hardware
282 * NOTE: All these arrays are guarenteed by tnl to be writeable and
285 #ifndef INTERP_QUALIFIER
286 #define INTERP_QUALIFIER static
289 #define GET_COLOR(ptr, idx) ((ptr)->data[idx])
292 INTERP_QUALIFIER
void TAG(interp_extras
)( GLcontext
*ctx
,
294 GLuint dst
, GLuint out
, GLuint in
,
295 GLboolean force_boundary
)
298 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
300 if (VB
->BackfaceColorPtr
) {
301 assert(VB
->BackfaceColorPtr
->stride
== 4 * sizeof(GLfloat
));
304 GET_COLOR(VB
->BackfaceColorPtr
, dst
),
305 GET_COLOR(VB
->BackfaceColorPtr
, out
),
306 GET_COLOR(VB
->BackfaceColorPtr
, in
) );
308 if (VB
->BackfaceSecondaryColorPtr
) {
310 GET_COLOR(VB
->BackfaceSecondaryColorPtr
, dst
),
311 GET_COLOR(VB
->BackfaceSecondaryColorPtr
, out
),
312 GET_COLOR(VB
->BackfaceSecondaryColorPtr
, in
) );
317 VB
->EdgeFlag
[dst
] = VB
->EdgeFlag
[out
] || force_boundary
;
320 INTERP_VERTEX(ctx
, t
, dst
, out
, in
, force_boundary
);
323 INTERP_QUALIFIER
void TAG(copy_pv_extras
)( GLcontext
*ctx
,
324 GLuint dst
, GLuint src
)
327 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
329 if (VB
->BackfaceColorPtr
) {
330 COPY_4FV( GET_COLOR(VB
->BackfaceColorPtr
, dst
),
331 GET_COLOR(VB
->BackfaceColorPtr
, src
) );
333 if (VB
->BackfaceSecondaryColorPtr
) {
334 COPY_4FV( GET_COLOR(VB
->BackfaceSecondaryColorPtr
, dst
),
335 GET_COLOR(VB
->BackfaceSecondaryColorPtr
, src
) );
339 COPY_PV_VERTEX(ctx
, dst
, src
);
343 #undef INTERP_QUALIFIER