/** State used to build the fragment program:
*/
-struct texenv_fragment_program {
+class texenv_fragment_program : public ir_factory {
+public:
struct gl_shader_program *shader_program;
struct gl_shader *shader;
- exec_list *instructions;
exec_list *top_instructions;
- void *mem_ctx;
struct state_key *state;
ir_variable *src_texture[MAX_TEXTURE_COORD_UNITS];
ir_variable *temp_var = new(p->mem_ctx) ir_variable(glsl_type::vec4_type,
"texenv_combine",
ir_var_temporary);
- p->instructions->push_tail(temp_var);
+ p->emit(temp_var);
ir_dereference *deref;
- ir_assignment *assign;
ir_rvalue *val;
/* Emit the RGB and A combine ops
val = saturate(val);
deref = new(p->mem_ctx) ir_dereference_variable(temp_var);
- assign = new(p->mem_ctx) ir_assignment(deref, val);
- p->instructions->push_tail(assign);
+ p->emit(new(p->mem_ctx) ir_assignment(deref, val));
}
else if (key->unit[unit].ModeRGB == MODE_DOT3_RGBA_EXT ||
key->unit[unit].ModeRGB == MODE_DOT3_RGBA) {
if (rgb_saturate)
val = saturate(val);
deref = new(p->mem_ctx) ir_dereference_variable(temp_var);
- assign = new(p->mem_ctx) ir_assignment(deref, val);
- p->instructions->push_tail(assign);
+ p->emit(new(p->mem_ctx) ir_assignment(deref, val));
}
else {
/* Need to do something to stop from re-emitting identical
if (rgb_saturate)
val = saturate(val);
deref = new(p->mem_ctx) ir_dereference_variable(temp_var);
- assign = new(p->mem_ctx) ir_assignment(deref, val, NULL, WRITEMASK_XYZ);
- p->instructions->push_tail(assign);
+ p->emit(new(p->mem_ctx) ir_assignment(deref, val, NULL, WRITEMASK_XYZ));
val = emit_combine(p, unit,
key->unit[unit].NumArgsA,
if (alpha_saturate)
val = saturate(val);
deref = new(p->mem_ctx) ir_dereference_variable(temp_var);
- assign = new(p->mem_ctx) ir_assignment(deref, val, NULL, WRITEMASK_W);
- p->instructions->push_tail(assign);
+ p->emit(new(p->mem_ctx) ir_assignment(deref, val, NULL, WRITEMASK_W));
}
deref = new(p->mem_ctx) ir_dereference_variable(temp_var);
static void load_texture( struct texenv_fragment_program *p, GLuint unit )
{
ir_dereference *deref;
- ir_assignment *assign;
if (p->src_texture[unit])
return;
p->src_texture[unit] = new(p->mem_ctx) ir_variable(glsl_type::vec4_type,
"dummy_tex",
ir_var_temporary);
- p->instructions->push_tail(p->src_texture[unit]);
+ p->emit(p->src_texture[unit]);
deref = new(p->mem_ctx) ir_dereference_variable(p->src_texture[unit]);
- assign = new(p->mem_ctx) ir_assignment(deref,
- new(p->mem_ctx) ir_constant(0.0f));
- p->instructions->push_tail(assign);
+ p->emit(new(p->mem_ctx) ir_assignment(deref,
+ new(p->mem_ctx) ir_constant(0.0f)));
return ;
}
p->src_texture[unit] = new(p->mem_ctx) ir_variable(glsl_type::vec4_type,
"tex",
ir_var_temporary);
- p->instructions->push_tail(p->src_texture[unit]);
+ p->emit(p->src_texture[unit]);
ir_texture *tex = new(p->mem_ctx) ir_texture(ir_tex);
tex->projector = swizzle_w(texcoord);
deref = new(p->mem_ctx) ir_dereference_variable(p->src_texture[unit]);
- assign = new(p->mem_ctx) ir_assignment(deref, tex);
- p->instructions->push_tail(assign);
+ p->emit(new(p->mem_ctx) ir_assignment(deref, tex));
}
static void
* note only 2 coords are affected the rest are left unchanged (mul by 0)
*/
ir_dereference *deref;
- ir_assignment *assign;
ir_rvalue *bump_x, *bump_y;
texcoord = smear(p, texcoord);
ir_variable *bumped = new(p->mem_ctx) ir_variable(texcoord->type,
"bump_texcoord",
ir_var_temporary);
- p->instructions->push_tail(bumped);
+ p->emit(bumped);
deref = new(p->mem_ctx) ir_dereference_variable(bumped);
- assign = new(p->mem_ctx) ir_assignment(deref, texcoord);
- p->instructions->push_tail(assign);
+ p->emit(new(p->mem_ctx) ir_assignment(deref, texcoord));
/* bump_texcoord.xy += arg0.x * rotmat0 + arg0.y * rotmat1 */
bump = get_source(p, key->unit[unit].OptRGB[0].Source, unit);
expr = add(swizzle_xy(bumped), add(bump_x, bump_y));
deref = new(p->mem_ctx) ir_dereference_variable(bumped);
- assign = new(p->mem_ctx) ir_assignment(deref, expr, NULL, WRITEMASK_XY);
- p->instructions->push_tail(assign);
+ p->emit(new(p->mem_ctx) ir_assignment(deref, expr, NULL, WRITEMASK_XY));
p->texcoord_tex[bumpedUnitNr] = bumped;
}
ir_rvalue *f, *temp;
ir_variable *params, *oparams;
ir_variable *fogcoord;
- ir_assignment *assign;
/* Temporary storage for the whole fog result. Fog calculations
* only affect rgb so we're hanging on to the .a value of fragcolor
ir_variable *fog_result = new(p->mem_ctx) ir_variable(glsl_type::vec4_type,
"fog_result",
ir_var_auto);
- p->instructions->push_tail(fog_result);
+ p->emit(fog_result);
temp = new(p->mem_ctx) ir_dereference_variable(fog_result);
- assign = new(p->mem_ctx) ir_assignment(temp, fragcolor);
- p->instructions->push_tail(assign);
+ p->emit(new(p->mem_ctx) ir_assignment(temp, fragcolor));
fragcolor = swizzle_xyz(fog_result);
ir_variable *f_var = new(p->mem_ctx) ir_variable(glsl_type::float_type,
"fog_factor", ir_var_auto);
- p->instructions->push_tail(f_var);
+ p->emit(f_var);
switch (key->fog_mode) {
case FOG_LINEAR:
ir_variable *temp_var = new(p->mem_ctx) ir_variable(glsl_type::float_type,
"fog_temp",
ir_var_auto);
- p->instructions->push_tail(temp_var);
+ p->emit(temp_var);
f = mul(f, swizzle_w(oparams));
temp = new(p->mem_ctx) ir_dereference_variable(temp_var);
- ir_assignment *assign = new(p->mem_ctx) ir_assignment(temp, f);
- p->instructions->push_tail(assign);
+ p->emit(new(p->mem_ctx) ir_assignment(temp, f));
f = mul(temp_var, temp_var);
f = new(p->mem_ctx) ir_expression(ir_unop_neg, f);
f = saturate(f);
temp = new(p->mem_ctx) ir_dereference_variable(f_var);
- assign = new(p->mem_ctx) ir_assignment(temp, f);
- p->instructions->push_tail(assign);
+ p->emit(new(p->mem_ctx) ir_assignment(temp, f));
f = sub(new(p->mem_ctx) ir_constant(1.0f), f_var);
temp = new(p->mem_ctx) ir_dereference_variable(params);
f = add(temp, mul(fragcolor, f_var));
ir_dereference *deref = new(p->mem_ctx) ir_dereference_variable(fog_result);
- assign = new(p->mem_ctx) ir_assignment(deref, f, NULL, WRITEMASK_XYZ);
- p->instructions->push_tail(assign);
+ p->emit(new(p->mem_ctx) ir_assignment(deref, f, NULL, WRITEMASK_XYZ));
return new(p->mem_ctx) ir_dereference_variable(fog_result);
}
ir_rvalue *cf = get_source(p, SRC_PREVIOUS, 0);
ir_dereference_variable *deref;
- ir_assignment *assign;
if (key->separate_specular) {
ir_rvalue *tmp0;
"specular_add",
ir_var_temporary);
- p->instructions->push_tail(spec_result);
+ p->emit(spec_result);
deref = new(p->mem_ctx) ir_dereference_variable(spec_result);
- assign = new(p->mem_ctx) ir_assignment(deref, cf);
- p->instructions->push_tail(assign);
+ p->emit(new(p->mem_ctx) ir_assignment(deref, cf));
ir_rvalue *secondary;
if (p->state->inputs_available & FRAG_BIT_COL1) {
tmp0 = add(swizzle_xyz(spec_result), secondary);
deref = new(p->mem_ctx) ir_dereference_variable(spec_result);
- assign = new(p->mem_ctx) ir_assignment(deref, tmp0, NULL, WRITEMASK_XYZ);
- p->instructions->push_tail(assign);
+ p->emit(new(p->mem_ctx) ir_assignment(deref, tmp0, NULL, WRITEMASK_XYZ));
cf = new(p->mem_ctx) ir_dereference_variable(spec_result);
}
ir_variable *frag_color = p->shader->symbols->get_variable("gl_FragColor");
assert(frag_color);
deref = new(p->mem_ctx) ir_dereference_variable(frag_color);
- assign = new(p->mem_ctx) ir_assignment(deref, cf);
- p->instructions->push_tail(assign);
+ p->emit(new(p->mem_ctx) ir_assignment(deref, cf));
}
/**
static struct gl_shader_program *
create_new_program(struct gl_context *ctx, struct state_key *key)
{
- struct texenv_fragment_program p;
+ texenv_fragment_program p;
unsigned int unit;
_mesa_glsl_parse_state *state;
- memset(&p, 0, sizeof(p));
p.mem_ctx = ralloc_context(NULL);
p.shader = ctx->Driver.NewShader(ctx, 0, GL_FRAGMENT_SHADER);
p.shader->ir = new(p.shader) exec_list;
p.src_previous = NULL;
ir_function *main_f = new(p.mem_ctx) ir_function("main");
- p.instructions->push_tail(main_f);
+ p.emit(main_f);
state->symbols->add_function(main_f);
ir_function_signature *main_sig =