mojoshader.c
changeset 1184 62922fc6abe9
parent 1183 ec44ee868688
child 1188 25000edc0176
equal deleted inserted replaced
1183:ec44ee868688 1184:62922fc6abe9
  2225         if (shader_is_vertex(ctx))
  2225         if (shader_is_vertex(ctx))
  2226             output_line(ctx, "precision highp float;");
  2226             output_line(ctx, "precision highp float;");
  2227         else
  2227         else
  2228             output_line(ctx, "precision mediump float;");
  2228             output_line(ctx, "precision mediump float;");
  2229         output_line(ctx, "precision mediump int;");
  2229         output_line(ctx, "precision mediump int;");
  2230         // Some drivers don't like it when the precision varies between shaders. -ade
       
  2231         output_line(ctx, "varying highp vec4 v_FrontColor;");
       
  2232         output_line(ctx, "varying highp vec4 v_FrontSecondaryColor;");
       
  2233         output_line(ctx, "varying highp vec4 v_TexCoord[10];"); // 10 according to SM3
       
  2234         pop_output(ctx);
  2230         pop_output(ctx);
  2235     } // else if
  2231     } // else if
  2236     #endif
  2232     #endif
  2237 
  2233 
  2238     else
  2234     else
  2347                 //  they work like temps, initialize with tex coords, and the
  2343                 //  they work like temps, initialize with tex coords, and the
  2348                 //  ps_1_1 TEX opcode expects to overwrite it.
  2344                 //  ps_1_1 TEX opcode expects to overwrite it.
  2349                 if (!shader_version_atleast(ctx, 1, 4))
  2345                 if (!shader_version_atleast(ctx, 1, 4))
  2350                 {
  2346                 {
  2351 #if SUPPORT_PROFILE_GLSLES
  2347 #if SUPPORT_PROFILE_GLSLES
       
  2348                     // GLSL ES does not have gl_TexCoord
  2352                     if (support_glsles(ctx))
  2349                     if (support_glsles(ctx))
  2353                         output_line(ctx, "vec4 %s = v_TexCoord[%d];",
  2350                         output_line(ctx, "vec4 %s = io_%i_%i;",
  2354                                     varname, regnum);
  2351                                     varname, MOJOSHADER_USAGE_TEXCOORD, regnum);
  2355                     else
  2352                     else
  2356 #endif
  2353 #endif
  2357                     output_line(ctx, "vec4 %s = gl_TexCoord[%d];",
  2354                     output_line(ctx, "vec4 %s = gl_TexCoord[%d];",
  2358                                 varname, regnum);
  2355                                 varname, regnum);
  2359                 } // if
  2356                 } // if
  2612                     break;
  2609                     break;
  2613                 case MOJOSHADER_USAGE_POINTSIZE:
  2610                 case MOJOSHADER_USAGE_POINTSIZE:
  2614                     usage_str = "gl_PointSize";
  2611                     usage_str = "gl_PointSize";
  2615                     break;
  2612                     break;
  2616                 case MOJOSHADER_USAGE_COLOR:
  2613                 case MOJOSHADER_USAGE_COLOR:
       
  2614 #if SUPPORT_PROFILE_GLSLES
       
  2615                     if (support_glsles(ctx))
       
  2616                         break; // GLSL ES does not have gl_FrontColor
       
  2617 #endif
  2617                     index_str[0] = '\0';  // no explicit number.
  2618                     index_str[0] = '\0';  // no explicit number.
  2618                     if (index == 0)
  2619                     if (index == 0)
  2619                     {
  2620                     {
  2620 #if SUPPORT_PROFILE_GLSLES
       
  2621                         if (support_glsles(ctx))
       
  2622                             usage_str = "v_FrontColor";
       
  2623                         else
       
  2624 #endif
       
  2625                         usage_str = "gl_FrontColor";
  2621                         usage_str = "gl_FrontColor";
  2626                     } // if
  2622                     } // if
  2627                     else if (index == 1)
  2623                     else if (index == 1)
  2628                     {
  2624                     {
  2629 #if SUPPORT_PROFILE_GLSLES
       
  2630                         if (support_glsles(ctx))
       
  2631                             usage_str = "v_FrontSecondaryColor";
       
  2632                         else
       
  2633 #endif
       
  2634                         usage_str = "gl_FrontSecondaryColor";
  2625                         usage_str = "gl_FrontSecondaryColor";
  2635                     } // else if
  2626                     } // else if
  2636                     break;
  2627                     break;
  2637                 case MOJOSHADER_USAGE_FOG:
  2628                 case MOJOSHADER_USAGE_FOG:
  2638                     usage_str = "gl_FogFragCoord";
  2629                     usage_str = "gl_FogFragCoord";
  2639                     break;
  2630                     break;
  2640                 case MOJOSHADER_USAGE_TEXCOORD:
  2631                 case MOJOSHADER_USAGE_TEXCOORD:
  2641                     snprintf(index_str, sizeof (index_str), "%u", (uint) index);
       
  2642 #if SUPPORT_PROFILE_GLSLES
  2632 #if SUPPORT_PROFILE_GLSLES
  2643                     if (support_glsles(ctx))
  2633                     if (support_glsles(ctx))
  2644                         usage_str = "v_TexCoord";
  2634                         break; // GLSL ES does not have gl_TexCoord
  2645                     else
       
  2646 #endif
  2635 #endif
       
  2636                     snprintf(index_str, sizeof (index_str), "%u", (uint) index);
  2647                     usage_str = "gl_TexCoord";
  2637                     usage_str = "gl_TexCoord";
  2648                     arrayleft = "[";
  2638                     arrayleft = "[";
  2649                     arrayright = "]";
  2639                     arrayright = "]";
  2650                     break;
  2640                     break;
  2651                 default:
  2641                 default:
  2708             usage_str = "gl_FragDepth";
  2698             usage_str = "gl_FragDepth";
  2709 
  2699 
  2710         // !!! FIXME: can you actualy have a texture register with COLOR usage?
  2700         // !!! FIXME: can you actualy have a texture register with COLOR usage?
  2711         else if ((regtype == REG_TYPE_TEXTURE) || (regtype == REG_TYPE_INPUT))
  2701         else if ((regtype == REG_TYPE_TEXTURE) || (regtype == REG_TYPE_INPUT))
  2712         {
  2702         {
       
  2703 #if SUPPORT_PROFILE_GLSLES
       
  2704             if (!support_glsles(ctx))
       
  2705             {
       
  2706 #endif
  2713             if (usage == MOJOSHADER_USAGE_TEXCOORD)
  2707             if (usage == MOJOSHADER_USAGE_TEXCOORD)
  2714             {
  2708             {
  2715                 // ps_1_1 does a different hack for this attribute.
  2709                 // ps_1_1 does a different hack for this attribute.
  2716                 //  Refer to emit_GLSL_global()'s REG_TYPE_ADDRESS code.
  2710                 //  Refer to emit_GLSL_global()'s REG_TYPE_ADDRESS code.
  2717                 if (shader_version_atleast(ctx, 1, 4))
  2711                 if (shader_version_atleast(ctx, 1, 4))
  2718                 {
  2712                 {
  2719                     snprintf(index_str, sizeof (index_str), "%u", (uint) index);
  2713                     snprintf(index_str, sizeof (index_str), "%u", (uint) index);
  2720 #if SUPPORT_PROFILE_GLSLES
       
  2721                     if (support_glsles(ctx))
       
  2722                         usage_str = "v_TexCoord";
       
  2723                     else
       
  2724 #endif
       
  2725                     usage_str = "gl_TexCoord";
  2714                     usage_str = "gl_TexCoord";
  2726                     arrayleft = "[";
  2715                     arrayleft = "[";
  2727                     arrayright = "]";
  2716                     arrayright = "]";
  2728                 } // if
  2717                 } // if
  2729             } // if
  2718             } // if
  2731             else if (usage == MOJOSHADER_USAGE_COLOR)
  2720             else if (usage == MOJOSHADER_USAGE_COLOR)
  2732             {
  2721             {
  2733                 index_str[0] = '\0';  // no explicit number.
  2722                 index_str[0] = '\0';  // no explicit number.
  2734                 if (index == 0)
  2723                 if (index == 0)
  2735                 {
  2724                 {
  2736 #if SUPPORT_PROFILE_GLSLES
       
  2737                     if (support_glsles(ctx))
       
  2738                         usage_str = "v_FrontColor";
       
  2739                     else
       
  2740 #endif
       
  2741                     usage_str = "gl_Color";
  2725                     usage_str = "gl_Color";
  2742                 } // if
  2726                 } // if
  2743                 else if (index == 1)
  2727                 else if (index == 1)
  2744                 {
  2728                 {
  2745 #if SUPPORT_PROFILE_GLSLES
       
  2746                     if (support_glsles(ctx))
       
  2747                         usage_str = "v_FrontSecondaryColor";
       
  2748                     else
       
  2749 #endif
       
  2750                     usage_str = "gl_SecondaryColor";
  2729                     usage_str = "gl_SecondaryColor";
  2751                 } // else if
  2730                 } // else if
  2752                 // FIXME: Does this even matter when we have varyings? -flibit
  2731                 // FIXME: Does this even matter when we have varyings? -flibit
  2753                 // else
  2732                 // else
  2754                 //    fail(ctx, "unsupported color index");
  2733                 //    fail(ctx, "unsupported color index");
  2755             } // else if
  2734             } // else if
       
  2735 #if SUPPORT_PROFILE_GLSLES
       
  2736             } // if
       
  2737 #endif
  2756         } // else if
  2738         } // else if
  2757 
  2739 
  2758         else if (regtype == REG_TYPE_MISCTYPE)
  2740         else if (regtype == REG_TYPE_MISCTYPE)
  2759         {
  2741         {
  2760             const MiscTypeType mt = (MiscTypeType) regnum;
  2742             const MiscTypeType mt = (MiscTypeType) regnum;