mojoshader.c
changeset 1173 4b2f745c643b
parent 1169 68e644e677fd
child 1174 e83fe013f0c5
equal deleted inserted replaced
1172:55700e64bd8c 1173:4b2f745c643b
  2222         if (shader_is_vertex(ctx))
  2222         if (shader_is_vertex(ctx))
  2223             output_line(ctx, "precision highp float;");
  2223             output_line(ctx, "precision highp float;");
  2224         else
  2224         else
  2225             output_line(ctx, "precision mediump float;");
  2225             output_line(ctx, "precision mediump float;");
  2226         output_line(ctx, "precision mediump int;");
  2226         output_line(ctx, "precision mediump int;");
  2227         output_line(ctx, "varying vec4 v_FrontColor;");
  2227         // Some drivers don't like it when the precision varies between shaders. -ade
  2228         output_line(ctx, "varying vec4 v_FrontSecondaryColor;");
  2228         output_line(ctx, "varying highp vec4 v_FrontColor;");
  2229         output_line(ctx, "varying vec4 v_TexCoord[10];"); // 10 according to SM3
  2229         output_line(ctx, "varying highp vec4 v_FrontSecondaryColor;");
       
  2230         output_line(ctx, "varying highp vec4 v_TexCoord[10];"); // 10 according to SM3
  2230         pop_output(ctx);
  2231         pop_output(ctx);
  2231     } // else if
  2232     } // else if
  2232     #endif
  2233     #endif
  2233 
  2234 
  2234     else
  2235     else
  2342                 // We have to map texture registers to temps for ps_1_1, since
  2343                 // We have to map texture registers to temps for ps_1_1, since
  2343                 //  they work like temps, initialize with tex coords, and the
  2344                 //  they work like temps, initialize with tex coords, and the
  2344                 //  ps_1_1 TEX opcode expects to overwrite it.
  2345                 //  ps_1_1 TEX opcode expects to overwrite it.
  2345                 if (!shader_version_atleast(ctx, 1, 4))
  2346                 if (!shader_version_atleast(ctx, 1, 4))
  2346                 {
  2347                 {
       
  2348 #if SUPPORT_PROFILE_GLSLES
       
  2349                     if (support_glsles(ctx))
       
  2350                         output_line(ctx, "vec4 %s = v_TexCoord[%d];",
       
  2351                                     varname, regnum);
       
  2352                     else
       
  2353 #endif
  2347                     output_line(ctx, "vec4 %s = gl_TexCoord[%d];",
  2354                     output_line(ctx, "vec4 %s = gl_TexCoord[%d];",
  2348                                 varname, regnum);
  2355                                 varname, regnum);
  2349                 } // if
  2356                 } // if
  2350             } // else if
  2357             } // else if
  2351             break;
  2358             break;
  2646             // !!! FIXME: the #define is a little hacky, but it means we don't
  2653             // !!! FIXME: the #define is a little hacky, but it means we don't
  2647             // !!! FIXME:  have to track these separately if this works.
  2654             // !!! FIXME:  have to track these separately if this works.
  2648             push_output(ctx, &ctx->globals);
  2655             push_output(ctx, &ctx->globals);
  2649             // no mapping to built-in var? Just make it a regular global, pray.
  2656             // no mapping to built-in var? Just make it a regular global, pray.
  2650             if (usage_str == NULL)
  2657             if (usage_str == NULL)
  2651                 output_line(ctx, "vec4 %s;", var);
  2658             {
       
  2659 #if SUPPORT_PROFILE_GLSLES
       
  2660                 if (support_glsles(ctx))
       
  2661                     output_line(ctx, "varying highp vec4 io_%i_%i;", usage, index);
       
  2662                 else
       
  2663 #endif
       
  2664                 output_line(ctx, "varying vec4 io_%i_%i;", usage, index);
       
  2665                 output_line(ctx, "#define %s io_%i_%i", var, usage, index);
       
  2666             } // if
  2652             else
  2667             else
  2653             {
  2668             {
  2654                 output_line(ctx, "#define %s %s%s%s%s", var, usage_str,
  2669                 output_line(ctx, "#define %s %s%s%s%s", var, usage_str,
  2655                             arrayleft, index_str, arrayright);
  2670                             arrayleft, index_str, arrayright);
  2656             } // else
  2671             } // else
  2729                         usage_str = "v_FrontSecondaryColor";
  2744                         usage_str = "v_FrontSecondaryColor";
  2730                     else
  2745                     else
  2731 #endif
  2746 #endif
  2732                     usage_str = "gl_SecondaryColor";
  2747                     usage_str = "gl_SecondaryColor";
  2733                 } // else if
  2748                 } // else if
  2734                 else
  2749                 // FIXME: Does this even matter when we have varyings? -flibit
  2735                     fail(ctx, "unsupported color index");
  2750                 // else
  2736             } // else if
  2751                 //    fail(ctx, "unsupported color index");
  2737 
       
  2738             else if (usage == MOJOSHADER_USAGE_DEPTH) // !!! FIXME: Possibly more! -flibit
       
  2739             {
       
  2740                 push_output(ctx, &ctx->globals);
       
  2741                 output_line(ctx, "attribute vec4 %s;", var);
       
  2742                 pop_output(ctx);
       
  2743             } // else if
  2752             } // else if
  2744         } // else if
  2753         } // else if
  2745 
  2754 
  2746         else if (regtype == REG_TYPE_MISCTYPE)
  2755         else if (regtype == REG_TYPE_MISCTYPE)
  2747         {
  2756         {
  2766         else
  2775         else
  2767         {
  2776         {
  2768             fail(ctx, "unknown pixel shader attribute register");
  2777             fail(ctx, "unknown pixel shader attribute register");
  2769         } // else
  2778         } // else
  2770 
  2779 
  2771         if (usage_str != NULL)
  2780         push_output(ctx, &ctx->globals);
  2772         {
  2781         // no mapping to built-in var? Just make it a regular global, pray.
  2773             push_output(ctx, &ctx->globals);
  2782         if (usage_str == NULL)
       
  2783         {
       
  2784 #if SUPPORT_PROFILE_GLSLES
       
  2785             if (support_glsles(ctx))
       
  2786                 output_line(ctx, "varying highp vec4 io_%i_%i;", usage, index);
       
  2787             else
       
  2788 #endif
       
  2789             output_line(ctx, "varying vec4 io_%i_%i;", usage, index);
       
  2790             output_line(ctx, "#define %s io_%i_%i", var, usage, index);
       
  2791         } // if
       
  2792         else
       
  2793         {
  2774             output_line(ctx, "#define %s %s%s%s%s", var, usage_str,
  2794             output_line(ctx, "#define %s %s%s%s%s", var, usage_str,
  2775                         arrayleft, index_str, arrayright);
  2795                         arrayleft, index_str, arrayright);
  2776             pop_output(ctx);
  2796         } // else
  2777         } // if
  2797         pop_output(ctx);
  2778     } // else if
  2798     } // else if
  2779 
  2799 
  2780     else
  2800     else
  2781     {
  2801     {
  2782         fail(ctx, "Unknown shader type");  // state machine should catch this.
  2802         fail(ctx, "Unknown shader type");  // state machine should catch this.
  5029                 else if (usage == MOJOSHADER_USAGE_COLOR)
  5049                 else if (usage == MOJOSHADER_USAGE_COLOR)
  5030                     output_line(ctx, "float4 %s [[user(color%d)]];", var, index);
  5050                     output_line(ctx, "float4 %s [[user(color%d)]];", var, index);
  5031 
  5051 
  5032                 else if (usage == MOJOSHADER_USAGE_FOG)
  5052                 else if (usage == MOJOSHADER_USAGE_FOG)
  5033                     output_line(ctx, "float4 %s [[user(fog)]];", var);
  5053                     output_line(ctx, "float4 %s [[user(fog)]];", var);
  5034 
       
  5035                 #if 0  // !!! FIXME: Ethan added this for GLSL, but I don't know what it does.  --ryan.
       
  5036                 else if (usage == MOJOSHADER_USAGE_DEPTH) // !!! FIXME: Possibly more! -flibit
       
  5037                 {
       
  5038                     push_output(ctx, &ctx->globals);
       
  5039                     output_line(ctx, "attribute vec4 %s;", var);
       
  5040                     pop_output(ctx);
       
  5041                 } // else if
       
  5042                 #endif
       
  5043             } // else
  5054             } // else
  5044 
  5055 
  5045             pop_output(ctx);
  5056             pop_output(ctx);
  5046 
  5057 
  5047             // !!! FIXME: can cause unused var warnings in Clang...
  5058             // !!! FIXME: can cause unused var warnings in Clang...