mojoshader.h
changeset 1104 9147482e1ec7
parent 1090 636ffcd3f14a
child 1106 2bef26cc20f9
equal deleted inserted replaced
1103:8b7c29c019d5 1104:9147482e1ec7
   187     MOJOSHADER_samplerType type;
   187     MOJOSHADER_samplerType type;
   188     int index;
   188     int index;
   189     const char *name;
   189     const char *name;
   190     int texbem;
   190     int texbem;
   191 } MOJOSHADER_sampler;
   191 } MOJOSHADER_sampler;
       
   192 
       
   193 
       
   194 /*
       
   195  * This struct is used if you have to force a sampler to a specific type.
       
   196  *  Generally, you can ignore this, but if you have, say, a ps_1_1
       
   197  *  shader, you might need to specify what the samplers are meant to be
       
   198  *  to get correct results, as Shader Model 1 samples textures according
       
   199  *  to what is bound to a sampler at the moment instead of what the shader
       
   200  *  is hardcoded to expect.
       
   201  */
       
   202 typedef struct MOJOSHADER_samplerMap
       
   203 {
       
   204     int index;
       
   205     MOJOSHADER_samplerType type;
       
   206 } MOJOSHADER_samplerMap;
   192 
   207 
   193 /*
   208 /*
   194  * Data types for attributes. See MOJOSHADER_attribute for more information.
   209  * Data types for attributes. See MOJOSHADER_attribute for more information.
   195  */
   210  */
   196 typedef enum
   211 typedef enum
   693  *  that COLOR0 should be RGBA but you're passing in ARGB, you can specify
   708  *  that COLOR0 should be RGBA but you're passing in ARGB, you can specify
   694  *  a swizzle of { MOJOSHADER_USAGE_COLOR, 0, {1,2,3,0} } to (swiz). If the
   709  *  a swizzle of { MOJOSHADER_USAGE_COLOR, 0, {1,2,3,0} } to (swiz). If the
   695  *  input register in the code would produce reg.ywzx, that swizzle would
   710  *  input register in the code would produce reg.ywzx, that swizzle would
   696  *  change it to reg.wzxy ... (swiz) can be NULL.
   711  *  change it to reg.wzxy ... (swiz) can be NULL.
   697  *
   712  *
       
   713  * You can force the shader to expect samplers of certain types. Generally
       
   714  *  you don't need this, as Shader Model 2 and later always specify what they
       
   715  *  expect samplers to be (2D, cubemap, etc). Shader Model 1, however, just
       
   716  *  uses whatever is bound to a given sampler at draw time, but this doesn't
       
   717  *  work in OpenGL, etc. In these cases, MojoShader will default to
       
   718  *  2D texture sampling, which works 75% of the time, but if you really
       
   719  *  needed something else, you'll need to specify it here. This can also be
       
   720  *  used, at your own risk, to override DCL opcodes in shaders: if the
       
   721  *  shader explicit says 2D, but you want Cubemap, for example, you can use
       
   722  *  this to override. If you aren't sure about any of this stuff, you can
       
   723  *  almost certainly ignore it: (smap) can be NULL.
       
   724  *
   698  * This function is thread safe, so long as (m) and (f) are too, and that
   725  * This function is thread safe, so long as (m) and (f) are too, and that
   699  *  (tokenbuf) remains intact for the duration of the call. This allows you
   726  *  (tokenbuf) remains intact for the duration of the call. This allows you
   700  *  to parse several shaders on separate CPU cores at the same time.
   727  *  to parse several shaders on separate CPU cores at the same time.
   701  */
   728  */
   702 const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile,
   729 const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile,
   703                                              const unsigned char *tokenbuf,
   730                                              const unsigned char *tokenbuf,
   704                                              const unsigned int bufsize,
   731                                              const unsigned int bufsize,
   705                                              const MOJOSHADER_swizzle *swiz,
   732                                              const MOJOSHADER_swizzle *swiz,
   706                                              const unsigned int swizcount,
   733                                              const unsigned int swizcount,
       
   734                                              const MOJOSHADER_samplerMap *smap,
       
   735                                              const unsigned int smapcount,
   707                                              MOJOSHADER_malloc m,
   736                                              MOJOSHADER_malloc m,
   708                                              MOJOSHADER_free f,
   737                                              MOJOSHADER_free f,
   709                                              void *d);
   738                                              void *d);
   710 
   739 
   711 /*
   740 /*
   852 const MOJOSHADER_effect *MOJOSHADER_parseEffect(const char *profile,
   881 const MOJOSHADER_effect *MOJOSHADER_parseEffect(const char *profile,
   853                                                 const unsigned char *buf,
   882                                                 const unsigned char *buf,
   854                                                 const unsigned int _len,
   883                                                 const unsigned int _len,
   855                                                 const MOJOSHADER_swizzle *swiz,
   884                                                 const MOJOSHADER_swizzle *swiz,
   856                                                 const unsigned int swizcount,
   885                                                 const unsigned int swizcount,
       
   886                                                 const MOJOSHADER_samplerMap *smap,
       
   887                                                 const unsigned int smapcount,
   857                                                 MOJOSHADER_malloc m,
   888                                                 MOJOSHADER_malloc m,
   858                                                 MOJOSHADER_free f,
   889                                                 MOJOSHADER_free f,
   859                                                 void *d);
   890                                                 void *d);
   860 
   891 
   861 
   892 
  2632  * Compile a buffer of Direct3D shader bytecode into an OpenGL shader.
  2663  * Compile a buffer of Direct3D shader bytecode into an OpenGL shader.
  2633  *  You still need to link the shader before you may render with it.
  2664  *  You still need to link the shader before you may render with it.
  2634  *
  2665  *
  2635  *   (tokenbuf) is a buffer of Direct3D shader bytecode.
  2666  *   (tokenbuf) is a buffer of Direct3D shader bytecode.
  2636  *   (bufsize) is the size, in bytes, of the bytecode buffer.
  2667  *   (bufsize) is the size, in bytes, of the bytecode buffer.
  2637  *   (swiz) and (swizcount) are passed to MOJOSHADER_parse() unmolested.
  2668  *   (swiz), (swizcount), (smap), and (smapcount) are passed to
       
  2669  *   MOJOSHADER_parse() unmolested.
  2638  *
  2670  *
  2639  * Returns NULL on error, or a shader handle on success.
  2671  * Returns NULL on error, or a shader handle on success.
  2640  *
  2672  *
  2641  * This call is NOT thread safe! As most OpenGL implementations are not thread
  2673  * This call is NOT thread safe! As most OpenGL implementations are not thread
  2642  *  safe, you should probably only call this from the same thread that created
  2674  *  safe, you should probably only call this from the same thread that created
  2648  * Compiled shaders from this function may not be shared between contexts.
  2680  * Compiled shaders from this function may not be shared between contexts.
  2649  */
  2681  */
  2650 MOJOSHADER_glShader *MOJOSHADER_glCompileShader(const unsigned char *tokenbuf,
  2682 MOJOSHADER_glShader *MOJOSHADER_glCompileShader(const unsigned char *tokenbuf,
  2651                                                 const unsigned int bufsize,
  2683                                                 const unsigned int bufsize,
  2652                                                 const MOJOSHADER_swizzle *swiz,
  2684                                                 const MOJOSHADER_swizzle *swiz,
  2653                                                 const unsigned int swizcount);
  2685                                                 const unsigned int swizcount,
       
  2686                                                 const MOJOSHADER_samplerMap *smap,
       
  2687                                                 const unsigned int smapcount);
  2654 
  2688 
  2655 
  2689 
  2656 /*
  2690 /*
  2657  * Get the MOJOSHADER_parseData structure that was produced from the
  2691  * Get the MOJOSHADER_parseData structure that was produced from the
  2658  *  call to MOJOSHADER_glCompileShader().
  2692  *  call to MOJOSHADER_glCompileShader().