mojoshader.c
branchtrunk
changeset 232 dbb39e20ed9a
parent 231 be53929fe38f
child 233 ba5abb771d6f
equal deleted inserted replaced
231:be53929fe38f 232:dbb39e20ed9a
  1974     pop_output(ctx);
  1974     pop_output(ctx);
  1975 } // emit_GLSL_finalize
  1975 } // emit_GLSL_finalize
  1976 
  1976 
  1977 static void emit_GLSL_global(Context *ctx, RegisterType regtype, int regnum)
  1977 static void emit_GLSL_global(Context *ctx, RegisterType regtype, int regnum)
  1978 {
  1978 {
       
  1979     const char *varname = get_GLSL_varname(ctx, regtype, regnum);
       
  1980 
  1979     push_output(ctx, &ctx->globals);
  1981     push_output(ctx, &ctx->globals);
  1980     switch (regtype)
  1982     switch (regtype)
  1981     {
  1983     {
  1982         case REG_TYPE_ADDRESS:
  1984         case REG_TYPE_ADDRESS:
  1983             output_line(ctx, "ivec4 a%d;", regnum);
  1985             output_line(ctx, "ivec4 %s;", varname);
  1984             break;
  1986             break;
  1985         case REG_TYPE_PREDICATE:
  1987         case REG_TYPE_PREDICATE:
  1986             output_line(ctx, "bvec4 p%d;", regnum);
  1988             output_line(ctx, "bvec4 %s;", varname);
  1987             break;
  1989             break;
  1988         case REG_TYPE_TEMP:
  1990         case REG_TYPE_TEMP:
  1989             output_line(ctx, "vec4 r%d;", regnum);
  1991             output_line(ctx, "vec4 %s;", varname);
  1990             break;
  1992             break;
  1991         case REG_TYPE_LOOP:
  1993         case REG_TYPE_LOOP:
  1992             break; // no-op. We declare these in for loops at the moment.
  1994             break; // no-op. We declare these in for loops at the moment.
  1993         case REG_TYPE_LABEL:
  1995         case REG_TYPE_LABEL:
  1994             break; // no-op. If we see it here, it means we optimized it out.
  1996             break; // no-op. If we see it here, it means we optimized it out.
  1999     pop_output(ctx);
  2001     pop_output(ctx);
  2000 } // emit_GLSL_global
  2002 } // emit_GLSL_global
  2001 
  2003 
  2002 static void emit_GLSL_uniform(Context *ctx, RegisterType regtype, int regnum)
  2004 static void emit_GLSL_uniform(Context *ctx, RegisterType regtype, int regnum)
  2003 {
  2005 {
       
  2006     const char *varname = get_GLSL_varname(ctx, regtype, regnum);
       
  2007 
  2004     push_output(ctx, &ctx->globals);
  2008     push_output(ctx, &ctx->globals);
  2005     if (regtype == REG_TYPE_CONST)
  2009     if (regtype == REG_TYPE_CONST)
  2006         output_line(ctx, "uniform vec4 c%d;", regnum);
  2010         output_line(ctx, "uniform vec4 %s;", varname);
  2007     else if (regtype == REG_TYPE_CONST2)
  2011     else if (regtype == REG_TYPE_CONST2)
  2008         output_line(ctx, "uniform vec4 c%d;", regnum + 2048);
  2012         output_line(ctx, "uniform vec4 %s;", varname);
  2009     else if (regtype == REG_TYPE_CONST3)
  2013     else if (regtype == REG_TYPE_CONST3)
  2010         output_line(ctx, "uniform vec4 c%d;", regnum + 4096);
  2014         output_line(ctx, "uniform vec4 %s;", varname);
  2011     else if (regtype == REG_TYPE_CONST4)
  2015     else if (regtype == REG_TYPE_CONST4)
  2012         output_line(ctx, "uniform vec4 c%d;", regnum + 6144);
  2016         output_line(ctx, "uniform vec4 %s;", varname);
  2013     else if (regtype == REG_TYPE_CONSTINT)
  2017     else if (regtype == REG_TYPE_CONSTINT)
  2014         output_line(ctx, "uniform ivec4 i%d;", regnum);
  2018         output_line(ctx, "uniform ivec4 %s;", varname);
  2015     else if (regtype == REG_TYPE_CONSTBOOL)
  2019     else if (regtype == REG_TYPE_CONSTBOOL)
  2016         output_line(ctx, "uniform bvec4 i%d;", regnum);
  2020         output_line(ctx, "uniform bvec4 %s;", varname);
  2017     else
  2021     else
  2018         fail(ctx, "BUG: we used a uniform we don't know how to define.");
  2022         fail(ctx, "BUG: we used a uniform we don't know how to define.");
  2019     pop_output(ctx);
  2023     pop_output(ctx);
  2020 } // emit_GLSL_uniform
  2024 } // emit_GLSL_uniform
  2021 
  2025 
  2022 static void emit_GLSL_sampler(Context *ctx, int stage, TextureType ttype)
  2026 static void emit_GLSL_sampler(Context *ctx, int stage, TextureType ttype)
  2023 {
  2027 {
       
  2028     const char *varname = get_GLSL_varname(ctx, REG_TYPE_SAMPLER, stage);
       
  2029 
  2024     push_output(ctx, &ctx->globals);
  2030     push_output(ctx, &ctx->globals);
  2025     if (ttype == TEXTURE_TYPE_2D)
  2031     if (ttype == TEXTURE_TYPE_2D)
  2026         output_line(ctx, "uniform sampler2D s%d;", stage);
  2032         output_line(ctx, "uniform sampler2D %s", varname);
  2027     else if (ttype == TEXTURE_TYPE_CUBE)
  2033     else if (ttype == TEXTURE_TYPE_CUBE)
  2028         output_line(ctx, "uniform samplerCube s%d;", stage);
  2034         output_line(ctx, "uniform samplerCube %s", varname);
  2029     else if (ttype == TEXTURE_TYPE_VOLUME)
  2035     else if (ttype == TEXTURE_TYPE_VOLUME)
  2030         output_line(ctx, "uniform sampler3D s%d;", stage);
  2036         output_line(ctx, "uniform sampler3D %s", varname);
  2031     else
  2037     else
  2032         fail(ctx, "BUG: we used a sampler we don't know how to define.");
  2038         fail(ctx, "BUG: we used a sampler we don't know how to define.");
  2033     pop_output(ctx);
  2039     pop_output(ctx);
  2034 } // emit_GLSL_sampler
  2040 } // emit_GLSL_sampler
  2035 
  2041