~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to src/mesa/main/texenvprogram.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "shader/program.h"
34
34
#include "shader/program_instruction.h"
35
35
 
36
 
#define MAX_INSTRUCTIONS 100
 
36
/**
 
37
 * According to Glean's texCombine test, no more than 21 instructions
 
38
 * are needed.  Allow a few extra just in case.
 
39
 */
 
40
#define MAX_INSTRUCTIONS 24
37
41
 
38
42
#define DISASSEM (MESA_VERBOSE & VERBOSE_DISASSEM)
39
43
 
474
478
   GLuint nr = p->program->Base.NumInstructions++;
475
479
   struct prog_instruction *inst = &p->program->Base.Instructions[nr];
476
480
      
477
 
   _mesa_init_instruction(inst);
 
481
   _mesa_init_instructions(inst, 1);
478
482
   inst->Opcode = op;
479
483
   
480
484
   emit_arg( &inst->SrcReg[0], src0 );
571
575
   values[1] = s1;
572
576
   values[2] = s2;
573
577
   values[3] = s3;
574
 
   idx = _mesa_add_unnamed_constant( p->program->Base.Parameters, values );
 
578
   idx = _mesa_add_unnamed_constant( p->program->Base.Parameters, values, 4 );
575
579
   return make_ureg(PROGRAM_STATE_VAR, idx);
576
580
}
577
581
 
988
992
 * current texture env/combine mode.
989
993
 */
990
994
static void
991
 
create_new_program(struct state_key *key, GLcontext *ctx,
 
995
create_new_program(GLcontext *ctx, struct state_key *key,
992
996
                   struct gl_fragment_program *program)
993
997
{
 
998
   struct prog_instruction instBuffer[MAX_INSTRUCTIONS];
994
999
   struct texenv_fragment_program p;
995
1000
   GLuint unit;
996
1001
   struct ureg cf, out;
1000
1005
   p.state = key;
1001
1006
   p.program = program;
1002
1007
 
1003
 
   p.program->Base.Instructions =
1004
 
      (struct prog_instruction*) _mesa_malloc(sizeof(struct prog_instruction) * MAX_INSTRUCTIONS);
1005
 
   p.program->Base.NumInstructions = 0;
 
1008
   /* During code generation, use locally-allocated instruction buffer,
 
1009
    * then alloc dynamic storage below.
 
1010
    */
 
1011
   p.program->Base.Instructions = instBuffer;
1006
1012
   p.program->Base.Target = GL_FRAGMENT_PROGRAM_ARB;
1007
1013
   p.program->NumTexIndirections = 1;   /* correct? */
1008
1014
   p.program->NumTexInstructions = 0;
1009
1015
   p.program->NumAluInstructions = 0;
1010
1016
   p.program->Base.String = 0;
1011
1017
   p.program->Base.NumInstructions =
1012
 
      p.program->Base.NumTemporaries =
1013
 
      p.program->Base.NumParameters =
1014
 
      p.program->Base.NumAttributes = p.program->Base.NumAddressRegs = 0;
 
1018
   p.program->Base.NumTemporaries =
 
1019
   p.program->Base.NumParameters =
 
1020
   p.program->Base.NumAttributes = p.program->Base.NumAddressRegs = 0;
1015
1021
   p.program->Base.Parameters = _mesa_new_parameter_list();
1016
1022
 
1017
1023
   p.program->Base.InputsRead = 0;
1088
1094
 
1089
1095
   ASSERT(p.program->Base.NumInstructions <= MAX_INSTRUCTIONS);
1090
1096
 
 
1097
   /* Allocate final instruction array */
 
1098
   program->Base.Instructions
 
1099
      = _mesa_alloc_instructions(program->Base.NumInstructions);
 
1100
   if (!program->Base.Instructions) {
 
1101
      _mesa_error(ctx, GL_OUT_OF_MEMORY,
 
1102
                  "generating tex env program");
 
1103
      return;
 
1104
   }
 
1105
   _mesa_memcpy(program->Base.Instructions, instBuffer,
 
1106
                sizeof(struct prog_instruction)
 
1107
                * program->Base.NumInstructions);
 
1108
 
1091
1109
   /* Notify driver the fragment program has (actually) changed.
1092
1110
    */
1093
 
   if (ctx->Driver.ProgramStringNotify || DISASSEM) {
1094
 
      if (ctx->Driver.ProgramStringNotify)
1095
 
         ctx->Driver.ProgramStringNotify( ctx, GL_FRAGMENT_PROGRAM_ARB, 
1096
 
                                          &p.program->Base );
 
1111
   if (ctx->Driver.ProgramStringNotify) {
 
1112
      ctx->Driver.ProgramStringNotify( ctx, GL_FRAGMENT_PROGRAM_ARB, 
 
1113
                                       &p.program->Base );
 
1114
   }
1097
1115
 
1098
 
      if (DISASSEM) {
1099
 
         _mesa_print_program(&p.program->Base);
1100
 
         _mesa_printf("\n");
1101
 
      }
 
1116
   if (DISASSEM) {
 
1117
      _mesa_print_program(&p.program->Base);
 
1118
      _mesa_printf("\n");
1102
1119
   }
1103
1120
}
1104
1121
 
1225
1242
            (struct gl_fragment_program *) 
1226
1243
            ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
1227
1244
                
1228
 
         create_new_program(&key, ctx, ctx->_TexEnvProgram);
 
1245
         create_new_program(ctx, &key, ctx->_TexEnvProgram);
1229
1246
 
1230
1247
         cache_item(&ctx->Texture.env_fp_cache, hash, &key, ctx->_TexEnvProgram);
1231
1248
      } else {