3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2003 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>
30 static void TAG(emit
)(GLcontext
*ctx
, GLuint start
, GLuint end
,
33 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
34 struct vertex_buffer
*VB
= &tnl
->vb
;
36 const GLfloat
*ndc
; /* NDC (i.e. projected clip coordinates) */
37 const GLfloat
*tc
[MAX_TEXTURE_COORD_UNITS
];
42 const GLfloat
*pointSize
;
43 GLuint tsz
[MAX_TEXTURE_COORD_UNITS
];
44 GLuint tstride
[MAX_TEXTURE_COORD_UNITS
];
45 GLuint ndc_stride
, color_stride
, spec_stride
, index_stride
;
46 GLuint fog_stride
, pointSize_stride
;
48 GLfloat
*m
= ctx
->Viewport
._WindowMap
.m
;
49 const GLfloat sx
= m
[0];
50 const GLfloat sy
= m
[5];
51 const GLfloat sz
= m
[10];
52 const GLfloat tx
= m
[12];
53 const GLfloat ty
= m
[13];
54 const GLfloat tz
= m
[14];
58 tc
[0] = (GLfloat
*)VB
->TexCoordPtr
[0]->data
;
59 tsz
[0] = VB
->TexCoordPtr
[0]->size
;
60 tstride
[0] = VB
->TexCoordPtr
[0]->stride
;
64 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
65 if (VB
->TexCoordPtr
[i
]) {
67 tc
[i
] = (GLfloat
*)VB
->TexCoordPtr
[i
]->data
;
68 tsz
[i
] = VB
->TexCoordPtr
[i
]->size
;
69 tstride
[i
] = VB
->TexCoordPtr
[i
]->stride
;
75 ndc
= VB
->NdcPtr
->data
[0];
76 ndc_stride
= VB
->NdcPtr
->stride
;
79 fog
= (GLfloat
*) VB
->FogCoordPtr
->data
;
80 fog_stride
= VB
->FogCoordPtr
->stride
;
83 color
= (GLfloat
*) VB
->ColorPtr
[0]->data
;
84 color_stride
= VB
->ColorPtr
[0]->stride
;
87 spec
= (GLfloat
*) VB
->SecondaryColorPtr
[0]->data
;
88 spec_stride
= VB
->SecondaryColorPtr
[0]->stride
;
91 index
= (GLfloat
*) VB
->IndexPtr
[0]->data
;
92 index_stride
= VB
->IndexPtr
[0]->stride
;
95 pointSize
= (GLfloat
*) VB
->PointSizePtr
->data
;
96 pointSize_stride
= VB
->PointSizePtr
->stride
;
99 v
= &(SWSETUP_CONTEXT(ctx
)->verts
[start
]);
101 for (i
=start
; i
< end
; i
++, v
++) {
102 if (VB
->ClipMask
[i
] == 0) {
103 v
->win
[0] = sx
* ndc
[0] + tx
;
104 v
->win
[1] = sy
* ndc
[1] + ty
;
105 v
->win
[2] = sz
* ndc
[2] + tz
;
108 STRIDE_F(ndc
, ndc_stride
);
111 COPY_CLEAN_4V( v
->texcoord
[0], tsz
[0], tc
[0] );
112 STRIDE_F(tc
[0], tstride
[0]);
115 if (IND
& MULTITEX
) {
117 for (u
= 0 ; u
< maxtex
; u
++)
119 COPY_CLEAN_4V( v
->texcoord
[u
], tsz
[u
], tc
[u
] );
120 STRIDE_F(tc
[u
], tstride
[u
]);
125 UNCLAMPED_FLOAT_TO_RGBA_CHAN(v
->color
, color
);
126 STRIDE_F(color
, color_stride
);
130 UNCLAMPED_FLOAT_TO_RGBA_CHAN(v
->specular
, spec
);
131 STRIDE_F(spec
, spec_stride
);
136 STRIDE_F(fog
, fog_stride
);
140 v
->index
= (GLuint
) index
[0];
141 STRIDE_F(index
, index_stride
);
145 v
->pointSize
= pointSize
[0];
146 STRIDE_F(pointSize
, pointSize_stride
);
153 static void TAG(interp
)( GLcontext
*ctx
,
155 GLuint edst
, GLuint eout
, GLuint ein
,
156 GLboolean force_boundary
)
158 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
159 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
160 GLfloat
*m
= ctx
->Viewport
._WindowMap
.m
;
161 GLfloat
*clip
= VB
->ClipPtr
->data
[edst
];
163 SWvertex
*dst
= &swsetup
->verts
[edst
];
164 SWvertex
*in
= &swsetup
->verts
[ein
];
165 SWvertex
*out
= &swsetup
->verts
[eout
];
167 /* Avoid division by zero by rearranging order of clip planes?
169 if (clip
[3] != 0.0) {
170 GLfloat oow
= 1.0F
/ clip
[3];
171 dst
->win
[0] = m
[0] * clip
[0] * oow
+ m
[12];
172 dst
->win
[1] = m
[5] * clip
[1] * oow
+ m
[13];
173 dst
->win
[2] = m
[10] * clip
[2] * oow
+ m
[14];
178 INTERP_4F( t
, dst
->texcoord
[0], out
->texcoord
[0], in
->texcoord
[0] );
181 if (IND
& MULTITEX
) {
183 GLuint maxtex
= ctx
->Const
.MaxTextureUnits
;
184 for (u
= 0 ; u
< maxtex
; u
++)
185 if (VB
->TexCoordPtr
[u
]) {
186 INTERP_4F( t
, dst
->texcoord
[u
], out
->texcoord
[u
], in
->texcoord
[u
] );
191 INTERP_CHAN( t
, dst
->color
[0], out
->color
[0], in
->color
[0] );
192 INTERP_CHAN( t
, dst
->color
[1], out
->color
[1], in
->color
[1] );
193 INTERP_CHAN( t
, dst
->color
[2], out
->color
[2], in
->color
[2] );
194 INTERP_CHAN( t
, dst
->color
[3], out
->color
[3], in
->color
[3] );
198 INTERP_CHAN( t
, dst
->specular
[0], out
->specular
[0], in
->specular
[0] );
199 INTERP_CHAN( t
, dst
->specular
[1], out
->specular
[1], in
->specular
[1] );
200 INTERP_CHAN( t
, dst
->specular
[2], out
->specular
[2], in
->specular
[2] );
204 INTERP_F( t
, dst
->fog
, out
->fog
, in
->fog
);
208 INTERP_UI( t
, dst
->index
, out
->index
, in
->index
);
211 /* XXX Point size interpolation??? */
213 INTERP_F( t
, dst
->pointSize
, out
->pointSize
, in
->pointSize
);
218 static void TAG(copy_pv
)( GLcontext
*ctx
, GLuint edst
, GLuint esrc
)
220 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
221 SWvertex
*dst
= &swsetup
->verts
[edst
];
222 SWvertex
*src
= &swsetup
->verts
[esrc
];
225 COPY_CHAN4( dst
->color
, src
->color
);
229 COPY_3V( dst
->specular
, src
->specular
);
233 dst
->index
= src
->index
;
238 static void TAG(init
)( void )
240 setup_tab
[IND
] = TAG(emit
);
241 interp_tab
[IND
] = TAG(interp
);
242 copy_pv_tab
[IND
] = TAG(copy_pv
);