mojoshader.c
branchtrunk
changeset 233 ba5abb771d6f
parent 232 dbb39e20ed9a
child 234 c05582e582ad
equal deleted inserted replaced
232:dbb39e20ed9a 233:ba5abb771d6f
  2002 } // emit_GLSL_global
  2002 } // emit_GLSL_global
  2003 
  2003 
  2004 static void emit_GLSL_uniform(Context *ctx, RegisterType regtype, int regnum)
  2004 static void emit_GLSL_uniform(Context *ctx, RegisterType regtype, int regnum)
  2005 {
  2005 {
  2006     const char *varname = get_GLSL_varname(ctx, regtype, regnum);
  2006     const char *varname = get_GLSL_varname(ctx, regtype, regnum);
       
  2007     const char *type = NULL;
       
  2008     switch (regtype)
       
  2009     {
       
  2010         case REG_TYPE_CONST: type = "vec4"; break;
       
  2011         case REG_TYPE_CONSTINT: type = "ivec4"; break;
       
  2012         case REG_TYPE_CONSTBOOL: type = "bvec4"; break;
       
  2013         default: fail(ctx, "BUG: used a uniform we don't know how to define.");
       
  2014     } // switch
  2007 
  2015 
  2008     push_output(ctx, &ctx->globals);
  2016     push_output(ctx, &ctx->globals);
  2009     if (regtype == REG_TYPE_CONST)
  2017     output_line(ctx, "uniform %s %s;", type, varname);
  2010         output_line(ctx, "uniform vec4 %s;", varname);
       
  2011     else if (regtype == REG_TYPE_CONST2)
       
  2012         output_line(ctx, "uniform vec4 %s;", varname);
       
  2013     else if (regtype == REG_TYPE_CONST3)
       
  2014         output_line(ctx, "uniform vec4 %s;", varname);
       
  2015     else if (regtype == REG_TYPE_CONST4)
       
  2016         output_line(ctx, "uniform vec4 %s;", varname);
       
  2017     else if (regtype == REG_TYPE_CONSTINT)
       
  2018         output_line(ctx, "uniform ivec4 %s;", varname);
       
  2019     else if (regtype == REG_TYPE_CONSTBOOL)
       
  2020         output_line(ctx, "uniform bvec4 %s;", varname);
       
  2021     else
       
  2022         fail(ctx, "BUG: we used a uniform we don't know how to define.");
       
  2023     pop_output(ctx);
  2018     pop_output(ctx);
  2024 } // emit_GLSL_uniform
  2019 } // emit_GLSL_uniform
  2025 
  2020 
  2026 static void emit_GLSL_sampler(Context *ctx, int stage, TextureType ttype)
  2021 static void emit_GLSL_sampler(Context *ctx, int stage, TextureType ttype)
  2027 {
  2022 {
  2028     const char *varname = get_GLSL_varname(ctx, REG_TYPE_SAMPLER, stage);
  2023     const char *varname = get_GLSL_varname(ctx, REG_TYPE_SAMPLER, stage);
       
  2024     const char *type = NULL;
       
  2025     switch (ttype)
       
  2026     {
       
  2027         case TEXTURE_TYPE_2D: type = "sampler2D"; break;
       
  2028         case TEXTURE_TYPE_CUBE: type = "samplerCube"; break;
       
  2029         case TEXTURE_TYPE_VOLUME: type = "sampler3D"; break;
       
  2030         default: fail(ctx, "BUG: used a sampler we don't know how to define.");
       
  2031     } // switch
  2029 
  2032 
  2030     push_output(ctx, &ctx->globals);
  2033     push_output(ctx, &ctx->globals);
  2031     if (ttype == TEXTURE_TYPE_2D)
  2034     output_line(ctx, "uniform %s %s;", type, varname);
  2032         output_line(ctx, "uniform sampler2D %s", varname);
       
  2033     else if (ttype == TEXTURE_TYPE_CUBE)
       
  2034         output_line(ctx, "uniform samplerCube %s", varname);
       
  2035     else if (ttype == TEXTURE_TYPE_VOLUME)
       
  2036         output_line(ctx, "uniform sampler3D %s", varname);
       
  2037     else
       
  2038         fail(ctx, "BUG: we used a sampler we don't know how to define.");
       
  2039     pop_output(ctx);
  2035     pop_output(ctx);
  2040 } // emit_GLSL_sampler
  2036 } // emit_GLSL_sampler
  2041 
  2037 
  2042 static void emit_GLSL_attribute(Context *ctx, RegisterType regtype, int regnum,
  2038 static void emit_GLSL_attribute(Context *ctx, RegisterType regtype, int regnum,
  2043                                 MOJOSHADER_usage usage, int index, int wmask)
  2039                                 MOJOSHADER_usage usage, int index, int wmask)