mojoshader.c
changeset 1106 2bef26cc20f9
parent 1104 9147482e1ec7
child 1107 b18605919c3c
equal deleted inserted replaced
1105:57e255c3b243 1106:2bef26cc20f9
  3450     char code[512];
  3450     char code[512];
  3451 
  3451 
  3452     // !!! FIXME: this code counts on the register not having swizzles, etc.
  3452     // !!! FIXME: this code counts on the register not having swizzles, etc.
  3453     get_GLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum,
  3453     get_GLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum,
  3454                             sampler, sizeof (sampler));
  3454                             sampler, sizeof (sampler));
  3455 
       
  3456     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x2pad_src0,
  3455     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x2pad_src0,
  3457                             src0, sizeof (src0));
  3456                             src0, sizeof (src0));
  3458     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x2pad_dst0,
  3457     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x2pad_dst0,
  3459                             src1, sizeof (src1));
  3458                             src1, sizeof (src1));
  3460     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[0].regnum,
  3459     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[0].regnum,
  7462     if (src->regnum >= dst->regnum)  // so says MSDN.
  7461     if (src->regnum >= dst->regnum)  // so says MSDN.
  7463         failf(ctx, "%s dest must be a higher register than source", opcode);
  7462         failf(ctx, "%s dest must be a higher register than source", opcode);
  7464 
  7463 
  7465     if (dims)
  7464     if (dims)
  7466     {
  7465     {
  7467         TextureType ttyp = (dims == 2) ? TEXTURE_TYPE_2D : TEXTURE_TYPE_VOLUME;
  7466         TextureType ttyp = (dims == 2) ? TEXTURE_TYPE_2D : TEXTURE_TYPE_CUBE;
  7468         add_sampler(ctx, dst->regnum, ttyp, texbem);
  7467         add_sampler(ctx, dst->regnum, ttyp, texbem);
  7469     } // if
  7468     } // if
  7470 
  7469 
  7471     add_attribute_register(ctx, REG_TYPE_TEXTURE, dst->regnum,
  7470     add_attribute_register(ctx, REG_TYPE_TEXTURE, dst->regnum,
  7472                            MOJOSHADER_USAGE_TEXCOORD, dst->regnum, 0xF, 0);
  7471                            MOJOSHADER_USAGE_TEXCOORD, dst->regnum, 0xF, 0);
  7536     if (ctx->texm3x2pad_dst0 == -1)
  7535     if (ctx->texm3x2pad_dst0 == -1)
  7537         fail(ctx, "TEXM3X2TEX opcode without matching TEXM3X2PAD");
  7536         fail(ctx, "TEXM3X2TEX opcode without matching TEXM3X2PAD");
  7538     // !!! FIXME: check for correct opcode existance and order more rigorously?
  7537     // !!! FIXME: check for correct opcode existance and order more rigorously?
  7539     state_texops(ctx, "TEXM3X2TEX", 2, 0);
  7538     state_texops(ctx, "TEXM3X2TEX", 2, 0);
  7540     ctx->reset_texmpad = 1;
  7539     ctx->reset_texmpad = 1;
       
  7540 
       
  7541     RegisterList *sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER,
       
  7542                                       ctx->dest_arg.regnum);
       
  7543     const TextureType ttype = (TextureType) (sreg ? sreg->index : 0);
       
  7544 
       
  7545     // A samplermap might change this to something nonsensical.
       
  7546     if (ttype != TEXTURE_TYPE_2D)
       
  7547         fail(ctx, "TEXM3X2TEX needs a 2D sampler");
  7541 } // state_TEXM3X2TEX
  7548 } // state_TEXM3X2TEX
  7542 
  7549 
  7543 static void state_TEXM3X3PAD(Context *ctx)
  7550 static void state_TEXM3X3PAD(Context *ctx)
  7544 {
  7551 {
  7545     if (shader_version_atleast(ctx, 1, 4))
  7552     if (shader_version_atleast(ctx, 1, 4))
  7566         failf(ctx, "%s opcode not available after Shader Model 1.3", opcode);
  7573         failf(ctx, "%s opcode not available after Shader Model 1.3", opcode);
  7567     if (ctx->texm3x3pad_dst1 == -1)
  7574     if (ctx->texm3x3pad_dst1 == -1)
  7568         failf(ctx, "%s opcode without matching TEXM3X3PADs", opcode);
  7575         failf(ctx, "%s opcode without matching TEXM3X3PADs", opcode);
  7569     state_texops(ctx, opcode, dims, 0);
  7576     state_texops(ctx, opcode, dims, 0);
  7570     ctx->reset_texmpad = 1;
  7577     ctx->reset_texmpad = 1;
       
  7578 
       
  7579     RegisterList *sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER,
       
  7580                                       ctx->dest_arg.regnum);
       
  7581     const TextureType ttype = (TextureType) (sreg ? sreg->index : 0);
       
  7582 
       
  7583     // A samplermap might change this to something nonsensical.
       
  7584     if ((ttype != TEXTURE_TYPE_VOLUME) && (ttype != TEXTURE_TYPE_CUBE))
       
  7585         failf(ctx, "%s needs a 3D or Cubemap sampler", opcode);
  7571 } // state_texm3x3
  7586 } // state_texm3x3
  7572 
  7587 
  7573 static void state_TEXM3X3(Context *ctx)
  7588 static void state_TEXM3X3(Context *ctx)
  7574 {
  7589 {
  7575     if (!shader_version_atleast(ctx, 1, 2))
  7590     if (!shader_version_atleast(ctx, 1, 2))