Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
More work on sampler remapping...3D should probably default to cubema…
…ps, etc.
  • Loading branch information
icculus committed May 29, 2012
1 parent 925dbf1 commit 14d62a2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
19 changes: 17 additions & 2 deletions mojoshader.c
Expand Up @@ -3452,7 +3452,6 @@ static void emit_GLSL_TEXM3X2TEX(Context *ctx)
// !!! FIXME: this code counts on the register not having swizzles, etc.
get_GLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum,
sampler, sizeof (sampler));

get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x2pad_src0,
src0, sizeof (src0));
get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x2pad_dst0,
Expand Down Expand Up @@ -7464,7 +7463,7 @@ static void state_texops(Context *ctx, const char *opcode,

if (dims)
{
TextureType ttyp = (dims == 2) ? TEXTURE_TYPE_2D : TEXTURE_TYPE_VOLUME;
TextureType ttyp = (dims == 2) ? TEXTURE_TYPE_2D : TEXTURE_TYPE_CUBE;
add_sampler(ctx, dst->regnum, ttyp, texbem);
} // if

Expand Down Expand Up @@ -7538,6 +7537,14 @@ static void state_TEXM3X2TEX(Context *ctx)
// !!! FIXME: check for correct opcode existance and order more rigorously?
state_texops(ctx, "TEXM3X2TEX", 2, 0);
ctx->reset_texmpad = 1;

RegisterList *sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER,
ctx->dest_arg.regnum);
const TextureType ttype = (TextureType) (sreg ? sreg->index : 0);

// A samplermap might change this to something nonsensical.
if (ttype != TEXTURE_TYPE_2D)
fail(ctx, "TEXM3X2TEX needs a 2D sampler");
} // state_TEXM3X2TEX

static void state_TEXM3X3PAD(Context *ctx)
Expand Down Expand Up @@ -7568,6 +7575,14 @@ static void state_texm3x3(Context *ctx, const char *opcode, const int dims)
failf(ctx, "%s opcode without matching TEXM3X3PADs", opcode);
state_texops(ctx, opcode, dims, 0);
ctx->reset_texmpad = 1;

RegisterList *sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER,
ctx->dest_arg.regnum);
const TextureType ttype = (TextureType) (sreg ? sreg->index : 0);

// A samplermap might change this to something nonsensical.
if ((ttype != TEXTURE_TYPE_VOLUME) && (ttype != TEXTURE_TYPE_CUBE))
failf(ctx, "%s needs a 3D or Cubemap sampler", opcode);
} // state_texm3x3

static void state_TEXM3X3(Context *ctx)
Expand Down
13 changes: 7 additions & 6 deletions mojoshader.h
Expand Up @@ -715,12 +715,13 @@ int MOJOSHADER_maxShaderModel(const char *profile);
* expect samplers to be (2D, cubemap, etc). Shader Model 1, however, just
* uses whatever is bound to a given sampler at draw time, but this doesn't
* work in OpenGL, etc. In these cases, MojoShader will default to
* 2D texture sampling, which works 75% of the time, but if you really
* needed something else, you'll need to specify it here. This can also be
* used, at your own risk, to override DCL opcodes in shaders: if the
* shader explicit says 2D, but you want Cubemap, for example, you can use
* this to override. If you aren't sure about any of this stuff, you can
* almost certainly ignore it: (smap) can be NULL.
* 2D texture sampling (or cubemap sampling, in cases where it makes sense,
* like the TEXM3X3TEX opcode), which works 75% of the time, but if you
* really needed something else, you'll need to specify it here. This can
* also be used, at your own risk, to override DCL opcodes in shaders: if
* the shader explicit says 2D, but you want Cubemap, for example, you can
* use this to override. If you aren't sure about any of this stuff, you can
* (and should) almost certainly ignore it: (smap) can be NULL.
*
* This function is thread safe, so long as (m) and (f) are too, and that
* (tokenbuf) remains intact for the duration of the call. This allows you
Expand Down

0 comments on commit 14d62a2

Please sign in to comment.