1 /* $Id: t_vb_program.c,v 1.5 2001/12/18 04:06:46 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * -------- Regarding NV_vertex_program --------
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions are met:
32 * o Redistribution of the source code must contain a copyright notice
33 * and this list of conditions;
35 * o Redistribution in binary and source code form must contain the
36 * following Notice in the software and any documentation and/or other
37 * materials provided with the distribution; and
39 * o The name of Nvidia may not be used to promote or endorse software
40 * derived from the software.
42 * NOTICE: Nvidia hereby grants to each recipient a non-exclusive worldwide
43 * royalty free patent license under patent claims that are licensable by
44 * Nvidia and which are necessarily required and for which no commercially
45 * viable non infringing alternative exists to make, use, sell, offer to sell,
46 * import and otherwise transfer the vertex extension for the Mesa 3D Graphics
47 * Library as distributed in source code and object code form. No hardware or
48 * hardware implementation (including a semiconductor implementation and chips)
49 * are licensed hereunder. If a recipient makes a patent claim or institutes
50 * patent litigation against Nvidia or Nvidia's customers for use or sale of
51 * Nvidia products, then this license grant as to such recipient shall
52 * immediately terminate and recipient immediately agrees to cease use and
53 * distribution of the Mesa Program and derivatives thereof.
55 * THE MESA 3D GRAPHICS LIBRARY IS PROVIDED ON AN "AS IS BASIS, WITHOUT
56 * WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING,
57 * WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-NFRINGEMENT
58 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
60 * NVIDIA SHALL NOT HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
61 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
62 * LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
63 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
64 * ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE MESA 3D GRAPHICS
65 * LIBRARY OR EVIDENCE OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDR, EVEN
66 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 * If you do not comply with this agreement, then Nvidia may cancel the license
69 * and rights granted herein.
70 * ---------------------------------------------
89 #include "simple_list.h"
93 #include "math/m_translate.h"
95 #include "t_context.h"
96 #include "t_pipeline.h"
97 #include "t_imm_api.h"
98 #include "t_imm_exec.h"
103 _vp_ArrayElement( GLint i
)
109 _vp_Color3f( GLfloat r
, GLfloat g
, GLfloat b
)
112 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_COLOR0
][IM
->Count
];
113 ASSIGN_4V(attrib
, r
, g
, b
, 1.0F
);
114 IM
->Flag
[IM
->Count
] |= VERT_COLOR0_BIT
;
118 _vp_Color3fv( const GLfloat
*color
)
121 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_COLOR0
][IM
->Count
];
122 ASSIGN_4V(attrib
, color
[0], color
[1], color
[2], 1.0F
);
123 IM
->Flag
[IM
->Count
] |= VERT_COLOR0_BIT
;
127 _vp_Color3ub( GLubyte r
, GLubyte g
, GLubyte b
)
130 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_COLOR0
][IM
->Count
];
131 attrib
[0] = UBYTE_TO_FLOAT(r
);
132 attrib
[1] = UBYTE_TO_FLOAT(g
);
133 attrib
[2] = UBYTE_TO_FLOAT(b
);
135 IM
->Flag
[IM
->Count
] |= VERT_COLOR0_BIT
;
139 _vp_Color3ubv( const GLubyte
*color
)
142 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_COLOR0
][IM
->Count
];
143 attrib
[0] = UBYTE_TO_FLOAT(color
[0]);
144 attrib
[1] = UBYTE_TO_FLOAT(color
[1]);
145 attrib
[2] = UBYTE_TO_FLOAT(color
[2]);
147 IM
->Flag
[IM
->Count
] |= VERT_COLOR0_BIT
;
151 _vp_Color4f( GLfloat r
, GLfloat g
, GLfloat b
, GLfloat a
)
154 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_COLOR0
][IM
->Count
];
155 ASSIGN_4V(attrib
, r
, g
, b
, a
);
156 IM
->Flag
[IM
->Count
] |= VERT_COLOR0_BIT
;
160 _vp_Color4fv( const GLfloat
*color
)
163 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_COLOR0
][IM
->Count
];
164 COPY_4V(attrib
, color
);
165 IM
->Flag
[IM
->Count
] |= VERT_COLOR0_BIT
;
169 _vp_Color4ub( GLubyte r
, GLubyte g
, GLubyte b
, GLubyte a
)
172 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_COLOR0
][IM
->Count
];
173 attrib
[0] = UBYTE_TO_FLOAT(r
);
174 attrib
[1] = UBYTE_TO_FLOAT(g
);
175 attrib
[2] = UBYTE_TO_FLOAT(b
);
176 attrib
[3] = UBYTE_TO_FLOAT(a
);
177 IM
->Flag
[IM
->Count
] |= VERT_COLOR0_BIT
;
181 _vp_Color4ubv( const GLubyte
*color
)
184 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_COLOR0
][IM
->Count
];
185 attrib
[0] = UBYTE_TO_FLOAT(color
[0]);
186 attrib
[1] = UBYTE_TO_FLOAT(color
[1]);
187 attrib
[2] = UBYTE_TO_FLOAT(color
[2]);
188 attrib
[3] = UBYTE_TO_FLOAT(color
[3]);
189 IM
->Flag
[IM
->Count
] |= VERT_COLOR0_BIT
;
193 _vp_EdgeFlag( GLboolean flag
)
196 IM
->EdgeFlag
[IM
->Count
] = flag
;
197 IM
->Flag
[IM
->Count
] |= VERT_EDGEFLAG_BIT
;
201 _vp_EdgeFlagv( const GLboolean
*flag
)
204 IM
->EdgeFlag
[IM
->Count
] = *flag
;
205 IM
->Flag
[IM
->Count
] |= VERT_EDGEFLAG_BIT
;
209 _vp_EvalCoord1f( GLfloat s
)
216 _vp_EvalCoord1fv( const GLfloat
*v
)
223 _vp_EvalCoord2f( GLfloat s
, GLfloat t
)
231 _vp_EvalCoord2fv( const GLfloat
*v
)
238 _vp_EvalPoint1( GLint i
)
244 _vp_EvalPoint2( GLint i
, GLint j
)
251 _vp_FogCoordf( GLfloat f
)
254 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_FOG
][IM
->Count
];
255 ASSIGN_4V(attrib
, f
, 0.0F
, 0.0F
, 1.0F
);
256 IM
->Flag
[IM
->Count
] |= VERT_FOG_BIT
;
260 _vp_FogCoordfv( const GLfloat
*f
)
263 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_FOG
][IM
->Count
];
264 ASSIGN_4V(attrib
, f
[0], 0.0F
, 0.0F
, 1.0F
);
265 IM
->Flag
[IM
->Count
] |= VERT_FOG_BIT
;
269 _vp_Indexi( GLint i
)
275 _vp_Indexiv( const GLint
*i
)
281 _vp_Materialfv( GLenum face
, GLenum pname
, const GLfloat
*v
)
287 _vp_MultiTexCoord1f( GLenum unit
, GLfloat s
)
289 const GLint u
= (GLint
) unit
- GL_TEXTURE0_ARB
;
290 if (u
>=0 && u
< 8) {
292 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_TEX0
+ u
][IM
->Count
];
293 ASSIGN_4V(attrib
, s
, 0.0F
, 0.0F
, 1.0F
);
294 IM
->Flag
[IM
->Count
] |= (VERT_TEX0_BIT
<< u
);
299 _vp_MultiTexCoord1fv( GLenum unit
, const GLfloat
*c
)
301 const GLint u
= unit
- GL_TEXTURE0_ARB
;
302 if (u
>=0 && u
< 8) {
304 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_TEX0
+ u
][IM
->Count
];
305 ASSIGN_4V(attrib
, c
[0], 0.0F
, 0.0F
, 1.0F
);
306 IM
->Flag
[IM
->Count
] |= (VERT_TEX0_BIT
<< u
);
311 _vp_MultiTexCoord2f( GLenum unit
, GLfloat s
, GLfloat t
)
313 const GLint u
= unit
- GL_TEXTURE0_ARB
;
314 if (u
>=0 && u
< 8) {
316 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_TEX0
+ u
][IM
->Count
];
317 ASSIGN_4V(attrib
, s
, t
, 0.0F
, 1.0F
);
318 IM
->Flag
[IM
->Count
] |= (VERT_TEX0_BIT
<< u
);
323 _vp_MultiTexCoord2fv( GLenum unit
, const GLfloat
*c
)
325 const GLint u
= unit
- GL_TEXTURE0_ARB
;
326 if (u
>=0 && u
< 8) {
328 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_TEX0
+ u
][IM
->Count
];
329 ASSIGN_4V(attrib
, c
[0], c
[1], 0.0F
, 1.0F
);
330 IM
->Flag
[IM
->Count
] |= (VERT_TEX0_BIT
<< u
);
335 _vp_MultiTexCoord3f( GLenum unit
, GLfloat s
, GLfloat t
, GLfloat r
)
337 const GLint u
= unit
- GL_TEXTURE0_ARB
;
338 if (u
>=0 && u
< 8) {
340 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_TEX0
+ u
][IM
->Count
];
341 ASSIGN_4V(attrib
, s
, t
, r
, 1.0F
);
342 IM
->Flag
[IM
->Count
] |= (VERT_TEX0_BIT
<< u
);
347 _vp_MultiTexCoord3fv( GLenum unit
, const GLfloat
*c
)
349 const GLint u
= unit
- GL_TEXTURE0_ARB
;
350 if (u
>=0 && u
< 8) {
352 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_TEX0
+ u
][IM
->Count
];
353 ASSIGN_4V(attrib
, c
[0], c
[1], c
[2], 1.0F
);
354 IM
->Flag
[IM
->Count
] |= (VERT_TEX0_BIT
<< u
);
359 _vp_MultiTexCoord4f( GLenum unit
, GLfloat s
, GLfloat t
, GLfloat r
, GLfloat q
)
361 const GLint u
= unit
- GL_TEXTURE0_ARB
;
362 if (u
>=0 && u
< 8) {
364 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_TEX0
+ u
][IM
->Count
];
365 ASSIGN_4V(attrib
, s
, t
, r
, q
);
366 IM
->Flag
[IM
->Count
] |= (VERT_TEX0_BIT
<< u
);
371 _vp_MultiTexCoord4fv( GLenum unit
, const GLfloat
*c
)
373 const GLint u
= unit
- GL_TEXTURE0_ARB
;
374 if (u
>=0 && u
< 8) {
376 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_TEX0
+ u
][IM
->Count
];
378 IM
->Flag
[IM
->Count
] |= (VERT_TEX0_BIT
<< u
);
383 _vp_Normal3f( GLfloat x
, GLfloat y
, GLfloat z
)
386 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_NORMAL
][IM
->Count
];
387 ASSIGN_4V(attrib
, x
, y
, z
, 1.0F
);
388 IM
->Flag
[IM
->Count
] |= VERT_NORMAL_BIT
;
392 _vp_Normal3fv( const GLfloat
*n
)
395 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_NORMAL
][IM
->Count
];
396 ASSIGN_4V(attrib
, n
[0], n
[1], n
[2], 1.0F
);
397 IM
->Flag
[IM
->Count
] |= VERT_NORMAL_BIT
;
401 _vp_SecondaryColor3f( GLfloat r
, GLfloat g
, GLfloat b
)
404 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_COLOR1
][IM
->Count
];
405 ASSIGN_4V(attrib
, r
, g
, b
, 1.0F
);
406 IM
->Flag
[IM
->Count
] |= VERT_COLOR1_BIT
;
410 _vp_SecondaryColor3fv( const GLfloat
*color
)
413 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_COLOR1
][IM
->Count
];
414 ASSIGN_4V(attrib
, color
[0], color
[1], color
[2], 1.0F
);
415 IM
->Flag
[IM
->Count
] |= VERT_COLOR1_BIT
;
419 _vp_SecondaryColor3ub( GLubyte r
, GLubyte g
, GLubyte b
)
422 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_COLOR1
][IM
->Count
];
423 attrib
[0] = UBYTE_TO_FLOAT(r
);
424 attrib
[1] = UBYTE_TO_FLOAT(g
);
425 attrib
[2] = UBYTE_TO_FLOAT(b
);
427 IM
->Flag
[IM
->Count
] |= VERT_COLOR1_BIT
;
431 _vp_SecondaryColor3ubv( const GLubyte
*color
)
434 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_COLOR1
][IM
->Count
];
435 attrib
[0] = UBYTE_TO_FLOAT(color
[0]);
436 attrib
[1] = UBYTE_TO_FLOAT(color
[1]);
437 attrib
[2] = UBYTE_TO_FLOAT(color
[2]);
439 IM
->Flag
[IM
->Count
] |= VERT_COLOR1_BIT
;
443 _vp_TexCoord1f( GLfloat s
)
446 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_TEX0
][IM
->Count
];
447 ASSIGN_4V(attrib
, s
, 0.0F
, 0.0F
, 1.0F
);
448 IM
->Flag
[IM
->Count
] |= VERT_TEX0_BIT
;
452 _vp_TexCoord1fv( const GLfloat
*c
)
455 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_TEX0
][IM
->Count
];
456 ASSIGN_4V(attrib
, c
[0], 0.0F
, 0.0F
, 1.0F
);
457 IM
->Flag
[IM
->Count
] |= VERT_TEX0_BIT
;
461 _vp_TexCoord2f( GLfloat s
, GLfloat t
)
464 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_TEX0
][IM
->Count
];
465 ASSIGN_4V(attrib
, s
, t
, 0.0F
, 1.0F
);
466 IM
->Flag
[IM
->Count
] |= VERT_TEX0_BIT
;
470 _vp_TexCoord2fv( const GLfloat
*c
)
473 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_TEX0
][IM
->Count
];
474 ASSIGN_4V(attrib
, c
[0], c
[1], 0.0F
, 1.0F
);
475 IM
->Flag
[IM
->Count
] |= VERT_TEX0_BIT
;
479 _vp_TexCoord3f( GLfloat s
, GLfloat t
, GLfloat r
)
482 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_TEX0
][IM
->Count
];
483 ASSIGN_4V(attrib
, s
, t
, r
, 1.0F
);
484 IM
->Flag
[IM
->Count
] |= VERT_TEX0_BIT
;
488 _vp_TexCoord3fv( const GLfloat
*c
)
491 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_TEX0
][IM
->Count
];
492 ASSIGN_4V(attrib
, c
[0], c
[1], c
[2], 1.0F
);
493 IM
->Flag
[IM
->Count
] |= VERT_TEX0_BIT
;
497 _vp_TexCoord4f( GLfloat s
, GLfloat t
, GLfloat r
, GLfloat q
)
500 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_TEX0
][IM
->Count
];
501 ASSIGN_4V(attrib
, s
, t
, r
, 1.0F
);
502 IM
->Flag
[IM
->Count
] |= VERT_TEX0_BIT
;
506 _vp_TexCoord4fv( const GLfloat
*c
)
509 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_TEX0
][IM
->Count
];
511 IM
->Flag
[IM
->Count
] |= VERT_TEX0_BIT
;
515 _vp_Vertex2f( GLfloat x
, GLfloat y
)
518 const GLuint count
= IM
->Count
++;
519 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_POS
][count
];
520 ASSIGN_4V(attrib
, x
, y
, 0.0F
, 1.0F
);
521 IM
->Flag
[count
] |= VERT_OBJ_BIT
;
522 if (count
== IMM_MAXDATA
- 1)
523 _tnl_flush_immediate( IM
);
527 _vp_Vertex2fv( const GLfloat
*v
)
530 const GLuint count
= IM
->Count
++;
531 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_POS
][count
];
532 ASSIGN_4V(attrib
, v
[0], v
[1], 0.0F
, 1.0F
);
533 IM
->Flag
[count
] |= VERT_OBJ_BIT
;
534 if (count
== IMM_MAXDATA
- 1)
535 _tnl_flush_immediate( IM
);
539 _vp_Vertex3f( GLfloat x
, GLfloat y
, GLfloat z
)
542 const GLuint count
= IM
->Count
++;
543 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_POS
][count
];
544 ASSIGN_4V(attrib
, x
, y
, z
, 1.0F
);
545 IM
->Flag
[count
] |= VERT_OBJ_BIT
;
546 if (count
== IMM_MAXDATA
- 1)
547 _tnl_flush_immediate( IM
);
551 _vp_Vertex3fv( const GLfloat
*v
)
554 const GLuint count
= IM
->Count
++;
555 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_POS
][count
];
556 ASSIGN_4V(attrib
, v
[0], v
[1], v
[2], 1.0F
);
557 IM
->Flag
[count
] |= VERT_OBJ_BIT
;
558 if (count
== IMM_MAXDATA
- 1)
559 _tnl_flush_immediate( IM
);
563 _vp_Vertex4f( GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
566 const GLuint count
= IM
->Count
++;
567 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_POS
][count
];
568 ASSIGN_4V(attrib
, x
, y
, z
, w
);
569 IM
->Flag
[count
] |= VERT_OBJ_BIT
;
570 if (count
== IMM_MAXDATA
- 1)
571 _tnl_flush_immediate( IM
);
575 _vp_Vertex4fv( const GLfloat
*v
)
578 const GLuint count
= IM
->Count
++;
579 GLfloat
*attrib
= IM
->Attrib
[VERT_ATTRIB_POS
][count
];
581 IM
->Flag
[count
] |= VERT_OBJ_BIT
;
582 if (count
== IMM_MAXDATA
- 1)
583 _tnl_flush_immediate( IM
);
587 _vp_VertexAttrib4f( GLuint index
, GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
591 const GLuint count
= IM
->Count
;
592 GLfloat
*attrib
= IM
->Attrib
[index
][count
];
593 ASSIGN_4V(attrib
, x
, y
, z
, w
);
594 IM
->Flag
[count
] |= (1 << index
);
597 if (count
== IMM_MAXDATA
- 1)
598 _tnl_flush_immediate( IM
);
604 _vp_VertexAttrib4fv( GLuint index
, const GLfloat
*v
)
608 const GLuint count
= IM
->Count
;
609 GLfloat
*attrib
= IM
->Attrib
[index
][count
];
611 IM
->Flag
[count
] |= (1 << index
);
614 if (count
== IMM_MAXDATA
- 1)
615 _tnl_flush_immediate( IM
);
622 * When vertex program mode is enabled we hook in different per-vertex
625 void _tnl_vprog_vtxfmt_init( GLcontext
*ctx
)
627 GLvertexformat
*vfmt
= &(TNL_CONTEXT(ctx
)->vtxfmt
);
629 /* All begin/end operations are handled by this vertex format:
631 vfmt
->ArrayElement
= _vp_ArrayElement
;
632 vfmt
->Begin
= _tnl_Begin
;
633 vfmt
->Color3f
= _vp_Color3f
;
634 vfmt
->Color3fv
= _vp_Color3fv
;
635 vfmt
->Color3ub
= _vp_Color3ub
;
636 vfmt
->Color3ubv
= _vp_Color3ubv
;
637 vfmt
->Color4f
= _vp_Color4f
;
638 vfmt
->Color4fv
= _vp_Color4fv
;
639 vfmt
->Color4ub
= _vp_Color4ub
;
640 vfmt
->Color4ubv
= _vp_Color4ubv
;
641 vfmt
->EdgeFlag
= _vp_EdgeFlag
;
642 vfmt
->EdgeFlagv
= _vp_EdgeFlagv
;
643 vfmt
->End
= _tnl_End
;
644 vfmt
->EvalCoord1f
= _vp_EvalCoord1f
;
645 vfmt
->EvalCoord1fv
= _vp_EvalCoord1fv
;
646 vfmt
->EvalCoord2f
= _vp_EvalCoord2f
;
647 vfmt
->EvalCoord2fv
= _vp_EvalCoord2fv
;
648 vfmt
->EvalPoint1
= _vp_EvalPoint1
;
649 vfmt
->EvalPoint2
= _vp_EvalPoint2
;
650 vfmt
->FogCoordfEXT
= _vp_FogCoordf
;
651 vfmt
->FogCoordfvEXT
= _vp_FogCoordfv
;
652 vfmt
->Indexi
= _vp_Indexi
;
653 vfmt
->Indexiv
= _vp_Indexiv
;
654 vfmt
->Materialfv
= _vp_Materialfv
;
655 vfmt
->MultiTexCoord1fARB
= _vp_MultiTexCoord1f
;
656 vfmt
->MultiTexCoord1fvARB
= _vp_MultiTexCoord1fv
;
657 vfmt
->MultiTexCoord2fARB
= _vp_MultiTexCoord2f
;
658 vfmt
->MultiTexCoord2fvARB
= _vp_MultiTexCoord2fv
;
659 vfmt
->MultiTexCoord3fARB
= _vp_MultiTexCoord3f
;
660 vfmt
->MultiTexCoord3fvARB
= _vp_MultiTexCoord3fv
;
661 vfmt
->MultiTexCoord4fARB
= _vp_MultiTexCoord4f
;
662 vfmt
->MultiTexCoord4fvARB
= _vp_MultiTexCoord4fv
;
663 vfmt
->Normal3f
= _vp_Normal3f
;
664 vfmt
->Normal3fv
= _vp_Normal3fv
;
665 vfmt
->SecondaryColor3fEXT
= _vp_SecondaryColor3f
;
666 vfmt
->SecondaryColor3fvEXT
= _vp_SecondaryColor3fv
;
667 vfmt
->SecondaryColor3ubEXT
= _vp_SecondaryColor3ub
;
668 vfmt
->SecondaryColor3ubvEXT
= _vp_SecondaryColor3ubv
;
669 vfmt
->TexCoord1f
= _vp_TexCoord1f
;
670 vfmt
->TexCoord1fv
= _vp_TexCoord1fv
;
671 vfmt
->TexCoord2f
= _vp_TexCoord2f
;
672 vfmt
->TexCoord2fv
= _vp_TexCoord2fv
;
673 vfmt
->TexCoord3f
= _vp_TexCoord3f
;
674 vfmt
->TexCoord3fv
= _vp_TexCoord3fv
;
675 vfmt
->TexCoord4f
= _vp_TexCoord4f
;
676 vfmt
->TexCoord4fv
= _vp_TexCoord4fv
;
677 vfmt
->Vertex2f
= _vp_Vertex2f
;
678 vfmt
->Vertex2fv
= _vp_Vertex2fv
;
679 vfmt
->Vertex3f
= _vp_Vertex3f
;
680 vfmt
->Vertex3fv
= _vp_Vertex3fv
;
681 vfmt
->Vertex4f
= _vp_Vertex4f
;
682 vfmt
->Vertex4fv
= _vp_Vertex4fv
;
683 vfmt
->VertexAttrib4fNV
= _vp_VertexAttrib4f
;
684 vfmt
->VertexAttrib4fvNV
= _vp_VertexAttrib4fv
;
686 /* Outside begin/end functions (from t_varray.c, t_eval.c, ...):
688 vfmt
->Rectf
= _mesa_noop_Rectf
;
690 /* Just use the core function:
692 vfmt
->CallList
= _mesa_CallList
;
694 vfmt
->prefer_float_colors
= GL_TRUE
;
699 struct vp_stage_data
{
700 GLvector4f clipCoords
; /* post-modelview/projection coords */
701 GLvector4f ndcCoords
; /* normalized device coords */
702 struct gl_client_array color0
[2]; /* front and back */
703 struct gl_client_array color1
[2]; /* front and back */
704 GLvector4f texCoord
[MAX_TEXTURE_UNITS
];
706 GLvector1f pointSize
;
708 GLubyte ormask
, andmask
;
712 #define VP_STAGE_DATA(stage) ((struct vp_stage_data *)(stage->privatePtr))
715 static GLboolean
run_vp( GLcontext
*ctx
, struct gl_pipeline_stage
*stage
)
717 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
718 struct vp_stage_data
*store
= VP_STAGE_DATA(stage
);
719 struct vertex_buffer
*VB
= &tnl
->vb
;
720 struct vp_machine
*machine
= &(ctx
->VertexProgram
.Machine
);
723 /* convenience pointers */
724 GLfloat (*clip
)[4] = (GLfloat (*)[4]) store
->clipCoords
.data
;
725 GLfloat (*color0
)[4] = (GLfloat (*)[4]) store
->color0
[0].Ptr
;
726 GLfloat (*color1
)[4] = (GLfloat (*)[4]) store
->color1
[0].Ptr
;
727 GLfloat (*bfcolor0
)[4] = (GLfloat (*)[4]) store
->color0
[1].Ptr
;
728 GLfloat (*bfcolor1
)[4] = (GLfloat (*)[4]) store
->color1
[1].Ptr
;
729 GLfloat
*fog
= (GLfloat
*) store
->fogCoord
.data
;
730 GLfloat
*pointSize
= (GLfloat
*) store
->pointSize
.data
;
731 GLfloat (*texture0
)[4] = (GLfloat (*)[4]) store
->texCoord
[0].data
;
732 GLfloat (*texture1
)[4] = (GLfloat (*)[4]) store
->texCoord
[1].data
;
733 GLfloat (*texture2
)[4] = (GLfloat (*)[4]) store
->texCoord
[2].data
;
734 GLfloat (*texture3
)[4] = (GLfloat (*)[4]) store
->texCoord
[3].data
;
736 _mesa_init_tracked_matrices(ctx
);
737 _mesa_init_vp_registers(ctx
); /* sets temp regs to (0,0,0,1) */
739 for (i
= 0; i
< VB
->Count
; i
++) {
743 printf("Input %d: %f, %f, %f, %f\n", i
,
744 VB
->AttribPtr
[0]->data
[i
][0],
745 VB
->AttribPtr
[0]->data
[i
][1],
746 VB
->AttribPtr
[0]->data
[i
][2],
747 VB
->AttribPtr
[0]->data
[i
][3]);
748 printf(" color: %f, %f, %f, %f\n",
749 VB
->AttribPtr
[3]->data
[i
][0],
750 VB
->AttribPtr
[3]->data
[i
][1],
751 VB
->AttribPtr
[3]->data
[i
][2],
752 VB
->AttribPtr
[3]->data
[i
][3]);
753 printf(" normal: %f, %f, %f, %f\n",
754 VB
->AttribPtr
[2]->data
[i
][0],
755 VB
->AttribPtr
[2]->data
[i
][1],
756 VB
->AttribPtr
[2]->data
[i
][2],
757 VB
->AttribPtr
[2]->data
[i
][3]);
760 /* load the input attribute registers */
761 for (attr
= 0; attr
< 16; attr
++) {
762 if (VB
->Flag
[i
] & (1 << attr
)) {
763 COPY_4V(machine
->Registers
[VP_INPUT_REG_START
+ attr
],
764 VB
->AttribPtr
[attr
]->data
[i
]);
768 /* execute the program */
769 ASSERT(ctx
->VertexProgram
.Current
);
770 _mesa_exec_program(ctx
, ctx
->VertexProgram
.Current
);
773 printf("Output %d: %f, %f, %f, %f\n", i
,
774 machine
->Registers
[VP_OUT_HPOS
][0],
775 machine
->Registers
[VP_OUT_HPOS
][1],
776 machine
->Registers
[VP_OUT_HPOS
][2],
777 machine
->Registers
[VP_OUT_HPOS
][3]);
778 printf(" color: %f, %f, %f, %f\n",
779 machine
->Registers
[VP_OUT_COL0
][0],
780 machine
->Registers
[VP_OUT_COL0
][1],
781 machine
->Registers
[VP_OUT_COL0
][2],
782 machine
->Registers
[VP_OUT_COL0
][3]);
785 /* store the attribute output registers into the VB arrays */
786 COPY_4V(clip
[i
], machine
->Registers
[VP_OUT_HPOS
]);
787 COPY_4V(color0
[i
], machine
->Registers
[VP_OUT_COL0
]);
788 COPY_4V(color1
[i
], machine
->Registers
[VP_OUT_COL1
]);
789 COPY_4V(bfcolor0
[i
], machine
->Registers
[VP_OUT_BFC0
]);
790 COPY_4V(bfcolor1
[i
], machine
->Registers
[VP_OUT_BFC1
]);
791 fog
[i
] = machine
->Registers
[VP_OUT_FOGC
][0];
792 pointSize
[i
] = machine
->Registers
[VP_OUT_PSIZ
][0];
793 COPY_4V(texture0
[i
], machine
->Registers
[VP_OUT_TEX0
]);
794 COPY_4V(texture1
[i
], machine
->Registers
[VP_OUT_TEX0
]);
795 COPY_4V(texture2
[i
], machine
->Registers
[VP_OUT_TEX0
]);
796 COPY_4V(texture3
[i
], machine
->Registers
[VP_OUT_TEX0
]);
799 VB
->ClipPtr
= &store
->clipCoords
;
800 VB
->ClipPtr
->size
= 4;
801 VB
->ClipPtr
->count
= VB
->Count
;
802 VB
->ColorPtr
[0] = &store
->color0
[0];
803 VB
->ColorPtr
[1] = &store
->color0
[1];
804 VB
->SecondaryColorPtr
[0] = &store
->color1
[0];
805 VB
->SecondaryColorPtr
[1] = &store
->color1
[1];
806 VB
->FogCoordPtr
= &store
->fogCoord
;
807 VB
->PointSizePtr
= &store
->pointSize
;
808 VB
->TexCoordPtr
[0] = &store
->texCoord
[0];
809 VB
->TexCoordPtr
[1] = &store
->texCoord
[1];
810 VB
->TexCoordPtr
[2] = &store
->texCoord
[2];
811 VB
->TexCoordPtr
[3] = &store
->texCoord
[3];
813 /* Cliptest and perspective divide. Clip functions must clear
817 store
->andmask
= CLIP_ALL_BITS
;
819 if (tnl
->NeedNdcCoords
) {
821 _mesa_clip_tab
[VB
->ClipPtr
->size
]( VB
->ClipPtr
,
830 _mesa_clip_np_tab
[VB
->ClipPtr
->size
]( VB
->ClipPtr
,
837 if (store
->andmask
) /* All vertices are outside the frustum */
841 /* This is where we'd do clip testing against the user-defined
842 * clipping planes, but they're not supported by vertex programs.
845 VB
->ClipOrMask
= store
->ormask
;
846 VB
->ClipMask
= store
->clipmask
;
849 if (VB->ClipPtr == VB->ObjPtr && (VB->importable_data & VERT_OBJ_BIT))
850 VB->importable_data |= VERT_CLIP;
857 /* Called in place of do_lighting when the light table may have changed.
859 static GLboolean
run_validate_program( GLcontext
*ctx
,
860 struct gl_pipeline_stage
*stage
)
866 if (ctx
->Visual
.rgbMode
) {
867 if (ctx
->Light
._NeedVertices
) {
868 if (ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
)
869 tab
= _tnl_light_spec_tab
;
871 tab
= _tnl_light_tab
;
874 if (ctx
->Light
.EnabledList
.next
== ctx
->Light
.EnabledList
.prev
)
875 tab
= _tnl_light_fast_single_tab
;
877 tab
= _tnl_light_fast_tab
;
881 tab
= _tnl_light_ci_tab
;
883 if (ctx
->Light
.ColorMaterialEnabled
)
884 ind
|= LIGHT_COLORMATERIAL
;
886 if (ctx
->Light
.Model
.TwoSide
)
887 ind
|= LIGHT_TWOSIDE
;
889 VP_STAGE_DATA(stage
)->light_func_tab
= &tab
[ind
];
891 /* This and the above should only be done on _NEW_LIGHT:
893 _mesa_validate_all_lighting_tables( ctx
);
896 /* Now run the stage...
899 return stage
->run( ctx
, stage
);
905 static void alloc_4chan( struct gl_client_array
*a
, GLuint sz
)
907 a
->Ptr
= ALIGN_MALLOC( sz
* sizeof(GLchan
) * 4, 32 );
911 a
->StrideB
= sizeof(GLchan
) * 4;
917 static void alloc_4float( struct gl_client_array
*a
, GLuint sz
)
919 a
->Ptr
= ALIGN_MALLOC( sz
* sizeof(GLfloat
) * 4, 32 );
923 a
->StrideB
= sizeof(GLfloat
) * 4;
929 /* Called the first time stage->run is called. In effect, don't
930 * allocate data until the first time the stage is run.
932 static GLboolean
run_init_vp( GLcontext
*ctx
,
933 struct gl_pipeline_stage
*stage
)
935 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
936 struct vertex_buffer
*VB
= &(tnl
->vb
);
937 struct vp_stage_data
*store
;
938 const GLuint size
= VB
->Size
;
941 stage
->privatePtr
= MALLOC(sizeof(*store
));
942 store
= VP_STAGE_DATA(stage
);
946 /* The output of a vertex program is: */
947 _mesa_vector4f_alloc( &store
->clipCoords
, 0, size
, 32 );
948 _mesa_vector4f_alloc( &store
->ndcCoords
, 0, size
, 32 );
949 alloc_4float( &store
->color0
[0], size
);
950 alloc_4float( &store
->color0
[1], size
);
951 alloc_4float( &store
->color1
[0], size
);
952 alloc_4float( &store
->color1
[1], size
);
953 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++)
954 _mesa_vector4f_alloc( &store
->texCoord
[i
], 0, VB
->Size
, 32 );
955 _mesa_vector1f_alloc( &store
->fogCoord
, 0, size
, 32 );
956 _mesa_vector1f_alloc( &store
->pointSize
, 0, size
, 32 );
957 store
->clipmask
= (GLubyte
*) ALIGN_MALLOC(sizeof(GLubyte
)*size
, 32 );
960 /* Now validate the stage derived data...
962 stage
->run
= run_validate_program
;
963 return stage
->run( ctx
, stage
);
969 * Check if vertex program mode is enabled.
970 * If so, configure the pipeline stage's type, inputs, and outputs.
972 static void check_vp( GLcontext
*ctx
, struct gl_pipeline_stage
*stage
)
974 stage
->active
= ctx
->VertexProgram
.Enabled
;
978 if (stage
->privatePtr
)
979 stage
->run
= run_validate_program
;
980 stage
->inputs
= VERT_NORMAL_BIT
|VERT_MATERIAL
;
981 if (ctx
->Light
._NeedVertices
)
982 stage
->inputs
|= VERT_EYE
; /* effectively, even when lighting in obj */
983 if (ctx
->Light
.ColorMaterialEnabled
)
984 stage
->inputs
|= VERT_COLOR0_BIT
;
986 stage
->outputs
= VERT_COLOR0_BIT
;
987 if (ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
)
988 stage
->outputs
|= VERT_COLOR1_BIT
;
994 static void dtr( struct gl_pipeline_stage
*stage
)
996 struct vp_stage_data
*store
= VP_STAGE_DATA(stage
);
1000 _mesa_vector4f_free( &store
->clipCoords
);
1001 _mesa_vector4f_free( &store
->ndcCoords
);
1002 ALIGN_FREE( store
->color0
[0].Ptr
);
1003 ALIGN_FREE( store
->color0
[1].Ptr
);
1004 ALIGN_FREE( store
->color1
[0].Ptr
);
1005 ALIGN_FREE( store
->color1
[1].Ptr
);
1006 for (i
= 0 ; i
< MAX_TEXTURE_UNITS
; i
++)
1007 if (store
->texCoord
[i
].data
)
1008 _mesa_vector4f_free( &store
->texCoord
[i
] );
1009 _mesa_vector1f_free( &store
->fogCoord
);
1010 _mesa_vector1f_free( &store
->pointSize
);
1011 ALIGN_FREE( store
->clipmask
);
1014 stage
->privatePtr
= 0;
1018 const struct gl_pipeline_stage _tnl_vertex_program_stage
=
1021 _NEW_ALL
, /*XXX FIX */ /* recheck */
1022 _NEW_ALL
, /*XXX FIX */ /* recalc -- modelview dependency
1023 * otherwise not captured by inputs
1024 * (which may be VERT_OBJ_BIT) */
1025 GL_FALSE
, /* active */
1027 VERT_CLIP
| VERT_COLOR0_BIT
, /* outputs */
1028 0, /* changed_inputs */
1029 NULL
, /* private_data */
1031 check_vp
, /* check */
1032 run_init_vp
/* run -- initially set to ctr */