Navigation Menu

Skip to content

Commit

Permalink
[svn] Chopped out a bunch of D3D2GLSL_ crap.
Browse files Browse the repository at this point in the history
--HG--
branch : trunk
  • Loading branch information
icculus committed Mar 22, 2008
1 parent bcedc4f commit dd3444f
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions d3d2glsl.c
Expand Up @@ -112,7 +112,7 @@ typedef struct
emit_start start_emitter;
emit_end end_emitter;
emit_comment comment_emitter;
} D3D2GLSL_profile;
} Profile;


typedef enum
Expand All @@ -121,7 +121,7 @@ typedef enum
SHADER_TYPE_PIXEL,
SHADER_TYPE_VERTEX,
SHADER_TYPE_TOTAL
} D3D2GLSL_shaderType;
} ShaderType;

typedef enum
{
Expand All @@ -148,22 +148,22 @@ typedef enum
REGISTER_TYPE_LABEL = 18,
REGISTER_TYPE_PREDICATE = 19,
REGISTER_TYPE_MAX = 19
} registerType;
} RegisterType;

typedef enum
{
RASTOUT_TYPE_POSITION = 0,
RASTOUT_TYPE_FOG = 1,
RASTOUT_TYPE_POINT_SIZE = 2,
RASTOUT_TYPE_MAX = 2
} D3D2GLSL_rastoutType;
} RastOutType;

typedef enum
{
MISCTYPE_TYPE_POSITION = 0,
MISCTYPE_TYPE_FACE = 1,
MISCTYPE_TYPE_MAX = 1
} D3D2GLSL_misctypeType;
} MiscTypeType;

typedef enum
{
Expand All @@ -181,14 +181,14 @@ typedef enum
DECLUSAGE_FOG = 11,
DECLUSAGE_DEPTH = 12,
DECLUSAGE_SAMPLE = 13
} D3D2GLSL_declusageType;
} DeclUsageType;

typedef enum
{
TEXTURE_TYPE_2D = 2,
TEXTURE_TYPE_CUBE = 3,
TEXTURE_TYPE_VOLUME = 4,
} D3D2GLSL_samplerTextureType;
} TextureType;


// A simple linked list of strings, so we can build the final output without
Expand Down Expand Up @@ -224,7 +224,7 @@ typedef enum
SRCMOD_ABSNEGATE,
SRCMOD_NOT,
SRCMOD_TOTAL
} D3D2GLSL_sourceMod;
} SourceMod;


typedef struct
Expand Down Expand Up @@ -257,8 +257,8 @@ typedef struct
} SourceArgInfo;


#define D3D2GLSL_SCRATCH_BUFFER_SIZE 256
#define D3D2GLSL_SCRATCH_BUFFERS 10
#define SCRATCH_BUFFER_SIZE 256
#define SCRATCH_BUFFERS 10

// Context...this is state that changes as we parse through a shader...
struct Context
Expand All @@ -273,11 +273,11 @@ struct Context
const char *endline;
int endline_len;
const char *failstr;
char scratch[D3D2GLSL_SCRATCH_BUFFERS][D3D2GLSL_SCRATCH_BUFFER_SIZE];
char scratch[SCRATCH_BUFFERS][SCRATCH_BUFFER_SIZE];
int scratchidx; // current scratch buffer.
int profileid;
const D3D2GLSL_profile *profile;
D3D2GLSL_shaderType shader_type;
const Profile *profile;
ShaderType shader_type;
uint32 major_ver;
uint32 minor_ver;
DestArgInfo dest_args[1];
Expand All @@ -290,7 +290,7 @@ struct Context

static inline char *get_scratch_buffer(Context *ctx)
{
ctx->scratchidx = (ctx->scratchidx + 1) % D3D2GLSL_SCRATCH_BUFFERS;
ctx->scratchidx = (ctx->scratchidx + 1) % SCRATCH_BUFFERS;
return ctx->scratch[ctx->scratchidx];
} // get_scratch_buffer

Expand All @@ -316,7 +316,7 @@ static int failf(Context *ctx, const char *fmt, ...)
char *scratch = get_scratch_buffer(ctx);
va_list ap;
va_start(ap, fmt);
const int len = vsnprintf(scratch,D3D2GLSL_SCRATCH_BUFFER_SIZE,fmt,ap);
const int len = vsnprintf(scratch,SCRATCH_BUFFER_SIZE,fmt,ap);
va_end(ap);

char *failstr = (char *) ctx->malloc(len + 1);
Expand All @@ -325,7 +325,7 @@ static int failf(Context *ctx, const char *fmt, ...)
else
{
// see comments about scratch buffer overflow in output_line().
if (len < D3D2GLSL_SCRATCH_BUFFER_SIZE)
if (len < SCRATCH_BUFFER_SIZE)
strcpy(failstr, scratch); // copy it over.
else
{
Expand Down Expand Up @@ -360,7 +360,7 @@ static int output_line(Context *ctx, const char *fmt, ...)
char *scratch = get_scratch_buffer(ctx);
va_list ap;
va_start(ap, fmt);
const int len = vsnprintf(scratch, D3D2GLSL_SCRATCH_BUFFER_SIZE, fmt, ap);
const int len = vsnprintf(scratch, SCRATCH_BUFFER_SIZE, fmt, ap);
va_end(ap);

item->str = (char *) ctx->malloc(len + 1);
Expand All @@ -373,7 +373,7 @@ static int output_line(Context *ctx, const char *fmt, ...)
// If we overflowed our scratch buffer, that's okay. We were going to
// allocate anyhow...the scratch buffer just lets us avoid a second
// run of vsnprintf().
if (len < D3D2GLSL_SCRATCH_BUFFER_SIZE)
if (len < SCRATCH_BUFFER_SIZE)
strcpy(item->str, scratch); // copy it over.
else
{
Expand Down Expand Up @@ -402,7 +402,7 @@ static int output_line(Context *ctx, const char *fmt, ...)
#define PROFILE_EMITTER_D3D(op) emit_D3D_##op,

static const char *get_D3D_register_string(Context *ctx,
registerType regtype,
RegisterType regtype,
int regnum, char *regnum_str,
size_t regnum_size)
{
Expand Down Expand Up @@ -443,7 +443,7 @@ static const char *get_D3D_register_string(Context *ctx,
break;

case REGISTER_TYPE_RASTOUT:
switch ((D3D2GLSL_rastoutType) regnum)
switch ((RastOutType) regnum)
{
case RASTOUT_TYPE_POSITION: retval = "oPos"; break;
case RASTOUT_TYPE_FOG: retval = "oFog"; break;
Expand Down Expand Up @@ -493,7 +493,7 @@ static const char *get_D3D_register_string(Context *ctx,
// case REGISTER_TYPE_TEMPFLOAT16:

case REGISTER_TYPE_MISCTYPE:
switch ((D3D2GLSL_misctypeType) regnum)
switch ((MiscTypeType) regnum)
{
case MISCTYPE_TYPE_POSITION: retval = "vPos"; break;
case MISCTYPE_TYPE_FACE: retval = "vFace"; break;
Expand Down Expand Up @@ -546,7 +546,7 @@ static char *make_D3D_destarg_string(Context *ctx, const int idx)

char regnum_str[16];
const char *regtype_str = get_D3D_register_string(ctx,
(registerType) arg->regtype,
(RegisterType) arg->regtype,
arg->regnum, regnum_str,
sizeof (regnum_str));
if (regtype_str == NULL)
Expand All @@ -570,7 +570,7 @@ static char *make_D3D_destarg_string(Context *ctx, const int idx)

// may turn out something like "_x2_sat_pp_centroid r0.xyzw" ...
char *retval = get_scratch_buffer(ctx);
snprintf(retval, D3D2GLSL_SCRATCH_BUFFER_SIZE, "%s%s%s%s %s%s%s",
snprintf(retval, SCRATCH_BUFFER_SIZE, "%s%s%s%s %s%s%s",
result_shift_str, sat_str, pp_str, cent_str,
regtype_str, regnum_str, writemask_str);
return retval;
Expand All @@ -589,7 +589,7 @@ static char *make_D3D_sourcearg_string(Context *ctx, const int idx)

const char *premod_str = "";
const char *postmod_str = "";
switch ((D3D2GLSL_sourceMod) arg->src_mod)
switch ((SourceMod) arg->src_mod)
{
case SRCMOD_NEGATE:
premod_str = "-";
Expand Down Expand Up @@ -643,7 +643,7 @@ static char *make_D3D_sourcearg_string(Context *ctx, const int idx)

char regnum_str[16];
const char *regtype_str = get_D3D_register_string(ctx,
(registerType) arg->regtype,
(RegisterType) arg->regtype,
arg->regnum, regnum_str,
sizeof (regnum_str));

Expand Down Expand Up @@ -672,7 +672,7 @@ static char *make_D3D_sourcearg_string(Context *ctx, const int idx)
assert(i < sizeof (swizzle_str));

char *retval = get_scratch_buffer(ctx);
snprintf(retval, D3D2GLSL_SCRATCH_BUFFER_SIZE, "%s%s%s%s",
snprintf(retval, SCRATCH_BUFFER_SIZE, "%s%s%s%s",
premod_str, regtype_str, postmod_str, swizzle_str);
return retval;
} // make_D3D_sourcearg_string
Expand Down Expand Up @@ -1046,7 +1046,7 @@ static void emit_D3D_DCL(Context *ctx)

else if (arg->regtype == REGISTER_TYPE_SAMPLER)
{
switch ((const D3D2GLSL_samplerTextureType) ctx->dwords[0])
switch ((const TextureType) ctx->dwords[0])
{
case TEXTURE_TYPE_2D: usage_str = "_2d"; break;
case TEXTURE_TYPE_CUBE: usage_str = "_cube"; break;
Expand Down Expand Up @@ -1524,7 +1524,7 @@ static void emit_GLSL_RESERVED(Context *ctx)
#error No profiles are supported. Fix your build.
#endif

static const D3D2GLSL_profile profiles[] =
static const Profile profiles[] =
{
#if SUPPORT_PROFILE_D3D
{ "d3d", emit_D3D_start, emit_D3D_end, emit_D3D_comment },
Expand Down Expand Up @@ -1660,7 +1660,7 @@ static int parse_source_token(Context *ctx, SourceArgInfo *info)
return fail(ctx, "Relative addressing is unsupported"); // !!! FIXME
} // if

if ( ((D3D2GLSL_sourceMod) info->src_mod) >= SRCMOD_TOTAL )
if ( ((SourceMod) info->src_mod) >= SRCMOD_TOTAL )
return fail(ctx, "Unknown source modifier");

return 1;
Expand All @@ -1678,7 +1678,7 @@ static int parse_args_DEF(Context *ctx)
if (parse_destination_token(ctx, &ctx->dest_args[0]) == FAIL)
return FAIL;

switch ((registerType) ctx->dest_args[0].regtype)
switch ((RegisterType) ctx->dest_args[0].regtype)
{
case REGISTER_TYPE_CONST:
case REGISTER_TYPE_CONST2:
Expand All @@ -1704,7 +1704,7 @@ static int parse_args_DEFI(Context *ctx)
if (parse_destination_token(ctx, &ctx->dest_args[0]) == FAIL)
return FAIL;

if (((registerType) ctx->dest_args[0].regtype) != REGISTER_TYPE_CONSTINT)
if (((RegisterType) ctx->dest_args[0].regtype) != REGISTER_TYPE_CONSTINT)
return fail(ctx, "DEFI token using invalid register");

ctx->dwords[0] = SWAP32(ctx->tokens[0]);
Expand All @@ -1720,7 +1720,7 @@ static int parse_args_DEFB(Context *ctx)
if (parse_destination_token(ctx, &ctx->dest_args[0]) == FAIL)
return FAIL;

if (((registerType) ctx->dest_args[0].regtype) != REGISTER_TYPE_CONSTBOOL)
if (((RegisterType) ctx->dest_args[0].regtype) != REGISTER_TYPE_CONSTBOOL)
return fail(ctx, "DEFB token using invalid register");

ctx->dwords[0] = *(ctx->tokens) ? 1 : 0;
Expand All @@ -1733,7 +1733,7 @@ static int parse_args_DCL(Context *ctx)
{
int unsupported = 0;
const uint32 token = SWAP32(*(ctx->tokens));
const D3D2GLSL_declusageType usage = (D3D2GLSL_declusageType)(token & 0xF);
const DeclUsageType usage = (DeclUsageType)(token & 0xF);
const int reserved1 = (int) ((token >> 31) & 0x1); // bit 31
uint32 reserved_mask = 0x00000000;

Expand All @@ -1745,15 +1745,15 @@ static int parse_args_DCL(Context *ctx)
if (parse_destination_token(ctx, &ctx->dest_args[0]) == FAIL)
return FAIL;

const registerType regtype = (registerType) ctx->dest_args[0].regtype;
const RegisterType regtype = (RegisterType) ctx->dest_args[0].regtype;
if ((ctx->shader_type == SHADER_TYPE_PIXEL) && (ctx->major_ver >= 3))
{
if (regtype == REGISTER_TYPE_INPUT)
reserved_mask = 0x7FFFFFFF;

else if (regtype == REGISTER_TYPE_MISCTYPE)
{
const D3D2GLSL_misctypeType mt = (D3D2GLSL_misctypeType) ctx->dest_args[0].regnum;
const MiscTypeType mt = (MiscTypeType) ctx->dest_args[0].regnum;
if (mt == MISCTYPE_TYPE_POSITION)
reserved_mask = 0x7FFFFFFF;
else if (mt == MISCTYPE_TYPE_FACE)
Expand Down Expand Up @@ -1799,7 +1799,7 @@ static int parse_args_DCL(Context *ctx)
else if (regtype == REGISTER_TYPE_SAMPLER)
{
reserved_mask = 0x7FFFFFF;
ctx->dwords[0] = ((token >> 27) & 0xF); // samplerTextureType
ctx->dwords[0] = ((token >> 27) & 0xF); // TextureType
} // else if

else
Expand All @@ -1817,7 +1817,7 @@ static int parse_args_DCL(Context *ctx)
else if (regtype == REGISTER_TYPE_SAMPLER)
{
reserved_mask = 0x7FFFFFF;
ctx->dwords[0] = ((token >> 27) & 0xF); // samplerTextureType
ctx->dwords[0] = ((token >> 27) & 0xF); // TextureType
} // else if
else
{
Expand Down Expand Up @@ -2187,7 +2187,7 @@ static int parse_comment_token(Context *ctx)
{
const uint32 commenttoks = ((token >> 16) & 0xFFFF);
const uint32 len = commenttoks * sizeof (uint32);
const int needmalloc = (len >= D3D2GLSL_SCRATCH_BUFFER_SIZE);
const int needmalloc = (len >= SCRATCH_BUFFER_SIZE);
char *str = ((needmalloc) ? (char *) ctx->malloc(len + 1) :
get_scratch_buffer(ctx));
memcpy(str, (const char *) (ctx->tokens+1), len);
Expand Down

0 comments on commit dd3444f

Please sign in to comment.