profiles/mojoshader_profile_glsl.c
author Ethan Lee <flibitijibibo@flibitijibibo.com>
Mon, 27 May 2019 03:08:46 -0400
changeset 1203 825944b0dbfc
parent 1200 eb1e5280a5a9
child 1208 888630594fb5
permissions -rw-r--r--
Return after printing gl_FrontFacing variable, it does not need a define
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
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   470
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   471
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
   472
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   473
    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
   474
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   475
        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
   476
              (uint) ctx->shader_type);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   477
        return;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   478
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   479
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   480
    else if (strcmp(profilestr, MOJOSHADER_PROFILE_GLSL) == 0)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   481
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   482
        // 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
   483
        push_output(ctx, &ctx->preflight);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   484
        output_line(ctx, "#version 110");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   485
        pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   486
    } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   487
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   488
    #if SUPPORT_PROFILE_GLSL120
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   489
    else if (strcmp(profilestr, MOJOSHADER_PROFILE_GLSL120) == 0)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   490
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   491
        ctx->profile_supports_glsl120 = 1;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   492
        push_output(ctx, &ctx->preflight);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   493
        output_line(ctx, "#version 120");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   494
        pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   495
    } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   496
    #endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   497
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   498
    #if SUPPORT_PROFILE_GLSLES
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   499
    else if (strcmp(profilestr, MOJOSHADER_PROFILE_GLSLES) == 0)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   500
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   501
        ctx->profile_supports_glsles = 1;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   502
        push_output(ctx, &ctx->preflight);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   503
        output_line(ctx, "#version 100");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   504
        if (shader_is_vertex(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   505
            output_line(ctx, "precision highp float;");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   506
        else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   507
            output_line(ctx, "precision mediump float;");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   508
        output_line(ctx, "precision mediump int;");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   509
        pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   510
    } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   511
    #endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   512
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   513
    else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   514
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   515
        failf(ctx, "Profile '%s' unsupported or unknown.", profilestr);
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
    } // else
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
    push_output(ctx, &ctx->mainline_intro);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   520
    output_line(ctx, "void main()");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   521
    output_line(ctx, "{");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   522
    pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   523
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   524
    set_output(ctx, &ctx->mainline);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   525
    ctx->indent++;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   526
} // emit_GLSL_start
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   527
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   528
void emit_GLSL_RET(Context *ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   529
void emit_GLSL_end(Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   530
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   531
    // 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
   532
    // 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
   533
    //  RET isn't available before ps_2_0.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   534
    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
   535
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   536
        const char *shstr = ctx->shader_type_str;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   537
        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
   538
        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
   539
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   540
    else if (shader_is_vertex(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   541
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   542
#ifdef MOJOSHADER_FLIP_RENDERTARGET
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   543
        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
   544
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   545
#ifdef MOJOSHADER_DEPTH_CLIPPING
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   546
        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
   547
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   548
    } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   549
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   550
    // 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
   551
    if (ctx->previous_opcode != OPCODE_RET)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   552
        emit_GLSL_RET(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   553
} // emit_GLSL_end
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   554
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   555
void emit_GLSL_phase(Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   556
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   557
    // no-op in GLSL.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   558
} // emit_GLSL_phase
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   559
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   560
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
   561
                               const int size)
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
    if (size > 0)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   564
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   565
        char buf[64];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   566
        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
   567
        const char *typ;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   568
        switch (regtype)
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
            case REG_TYPE_CONST: typ = "vec4"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   571
            case REG_TYPE_CONSTINT: typ ="ivec4"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   572
            case REG_TYPE_CONSTBOOL: typ = "bool"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   573
            default:
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
                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
   576
                return;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   577
            } // default
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   578
        } // switch
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   579
        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
   580
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   581
} // output_GLSL_uniform_array
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   582
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   583
void emit_GLSL_finalize(Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   584
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   585
    // 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
   586
    push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   587
    output_blank_line(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   588
    pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   589
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   590
    // 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
   591
    //  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
   592
    //  arrays of attributes.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   593
    //vec4 blah_array[BIGGEST_ARRAY];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   594
    if (ctx->have_relative_input_registers) // !!! FIXME
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   595
        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
   596
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   597
    push_output(ctx, &ctx->preflight);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   598
    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
   599
    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
   600
    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
   601
#ifdef MOJOSHADER_FLIP_RENDERTARGET
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   602
    if (shader_is_vertex(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   603
        output_line(ctx, "uniform float vpFlip;");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   604
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   605
    pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   606
} // emit_GLSL_finalize
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   607
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   608
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
   609
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   610
    char varname[64];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   611
    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
   612
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   613
    push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   614
    switch (regtype)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   615
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   616
        case REG_TYPE_ADDRESS:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   617
            if (shader_is_vertex(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   618
                output_line(ctx, "ivec4 %s;", varname);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   619
            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
   620
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   621
                // 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
   622
                //  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
   623
                //  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
   624
                if (!shader_version_atleast(ctx, 1, 4))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   625
                {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   626
#if SUPPORT_PROFILE_GLSLES
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   627
                    // GLSL ES does not have gl_TexCoord
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   628
                    if (support_glsles(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   629
                        output_line(ctx, "vec4 %s = io_%i_%i;",
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   630
                                    varname, MOJOSHADER_USAGE_TEXCOORD, regnum);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   631
                    else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   632
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   633
                    output_line(ctx, "vec4 %s = gl_TexCoord[%d];",
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   634
                                varname, regnum);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   635
                } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   636
            } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   637
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   638
        case REG_TYPE_PREDICATE:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   639
            output_line(ctx, "bvec4 %s;", varname);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   640
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   641
        case REG_TYPE_TEMP:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   642
            output_line(ctx, "vec4 %s;", varname);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   643
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   644
        case REG_TYPE_LOOP:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   645
            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
   646
        case REG_TYPE_LABEL:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   647
            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
   648
        default:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   649
            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
   650
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   651
    } // switch
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   652
    pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   653
} // emit_GLSL_global
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   654
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   655
void emit_GLSL_array(Context *ctx, VariableList *var)
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
    // 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
   658
    //  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
   659
    //  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
   660
    //  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
   661
    // 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
   662
    //  and let dereferences use that #define.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   663
    const int base = var->index;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   664
    const int glslbase = ctx->uniform_float4_count;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   665
    push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   666
    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
   667
    pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   668
    var->emit_position = glslbase;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   669
} // emit_GLSL_array
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   670
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   671
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
   672
                           int base, int size)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   673
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   674
    char varname[64];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   675
    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
   676
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   677
#if 0
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   678
    // !!! 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
   679
    // !!! 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
   680
    if (support_glsl120(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   681
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   682
        // GLSL 1.20 can do constant arrays.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   683
        const char *cstr = NULL;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   684
        push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   685
        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
   686
        ctx->indent++;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   687
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   688
        int i;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   689
        for (i = 0; i < size; i++)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   690
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   691
            while (clist->constant.type != MOJOSHADER_UNIFORM_FLOAT)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   692
                clist = clist->next;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   693
            assert(clist->constant.index == (base + i));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   694
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   695
            char val0[32];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   696
            char val1[32];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   697
            char val2[32];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   698
            char val3[32];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   699
            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
   700
            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
   701
            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
   702
            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
   703
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   704
            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
   705
                        (i < (size-1)) ? "," : "");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   706
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   707
            clist = clist->next;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   708
        } // for
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   709
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   710
        ctx->indent--;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   711
        output_line(ctx, ");");
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
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   714
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   715
    else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   716
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   717
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   718
        // 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
   719
        //  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
   720
        push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   721
        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
   722
        pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   723
    } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   724
} // emit_GLSL_const_array
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   725
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   726
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
   727
                       const VariableList *var)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   728
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   729
    // 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
   730
    //  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
   731
    //  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
   732
    //  uploading unused data.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   733
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   734
    char varname[64];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   735
    char name[64];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   736
    int index = 0;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   737
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   738
    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
   739
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   740
    push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   741
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   742
    if (var == NULL)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   743
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   744
        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
   745
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   746
        if (regtype == REG_TYPE_CONST)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   747
            index = ctx->uniform_float4_count;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   748
        else if (regtype == REG_TYPE_CONSTINT)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   749
            index = ctx->uniform_int4_count;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   750
        else if (regtype == REG_TYPE_CONSTBOOL)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   751
            index = ctx->uniform_bool_count;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   752
        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
   753
            assert(!(ctx->isfail));
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
        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
   756
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   757
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   758
    else
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
        const int arraybase = var->index;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   761
        if (var->constant)
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
            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
   764
                                                name, sizeof (name));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   765
            index = (regnum - arraybase);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   766
        } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   767
        else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   768
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   769
            assert(var->emit_position != -1);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   770
            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
   771
            index = (regnum - arraybase) + var->emit_position;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   772
        } // else
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
        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
   775
    } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   776
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   777
    pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   778
} // emit_GLSL_uniform
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   779
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   780
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
   781
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   782
    const char *type = "";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   783
    switch (ttype)
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
        case TEXTURE_TYPE_2D: type = "sampler2D"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   786
        case TEXTURE_TYPE_CUBE: type = "samplerCube"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   787
        case TEXTURE_TYPE_VOLUME: type = "sampler3D"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   788
        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
   789
    } // switch
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
    char var[64];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   792
    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
   793
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   794
    push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   795
    output_line(ctx, "uniform %s %s;", type, var);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   796
    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
   797
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   798
        char name[64];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   799
        const int index = ctx->uniform_float4_count;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   800
        ctx->uniform_float4_count += 2;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   801
        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
   802
        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
   803
        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
   804
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   805
    pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   806
} // emit_GLSL_sampler
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
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
   809
                         MOJOSHADER_usage usage, int index, int wmask,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   810
                         int flags)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   811
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   812
    // !!! 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
   813
    const char *usage_str = NULL;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   814
    const char *arrayleft = "";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   815
    const char *arrayright = "";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   816
    char index_str[16] = { '\0' };
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   817
    char var[64];
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
    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
   820
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   821
    //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
   822
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   823
    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
   824
        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
   825
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   826
    if (shader_is_vertex(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   827
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   828
        // pre-vs3 output registers.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   829
        // 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
   830
        //  output registers.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   831
        if (!shader_version_atleast(ctx, 3, 0))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   832
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   833
            if (regtype == REG_TYPE_RASTOUT)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   834
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   835
                regtype = REG_TYPE_OUTPUT;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   836
                index = regnum;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   837
                switch ((const RastOutType) regnum)
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
                    case RASTOUT_TYPE_POSITION:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   840
                        usage = MOJOSHADER_USAGE_POSITION;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   841
                        break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   842
                    case RASTOUT_TYPE_FOG:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   843
                        usage = MOJOSHADER_USAGE_FOG;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   844
                        break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   845
                    case RASTOUT_TYPE_POINT_SIZE:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   846
                        usage = MOJOSHADER_USAGE_POINTSIZE;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   847
                        break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   848
                } // switch
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
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   851
            else if (regtype == REG_TYPE_ATTROUT)
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
                regtype = REG_TYPE_OUTPUT;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   854
                usage = MOJOSHADER_USAGE_COLOR;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   855
                index = regnum;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   856
            } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   857
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   858
            else if (regtype == REG_TYPE_TEXCRDOUT)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   859
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   860
                regtype = REG_TYPE_OUTPUT;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   861
                usage = MOJOSHADER_USAGE_TEXCOORD;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   862
                index = regnum;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   863
            } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   864
        } // if
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
        // 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
   867
        // attributes (glSecondaryColorPointer() can only take 3 component
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   868
        // 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
   869
        // 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
   870
        // 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
   871
        // 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
   872
        // 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
   873
        // point limitations there.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   874
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   875
        if (regtype == REG_TYPE_INPUT)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   876
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   877
            push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   878
            output_line(ctx, "attribute vec4 %s;", var);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   879
            pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   880
        } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   881
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   882
        else if (regtype == REG_TYPE_OUTPUT)
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
            switch (usage)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   885
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   886
                case MOJOSHADER_USAGE_POSITION:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   887
                    if (index == 0)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   888
                    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   889
                        usage_str = "gl_Position";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   890
                    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   891
                    break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   892
                case MOJOSHADER_USAGE_POINTSIZE:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   893
                    usage_str = "gl_PointSize";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   894
                    break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   895
                case MOJOSHADER_USAGE_COLOR:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   896
#if SUPPORT_PROFILE_GLSLES
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   897
                    if (support_glsles(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   898
                        break; // GLSL ES does not have gl_FrontColor
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   899
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   900
                    index_str[0] = '\0';  // no explicit number.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   901
                    if (index == 0)
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
                        usage_str = "gl_FrontColor";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   904
                    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   905
                    else if (index == 1)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   906
                    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   907
                        usage_str = "gl_FrontSecondaryColor";
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
                    break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   910
                case MOJOSHADER_USAGE_FOG:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   911
                    usage_str = "gl_FogFragCoord";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   912
                    break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   913
                case MOJOSHADER_USAGE_TEXCOORD:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   914
#if SUPPORT_PROFILE_GLSLES
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   915
                    if (support_glsles(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   916
                        break; // GLSL ES does not have gl_TexCoord
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   917
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   918
                    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
   919
                    usage_str = "gl_TexCoord";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   920
                    arrayleft = "[";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   921
                    arrayright = "]";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   922
                    break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   923
                default:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   924
                    // !!! 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
   925
                    break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   926
            } // switch
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   927
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   928
            // !!! 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
   929
            // !!! 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
   930
            push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   931
            // 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
   932
            if (usage_str == NULL)
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
#if SUPPORT_PROFILE_GLSLES
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   935
                if (support_glsles(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   936
                    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
   937
                else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   938
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   939
                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
   940
                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
   941
            } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   942
            else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   943
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   944
                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
   945
                            arrayleft, index_str, arrayright);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   946
            } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   947
            pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   948
        } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   949
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   950
        else
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
            fail(ctx, "unknown vertex shader attribute register");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   953
        } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   954
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   955
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   956
    else if (shader_is_pixel(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   957
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   958
        // samplers DCLs get handled in emit_GLSL_sampler().
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   959
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   960
        if (flags & MOD_CENTROID)  // !!! FIXME
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   961
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   962
            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
   963
            return;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   964
        } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   965
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   966
        if (regtype == REG_TYPE_COLOROUT)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   967
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   968
            if (!ctx->have_multi_color_outputs)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   969
                usage_str = "gl_FragColor";  // maybe faster?
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   970
            else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   971
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   972
                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
   973
                usage_str = "gl_FragData";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   974
                arrayleft = "[";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   975
                arrayright = "]";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   976
            } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   977
        } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   978
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   979
        else if (regtype == REG_TYPE_DEPTHOUT)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   980
            usage_str = "gl_FragDepth";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   981
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   982
        // !!! 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
   983
        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
   984
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   985
#if SUPPORT_PROFILE_GLSLES
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   986
            if (!support_glsles(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   987
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   988
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   989
            if (usage == MOJOSHADER_USAGE_TEXCOORD)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   990
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   991
                // 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
   992
                //  Refer to emit_GLSL_global()'s REG_TYPE_ADDRESS code.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   993
                if (shader_version_atleast(ctx, 1, 4))
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
                    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
   996
                    usage_str = "gl_TexCoord";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   997
                    arrayleft = "[";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   998
                    arrayright = "]";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   999
                } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1000
            } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1001
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1002
            else if (usage == MOJOSHADER_USAGE_COLOR)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1003
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1004
                index_str[0] = '\0';  // no explicit number.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1005
                if (index == 0)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1006
                {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1007
                    usage_str = "gl_Color";
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 if (index == 1)
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
                    usage_str = "gl_SecondaryColor";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1012
                } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1013
                // 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
  1014
                // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1015
                //    fail(ctx, "unsupported color index");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1016
            } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1017
#if SUPPORT_PROFILE_GLSLES
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1018
            } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1019
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1020
        } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1021
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1022
        else if (regtype == REG_TYPE_MISCTYPE)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1023
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1024
            const MiscTypeType mt = (MiscTypeType) regnum;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1025
            if (mt == MISCTYPE_TYPE_FACE)
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
                push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1028
                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
  1029
                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
  1030
                return;
1199
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
            else if (mt == MISCTYPE_TYPE_POSITION)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1033
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1034
                index_str[0] = '\0';  // no explicit number.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1035
                usage_str = "gl_FragCoord";  // !!! FIXME: is this the same coord space as D3D?
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1036
            } // else if
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
                fail(ctx, "BUG: unhandled misc register");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1040
            } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1041
        } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1042
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
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1045
            fail(ctx, "unknown pixel shader attribute register");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1046
        } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1047
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1048
        push_output(ctx, &ctx->globals);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1049
        // 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
  1050
        if (usage_str == NULL)
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
                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
  1055
            else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1056
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1057
            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
  1058
            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
  1059
        } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1060
        else
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
            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
  1063
                        arrayleft, index_str, arrayright);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1064
        } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1065
        pop_output(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1066
    } // else if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1067
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1068
    else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1069
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1070
        fail(ctx, "Unknown shader type");  // state machine should catch this.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1071
    } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1072
} // emit_GLSL_attribute
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
void emit_GLSL_NOP(Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1075
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1076
    // no-op is a no-op.  :)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1077
} // emit_GLSL_NOP
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1078
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1079
void emit_GLSL_MOV(Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1080
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1081
    char src0[64]; make_GLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1082
    char code[128];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1083
    make_GLSL_destarg_assign(ctx, code, sizeof (code), "%s", src0);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1084
    output_line(ctx, "%s", code);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1085
} // emit_GLSL_MOV
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1086
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1087
void emit_GLSL_ADD(Context *ctx)
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
    char src0[64]; make_GLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1090
    char src1[64]; make_GLSL_srcarg_string_masked(ctx, 1, src1, sizeof (src1));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1091
    char code[128];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1092
    make_GLSL_destarg_assign(ctx, code, sizeof (code), "%s + %s", src0, src1);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1093
    output_line(ctx, "%s", code);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1094
} // emit_GLSL_ADD
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1095
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1096
void emit_GLSL_SUB(Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1097
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1098
    char src0[64]; make_GLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1099
    char src1[64]; make_GLSL_srcarg_string_masked(ctx, 1, src1, sizeof (src1));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1100
    char code[128];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1101
    make_GLSL_destarg_assign(ctx, code, sizeof (code), "%s - %s", src0, src1);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1102
    output_line(ctx, "%s", code);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1103
} // emit_GLSL_SUB
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1104
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1105
void emit_GLSL_MAD(Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1106
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1107
    char src0[64]; make_GLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1108
    char src1[64]; make_GLSL_srcarg_string_masked(ctx, 1, src1, sizeof (src1));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1109
    char src2[64]; make_GLSL_srcarg_string_masked(ctx, 2, src2, sizeof (src2));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1110
    char code[128];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1111
    make_GLSL_destarg_assign(ctx, code, sizeof (code), "(%s * %s) + %s", src0, src1, src2);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1112
    output_line(ctx, "%s", code);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1113
} // emit_GLSL_MAD
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1114
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1115
void emit_GLSL_MUL(Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1116
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1117
    char src0[64]; make_GLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1118
    char src1[64]; make_GLSL_srcarg_string_masked(ctx, 1, src1, sizeof (src1));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1119
    char code[128];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1120
    make_GLSL_destarg_assign(ctx, code, sizeof (code), "%s * %s", src0, src1);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1121
    output_line(ctx, "%s", code);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1122
} // emit_GLSL_MUL
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1123
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1124
void emit_GLSL_RCP(Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1125
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1126
    char src0[64]; make_GLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1127
    char code[128];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1128
    make_GLSL_destarg_assign(ctx, code, sizeof (code), "1.0 / %s", src0);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1129
    output_line(ctx, "%s", code);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1130
} // emit_GLSL_RCP
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1131
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1132
void emit_GLSL_RSQ(Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1133
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1134
    char src0[64]; make_GLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1135
    char code[128];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1136
    make_GLSL_destarg_assign(ctx, code, sizeof (code), "inversesqrt(%s)", src0);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1137
    output_line(ctx, "%s", code);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1138
} // emit_GLSL_RSQ
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1139
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1140
void emit_GLSL_dotprod(Context *ctx, const char *src0, const char *src1,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1141
                       const char *extra)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1142
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
  1143
    const int vecsize = vecsize_from_writemask(ctx->dest_arg.writemask);