1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 * \file ffvertex_prog.
31 * Create a vertex program to execute the current fixed function T&L pipeline.
32 * \author Keith Whitwell
36 #include "main/glheader.h"
37 #include "main/mtypes.h"
38 #include "main/macros.h"
39 #include "main/enums.h"
40 #include "main/ffvertex_prog.h"
41 #include "shader/program.h"
42 #include "shader/prog_cache.h"
43 #include "shader/prog_instruction.h"
44 #include "shader/prog_parameter.h"
45 #include "shader/prog_print.h"
46 #include "shader/prog_statevars.h"
50 unsigned light_global_enabled
:1;
51 unsigned light_local_viewer
:1;
52 unsigned light_twoside
:1;
53 unsigned light_color_material
:1;
54 unsigned light_color_material_mask
:12;
55 unsigned light_material_mask
:12;
58 unsigned rescale_normals
:1;
59 unsigned fog_source_is_depth
:1;
60 unsigned tnl_do_vertex_fog
:1;
61 unsigned separate_specular
:1;
63 unsigned point_attenuated
:1;
64 unsigned texture_enabled_global
:1;
65 unsigned fragprog_inputs_read
:12;
68 unsigned light_enabled
:1;
69 unsigned light_eyepos3_is_zero
:1;
70 unsigned light_spotcutoff_is_180
:1;
71 unsigned light_attenuated
:1;
72 unsigned texunit_really_enabled
:1;
73 unsigned texmat_enabled
:1;
74 unsigned texgen_enabled
:4;
75 unsigned texgen_mode0
:4;
76 unsigned texgen_mode1
:4;
77 unsigned texgen_mode2
:4;
78 unsigned texgen_mode3
:4;
89 static GLuint
translate_fog_mode( GLenum mode
)
92 case GL_LINEAR
: return FOG_LINEAR
;
93 case GL_EXP
: return FOG_EXP
;
94 case GL_EXP2
: return FOG_EXP2
;
95 default: return FOG_NONE
;
100 #define TXG_OBJ_LINEAR 1
101 #define TXG_EYE_LINEAR 2
102 #define TXG_SPHERE_MAP 3
103 #define TXG_REFLECTION_MAP 4
104 #define TXG_NORMAL_MAP 5
106 static GLuint
translate_texgen( GLboolean enabled
, GLenum mode
)
112 case GL_OBJECT_LINEAR
: return TXG_OBJ_LINEAR
;
113 case GL_EYE_LINEAR
: return TXG_EYE_LINEAR
;
114 case GL_SPHERE_MAP
: return TXG_SPHERE_MAP
;
115 case GL_REFLECTION_MAP_NV
: return TXG_REFLECTION_MAP
;
116 case GL_NORMAL_MAP_NV
: return TXG_NORMAL_MAP
;
117 default: return TXG_NONE
;
123 * Returns bitmask of flags indicating which materials are set per-vertex
125 * XXX get these from the VBO...
128 tnl_get_per_vertex_materials(GLcontext
*ctx
)
130 GLbitfield mask
= 0x0;
132 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
133 struct vertex_buffer
*VB
= &tnl
->vb
;
136 for (i
= _TNL_FIRST_MAT
; i
<= _TNL_LAST_MAT
; i
++)
137 if (VB
->AttribPtr
[i
] && VB
->AttribPtr
[i
]->stride
)
138 mask
|= 1 << (i
- _TNL_FIRST_MAT
);
144 * Should fog be computed per-vertex?
147 tnl_get_per_vertex_fog(GLcontext
*ctx
)
150 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
151 return tnl
->_DoVertexFog
;
158 static struct state_key
*make_state_key( GLcontext
*ctx
)
160 const struct gl_fragment_program
*fp
;
161 struct state_key
*key
= CALLOC_STRUCT(state_key
);
164 fp
= ctx
->FragmentProgram
._Current
;
166 /* This now relies on texenvprogram.c being active:
170 key
->fragprog_inputs_read
= fp
->Base
.InputsRead
;
172 if (ctx
->RenderMode
== GL_FEEDBACK
) {
173 /* make sure the vertprog emits color and tex0 */
174 key
->fragprog_inputs_read
|= (FRAG_BIT_COL0
| FRAG_BIT_TEX0
);
177 key
->separate_specular
= (ctx
->Light
.Model
.ColorControl
==
178 GL_SEPARATE_SPECULAR_COLOR
);
180 if (ctx
->Light
.Enabled
) {
181 key
->light_global_enabled
= 1;
183 if (ctx
->Light
.Model
.LocalViewer
)
184 key
->light_local_viewer
= 1;
186 if (ctx
->Light
.Model
.TwoSide
)
187 key
->light_twoside
= 1;
189 if (ctx
->Light
.ColorMaterialEnabled
) {
190 key
->light_color_material
= 1;
191 key
->light_color_material_mask
= ctx
->Light
.ColorMaterialBitmask
;
194 key
->light_material_mask
= tnl_get_per_vertex_materials(ctx
);
196 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
197 struct gl_light
*light
= &ctx
->Light
.Light
[i
];
199 if (light
->Enabled
) {
200 key
->unit
[i
].light_enabled
= 1;
202 if (light
->EyePosition
[3] == 0.0)
203 key
->unit
[i
].light_eyepos3_is_zero
= 1;
205 if (light
->SpotCutoff
== 180.0)
206 key
->unit
[i
].light_spotcutoff_is_180
= 1;
208 if (light
->ConstantAttenuation
!= 1.0 ||
209 light
->LinearAttenuation
!= 0.0 ||
210 light
->QuadraticAttenuation
!= 0.0)
211 key
->unit
[i
].light_attenuated
= 1;
216 if (ctx
->Transform
.Normalize
)
219 if (ctx
->Transform
.RescaleNormals
)
220 key
->rescale_normals
= 1;
222 key
->fog_mode
= translate_fog_mode(fp
->FogOption
);
224 if (ctx
->Fog
.FogCoordinateSource
== GL_FRAGMENT_DEPTH_EXT
)
225 key
->fog_source_is_depth
= 1;
227 key
->tnl_do_vertex_fog
= tnl_get_per_vertex_fog(ctx
);
229 if (ctx
->Point
._Attenuated
)
230 key
->point_attenuated
= 1;
232 if (ctx
->Texture
._TexGenEnabled
||
233 ctx
->Texture
._TexMatEnabled
||
234 ctx
->Texture
._EnabledUnits
)
235 key
->texture_enabled_global
= 1;
237 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
238 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[i
];
240 if (texUnit
->_ReallyEnabled
)
241 key
->unit
[i
].texunit_really_enabled
= 1;
243 if (ctx
->Texture
._TexMatEnabled
& ENABLE_TEXMAT(i
))
244 key
->unit
[i
].texmat_enabled
= 1;
246 if (texUnit
->TexGenEnabled
) {
247 key
->unit
[i
].texgen_enabled
= 1;
249 key
->unit
[i
].texgen_mode0
=
250 translate_texgen( texUnit
->TexGenEnabled
& (1<<0),
252 key
->unit
[i
].texgen_mode1
=
253 translate_texgen( texUnit
->TexGenEnabled
& (1<<1),
255 key
->unit
[i
].texgen_mode2
=
256 translate_texgen( texUnit
->TexGenEnabled
& (1<<2),
258 key
->unit
[i
].texgen_mode3
=
259 translate_texgen( texUnit
->TexGenEnabled
& (1<<3),
269 /* Very useful debugging tool - produces annotated listing of
270 * generated program with line/function references for each
271 * instruction back into this file:
273 #define DISASSEM (MESA_VERBOSE&VERBOSE_DISASSEM)
275 /* Should be tunable by the driver - do we want to do matrix
276 * multiplications with DP4's or with MUL/MAD's? SSE works better
277 * with the latter, drivers may differ.
283 /* Use uregs to represent registers internally, translate to Mesa's
284 * expected formats on emit.
286 * NOTE: These are passed by value extensively in this file rather
287 * than as usual by pointer reference. If this disturbs you, try
288 * remembering they are just 32bits in size.
290 * GCC is smart enough to deal with these dword-sized structures in
291 * much the same way as if I had defined them as dwords and was using
292 * macros to access and set the fields. This is much nicer and easier
297 GLint idx
:8; /* relative addressing may be negative */
305 const struct state_key
*state
;
306 struct gl_vertex_program
*program
;
309 GLuint temp_reserved
;
311 struct ureg eye_position
;
312 struct ureg eye_position_normalized
;
313 struct ureg eye_normal
;
314 struct ureg identity
;
317 GLuint color_materials
;
321 static const struct ureg undef
= {
339 static struct ureg
make_ureg(GLuint file
, GLint idx
)
345 reg
.swz
= SWIZZLE_NOOP
;
352 static struct ureg
negate( struct ureg reg
)
359 static struct ureg
swizzle( struct ureg reg
, int x
, int y
, int z
, int w
)
361 reg
.swz
= MAKE_SWIZZLE4(GET_SWZ(reg
.swz
, x
),
364 GET_SWZ(reg
.swz
, w
));
369 static struct ureg
swizzle1( struct ureg reg
, int x
)
371 return swizzle(reg
, x
, x
, x
, x
);
374 static struct ureg
get_temp( struct tnl_program
*p
)
376 int bit
= _mesa_ffs( ~p
->temp_in_use
);
378 _mesa_problem(NULL
, "%s: out of temporaries\n", __FILE__
);
382 if ((GLuint
) bit
> p
->program
->Base
.NumTemporaries
)
383 p
->program
->Base
.NumTemporaries
= bit
;
385 p
->temp_in_use
|= 1<<(bit
-1);
386 return make_ureg(PROGRAM_TEMPORARY
, bit
-1);
389 static struct ureg
reserve_temp( struct tnl_program
*p
)
391 struct ureg temp
= get_temp( p
);
392 p
->temp_reserved
|= 1<<temp
.idx
;
396 static void release_temp( struct tnl_program
*p
, struct ureg reg
)
398 if (reg
.file
== PROGRAM_TEMPORARY
) {
399 p
->temp_in_use
&= ~(1<<reg
.idx
);
400 p
->temp_in_use
|= p
->temp_reserved
; /* can't release reserved temps */
404 static void release_temps( struct tnl_program
*p
)
406 p
->temp_in_use
= p
->temp_reserved
;
411 static struct ureg
register_input( struct tnl_program
*p
, GLuint input
)
413 p
->program
->Base
.InputsRead
|= (1<<input
);
414 return make_ureg(PROGRAM_INPUT
, input
);
417 static struct ureg
register_output( struct tnl_program
*p
, GLuint output
)
419 p
->program
->Base
.OutputsWritten
|= (1<<output
);
420 return make_ureg(PROGRAM_OUTPUT
, output
);
423 static struct ureg
register_const4f( struct tnl_program
*p
,
436 idx
= _mesa_add_unnamed_constant( p
->program
->Base
.Parameters
, values
, 4,
438 ASSERT(swizzle
== SWIZZLE_NOOP
);
439 return make_ureg(PROGRAM_STATE_VAR
, idx
);
442 #define register_const1f(p, s0) register_const4f(p, s0, 0, 0, 1)
443 #define register_scalar_const(p, s0) register_const4f(p, s0, s0, s0, s0)
444 #define register_const2f(p, s0, s1) register_const4f(p, s0, s1, 0, 1)
445 #define register_const3f(p, s0, s1, s2) register_const4f(p, s0, s1, s2, 1)
447 static GLboolean
is_undef( struct ureg reg
)
449 return reg
.file
== PROGRAM_UNDEFINED
;
452 static struct ureg
get_identity_param( struct tnl_program
*p
)
454 if (is_undef(p
->identity
))
455 p
->identity
= register_const4f(p
, 0,0,0,1);
460 static struct ureg
register_param5(struct tnl_program
*p
,
467 gl_state_index tokens
[STATE_LENGTH
];
474 idx
= _mesa_add_state_reference( p
->program
->Base
.Parameters
, tokens
);
475 return make_ureg(PROGRAM_STATE_VAR
, idx
);
479 #define register_param1(p,s0) register_param5(p,s0,0,0,0,0)
480 #define register_param2(p,s0,s1) register_param5(p,s0,s1,0,0,0)
481 #define register_param3(p,s0,s1,s2) register_param5(p,s0,s1,s2,0,0)
482 #define register_param4(p,s0,s1,s2,s3) register_param5(p,s0,s1,s2,s3,0)
485 static void register_matrix_param5( struct tnl_program
*p
,
486 GLint s0
, /* modelview, projection, etc */
487 GLint s1
, /* texture matrix number */
488 GLint s2
, /* first row */
489 GLint s3
, /* last row */
490 GLint s4
, /* inverse, transpose, etc */
491 struct ureg
*matrix
)
495 /* This is a bit sad as the support is there to pull the whole
496 * matrix out in one go:
498 for (i
= 0; i
<= s3
- s2
; i
++)
499 matrix
[i
] = register_param5( p
, s0
, s1
, i
, i
, s4
);
503 static void emit_arg( struct prog_src_register
*src
,
506 src
->File
= reg
.file
;
507 src
->Index
= reg
.idx
;
508 src
->Swizzle
= reg
.swz
;
509 src
->NegateBase
= reg
.negate
? NEGATE_XYZW
: 0;
515 static void emit_dst( struct prog_dst_register
*dst
,
516 struct ureg reg
, GLuint mask
)
518 dst
->File
= reg
.file
;
519 dst
->Index
= reg
.idx
;
520 /* allow zero as a shorthand for xyzw */
521 dst
->WriteMask
= mask
? mask
: WRITEMASK_XYZW
;
522 dst
->CondMask
= COND_TR
; /* always pass cond test */
523 dst
->CondSwizzle
= SWIZZLE_NOOP
;
528 static void debug_insn( struct prog_instruction
*inst
, const char *fn
,
532 static const char *last_fn
;
536 _mesa_printf("%s:\n", fn
);
539 _mesa_printf("%d:\t", line
);
540 _mesa_print_instruction(inst
);
545 static void emit_op3fn(struct tnl_program
*p
,
555 GLuint nr
= p
->program
->Base
.NumInstructions
++;
556 struct prog_instruction
*inst
= &p
->program
->Base
.Instructions
[nr
];
558 if (p
->program
->Base
.NumInstructions
> MAX_INSN
) {
559 _mesa_problem(0, "Out of instructions in emit_op3fn\n");
563 inst
->Opcode
= (enum prog_opcode
) op
;
567 emit_arg( &inst
->SrcReg
[0], src0
);
568 emit_arg( &inst
->SrcReg
[1], src1
);
569 emit_arg( &inst
->SrcReg
[2], src2
);
571 emit_dst( &inst
->DstReg
, dest
, mask
);
573 debug_insn(inst
, fn
, line
);
577 #define emit_op3(p, op, dst, mask, src0, src1, src2) \
578 emit_op3fn(p, op, dst, mask, src0, src1, src2, __FUNCTION__, __LINE__)
580 #define emit_op2(p, op, dst, mask, src0, src1) \
581 emit_op3fn(p, op, dst, mask, src0, src1, undef, __FUNCTION__, __LINE__)
583 #define emit_op1(p, op, dst, mask, src0) \
584 emit_op3fn(p, op, dst, mask, src0, undef, undef, __FUNCTION__, __LINE__)
587 static struct ureg
make_temp( struct tnl_program
*p
, struct ureg reg
)
589 if (reg
.file
== PROGRAM_TEMPORARY
&&
590 !(p
->temp_reserved
& (1<<reg
.idx
)))
593 struct ureg temp
= get_temp(p
);
594 emit_op1(p
, OPCODE_MOV
, temp
, 0, reg
);
600 /* Currently no tracking performed of input/output/register size or
601 * active elements. Could be used to reduce these operations, as
602 * could the matrix type.
604 static void emit_matrix_transform_vec4( struct tnl_program
*p
,
606 const struct ureg
*mat
,
609 emit_op2(p
, OPCODE_DP4
, dest
, WRITEMASK_X
, src
, mat
[0]);
610 emit_op2(p
, OPCODE_DP4
, dest
, WRITEMASK_Y
, src
, mat
[1]);
611 emit_op2(p
, OPCODE_DP4
, dest
, WRITEMASK_Z
, src
, mat
[2]);
612 emit_op2(p
, OPCODE_DP4
, dest
, WRITEMASK_W
, src
, mat
[3]);
615 /* This version is much easier to implement if writemasks are not
616 * supported natively on the target or (like SSE), the target doesn't
617 * have a clean/obvious dotproduct implementation.
619 static void emit_transpose_matrix_transform_vec4( struct tnl_program
*p
,
621 const struct ureg
*mat
,
626 if (dest
.file
!= PROGRAM_TEMPORARY
)
631 emit_op2(p
, OPCODE_MUL
, tmp
, 0, swizzle1(src
,X
), mat
[0]);
632 emit_op3(p
, OPCODE_MAD
, tmp
, 0, swizzle1(src
,Y
), mat
[1], tmp
);
633 emit_op3(p
, OPCODE_MAD
, tmp
, 0, swizzle1(src
,Z
), mat
[2], tmp
);
634 emit_op3(p
, OPCODE_MAD
, dest
, 0, swizzle1(src
,W
), mat
[3], tmp
);
636 if (dest
.file
!= PROGRAM_TEMPORARY
)
637 release_temp(p
, tmp
);
640 static void emit_matrix_transform_vec3( struct tnl_program
*p
,
642 const struct ureg
*mat
,
645 emit_op2(p
, OPCODE_DP3
, dest
, WRITEMASK_X
, src
, mat
[0]);
646 emit_op2(p
, OPCODE_DP3
, dest
, WRITEMASK_Y
, src
, mat
[1]);
647 emit_op2(p
, OPCODE_DP3
, dest
, WRITEMASK_Z
, src
, mat
[2]);
651 static void emit_normalize_vec3( struct tnl_program
*p
,
655 struct ureg tmp
= get_temp(p
);
656 emit_op2(p
, OPCODE_DP3
, tmp
, 0, src
, src
);
657 emit_op1(p
, OPCODE_RSQ
, tmp
, 0, tmp
);
658 emit_op2(p
, OPCODE_MUL
, dest
, 0, src
, tmp
);
659 release_temp(p
, tmp
);
662 static void emit_passthrough( struct tnl_program
*p
,
666 struct ureg out
= register_output(p
, output
);
667 emit_op1(p
, OPCODE_MOV
, out
, 0, register_input(p
, input
));
670 static struct ureg
get_eye_position( struct tnl_program
*p
)
672 if (is_undef(p
->eye_position
)) {
673 struct ureg pos
= register_input( p
, VERT_ATTRIB_POS
);
674 struct ureg modelview
[4];
676 p
->eye_position
= reserve_temp(p
);
679 register_matrix_param5( p
, STATE_MODELVIEW_MATRIX
, 0, 0, 3,
682 emit_matrix_transform_vec4(p
, p
->eye_position
, modelview
, pos
);
685 register_matrix_param5( p
, STATE_MODELVIEW_MATRIX
, 0, 0, 3,
686 STATE_MATRIX_TRANSPOSE
, modelview
);
688 emit_transpose_matrix_transform_vec4(p
, p
->eye_position
, modelview
, pos
);
692 return p
->eye_position
;
696 static struct ureg
get_eye_position_normalized( struct tnl_program
*p
)
698 if (is_undef(p
->eye_position_normalized
)) {
699 struct ureg eye
= get_eye_position(p
);
700 p
->eye_position_normalized
= reserve_temp(p
);
701 emit_normalize_vec3(p
, p
->eye_position_normalized
, eye
);
704 return p
->eye_position_normalized
;
708 static struct ureg
get_eye_normal( struct tnl_program
*p
)
710 if (is_undef(p
->eye_normal
)) {
711 struct ureg normal
= register_input(p
, VERT_ATTRIB_NORMAL
);
712 struct ureg mvinv
[3];
714 register_matrix_param5( p
, STATE_MODELVIEW_MATRIX
, 0, 0, 2,
715 STATE_MATRIX_INVTRANS
, mvinv
);
717 p
->eye_normal
= reserve_temp(p
);
719 /* Transform to eye space:
721 emit_matrix_transform_vec3( p
, p
->eye_normal
, mvinv
, normal
);
723 /* Normalize/Rescale:
725 if (p
->state
->normalize
) {
726 emit_normalize_vec3( p
, p
->eye_normal
, p
->eye_normal
);
728 else if (p
->state
->rescale_normals
) {
729 struct ureg rescale
= register_param2(p
, STATE_INTERNAL
,
732 emit_op2( p
, OPCODE_MUL
, p
->eye_normal
, 0, p
->eye_normal
,
733 swizzle1(rescale
, X
));
737 return p
->eye_normal
;
742 static void build_hpos( struct tnl_program
*p
)
744 struct ureg pos
= register_input( p
, VERT_ATTRIB_POS
);
745 struct ureg hpos
= register_output( p
, VERT_RESULT_HPOS
);
749 register_matrix_param5( p
, STATE_MVP_MATRIX
, 0, 0, 3,
751 emit_matrix_transform_vec4( p
, hpos
, mvp
, pos
);
754 register_matrix_param5( p
, STATE_MVP_MATRIX
, 0, 0, 3,
755 STATE_MATRIX_TRANSPOSE
, mvp
);
756 emit_transpose_matrix_transform_vec4( p
, hpos
, mvp
, pos
);
761 static GLuint
material_attrib( GLuint side
, GLuint property
)
763 return ((property
- STATE_AMBIENT
) * 2 +
767 /* Get a bitmask of which material values vary on a per-vertex basis.
769 static void set_material_flags( struct tnl_program
*p
)
771 p
->color_materials
= 0;
774 if (p
->state
->light_color_material
) {
776 p
->color_materials
= p
->state
->light_color_material_mask
;
779 p
->materials
|= p
->state
->light_material_mask
;
783 /* XXX temporary!!! */
784 #define _TNL_ATTRIB_MAT_FRONT_AMBIENT 32
786 static struct ureg
get_material( struct tnl_program
*p
, GLuint side
,
789 GLuint attrib
= material_attrib(side
, property
);
791 if (p
->color_materials
& (1<<attrib
))
792 return register_input(p
, VERT_ATTRIB_COLOR0
);
793 else if (p
->materials
& (1<<attrib
))
794 return register_input( p
, attrib
+ _TNL_ATTRIB_MAT_FRONT_AMBIENT
);
796 return register_param3( p
, STATE_MATERIAL
, side
, property
);
799 #define SCENE_COLOR_BITS(side) (( MAT_BIT_FRONT_EMISSION | \
800 MAT_BIT_FRONT_AMBIENT | \
801 MAT_BIT_FRONT_DIFFUSE) << (side))
803 /* Either return a precalculated constant value or emit code to
804 * calculate these values dynamically in the case where material calls
805 * are present between begin/end pairs.
807 * Probably want to shift this to the program compilation phase - if
808 * we always emitted the calculation here, a smart compiler could
809 * detect that it was constant (given a certain set of inputs), and
810 * lift it out of the main loop. That way the programs created here
811 * would be independent of the vertex_buffer details.
813 static struct ureg
get_scenecolor( struct tnl_program
*p
, GLuint side
)
815 if (p
->materials
& SCENE_COLOR_BITS(side
)) {
816 struct ureg lm_ambient
= register_param1(p
, STATE_LIGHTMODEL_AMBIENT
);
817 struct ureg material_emission
= get_material(p
, side
, STATE_EMISSION
);
818 struct ureg material_ambient
= get_material(p
, side
, STATE_AMBIENT
);
819 struct ureg material_diffuse
= get_material(p
, side
, STATE_DIFFUSE
);
820 struct ureg tmp
= make_temp(p
, material_diffuse
);
821 emit_op3(p
, OPCODE_MAD
, tmp
, WRITEMASK_XYZ
, lm_ambient
,
822 material_ambient
, material_emission
);
826 return register_param2( p
, STATE_LIGHTMODEL_SCENECOLOR
, side
);
830 static struct ureg
get_lightprod( struct tnl_program
*p
, GLuint light
,
831 GLuint side
, GLuint property
)
833 GLuint attrib
= material_attrib(side
, property
);
834 if (p
->materials
& (1<<attrib
)) {
835 struct ureg light_value
=
836 register_param3(p
, STATE_LIGHT
, light
, property
);
837 struct ureg material_value
= get_material(p
, side
, property
);
838 struct ureg tmp
= get_temp(p
);
839 emit_op2(p
, OPCODE_MUL
, tmp
, 0, light_value
, material_value
);
843 return register_param4(p
, STATE_LIGHTPROD
, light
, side
, property
);
846 static struct ureg
calculate_light_attenuation( struct tnl_program
*p
,
851 struct ureg attenuation
= register_param3(p
, STATE_LIGHT
, i
,
853 struct ureg att
= get_temp(p
);
855 /* Calculate spot attenuation:
857 if (!p
->state
->unit
[i
].light_spotcutoff_is_180
) {
858 struct ureg spot_dir_norm
= register_param3(p
, STATE_INTERNAL
,
859 STATE_SPOT_DIR_NORMALIZED
, i
);
860 struct ureg spot
= get_temp(p
);
861 struct ureg slt
= get_temp(p
);
863 emit_op2(p
, OPCODE_DP3
, spot
, 0, negate(VPpli
), spot_dir_norm
);
864 emit_op2(p
, OPCODE_SLT
, slt
, 0, swizzle1(spot_dir_norm
,W
), spot
);
865 emit_op2(p
, OPCODE_POW
, spot
, 0, spot
, swizzle1(attenuation
, W
));
866 emit_op2(p
, OPCODE_MUL
, att
, 0, slt
, spot
);
868 release_temp(p
, spot
);
869 release_temp(p
, slt
);
872 /* Calculate distance attenuation:
874 if (p
->state
->unit
[i
].light_attenuated
) {
877 emit_op1(p
, OPCODE_RCP
, dist
, WRITEMASK_YZ
, dist
);
879 emit_op2(p
, OPCODE_MUL
, dist
, WRITEMASK_XZ
, dist
, swizzle1(dist
,Y
));
881 emit_op2(p
, OPCODE_DP3
, dist
, 0, attenuation
, dist
);
883 if (!p
->state
->unit
[i
].light_spotcutoff_is_180
) {
885 emit_op1(p
, OPCODE_RCP
, dist
, 0, dist
);
886 /* spot-atten * dist-atten */
887 emit_op2(p
, OPCODE_MUL
, att
, 0, dist
, att
);
890 emit_op1(p
, OPCODE_RCP
, att
, 0, dist
);
901 /* Need to add some addtional parameters to allow lighting in object
902 * space - STATE_SPOT_DIRECTION and STATE_HALF_VECTOR implicitly assume eye
905 static void build_lighting( struct tnl_program
*p
)
907 const GLboolean twoside
= p
->state
->light_twoside
;
908 const GLboolean separate
= p
->state
->separate_specular
;
909 GLuint nr_lights
= 0, count
= 0;
910 struct ureg normal
= get_eye_normal(p
);
911 struct ureg lit
= get_temp(p
);
912 struct ureg dots
= get_temp(p
);
913 struct ureg _col0
= undef
, _col1
= undef
;
914 struct ureg _bfc0
= undef
, _bfc1
= undef
;
917 for (i
= 0; i
< MAX_LIGHTS
; i
++)
918 if (p
->state
->unit
[i
].light_enabled
)
921 set_material_flags(p
);
924 struct ureg shininess
= get_material(p
, 0, STATE_SHININESS
);
925 emit_op1(p
, OPCODE_MOV
, dots
, WRITEMASK_W
, swizzle1(shininess
,X
));
926 release_temp(p
, shininess
);
928 _col0
= make_temp(p
, get_scenecolor(p
, 0));
930 _col1
= make_temp(p
, get_identity_param(p
));
937 struct ureg shininess
= get_material(p
, 1, STATE_SHININESS
);
938 emit_op1(p
, OPCODE_MOV
, dots
, WRITEMASK_Z
,
939 negate(swizzle1(shininess
,X
)));
940 release_temp(p
, shininess
);
942 _bfc0
= make_temp(p
, get_scenecolor(p
, 1));
944 _bfc1
= make_temp(p
, get_identity_param(p
));
950 /* If no lights, still need to emit the scenecolor.
953 struct ureg res0
= register_output( p
, VERT_RESULT_COL0
);
954 emit_op1(p
, OPCODE_MOV
, res0
, 0, _col0
);
958 struct ureg res1
= register_output( p
, VERT_RESULT_COL1
);
959 emit_op1(p
, OPCODE_MOV
, res1
, 0, _col1
);
963 struct ureg res0
= register_output( p
, VERT_RESULT_BFC0
);
964 emit_op1(p
, OPCODE_MOV
, res0
, 0, _bfc0
);
967 if (twoside
&& separate
) {
968 struct ureg res1
= register_output( p
, VERT_RESULT_BFC1
);
969 emit_op1(p
, OPCODE_MOV
, res1
, 0, _bfc1
);
972 if (nr_lights
== 0) {
978 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
979 if (p
->state
->unit
[i
].light_enabled
) {
980 struct ureg half
= undef
;
981 struct ureg att
= undef
, VPpli
= undef
;
985 if (p
->state
->unit
[i
].light_eyepos3_is_zero
) {
986 /* Can used precomputed constants in this case.
987 * Attenuation never applies to infinite lights.
989 VPpli
= register_param3(p
, STATE_LIGHT
, i
,
990 STATE_POSITION_NORMALIZED
);
991 if (p
->state
->light_local_viewer
) {
992 struct ureg eye_hat
= get_eye_position_normalized(p
);
994 emit_op2(p
, OPCODE_SUB
, half
, 0, VPpli
, eye_hat
);
995 emit_normalize_vec3(p
, half
, half
);
997 half
= register_param3(p
, STATE_LIGHT
, i
, STATE_HALF_VECTOR
);
1001 struct ureg Ppli
= register_param3(p
, STATE_LIGHT
, i
,
1003 struct ureg V
= get_eye_position(p
);
1004 struct ureg dist
= get_temp(p
);
1006 VPpli
= get_temp(p
);
1009 /* Calulate VPpli vector
1011 emit_op2(p
, OPCODE_SUB
, VPpli
, 0, Ppli
, V
);
1013 /* Normalize VPpli. The dist value also used in
1014 * attenuation below.
1016 emit_op2(p
, OPCODE_DP3
, dist
, 0, VPpli
, VPpli
);
1017 emit_op1(p
, OPCODE_RSQ
, dist
, 0, dist
);
1018 emit_op2(p
, OPCODE_MUL
, VPpli
, 0, VPpli
, dist
);
1021 /* Calculate attenuation:
1023 if (!p
->state
->unit
[i
].light_spotcutoff_is_180
||
1024 p
->state
->unit
[i
].light_attenuated
) {
1025 att
= calculate_light_attenuation(p
, i
, VPpli
, dist
);
1029 /* Calculate viewer direction, or use infinite viewer:
1031 if (p
->state
->light_local_viewer
) {
1032 struct ureg eye_hat
= get_eye_position_normalized(p
);
1033 emit_op2(p
, OPCODE_SUB
, half
, 0, VPpli
, eye_hat
);
1036 struct ureg z_dir
= swizzle(get_identity_param(p
),X
,Y
,W
,Z
);
1037 emit_op2(p
, OPCODE_ADD
, half
, 0, VPpli
, z_dir
);
1040 emit_normalize_vec3(p
, half
, half
);
1042 release_temp(p
, dist
);
1045 /* Calculate dot products:
1047 emit_op2(p
, OPCODE_DP3
, dots
, WRITEMASK_X
, normal
, VPpli
);
1048 emit_op2(p
, OPCODE_DP3
, dots
, WRITEMASK_Y
, normal
, half
);
1051 /* Front face lighting:
1054 struct ureg ambient
= get_lightprod(p
, i
, 0, STATE_AMBIENT
);
1055 struct ureg diffuse
= get_lightprod(p
, i
, 0, STATE_DIFFUSE
);
1056 struct ureg specular
= get_lightprod(p
, i
, 0, STATE_SPECULAR
);
1057 struct ureg res0
, res1
;
1058 GLuint mask0
, mask1
;
1060 emit_op1(p
, OPCODE_LIT
, lit
, 0, dots
);
1063 emit_op2(p
, OPCODE_MUL
, lit
, 0, lit
, att
);
1066 if (count
== nr_lights
) {
1068 mask0
= WRITEMASK_XYZ
;
1069 mask1
= WRITEMASK_XYZ
;
1070 res0
= register_output( p
, VERT_RESULT_COL0
);
1071 res1
= register_output( p
, VERT_RESULT_COL1
);
1075 mask1
= WRITEMASK_XYZ
;
1077 res1
= register_output( p
, VERT_RESULT_COL0
);
1086 emit_op3(p
, OPCODE_MAD
, _col0
, 0, swizzle1(lit
,X
), ambient
, _col0
);
1087 emit_op3(p
, OPCODE_MAD
, res0
, mask0
, swizzle1(lit
,Y
), diffuse
, _col0
);
1088 emit_op3(p
, OPCODE_MAD
, res1
, mask1
, swizzle1(lit
,Z
), specular
, _col1
);
1090 release_temp(p
, ambient
);
1091 release_temp(p
, diffuse
);
1092 release_temp(p
, specular
);
1095 /* Back face lighting:
1098 struct ureg ambient
= get_lightprod(p
, i
, 1, STATE_AMBIENT
);
1099 struct ureg diffuse
= get_lightprod(p
, i
, 1, STATE_DIFFUSE
);
1100 struct ureg specular
= get_lightprod(p
, i
, 1, STATE_SPECULAR
);
1101 struct ureg res0
, res1
;
1102 GLuint mask0
, mask1
;
1104 emit_op1(p
, OPCODE_LIT
, lit
, 0, negate(swizzle(dots
,X
,Y
,W
,Z
)));
1107 emit_op2(p
, OPCODE_MUL
, lit
, 0, lit
, att
);
1109 if (count
== nr_lights
) {
1111 mask0
= WRITEMASK_XYZ
;
1112 mask1
= WRITEMASK_XYZ
;
1113 res0
= register_output( p
, VERT_RESULT_BFC0
);
1114 res1
= register_output( p
, VERT_RESULT_BFC1
);
1118 mask1
= WRITEMASK_XYZ
;
1120 res1
= register_output( p
, VERT_RESULT_BFC0
);
1129 emit_op3(p
, OPCODE_MAD
, _bfc0
, 0, swizzle1(lit
,X
), ambient
, _bfc0
);
1130 emit_op3(p
, OPCODE_MAD
, res0
, mask0
, swizzle1(lit
,Y
), diffuse
, _bfc0
);
1131 emit_op3(p
, OPCODE_MAD
, res1
, mask1
, swizzle1(lit
,Z
), specular
, _bfc1
);
1133 release_temp(p
, ambient
);
1134 release_temp(p
, diffuse
);
1135 release_temp(p
, specular
);
1138 release_temp(p
, half
);
1139 release_temp(p
, VPpli
);
1140 release_temp(p
, att
);
1148 static void build_fog( struct tnl_program
*p
)
1150 struct ureg fog
= register_output(p
, VERT_RESULT_FOGC
);
1153 if (p
->state
->fog_source_is_depth
) {
1154 input
= swizzle1(get_eye_position(p
), Z
);
1157 input
= swizzle1(register_input(p
, VERT_ATTRIB_FOG
), X
);
1160 if (p
->state
->fog_mode
&& p
->state
->tnl_do_vertex_fog
) {
1161 struct ureg params
= register_param2(p
, STATE_INTERNAL
,
1162 STATE_FOG_PARAMS_OPTIMIZED
);
1163 struct ureg tmp
= get_temp(p
);
1164 GLboolean useabs
= (p
->state
->fog_mode
!= FOG_EXP2
);
1167 emit_op1(p
, OPCODE_ABS
, tmp
, 0, input
);
1170 switch (p
->state
->fog_mode
) {
1172 struct ureg id
= get_identity_param(p
);
1173 emit_op3(p
, OPCODE_MAD
, tmp
, 0, useabs
? tmp
: input
,
1174 swizzle1(params
,X
), swizzle1(params
,Y
));
1175 emit_op2(p
, OPCODE_MAX
, tmp
, 0, tmp
, swizzle1(id
,X
)); /* saturate */
1176 emit_op2(p
, OPCODE_MIN
, fog
, WRITEMASK_X
, tmp
, swizzle1(id
,W
));
1180 emit_op2(p
, OPCODE_MUL
, tmp
, 0, useabs
? tmp
: input
,
1181 swizzle1(params
,Z
));
1182 emit_op1(p
, OPCODE_EX2
, fog
, WRITEMASK_X
, negate(tmp
));
1185 emit_op2(p
, OPCODE_MUL
, tmp
, 0, input
, swizzle1(params
,W
));
1186 emit_op2(p
, OPCODE_MUL
, tmp
, 0, tmp
, tmp
);
1187 emit_op1(p
, OPCODE_EX2
, fog
, WRITEMASK_X
, negate(tmp
));
1191 release_temp(p
, tmp
);
1194 /* results = incoming fog coords (compute fog per-fragment later)
1196 * KW: Is it really necessary to do anything in this case?
1197 * BP: Yes, we always need to compute the absolute value, unless
1198 * we want to push that down into the fragment program...
1200 GLboolean useabs
= GL_TRUE
;
1201 emit_op1(p
, useabs
? OPCODE_ABS
: OPCODE_MOV
, fog
, WRITEMASK_X
, input
);
1205 static void build_reflect_texgen( struct tnl_program
*p
,
1209 struct ureg normal
= get_eye_normal(p
);
1210 struct ureg eye_hat
= get_eye_position_normalized(p
);
1211 struct ureg tmp
= get_temp(p
);
1214 emit_op2(p
, OPCODE_DP3
, tmp
, 0, normal
, eye_hat
);
1216 emit_op2(p
, OPCODE_ADD
, tmp
, 0, tmp
, tmp
);
1218 emit_op3(p
, OPCODE_MAD
, dest
, writemask
, negate(tmp
), normal
, eye_hat
);
1220 release_temp(p
, tmp
);
1223 static void build_sphere_texgen( struct tnl_program
*p
,
1227 struct ureg normal
= get_eye_normal(p
);
1228 struct ureg eye_hat
= get_eye_position_normalized(p
);
1229 struct ureg tmp
= get_temp(p
);
1230 struct ureg half
= register_scalar_const(p
, .5);
1231 struct ureg r
= get_temp(p
);
1232 struct ureg inv_m
= get_temp(p
);
1233 struct ureg id
= get_identity_param(p
);
1235 /* Could share the above calculations, but it would be
1236 * a fairly odd state for someone to set (both sphere and
1237 * reflection active for different texture coordinate
1238 * components. Of course - if two texture units enable
1239 * reflect and/or sphere, things start to tilt in favour
1240 * of seperating this out:
1244 emit_op2(p
, OPCODE_DP3
, tmp
, 0, normal
, eye_hat
);
1246 emit_op2(p
, OPCODE_ADD
, tmp
, 0, tmp
, tmp
);
1248 emit_op3(p
, OPCODE_MAD
, r
, 0, negate(tmp
), normal
, eye_hat
);
1250 emit_op2(p
, OPCODE_ADD
, tmp
, 0, r
, swizzle(id
,X
,Y
,W
,Z
));
1251 /* rx^2 + ry^2 + (rz+1)^2 */
1252 emit_op2(p
, OPCODE_DP3
, tmp
, 0, tmp
, tmp
);
1254 emit_op1(p
, OPCODE_RSQ
, tmp
, 0, tmp
);
1256 emit_op2(p
, OPCODE_MUL
, inv_m
, 0, tmp
, half
);
1258 emit_op3(p
, OPCODE_MAD
, dest
, writemask
, r
, inv_m
, half
);
1260 release_temp(p
, tmp
);
1262 release_temp(p
, inv_m
);
1266 static void build_texture_transform( struct tnl_program
*p
)
1270 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
1272 if (!(p
->state
->fragprog_inputs_read
& FRAG_BIT_TEX(i
)))
1275 if (p
->state
->unit
[i
].texgen_enabled
||
1276 p
->state
->unit
[i
].texmat_enabled
) {
1278 GLuint texmat_enabled
= p
->state
->unit
[i
].texmat_enabled
;
1279 struct ureg out
= register_output(p
, VERT_RESULT_TEX0
+ i
);
1280 struct ureg out_texgen
= undef
;
1282 if (p
->state
->unit
[i
].texgen_enabled
) {
1283 GLuint copy_mask
= 0;
1284 GLuint sphere_mask
= 0;
1285 GLuint reflect_mask
= 0;
1286 GLuint normal_mask
= 0;
1290 out_texgen
= get_temp(p
);
1294 modes
[0] = p
->state
->unit
[i
].texgen_mode0
;
1295 modes
[1] = p
->state
->unit
[i
].texgen_mode1
;
1296 modes
[2] = p
->state
->unit
[i
].texgen_mode2
;
1297 modes
[3] = p
->state
->unit
[i
].texgen_mode3
;
1299 for (j
= 0; j
< 4; j
++) {
1301 case TXG_OBJ_LINEAR
: {
1302 struct ureg obj
= register_input(p
, VERT_ATTRIB_POS
);
1304 register_param3(p
, STATE_TEXGEN
, i
,
1305 STATE_TEXGEN_OBJECT_S
+ j
);
1307 emit_op2(p
, OPCODE_DP4
, out_texgen
, WRITEMASK_X
<< j
,
1311 case TXG_EYE_LINEAR
: {
1312 struct ureg eye
= get_eye_position(p
);
1314 register_param3(p
, STATE_TEXGEN
, i
,
1315 STATE_TEXGEN_EYE_S
+ j
);
1317 emit_op2(p
, OPCODE_DP4
, out_texgen
, WRITEMASK_X
<< j
,
1321 case TXG_SPHERE_MAP
:
1322 sphere_mask
|= WRITEMASK_X
<< j
;
1324 case TXG_REFLECTION_MAP
:
1325 reflect_mask
|= WRITEMASK_X
<< j
;
1327 case TXG_NORMAL_MAP
:
1328 normal_mask
|= WRITEMASK_X
<< j
;
1331 copy_mask
|= WRITEMASK_X
<< j
;
1338 build_sphere_texgen(p
, out_texgen
, sphere_mask
);
1342 build_reflect_texgen(p
, out_texgen
, reflect_mask
);
1346 struct ureg normal
= get_eye_normal(p
);
1347 emit_op1(p
, OPCODE_MOV
, out_texgen
, normal_mask
, normal
);
1351 struct ureg in
= register_input(p
, VERT_ATTRIB_TEX0
+i
);
1352 emit_op1(p
, OPCODE_MOV
, out_texgen
, copy_mask
, in
);
1356 if (texmat_enabled
) {
1357 struct ureg texmat
[4];
1358 struct ureg in
= (!is_undef(out_texgen
) ?
1360 register_input(p
, VERT_ATTRIB_TEX0
+i
));
1362 register_matrix_param5( p
, STATE_TEXTURE_MATRIX
, i
, 0, 3,
1364 emit_matrix_transform_vec4( p
, out
, texmat
, in
);
1367 register_matrix_param5( p
, STATE_TEXTURE_MATRIX
, i
, 0, 3,
1368 STATE_MATRIX_TRANSPOSE
, texmat
);
1369 emit_transpose_matrix_transform_vec4( p
, out
, texmat
, in
);
1376 emit_passthrough(p
, VERT_ATTRIB_TEX0
+i
, VERT_RESULT_TEX0
+i
);
1382 static void build_pointsize( struct tnl_program
*p
)
1384 struct ureg eye
= get_eye_position(p
);
1385 struct ureg state_size
= register_param1(p
, STATE_POINT_SIZE
);
1386 struct ureg state_attenuation
= register_param1(p
, STATE_POINT_ATTENUATION
);
1387 struct ureg out
= register_output(p
, VERT_RESULT_PSIZ
);
1388 struct ureg ut
= get_temp(p
);
1391 emit_op1(p
, OPCODE_ABS
, ut
, WRITEMASK_Y
, swizzle1(eye
, Z
));
1392 /* p1 + dist * (p2 + dist * p3); */
1393 emit_op3(p
, OPCODE_MAD
, ut
, WRITEMASK_X
, swizzle1(ut
, Y
),
1394 swizzle1(state_attenuation
, Z
), swizzle1(state_attenuation
, Y
));
1395 emit_op3(p
, OPCODE_MAD
, ut
, WRITEMASK_X
, swizzle1(ut
, Y
),
1396 ut
, swizzle1(state_attenuation
, X
));
1398 /* 1 / sqrt(factor) */
1399 emit_op1(p
, OPCODE_RSQ
, ut
, WRITEMASK_X
, ut
);
1402 /* out = pointSize / sqrt(factor) */
1403 emit_op2(p
, OPCODE_MUL
, out
, WRITEMASK_X
, ut
, state_size
);
1405 /* not sure, might make sense to do clamping here,
1406 but it's not done in t_vb_points neither */
1407 emit_op2(p
, OPCODE_MUL
, ut
, WRITEMASK_X
, ut
, state_size
);
1408 emit_op2(p
, OPCODE_MAX
, ut
, WRITEMASK_X
, ut
, swizzle1(state_size
, Y
));
1409 emit_op2(p
, OPCODE_MIN
, out
, WRITEMASK_X
, ut
, swizzle1(state_size
, Z
));
1412 release_temp(p
, ut
);
1416 * Emit constant point size.
1418 static void constant_pointsize( struct tnl_program
*p
)
1420 struct ureg state_size
= register_param1(p
, STATE_POINT_SIZE
);
1421 struct ureg out
= register_output(p
, VERT_RESULT_PSIZ
);
1422 emit_op1(p
, OPCODE_MOV
, out
, WRITEMASK_X
, state_size
);
1425 static void build_tnl_program( struct tnl_program
*p
)
1426 { /* Emit the program, starting with modelviewproject:
1430 /* Lighting calculations:
1432 if (p
->state
->fragprog_inputs_read
& (FRAG_BIT_COL0
|FRAG_BIT_COL1
)) {
1433 if (p
->state
->light_global_enabled
)
1436 if (p
->state
->fragprog_inputs_read
& FRAG_BIT_COL0
)
1437 emit_passthrough(p
, VERT_ATTRIB_COLOR0
, VERT_RESULT_COL0
);
1439 if (p
->state
->fragprog_inputs_read
& FRAG_BIT_COL1
)
1440 emit_passthrough(p
, VERT_ATTRIB_COLOR1
, VERT_RESULT_COL1
);
1444 if ((p
->state
->fragprog_inputs_read
& FRAG_BIT_FOGC
) ||
1445 p
->state
->fog_mode
!= FOG_NONE
)
1448 if (p
->state
->fragprog_inputs_read
& FRAG_BITS_TEX_ANY
)
1449 build_texture_transform(p
);
1451 if (p
->state
->point_attenuated
)
1455 constant_pointsize(p
);
1460 emit_op1(p
, OPCODE_END
, undef
, 0, undef
);
1465 _mesa_printf ("\n");
1471 create_new_program( const struct state_key
*key
,
1472 struct gl_vertex_program
*program
,
1475 struct tnl_program p
;
1477 _mesa_memset(&p
, 0, sizeof(p
));
1479 p
.program
= program
;
1480 p
.eye_position
= undef
;
1481 p
.eye_position_normalized
= undef
;
1482 p
.eye_normal
= undef
;
1486 if (max_temps
>= sizeof(int) * 8)
1487 p
.temp_reserved
= 0;
1489 p
.temp_reserved
= ~((1<<max_temps
)-1);
1491 p
.program
->Base
.Instructions
= _mesa_alloc_instructions(MAX_INSN
);
1492 p
.program
->Base
.String
= NULL
;
1493 p
.program
->Base
.NumInstructions
=
1494 p
.program
->Base
.NumTemporaries
=
1495 p
.program
->Base
.NumParameters
=
1496 p
.program
->Base
.NumAttributes
= p
.program
->Base
.NumAddressRegs
= 0;
1497 p
.program
->Base
.Parameters
= _mesa_new_parameter_list();
1498 p
.program
->Base
.InputsRead
= 0;
1499 p
.program
->Base
.OutputsWritten
= 0;
1501 build_tnl_program( &p
);
1506 * Return a vertex program which implements the current fixed-function
1507 * transform/lighting/texgen operations.
1508 * XXX move this into core mesa (main/)
1510 struct gl_vertex_program
*
1511 _mesa_get_fixed_func_vertex_program(GLcontext
*ctx
)
1513 struct gl_vertex_program
*prog
;
1514 struct state_key
*key
;
1516 /* Grab all the relevent state and put it in a single structure:
1518 key
= make_state_key(ctx
);
1520 /* Look for an already-prepared program for this state:
1522 prog
= (struct gl_vertex_program
*)
1523 _mesa_search_program_cache(ctx
->VertexProgram
.Cache
, key
, sizeof(*key
));
1526 /* OK, we'll have to build a new one */
1528 _mesa_printf("Build new TNL program\n");
1530 prog
= (struct gl_vertex_program
*)
1531 ctx
->Driver
.NewProgram(ctx
, GL_VERTEX_PROGRAM_ARB
, 0);
1535 create_new_program( key
, prog
,
1536 ctx
->Const
.VertexProgram
.MaxTemps
);
1539 if (ctx
->Driver
.ProgramStringNotify
)
1540 ctx
->Driver
.ProgramStringNotify( ctx
, GL_VERTEX_PROGRAM_ARB
,
1543 _mesa_program_cache_insert(ctx
, ctx
->VertexProgram
.Cache
,
1544 key
, sizeof(*key
), &prog
->Base
);