blob: 7732425dd1634d0108010a28adc0884e339d93c3 [file] [log] [blame]
Keith Whitwellfabb9732003-12-21 17:54:31 +00001/*
2 * Copyright 2003 Tungsten Graphics, inc.
3 * All Rights Reserved.
4 *
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
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 * TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Keith Whitwell <keithw@tungstengraphics.com>
26 */
27
Keith Whitwell79073402004-01-05 09:43:42 +000028#include "glheader.h"
29#include "context.h"
30#include "colormac.h"
31
32#include "t_context.h"
33#include "t_vertex.h"
34
Keith Whitwell2b2bd082005-05-18 15:26:48 +000035#define DBG 0
Keith Whitwell79073402004-01-05 09:43:42 +000036
37/* Build and manage clipspace/ndc/window vertices.
Keith Whitwell79073402004-01-05 09:43:42 +000038 */
Keith Whitwellfabb9732003-12-21 17:54:31 +000039
Keith Whitwell2b2bd082005-05-18 15:26:48 +000040static GLboolean match_fastpath( struct tnl_clipspace *vtx,
41 const struct tnl_clipspace_fastpath *fp)
Keith Whitwellfabb9732003-12-21 17:54:31 +000042{
Brian Paulfde4c532004-03-13 18:27:06 +000043 GLuint j;
Keith Whitwellfabb9732003-12-21 17:54:31 +000044
Keith Whitwell2b2bd082005-05-18 15:26:48 +000045 if (vtx->attr_count != fp->attr_count)
46 return GL_FALSE;
Keith Whitwellfabb9732003-12-21 17:54:31 +000047
Keith Whitwell2b2bd082005-05-18 15:26:48 +000048 for (j = 0; j < vtx->attr_count; j++)
49 if (vtx->attr[j].format != fp->attr[j].format)
50 return GL_FALSE;
Keith Whitwella887a442005-01-10 12:30:08 +000051
Keith Whitwell2b2bd082005-05-18 15:26:48 +000052 if (fp->match_strides) {
53 if (vtx->vertex_size != fp->vertex_size)
54 return GL_FALSE;
55
56 for (j = 0; j < vtx->attr_count; j++)
57 if (vtx->attr[j].inputstride != fp->attr[j].stride)
58 return GL_FALSE;
Keith Whitwella887a442005-01-10 12:30:08 +000059 }
60
Keith Whitwell2b2bd082005-05-18 15:26:48 +000061 return GL_TRUE;
Keith Whitwellfabb9732003-12-21 17:54:31 +000062}
63
Keith Whitwell2b2bd082005-05-18 15:26:48 +000064static GLboolean search_fastpath_emit( struct tnl_clipspace *vtx )
Keith Whitwell79073402004-01-05 09:43:42 +000065{
Keith Whitwell2b2bd082005-05-18 15:26:48 +000066 struct tnl_clipspace_fastpath *fp = vtx->fastpath;
Keith Whitwell79073402004-01-05 09:43:42 +000067
Keith Whitwell2b2bd082005-05-18 15:26:48 +000068 for ( ; fp ; fp = fp->next) {
69 if (match_fastpath(vtx, fp)) {
70 vtx->emit = fp->func;
71 return GL_TRUE;
72 }
Keith Whitwell79073402004-01-05 09:43:42 +000073 }
Keith Whitwella887a442005-01-10 12:30:08 +000074
Keith Whitwell2b2bd082005-05-18 15:26:48 +000075 return GL_FALSE;
Keith Whitwell79073402004-01-05 09:43:42 +000076}
Keith Whitwellfabb9732003-12-21 17:54:31 +000077
Keith Whitwell2b2bd082005-05-18 15:26:48 +000078void _tnl_register_fastpath( struct tnl_clipspace *vtx,
79 GLboolean match_strides )
80{
81 struct tnl_clipspace_fastpath *fastpath = CALLOC_STRUCT(tnl_clipspace_fastpath);
82 GLuint i;
83
84 fastpath->vertex_size = vtx->vertex_size;
85 fastpath->attr_count = vtx->attr_count;
86 fastpath->match_strides = match_strides;
87 fastpath->func = vtx->emit;
88 fastpath->attr = MALLOC(vtx->attr_count * sizeof(fastpath->attr[0]));
89
90 for (i = 0; i < vtx->attr_count; i++) {
91 fastpath->attr[i].format = vtx->attr[i].format;
92 fastpath->attr[i].stride = vtx->attr[i].inputstride;
93 }
94
95 fastpath->next = vtx->fastpath;
96 vtx->fastpath = fastpath;
97}
Keith Whitwellfabb9732003-12-21 17:54:31 +000098
99
100
Keith Whitwellfabb9732003-12-21 17:54:31 +0000101/***********************************************************************
102 * Build codegen functions or return generic ones:
103 */
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +0000104static void choose_emit_func( GLcontext *ctx, GLuint count, GLubyte *dest)
Keith Whitwellfabb9732003-12-21 17:54:31 +0000105{
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000106 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
Keith Whitwell79073402004-01-05 09:43:42 +0000107 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Keith Whitwell009aa3e2004-06-30 11:48:21 +0000108 struct tnl_clipspace_attr *a = vtx->attr;
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +0000109 const GLuint attr_count = vtx->attr_count;
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000110 GLuint j;
111
112 for (j = 0; j < attr_count; j++) {
113 GLvector4f *vptr = VB->AttribPtr[a[j].attrib];
114 a[j].inputstride = vptr->stride;
115 a[j].inputsize = vptr->size;
116 a[j].emit = a[j].insert[vptr->size - 1]; /* not always used */
117 }
118
Keith Whitwellb97e4782005-02-10 10:57:22 +0000119 vtx->emit = NULL;
Keith Whitwell009aa3e2004-06-30 11:48:21 +0000120
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000121 /* Does this match an existing (hardwired, codegen or known-bad)
122 * fastpath?
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +0000123 */
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000124 if (search_fastpath_emit(vtx)) {
125 /* Use this result. If it is null, then it is already known
126 * that the current state will fail for codegen and there is no
127 * point trying again.
128 */
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +0000129 }
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000130 else if (vtx->codegen_emit) {
131 vtx->codegen_emit(ctx);
132 }
133
134 if (!vtx->emit) {
135 _tnl_generate_hardwired_emit(ctx);
136 }
137
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +0000138 /* Otherwise use the generic version:
139 */
Keith Whitwell009aa3e2004-06-30 11:48:21 +0000140 if (!vtx->emit)
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000141 vtx->emit = _tnl_generic_emit;
Keith Whitwell009aa3e2004-06-30 11:48:21 +0000142
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +0000143 vtx->emit( ctx, count, dest );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000144}
145
146
Keith Whitwell009aa3e2004-06-30 11:48:21 +0000147
Keith Whitwellfabb9732003-12-21 17:54:31 +0000148static void choose_interp_func( GLcontext *ctx,
149 GLfloat t,
150 GLuint edst, GLuint eout, GLuint ein,
151 GLboolean force_boundary )
152{
Keith Whitwell79073402004-01-05 09:43:42 +0000153 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
154
155 if (vtx->need_extras &&
156 (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000157 vtx->interp = _tnl_generic_interp_extras;
Keith Whitwell79073402004-01-05 09:43:42 +0000158 } else {
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000159 vtx->interp = _tnl_generic_interp;
Keith Whitwell79073402004-01-05 09:43:42 +0000160 }
161
162 vtx->interp( ctx, t, edst, eout, ein, force_boundary );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000163}
164
165
Keith Whitwell79073402004-01-05 09:43:42 +0000166static void choose_copy_pv_func( GLcontext *ctx, GLuint edst, GLuint esrc )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000167{
Keith Whitwell79073402004-01-05 09:43:42 +0000168 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
169
170 if (vtx->need_extras &&
171 (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000172 vtx->copy_pv = _tnl_generic_copy_pv_extras;
Keith Whitwell79073402004-01-05 09:43:42 +0000173 } else {
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000174 vtx->copy_pv = _tnl_generic_copy_pv;
Keith Whitwell79073402004-01-05 09:43:42 +0000175 }
176
177 vtx->copy_pv( ctx, edst, esrc );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000178}
179
180
181/***********************************************************************
182 * Public entrypoints, mostly dispatch to the above:
183 */
184
Keith Whitwellfabb9732003-12-21 17:54:31 +0000185
186/* Interpolate between two vertices to produce a third:
187 */
188void _tnl_interp( GLcontext *ctx,
189 GLfloat t,
190 GLuint edst, GLuint eout, GLuint ein,
191 GLboolean force_boundary )
192{
Keith Whitwell79073402004-01-05 09:43:42 +0000193 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
194 vtx->interp( ctx, t, edst, eout, ein, force_boundary );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000195}
196
197/* Copy colors from one vertex to another:
198 */
Keith Whitwell79073402004-01-05 09:43:42 +0000199void _tnl_copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000200{
Keith Whitwell79073402004-01-05 09:43:42 +0000201 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
202 vtx->copy_pv( ctx, edst, esrc );
Keith Whitwellfabb9732003-12-21 17:54:31 +0000203}
204
205
206/* Extract a named attribute from a hardware vertex. Will have to
207 * reverse any viewport transformation, swizzling or other conversions
208 * which may have been applied:
209 */
Keith Whitwell79073402004-01-05 09:43:42 +0000210void _tnl_get_attr( GLcontext *ctx, const void *vin,
211 GLenum attr, GLfloat *dest )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000212{
Keith Whitwell79073402004-01-05 09:43:42 +0000213 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
214 const struct tnl_clipspace_attr *a = vtx->attr;
Brian Paulfde4c532004-03-13 18:27:06 +0000215 const GLuint attr_count = vtx->attr_count;
216 GLuint j;
Keith Whitwell79073402004-01-05 09:43:42 +0000217
218 for (j = 0; j < attr_count; j++) {
Brian Paulbdd15b52004-05-04 15:11:06 +0000219 if (a[j].attrib == attr) {
Keith Whitwell44d4a8f2004-01-06 00:18:03 +0000220 a[j].extract( &a[j], dest, (GLubyte *)vin + a[j].vertoffset );
Keith Whitwell79073402004-01-05 09:43:42 +0000221 return;
222 }
223 }
224
Keith Whitwellfa136222005-01-07 15:54:48 +0000225 /* Else return the value from ctx->Current.
Keith Whitwell79073402004-01-05 09:43:42 +0000226 */
Brian Paul3663c0f2004-01-15 00:29:51 +0000227 _mesa_memcpy( dest, ctx->Current.Attrib[attr], 4*sizeof(GLfloat));
Keith Whitwell79073402004-01-05 09:43:42 +0000228}
229
Keith Whitwell47736342004-02-16 15:15:24 +0000230
231/* Complementary operation to the above.
232 */
233void _tnl_set_attr( GLcontext *ctx, void *vout,
234 GLenum attr, const GLfloat *src )
235{
236 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
237 const struct tnl_clipspace_attr *a = vtx->attr;
Brian Paulfde4c532004-03-13 18:27:06 +0000238 const GLuint attr_count = vtx->attr_count;
239 GLuint j;
Keith Whitwell47736342004-02-16 15:15:24 +0000240
241 for (j = 0; j < attr_count; j++) {
Brian Paulbdd15b52004-05-04 15:11:06 +0000242 if (a[j].attrib == attr) {
Keith Whitwell47736342004-02-16 15:15:24 +0000243 a[j].insert[4-1]( &a[j], (GLubyte *)vout + a[j].vertoffset, src );
244 return;
245 }
246 }
247}
248
249
Keith Whitwell79073402004-01-05 09:43:42 +0000250void *_tnl_get_vertex( GLcontext *ctx, GLuint nr )
251{
252 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
253
254 return vtx->vertex_buf + nr * vtx->vertex_size;
255}
256
257void _tnl_invalidate_vertex_state( GLcontext *ctx, GLuint new_state )
258{
259 if (new_state & (_DD_NEW_TRI_LIGHT_TWOSIDE|_DD_NEW_TRI_UNFILLED) ) {
260 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
261 vtx->new_inputs = ~0;
262 vtx->interp = choose_interp_func;
263 vtx->copy_pv = choose_copy_pv_func;
264 }
Keith Whitwellfabb9732003-12-21 17:54:31 +0000265}
266
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000267static void invalidate_funcs( struct tnl_clipspace *vtx )
268{
269 vtx->emit = choose_emit_func;
270 vtx->interp = choose_interp_func;
271 vtx->copy_pv = choose_copy_pv_func;
272 vtx->new_inputs = ~0;
273}
Keith Whitwellfabb9732003-12-21 17:54:31 +0000274
Keith Whitwell79073402004-01-05 09:43:42 +0000275GLuint _tnl_install_attrs( GLcontext *ctx, const struct tnl_attr_map *map,
Keith Whitwell58822572004-01-05 15:24:53 +0000276 GLuint nr, const GLfloat *vp,
277 GLuint unpacked_size )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000278{
Keith Whitwell79073402004-01-05 09:43:42 +0000279 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Brian Paulfde4c532004-03-13 18:27:06 +0000280 GLuint offset = 0;
Keith Whitwell4d36f332004-01-21 15:31:46 +0000281 GLuint i, j;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000282
Keith Whitwell79073402004-01-05 09:43:42 +0000283 assert(nr < _TNL_ATTRIB_MAX);
284 assert(nr == 0 || map[0].attrib == VERT_ATTRIB_POS);
Keith Whitwellfabb9732003-12-21 17:54:31 +0000285
Keith Whitwell79073402004-01-05 09:43:42 +0000286 vtx->new_inputs = ~0;
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000287 vtx->need_viewport = GL_FALSE;
288
289 if (vp) {
290 vtx->need_viewport = GL_TRUE;
291 vtx->vp_scale[0] = vp[MAT_SX];
292 vtx->vp_scale[1] = vp[MAT_SY];
293 vtx->vp_scale[2] = vp[MAT_SZ];
294 vtx->vp_scale[3] = 1.0;
295 vtx->vp_xlate[0] = vp[MAT_TX];
296 vtx->vp_xlate[1] = vp[MAT_TY];
297 vtx->vp_xlate[2] = vp[MAT_TZ];
298 vtx->vp_xlate[3] = 0.0;
299 }
Keith Whitwellfabb9732003-12-21 17:54:31 +0000300
Keith Whitwell4d36f332004-01-21 15:31:46 +0000301 for (j = 0, i = 0; i < nr; i++) {
Brian Paulfde4c532004-03-13 18:27:06 +0000302 const GLuint format = map[i].format;
Keith Whitwell4d36f332004-01-21 15:31:46 +0000303 if (format == EMIT_PAD) {
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000304 if (DBG)
305 _mesa_printf("%d: pad %d, offset %d\n", i,
306 map[i].offset, offset);
307
Keith Whitwell009aa3e2004-06-30 11:48:21 +0000308 offset += map[i].offset;
Keith Whitwell16f54212004-01-05 15:55:01 +0000309
Keith Whitwell4d36f332004-01-21 15:31:46 +0000310 }
311 else {
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000312 GLuint tmpoffset;
Keith Whitwell44d4a8f2004-01-06 00:18:03 +0000313
Keith Whitwell4d36f332004-01-21 15:31:46 +0000314 if (unpacked_size)
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000315 tmpoffset = map[i].offset;
Keith Whitwell4d36f332004-01-21 15:31:46 +0000316 else
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000317 tmpoffset = offset;
318
319 if (vtx->attr_count != j ||
320 vtx->attr[j].attrib != map[i].attrib ||
321 vtx->attr[j].format != format ||
322 vtx->attr[j].vertoffset != tmpoffset) {
323 invalidate_funcs(vtx);
324
325 vtx->attr[j].attrib = map[i].attrib;
326 vtx->attr[j].format = format;
327 vtx->attr[j].vp = vp;
328 vtx->attr[j].insert = _tnl_format_info[format].insert;
329 vtx->attr[j].extract = _tnl_format_info[format].extract;
330 vtx->attr[j].vertattrsize = _tnl_format_info[format].attrsize;
331 vtx->attr[j].vertoffset = tmpoffset;
332 }
333
Keith Whitwell4d36f332004-01-21 15:31:46 +0000334
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000335 if (DBG)
336 _mesa_printf("%d: %s, vp %p, offset %d\n", i,
337 _tnl_format_info[format].name, (void *)vp,
338 vtx->attr[j].vertoffset);
339
340 offset += _tnl_format_info[format].attrsize;
Keith Whitwell4d36f332004-01-21 15:31:46 +0000341 j++;
342 }
Keith Whitwellfabb9732003-12-21 17:54:31 +0000343 }
Keith Whitwell79073402004-01-05 09:43:42 +0000344
Keith Whitwell4d36f332004-01-21 15:31:46 +0000345 vtx->attr_count = j;
346
Keith Whitwell58822572004-01-05 15:24:53 +0000347 if (unpacked_size)
348 vtx->vertex_size = unpacked_size;
349 else
350 vtx->vertex_size = offset;
Keith Whitwell79073402004-01-05 09:43:42 +0000351
Keith Whitwell58822572004-01-05 15:24:53 +0000352 assert(vtx->vertex_size <= vtx->max_vertex_size);
Keith Whitwell79073402004-01-05 09:43:42 +0000353 return vtx->vertex_size;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000354}
355
356
357
Keith Whitwell79073402004-01-05 09:43:42 +0000358void _tnl_invalidate_vertices( GLcontext *ctx, GLuint newinputs )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000359{
Keith Whitwell79073402004-01-05 09:43:42 +0000360 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
361 vtx->new_inputs |= newinputs;
Keith Whitwellfabb9732003-12-21 17:54:31 +0000362}
363
364
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000365/* This event has broader use beyond this file - will move elsewhere
366 * and probably invoke a driver callback.
367 */
368void _tnl_notify_pipeline_output_change( GLcontext *ctx )
369{
370 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
371 invalidate_funcs(vtx);
372}
373
374static void update_input_ptrs( GLcontext *ctx, GLuint start )
375{
376 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
377 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
378 struct tnl_clipspace_attr *a = vtx->attr;
379 const GLuint count = vtx->attr_count;
380 GLuint j;
381
382 for (j = 0; j < count; j++) {
383 GLvector4f *vptr = VB->AttribPtr[a[j].attrib];
384
385 if (vtx->emit != choose_emit_func) {
386 assert(a[j].inputstride == vptr->stride);
387 assert(a[j].inputsize == vptr->size);
388 }
389
390 a[j].inputptr = ((GLubyte *)vptr->data) + start * vptr->stride;
391 }
392}
393
394
Keith Whitwell79073402004-01-05 09:43:42 +0000395void _tnl_build_vertices( GLcontext *ctx,
Keith Whitwell8d97ad12004-01-19 23:29:40 +0000396 GLuint start,
397 GLuint end,
398 GLuint newinputs )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000399{
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000400 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
401 update_input_ptrs( ctx, start );
402 vtx->emit( ctx, end - start,
403 (GLubyte *)(vtx->vertex_buf +
404 start * vtx->vertex_size));
Keith Whitwellfabb9732003-12-21 17:54:31 +0000405}
406
Keith Whitwellfa136222005-01-07 15:54:48 +0000407/* Emit VB vertices start..end to dest. Note that VB vertex at
408 * postion start will be emitted to dest at position zero.
409 */
Keith Whitwell79073402004-01-05 09:43:42 +0000410void *_tnl_emit_vertices_to_buffer( GLcontext *ctx,
Keith Whitwell8d97ad12004-01-19 23:29:40 +0000411 GLuint start,
412 GLuint end,
413 void *dest )
Keith Whitwellfabb9732003-12-21 17:54:31 +0000414{
Keith Whitwell79073402004-01-05 09:43:42 +0000415 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +0000416
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000417 update_input_ptrs(ctx, start);
Keith Whitwell9a8a9fb2005-01-05 12:58:14 +0000418
419 /* Note: dest should not be adjusted for non-zero 'start' values:
420 */
421 vtx->emit( ctx, end - start, dest );
Keith Whitwell8d97ad12004-01-19 23:29:40 +0000422 return (void *)((GLubyte *)dest + vtx->vertex_size * (end - start));
Keith Whitwellfabb9732003-12-21 17:54:31 +0000423}
424
Keith Whitwell79073402004-01-05 09:43:42 +0000425
426void _tnl_init_vertices( GLcontext *ctx,
427 GLuint vb_size,
428 GLuint max_vertex_size )
429{
430 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
431
Keith Whitwellb97e4782005-02-10 10:57:22 +0000432 _tnl_install_attrs( ctx, NULL, 0, NULL, 0 );
Keith Whitwell79073402004-01-05 09:43:42 +0000433
434 vtx->need_extras = GL_TRUE;
Keith Whitwell58822572004-01-05 15:24:53 +0000435 if (max_vertex_size > vtx->max_vertex_size) {
436 _tnl_free_vertices( ctx );
437 vtx->max_vertex_size = max_vertex_size;
Brian Paulcb7c6892004-01-26 16:16:16 +0000438 vtx->vertex_buf = (GLubyte *)ALIGN_CALLOC(vb_size * max_vertex_size, 32 );
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000439 invalidate_funcs(vtx);
Keith Whitwell58822572004-01-05 15:24:53 +0000440 }
Keith Whitwell009aa3e2004-06-30 11:48:21 +0000441
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000442 switch(CHAN_TYPE) {
443 case GL_UNSIGNED_BYTE:
444 vtx->chan_scale[0] = 255.0;
445 vtx->chan_scale[1] = 255.0;
446 vtx->chan_scale[2] = 255.0;
447 vtx->chan_scale[3] = 255.0;
448 break;
449 case GL_UNSIGNED_SHORT:
450 vtx->chan_scale[0] = 65535.0;
451 vtx->chan_scale[1] = 65535.0;
452 vtx->chan_scale[2] = 65535.0;
453 vtx->chan_scale[3] = 65535.0;
454 break;
455 default:
456 vtx->chan_scale[0] = 1.0;
457 vtx->chan_scale[1] = 1.0;
458 vtx->chan_scale[2] = 1.0;
459 vtx->chan_scale[3] = 1.0;
460 break;
461 }
462
463 vtx->identity[0] = 0.0;
464 vtx->identity[1] = 0.0;
465 vtx->identity[2] = 0.0;
466 vtx->identity[3] = 1.0;
467
468 vtx->codegen_emit = NULL;
469
470#ifdef __i386__
471 if (getenv("MESA_EXPERIMENTAL"))
472 vtx->codegen_emit = _tnl_generate_sse_emit;
473#endif
Keith Whitwell79073402004-01-05 09:43:42 +0000474}
475
476
477void _tnl_free_vertices( GLcontext *ctx )
478{
479 struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000480 struct tnl_clipspace_fastpath *fp, *tmp;
481
Keith Whitwell79073402004-01-05 09:43:42 +0000482 if (vtx->vertex_buf) {
483 ALIGN_FREE(vtx->vertex_buf);
Keith Whitwellb97e4782005-02-10 10:57:22 +0000484 vtx->vertex_buf = NULL;
Keith Whitwell79073402004-01-05 09:43:42 +0000485 }
Keith Whitwell0aca0862005-01-12 19:38:41 +0000486
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000487 for (fp = vtx->fastpath ; fp ; fp = tmp) {
488 tmp = fp->next;
489 FREE(fp->attr);
490 FREE((void *)fp->func);
491 FREE(fp);
492 }
493
494 vtx->fastpath = NULL;
Keith Whitwell79073402004-01-05 09:43:42 +0000495}