blob: 1e46d8c3754a3d77e74869adbe6d44ecd4d20e03 [file] [log] [blame]
Keith Whitwell15e75e02005-04-29 15:11:39 +00001/**************************************************************************
2 *
Brianf4a5ea22007-10-31 12:45:32 -06003 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
Keith Whitwell15e75e02005-04-29 15:11:39 +00004 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
Keith Whitwell15e75e02005-04-29 15:11:39 +000028#include "glheader.h"
29#include "macros.h"
30#include "enums.h"
Brianc223c6b2007-07-04 13:15:20 -060031#include "shader/prog_parameter.h"
Brianf4a5ea22007-10-31 12:45:32 -060032#include "shader/prog_cache.h"
Brianc223c6b2007-07-04 13:15:20 -060033#include "shader/prog_instruction.h"
34#include "shader/prog_print.h"
35#include "shader/prog_statevars.h"
Brian83fad682007-09-25 15:20:04 -060036#include "shader/programopt.h"
Keith Whitwell15e75e02005-04-29 15:11:39 +000037#include "texenvprogram.h"
38
Brian Paule998c342006-10-29 21:17:18 +000039/**
Briane69943e2007-10-23 10:23:01 -060040 * This MAX is probably a bit generous, but that's OK. There can be
41 * up to four instructions per texture unit (TEX + 3 for combine),
42 * then there's fog and specular add.
Brian Paule998c342006-10-29 21:17:18 +000043 */
Briane69943e2007-10-23 10:23:01 -060044#define MAX_INSTRUCTIONS ((MAX_TEXTURE_UNITS * 4) + 12)
Keith Whitwell15e75e02005-04-29 15:11:39 +000045
Keith Whitwell269e3892005-05-12 10:28:43 +000046#define DISASSEM (MESA_VERBOSE & VERBOSE_DISASSEM)
Keith Whitwell15e75e02005-04-29 15:11:39 +000047
Keith Whitwellce721142005-07-11 10:10:38 +000048struct mode_opt {
Brian Paul5d7b49f2005-11-19 23:12:20 +000049 GLuint Source:4;
50 GLuint Operand:3;
Keith Whitwellce721142005-07-11 10:10:38 +000051};
52
53struct state_key {
Brian Paul5d7b49f2005-11-19 23:12:20 +000054 GLbitfield enabled_units;
55 GLuint separate_specular:1;
56 GLuint fog_enabled:1;
57 GLuint fog_mode:2;
Keith Whitwellce721142005-07-11 10:10:38 +000058
59 struct {
Brian Paul5d7b49f2005-11-19 23:12:20 +000060 GLuint enabled:1;
61 GLuint source_index:3; /* one of TEXTURE_1D/2D/3D/CUBE/RECT_INDEX */
62 GLuint ScaleShiftRGB:2;
63 GLuint ScaleShiftA:2;
Keith Whitwellce721142005-07-11 10:10:38 +000064
Brian Paul5d7b49f2005-11-19 23:12:20 +000065 GLuint NumArgsRGB:2;
66 GLuint ModeRGB:4;
Keith Whitwellce721142005-07-11 10:10:38 +000067 struct mode_opt OptRGB[3];
68
Brian Paul5d7b49f2005-11-19 23:12:20 +000069 GLuint NumArgsA:2;
70 GLuint ModeA:4;
Keith Whitwellce721142005-07-11 10:10:38 +000071 struct mode_opt OptA[3];
72 } unit[8];
73};
74
75#define FOG_LINEAR 0
76#define FOG_EXP 1
77#define FOG_EXP2 2
78#define FOG_UNKNOWN 3
79
80static GLuint translate_fog_mode( GLenum mode )
81{
82 switch (mode) {
83 case GL_LINEAR: return FOG_LINEAR;
84 case GL_EXP: return FOG_EXP;
85 case GL_EXP2: return FOG_EXP2;
86 default: return FOG_UNKNOWN;
87 }
88}
89
90#define OPR_SRC_COLOR 0
91#define OPR_ONE_MINUS_SRC_COLOR 1
92#define OPR_SRC_ALPHA 2
93#define OPR_ONE_MINUS_SRC_ALPHA 3
94#define OPR_ZERO 4
95#define OPR_ONE 5
96#define OPR_UNKNOWN 7
97
98static GLuint translate_operand( GLenum operand )
99{
100 switch (operand) {
101 case GL_SRC_COLOR: return OPR_SRC_COLOR;
102 case GL_ONE_MINUS_SRC_COLOR: return OPR_ONE_MINUS_SRC_COLOR;
103 case GL_SRC_ALPHA: return OPR_SRC_ALPHA;
104 case GL_ONE_MINUS_SRC_ALPHA: return OPR_ONE_MINUS_SRC_ALPHA;
105 case GL_ZERO: return OPR_ZERO;
106 case GL_ONE: return OPR_ONE;
107 default: return OPR_UNKNOWN;
108 }
109}
110
111#define SRC_TEXTURE 0
112#define SRC_TEXTURE0 1
113#define SRC_TEXTURE1 2
114#define SRC_TEXTURE2 3
115#define SRC_TEXTURE3 4
116#define SRC_TEXTURE4 5
117#define SRC_TEXTURE5 6
118#define SRC_TEXTURE6 7
119#define SRC_TEXTURE7 8
120#define SRC_CONSTANT 9
121#define SRC_PRIMARY_COLOR 10
122#define SRC_PREVIOUS 11
123#define SRC_UNKNOWN 15
124
125static GLuint translate_source( GLenum src )
126{
127 switch (src) {
128 case GL_TEXTURE: return SRC_TEXTURE;
129 case GL_TEXTURE0:
130 case GL_TEXTURE1:
131 case GL_TEXTURE2:
132 case GL_TEXTURE3:
133 case GL_TEXTURE4:
134 case GL_TEXTURE5:
135 case GL_TEXTURE6:
136 case GL_TEXTURE7: return SRC_TEXTURE0 + (src - GL_TEXTURE0);
137 case GL_CONSTANT: return SRC_CONSTANT;
138 case GL_PRIMARY_COLOR: return SRC_PRIMARY_COLOR;
139 case GL_PREVIOUS: return SRC_PREVIOUS;
140 default: return SRC_UNKNOWN;
141 }
142}
143
144#define MODE_REPLACE 0
145#define MODE_MODULATE 1
146#define MODE_ADD 2
147#define MODE_ADD_SIGNED 3
148#define MODE_INTERPOLATE 4
149#define MODE_SUBTRACT 5
150#define MODE_DOT3_RGB 6
151#define MODE_DOT3_RGB_EXT 7
152#define MODE_DOT3_RGBA 8
153#define MODE_DOT3_RGBA_EXT 9
154#define MODE_MODULATE_ADD_ATI 10
155#define MODE_MODULATE_SIGNED_ADD_ATI 11
156#define MODE_MODULATE_SUBTRACT_ATI 12
157#define MODE_UNKNOWN 15
158
159static GLuint translate_mode( GLenum mode )
160{
161 switch (mode) {
162 case GL_REPLACE: return MODE_REPLACE;
163 case GL_MODULATE: return MODE_MODULATE;
164 case GL_ADD: return MODE_ADD;
165 case GL_ADD_SIGNED: return MODE_ADD_SIGNED;
166 case GL_INTERPOLATE: return MODE_INTERPOLATE;
167 case GL_SUBTRACT: return MODE_SUBTRACT;
168 case GL_DOT3_RGB: return MODE_DOT3_RGB;
169 case GL_DOT3_RGB_EXT: return MODE_DOT3_RGB_EXT;
170 case GL_DOT3_RGBA: return MODE_DOT3_RGBA;
171 case GL_DOT3_RGBA_EXT: return MODE_DOT3_RGBA_EXT;
172 case GL_MODULATE_ADD_ATI: return MODE_MODULATE_ADD_ATI;
173 case GL_MODULATE_SIGNED_ADD_ATI: return MODE_MODULATE_SIGNED_ADD_ATI;
174 case GL_MODULATE_SUBTRACT_ATI: return MODE_MODULATE_SUBTRACT_ATI;
175 default: return MODE_UNKNOWN;
176 }
177}
178
179#define TEXTURE_UNKNOWN_INDEX 7
Brian Paule00ac112005-09-15 05:00:45 +0000180static GLuint translate_tex_src_bit( GLbitfield bit )
Keith Whitwellce721142005-07-11 10:10:38 +0000181{
182 switch (bit) {
183 case TEXTURE_1D_BIT: return TEXTURE_1D_INDEX;
184 case TEXTURE_2D_BIT: return TEXTURE_2D_INDEX;
185 case TEXTURE_RECT_BIT: return TEXTURE_RECT_INDEX;
186 case TEXTURE_3D_BIT: return TEXTURE_3D_INDEX;
187 case TEXTURE_CUBE_BIT: return TEXTURE_CUBE_INDEX;
188 default: return TEXTURE_UNKNOWN_INDEX;
189 }
190}
191
Brian Paul22db5352005-11-19 23:45:10 +0000192/**
193 * Examine current texture environment state and generate a unique
194 * key to identify it.
195 */
Keith Whitwell8065c122006-05-22 16:09:27 +0000196static void make_state_key( GLcontext *ctx, struct state_key *key )
Keith Whitwellce721142005-07-11 10:10:38 +0000197{
Keith Whitwellce721142005-07-11 10:10:38 +0000198 GLuint i, j;
199
Keith Whitwell8065c122006-05-22 16:09:27 +0000200 memset(key, 0, sizeof(*key));
201
Keith Whitwellce721142005-07-11 10:10:38 +0000202 for (i=0;i<MAX_TEXTURE_UNITS;i++) {
Brian Pauld9736db2006-05-23 02:44:46 +0000203 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i];
Keith Whitwellce721142005-07-11 10:10:38 +0000204
205 if (!texUnit->_ReallyEnabled)
206 continue;
207
208 key->unit[i].enabled = 1;
209 key->enabled_units |= (1<<i);
210
211 key->unit[i].source_index =
212 translate_tex_src_bit(texUnit->_ReallyEnabled);
213
214 key->unit[i].NumArgsRGB = texUnit->_CurrentCombine->_NumArgsRGB;
215 key->unit[i].NumArgsA = texUnit->_CurrentCombine->_NumArgsA;
216
217 key->unit[i].ModeRGB =
218 translate_mode(texUnit->_CurrentCombine->ModeRGB);
219 key->unit[i].ModeA =
220 translate_mode(texUnit->_CurrentCombine->ModeA);
221
222 key->unit[i].ScaleShiftRGB = texUnit->_CurrentCombine->ScaleShiftRGB;
Keith Whitwell64da1612006-05-22 14:30:58 +0000223 key->unit[i].ScaleShiftA = texUnit->_CurrentCombine->ScaleShiftA;
Keith Whitwellce721142005-07-11 10:10:38 +0000224
225 for (j=0;j<3;j++) {
226 key->unit[i].OptRGB[j].Operand =
227 translate_operand(texUnit->_CurrentCombine->OperandRGB[j]);
228 key->unit[i].OptA[j].Operand =
229 translate_operand(texUnit->_CurrentCombine->OperandA[j]);
230 key->unit[i].OptRGB[j].Source =
231 translate_source(texUnit->_CurrentCombine->SourceRGB[j]);
232 key->unit[i].OptA[j].Source =
233 translate_source(texUnit->_CurrentCombine->SourceA[j]);
234 }
235 }
236
237 if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR)
238 key->separate_specular = 1;
239
240 if (ctx->Fog.Enabled) {
241 key->fog_enabled = 1;
242 key->fog_mode = translate_fog_mode(ctx->Fog.Mode);
243 }
Keith Whitwellce721142005-07-11 10:10:38 +0000244}
245
Keith Whitwell15e75e02005-04-29 15:11:39 +0000246/* Use uregs to represent registers internally, translate to Mesa's
247 * expected formats on emit.
248 *
249 * NOTE: These are passed by value extensively in this file rather
250 * than as usual by pointer reference. If this disturbs you, try
251 * remembering they are just 32bits in size.
252 *
253 * GCC is smart enough to deal with these dword-sized structures in
254 * much the same way as if I had defined them as dwords and was using
255 * macros to access and set the fields. This is much nicer and easier
256 * to evolve.
257 */
258struct ureg {
259 GLuint file:4;
260 GLuint idx:8;
261 GLuint negatebase:1;
262 GLuint abs:1;
263 GLuint negateabs:1;
264 GLuint swz:12;
265 GLuint pad:5;
266};
267
Brian Paul13abf912006-04-13 19:17:13 +0000268static const struct ureg undef = {
Alan Hourihane8d972652006-08-10 13:12:00 +0000269 PROGRAM_UNDEFINED,
Keith Whitwell15e75e02005-04-29 15:11:39 +0000270 ~0,
271 0,
272 0,
273 0,
274 0,
275 0
276};
277
Keith Whitwell15e75e02005-04-29 15:11:39 +0000278
Keith Whitwell15e75e02005-04-29 15:11:39 +0000279/* State used to build the fragment program:
280 */
281struct texenv_fragment_program {
Brian Paul122629f2006-07-20 16:49:57 +0000282 struct gl_fragment_program *program;
Keith Whitwell15e75e02005-04-29 15:11:39 +0000283 GLcontext *ctx;
Keith Whitwellce721142005-07-11 10:10:38 +0000284 struct state_key *state;
Keith Whitwell15e75e02005-04-29 15:11:39 +0000285
Brian Paulc8d17412005-12-14 03:06:16 +0000286 GLbitfield alu_temps; /* Track texture indirections, see spec. */
287 GLbitfield temps_output; /* Track texture indirections, see spec. */
288 GLbitfield temp_in_use; /* Tracks temporary regs which are in use. */
Keith Whitwell15e75e02005-04-29 15:11:39 +0000289 GLboolean error;
290
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000291 struct ureg src_texture[MAX_TEXTURE_UNITS];
Keith Whitwellce721142005-07-11 10:10:38 +0000292 /* Reg containing each texture unit's sampled texture color,
293 * else undef.
294 */
Keith Whitwell15e75e02005-04-29 15:11:39 +0000295
296 struct ureg src_previous; /* Reg containing color from previous
297 * stage. May need to be decl'd.
298 */
299
300 GLuint last_tex_stage; /* Number of last enabled texture unit */
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000301
302 struct ureg half;
303 struct ureg one;
304 struct ureg zero;
Keith Whitwell15e75e02005-04-29 15:11:39 +0000305};
306
307
308
309static struct ureg make_ureg(GLuint file, GLuint idx)
310{
311 struct ureg reg;
312 reg.file = file;
313 reg.idx = idx;
314 reg.negatebase = 0;
315 reg.abs = 0;
316 reg.negateabs = 0;
317 reg.swz = SWIZZLE_NOOP;
318 reg.pad = 0;
319 return reg;
320}
321
322static struct ureg swizzle( struct ureg reg, int x, int y, int z, int w )
323{
324 reg.swz = MAKE_SWIZZLE4(GET_SWZ(reg.swz, x),
325 GET_SWZ(reg.swz, y),
326 GET_SWZ(reg.swz, z),
327 GET_SWZ(reg.swz, w));
328
329 return reg;
330}
331
332static struct ureg swizzle1( struct ureg reg, int x )
333{
334 return swizzle(reg, x, x, x, x);
335}
336
Keith Whitwell6fe176a2005-05-23 08:08:43 +0000337static struct ureg negate( struct ureg reg )
338{
339 reg.negatebase ^= 1;
340 return reg;
341}
342
Keith Whitwell15e75e02005-04-29 15:11:39 +0000343static GLboolean is_undef( struct ureg reg )
344{
Alan Hourihane8d972652006-08-10 13:12:00 +0000345 return reg.file == PROGRAM_UNDEFINED;
Keith Whitwell15e75e02005-04-29 15:11:39 +0000346}
347
Keith Whitwellecb6bfc2005-05-10 08:58:44 +0000348
Keith Whitwell15e75e02005-04-29 15:11:39 +0000349static struct ureg get_temp( struct texenv_fragment_program *p )
350{
Brian Paul13abf912006-04-13 19:17:13 +0000351 GLint bit;
Keith Whitwellecb6bfc2005-05-10 08:58:44 +0000352
Keith Whitwellcf4f3c52005-05-16 12:15:01 +0000353 /* First try and reuse temps which have been used already:
Keith Whitwellecb6bfc2005-05-10 08:58:44 +0000354 */
Brian Paulb3aefd12005-09-19 20:12:32 +0000355 bit = _mesa_ffs( ~p->temp_in_use & p->alu_temps );
Keith Whitwellecb6bfc2005-05-10 08:58:44 +0000356
357 /* Then any unused temporary:
358 */
359 if (!bit)
Brian Paulb3aefd12005-09-19 20:12:32 +0000360 bit = _mesa_ffs( ~p->temp_in_use );
Keith Whitwellecb6bfc2005-05-10 08:58:44 +0000361
Keith Whitwell15e75e02005-04-29 15:11:39 +0000362 if (!bit) {
Brian Paulbfb5ea32005-07-19 18:20:04 +0000363 _mesa_problem(NULL, "%s: out of temporaries\n", __FILE__);
Brian Paulb3aefd12005-09-19 20:12:32 +0000364 _mesa_exit(1);
Keith Whitwell15e75e02005-04-29 15:11:39 +0000365 }
366
Brian Paul13abf912006-04-13 19:17:13 +0000367 if ((GLuint) bit > p->program->Base.NumTemporaries)
Keith Whitwellb5cbaf92005-09-08 18:45:03 +0000368 p->program->Base.NumTemporaries = bit;
369
Keith Whitwell93cd9232005-05-11 08:30:23 +0000370 p->temp_in_use |= 1<<(bit-1);
Keith Whitwell15e75e02005-04-29 15:11:39 +0000371 return make_ureg(PROGRAM_TEMPORARY, (bit-1));
372}
373
Keith Whitwellecb6bfc2005-05-10 08:58:44 +0000374static struct ureg get_tex_temp( struct texenv_fragment_program *p )
375{
376 int bit;
377
Keith Whitwellcf4f3c52005-05-16 12:15:01 +0000378 /* First try to find availble temp not previously used (to avoid
379 * starting a new texture indirection). According to the spec, the
380 * ~p->temps_output isn't necessary, but will keep it there for
381 * now:
Keith Whitwellecb6bfc2005-05-10 08:58:44 +0000382 */
Brian Paulb3aefd12005-09-19 20:12:32 +0000383 bit = _mesa_ffs( ~p->temp_in_use & ~p->alu_temps & ~p->temps_output );
Keith Whitwellecb6bfc2005-05-10 08:58:44 +0000384
385 /* Then any unused temporary:
386 */
Keith Whitwellcf4f3c52005-05-16 12:15:01 +0000387 if (!bit)
Brian Paulb3aefd12005-09-19 20:12:32 +0000388 bit = _mesa_ffs( ~p->temp_in_use );
Keith Whitwellecb6bfc2005-05-10 08:58:44 +0000389
390 if (!bit) {
Brian Paulbfb5ea32005-07-19 18:20:04 +0000391 _mesa_problem(NULL, "%s: out of temporaries\n", __FILE__);
Brian Paulb3aefd12005-09-19 20:12:32 +0000392 _mesa_exit(1);
Keith Whitwellecb6bfc2005-05-10 08:58:44 +0000393 }
394
Brian Paul13abf912006-04-13 19:17:13 +0000395 if ((GLuint) bit > p->program->Base.NumTemporaries)
Keith Whitwellb5cbaf92005-09-08 18:45:03 +0000396 p->program->Base.NumTemporaries = bit;
397
Keith Whitwell93cd9232005-05-11 08:30:23 +0000398 p->temp_in_use |= 1<<(bit-1);
Keith Whitwellecb6bfc2005-05-10 08:58:44 +0000399 return make_ureg(PROGRAM_TEMPORARY, (bit-1));
400}
401
Keith Whitwell15e75e02005-04-29 15:11:39 +0000402
Brianf18d4e02007-10-29 12:25:46 -0600403static void release_temps(GLcontext *ctx, struct texenv_fragment_program *p )
Keith Whitwell15e75e02005-04-29 15:11:39 +0000404{
Brianf18d4e02007-10-29 12:25:46 -0600405 GLuint max_temp = ctx->Const.FragmentProgram.MaxTemps;
Keith Whitwell93cd9232005-05-11 08:30:23 +0000406
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000407 /* KW: To support tex_env_crossbar, don't release the registers in
408 * temps_output.
409 */
Keith Whitwell93cd9232005-05-11 08:30:23 +0000410 if (max_temp >= sizeof(int) * 8)
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000411 p->temp_in_use = p->temps_output;
Keith Whitwell93cd9232005-05-11 08:30:23 +0000412 else
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000413 p->temp_in_use = ~((1<<max_temp)-1) | p->temps_output;
Keith Whitwell15e75e02005-04-29 15:11:39 +0000414}
415
416
Brian9fe3e2e2007-02-23 11:44:14 -0700417static struct ureg register_param5( struct texenv_fragment_program *p,
Keith Whitwellce721142005-07-11 10:10:38 +0000418 GLint s0,
419 GLint s1,
420 GLint s2,
421 GLint s3,
Brian9fe3e2e2007-02-23 11:44:14 -0700422 GLint s4)
Keith Whitwell15e75e02005-04-29 15:11:39 +0000423{
Brian9fe3e2e2007-02-23 11:44:14 -0700424 gl_state_index tokens[STATE_LENGTH];
Keith Whitwell47b29f52005-05-04 11:44:44 +0000425 GLuint idx;
426 tokens[0] = s0;
427 tokens[1] = s1;
428 tokens[2] = s2;
429 tokens[3] = s3;
430 tokens[4] = s4;
Brian Paulde997602005-11-12 17:53:14 +0000431 idx = _mesa_add_state_reference( p->program->Base.Parameters, tokens );
Keith Whitwell47b29f52005-05-04 11:44:44 +0000432 return make_ureg(PROGRAM_STATE_VAR, idx);
Keith Whitwell15e75e02005-04-29 15:11:39 +0000433}
434
Keith Whitwell47b29f52005-05-04 11:44:44 +0000435
Brian9fe3e2e2007-02-23 11:44:14 -0700436#define register_param1(p,s0) register_param5(p,s0,0,0,0,0)
437#define register_param2(p,s0,s1) register_param5(p,s0,s1,0,0,0)
438#define register_param3(p,s0,s1,s2) register_param5(p,s0,s1,s2,0,0)
439#define register_param4(p,s0,s1,s2,s3) register_param5(p,s0,s1,s2,s3,0)
Keith Whitwell47b29f52005-05-04 11:44:44 +0000440
441
442static struct ureg register_input( struct texenv_fragment_program *p, GLuint input )
443{
Brian Paulde997602005-11-12 17:53:14 +0000444 p->program->Base.InputsRead |= (1 << input);
Keith Whitwell47b29f52005-05-04 11:44:44 +0000445 return make_ureg(PROGRAM_INPUT, input);
446}
447
448
Brian Paul7e807512005-11-05 17:10:45 +0000449static void emit_arg( struct prog_src_register *reg,
Keith Whitwell15e75e02005-04-29 15:11:39 +0000450 struct ureg ureg )
451{
452 reg->File = ureg.file;
453 reg->Index = ureg.idx;
454 reg->Swizzle = ureg.swz;
Keith Whitwellf2802c42005-10-07 09:55:26 +0000455 reg->NegateBase = ureg.negatebase ? 0xf : 0x0;
Keith Whitwell15e75e02005-04-29 15:11:39 +0000456 reg->Abs = ureg.abs;
457 reg->NegateAbs = ureg.negateabs;
458}
459
Brian Paul7e807512005-11-05 17:10:45 +0000460static void emit_dst( struct prog_dst_register *dst,
Keith Whitwell15e75e02005-04-29 15:11:39 +0000461 struct ureg ureg, GLuint mask )
462{
463 dst->File = ureg.file;
464 dst->Index = ureg.idx;
465 dst->WriteMask = mask;
Brian112a1582007-10-23 10:54:50 -0600466 dst->CondMask = COND_TR; /* always pass cond test */
467 dst->CondSwizzle = SWIZZLE_NOOP;
Keith Whitwell15e75e02005-04-29 15:11:39 +0000468}
469
Brian Paul7e807512005-11-05 17:10:45 +0000470static struct prog_instruction *
Keith Whitwell15e75e02005-04-29 15:11:39 +0000471emit_op(struct texenv_fragment_program *p,
Brian Paul5d7b49f2005-11-19 23:12:20 +0000472 enum prog_opcode op,
Keith Whitwell15e75e02005-04-29 15:11:39 +0000473 struct ureg dest,
474 GLuint mask,
Brian Paul22db5352005-11-19 23:45:10 +0000475 GLboolean saturate,
Keith Whitwell15e75e02005-04-29 15:11:39 +0000476 struct ureg src0,
477 struct ureg src1,
478 struct ureg src2 )
479{
Keith Whitwell47b29f52005-05-04 11:44:44 +0000480 GLuint nr = p->program->Base.NumInstructions++;
Brian Paulde997602005-11-12 17:53:14 +0000481 struct prog_instruction *inst = &p->program->Base.Instructions[nr];
Keith Whitwell15e75e02005-04-29 15:11:39 +0000482
Briane69943e2007-10-23 10:23:01 -0600483 assert(nr < MAX_INSTRUCTIONS);
484
Brian Pauld6272e02006-10-29 18:03:16 +0000485 _mesa_init_instructions(inst, 1);
Keith Whitwell15e75e02005-04-29 15:11:39 +0000486 inst->Opcode = op;
487
Keith Whitwell47b29f52005-05-04 11:44:44 +0000488 emit_arg( &inst->SrcReg[0], src0 );
489 emit_arg( &inst->SrcReg[1], src1 );
490 emit_arg( &inst->SrcReg[2], src2 );
Keith Whitwell15e75e02005-04-29 15:11:39 +0000491
Brian Paule31ac052005-11-20 17:52:40 +0000492 inst->SaturateMode = saturate ? SATURATE_ZERO_ONE : SATURATE_OFF;
Keith Whitwell15e75e02005-04-29 15:11:39 +0000493
494 emit_dst( &inst->DstReg, dest, mask );
495
Keith Whitwellcf4f3c52005-05-16 12:15:01 +0000496 /* Accounting for indirection tracking:
497 */
498 if (dest.file == PROGRAM_TEMPORARY)
499 p->temps_output |= 1 << dest.idx;
500
Keith Whitwell15e75e02005-04-29 15:11:39 +0000501 return inst;
502}
503
504
505static struct ureg emit_arith( struct texenv_fragment_program *p,
Brian Paul5d7b49f2005-11-19 23:12:20 +0000506 enum prog_opcode op,
Keith Whitwell47b29f52005-05-04 11:44:44 +0000507 struct ureg dest,
508 GLuint mask,
Brian Paul22db5352005-11-19 23:45:10 +0000509 GLboolean saturate,
Keith Whitwell47b29f52005-05-04 11:44:44 +0000510 struct ureg src0,
511 struct ureg src1,
512 struct ureg src2 )
Keith Whitwell15e75e02005-04-29 15:11:39 +0000513{
514 emit_op(p, op, dest, mask, saturate, src0, src1, src2);
515
Keith Whitwellcf4f3c52005-05-16 12:15:01 +0000516 /* Accounting for indirection tracking:
517 */
518 if (src0.file == PROGRAM_TEMPORARY)
519 p->alu_temps |= 1 << src0.idx;
520
521 if (!is_undef(src1) && src1.file == PROGRAM_TEMPORARY)
522 p->alu_temps |= 1 << src1.idx;
523
524 if (!is_undef(src2) && src2.file == PROGRAM_TEMPORARY)
525 p->alu_temps |= 1 << src2.idx;
526
527 if (dest.file == PROGRAM_TEMPORARY)
528 p->alu_temps |= 1 << dest.idx;
529
Brian21f99792007-01-09 11:00:21 -0700530 p->program->Base.NumAluInstructions++;
Keith Whitwell15e75e02005-04-29 15:11:39 +0000531 return dest;
532}
533
534static struct ureg emit_texld( struct texenv_fragment_program *p,
Brian Paul5d7b49f2005-11-19 23:12:20 +0000535 enum prog_opcode op,
Keith Whitwellce721142005-07-11 10:10:38 +0000536 struct ureg dest,
537 GLuint destmask,
538 GLuint tex_unit,
539 GLuint tex_idx,
540 struct ureg coord )
Keith Whitwell15e75e02005-04-29 15:11:39 +0000541{
Brian Paul7e807512005-11-05 17:10:45 +0000542 struct prog_instruction *inst = emit_op( p, op,
Keith Whitwell15e75e02005-04-29 15:11:39 +0000543 dest, destmask,
Brian Paul22db5352005-11-19 23:45:10 +0000544 GL_FALSE, /* don't saturate? */
Keith Whitwell15e75e02005-04-29 15:11:39 +0000545 coord, /* arg 0? */
546 undef,
547 undef);
548
Brian Paul7e807512005-11-05 17:10:45 +0000549 inst->TexSrcTarget = tex_idx;
Keith Whitwell15e75e02005-04-29 15:11:39 +0000550 inst->TexSrcUnit = tex_unit;
551
Brian21f99792007-01-09 11:00:21 -0700552 p->program->Base.NumTexInstructions++;
Keith Whitwell15e75e02005-04-29 15:11:39 +0000553
Keith Whitwellcf4f3c52005-05-16 12:15:01 +0000554 /* Is this a texture indirection?
555 */
556 if ((coord.file == PROGRAM_TEMPORARY &&
557 (p->temps_output & (1<<coord.idx))) ||
558 (dest.file == PROGRAM_TEMPORARY &&
559 (p->alu_temps & (1<<dest.idx)))) {
Brian21f99792007-01-09 11:00:21 -0700560 p->program->Base.NumTexIndirections++;
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000561 p->temps_output = 1<<coord.idx;
Keith Whitwellcf4f3c52005-05-16 12:15:01 +0000562 p->alu_temps = 0;
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000563 assert(0); /* KW: texture env crossbar */
Keith Whitwell15e75e02005-04-29 15:11:39 +0000564 }
565
566 return dest;
567}
568
569
Keith Whitwell47b29f52005-05-04 11:44:44 +0000570static struct ureg register_const4f( struct texenv_fragment_program *p,
Keith Whitwellce721142005-07-11 10:10:38 +0000571 GLfloat s0,
572 GLfloat s1,
573 GLfloat s2,
574 GLfloat s3)
Keith Whitwell15e75e02005-04-29 15:11:39 +0000575{
Keith Whitwell47b29f52005-05-04 11:44:44 +0000576 GLfloat values[4];
Briana90046f2006-12-15 10:07:26 -0700577 GLuint idx, swizzle;
Keith Whitwell47b29f52005-05-04 11:44:44 +0000578 values[0] = s0;
579 values[1] = s1;
580 values[2] = s2;
581 values[3] = s3;
Briana90046f2006-12-15 10:07:26 -0700582 idx = _mesa_add_unnamed_constant( p->program->Base.Parameters, values, 4,
583 &swizzle );
584 ASSERT(swizzle == SWIZZLE_NOOP);
Keith Whitwell47b29f52005-05-04 11:44:44 +0000585 return make_ureg(PROGRAM_STATE_VAR, idx);
Keith Whitwell15e75e02005-04-29 15:11:39 +0000586}
587
Keith Whitwelle4902422005-05-11 15:16:35 +0000588#define register_scalar_const(p, s0) register_const4f(p, s0, s0, s0, s0)
Keith Whitwell47b29f52005-05-04 11:44:44 +0000589#define register_const1f(p, s0) register_const4f(p, s0, 0, 0, 1)
590#define register_const2f(p, s0, s1) register_const4f(p, s0, s1, 0, 1)
591#define register_const3f(p, s0, s1, s2) register_const4f(p, s0, s1, s2, 1)
Keith Whitwell15e75e02005-04-29 15:11:39 +0000592
593
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000594static struct ureg get_one( struct texenv_fragment_program *p )
595{
596 if (is_undef(p->one))
597 p->one = register_scalar_const(p, 1.0);
598 return p->one;
599}
600
601static struct ureg get_half( struct texenv_fragment_program *p )
602{
603 if (is_undef(p->half))
Aapo Tahkola4dd8a892006-01-24 20:24:06 +0000604 p->half = register_scalar_const(p, 0.5);
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000605 return p->half;
606}
607
608static struct ureg get_zero( struct texenv_fragment_program *p )
609{
610 if (is_undef(p->zero))
Aapo Tahkola4dd8a892006-01-24 20:24:06 +0000611 p->zero = register_scalar_const(p, 0.0);
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000612 return p->zero;
613}
614
Keith Whitwell15e75e02005-04-29 15:11:39 +0000615
Keith Whitwell15e75e02005-04-29 15:11:39 +0000616static void program_error( struct texenv_fragment_program *p, const char *msg )
617{
Brian Paulbfb5ea32005-07-19 18:20:04 +0000618 _mesa_problem(NULL, msg);
Keith Whitwell15e75e02005-04-29 15:11:39 +0000619 p->error = 1;
620}
621
Keith Whitwell15e75e02005-04-29 15:11:39 +0000622static struct ureg get_source( struct texenv_fragment_program *p,
Keith Whitwellce721142005-07-11 10:10:38 +0000623 GLuint src, GLuint unit )
Keith Whitwell15e75e02005-04-29 15:11:39 +0000624{
625 switch (src) {
Keith Whitwellce721142005-07-11 10:10:38 +0000626 case SRC_TEXTURE:
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000627 assert(!is_undef(p->src_texture[unit]));
628 return p->src_texture[unit];
Keith Whitwell15e75e02005-04-29 15:11:39 +0000629
Keith Whitwellce721142005-07-11 10:10:38 +0000630 case SRC_TEXTURE0:
631 case SRC_TEXTURE1:
632 case SRC_TEXTURE2:
633 case SRC_TEXTURE3:
634 case SRC_TEXTURE4:
635 case SRC_TEXTURE5:
636 case SRC_TEXTURE6:
637 case SRC_TEXTURE7:
638 assert(!is_undef(p->src_texture[src - SRC_TEXTURE0]));
639 return p->src_texture[src - SRC_TEXTURE0];
Keith Whitwell15e75e02005-04-29 15:11:39 +0000640
Keith Whitwellce721142005-07-11 10:10:38 +0000641 case SRC_CONSTANT:
Keith Whitwell47b29f52005-05-04 11:44:44 +0000642 return register_param2(p, STATE_TEXENV_COLOR, unit);
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000643
Keith Whitwellce721142005-07-11 10:10:38 +0000644 case SRC_PRIMARY_COLOR:
Keith Whitwell47b29f52005-05-04 11:44:44 +0000645 return register_input(p, FRAG_ATTRIB_COL0);
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000646
Keith Whitwellce721142005-07-11 10:10:38 +0000647 case SRC_PREVIOUS:
648 default:
Keith Whitwell47b29f52005-05-04 11:44:44 +0000649 if (is_undef(p->src_previous))
650 return register_input(p, FRAG_ATTRIB_COL0);
651 else
652 return p->src_previous;
Keith Whitwell15e75e02005-04-29 15:11:39 +0000653 }
654}
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000655
Keith Whitwell15e75e02005-04-29 15:11:39 +0000656static struct ureg emit_combine_source( struct texenv_fragment_program *p,
Keith Whitwellce721142005-07-11 10:10:38 +0000657 GLuint mask,
658 GLuint unit,
659 GLuint source,
660 GLuint operand )
Keith Whitwell15e75e02005-04-29 15:11:39 +0000661{
662 struct ureg arg, src, one;
663
664 src = get_source(p, source, unit);
665
666 switch (operand) {
Keith Whitwellce721142005-07-11 10:10:38 +0000667 case OPR_ONE_MINUS_SRC_COLOR:
Keith Whitwell15e75e02005-04-29 15:11:39 +0000668 /* Get unused tmp,
669 * Emit tmp = 1.0 - arg.xyzw
670 */
671 arg = get_temp( p );
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000672 one = get_one( p );
Brian Paul7e807512005-11-05 17:10:45 +0000673 return emit_arith( p, OPCODE_SUB, arg, mask, 0, one, src, undef);
Keith Whitwell15e75e02005-04-29 15:11:39 +0000674
Keith Whitwellce721142005-07-11 10:10:38 +0000675 case OPR_SRC_ALPHA:
Keith Whitwell15e75e02005-04-29 15:11:39 +0000676 if (mask == WRITEMASK_W)
677 return src;
678 else
Brian Paul22db5352005-11-19 23:45:10 +0000679 return swizzle1( src, SWIZZLE_W );
Keith Whitwellce721142005-07-11 10:10:38 +0000680 case OPR_ONE_MINUS_SRC_ALPHA:
Keith Whitwell15e75e02005-04-29 15:11:39 +0000681 /* Get unused tmp,
682 * Emit tmp = 1.0 - arg.wwww
683 */
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000684 arg = get_temp(p);
685 one = get_one(p);
Brian Paul7e807512005-11-05 17:10:45 +0000686 return emit_arith(p, OPCODE_SUB, arg, mask, 0,
Brian Paul22db5352005-11-19 23:45:10 +0000687 one, swizzle1(src, SWIZZLE_W), undef);
Keith Whitwellce721142005-07-11 10:10:38 +0000688 case OPR_ZERO:
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000689 return get_zero(p);
Keith Whitwellce721142005-07-11 10:10:38 +0000690 case OPR_ONE:
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000691 return get_one(p);
Keith Whitwellce721142005-07-11 10:10:38 +0000692 case OPR_SRC_COLOR:
Keith Whitwell15e75e02005-04-29 15:11:39 +0000693 default:
694 return src;
695 }
696}
697
Keith Whitwellce721142005-07-11 10:10:38 +0000698static GLboolean args_match( struct state_key *key, GLuint unit )
Keith Whitwell15e75e02005-04-29 15:11:39 +0000699{
Brian Paul22db5352005-11-19 23:45:10 +0000700 GLuint i, nr = key->unit[unit].NumArgsRGB;
Keith Whitwell15e75e02005-04-29 15:11:39 +0000701
702 for (i = 0 ; i < nr ; i++) {
Keith Whitwellce721142005-07-11 10:10:38 +0000703 if (key->unit[unit].OptA[i].Source != key->unit[unit].OptRGB[i].Source)
Keith Whitwell15e75e02005-04-29 15:11:39 +0000704 return GL_FALSE;
705
Keith Whitwellce721142005-07-11 10:10:38 +0000706 switch(key->unit[unit].OptA[i].Operand) {
707 case OPR_SRC_ALPHA:
708 switch(key->unit[unit].OptRGB[i].Operand) {
709 case OPR_SRC_COLOR:
710 case OPR_SRC_ALPHA:
Keith Whitwell15e75e02005-04-29 15:11:39 +0000711 break;
712 default:
713 return GL_FALSE;
714 }
715 break;
Keith Whitwellce721142005-07-11 10:10:38 +0000716 case OPR_ONE_MINUS_SRC_ALPHA:
717 switch(key->unit[unit].OptRGB[i].Operand) {
718 case OPR_ONE_MINUS_SRC_COLOR:
719 case OPR_ONE_MINUS_SRC_ALPHA:
Keith Whitwell15e75e02005-04-29 15:11:39 +0000720 break;
721 default:
722 return GL_FALSE;
723 }
724 break;
725 default:
726 return GL_FALSE; /* impossible */
727 }
728 }
729
730 return GL_TRUE;
731}
732
Keith Whitwell15e75e02005-04-29 15:11:39 +0000733static struct ureg emit_combine( struct texenv_fragment_program *p,
Keith Whitwellce721142005-07-11 10:10:38 +0000734 struct ureg dest,
735 GLuint mask,
Brian Paul22db5352005-11-19 23:45:10 +0000736 GLboolean saturate,
Keith Whitwellce721142005-07-11 10:10:38 +0000737 GLuint unit,
738 GLuint nr,
739 GLuint mode,
Brian Pauld9736db2006-05-23 02:44:46 +0000740 const struct mode_opt *opt)
Keith Whitwell15e75e02005-04-29 15:11:39 +0000741{
Keith Whitwell15e75e02005-04-29 15:11:39 +0000742 struct ureg src[3];
Keith Whitwellcf4f3c52005-05-16 12:15:01 +0000743 struct ureg tmp, half;
Brian Paul22db5352005-11-19 23:45:10 +0000744 GLuint i;
Keith Whitwell15e75e02005-04-29 15:11:39 +0000745
Brian Paul00630842005-12-12 15:27:55 +0000746 tmp = undef; /* silence warning (bug 5318) */
747
Keith Whitwell15e75e02005-04-29 15:11:39 +0000748 for (i = 0; i < nr; i++)
Keith Whitwellce721142005-07-11 10:10:38 +0000749 src[i] = emit_combine_source( p, mask, unit, opt[i].Source, opt[i].Operand );
Keith Whitwell15e75e02005-04-29 15:11:39 +0000750
751 switch (mode) {
Keith Whitwellce721142005-07-11 10:10:38 +0000752 case MODE_REPLACE:
Keith Whitwell15e75e02005-04-29 15:11:39 +0000753 if (mask == WRITEMASK_XYZW && !saturate)
754 return src[0];
755 else
Brian Paul7e807512005-11-05 17:10:45 +0000756 return emit_arith( p, OPCODE_MOV, dest, mask, saturate, src[0], undef, undef );
Keith Whitwellce721142005-07-11 10:10:38 +0000757 case MODE_MODULATE:
Brian Paul7e807512005-11-05 17:10:45 +0000758 return emit_arith( p, OPCODE_MUL, dest, mask, saturate,
Keith Whitwell6fe176a2005-05-23 08:08:43 +0000759 src[0], src[1], undef );
Keith Whitwellce721142005-07-11 10:10:38 +0000760 case MODE_ADD:
Brian Paul7e807512005-11-05 17:10:45 +0000761 return emit_arith( p, OPCODE_ADD, dest, mask, saturate,
Keith Whitwell6fe176a2005-05-23 08:08:43 +0000762 src[0], src[1], undef );
Keith Whitwellce721142005-07-11 10:10:38 +0000763 case MODE_ADD_SIGNED:
Keith Whitwell15e75e02005-04-29 15:11:39 +0000764 /* tmp = arg0 + arg1
Keith Whitwellcf4f3c52005-05-16 12:15:01 +0000765 * result = tmp - .5
Keith Whitwell15e75e02005-04-29 15:11:39 +0000766 */
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000767 half = get_half(p);
Jerome Glisse99da2d32006-01-24 23:04:51 +0000768 tmp = get_temp( p );
Brian Paul7e807512005-11-05 17:10:45 +0000769 emit_arith( p, OPCODE_ADD, tmp, mask, 0, src[0], src[1], undef );
770 emit_arith( p, OPCODE_SUB, dest, mask, saturate, tmp, half, undef );
Keith Whitwell15e75e02005-04-29 15:11:39 +0000771 return dest;
Keith Whitwellce721142005-07-11 10:10:38 +0000772 case MODE_INTERPOLATE:
Keith Whitwell15e75e02005-04-29 15:11:39 +0000773 /* Arg0 * (Arg2) + Arg1 * (1-Arg2) -- note arguments are reordered:
774 */
Brian Paul7e807512005-11-05 17:10:45 +0000775 return emit_arith( p, OPCODE_LRP, dest, mask, saturate, src[2], src[0], src[1] );
Keith Whitwell15e75e02005-04-29 15:11:39 +0000776
Keith Whitwellce721142005-07-11 10:10:38 +0000777 case MODE_SUBTRACT:
Brian Paul7e807512005-11-05 17:10:45 +0000778 return emit_arith( p, OPCODE_SUB, dest, mask, saturate, src[0], src[1], undef );
Keith Whitwell15e75e02005-04-29 15:11:39 +0000779
Keith Whitwellce721142005-07-11 10:10:38 +0000780 case MODE_DOT3_RGBA:
781 case MODE_DOT3_RGBA_EXT:
782 case MODE_DOT3_RGB_EXT:
783 case MODE_DOT3_RGB: {
Keith Whitwell15e75e02005-04-29 15:11:39 +0000784 struct ureg tmp0 = get_temp( p );
785 struct ureg tmp1 = get_temp( p );
Keith Whitwelle4902422005-05-11 15:16:35 +0000786 struct ureg neg1 = register_scalar_const(p, -1);
787 struct ureg two = register_scalar_const(p, 2);
Keith Whitwell15e75e02005-04-29 15:11:39 +0000788
789 /* tmp0 = 2*src0 - 1
790 * tmp1 = 2*src1 - 1
791 *
792 * dst = tmp0 dot3 tmp1
793 */
Brian Paul7e807512005-11-05 17:10:45 +0000794 emit_arith( p, OPCODE_MAD, tmp0, WRITEMASK_XYZW, 0,
Keith Whitwell6fe176a2005-05-23 08:08:43 +0000795 two, src[0], neg1);
Keith Whitwell15e75e02005-04-29 15:11:39 +0000796
Brian Paulaa206952005-09-16 18:14:24 +0000797 if (_mesa_memcmp(&src[0], &src[1], sizeof(struct ureg)) == 0)
Keith Whitwell15e75e02005-04-29 15:11:39 +0000798 tmp1 = tmp0;
799 else
Brian Paul7e807512005-11-05 17:10:45 +0000800 emit_arith( p, OPCODE_MAD, tmp1, WRITEMASK_XYZW, 0,
Keith Whitwell6fe176a2005-05-23 08:08:43 +0000801 two, src[1], neg1);
Brian Paul7e807512005-11-05 17:10:45 +0000802 emit_arith( p, OPCODE_DP3, dest, mask, saturate, tmp0, tmp1, undef);
Keith Whitwell15e75e02005-04-29 15:11:39 +0000803 return dest;
804 }
Keith Whitwellce721142005-07-11 10:10:38 +0000805 case MODE_MODULATE_ADD_ATI:
Keith Whitwell6fe176a2005-05-23 08:08:43 +0000806 /* Arg0 * Arg2 + Arg1 */
Brian Paul7e807512005-11-05 17:10:45 +0000807 return emit_arith( p, OPCODE_MAD, dest, mask, saturate,
Keith Whitwell6fe176a2005-05-23 08:08:43 +0000808 src[0], src[2], src[1] );
Keith Whitwellce721142005-07-11 10:10:38 +0000809 case MODE_MODULATE_SIGNED_ADD_ATI: {
Keith Whitwell6fe176a2005-05-23 08:08:43 +0000810 /* Arg0 * Arg2 + Arg1 - 0.5 */
811 struct ureg tmp0 = get_temp(p);
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000812 half = get_half(p);
Brian Paul7e807512005-11-05 17:10:45 +0000813 emit_arith( p, OPCODE_MAD, tmp0, mask, 0, src[0], src[2], src[1] );
814 emit_arith( p, OPCODE_SUB, dest, mask, saturate, tmp0, half, undef );
Keith Whitwell6fe176a2005-05-23 08:08:43 +0000815 return dest;
816 }
Keith Whitwellce721142005-07-11 10:10:38 +0000817 case MODE_MODULATE_SUBTRACT_ATI:
Keith Whitwell6fe176a2005-05-23 08:08:43 +0000818 /* Arg0 * Arg2 - Arg1 */
Brian Paul7e807512005-11-05 17:10:45 +0000819 emit_arith( p, OPCODE_MAD, dest, mask, 0, src[0], src[2], negate(src[1]) );
Keith Whitwell6fe176a2005-05-23 08:08:43 +0000820 return dest;
Keith Whitwell15e75e02005-04-29 15:11:39 +0000821 default:
822 return src[0];
823 }
824}
825
Keith Whitwell15e75e02005-04-29 15:11:39 +0000826
Brian Paul22db5352005-11-19 23:45:10 +0000827/**
828 * Generate instructions for one texture unit's env/combiner mode.
829 */
830static struct ureg
831emit_texenv(struct texenv_fragment_program *p, GLuint unit)
Keith Whitwell15e75e02005-04-29 15:11:39 +0000832{
Keith Whitwellce721142005-07-11 10:10:38 +0000833 struct state_key *key = p->state;
Brian Paul22db5352005-11-19 23:45:10 +0000834 GLboolean saturate = (unit < p->last_tex_stage);
Keith Whitwell15e75e02005-04-29 15:11:39 +0000835 GLuint rgb_shift, alpha_shift;
836 struct ureg out, shift;
Keith Whitwellcf4f3c52005-05-16 12:15:01 +0000837 struct ureg dest;
Keith Whitwell15e75e02005-04-29 15:11:39 +0000838
Keith Whitwellce721142005-07-11 10:10:38 +0000839 if (!key->unit[unit].enabled) {
840 return get_source(p, SRC_PREVIOUS, 0);
Keith Whitwell15e75e02005-04-29 15:11:39 +0000841 }
Keith Whitwellce721142005-07-11 10:10:38 +0000842
843 switch (key->unit[unit].ModeRGB) {
844 case MODE_DOT3_RGB_EXT:
845 alpha_shift = key->unit[unit].ScaleShiftA;
Keith Whitwell15e75e02005-04-29 15:11:39 +0000846 rgb_shift = 0;
847 break;
Keith Whitwellce721142005-07-11 10:10:38 +0000848 case MODE_DOT3_RGBA_EXT:
Keith Whitwell15e75e02005-04-29 15:11:39 +0000849 alpha_shift = 0;
850 rgb_shift = 0;
851 break;
Keith Whitwell15e75e02005-04-29 15:11:39 +0000852 default:
Keith Whitwellce721142005-07-11 10:10:38 +0000853 rgb_shift = key->unit[unit].ScaleShiftRGB;
854 alpha_shift = key->unit[unit].ScaleShiftA;
Keith Whitwell15e75e02005-04-29 15:11:39 +0000855 break;
856 }
Keith Whitwellce721142005-07-11 10:10:38 +0000857
Keith Whitwellcf4f3c52005-05-16 12:15:01 +0000858 /* If this is the very last calculation, emit direct to output reg:
859 */
Keith Whitwellce721142005-07-11 10:10:38 +0000860 if (key->separate_specular ||
Keith Whitwellcf4f3c52005-05-16 12:15:01 +0000861 unit != p->last_tex_stage ||
862 alpha_shift ||
863 rgb_shift)
864 dest = get_temp( p );
865 else
Brian Paul90ebb582005-11-02 18:06:12 +0000866 dest = make_ureg(PROGRAM_OUTPUT, FRAG_RESULT_COLR);
Keith Whitwell15e75e02005-04-29 15:11:39 +0000867
868 /* Emit the RGB and A combine ops
869 */
Keith Whitwellce721142005-07-11 10:10:38 +0000870 if (key->unit[unit].ModeRGB == key->unit[unit].ModeA &&
871 args_match(key, unit)) {
Keith Whitwell15e75e02005-04-29 15:11:39 +0000872 out = emit_combine( p, dest, WRITEMASK_XYZW, saturate,
873 unit,
Keith Whitwellce721142005-07-11 10:10:38 +0000874 key->unit[unit].NumArgsRGB,
875 key->unit[unit].ModeRGB,
876 key->unit[unit].OptRGB);
Keith Whitwell15e75e02005-04-29 15:11:39 +0000877 }
Keith Whitwellce721142005-07-11 10:10:38 +0000878 else if (key->unit[unit].ModeRGB == MODE_DOT3_RGBA_EXT ||
Roland Scheidegger9a451762007-07-03 14:27:41 +0200879 key->unit[unit].ModeRGB == MODE_DOT3_RGBA) {
Keith Whitwell15e75e02005-04-29 15:11:39 +0000880
881 out = emit_combine( p, dest, WRITEMASK_XYZW, saturate,
882 unit,
Keith Whitwellce721142005-07-11 10:10:38 +0000883 key->unit[unit].NumArgsRGB,
884 key->unit[unit].ModeRGB,
885 key->unit[unit].OptRGB);
Keith Whitwell15e75e02005-04-29 15:11:39 +0000886 }
887 else {
888 /* Need to do something to stop from re-emitting identical
889 * argument calculations here:
890 */
891 out = emit_combine( p, dest, WRITEMASK_XYZ, saturate,
892 unit,
Keith Whitwellce721142005-07-11 10:10:38 +0000893 key->unit[unit].NumArgsRGB,
894 key->unit[unit].ModeRGB,
895 key->unit[unit].OptRGB);
Keith Whitwell15e75e02005-04-29 15:11:39 +0000896 out = emit_combine( p, dest, WRITEMASK_W, saturate,
897 unit,
Keith Whitwellce721142005-07-11 10:10:38 +0000898 key->unit[unit].NumArgsA,
899 key->unit[unit].ModeA,
900 key->unit[unit].OptA);
Keith Whitwell15e75e02005-04-29 15:11:39 +0000901 }
902
903 /* Deal with the final shift:
904 */
905 if (alpha_shift || rgb_shift) {
906 if (rgb_shift == alpha_shift) {
Keith Whitwelle4902422005-05-11 15:16:35 +0000907 shift = register_scalar_const(p, 1<<rgb_shift);
Keith Whitwell15e75e02005-04-29 15:11:39 +0000908 }
909 else {
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000910 shift = register_const4f(p,
911 1<<rgb_shift,
912 1<<rgb_shift,
913 1<<rgb_shift,
914 1<<alpha_shift);
Keith Whitwell15e75e02005-04-29 15:11:39 +0000915 }
Brian Paul7e807512005-11-05 17:10:45 +0000916 return emit_arith( p, OPCODE_MUL, dest, WRITEMASK_XYZW,
Keith Whitwell15e75e02005-04-29 15:11:39 +0000917 saturate, out, shift, undef );
918 }
919 else
920 return out;
921}
922
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000923
Brian Paul22db5352005-11-19 23:45:10 +0000924/**
925 * Generate instruction for getting a texture source term.
926 */
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000927static void load_texture( struct texenv_fragment_program *p, GLuint unit )
928{
929 if (is_undef(p->src_texture[unit])) {
Keith Whitwellce721142005-07-11 10:10:38 +0000930 GLuint dim = p->state->unit[unit].source_index;
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000931 struct ureg texcoord = register_input(p, FRAG_ATTRIB_TEX0+unit);
932 struct ureg tmp = get_tex_temp( p );
933
Brian Paulbfb5ea32005-07-19 18:20:04 +0000934 if (dim == TEXTURE_UNKNOWN_INDEX)
935 program_error(p, "TexSrcBit");
Keith Whitwellce721142005-07-11 10:10:38 +0000936
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000937 /* TODO: Use D0_MASK_XY where possible.
938 */
Brian1e3b07f2007-12-14 11:16:49 -0700939 if (p->state->unit[unit].enabled) {
Aapo Tahkolab8915342006-03-28 10:26:34 +0000940 p->src_texture[unit] = emit_texld( p, OPCODE_TXP,
941 tmp, WRITEMASK_XYZW,
942 unit, dim, texcoord );
Brian1e3b07f2007-12-14 11:16:49 -0700943 p->program->Base.SamplersUsed |= (1 << unit);
944 }
Aapo Tahkolab8915342006-03-28 10:26:34 +0000945 else
946 p->src_texture[unit] = get_zero(p);
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000947 }
948}
949
Keith Whitwell241b6b72005-05-23 09:50:34 +0000950static GLboolean load_texenv_source( struct texenv_fragment_program *p,
Keith Whitwellce721142005-07-11 10:10:38 +0000951 GLuint src, GLuint unit )
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000952{
953 switch (src) {
Aapo Tahkola4dd8a892006-01-24 20:24:06 +0000954 case SRC_TEXTURE:
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000955 load_texture(p, unit);
956 break;
957
Keith Whitwellce721142005-07-11 10:10:38 +0000958 case SRC_TEXTURE0:
959 case SRC_TEXTURE1:
960 case SRC_TEXTURE2:
961 case SRC_TEXTURE3:
962 case SRC_TEXTURE4:
963 case SRC_TEXTURE5:
964 case SRC_TEXTURE6:
965 case SRC_TEXTURE7:
Keith Whitwellce721142005-07-11 10:10:38 +0000966 load_texture(p, src - SRC_TEXTURE0);
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000967 break;
968
969 default:
970 break;
971 }
Keith Whitwell241b6b72005-05-23 09:50:34 +0000972
973 return GL_TRUE;
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000974}
975
Brian Paul22db5352005-11-19 23:45:10 +0000976
977/**
978 * Generate instructions for loading all texture source terms.
979 */
980static GLboolean
981load_texunit_sources( struct texenv_fragment_program *p, int unit )
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000982{
Keith Whitwellce721142005-07-11 10:10:38 +0000983 struct state_key *key = p->state;
Aapo Tahkolab8915342006-03-28 10:26:34 +0000984 GLuint i;
985
986 for (i = 0; i < key->unit[unit].NumArgsRGB; i++) {
987 load_texenv_source( p, key->unit[unit].OptRGB[i].Source, unit);
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000988 }
Aapo Tahkolab8915342006-03-28 10:26:34 +0000989
990 for (i = 0; i < key->unit[unit].NumArgsA; i++) {
991 load_texenv_source( p, key->unit[unit].OptA[i].Source, unit );
992 }
993
Keith Whitwell241b6b72005-05-23 09:50:34 +0000994 return GL_TRUE;
Keith Whitwell2dea6df2005-05-23 09:37:32 +0000995}
996
Brian Paul22db5352005-11-19 23:45:10 +0000997
998/**
999 * Generate a new fragment program which implements the context's
1000 * current texture env/combine mode.
1001 */
1002static void
Brian Paule998c342006-10-29 21:17:18 +00001003create_new_program(GLcontext *ctx, struct state_key *key,
Brian Paul122629f2006-07-20 16:49:57 +00001004 struct gl_fragment_program *program)
Keith Whitwell15e75e02005-04-29 15:11:39 +00001005{
Brian Paule998c342006-10-29 21:17:18 +00001006 struct prog_instruction instBuffer[MAX_INSTRUCTIONS];
Keith Whitwell15e75e02005-04-29 15:11:39 +00001007 struct texenv_fragment_program p;
1008 GLuint unit;
1009 struct ureg cf, out;
Keith Whitwell276330b2005-05-09 17:58:13 +00001010
Keith Whitwelle4902422005-05-11 15:16:35 +00001011 _mesa_memset(&p, 0, sizeof(p));
Keith Whitwell47b29f52005-05-04 11:44:44 +00001012 p.ctx = ctx;
Keith Whitwellce721142005-07-11 10:10:38 +00001013 p.state = key;
1014 p.program = program;
Keith Whitwell47b29f52005-05-04 11:44:44 +00001015
Brian Paule998c342006-10-29 21:17:18 +00001016 /* During code generation, use locally-allocated instruction buffer,
1017 * then alloc dynamic storage below.
1018 */
1019 p.program->Base.Instructions = instBuffer;
Keith Whitwell276330b2005-05-09 17:58:13 +00001020 p.program->Base.Target = GL_FRAGMENT_PROGRAM_ARB;
Brian21f99792007-01-09 11:00:21 -07001021 p.program->Base.NumTexIndirections = 1; /* correct? */
1022 p.program->Base.NumTexInstructions = 0;
1023 p.program->Base.NumAluInstructions = 0;
Brian1240eb22007-03-22 08:50:20 -06001024 p.program->Base.String = NULL;
Keith Whitwell9ca88152005-05-10 09:56:02 +00001025 p.program->Base.NumInstructions =
Brian Paule998c342006-10-29 21:17:18 +00001026 p.program->Base.NumTemporaries =
1027 p.program->Base.NumParameters =
1028 p.program->Base.NumAttributes = p.program->Base.NumAddressRegs = 0;
Brian Paulde997602005-11-12 17:53:14 +00001029 p.program->Base.Parameters = _mesa_new_parameter_list();
Keith Whitwelldbeea252005-05-10 13:57:50 +00001030
Brian Paulde997602005-11-12 17:53:14 +00001031 p.program->Base.InputsRead = 0;
1032 p.program->Base.OutputsWritten = 1 << FRAG_RESULT_COLR;
Keith Whitwell15e75e02005-04-29 15:11:39 +00001033
Keith Whitwell2dea6df2005-05-23 09:37:32 +00001034 for (unit = 0; unit < MAX_TEXTURE_UNITS; unit++)
1035 p.src_texture[unit] = undef;
1036
Keith Whitwell47b29f52005-05-04 11:44:44 +00001037 p.src_previous = undef;
Keith Whitwell5ddc53f2006-05-22 14:17:32 +00001038 p.half = undef;
1039 p.zero = undef;
1040 p.one = undef;
1041
Keith Whitwell15e75e02005-04-29 15:11:39 +00001042 p.last_tex_stage = 0;
Brianf18d4e02007-10-29 12:25:46 -06001043 release_temps(ctx, &p);
Keith Whitwell15e75e02005-04-29 15:11:39 +00001044
Keith Whitwellce721142005-07-11 10:10:38 +00001045 if (key->enabled_units) {
Keith Whitwell2dea6df2005-05-23 09:37:32 +00001046 /* First pass - to support texture_env_crossbar, first identify
1047 * all referenced texture sources and emit texld instructions
1048 * for each:
1049 */
Keith Whitwell15e75e02005-04-29 15:11:39 +00001050 for (unit = 0 ; unit < ctx->Const.MaxTextureUnits ; unit++)
Keith Whitwellce721142005-07-11 10:10:38 +00001051 if (key->unit[unit].enabled) {
Aapo Tahkolab8915342006-03-28 10:26:34 +00001052 load_texunit_sources( &p, unit );
1053 p.last_tex_stage = unit;
Keith Whitwell15e75e02005-04-29 15:11:39 +00001054 }
1055
Keith Whitwell2dea6df2005-05-23 09:37:32 +00001056 /* Second pass - emit combine instructions to build final color:
1057 */
Keith Whitwell15e75e02005-04-29 15:11:39 +00001058 for (unit = 0 ; unit < ctx->Const.MaxTextureUnits; unit++)
Keith Whitwellce721142005-07-11 10:10:38 +00001059 if (key->enabled_units & (1<<unit)) {
Keith Whitwell15e75e02005-04-29 15:11:39 +00001060 p.src_previous = emit_texenv( &p, unit );
Brianf18d4e02007-10-29 12:25:46 -06001061 release_temps(ctx, &p); /* release all temps */
Keith Whitwell15e75e02005-04-29 15:11:39 +00001062 }
1063 }
1064
Keith Whitwellce721142005-07-11 10:10:38 +00001065 cf = get_source( &p, SRC_PREVIOUS, 0 );
Brian Paul90ebb582005-11-02 18:06:12 +00001066 out = make_ureg( PROGRAM_OUTPUT, FRAG_RESULT_COLR );
Keith Whitwell15e75e02005-04-29 15:11:39 +00001067
Keith Whitwellce721142005-07-11 10:10:38 +00001068 if (key->separate_specular) {
Keith Whitwell15e75e02005-04-29 15:11:39 +00001069 /* Emit specular add.
1070 */
Keith Whitwell47b29f52005-05-04 11:44:44 +00001071 struct ureg s = register_input(&p, FRAG_ATTRIB_COL1);
Brian Paul7e807512005-11-05 17:10:45 +00001072 emit_arith( &p, OPCODE_ADD, out, WRITEMASK_XYZ, 0, cf, s, undef );
1073 emit_arith( &p, OPCODE_MOV, out, WRITEMASK_W, 0, cf, undef, undef );
Keith Whitwell15e75e02005-04-29 15:11:39 +00001074 }
Brian Paulaa206952005-09-16 18:14:24 +00001075 else if (_mesa_memcmp(&cf, &out, sizeof(cf)) != 0) {
Keith Whitwell15e75e02005-04-29 15:11:39 +00001076 /* Will wind up in here if no texture enabled or a couple of
1077 * other scenarios (GL_REPLACE for instance).
1078 */
Brian Paul7e807512005-11-05 17:10:45 +00001079 emit_arith( &p, OPCODE_MOV, out, WRITEMASK_XYZW, 0, cf, undef, undef );
Keith Whitwell15e75e02005-04-29 15:11:39 +00001080 }
1081
Keith Whitwell47b29f52005-05-04 11:44:44 +00001082 /* Finish up:
1083 */
Brian Paul7e807512005-11-05 17:10:45 +00001084 emit_arith( &p, OPCODE_END, undef, WRITEMASK_XYZW, 0, undef, undef, undef);
Keith Whitwell47b29f52005-05-04 11:44:44 +00001085
Keith Whitwellce721142005-07-11 10:10:38 +00001086 if (key->fog_enabled) {
1087 /* Pull fog mode from GLcontext, the value in the state key is
1088 * a reduced value and not what is expected in FogOption
1089 */
Keith Whitwell276330b2005-05-09 17:58:13 +00001090 p.program->FogOption = ctx->Fog.Mode;
Brian63be96b2007-09-18 19:29:26 -06001091 p.program->Base.InputsRead |= FRAG_BIT_FOGC; /* XXX new */
Keith Whitwellce721142005-07-11 10:10:38 +00001092 } else
Keith Whitwell276330b2005-05-09 17:58:13 +00001093 p.program->FogOption = GL_NONE;
Keith Whitwell47b29f52005-05-04 11:44:44 +00001094
Brian21f99792007-01-09 11:00:21 -07001095 if (p.program->Base.NumTexIndirections > ctx->Const.FragmentProgram.MaxTexIndirections)
Keith Whitwell15e75e02005-04-29 15:11:39 +00001096 program_error(&p, "Exceeded max nr indirect texture lookups");
1097
Brian21f99792007-01-09 11:00:21 -07001098 if (p.program->Base.NumTexInstructions > ctx->Const.FragmentProgram.MaxTexInstructions)
Keith Whitwell15e75e02005-04-29 15:11:39 +00001099 program_error(&p, "Exceeded max TEX instructions");
1100
Brian21f99792007-01-09 11:00:21 -07001101 if (p.program->Base.NumAluInstructions > ctx->Const.FragmentProgram.MaxAluInstructions)
Keith Whitwell15e75e02005-04-29 15:11:39 +00001102 program_error(&p, "Exceeded max ALU instructions");
1103
Brian Paul5d7b49f2005-11-19 23:12:20 +00001104 ASSERT(p.program->Base.NumInstructions <= MAX_INSTRUCTIONS);
Keith Whitwell8b88f622005-05-10 11:39:50 +00001105
Brian Paule998c342006-10-29 21:17:18 +00001106 /* Allocate final instruction array */
Brian3bf8d2a2007-09-25 15:18:51 -06001107 p.program->Base.Instructions
1108 = _mesa_alloc_instructions(p.program->Base.NumInstructions);
1109 if (!p.program->Base.Instructions) {
Brian Paule998c342006-10-29 21:17:18 +00001110 _mesa_error(ctx, GL_OUT_OF_MEMORY,
1111 "generating tex env program");
1112 return;
1113 }
Brian3bf8d2a2007-09-25 15:18:51 -06001114 _mesa_copy_instructions(p.program->Base.Instructions, instBuffer,
1115 p.program->Base.NumInstructions);
1116
1117 if (p.program->FogOption) {
1118 _mesa_append_fog_code(ctx, p.program);
1119 p.program->FogOption = GL_NONE;
1120 }
1121
Brian Paule998c342006-10-29 21:17:18 +00001122
Keith Whitwelldbeea252005-05-10 13:57:50 +00001123 /* Notify driver the fragment program has (actually) changed.
Keith Whitwell8b88f622005-05-10 11:39:50 +00001124 */
Brian Paule998c342006-10-29 21:17:18 +00001125 if (ctx->Driver.ProgramStringNotify) {
1126 ctx->Driver.ProgramStringNotify( ctx, GL_FRAGMENT_PROGRAM_ARB,
1127 &p.program->Base );
1128 }
Keith Whitwelldbeea252005-05-10 13:57:50 +00001129
Brian Paule998c342006-10-29 21:17:18 +00001130 if (DISASSEM) {
1131 _mesa_print_program(&p.program->Base);
1132 _mesa_printf("\n");
Keith Whitwelle4902422005-05-11 15:16:35 +00001133 }
Keith Whitwell15e75e02005-04-29 15:11:39 +00001134}
1135
Brian Paul5d7b49f2005-11-19 23:12:20 +00001136
Briana90046f2006-12-15 10:07:26 -07001137/**
Brian83ce6c52007-10-29 11:23:02 -06001138 * Return a fragment program which implements the current
1139 * fixed-function texture, fog and color-sum operations.
1140 */
1141struct gl_fragment_program *
1142_mesa_get_fixed_func_fragment_program(GLcontext *ctx)
1143{
1144 struct gl_fragment_program *prog;
1145 struct state_key key;
Brian83ce6c52007-10-29 11:23:02 -06001146
1147 make_state_key(ctx, &key);
Brian83ce6c52007-10-29 11:23:02 -06001148
Brianf4a5ea22007-10-31 12:45:32 -06001149 prog = (struct gl_fragment_program *)
1150 _mesa_search_program_cache(ctx->FragmentProgram.Cache,
1151 &key, sizeof(key));
Brian83ce6c52007-10-29 11:23:02 -06001152
1153 if (!prog) {
Brian83ce6c52007-10-29 11:23:02 -06001154 prog = (struct gl_fragment_program *)
1155 ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
1156
1157 create_new_program(ctx, &key, prog);
1158
Brianf4a5ea22007-10-31 12:45:32 -06001159 _mesa_program_cache_insert(ctx, ctx->FragmentProgram.Cache,
1160 &key, sizeof(key), &prog->Base);
Brian83ce6c52007-10-29 11:23:02 -06001161 }
1162
1163 return prog;
1164}
1165
1166
1167
1168/**
Briana90046f2006-12-15 10:07:26 -07001169 * If _MaintainTexEnvProgram is set we'll generate a fragment program that
1170 * implements the current texture env/combine mode.
1171 * This function generates that program and puts it into effect.
1172 */
1173void
1174_mesa_UpdateTexEnvProgram( GLcontext *ctx )
Keith Whitwellce721142005-07-11 10:10:38 +00001175{
Brian Paul122629f2006-07-20 16:49:57 +00001176 const struct gl_fragment_program *prev = ctx->FragmentProgram._Current;
Keith Whitwellce721142005-07-11 10:10:38 +00001177
Briana90046f2006-12-15 10:07:26 -07001178 ASSERT(ctx->FragmentProgram._MaintainTexEnvProgram);
1179
1180 /* If a conventional fragment program/shader isn't in effect... */
Brianefcfdbd2007-02-24 15:51:41 -07001181 if (!ctx->FragmentProgram._Enabled &&
Briand781cdc2007-10-02 16:55:21 -06001182 (!ctx->Shader.CurrentProgram ||
1183 !ctx->Shader.CurrentProgram->FragmentProgram) ) {
Keith Whitwellce721142005-07-11 10:10:38 +00001184
Brian83ce6c52007-10-29 11:23:02 -06001185 ctx->FragmentProgram._Current
1186 = ctx->FragmentProgram._TexEnvProgram
1187 = _mesa_get_fixed_func_fragment_program(ctx);
Keith Whitwellc3626a92005-11-01 17:25:49 +00001188 }
Keith Whitwellc3626a92005-11-01 17:25:49 +00001189
1190 /* Tell the driver about the change. Could define a new target for
1191 * this?
1192 */
Brian Paul5d7b49f2005-11-19 23:12:20 +00001193 if (ctx->FragmentProgram._Current != prev && ctx->Driver.BindProgram) {
1194 ctx->Driver.BindProgram(ctx, GL_FRAGMENT_PROGRAM_ARB,
Briana90046f2006-12-15 10:07:26 -07001195 (struct gl_program *) ctx->FragmentProgram._Current);
Brian Paul5d7b49f2005-11-19 23:12:20 +00001196 }
Keith Whitwellce721142005-07-11 10:10:38 +00001197}