profiles/mojoshader_profile_glsl.c
author Ryan C. Gordon <icculus@icculus.org>
Mon, 20 Jul 2020 19:02:27 -0400
changeset 1292 32d4493dc144
parent 1255 0135d797e287
child 1293 ee08d870641b
permissions -rw-r--r--
glsl: Fix compiler warning.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
     1
/**
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
     3
 *  Direct3D shaders.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
     4
 *
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
     5
 * Please see the file LICENSE.txt in the source's root directory.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
     6
 *
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
     7
 *  This file written by Ryan C. Gordon.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
     8
 */
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
     9
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    10
#define __MOJOSHADER_INTERNAL__ 1
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    11
#include "mojoshader_profile.h"
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    12
1200
eb1e5280a5a9 Move the visibility pragmas below the includes.
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1199
diff changeset
    13
#pragma GCC visibility push(hidden)
eb1e5280a5a9 Move the visibility pragmas below the includes.
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1199
diff changeset
    14
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    15
#if SUPPORT_PROFILE_GLSL
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    16
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    17
#define EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(op) \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    18
    void emit_GLSL_##op(Context *ctx) { \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    19
        fail(ctx, #op " unimplemented in glsl profile"); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    20
    }
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    21
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    22
static inline const char *get_GLSL_register_string(Context *ctx,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    23
                        const RegisterType regtype, const int regnum,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    24
                        char *regnum_str, const size_t regnum_size)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    25
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    26
    // turns out these are identical at the moment.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    27
    return get_D3D_register_string(ctx,regtype,regnum,regnum_str,regnum_size);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    28
} // get_GLSL_register_string
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    29
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    30
const char *get_GLSL_uniform_type(Context *ctx, const RegisterType rtype)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    31
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    32
    switch (rtype)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    33
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    34
        case REG_TYPE_CONST: return "vec4";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    35
        case REG_TYPE_CONSTINT: return "ivec4";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    36
        case REG_TYPE_CONSTBOOL: return "bool";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    37
        default: fail(ctx, "BUG: used a uniform we don't know how to define.");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    38
    } // switch
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    39
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    40
    return NULL;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    41
} // get_GLSL_uniform_type
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    42
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    43
const char *get_GLSL_varname_in_buf(Context *ctx, RegisterType rt,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    44
                                    int regnum, char *buf,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    45
                                    const size_t len)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    46
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    47
    char regnum_str[16];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    48
    const char *regtype_str = get_GLSL_register_string(ctx, rt, regnum,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    49
                                              regnum_str, sizeof (regnum_str));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    50
    snprintf(buf,len,"%s_%s%s", ctx->shader_type_str, regtype_str, regnum_str);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    51
    return buf;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    52
} // get_GLSL_varname_in_buf
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    53
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    54
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    55
const char *get_GLSL_varname(Context *ctx, RegisterType rt, int regnum)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    56
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    57
    char buf[64];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    58
    get_GLSL_varname_in_buf(ctx, rt, regnum, buf, sizeof (buf));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    59
    return StrDup(ctx, buf);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    60
} // get_GLSL_varname
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    61
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    62
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    63
static inline const char *get_GLSL_const_array_varname_in_buf(Context *ctx,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    64
                                                const int base, const int size,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    65
                                                char *buf, const size_t buflen)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    66
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    67
    const char *type = ctx->shader_type_str;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    68
    snprintf(buf, buflen, "%s_const_array_%d_%d", type, base, size);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    69
    return buf;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    70
} // get_GLSL_const_array_varname_in_buf
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    71
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    72
const char *get_GLSL_const_array_varname(Context *ctx, int base, int size)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    73
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    74
    char buf[64];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    75
    get_GLSL_const_array_varname_in_buf(ctx, base, size, buf, sizeof (buf));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    76
    return StrDup(ctx, buf);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    77
} // get_GLSL_const_array_varname
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    78
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    79
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    80
static inline const char *get_GLSL_input_array_varname(Context *ctx,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    81
                                                char *buf, const size_t buflen)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    82
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    83
    snprintf(buf, buflen, "%s", "vertex_input_array");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    84
    return buf;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    85
} // get_GLSL_input_array_varname
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    86
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    87
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    88
const char *get_GLSL_uniform_array_varname(Context *ctx,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    89
                                           const RegisterType regtype,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    90
                                           char *buf, const size_t len)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    91
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    92
    const char *shadertype = ctx->shader_type_str;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    93
    const char *type = get_GLSL_uniform_type(ctx, regtype);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    94
    snprintf(buf, len, "%s_uniforms_%s", shadertype, type);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    95
    return buf;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    96
} // get_GLSL_uniform_array_varname
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    97
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    98
const char *get_GLSL_destarg_varname(Context *ctx, char *buf, size_t len)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    99
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   100
    const DestArgInfo *arg = &ctx->dest_arg;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   101
    return get_GLSL_varname_in_buf(ctx, arg->regtype, arg->regnum, buf, len);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   102
} // get_GLSL_destarg_varname
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   103
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   104
const char *get_GLSL_srcarg_varname(Context *ctx, const size_t idx,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   105
                                    char *buf, size_t len)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   106
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   107
    if (idx >= STATICARRAYLEN(ctx->source_args))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   108
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   109
        fail(ctx, "Too many source args");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   110
        *buf = '\0';
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   111
        return buf;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   112
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   113
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   114
    const SourceArgInfo *arg = &ctx->source_args[idx];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   115
    return get_GLSL_varname_in_buf(ctx, arg->regtype, arg->regnum, buf, len);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   116
} // get_GLSL_srcarg_varname
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   117
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   118
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   119
const char *make_GLSL_destarg_assign(Context *, char *, const size_t,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   120
                                     const char *, ...) ISPRINTF(4,5);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   121
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   122
const char *make_GLSL_destarg_assign(Context *ctx, char *buf,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   123
                                     const size_t buflen,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   124
                                     const char *fmt, ...)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   125
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   126
    int need_parens = 0;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   127
    const DestArgInfo *arg = &ctx->dest_arg;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   128
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   129
    if (arg->writemask == 0)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   130
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   131
        *buf = '\0';
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   132
        return buf;  // no writemask? It's a no-op.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   133
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   134
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   135
    char clampbuf[32] = { '\0' };
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   136
    const char *clampleft = "";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   137
    const char *clampright = "";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   138
    if (arg->result_mod & MOD_SATURATE)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   139
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   140
        const int vecsize = vecsize_from_writemask(arg->writemask);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   141
        clampleft = "clamp(";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   142
        if (vecsize == 1)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   143
            clampright = ", 0.0, 1.0)";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   144
        else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   145
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   146
            snprintf(clampbuf, sizeof (clampbuf),
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   147
                     ", vec%d(0.0), vec%d(1.0))", vecsize, vecsize);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   148
            clampright = clampbuf;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   149
        } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   150
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   151
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   152
    // MSDN says MOD_PP is a hint and many implementations ignore it. So do we.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   153
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   154
    // CENTROID only allowed in DCL opcodes, which shouldn't come through here.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   155
    assert((arg->result_mod & MOD_CENTROID) == 0);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   156
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   157
    if (ctx->predicated)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   158
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   159
        fail(ctx, "predicated destinations unsupported");  // !!! FIXME
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   160
        *buf = '\0';
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   161
        return buf;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   162
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   163
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   164
    char operation[256];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   165
    va_list ap;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   166
    va_start(ap, fmt);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   167
    const int len = vsnprintf(operation, sizeof (operation), fmt, ap);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   168
    va_end(ap);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   169
    if (len >= sizeof (operation))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   170
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   171
        fail(ctx, "operation string too large");  // I'm lazy.  :P
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   172
        *buf = '\0';
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   173
        return buf;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   174
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   175
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   176
    const char *result_shift_str = "";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   177
    switch (arg->result_shift)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   178
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   179
        case 0x1: result_shift_str = " * 2.0"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   180
        case 0x2: result_shift_str = " * 4.0"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   181
        case 0x3: result_shift_str = " * 8.0"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   182
        case 0xD: result_shift_str = " / 8.0"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   183
        case 0xE: result_shift_str = " / 4.0"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   184
        case 0xF: result_shift_str = " / 2.0"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   185
    } // switch
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   186
    need_parens |= (result_shift_str[0] != '\0');
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   187
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   188
    char regnum_str[16];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   189
    const char *regtype_str = get_GLSL_register_string(ctx, arg->regtype,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   190
                                                       arg->regnum, regnum_str,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   191
                                                       sizeof (regnum_str));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   192
    char writemask_str[6];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   193
    size_t i = 0;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   194
    const int scalar = isscalar(ctx, ctx->shader_type, arg->regtype, arg->regnum);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   195
    if (!scalar && !writemask_xyzw(arg->writemask))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   196
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   197
        writemask_str[i++] = '.';
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   198
        if (arg->writemask0) writemask_str[i++] = 'x';
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   199
        if (arg->writemask1) writemask_str[i++] = 'y';
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   200
        if (arg->writemask2) writemask_str[i++] = 'z';
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   201
        if (arg->writemask3) writemask_str[i++] = 'w';
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   202
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   203
    writemask_str[i] = '\0';
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   204
    assert(i < sizeof (writemask_str));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   205
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   206
    const char *leftparen = (need_parens) ? "(" : "";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   207
    const char *rightparen = (need_parens) ? ")" : "";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   208
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   209
    snprintf(buf, buflen, "%s_%s%s%s = %s%s%s%s%s%s;",
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   210
             ctx->shader_type_str, regtype_str, regnum_str, writemask_str,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   211
             clampleft, leftparen, operation, rightparen, result_shift_str,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   212
             clampright);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   213
    // !!! FIXME: make sure the scratch buffer was large enough.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   214
    return buf;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   215
} // make_GLSL_destarg_assign
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   216
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   217
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   218
char *make_GLSL_swizzle_string(char *swiz_str, const size_t strsize,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   219
                               const int swizzle, const int writemask)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   220
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   221
    size_t i = 0;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   222
    if ( (!no_swizzle(swizzle)) || (!writemask_xyzw(writemask)) )
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   223
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   224
        const int writemask0 = (writemask >> 0) & 0x1;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   225
        const int writemask1 = (writemask >> 1) & 0x1;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   226
        const int writemask2 = (writemask >> 2) & 0x1;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   227
        const int writemask3 = (writemask >> 3) & 0x1;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   228
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   229
        const int swizzle_x = (swizzle >> 0) & 0x3;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   230
        const int swizzle_y = (swizzle >> 2) & 0x3;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   231
        const int swizzle_z = (swizzle >> 4) & 0x3;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   232
        const int swizzle_w = (swizzle >> 6) & 0x3;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   233
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   234
        swiz_str[i++] = '.';
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   235
        if (writemask0) swiz_str[i++] = swizzle_channels[swizzle_x];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   236
        if (writemask1) swiz_str[i++] = swizzle_channels[swizzle_y];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   237
        if (writemask2) swiz_str[i++] = swizzle_channels[swizzle_z];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   238
        if (writemask3) swiz_str[i++] = swizzle_channels[swizzle_w];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   239
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   240
    assert(i < strsize);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   241
    swiz_str[i] = '\0';
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   242
    return swiz_str;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   243
} // make_GLSL_swizzle_string
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   244
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   245
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   246
const char *make_GLSL_srcarg_string(Context *ctx, const size_t idx,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   247
                                    const int writemask, char *buf,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   248
                                    const size_t buflen)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   249
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   250
    *buf = '\0';
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   251
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   252
    if (idx >= STATICARRAYLEN(ctx->source_args))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   253
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   254
        fail(ctx, "Too many source args");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   255
        return buf;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   256
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   257
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   258
    const SourceArgInfo *arg = &ctx->source_args[idx];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   259
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   260
    const char *premod_str = "";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   261
    const char *postmod_str = "";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   262
    switch (arg->src_mod)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   263
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   264
        case SRCMOD_NEGATE:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   265
            premod_str = "-";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   266
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   267
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   268
        case SRCMOD_BIASNEGATE:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   269
            premod_str = "-(";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   270
            postmod_str = " - 0.5)";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   271
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   272
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   273
        case SRCMOD_BIAS:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   274
            premod_str = "(";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   275
            postmod_str = " - 0.5)";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   276
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   277
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   278
        case SRCMOD_SIGNNEGATE:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   279
            premod_str = "-((";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   280
            postmod_str = " - 0.5) * 2.0)";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   281
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   282
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   283
        case SRCMOD_SIGN:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   284
            premod_str = "((";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   285
            postmod_str = " - 0.5) * 2.0)";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   286
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   287
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   288
        case SRCMOD_COMPLEMENT:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   289
            premod_str = "(1.0 - ";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   290
            postmod_str = ")";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   291
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   292
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   293
        case SRCMOD_X2NEGATE:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   294
            premod_str = "-(";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   295
            postmod_str = " * 2.0)";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   296
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   297
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   298
        case SRCMOD_X2:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   299
            premod_str = "(";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   300
            postmod_str = " * 2.0)";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   301
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   302
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   303
        case SRCMOD_DZ:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   304
            fail(ctx, "SRCMOD_DZ unsupported"); return buf; // !!! FIXME
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   305
            postmod_str = "_dz";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   306
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   307
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   308
        case SRCMOD_DW:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   309
            fail(ctx, "SRCMOD_DW unsupported"); return buf; // !!! FIXME
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   310
            postmod_str = "_dw";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   311
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   312
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   313
        case SRCMOD_ABSNEGATE:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   314
            premod_str = "-abs(";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   315
            postmod_str = ")";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   316
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   317
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   318
        case SRCMOD_ABS:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   319
            premod_str = "abs(";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   320
            postmod_str = ")";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   321
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   322
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   323
        case SRCMOD_NOT:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   324
            premod_str = "!";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   325
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   326
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   327
        case SRCMOD_NONE:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   328
        case SRCMOD_TOTAL:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   329
             break;  // stop compiler whining.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   330
    } // switch
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   331
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   332
    const char *regtype_str = NULL;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   333
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   334
    if (!arg->relative)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   335
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   336
        regtype_str = get_GLSL_varname_in_buf(ctx, arg->regtype, arg->regnum,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   337
                                              (char *) alloca(64), 64);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   338
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   339
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   340
    const char *rel_lbracket = "";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   341
    char rel_offset[32] = { '\0' };
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   342
    const char *rel_rbracket = "";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   343
    char rel_swizzle[4] = { '\0' };
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   344
    const char *rel_regtype_str = "";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   345
    if (arg->relative)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   346
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   347
        if (arg->regtype == REG_TYPE_INPUT)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   348
            regtype_str=get_GLSL_input_array_varname(ctx,(char*)alloca(64),64);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   349
        else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   350
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   351
            assert(arg->regtype == REG_TYPE_CONST);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   352
            const int arrayidx = arg->relative_array->index;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   353
            const int offset = arg->regnum - arrayidx;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   354
            assert(offset >= 0);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   355
            if (arg->relative_array->constant)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   356
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   357
                const int arraysize = arg->relative_array->count;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   358
                regtype_str = get_GLSL_const_array_varname_in_buf(ctx,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   359
                                arrayidx, arraysize, (char *) alloca(64), 64);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   360
                if (offset != 0)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   361
                    snprintf(rel_offset, sizeof (rel_offset), "%d + ", offset);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   362
            } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   363
            else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   364
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   365
                regtype_str = get_GLSL_uniform_array_varname(ctx, arg->regtype,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   366
                                                      (char *) alloca(64), 64);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   367
                if (offset == 0)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   368
                {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   369
                    snprintf(rel_offset, sizeof (rel_offset),
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   370
                             "ARRAYBASE_%d + ", arrayidx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   371
                } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   372
                else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   373
                {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   374
                    snprintf(rel_offset, sizeof (rel_offset),
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   375
                             "(ARRAYBASE_%d + %d) + ", arrayidx, offset);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   376
                } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   377
            } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   378
        } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   379
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   380
        rel_lbracket = "[";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   381
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   382
        if (arg->relative_regtype == REG_TYPE_LOOP)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   383
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   384
            rel_regtype_str = "aL";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   385
            rel_swizzle[0] = '\0';
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   386
            rel_swizzle[1] = '\0';
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   387
            rel_swizzle[2] = '\0';
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   388
        } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   389
        else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   390
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   391
            rel_regtype_str = get_GLSL_varname_in_buf(ctx, arg->relative_regtype,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   392
                                                      arg->relative_regnum,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   393
                                                      (char *) alloca(64), 64);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   394
            rel_swizzle[0] = '.';
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   395
            rel_swizzle[1] = swizzle_channels[arg->relative_component];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   396
            rel_swizzle[2] = '\0';
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   397
        } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   398
        rel_rbracket = "]";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   399
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   400
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   401
    char swiz_str[6] = { '\0' };
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   402
    if (!isscalar(ctx, ctx->shader_type, arg->regtype, arg->regnum))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   403
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   404
        make_GLSL_swizzle_string(swiz_str, sizeof (swiz_str),
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   405
                                 arg->swizzle, writemask);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   406
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   407
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   408
    if (regtype_str == NULL)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   409
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   410
        fail(ctx, "Unknown source register type.");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   411
        return buf;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   412
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   413
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   414
    snprintf(buf, buflen, "%s%s%s%s%s%s%s%s%s",
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   415
             premod_str, regtype_str, rel_lbracket, rel_offset,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   416
             rel_regtype_str, rel_swizzle, rel_rbracket, swiz_str,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   417
             postmod_str);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   418
    // !!! FIXME: make sure the scratch buffer was large enough.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   419
    return buf;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   420
} // make_GLSL_srcarg_string
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   421
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   422
// generate some convenience functions.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   423
#define MAKE_GLSL_SRCARG_STRING_(mask, bitmask) \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   424
    static inline const char *make_GLSL_srcarg_string_##mask(Context *ctx, \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   425
                                                const size_t idx, char *buf, \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   426
                                                const size_t buflen) { \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   427
        return make_GLSL_srcarg_string(ctx, idx, bitmask, buf, buflen); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   428
    }
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   429
MAKE_GLSL_SRCARG_STRING_(x, (1 << 0))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   430
MAKE_GLSL_SRCARG_STRING_(y, (1 << 1))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   431
MAKE_GLSL_SRCARG_STRING_(z, (1 << 2))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   432
MAKE_GLSL_SRCARG_STRING_(w, (1 << 3))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   433
MAKE_GLSL_SRCARG_STRING_(scalar, (1 << 0))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   434
MAKE_GLSL_SRCARG_STRING_(full, 0xF)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   435
MAKE_GLSL_SRCARG_STRING_(masked, ctx->dest_arg.writemask)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   436
MAKE_GLSL_SRCARG_STRING_(vec3, 0x7)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   437
MAKE_GLSL_SRCARG_STRING_(vec2, 0x3)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   438
#undef MAKE_GLSL_SRCARG_STRING_
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   439
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   440
// special cases for comparison opcodes...
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   441
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   442
const char *get_GLSL_comparison_string_scalar(Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   443
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   444
    const char *comps[] = { "", ">", "==", ">=", "<", "!=", "<=" };
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   445
    if (ctx->instruction_controls >= STATICARRAYLEN(comps))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   446
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   447
        fail(ctx, "unknown comparison control");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   448
        return "";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   449
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   450
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   451
    return comps[ctx->instruction_controls];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   452
} // get_GLSL_comparison_string_scalar
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   453
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   454
const char *get_GLSL_comparison_string_vector(Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   455
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   456
    const char *comps[] = {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   457
        "", "greaterThan", "equal", "greaterThanEqual", "lessThan",
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   458
        "notEqual", "lessThanEqual"
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   459
    };
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   460
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   461
    if (ctx->instruction_controls >= STATICARRAYLEN(comps))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   462
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   463
        fail(ctx, "unknown comparison control");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   464
        return "";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   465
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   466
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   467
    return comps[ctx->instruction_controls];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   468
} // get_GLSL_comparison_string_vector
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   469
1212
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   470
// special extensions needed for texldd/texldl...
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   471
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   472
static void prepend_glsl_texlod_extensions(Context *ctx)
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   473
{
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   474
    // !!! FIXME:
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   475
    // GLSL 1.30 introduced textureGrad() for this, but it looks like the
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   476
    //  functions are overloaded instead of texture2DGrad() (etc).
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   477
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   478
    // !!! FIXME:
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   479
    // The spec says we can't use GLSL's texture*Lod() built-ins from fragment
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   480
    //  shaders for some inexplicable reason.
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   481
    // For now, you'll just have to suffer with the potentially wrong mipmap
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   482
    //  until I can figure something out.
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   483
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   484
    // ARB_shader_texture_lod and EXT_gpu_shader4 added texture2DLod/Grad*(),
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   485
    //  so we'll use them if available. Failing that, we'll just fallback
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   486
    //  to a regular texture2D call and hope the mipmap it chooses is close
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   487
    //  enough.
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   488
    if (!ctx->glsl_generated_texlod_setup)
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   489
    {
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   490
        ctx->glsl_generated_texlod_setup = 1;
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   491
        push_output(ctx, &ctx->preflight);
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   492
        output_line(ctx, "#if GL_ARB_shader_texture_lod");
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   493
        output_line(ctx, "#extension GL_ARB_shader_texture_lod : enable");
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   494
        output_line(ctx, "#define texture2DGrad texture2DGradARB");
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   495
        output_line(ctx, "#define texture2DProjGrad texture2DProjARB");
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   496
        output_line(ctx, "#elif GL_EXT_gpu_shader4");
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   497
        output_line(ctx, "#extension GL_EXT_gpu_shader4 : enable");
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   498
        output_line(ctx, "#else");
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   499
        output_line(ctx, "#define texture2DGrad(a,b,c,d) texture2D(a,b)");
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   500
        output_line(ctx, "#define texture2DProjGrad(a,b,c,d) texture2DProj(a,b)");
1214
5887634ea695 Follow texture2DLod/ARB_shader_texture_lod spec more aggressively
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1213
diff changeset
   501
        if (shader_is_pixel(ctx))
5887634ea695 Follow texture2DLod/ARB_shader_texture_lod spec more aggressively
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1213
diff changeset
   502
            output_line(ctx, "#define texture2DLod(a,b,c) texture2D(a,b)");
1212
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   503
        output_line(ctx, "#endif");
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   504
        output_blank_line(ctx);
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   505
        pop_output(ctx);
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   506
    } // if
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   507
} // prepend_glsl_texlod_extensions
124155bb9bed GLSL: Implement texldl instruction
Katelyn Gadd <kg@luminance.org>
parents: 1211
diff changeset
   508
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   509
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   510
void emit_GLSL_start(Context *ctx, const char *profilestr)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   511
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   512
    if (!shader_is_vertex(ctx) && !shader_is_pixel(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   513
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   514
        failf(ctx, "Shader type %u unsupported in this profile.",
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   515
              (uint) ctx->shader_type);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   516
        return;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   517
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   518
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   519
    else if (strcmp(profilestr, MOJOSHADER_PROFILE_GLSL) == 0)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   520
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   521
        // No gl_FragData[] before GLSL 1.10, so we have to force the version.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   522
        push_output(ctx, &ctx->preflight);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   523
        output_line(ctx, "#version 110");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   524
        pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   525
    } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   526
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   527
    #if SUPPORT_PROFILE_GLSL120
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   528
    else if (strcmp(profilestr, MOJOSHADER_PROFILE_GLSL120) == 0)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   529
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   530
        ctx->profile_supports_glsl120 = 1;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   531
        push_output(ctx, &ctx->preflight);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   532
        output_line(ctx, "#version 120");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   533
        pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   534
    } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   535
    #endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   536
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   537
    #if SUPPORT_PROFILE_GLSLES
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   538
    else if (strcmp(profilestr, MOJOSHADER_PROFILE_GLSLES) == 0)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   539
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   540
        ctx->profile_supports_glsles = 1;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   541
        push_output(ctx, &ctx->preflight);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   542
        output_line(ctx, "#version 100");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   543
        if (shader_is_vertex(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   544
            output_line(ctx, "precision highp float;");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   545
        else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   546
            output_line(ctx, "precision mediump float;");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   547
        output_line(ctx, "precision mediump int;");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   548
        pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   549
    } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   550
    #endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   551
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   552
    else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   553
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   554
        failf(ctx, "Profile '%s' unsupported or unknown.", profilestr);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   555
        return;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   556
    } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   557
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   558
    push_output(ctx, &ctx->mainline_intro);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   559
    output_line(ctx, "void main()");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   560
    output_line(ctx, "{");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   561
    pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   562
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   563
    set_output(ctx, &ctx->mainline);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   564
    ctx->indent++;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   565
} // emit_GLSL_start
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   566
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   567
void emit_GLSL_RET(Context *ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   568
void emit_GLSL_end(Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   569
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   570
    // ps_1_* writes color to r0 instead oC0. We move it to the right place.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   571
    // We don't have to worry about a RET opcode messing this up, since
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   572
    //  RET isn't available before ps_2_0.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   573
    if (shader_is_pixel(ctx) && !shader_version_atleast(ctx, 2, 0))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   574
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   575
        const char *shstr = ctx->shader_type_str;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   576
        set_used_register(ctx, REG_TYPE_COLOROUT, 0, 1);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   577
        output_line(ctx, "%s_oC0 = %s_r0;", shstr, shstr);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   578
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   579
    else if (shader_is_vertex(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   580
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   581
#ifdef MOJOSHADER_FLIP_RENDERTARGET
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   582
        output_line(ctx, "gl_Position.y = gl_Position.y * vpFlip;");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   583
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   584
#ifdef MOJOSHADER_DEPTH_CLIPPING
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   585
        output_line(ctx, "gl_Position.z = gl_Position.z * 2.0 - gl_Position.w;");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   586
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   587
    } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   588
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   589
    // force a RET opcode if we're at the end of the stream without one.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   590
    if (ctx->previous_opcode != OPCODE_RET)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   591
        emit_GLSL_RET(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   592
} // emit_GLSL_end
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   593
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   594
void emit_GLSL_phase(Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   595
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   596
    // no-op in GLSL.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   597
} // emit_GLSL_phase
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   598
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   599
void output_GLSL_uniform_array(Context *ctx, const RegisterType regtype,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   600
                               const int size)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   601
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   602
    if (size > 0)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   603
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   604
        char buf[64];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   605
        get_GLSL_uniform_array_varname(ctx, regtype, buf, sizeof (buf));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   606
        const char *typ;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   607
        switch (regtype)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   608
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   609
            case REG_TYPE_CONST: typ = "vec4"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   610
            case REG_TYPE_CONSTINT: typ ="ivec4"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   611
            case REG_TYPE_CONSTBOOL: typ = "bool"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   612
            default:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   613
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   614
                fail(ctx, "BUG: used a uniform we don't know how to define.");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   615
                return;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   616
            } // default
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   617
        } // switch
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   618
        output_line(ctx, "uniform %s %s[%d];", typ, buf, size);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   619
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   620
} // output_GLSL_uniform_array
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   621
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   622
void emit_GLSL_finalize(Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   623
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   624
    // throw some blank lines around to make source more readable.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   625
    push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   626
    output_blank_line(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   627
    pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   628
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   629
    // If we had a relative addressing of REG_TYPE_INPUT, we need to build
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   630
    //  an array for it at the start of main(). GLSL doesn't let you specify
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   631
    //  arrays of attributes.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   632
    //vec4 blah_array[BIGGEST_ARRAY];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   633
    if (ctx->have_relative_input_registers) // !!! FIXME
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   634
        fail(ctx, "Relative addressing of input registers not supported.");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   635
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   636
    push_output(ctx, &ctx->preflight);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   637
    output_GLSL_uniform_array(ctx, REG_TYPE_CONST, ctx->uniform_float4_count);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   638
    output_GLSL_uniform_array(ctx, REG_TYPE_CONSTINT, ctx->uniform_int4_count);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   639
    output_GLSL_uniform_array(ctx, REG_TYPE_CONSTBOOL, ctx->uniform_bool_count);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   640
#ifdef MOJOSHADER_FLIP_RENDERTARGET
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   641
    if (shader_is_vertex(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   642
        output_line(ctx, "uniform float vpFlip;");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   643
#endif
1255
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1222
diff changeset
   644
    if (ctx->need_max_float)
1221
012dec2787aa Replicate D3D's div by 0 behavior for RCP/RSQ (GLSL Edition)
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1216
diff changeset
   645
        output_line(ctx, "const float FLT_MAX = 1e38;");
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   646
    pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   647
} // emit_GLSL_finalize
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   648
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   649
void emit_GLSL_global(Context *ctx, RegisterType regtype, int regnum)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   650
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   651
    char varname[64];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   652
    get_GLSL_varname_in_buf(ctx, regtype, regnum, varname, sizeof (varname));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   653
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   654
    push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   655
    switch (regtype)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   656
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   657
        case REG_TYPE_ADDRESS:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   658
            if (shader_is_vertex(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   659
                output_line(ctx, "ivec4 %s;", varname);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   660
            else if (shader_is_pixel(ctx))  // actually REG_TYPE_TEXTURE.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   661
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   662
                // We have to map texture registers to temps for ps_1_1, since
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   663
                //  they work like temps, initialize with tex coords, and the
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   664
                //  ps_1_1 TEX opcode expects to overwrite it.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   665
                if (!shader_version_atleast(ctx, 1, 4))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   666
                {
1208
888630594fb5 Only use gl_TexCoord for index values < 4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1203
diff changeset
   667
                    // GLSL ES does not have gl_TexCoord!
888630594fb5 Only use gl_TexCoord for index values < 4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1203
diff changeset
   668
                    // Also, gl_TexCoord[4+] is unreliable!
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   669
#if SUPPORT_PROFILE_GLSLES
1208
888630594fb5 Only use gl_TexCoord for index values < 4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1203
diff changeset
   670
                    const int skipGLTexCoord = support_glsles(ctx) || (regnum >= 4);
888630594fb5 Only use gl_TexCoord for index values < 4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1203
diff changeset
   671
#else
888630594fb5 Only use gl_TexCoord for index values < 4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1203
diff changeset
   672
                    const int skipGLTexCoord = (regnum >= 4);
888630594fb5 Only use gl_TexCoord for index values < 4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1203
diff changeset
   673
#endif
888630594fb5 Only use gl_TexCoord for index values < 4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1203
diff changeset
   674
                    if (skipGLTexCoord)
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   675
                        output_line(ctx, "vec4 %s = io_%i_%i;",
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   676
                                    varname, MOJOSHADER_USAGE_TEXCOORD, regnum);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   677
                    else
1208
888630594fb5 Only use gl_TexCoord for index values < 4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1203
diff changeset
   678
                        output_line(ctx, "vec4 %s = gl_TexCoord[%d];",
888630594fb5 Only use gl_TexCoord for index values < 4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1203
diff changeset
   679
                                    varname, regnum);
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   680
                } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   681
            } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   682
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   683
        case REG_TYPE_PREDICATE:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   684
            output_line(ctx, "bvec4 %s;", varname);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   685
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   686
        case REG_TYPE_TEMP:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   687
            output_line(ctx, "vec4 %s;", varname);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   688
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   689
        case REG_TYPE_LOOP:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   690
            break; // no-op. We declare these in for loops at the moment.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   691
        case REG_TYPE_LABEL:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   692
            break; // no-op. If we see it here, it means we optimized it out.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   693
        default:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   694
            fail(ctx, "BUG: we used a register we don't know how to define.");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   695
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   696
    } // switch
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   697
    pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   698
} // emit_GLSL_global
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   699
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   700
void emit_GLSL_array(Context *ctx, VariableList *var)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   701
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   702
    // All uniforms (except constant arrays, which only get pushed once at
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   703
    //  compile time) are now packed into a single array, so we can batch
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   704
    //  the uniform transfers. So this doesn't actually define an array
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   705
    //  here; the one, big array is emitted during finalization instead.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   706
    // However, we need to #define the offset into the one, big array here,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   707
    //  and let dereferences use that #define.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   708
    const int base = var->index;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   709
    const int glslbase = ctx->uniform_float4_count;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   710
    push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   711
    output_line(ctx, "#define ARRAYBASE_%d %d", base, glslbase);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   712
    pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   713
    var->emit_position = glslbase;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   714
} // emit_GLSL_array
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   715
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   716
void emit_GLSL_const_array(Context *ctx, const ConstantsList *clist,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   717
                           int base, int size)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   718
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   719
    char varname[64];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   720
    get_GLSL_const_array_varname_in_buf(ctx,base,size,varname,sizeof(varname));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   721
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   722
#if 0
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   723
    // !!! FIXME: fails on Nvidia's and Apple's GL, even with #version 120.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   724
    // !!! FIXME:  (the 1.20 spec says it should work, though, I think...)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   725
    if (support_glsl120(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   726
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   727
        // GLSL 1.20 can do constant arrays.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   728
        const char *cstr = NULL;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   729
        push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   730
        output_line(ctx, "const vec4 %s[%d] = vec4[%d](", varname, size, size);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   731
        ctx->indent++;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   732
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   733
        int i;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   734
        for (i = 0; i < size; i++)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   735
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   736
            while (clist->constant.type != MOJOSHADER_UNIFORM_FLOAT)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   737
                clist = clist->next;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   738
            assert(clist->constant.index == (base + i));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   739
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   740
            char val0[32];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   741
            char val1[32];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   742
            char val2[32];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   743
            char val3[32];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   744
            floatstr(ctx, val0, sizeof (val0), clist->constant.value.f[0], 1);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   745
            floatstr(ctx, val1, sizeof (val1), clist->constant.value.f[1], 1);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   746
            floatstr(ctx, val2, sizeof (val2), clist->constant.value.f[2], 1);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   747
            floatstr(ctx, val3, sizeof (val3), clist->constant.value.f[3], 1);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   748
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   749
            output_line(ctx, "vec4(%s, %s, %s, %s)%s", val0, val1, val2, val3,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   750
                        (i < (size-1)) ? "," : "");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   751
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   752
            clist = clist->next;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   753
        } // for
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   754
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   755
        ctx->indent--;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   756
        output_line(ctx, ");");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   757
        pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   758
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   759
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   760
    else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   761
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   762
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   763
        // stock GLSL 1.0 can't do constant arrays, so make a uniform array
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   764
        //  and have the OpenGL glue assign it at link time. Lame!
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   765
        push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   766
        output_line(ctx, "uniform vec4 %s[%d];", varname, size);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   767
        pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   768
    } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   769
} // emit_GLSL_const_array
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   770
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   771
void emit_GLSL_uniform(Context *ctx, RegisterType regtype, int regnum,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   772
                       const VariableList *var)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   773
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   774
    // Now that we're pushing all the uniforms as one big array, pack these
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   775
    //  down, so if we only use register c439, it'll actually map to
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   776
    //  glsl_uniforms_vec4[0]. As we push one big array, this will prevent
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   777
    //  uploading unused data.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   778
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   779
    char varname[64];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   780
    char name[64];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   781
    int index = 0;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   782
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   783
    get_GLSL_varname_in_buf(ctx, regtype, regnum, varname, sizeof (varname));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   784
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   785
    push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   786
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   787
    if (var == NULL)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   788
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   789
        get_GLSL_uniform_array_varname(ctx, regtype, name, sizeof (name));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   790
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   791
        if (regtype == REG_TYPE_CONST)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   792
            index = ctx->uniform_float4_count;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   793
        else if (regtype == REG_TYPE_CONSTINT)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   794
            index = ctx->uniform_int4_count;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   795
        else if (regtype == REG_TYPE_CONSTBOOL)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   796
            index = ctx->uniform_bool_count;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   797
        else  // get_GLSL_uniform_array_varname() would have called fail().
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   798
            assert(!(ctx->isfail));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   799
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   800
        output_line(ctx, "#define %s %s[%d]", varname, name, index);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   801
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   802
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   803
    else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   804
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   805
        const int arraybase = var->index;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   806
        if (var->constant)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   807
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   808
            get_GLSL_const_array_varname_in_buf(ctx, arraybase, var->count,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   809
                                                name, sizeof (name));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   810
            index = (regnum - arraybase);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   811
        } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   812
        else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   813
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   814
            assert(var->emit_position != -1);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   815
            get_GLSL_uniform_array_varname(ctx, regtype, name, sizeof (name));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   816
            index = (regnum - arraybase) + var->emit_position;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   817
        } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   818
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   819
        output_line(ctx, "#define %s %s[%d]", varname, name, index);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   820
    } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   821
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   822
    pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   823
} // emit_GLSL_uniform
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   824
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   825
void emit_GLSL_sampler(Context *ctx,int stage,TextureType ttype,int tb)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   826
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   827
    const char *type = "";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   828
    switch (ttype)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   829
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   830
        case TEXTURE_TYPE_2D: type = "sampler2D"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   831
        case TEXTURE_TYPE_CUBE: type = "samplerCube"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   832
        case TEXTURE_TYPE_VOLUME: type = "sampler3D"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   833
        default: fail(ctx, "BUG: used a sampler we don't know how to define.");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   834
    } // switch
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   835
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   836
    char var[64];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   837
    get_GLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, stage, var, sizeof (var));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   838
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   839
    push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   840
    output_line(ctx, "uniform %s %s;", type, var);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   841
    if (tb)  // This sampler used a ps_1_1 TEXBEM opcode?
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   842
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   843
        char name[64];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   844
        const int index = ctx->uniform_float4_count;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   845
        ctx->uniform_float4_count += 2;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   846
        get_GLSL_uniform_array_varname(ctx, REG_TYPE_CONST, name, sizeof (name));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   847
        output_line(ctx, "#define %s_texbem %s[%d]", var, name, index);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   848
        output_line(ctx, "#define %s_texbeml %s[%d]", var, name, index+1);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   849
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   850
    pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   851
} // emit_GLSL_sampler
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   852
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   853
void emit_GLSL_attribute(Context *ctx, RegisterType regtype, int regnum,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   854
                         MOJOSHADER_usage usage, int index, int wmask,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   855
                         int flags)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   856
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   857
    // !!! FIXME: this function doesn't deal with write masks at all yet!
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   858
    const char *usage_str = NULL;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   859
    const char *arrayleft = "";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   860
    const char *arrayright = "";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   861
    char index_str[16] = { '\0' };
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   862
    char var[64];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   863
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   864
    get_GLSL_varname_in_buf(ctx, regtype, regnum, var, sizeof (var));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   865
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   866
    //assert((flags & MOD_PP) == 0);  // !!! FIXME: is PP allowed?
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   867
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   868
    if (index != 0)  // !!! FIXME: a lot of these MUST be zero.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   869
        snprintf(index_str, sizeof (index_str), "%u", (uint) index);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   870
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   871
    if (shader_is_vertex(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   872
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   873
        // pre-vs3 output registers.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   874
        // these don't ever happen in DCL opcodes, I think. Map to vs_3_*
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   875
        //  output registers.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   876
        if (!shader_version_atleast(ctx, 3, 0))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   877
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   878
            if (regtype == REG_TYPE_RASTOUT)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   879
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   880
                regtype = REG_TYPE_OUTPUT;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   881
                index = regnum;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   882
                switch ((const RastOutType) regnum)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   883
                {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   884
                    case RASTOUT_TYPE_POSITION:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   885
                        usage = MOJOSHADER_USAGE_POSITION;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   886
                        break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   887
                    case RASTOUT_TYPE_FOG:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   888
                        usage = MOJOSHADER_USAGE_FOG;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   889
                        break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   890
                    case RASTOUT_TYPE_POINT_SIZE:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   891
                        usage = MOJOSHADER_USAGE_POINTSIZE;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   892
                        break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   893
                } // switch
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   894
            } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   895
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   896
            else if (regtype == REG_TYPE_ATTROUT)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   897
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   898
                regtype = REG_TYPE_OUTPUT;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   899
                usage = MOJOSHADER_USAGE_COLOR;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   900
                index = regnum;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   901
            } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   902
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   903
            else if (regtype == REG_TYPE_TEXCRDOUT)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   904
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   905
                regtype = REG_TYPE_OUTPUT;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   906
                usage = MOJOSHADER_USAGE_TEXCOORD;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   907
                index = regnum;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   908
            } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   909
        } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   910
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   911
        // to avoid limitations of various GL entry points for input
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   912
        // attributes (glSecondaryColorPointer() can only take 3 component
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   913
        // items, glVertexPointer() can't do GL_UNSIGNED_BYTE, many other
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   914
        // issues), we set up all inputs as generic vertex attributes, so we
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   915
        // can pass data in just about any form, and ignore the built-in GLSL
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   916
        // attributes like gl_SecondaryColor. Output needs to use the the
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   917
        // built-ins, though, but we don't have to worry about the GL entry
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   918
        // point limitations there.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   919
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   920
        if (regtype == REG_TYPE_INPUT)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   921
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   922
            push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   923
            output_line(ctx, "attribute vec4 %s;", var);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   924
            pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   925
        } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   926
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   927
        else if (regtype == REG_TYPE_OUTPUT)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   928
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   929
            switch (usage)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   930
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   931
                case MOJOSHADER_USAGE_POSITION:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   932
                    if (index == 0)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   933
                    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   934
                        usage_str = "gl_Position";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   935
                    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   936
                    break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   937
                case MOJOSHADER_USAGE_POINTSIZE:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   938
                    usage_str = "gl_PointSize";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   939
                    break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   940
                case MOJOSHADER_USAGE_COLOR:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   941
#if SUPPORT_PROFILE_GLSLES
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   942
                    if (support_glsles(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   943
                        break; // GLSL ES does not have gl_FrontColor
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   944
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   945
                    index_str[0] = '\0';  // no explicit number.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   946
                    if (index == 0)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   947
                    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   948
                        usage_str = "gl_FrontColor";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   949
                    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   950
                    else if (index == 1)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   951
                    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   952
                        usage_str = "gl_FrontSecondaryColor";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   953
                    } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   954
                    break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   955
                case MOJOSHADER_USAGE_FOG:
1215
8e9fb483f4d4 Fix USAGE_FOG for glsles, index values > 0
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1214
diff changeset
   956
#if SUPPORT_PROFILE_GLSLES
8e9fb483f4d4 Fix USAGE_FOG for glsles, index values > 0
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1214
diff changeset
   957
                    if (support_glsles(ctx))
8e9fb483f4d4 Fix USAGE_FOG for glsles, index values > 0
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1214
diff changeset
   958
                        break; // GLSL ES does not have gl_FogFragCoord
8e9fb483f4d4 Fix USAGE_FOG for glsles, index values > 0
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1214
diff changeset
   959
#endif
1222
c6e847dd9d4b MSVC buildfix (also removes redundant ES check)
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1221
diff changeset
   960
                    if (index == 0)
1215
8e9fb483f4d4 Fix USAGE_FOG for glsles, index values > 0
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1214
diff changeset
   961
                    {
8e9fb483f4d4 Fix USAGE_FOG for glsles, index values > 0
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1214
diff changeset
   962
                        usage_str = "gl_FogFragCoord";
8e9fb483f4d4 Fix USAGE_FOG for glsles, index values > 0
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1214
diff changeset
   963
                    } // if
1216
9d725de6c61c USAGE_FOG is a float, not a vec4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1215
diff changeset
   964
                    else
9d725de6c61c USAGE_FOG is a float, not a vec4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1215
diff changeset
   965
                    {
9d725de6c61c USAGE_FOG is a float, not a vec4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1215
diff changeset
   966
                        push_output(ctx, &ctx->globals);
9d725de6c61c USAGE_FOG is a float, not a vec4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1215
diff changeset
   967
#if SUPPORT_PROFILE_GLSLES
9d725de6c61c USAGE_FOG is a float, not a vec4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1215
diff changeset
   968
                        if (support_glsles(ctx))
9d725de6c61c USAGE_FOG is a float, not a vec4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1215
diff changeset
   969
                            output_line(ctx, "varying highp float io_%i_%i;", usage, index);
9d725de6c61c USAGE_FOG is a float, not a vec4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1215
diff changeset
   970
                        else
9d725de6c61c USAGE_FOG is a float, not a vec4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1215
diff changeset
   971
#endif
9d725de6c61c USAGE_FOG is a float, not a vec4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1215
diff changeset
   972
                        output_line(ctx, "varying float io_%i_%i;", usage, index);
9d725de6c61c USAGE_FOG is a float, not a vec4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1215
diff changeset
   973
                        output_line(ctx, "#define %s io_%i_%i", var, usage, index);
9d725de6c61c USAGE_FOG is a float, not a vec4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1215
diff changeset
   974
                        pop_output(ctx);
9d725de6c61c USAGE_FOG is a float, not a vec4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1215
diff changeset
   975
                        return;
9d725de6c61c USAGE_FOG is a float, not a vec4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1215
diff changeset
   976
                    }
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   977
                    break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   978
                case MOJOSHADER_USAGE_TEXCOORD:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   979
#if SUPPORT_PROFILE_GLSLES
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   980
                    if (support_glsles(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   981
                        break; // GLSL ES does not have gl_TexCoord
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   982
#endif
1208
888630594fb5 Only use gl_TexCoord for index values < 4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1203
diff changeset
   983
                    if (index >= 4)
888630594fb5 Only use gl_TexCoord for index values < 4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1203
diff changeset
   984
                        break; // gl_TexCoord[4+] is unreliable!
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   985
                    snprintf(index_str, sizeof (index_str), "%u", (uint) index);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   986
                    usage_str = "gl_TexCoord";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   987
                    arrayleft = "[";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   988
                    arrayright = "]";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   989
                    break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   990
                default:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   991
                    // !!! FIXME: we need to deal with some more built-in varyings here.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   992
                    break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   993
            } // switch
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   994
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   995
            // !!! FIXME: the #define is a little hacky, but it means we don't
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   996
            // !!! FIXME:  have to track these separately if this works.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   997
            push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   998
            // no mapping to built-in var? Just make it a regular global, pray.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   999
            if (usage_str == NULL)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1000
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1001
#if SUPPORT_PROFILE_GLSLES
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1002
                if (support_glsles(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1003
                    output_line(ctx, "varying highp vec4 io_%i_%i;", usage, index);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1004
                else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1005
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1006
                output_line(ctx, "varying vec4 io_%i_%i;", usage, index);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1007
                output_line(ctx, "#define %s io_%i_%i", var, usage, index);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1008
            } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1009
            else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1010
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1011
                output_line(ctx, "#define %s %s%s%s%s", var, usage_str,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1012
                            arrayleft, index_str, arrayright);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1013
            } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1014
            pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1015
        } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1016
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1017
        else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1018
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1019
            fail(ctx, "unknown vertex shader attribute register");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1020
        } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1021
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1022
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1023
    else if (shader_is_pixel(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1024
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1025
        // samplers DCLs get handled in emit_GLSL_sampler().
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1026
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1027
        if (flags & MOD_CENTROID)  // !!! FIXME
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1028
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1029
            failf(ctx, "centroid unsupported in %s profile", ctx->profile->name);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1030
            return;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1031
        } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1032
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1033
        if (regtype == REG_TYPE_COLOROUT)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1034
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1035
            if (!ctx->have_multi_color_outputs)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1036
                usage_str = "gl_FragColor";  // maybe faster?
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1037
            else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1038
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1039
                snprintf(index_str, sizeof (index_str), "%u", (uint) regnum);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1040
                usage_str = "gl_FragData";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1041
                arrayleft = "[";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1042
                arrayright = "]";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1043
            } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1044
        } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1045
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1046
        else if (regtype == REG_TYPE_DEPTHOUT)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1047
            usage_str = "gl_FragDepth";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1048
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1049
        // !!! FIXME: can you actualy have a texture register with COLOR usage?
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1050
        else if ((regtype == REG_TYPE_TEXTURE) || (regtype == REG_TYPE_INPUT))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1051
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1052
#if SUPPORT_PROFILE_GLSLES
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1053
            if (!support_glsles(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1054
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1055
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1056
            if (usage == MOJOSHADER_USAGE_TEXCOORD)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1057
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1058
                // ps_1_1 does a different hack for this attribute.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1059
                //  Refer to emit_GLSL_global()'s REG_TYPE_ADDRESS code.
1208
888630594fb5 Only use gl_TexCoord for index values < 4
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1203
diff changeset
  1060
                if (shader_version_atleast(ctx, 1, 4) && (index < 4)) // gl_TexCoord[4+] is unreliable!
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1061
                {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1062
                    snprintf(index_str, sizeof (index_str), "%u", (uint) index);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1063
                    usage_str = "gl_TexCoord";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1064
                    arrayleft = "[";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1065
                    arrayright = "]";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1066
                } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1067
            } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1068
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1069
            else if (usage == MOJOSHADER_USAGE_COLOR)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1070
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1071
                index_str[0] = '\0';  // no explicit number.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1072
                if (index == 0)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1073
                {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1074
                    usage_str = "gl_Color";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1075
                } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1076
                else if (index == 1)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1077
                {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1078
                    usage_str = "gl_SecondaryColor";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1079
                } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1080
                // FIXME: Does this even matter when we have varyings? -flibit
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1081
                // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1082
                //    fail(ctx, "unsupported color index");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1083
            } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1084
#if SUPPORT_PROFILE_GLSLES
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1085
            } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1086
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1087
        } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1088
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1089
        else if (regtype == REG_TYPE_MISCTYPE)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1090
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1091
            const MiscTypeType mt = (MiscTypeType) regnum;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1092
            if (mt == MISCTYPE_TYPE_FACE)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1093
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1094
                push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1095
                output_line(ctx, "float %s = gl_FrontFacing ? 1.0 : -1.0;", var);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1096
                pop_output(ctx);
1203
825944b0dbfc Return after printing gl_FrontFacing variable, it does not need a define
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1200
diff changeset
  1097
                return;
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1098
            } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1099
            else if (mt == MISCTYPE_TYPE_POSITION)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1100
            {
1211
74c594099cba Remove the floor from vpos calculation
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1210
diff changeset
  1101
                // TODO: For half-pixel offset compensation, floor() this value!
1210
c586d4590241 Replace glProgramViewportFlip with glProgramViewportInfo
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1208
diff changeset
  1102
                push_output(ctx, &ctx->globals);
c586d4590241 Replace glProgramViewportFlip with glProgramViewportInfo
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1208
diff changeset
  1103
                output_line(ctx, "uniform vec2 vposFlip;");
1211
74c594099cba Remove the floor from vpos calculation
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1210
diff changeset
  1104
                output_line(ctx, "vec4 %s = vec4(gl_FragCoord.x, (gl_FragCoord.y * vposFlip.x) + vposFlip.y, gl_FragCoord.z, gl_FragCoord.w);", var);
1210
c586d4590241 Replace glProgramViewportFlip with glProgramViewportInfo
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1208
diff changeset
  1105
                pop_output(ctx);
c586d4590241 Replace glProgramViewportFlip with glProgramViewportInfo
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1208
diff changeset
  1106
                return;
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1107
            } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1108
            else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1109
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1110
                fail(ctx, "BUG: unhandled misc register");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1111
            } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1112
        } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1113
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1114
        else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1115
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1116
            fail(ctx, "unknown pixel shader attribute register");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1117
        } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1118
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1119
        push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1120
        // no mapping to built-in var? Just make it a regular global, pray.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1121
        if (usage_str == NULL)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1122
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1123
#if SUPPORT_PROFILE_GLSLES
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1124
            if (support_glsles(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1125
                output_line(ctx, "varying highp vec4 io_%i_%i;", usage, index);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1126
            else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1127
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1128
            output_line(ctx, "varying vec4 io_%i_%i;", usage, index);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1129
            output_line(ctx, "#define %s io_%i_%i", var, usage, index);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1130
        } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1131
        else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1132
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset