mojoshader_compiler.c
changeset 979 f3d1c6675d97
parent 978 0e17db32f9ce
child 980 83e96d285449
equal deleted inserted replaced
978:0e17db32f9ce 979:f3d1c6675d97
  2314                 if (!is_swizzle_str(member))
  2314                 if (!is_swizzle_str(member))
  2315                 {
  2315                 {
  2316                     fail(ctx, "invalid swizzle on vector");
  2316                     fail(ctx, "invalid swizzle on vector");
  2317                     // force this to be sane for further processing.
  2317                     // force this to be sane for further processing.
  2318                     const char *sane_swiz = stringcache(ctx->strcache, "xyzw");
  2318                     const char *sane_swiz = stringcache(ctx->strcache, "xyzw");
  2319                     ast->derefstruct.member = sane_swiz;
  2319                     member = ast->derefstruct.member = sane_swiz;
  2320                 } // if
  2320                 } // if
  2321                 ast->derefstruct.datatype = datatype;  // !!! FIXME: should float4(0,0,0,0).xy become a float2?
  2321 
       
  2322                 const int swizlen = (int) strlen(member);
       
  2323                 if (swizlen == reduced->vector.elements)
       
  2324                     datatype = reduced;
       
  2325                 else
       
  2326                 {
       
  2327                     const char *typestr = NULL;
       
  2328                     switch (reduced->vector.base->type)
       
  2329                     {
       
  2330                         case MOJOSHADER_AST_DATATYPE_BOOL: typestr = "bool"; break;
       
  2331                         case MOJOSHADER_AST_DATATYPE_INT: typestr = "int"; break;
       
  2332                         case MOJOSHADER_AST_DATATYPE_UINT: typestr = "uint"; break;
       
  2333                         case MOJOSHADER_AST_DATATYPE_HALF: typestr = "half"; break;
       
  2334                         case MOJOSHADER_AST_DATATYPE_FLOAT: typestr = "float"; break;
       
  2335                         case MOJOSHADER_AST_DATATYPE_DOUBLE: typestr = "double"; break;
       
  2336                         default: assert(0 && "This shouldn't happen"); break;
       
  2337                     } // switch
       
  2338 
       
  2339                     char buf[32];
       
  2340                     snprintf(buf, sizeof (buf), "%s%d", typestr, swizlen);
       
  2341                     datatype = get_usertype(ctx, buf);
       
  2342                     assert(datatype != NULL);
       
  2343                 } // else
       
  2344 
       
  2345                 ast->derefstruct.datatype = datatype;
  2322                 return ast->derefstruct.datatype;
  2346                 return ast->derefstruct.datatype;
  2323             } // if
  2347             } // if
  2324 
  2348 
  2325             // maybe this is an actual struct?
  2349             // maybe this is an actual struct?
  2326             // !!! FIXME: replace with an int or something if not.
  2350             // !!! FIXME: replace with an int or something if not.