d3d2glsl.c
branchtrunk
changeset 25 9664b0f62af6
parent 24 2177c6bee93d
child 26 ed1dc1eca8b2
equal deleted inserted replaced
24:2177c6bee93d 25:9664b0f62af6
   251     D3D2GLSL_shaderType shader_type;
   251     D3D2GLSL_shaderType shader_type;
   252     uint32 major_ver;
   252     uint32 major_ver;
   253     uint32 minor_ver;
   253     uint32 minor_ver;
   254     DestArgInfo dest_args[1];
   254     DestArgInfo dest_args[1];
   255     SourceArgInfo source_args[4];
   255     SourceArgInfo source_args[4];
       
   256     uint32 instruction_count;
   256 };
   257 };
   257 
   258 
   258 
   259 
   259 static inline char *get_scratch_buffer(Context *ctx)
   260 static inline char *get_scratch_buffer(Context *ctx)
   260 {
   261 {
   602     int i = 0;
   603     int i = 0;
   603     if (arg->swizzle != 0xE4)  // E4 == 11100100 ... 3 2 1 0. No swizzle.
   604     if (arg->swizzle != 0xE4)  // E4 == 11100100 ... 3 2 1 0. No swizzle.
   604     {
   605     {
   605         static const char channel[] = { 'x', 'y', 'z', 'w' };
   606         static const char channel[] = { 'x', 'y', 'z', 'w' };
   606         swizzle_str[i++] = '.';
   607         swizzle_str[i++] = '.';
   607 
   608         swizzle_str[i++] = channel[arg->swizzle_x];
   608         if ( (arg->swizzle_x == arg->swizzle_y) &&
   609         swizzle_str[i++] = channel[arg->swizzle_y];
   609              (arg->swizzle_x == arg->swizzle_z) &&
   610         swizzle_str[i++] = channel[arg->swizzle_z];
   610              (arg->swizzle_x == arg->swizzle_w) )
   611         swizzle_str[i++] = channel[arg->swizzle_w];
   611         {
   612 
   612             swizzle_str[i++] = channel[arg->swizzle_x];  // syntactic sugar.
   613         // .xyzz is the same as .xyz, .z is the same as .zzzz, etc.
   613         } // if
   614         while (swizzle_str[i-1] == swizzle_str[i-2])
   614         else
   615             i--;
   615         {
       
   616             swizzle_str[i++] = channel[arg->swizzle_x];
       
   617             swizzle_str[i++] = channel[arg->swizzle_y];
       
   618             swizzle_str[i++] = channel[arg->swizzle_z];
       
   619             swizzle_str[i++] = channel[arg->swizzle_w];
       
   620         } // else
       
   621     } // if
   616     } // if
   622     swizzle_str[i] = '\0';
   617     swizzle_str[i] = '\0';
   623     assert(i < sizeof (swizzle_str));
   618     assert(i < sizeof (swizzle_str));
   624 
   619 
   625     char *retval = get_scratch_buffer(ctx);
   620     char *retval = get_scratch_buffer(ctx);
  1703                     (uint) instruction->arg_tokens, (uint) ctx->tokencount,
  1698                     (uint) instruction->arg_tokens, (uint) ctx->tokencount,
  1704                     instruction->opcode_string);
  1699                     instruction->opcode_string);
  1705         } // else if
  1700         } // else if
  1706     } // if
  1701     } // if
  1707 
  1702 
       
  1703     ctx->instruction_count++;
       
  1704 
  1708     // Update the context with instruction's arguments.
  1705     // Update the context with instruction's arguments.
  1709     ctx->tokens++;
  1706     ctx->tokens++;
  1710     ctx->tokencount--;
  1707     ctx->tokencount--;
  1711     if (instruction->parse_args(ctx) == FAIL)
  1708     if (instruction->parse_args(ctx) == FAIL)
  1712         return FAIL;
  1709         return FAIL;