Skip to content

Commit

Permalink
Allow preshader support to be #ifdef'd out, to reduce binary size.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed May 31, 2011
1 parent 2d3e8a4 commit 43fa79c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions mojoshader.c
Expand Up @@ -7091,6 +7091,10 @@ static void parse_preshader(Context *ctx, uint32 tokcount)
if ((tokcount < 2) || (SWAP32(tokens[1]) != PRES_ID))
return; // not a preshader.

#if !SUPPORT_PRESHADERS
fail(ctx, "Preshader found, but preshader support is disabled!");
#else

assert(ctx->have_preshader == 0); // !!! FIXME: can you have more than one?
ctx->have_preshader = 1;

Expand Down Expand Up @@ -7396,6 +7400,7 @@ static void parse_preshader(Context *ctx, uint32 tokcount)
parse_preshader_cleanup:
free_symbols(ctx->free, ctx->malloc_data,
ctabdata.symbols, ctabdata.symbol_count);
#endif
} // parse_preshader


Expand Down
8 changes: 5 additions & 3 deletions mojoshader_effects.c
Expand Up @@ -12,7 +12,9 @@

#include <math.h>

void run_preshader(const MOJOSHADER_preshader *preshader, float *regs)
#if SUPPORT_PRESHADERS
void MOJOSHADER_runPreshader(const MOJOSHADER_preshader *preshader,
float *regs)
{
// this is fairly straightforward, as there aren't any branching
// opcodes in the preshader instruction set (at the moment, at least).
Expand Down Expand Up @@ -162,8 +164,8 @@ void run_preshader(const MOJOSHADER_preshader *preshader, float *regs)
regs[operand->index + i] = (float) dst[i];
} // else
} // for
} // run_preshader

} // MOJOSHADER_runPreshader
#endif

static MOJOSHADER_effect MOJOSHADER_out_of_mem_effect = {
1, &MOJOSHADER_out_of_mem_error, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Expand Down
15 changes: 14 additions & 1 deletion mojoshader_internal.h
Expand Up @@ -60,7 +60,6 @@
#define SUPPORT_PROFILE_ARB1_NV 1
#endif


#if SUPPORT_PROFILE_ARB1_NV && !SUPPORT_PROFILE_ARB1
#error nv profiles require arb1 profile. Fix your build.
#endif
Expand All @@ -70,6 +69,20 @@
#endif


// Other stuff you can disable...

// This removes the preshader parsing and execution code. You can save some
// bytes if you have normal shaders and not Effect files.
#ifndef SUPPORT_PRESHADERS
#define SUPPORT_PRESHADERS 1
#endif

#if SUPPORT_PRESHADERS
void MOJOSHADER_runPreshader(const MOJOSHADER_preshader *, float *);
#else
#define MOJOSHADER_runPreshader(a, b)
#endif


// Get basic wankery out of the way here...

Expand Down

0 comments on commit 43fa79c

Please sign in to comment.