mojoshader.c
branchtrunk
changeset 180 e25cd1bad94d
parent 179 3db6b937958e
child 181 346263640ccc
equal deleted inserted replaced
179:3db6b937958e 180:e25cd1bad94d
  2323     emit_GLSL_LIT_helper(ctx);
  2323     emit_GLSL_LIT_helper(ctx);
  2324 } // emit_GLSL_LIT
  2324 } // emit_GLSL_LIT
  2325 
  2325 
  2326 static void emit_GLSL_DST(Context *ctx)
  2326 static void emit_GLSL_DST(Context *ctx)
  2327 {
  2327 {
       
  2328     // !!! FIXME: needs to take ctx->dst_arg.writemask into account.
  2328     const char *src0_y = make_GLSL_srcarg_string_y(ctx, 0);
  2329     const char *src0_y = make_GLSL_srcarg_string_y(ctx, 0);
  2329     const char *src1_y = make_GLSL_srcarg_string_y(ctx, 1);
  2330     const char *src1_y = make_GLSL_srcarg_string_y(ctx, 1);
  2330     const char *src0_z = make_GLSL_srcarg_string_z(ctx, 0);
  2331     const char *src0_z = make_GLSL_srcarg_string_z(ctx, 0);
  2331     const char *src1_w = make_GLSL_srcarg_string_w(ctx, 1);
  2332     const char *src1_w = make_GLSL_srcarg_string_w(ctx, 1);
  2332     const char *code = make_GLSL_destarg_assign(ctx,
  2333     const char *code = make_GLSL_destarg_assign(ctx,
  2509     output_line(ctx, "%s", code);
  2510     output_line(ctx, "%s", code);
  2510 } // emit_GLSL_POW
  2511 } // emit_GLSL_POW
  2511 
  2512 
  2512 static void emit_GLSL_CRS(Context *ctx)
  2513 static void emit_GLSL_CRS(Context *ctx)
  2513 {
  2514 {
  2514     const char *src0 = make_GLSL_srcarg_string_full(ctx, 0);
  2515     // !!! FIXME: needs to take ctx->dst_arg.writemask into account.
  2515     const char *src1 = make_GLSL_srcarg_string_full(ctx, 1);
  2516     const char *src0 = make_GLSL_srcarg_string_vec3(ctx, 0);
  2516     const char *code = make_GLSL_destarg_assign(ctx, "cross(vec3(%s), vec3(%s))", src0, src1);
  2517     const char *src1 = make_GLSL_srcarg_string_vec3(ctx, 1);
       
  2518     const char *code = make_GLSL_destarg_assign(ctx, "cross(%s, %s)", src0, src1);
  2517     output_line(ctx, "%s", code);
  2519     output_line(ctx, "%s", code);
  2518 } // emit_GLSL_CRS
  2520 } // emit_GLSL_CRS
  2519 
  2521 
  2520 static void emit_GLSL_SGN(Context *ctx)
  2522 static void emit_GLSL_SGN(Context *ctx)
  2521 {
  2523 {
  2544     // we don't care about the temp registers that <= sm2 demands; ignore them.
  2546     // we don't care about the temp registers that <= sm2 demands; ignore them.
  2545     //  sm2 also talks about what components are left untouched vs. undefined,
  2547     //  sm2 also talks about what components are left untouched vs. undefined,
  2546     //  but we just leave those all untouched with GLSL write masks (which
  2548     //  but we just leave those all untouched with GLSL write masks (which
  2547     //  would fulfill the "undefined" requirement, too).
  2549     //  would fulfill the "undefined" requirement, too).
  2548     const int mask = ctx->dest_arg.writemask;
  2550     const int mask = ctx->dest_arg.writemask;
  2549     const char *src0 = make_GLSL_srcarg_string_masked(ctx, 0);
  2551     const char *src0 = make_GLSL_srcarg_string_scalar(ctx, 0);
  2550     const char *code = NULL;
  2552     const char *code = NULL;
  2551 
  2553 
  2552     if (mask == 0x1)  // .x
  2554     if (mask == 0x1)  // .x
  2553         code = make_GLSL_destarg_assign(ctx, "cos(%s)", src0);
  2555         code = make_GLSL_destarg_assign(ctx, "cos(%s)", src0);
  2554     else if (mask == 0x2)  // .y
  2556     else if (mask == 0x2)  // .y
  2562 {
  2564 {
  2563     // !!! FIXME:
  2565     // !!! FIXME:
  2564     // msdn docs say legal loop values are 0 to 255. We can check DEFI values
  2566     // msdn docs say legal loop values are 0 to 255. We can check DEFI values
  2565     //  at parse time, but if they are pulling a value from a uniform, do
  2567     //  at parse time, but if they are pulling a value from a uniform, do
  2566     //  we clamp here?
  2568     //  we clamp here?
  2567     const char *varname = get_GLSL_srcarg_varname(ctx, 0);
  2569     // !!! FIXME: swizzle is legal here, right?
       
  2570     const char *src0 = make_GLSL_srcarg_string_x(ctx, 0);
  2568     const uint rep = (uint) ctx->reps;
  2571     const uint rep = (uint) ctx->reps;
  2569     output_line(ctx, "for (int rep%u = 0; rep%u < %s.x; rep%u++) {",
  2572     output_line(ctx, "for (int rep%u = 0; rep%u < %s; rep%u++) {",
  2570                 rep, rep, varname, rep);
  2573                 rep, rep, src0, rep);
  2571     ctx->indent++;
  2574     ctx->indent++;
  2572 } // emit_GLSL_REP
  2575 } // emit_GLSL_REP
  2573 
  2576 
  2574 static void emit_GLSL_ENDREP(Context *ctx)
  2577 static void emit_GLSL_ENDREP(Context *ctx)
  2575 {
  2578 {
  2916     fail(ctx, "unimplemented.");  // !!! FIXME
  2919     fail(ctx, "unimplemented.");  // !!! FIXME
  2917 } // emit_GLSL_TEXLDD
  2920 } // emit_GLSL_TEXLDD
  2918 
  2921 
  2919 static void emit_GLSL_SETP(Context *ctx)
  2922 static void emit_GLSL_SETP(Context *ctx)
  2920 {
  2923 {
  2921     const char *comp = get_GLSL_comparison_string_vector(ctx);
  2924     const int vecsize = vecsize_from_writemask(ctx->dest_arg.writemask);
  2922     const char *src0 = make_GLSL_srcarg_string_masked(ctx, 0);
  2925     const char *src0 = make_GLSL_srcarg_string_masked(ctx, 0);
  2923     const char *src1 = make_GLSL_srcarg_string_masked(ctx, 1);
  2926     const char *src1 = make_GLSL_srcarg_string_masked(ctx, 1);
  2924     const char *code = make_GLSL_destarg_assign(ctx, "%s(%s, %s)", comp, src0, src1);
  2927     const char *code = NULL;
       
  2928 
       
  2929     // destination is always predicate register (which is type bvec4).
       
  2930     if (vecsize == 1)
       
  2931     {
       
  2932         const char *comp = get_GLSL_comparison_string_scalar(ctx);
       
  2933         code = make_GLSL_destarg_assign(ctx, "(%s %s %s)", src0, comp, src1);
       
  2934     } // if
       
  2935     else
       
  2936     {
       
  2937         const char *comp = get_GLSL_comparison_string_vector(ctx);
       
  2938         code = make_GLSL_destarg_assign(ctx, "%s(%s, %s)", comp, src0, src1);
       
  2939     } // else
       
  2940 
  2925     output_line(ctx, "%s", code);
  2941     output_line(ctx, "%s", code);
  2926 } // emit_GLSL_SETP
  2942 } // emit_GLSL_SETP
  2927 
  2943 
  2928 static void emit_GLSL_TEXLDL(Context *ctx)
  2944 static void emit_GLSL_TEXLDL(Context *ctx)
  2929 {
  2945 {