mojoshader_opengl.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 11 Nov 2011 02:20:36 -0500
changeset 1066 ff14db741834
parent 1063 b10281d6eb45
child 1067 e6397ec11bc9
permissions -rw-r--r--
Added MOJOSHADER_glBindShaders().
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
243
a0825a0d504a Added comment header to mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 242
diff changeset
     1
/**
a0825a0d504a Added comment header to mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 242
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
a0825a0d504a Added comment header to mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 242
diff changeset
     3
 *  Direct3D shaders.
a0825a0d504a Added comment header to mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 242
diff changeset
     4
 *
a0825a0d504a Added comment header to mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 242
diff changeset
     5
 * Please see the file LICENSE.txt in the source's root directory.
a0825a0d504a Added comment header to mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 242
diff changeset
     6
 *
a0825a0d504a Added comment header to mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 242
diff changeset
     7
 *  This file written by Ryan C. Gordon.
a0825a0d504a Added comment header to mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 242
diff changeset
     8
 */
a0825a0d504a Added comment header to mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 242
diff changeset
     9
1043
6227066350b4 Preshader input registers are separate from the actual shader constant file!
Ryan C. Gordon <icculus@icculus.org>
parents: 1040
diff changeset
    10
// !!! FIXME: preshaders shouldn't be handled in here at all. This should
6227066350b4 Preshader input registers are separate from the actual shader constant file!
Ryan C. Gordon <icculus@icculus.org>
parents: 1040
diff changeset
    11
// !!! FIXME:  be in the Effects API, once that's actually written.
6227066350b4 Preshader input registers are separate from the actual shader constant file!
Ryan C. Gordon <icculus@icculus.org>
parents: 1040
diff changeset
    12
202
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
#include <stdio.h>
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
#include <string.h>
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#include <stdlib.h>
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
#include <stdarg.h>
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#include <assert.h>
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
609
cfc937829b35 Added a FIXME.
Ryan C. Gordon <icculus@icculus.org>
parents: 608
diff changeset
    19
// !!! FIXME: most of these _MSC_VER should probably be _WINDOWS?
254
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 253
diff changeset
    20
#ifdef _MSC_VER
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 253
diff changeset
    21
#define WIN32_LEAN_AND_MEAN 1
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 253
diff changeset
    22
#include <windows.h>  // GL headers need this for WINGDIAPI definition.
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 253
diff changeset
    23
#endif
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 253
diff changeset
    24
457
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
    25
#if (defined(__APPLE__) && defined(__MACH__))
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
    26
#define PLATFORM_MACOSX 1
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
    27
#endif
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
    28
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
    29
#if PLATFORM_MACOSX
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
    30
#include <Carbon/Carbon.h>
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
    31
#endif
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
    32
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents: 463
diff changeset
    33
#define __MOJOSHADER_INTERNAL__ 1
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents: 463
diff changeset
    34
#include "mojoshader_internal.h"
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents: 463
diff changeset
    35
226
4a2b3d0b535f Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
    36
#define GL_GLEXT_LEGACY 1
246
897868fdd958 Moved gl*.h into GL directory.
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
    37
#include "GL/gl.h"
897868fdd958 Moved gl*.h into GL directory.
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
    38
#include "GL/glext.h"
202
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
449
5a978f37e750 Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents: 448
diff changeset
    40
#ifndef GL_HALF_FLOAT
5a978f37e750 Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents: 448
diff changeset
    41
#define GL_HALF_FLOAT 0x140B
5a978f37e750 Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents: 448
diff changeset
    42
#endif
5a978f37e750 Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents: 448
diff changeset
    43
5a978f37e750 Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents: 448
diff changeset
    44
#ifndef GL_HALF_FLOAT_OES
5a978f37e750 Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents: 448
diff changeset
    45
#define GL_HALF_FLOAT_OES 0x8D61
5a978f37e750 Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents: 448
diff changeset
    46
#endif
5a978f37e750 Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents: 448
diff changeset
    47
1056
73c697a7e950 Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
    48
// this happens to be the same value for ARB1 and GLSL.
73c697a7e950 Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
    49
#ifndef GL_PROGRAM_POINT_SIZE
73c697a7e950 Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
    50
#define GL_PROGRAM_POINT_SIZE 0x8642
73c697a7e950 Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
    51
#endif
449
5a978f37e750 Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents: 448
diff changeset
    52
202
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
struct MOJOSHADER_glShader
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
{
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
    const MOJOSHADER_parseData *parseData;
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
    56
    GLuint handle;
202
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
    uint32 refcount;
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
};
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
205
8583f89985df Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 204
diff changeset
    60
typedef struct
8583f89985df Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 204
diff changeset
    61
{
206
7027d889acdd Implemented MOJOSHADER_glProgramReady().
Ryan C. Gordon <icculus@icculus.org>
parents: 205
diff changeset
    62
    MOJOSHADER_shaderType shader_type;
226
4a2b3d0b535f Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
    63
    const MOJOSHADER_uniform *uniform;
798
5dd67cc04cf9 Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 797
diff changeset
    64
    GLint location;
205
8583f89985df Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 204
diff changeset
    65
} UniformMap;
8583f89985df Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 204
diff changeset
    66
213
73935330a973 Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 212
diff changeset
    67
typedef struct
73935330a973 Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 212
diff changeset
    68
{
226
4a2b3d0b535f Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
    69
    const MOJOSHADER_attribute *attribute;
798
5dd67cc04cf9 Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 797
diff changeset
    70
    GLint location;
213
73935330a973 Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 212
diff changeset
    71
} AttributeMap;
73935330a973 Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 212
diff changeset
    72
202
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
struct MOJOSHADER_glProgram
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
{
226
4a2b3d0b535f Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
    75
    MOJOSHADER_glShader *vertex;
4a2b3d0b535f Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
    76
    MOJOSHADER_glShader *fragment;
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
    77
    GLuint handle;
774
9ac0e5ad0205 Don't push uniforms if they've definitely not changed.
Ryan C. Gordon <icculus@icculus.org>
parents: 773
diff changeset
    78
    uint32 generation;
205
8583f89985df Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 204
diff changeset
    79
    uint32 uniform_count;
226
4a2b3d0b535f Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
    80
    UniformMap *uniforms;
213
73935330a973 Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 212
diff changeset
    81
    uint32 attribute_count;
226
4a2b3d0b535f Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
    82
    AttributeMap *attributes;
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
    83
    size_t vs_uniforms_float4_count;
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
    84
    GLfloat *vs_uniforms_float4;
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
    85
    size_t vs_uniforms_int4_count;
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
    86
    GLint *vs_uniforms_int4;
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
    87
    size_t vs_uniforms_bool_count;
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
    88
    GLint *vs_uniforms_bool;
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
    89
    size_t ps_uniforms_float4_count;
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
    90
    GLfloat *ps_uniforms_float4;
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
    91
    size_t ps_uniforms_int4_count;
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
    92
    GLint *ps_uniforms_int4;
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
    93
    size_t ps_uniforms_bool_count;
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
    94
    GLint *ps_uniforms_bool;
1043
6227066350b4 Preshader input registers are separate from the actual shader constant file!
Ryan C. Gordon <icculus@icculus.org>
parents: 1040
diff changeset
    95
6227066350b4 Preshader input registers are separate from the actual shader constant file!
Ryan C. Gordon <icculus@icculus.org>
parents: 1040
diff changeset
    96
    size_t vs_preshader_reg_count;
6227066350b4 Preshader input registers are separate from the actual shader constant file!
Ryan C. Gordon <icculus@icculus.org>
parents: 1040
diff changeset
    97
    GLfloat *vs_preshader_regs;
6227066350b4 Preshader input registers are separate from the actual shader constant file!
Ryan C. Gordon <icculus@icculus.org>
parents: 1040
diff changeset
    98
    size_t ps_preshader_reg_count;
6227066350b4 Preshader input registers are separate from the actual shader constant file!
Ryan C. Gordon <icculus@icculus.org>
parents: 1040
diff changeset
    99
    GLfloat *ps_preshader_regs;
6227066350b4 Preshader input registers are separate from the actual shader constant file!
Ryan C. Gordon <icculus@icculus.org>
parents: 1040
diff changeset
   100
202
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
    uint32 refcount;
1056
73c697a7e950 Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   102
73c697a7e950 Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   103
    int uses_pointsize;
73c697a7e950 Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   104
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   105
    // GLSL uses these...location of uniform arrays.
797
58d15db2881e GLSL Uniform locations are signed ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 791
diff changeset
   106
    GLint vs_float4_loc;
58d15db2881e GLSL Uniform locations are signed ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 791
diff changeset
   107
    GLint vs_int4_loc;
58d15db2881e GLSL Uniform locations are signed ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 791
diff changeset
   108
    GLint vs_bool_loc;
58d15db2881e GLSL Uniform locations are signed ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 791
diff changeset
   109
    GLint ps_float4_loc;
58d15db2881e GLSL Uniform locations are signed ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 791
diff changeset
   110
    GLint ps_int4_loc;
58d15db2881e GLSL Uniform locations are signed ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 791
diff changeset
   111
    GLint ps_bool_loc;
202
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
};
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
277
49a6571cac6d Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   114
#ifndef WINGDIAPI
49a6571cac6d Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   115
#define WINGDIAPI
49a6571cac6d Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   116
#endif
49a6571cac6d Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   117
242
c3c5693ba179 Fixed vertex attribute aliasing in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 241
diff changeset
   118
// Entry points in base OpenGL that lack function pointer prototypes...
276
1d7437469c94 Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   119
typedef WINGDIAPI void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params);
1d7437469c94 Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   120
typedef WINGDIAPI const GLubyte * (APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
333
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   121
typedef WINGDIAPI GLenum (APIENTRYP PFNGLGETERRORPROC) (void);
358
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   122
typedef WINGDIAPI void (APIENTRYP PFNGLENABLEPROC) (GLenum cap);
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   123
typedef WINGDIAPI void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap);
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   124
773
3e3638be6e2b Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents: 772
diff changeset
   125
// Max entries for each register file type...
3e3638be6e2b Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents: 772
diff changeset
   126
#define MAX_REG_FILE_F 8192
3e3638be6e2b Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents: 772
diff changeset
   127
#define MAX_REG_FILE_I 2047
3e3638be6e2b Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents: 772
diff changeset
   128
#define MAX_REG_FILE_B 2047
3e3638be6e2b Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents: 772
diff changeset
   129
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   130
struct MOJOSHADER_glContext
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   131
{
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   132
    // Allocators...
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   133
    MOJOSHADER_malloc malloc_fn;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   134
    MOJOSHADER_free free_fn;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   135
    void *malloc_data;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   136
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   137
    // The constant register files...
806
facbf9d3f1ce Added a FIXME.
Ryan C. Gordon <icculus@icculus.org>
parents: 798
diff changeset
   138
    // !!! FIXME: Man, it kills me how much memory this takes...
facbf9d3f1ce Added a FIXME.
Ryan C. Gordon <icculus@icculus.org>
parents: 798
diff changeset
   139
    // !!! FIXME:  ... make this dynamically allocated on demand.
773
3e3638be6e2b Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents: 772
diff changeset
   140
    GLfloat vs_reg_file_f[MAX_REG_FILE_F * 4];
3e3638be6e2b Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents: 772
diff changeset
   141
    GLint vs_reg_file_i[MAX_REG_FILE_I * 4];
3e3638be6e2b Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents: 772
diff changeset
   142
    uint8 vs_reg_file_b[MAX_REG_FILE_B];
3e3638be6e2b Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents: 772
diff changeset
   143
    GLfloat ps_reg_file_f[MAX_REG_FILE_F * 4];
3e3638be6e2b Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents: 772
diff changeset
   144
    GLint ps_reg_file_i[MAX_REG_FILE_I * 4];
3e3638be6e2b Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents: 772
diff changeset
   145
    uint8 ps_reg_file_b[MAX_REG_FILE_B];
284
ea52f9707795 Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 281
diff changeset
   146
    GLuint sampler_reg_file[16];
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   147
774
9ac0e5ad0205 Don't push uniforms if they've definitely not changed.
Ryan C. Gordon <icculus@icculus.org>
parents: 773
diff changeset
   148
    // This increments every time we change the register files.
9ac0e5ad0205 Don't push uniforms if they've definitely not changed.
Ryan C. Gordon <icculus@icculus.org>
parents: 773
diff changeset
   149
    uint32 generation;
9ac0e5ad0205 Don't push uniforms if they've definitely not changed.
Ryan C. Gordon <icculus@icculus.org>
parents: 773
diff changeset
   150
1066
ff14db741834 Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   151
    // This keeps track of implicitly linked programs.
ff14db741834 Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   152
    HashTable *linker_cache;
ff14db741834 Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   153
775
2c93dcb14687 Only enable/disable vertex arrays when forced to.
Ryan C. Gordon <icculus@icculus.org>
parents: 774
diff changeset
   154
    // This tells us which vertex attribute arrays we have enabled.
798
5dd67cc04cf9 Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 797
diff changeset
   155
    GLint max_attrs;
775
2c93dcb14687 Only enable/disable vertex arrays when forced to.
Ryan C. Gordon <icculus@icculus.org>
parents: 774
diff changeset
   156
    uint8 want_attr[32];
2c93dcb14687 Only enable/disable vertex arrays when forced to.
Ryan C. Gordon <icculus@icculus.org>
parents: 774
diff changeset
   157
    uint8 have_attr[32];
2c93dcb14687 Only enable/disable vertex arrays when forced to.
Ryan C. Gordon <icculus@icculus.org>
parents: 774
diff changeset
   158
1056
73c697a7e950 Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   159
    // rarely used, so we don't touch when we don't have to.
73c697a7e950 Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   160
    int pointsize_enabled;
73c697a7e950 Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   161
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   162
    // GL stuff...
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   163
    int opengl_major;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   164
    int opengl_minor;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   165
    MOJOSHADER_glProgram *bound_program;
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   166
    char profile[16];
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   167
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   168
    // Extensions...
463
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   169
    int have_base_opengl;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   170
    int have_GL_ARB_vertex_program;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   171
    int have_GL_ARB_fragment_program;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   172
    int have_GL_NV_vertex_program2_option;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   173
    int have_GL_NV_fragment_program2;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   174
    int have_GL_NV_vertex_program3;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   175
    int have_GL_NV_gpu_program4;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   176
    int have_GL_ARB_shader_objects;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   177
    int have_GL_ARB_vertex_shader;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   178
    int have_GL_ARB_fragment_shader;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   179
    int have_GL_ARB_shading_language_100;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   180
    int have_GL_NV_half_float;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   181
    int have_GL_ARB_half_float_vertex;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   182
    int have_GL_OES_vertex_half_float;
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   183
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   184
    // Entry points...
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   185
    PFNGLGETSTRINGPROC glGetString;
333
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   186
    PFNGLGETERRORPROC glGetError;
276
1d7437469c94 Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   187
    PFNGLGETINTEGERVPROC glGetIntegerv;
358
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   188
    PFNGLENABLEPROC glEnable;
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   189
    PFNGLDISABLEPROC glDisable;
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   190
    PFNGLDELETEOBJECTARBPROC glDeleteObject;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   191
    PFNGLATTACHOBJECTARBPROC glAttachObject;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   192
    PFNGLCOMPILESHADERARBPROC glCompileShader;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   193
    PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObject;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   194
    PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObject;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   195
    PFNGLDISABLEVERTEXATTRIBARRAYARBPROC glDisableVertexAttribArray;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   196
    PFNGLENABLEVERTEXATTRIBARRAYARBPROC glEnableVertexAttribArray;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   197
    PFNGLGETATTRIBLOCATIONARBPROC glGetAttribLocation;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   198
    PFNGLGETINFOLOGARBPROC glGetInfoLog;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   199
    PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameteriv;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   200
    PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocation;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   201
    PFNGLLINKPROGRAMARBPROC glLinkProgram;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   202
    PFNGLSHADERSOURCEARBPROC glShaderSource;
764
b68ebc750c34 Use ARB typedef name.
Ryan C. Gordon <icculus@icculus.org>
parents: 763
diff changeset
   203
    PFNGLUNIFORM1IARBPROC glUniform1i;
b68ebc750c34 Use ARB typedef name.
Ryan C. Gordon <icculus@icculus.org>
parents: 763
diff changeset
   204
    PFNGLUNIFORM1IVARBPROC glUniform1iv;
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   205
    PFNGLUNIFORM4FVARBPROC glUniform4fv;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   206
    PFNGLUNIFORM4IVARBPROC glUniform4iv;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   207
    PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObject;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   208
    PFNGLVERTEXATTRIBPOINTERARBPROC glVertexAttribPointer;
333
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   209
    PFNGLGETPROGRAMIVARBPROC glGetProgramivARB;
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   210
    PFNGLGETPROGRAMSTRINGARBPROC glGetProgramStringARB;
395
d2307cc5d6e7 Use local parameters, not environment params, in the arb1/nv2 profiles.
Ryan C. Gordon <icculus@icculus.org>
parents: 394
diff changeset
   211
    PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB;
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   212
    PFNGLPROGRAMLOCALPARAMETERI4IVNVPROC glProgramLocalParameterI4ivNV;
333
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   213
    PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB;
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   214
    PFNGLGENPROGRAMSARBPROC glGenProgramsARB;
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   215
    PFNGLBINDPROGRAMARBPROC glBindProgramARB;
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   216
    PFNGLPROGRAMSTRINGARBPROC glProgramStringARB;
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   217
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   218
    // interface for profile-specific things.
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   219
    int (*profileMaxUniforms)(MOJOSHADER_shaderType shader_type);
333
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   220
    int (*profileCompileShader)(const MOJOSHADER_parseData *pd, GLuint *s);
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   221
    void (*profileDeleteShader)(const GLuint shader);
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   222
    void (*profileDeleteProgram)(const GLuint program);
347
f8d9d0ae6ba8 Bunch more work (ARB1 profile, OpenGL glue, and general fixes).
Ryan C. Gordon <icculus@icculus.org>
parents: 340
diff changeset
   223
    GLint (*profileGetAttribLocation)(MOJOSHADER_glProgram *program, int idx);
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   224
    GLint (*profileGetUniformLocation)(MOJOSHADER_glProgram *program, MOJOSHADER_glShader *shader, int idx);
347
f8d9d0ae6ba8 Bunch more work (ARB1 profile, OpenGL glue, and general fixes).
Ryan C. Gordon <icculus@icculus.org>
parents: 340
diff changeset
   225
    GLint (*profileGetSamplerLocation)(MOJOSHADER_glProgram *, MOJOSHADER_glShader *, int);
333
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   226
    GLuint (*profileLinkProgram)(MOJOSHADER_glShader *, MOJOSHADER_glShader *);
765
076f3bd42329 Moved profileInitProgram to profileFinalInitProgram.
Ryan C. Gordon <icculus@icculus.org>
parents: 764
diff changeset
   227
    void (*profileFinalInitProgram)(MOJOSHADER_glProgram *program);
333
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   228
    void (*profileUseProgramObject)(MOJOSHADER_glProgram *program);
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   229
    void (*profilePushConstantArray)(MOJOSHADER_glProgram *, const MOJOSHADER_uniform *, const GLfloat *);
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   230
    void (*profilePushUniforms)(void);
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   231
    void (*profilePushSampler)(GLint loc, GLuint sampler);
760
6dc8d2cafc58 "Must Push" seemed more correct than "Must Load".
Ryan C. Gordon <icculus@icculus.org>
parents: 759
diff changeset
   232
    int (*profileMustPushConstantArrays)(void);
6dc8d2cafc58 "Must Push" seemed more correct than "Must Load".
Ryan C. Gordon <icculus@icculus.org>
parents: 759
diff changeset
   233
    int (*profileMustPushSamplers)(void);
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   234
};
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   235
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   236
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   237
static MOJOSHADER_glContext *ctx = NULL;
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   238
219
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
   239
// Error state...
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
   240
static char error_buffer[1024] = { '\0' };
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
   241
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
   242
static void set_error(const char *str)
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
   243
{
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
   244
    snprintf(error_buffer, sizeof (error_buffer), "%s", str);
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
   245
} // set_error
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
   246
457
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   247
#if PLATFORM_MACOSX
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   248
static inline int macosx_version_atleast(int x, int y, int z)
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   249
{
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   250
    static int checked = 0;
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   251
    static int combined = 0;
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   252
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   253
    if (!checked)
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   254
    {
807
138d76f766d1 Fixed compiler warnings on 64-bit Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 806
diff changeset
   255
        SInt32 ver, major, minor, patch;
457
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   256
        int convert = 0;
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   257
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   258
        if (Gestalt(gestaltSystemVersion, &ver) != noErr)
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   259
            ver = 0x1000;  // oh well.
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   260
        else if (ver < 0x1030)
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   261
            convert = 1;  // split (ver) into (major),(minor),(patch).
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   262
        else
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   263
        {
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   264
            // presumably this won't fail. But if it does, we'll just use the
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   265
            //  original version value. This might cut the value--10.12.11 will
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   266
            //  come out to 10.9.9, for example--but it's better than nothing.
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   267
            if (Gestalt(gestaltSystemVersionMajor, &major) != noErr)
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   268
                convert = 1;
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   269
            else if (Gestalt(gestaltSystemVersionMinor, &minor) != noErr)
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   270
                convert = 1;
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   271
            else if (Gestalt(gestaltSystemVersionBugFix, &patch) != noErr)
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   272
                convert = 1;
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   273
        } // else
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   274
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   275
        if (convert)
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   276
        {
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   277
            major = ((ver & 0xFF00) >> 8);
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   278
            major = (((major / 16) * 10) + (major % 16));
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   279
            minor = ((ver & 0xF0) >> 4);
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   280
            patch = (ver & 0xF);
533
177b9242d08a Fixed a comment.
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   281
        } // if
457
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   282
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   283
        combined = (major << 16) | (minor << 8) | patch;
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   284
        checked = 1;
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   285
    } // if
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   286
460
54c614f0fcb0 Fixed OS X detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 459
diff changeset
   287
    return (combined >= ((x << 16) | (y << 8) | z));
457
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   288
} // macosx_version_atleast
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   289
#endif
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   290
1066
ff14db741834 Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   291
static inline void out_of_memory(void)
ff14db741834 Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   292
{
ff14db741834 Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   293
    set_error("out of memory");
ff14db741834 Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   294
} // out_of_memory
202
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
static inline void *Malloc(const size_t len)
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
{
307
42f6a7ba69e2 Fixes for Visual Studio level 4 compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 291
diff changeset
   298
    void *retval = ctx->malloc_fn((int) len, ctx->malloc_data);
220
df5ea69833d5 Fixes to Malloc() and Free() in mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
   299
    if (retval == NULL)
1066
ff14db741834 Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   300
        out_of_memory();
220
df5ea69833d5 Fixes to Malloc() and Free() in mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
   301
    return retval;
202
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
} // Malloc
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
static inline void Free(void *ptr)
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
{
220
df5ea69833d5 Fixes to Malloc() and Free() in mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
   306
    if (ptr != NULL)
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   307
        ctx->free_fn(ptr, ctx->malloc_data);
202
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
} // Free
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
358
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   311
static inline void toggle_gl_state(GLenum state, int val)
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   312
{
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   313
    if (val)
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   314
        ctx->glEnable(state);
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   315
    else
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   316
        ctx->glDisable(state);
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   317
} // toggle_gl_state
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   318
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   319
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   320
// profile-specific implementations...
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   321
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   322
#if SUPPORT_PROFILE_GLSL
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   323
static inline GLenum glsl_shader_type(const MOJOSHADER_shaderType t)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   324
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   325
    if (t == MOJOSHADER_TYPE_VERTEX)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   326
        return GL_VERTEX_SHADER;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   327
    else if (t == MOJOSHADER_TYPE_PIXEL)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   328
        return GL_FRAGMENT_SHADER;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   329
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   330
    // !!! FIXME: geometry shaders?
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   331
    return GL_NONE;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   332
} // glsl_shader_type
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   333
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   334
760
6dc8d2cafc58 "Must Push" seemed more correct than "Must Load".
Ryan C. Gordon <icculus@icculus.org>
parents: 759
diff changeset
   335
static int impl_GLSL_MustPushConstantArrays(void) { return 1; }
6dc8d2cafc58 "Must Push" seemed more correct than "Must Load".
Ryan C. Gordon <icculus@icculus.org>
parents: 759
diff changeset
   336
static int impl_GLSL_MustPushSamplers(void) { return 1; }
438
73492129c1af Expose true constant arrays in parseData, load them at link time for GLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 436
diff changeset
   337
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   338
static int impl_GLSL_MaxUniforms(MOJOSHADER_shaderType shader_type)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   339
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   340
    GLenum pname = GL_NONE;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   341
    GLint val = 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   342
    if (shader_type == MOJOSHADER_TYPE_VERTEX)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   343
        pname = GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   344
    else if (shader_type == MOJOSHADER_TYPE_PIXEL)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   345
        pname = GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   346
    else
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   347
        return -1;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   348
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   349
    ctx->glGetIntegerv(pname, &val);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   350
    return (int) val;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   351
} // impl_GLSL_MaxUniforms
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   352
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   353
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   354
static int impl_GLSL_CompileShader(const MOJOSHADER_parseData *pd, GLuint *s)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   355
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   356
    GLint ok = 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   357
    GLint shaderlen = (GLint) pd->output_len;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   358
    const GLenum shader_type = glsl_shader_type(pd->shader_type);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   359
    GLuint shader = ctx->glCreateShaderObject(shader_type);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   360
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   361
    ctx->glShaderSource(shader, 1, (const GLchar **) &pd->output, &shaderlen);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   362
    ctx->glCompileShader(shader);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   363
    ctx->glGetObjectParameteriv(shader, GL_OBJECT_COMPILE_STATUS_ARB, &ok);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   364
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   365
    if (!ok)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   366
    {
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   367
        GLsizei len = 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   368
        ctx->glGetInfoLog(shader, sizeof (error_buffer), &len,
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   369
                          (GLchar *) error_buffer);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   370
        *s = 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   371
        return 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   372
    } // if
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   373
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   374
    *s = shader;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   375
    return 1;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   376
} // impl_GLSL_CompileShader
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   377
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   378
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   379
static void impl_GLSL_DeleteShader(const GLuint shader)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   380
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   381
    ctx->glDeleteObject(shader);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   382
} // impl_GLSL_DeleteShader
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   383
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   384
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   385
static void impl_GLSL_DeleteProgram(const GLuint program)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   386
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   387
    ctx->glDeleteObject(program);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   388
} // impl_GLSL_DeleteProgram
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   389
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   390
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   391
static GLint impl_GLSL_GetUniformLocation(MOJOSHADER_glProgram *program,
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   392
                                          MOJOSHADER_glShader *shader, int idx)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   393
{
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   394
    return 0;  // no-op, we push this as one big-ass array now.
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   395
} // impl_GLSL_GetUniformLocation
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   396
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   397
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   398
static GLint impl_GLSL_GetSamplerLocation(MOJOSHADER_glProgram *program,
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   399
                                          MOJOSHADER_glShader *shader, int idx)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   400
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   401
    return ctx->glGetUniformLocation(program->handle,
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   402
                                     shader->parseData->samplers[idx].name);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   403
} // impl_GLSL_GetSamplerLocation
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   404
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   405
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   406
static GLint impl_GLSL_GetAttribLocation(MOJOSHADER_glProgram *program, int idx)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   407
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   408
    const MOJOSHADER_parseData *pd = program->vertex->parseData;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   409
    const MOJOSHADER_attribute *a = pd->attributes;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   410
    return ctx->glGetAttribLocation(program->handle, a[idx].name);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   411
} // impl_GLSL_GetAttribLocation
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   412
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   413
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   414
static GLuint impl_GLSL_LinkProgram(MOJOSHADER_glShader *vshader,
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   415
                                    MOJOSHADER_glShader *pshader)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   416
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   417
    const GLuint program = ctx->glCreateProgramObject();
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   418
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   419
    if (vshader != NULL) ctx->glAttachObject(program, vshader->handle);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   420
    if (pshader != NULL) ctx->glAttachObject(program, pshader->handle);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   421
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   422
    ctx->glLinkProgram(program);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   423
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   424
    GLint ok = 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   425
    ctx->glGetObjectParameteriv(program, GL_OBJECT_LINK_STATUS_ARB, &ok);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   426
    if (!ok)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   427
    {
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   428
        GLsizei len = 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   429
        ctx->glGetInfoLog(program, sizeof (error_buffer), &len, (GLchar *) error_buffer);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   430
        ctx->glDeleteObject(program);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   431
        return 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   432
    } // if
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   433
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   434
    return program;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   435
} // impl_GLSL_LinkProgram
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   436
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   437
765
076f3bd42329 Moved profileInitProgram to profileFinalInitProgram.
Ryan C. Gordon <icculus@icculus.org>
parents: 764
diff changeset
   438
static void impl_GLSL_FinalInitProgram(MOJOSHADER_glProgram *program)
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   439
{
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   440
    program->vs_float4_loc =
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   441
        ctx->glGetUniformLocation(program->handle, "vs_uniforms_vec4");
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   442
    program->vs_int4_loc =
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   443
        ctx->glGetUniformLocation(program->handle, "vs_uniforms_ivec4");
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   444
    program->vs_bool_loc =
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   445
        ctx->glGetUniformLocation(program->handle, "vs_uniforms_bool");
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   446
    program->ps_float4_loc =
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   447
        ctx->glGetUniformLocation(program->handle, "ps_uniforms_vec4");
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   448
    program->ps_int4_loc =
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   449
        ctx->glGetUniformLocation(program->handle, "ps_uniforms_ivec4");
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   450
    program->ps_bool_loc =
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   451
        ctx->glGetUniformLocation(program->handle, "ps_uniforms_bool");
765
076f3bd42329 Moved profileInitProgram to profileFinalInitProgram.
Ryan C. Gordon <icculus@icculus.org>
parents: 764
diff changeset
   452
} // impl_GLSL_FinalInitProgram
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   453
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   454
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   455
static void impl_GLSL_UseProgramObject(MOJOSHADER_glProgram *program)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   456
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   457
    ctx->glUseProgramObject((program != NULL) ? program->handle : 0);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   458
} // impl_GLSL_UseProgramObject
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   459
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   460
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   461
static void impl_GLSL_PushConstantArray(MOJOSHADER_glProgram *program,
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   462
                                        const MOJOSHADER_uniform *u,
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   463
                                        const GLfloat *f)
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   464
{
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   465
    const GLint loc = ctx->glGetUniformLocation(program->handle, u->name);
798
5dd67cc04cf9 Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 797
diff changeset
   466
    if (loc >= 0)   // not optimized out?
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   467
        ctx->glUniform4fv(loc, u->array_count, f);
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   468
} // impl_GLSL_PushConstantArray
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   469
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   470
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   471
static void impl_GLSL_PushUniforms(void)
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   472
{
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   473
    const MOJOSHADER_glProgram *program = ctx->bound_program;
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   474
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   475
    assert(program->uniform_count > 0);  // don't call with nothing to do!
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   476
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   477
    if (program->vs_float4_loc != -1)
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   478
    {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   479
        ctx->glUniform4fv(program->vs_float4_loc,
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   480
                          program->vs_uniforms_float4_count,
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   481
                          program->vs_uniforms_float4);
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   482
    } // if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   483
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   484
    if (program->vs_int4_loc != -1)
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   485
    {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   486
        ctx->glUniform4iv(program->vs_int4_loc,
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   487
                          program->vs_uniforms_int4_count,
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   488
                          program->vs_uniforms_int4);
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   489
    } // if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   490
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   491
    if (program->vs_bool_loc != -1)
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   492
    {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   493
        ctx->glUniform1iv(program->vs_bool_loc,
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   494
                          program->vs_uniforms_bool_count,
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   495
                          program->vs_uniforms_bool);
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   496
    } // if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   497
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   498
    if (program->ps_float4_loc != -1)
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   499
    {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   500
        ctx->glUniform4fv(program->ps_float4_loc,
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   501
                          program->ps_uniforms_float4_count,
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   502
                          program->ps_uniforms_float4);
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   503
    } // if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   504
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   505
    if (program->ps_int4_loc != -1)
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   506
    {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   507
        ctx->glUniform4iv(program->ps_int4_loc,
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   508
                          program->ps_uniforms_int4_count,
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   509
                          program->ps_uniforms_int4);
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   510
    } // if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   511
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   512
    if (program->ps_bool_loc != -1)
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   513
    {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   514
        ctx->glUniform1iv(program->ps_bool_loc,
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   515
                          program->ps_uniforms_bool_count,
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   516
                          program->ps_uniforms_bool);
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   517
    } // if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   518
} // impl_GLSL_PushUniforms
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   519
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   520
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   521
static void impl_GLSL_PushSampler(GLint loc, GLuint sampler)
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   522
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   523
    ctx->glUniform1i(loc, sampler);
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   524
} // impl_GLSL_PushSampler
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   525
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   526
#endif  // SUPPORT_PROFILE_GLSL
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   527
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   528
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   529
#if SUPPORT_PROFILE_ARB1
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   530
static inline GLenum arb1_shader_type(const MOJOSHADER_shaderType t)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   531
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   532
    if (t == MOJOSHADER_TYPE_VERTEX)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   533
        return GL_VERTEX_PROGRAM_ARB;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   534
    else if (t == MOJOSHADER_TYPE_PIXEL)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   535
        return GL_FRAGMENT_PROGRAM_ARB;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   536
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   537
    // !!! FIXME: geometry shaders?
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   538
    return GL_NONE;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   539
} // arb1_shader_type
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   540
760
6dc8d2cafc58 "Must Push" seemed more correct than "Must Load".
Ryan C. Gordon <icculus@icculus.org>
parents: 759
diff changeset
   541
static int impl_ARB1_MustPushConstantArrays(void) { return 0; }
6dc8d2cafc58 "Must Push" seemed more correct than "Must Load".
Ryan C. Gordon <icculus@icculus.org>
parents: 759
diff changeset
   542
static int impl_ARB1_MustPushSamplers(void) { return 0; }
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   543
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   544
static int impl_ARB1_MaxUniforms(MOJOSHADER_shaderType shader_type)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   545
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   546
    GLint retval = 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   547
    const GLenum program_type = arb1_shader_type(shader_type);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   548
    if (program_type == GL_NONE)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   549
        return -1;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   550
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   551
    ctx->glGetProgramivARB(program_type, GL_MAX_PROGRAM_PARAMETERS_ARB, &retval);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   552
    return (int) retval;  // !!! FIXME: times four?
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   553
} // impl_ARB1_MaxUniforms
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   554
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   555
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   556
static int impl_ARB1_CompileShader(const MOJOSHADER_parseData *pd, GLuint *s)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   557
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   558
    GLint shaderlen = (GLint) pd->output_len;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   559
    const GLenum shader_type = arb1_shader_type(pd->shader_type);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   560
    GLuint shader = 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   561
    ctx->glGenProgramsARB(1, &shader);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   562
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   563
    ctx->glGetError();  // flush any existing error state.
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   564
    ctx->glBindProgramARB(shader_type, shader);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   565
    ctx->glProgramStringARB(shader_type, GL_PROGRAM_FORMAT_ASCII_ARB,
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   566
                                shaderlen, pd->output);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   567
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   568
    if (ctx->glGetError() == GL_INVALID_OPERATION)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   569
    { 
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   570
        GLint pos = 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   571
        ctx->glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   572
        const GLubyte *errstr = ctx->glGetString(GL_PROGRAM_ERROR_STRING_ARB);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   573
        snprintf(error_buffer, sizeof (error_buffer),
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   574
                  "ARB1 compile error at position %d: %s",
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   575
                  (int) pos, (const char *) errstr);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   576
        ctx->glBindProgramARB(shader_type, 0);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   577
        ctx->glDeleteProgramsARB(1, &shader);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   578
        *s = 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   579
        return 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   580
    } // if
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   581
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   582
    *s = shader;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   583
    return 1;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   584
} // impl_ARB1_CompileShader
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   585
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   586
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   587
static void impl_ARB1_DeleteShader(const GLuint _shader)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   588
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   589
    GLuint shader = _shader;  // const removal.
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   590
    ctx->glDeleteProgramsARB(1, &shader);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   591
} // impl_ARB1_DeleteShader
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   592
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   593
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   594
static void impl_ARB1_DeleteProgram(const GLuint program)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   595
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   596
    // no-op. ARB1 doesn't have real linked programs.
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   597
} // impl_GLSL_DeleteProgram
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   598
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   599
static GLint impl_ARB1_GetUniformLocation(MOJOSHADER_glProgram *program,
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   600
                                          MOJOSHADER_glShader *shader, int idx)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   601
{
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   602
    return 0;  // no-op, we push this as one big-ass array now.
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   603
} // impl_ARB1_GetUniformLocation
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   604
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   605
static GLint impl_ARB1_GetSamplerLocation(MOJOSHADER_glProgram *program,
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   606
                                          MOJOSHADER_glShader *shader, int idx)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   607
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   608
    return shader->parseData->samplers[idx].index;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   609
} // impl_ARB1_GetSamplerLocation
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   610
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   611
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   612
static GLint impl_ARB1_GetAttribLocation(MOJOSHADER_glProgram *program, int idx)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   613
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   614
    return idx;  // map to vertex arrays in the same order as the parseData.
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   615
} // impl_ARB1_GetAttribLocation
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   616
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   617
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   618
static GLuint impl_ARB1_LinkProgram(MOJOSHADER_glShader *vshader,
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   619
                                    MOJOSHADER_glShader *pshader)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   620
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   621
    // there is no formal linking in ARB1...just return a unique value.
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   622
    static GLuint retval = 1;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   623
    return retval++;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   624
} // impl_ARB1_LinkProgram
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   625
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   626
765
076f3bd42329 Moved profileInitProgram to profileFinalInitProgram.
Ryan C. Gordon <icculus@icculus.org>
parents: 764
diff changeset
   627
static void impl_ARB1_FinalInitProgram(MOJOSHADER_glProgram *program)
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   628
{
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   629
    // no-op.
765
076f3bd42329 Moved profileInitProgram to profileFinalInitProgram.
Ryan C. Gordon <icculus@icculus.org>
parents: 764
diff changeset
   630
} // impl_ARB1_FinalInitProgram
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   631
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   632
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   633
static void impl_ARB1_UseProgramObject(MOJOSHADER_glProgram *program)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   634
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   635
    GLuint vhandle = 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   636
    GLuint phandle = 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   637
    if (program != NULL)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   638
    {
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   639
        if (program->vertex != NULL)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   640
            vhandle = program->vertex->handle;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   641
        if (program->fragment != NULL)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   642
            phandle = program->fragment->handle;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   643
    } // if
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   644
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   645
    toggle_gl_state(GL_VERTEX_PROGRAM_ARB, vhandle != 0);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   646
    toggle_gl_state(GL_FRAGMENT_PROGRAM_ARB, phandle != 0);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   647
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   648
    ctx->glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vhandle);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   649
    ctx->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, phandle);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   650
} // impl_ARB1_UseProgramObject
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   651
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   652
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   653
static void impl_ARB1_PushConstantArray(MOJOSHADER_glProgram *program,
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   654
                                        const MOJOSHADER_uniform *u,
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   655
                                        const GLfloat *f)
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   656
{
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   657
    // no-op. Constant arrays are defined in source code for arb1.
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   658
} // impl_ARB1_PushConstantArray
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   659
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   660
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   661
static void impl_ARB1_PushUniforms(void)
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   662
{
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   663
    // vertex shader uniforms come first in program->uniforms array.
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   664
    MOJOSHADER_shaderType shader_type = MOJOSHADER_TYPE_VERTEX;
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   665
    GLenum arb_shader_type = arb1_shader_type(shader_type);
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   666
    const MOJOSHADER_glProgram *program = ctx->bound_program;
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   667
    const uint32 count = program->uniform_count;
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   668
    const GLfloat *srcf = program->vs_uniforms_float4;
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   669
    const GLint *srci = program->vs_uniforms_int4;
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   670
    const GLint *srcb = program->vs_uniforms_bool;
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   671
    GLint loc = 0;
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   672
    uint32 i;
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   673
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   674
    assert(count > 0);  // shouldn't call this with nothing to do!
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   675
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   676
    for (i = 0; i < count; i++)
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   677
    {
767
806ba18f23aa Cleanups and fixes in ARB1 uniform pushing.
Ryan C. Gordon <icculus@icculus.org>
parents: 766
diff changeset
   678
        UniformMap *map = &program->uniforms[i];
770
b5e545408b02 Fixed incorrect variable name.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   679
        const MOJOSHADER_shaderType uniform_shader_type = map->shader_type;
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   680
        const MOJOSHADER_uniform *u = map->uniform;
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   681
        const MOJOSHADER_uniformType type = u->type;
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   682
        const int size = u->array_count ? u->array_count : 1;
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   683
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   684
        assert(!u->constant);
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   685
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   686
        // Did we switch from vertex to pixel (to geometry, etc)?
770
b5e545408b02 Fixed incorrect variable name.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   687
        if (shader_type != uniform_shader_type)
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   688
        {
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   689
            // we start with vertex, move to pixel, then to geometry, etc.
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   690
            //  The array should always be sorted as such.
770
b5e545408b02 Fixed incorrect variable name.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   691
            if (uniform_shader_type == MOJOSHADER_TYPE_PIXEL)
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   692
            {
770
b5e545408b02 Fixed incorrect variable name.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   693
                assert(shader_type == MOJOSHADER_TYPE_VERTEX);
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   694
                srcf = program->ps_uniforms_float4;
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   695
                srci = program->ps_uniforms_int4;
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   696
                srcb = program->ps_uniforms_bool;
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   697
                loc = 0;
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   698
            } // if
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   699
            else
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   700
            {
769
0627038d2032 Fixed wrong assert; triggered if there were no vertex shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 768
diff changeset
   701
                // These should be ordered vertex, then pixel, then geometry.
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   702
                assert(0 && "Unexpected shader type");
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   703
            } // else
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   704
770
b5e545408b02 Fixed incorrect variable name.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   705
            shader_type = uniform_shader_type;
b5e545408b02 Fixed incorrect variable name.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   706
            arb_shader_type = arb1_shader_type(uniform_shader_type);
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   707
        } // if
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   708
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   709
        if (type == MOJOSHADER_UNIFORM_FLOAT)
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   710
        {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   711
            int i;
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   712
            for (i = 0; i < size; i++, srcf += 4, loc++)
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   713
                ctx->glProgramLocalParameter4fvARB(arb_shader_type, loc, srcf);
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   714
        } // if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   715
        else if (type == MOJOSHADER_UNIFORM_INT)
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   716
        {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   717
            int i;
1024
dbff93345a84 Test for the GL extension, not whether the entry point is NULL.
Ryan C. Gordon <icculus@icculus.org>
parents: 1023
diff changeset
   718
            if (ctx->have_GL_NV_gpu_program4)
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   719
            {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   720
                // GL_NV_gpu_program4 has integer uniform loading support.
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   721
                for (i = 0; i < size; i++, srci += 4, loc++)
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   722
                    ctx->glProgramLocalParameterI4ivNV(arb_shader_type, loc, srci);
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   723
            } // if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   724
            else
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   725
            {
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   726
                for (i = 0; i < size; i++, srci += 4, loc++)
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   727
                {
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   728
                    const GLfloat fv[4] = {
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   729
                        (GLfloat) srci[0], (GLfloat) srci[1],
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   730
                        (GLfloat) srci[2], (GLfloat) srci[3]
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   731
                    };
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   732
                    ctx->glProgramLocalParameter4fvARB(arb_shader_type, loc, fv);
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   733
                } // for
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   734
            } // else
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   735
        } // else if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   736
        else if (type == MOJOSHADER_UNIFORM_BOOL)
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   737
        {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   738
            int i;
1024
dbff93345a84 Test for the GL extension, not whether the entry point is NULL.
Ryan C. Gordon <icculus@icculus.org>
parents: 1023
diff changeset
   739
            if (ctx->have_GL_NV_gpu_program4)
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   740
            {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   741
                // GL_NV_gpu_program4 has integer uniform loading support.
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   742
                for (i = 0; i < size; i++, srcb++, loc++)
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   743
                {
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   744
                    const GLint ib = (GLint) ((*srcb) ? 1 : 0);
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   745
                    const GLint iv[4] = { ib, ib, ib, ib };
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   746
                    ctx->glProgramLocalParameterI4ivNV(arb_shader_type, loc, iv);
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   747
                } // for
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   748
            } // if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   749
            else
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   750
            {
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   751
                for (i = 0; i < size; i++, srcb++, loc++)
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   752
                {
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   753
                    const GLfloat fb = (GLfloat) ((*srcb) ? 1.0f : 0.0f);
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   754
                    const GLfloat fv[4] = { fb, fb, fb, fb };
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   755
                    ctx->glProgramLocalParameter4fvARB(arb_shader_type, loc, fv);
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   756
                } // for
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   757
            } // else
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   758
        } // else if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   759
    } // for
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   760
} // impl_ARB1_PushUniforms
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   761
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   762
static void impl_ARB1_PushSampler(GLint loc, GLuint sampler)
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   763
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   764
    // no-op in this profile...arb1 uses the texture units as-is.
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   765
    assert(loc == (GLint) sampler);
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   766
} // impl_ARB1_PushSampler
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   767
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   768
#endif  // SUPPORT_PROFILE_ARB1
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   769
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   770
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   771
const char *MOJOSHADER_glGetError(void)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   772
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   773
    return error_buffer;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   774
} // MOJOSHADER_glGetError
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   775
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   776
904
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   777
static void *loadsym(MOJOSHADER_glGetProcAddress lookup, void *d,
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   778
                     const char *fn, int *ext)
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   779
{
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   780
    void *retval = NULL;
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   781
    if (lookup != NULL)
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   782
    {
904
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   783
        retval = lookup(fn, d);
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   784
        if (retval == NULL)
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   785
        {
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   786
            char arbfn[64];
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   787
            snprintf(arbfn, sizeof (arbfn), "%sARB", fn);
904
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   788
            retval = lookup(arbfn, d);
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   789
        } // if
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   790
    } // if
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   791
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   792
    if (retval == NULL)
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   793
        *ext = 0;
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   794
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   795
    return retval;
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   796
} // loadsym
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   797
904
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   798
static void lookup_entry_points(MOJOSHADER_glGetProcAddress lookup, void *d)
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   799
{
363
bea8bf9e5536 Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   800
    #define DO_LOOKUP(ext, typ, fn) { \
1023
8f4d16a3b380 Cleaned up GL symbol lookup slightly.
Ryan C. Gordon <icculus@icculus.org>
parents: 906
diff changeset
   801
        ctx->fn = (typ) loadsym(lookup, d, #fn, &ctx->have_##ext); \
363
bea8bf9e5536 Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   802
    }
bea8bf9e5536 Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   803
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   804
    DO_LOOKUP(base_opengl, PFNGLGETSTRINGPROC, glGetString);
333
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   805
    DO_LOOKUP(base_opengl, PFNGLGETERRORPROC, glGetError);
276
1d7437469c94 Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   806
    DO_LOOKUP(base_opengl, PFNGLGETINTEGERVPROC, glGetIntegerv);
358
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   807
    DO_LOOKUP(base_opengl, PFNGLENABLEPROC, glEnable);
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   808
    DO_LOOKUP(base_opengl, PFNGLDISABLEPROC, glDisable);
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   809
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLDELETEOBJECTARBPROC, glDeleteObject);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   810
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLATTACHOBJECTARBPROC, glAttachObject);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   811
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLCOMPILESHADERARBPROC, glCompileShader);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   812
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLCREATEPROGRAMOBJECTARBPROC, glCreateProgramObject);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   813
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLCREATESHADEROBJECTARBPROC, glCreateShaderObject);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   814
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLGETINFOLOGARBPROC, glGetInfoLog);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   815
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLGETOBJECTPARAMETERIVARBPROC, glGetObjectParameteriv);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   816
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLGETUNIFORMLOCATIONARBPROC, glGetUniformLocation);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   817
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLLINKPROGRAMARBPROC, glLinkProgram);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   818
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLSHADERSOURCEARBPROC, glShaderSource);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   819
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLUNIFORM1IARBPROC, glUniform1i);
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   820
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLUNIFORM1IVARBPROC, glUniform1iv);
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   821
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLUNIFORM4FVARBPROC, glUniform4fv);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   822
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLUNIFORM4IVARBPROC, glUniform4iv);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   823
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLUSEPROGRAMOBJECTARBPROC, glUseProgramObject);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   824
    DO_LOOKUP(GL_ARB_vertex_shader, PFNGLDISABLEVERTEXATTRIBARRAYARBPROC, glDisableVertexAttribArray);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   825
    DO_LOOKUP(GL_ARB_vertex_shader, PFNGLENABLEVERTEXATTRIBARRAYARBPROC, glEnableVertexAttribArray);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   826
    DO_LOOKUP(GL_ARB_vertex_shader, PFNGLGETATTRIBLOCATIONARBPROC, glGetAttribLocation);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   827
    DO_LOOKUP(GL_ARB_vertex_shader, PFNGLVERTEXATTRIBPOINTERARBPROC, glVertexAttribPointer);
333
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   828
    DO_LOOKUP(GL_ARB_vertex_program, PFNGLVERTEXATTRIBPOINTERARBPROC, glVertexAttribPointer);
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   829
    DO_LOOKUP(GL_ARB_vertex_program, PFNGLGETPROGRAMIVARBPROC, glGetProgramivARB);
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   830
    DO_LOOKUP(GL_ARB_vertex_program, PFNGLGETPROGRAMSTRINGARBPROC, glGetProgramStringARB);
395
d2307cc5d6e7 Use local parameters, not environment params, in the arb1/nv2 profiles.
Ryan C. Gordon <icculus@icculus.org>
parents: 394
diff changeset
   831
    DO_LOOKUP(GL_ARB_vertex_program, PFNGLPROGRAMLOCALPARAMETER4FVARBPROC, glProgramLocalParameter4fvARB);
333
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   832
    DO_LOOKUP(GL_ARB_vertex_program, PFNGLDELETEPROGRAMSARBPROC, glDeleteProgramsARB);
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   833
    DO_LOOKUP(GL_ARB_vertex_program, PFNGLGENPROGRAMSARBPROC, glGenProgramsARB);
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   834
    DO_LOOKUP(GL_ARB_vertex_program, PFNGLBINDPROGRAMARBPROC, glBindProgramARB);
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   835
    DO_LOOKUP(GL_ARB_vertex_program, PFNGLPROGRAMSTRINGARBPROC, glProgramStringARB);
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   836
    DO_LOOKUP(GL_NV_gpu_program4, PFNGLPROGRAMLOCALPARAMETERI4IVNVPROC, glProgramLocalParameterI4ivNV);
333
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   837
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   838
    #undef DO_LOOKUP
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   839
} // lookup_entry_points
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   840
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   841
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   842
static int verify_extension(const char *ext, int have, const char *extlist,
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   843
                            int major, int minor)
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   844
{
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   845
    if (have == 0)
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   846
        return 0;  // don't bother checking, we're missing an entry point.
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   847
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   848
    else if (!ctx->have_base_opengl)
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   849
        return 0;  // don't bother checking, we're missing basic functionality.
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   850
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   851
    // See if it's in the spec for this GL implementation's version.
236
8e2fc535b210 Support for half-float attribute arrays.
Ryan C. Gordon <icculus@icculus.org>
parents: 230
diff changeset
   852
    if (major >= 0)
8e2fc535b210 Support for half-float attribute arrays.
Ryan C. Gordon <icculus@icculus.org>
parents: 230
diff changeset
   853
    {
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   854
        if ( ((ctx->opengl_major << 16) | (ctx->opengl_minor & 0xFFFF)) >=
236
8e2fc535b210 Support for half-float attribute arrays.
Ryan C. Gordon <icculus@icculus.org>
parents: 230
diff changeset
   855
             ((major << 16) | (minor & 0xFFFF)) )
8e2fc535b210 Support for half-float attribute arrays.
Ryan C. Gordon <icculus@icculus.org>
parents: 230
diff changeset
   856
            return 1;
8e2fc535b210 Support for half-float attribute arrays.
Ryan C. Gordon <icculus@icculus.org>
parents: 230
diff changeset
   857
    } // if
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   858
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   859
    // Not available in the GL version, check the extension list.
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   860
    const char *ptr = strstr(extlist, ext);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   861
    if (ptr == NULL)
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   862
        return 0;
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   863
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   864
    const char endchar = ptr[strlen(ext)];
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   865
    if ((endchar == '\0') || (endchar == ' '))
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   866
        return 1;  // extension is in the list.
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   867
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   868
    return 0;  // just not supported, fail.
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   869
} // verify_extension
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   870
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   871
407
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   872
static void parse_opengl_version_str(const char *verstr, int *maj, int *min)
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   873
{
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   874
    if (verstr == NULL)
407
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   875
        *maj = *min = 0;
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   876
    else
407
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   877
        sscanf(verstr, "%d.%d", maj, min);
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   878
} // parse_opengl_version_str
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   879
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   880
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   881
static inline void parse_opengl_version(const char *verstr)
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   882
{
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   883
    parse_opengl_version_str(verstr, &ctx->opengl_major, &ctx->opengl_minor);
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   884
} // parse_opengl_version
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   885
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   886
808
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 807
diff changeset
   887
#if SUPPORT_PROFILE_GLSL
407
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   888
static int glsl_version_atleast(int maj, int min)
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   889
{
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   890
    int glslmin = 0;
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   891
    int glslmaj = 0;
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   892
    ctx->glGetError();  // flush any existing error state.
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   893
    const GLenum enumval = GL_SHADING_LANGUAGE_VERSION_ARB;
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   894
    const char *str = (const char *) ctx->glGetString(enumval);
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   895
    if (ctx->glGetError() == GL_INVALID_ENUM)
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   896
        return 0;  // this is a basic, 1.0-compliant implementation.
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   897
    parse_opengl_version_str(str, &glslmaj, &glslmin);
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   898
    return ( (glslmaj > maj) || ((glslmaj == maj) && (glslmin >= min)) );
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   899
} // glsl_version_atleast
808
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 807
diff changeset
   900
#endif
407
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   901
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
   902
904
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   903
static void load_extensions(MOJOSHADER_glGetProcAddress lookup, void *d)
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   904
{
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   905
    const char *extlist = NULL;
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   906
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   907
    ctx->have_base_opengl = 1;
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   908
    ctx->have_GL_ARB_vertex_program = 1;
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   909
    ctx->have_GL_ARB_fragment_program = 1;
388
5930c6cd840e Fixed detection of OpenGL extensions needed by nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 363
diff changeset
   910
    ctx->have_GL_NV_vertex_program2_option = 1;
5930c6cd840e Fixed detection of OpenGL extensions needed by nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 363
diff changeset
   911
    ctx->have_GL_NV_fragment_program2 = 1;
421
bfd3d95273ec First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 420
diff changeset
   912
    ctx->have_GL_NV_vertex_program3 = 1;
432
6c59f6c0456a Fixed uninitialized variable in OpenGL glue's nv4 profile detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 431
diff changeset
   913
    ctx->have_GL_NV_gpu_program4 = 1;
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   914
    ctx->have_GL_ARB_shader_objects = 1;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   915
    ctx->have_GL_ARB_vertex_shader = 1;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   916
    ctx->have_GL_ARB_fragment_shader = 1;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   917
    ctx->have_GL_ARB_shading_language_100 = 1;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   918
    ctx->have_GL_NV_half_float = 1;
449
5a978f37e750 Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents: 448
diff changeset
   919
    ctx->have_GL_ARB_half_float_vertex = 1;
5a978f37e750 Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents: 448
diff changeset
   920
    ctx->have_GL_OES_vertex_half_float = 1;
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   921
904
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   922
    lookup_entry_points(lookup, d);
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   923
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   924
    if (!ctx->have_base_opengl)
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   925
        set_error("missing basic OpenGL entry points");
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   926
    else
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   927
    {
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   928
        parse_opengl_version((const char *) ctx->glGetString(GL_VERSION));
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   929
        extlist = (const char *) ctx->glGetString(GL_EXTENSIONS);
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   930
    } // else
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   931
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   932
    if (extlist == NULL)
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   933
        extlist = "";  // just in case.
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   934
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   935
    #define VERIFY_EXT(ext, major, minor) \
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   936
        ctx->have_##ext = verify_extension(#ext, ctx->have_##ext, extlist, major, minor)
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   937
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   938
    VERIFY_EXT(GL_ARB_vertex_program, -1, -1);
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   939
    VERIFY_EXT(GL_ARB_fragment_program, -1, -1);
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   940
    VERIFY_EXT(GL_ARB_shader_objects, 2, 0);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   941
    VERIFY_EXT(GL_ARB_vertex_shader, 2, 0);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   942
    VERIFY_EXT(GL_ARB_fragment_shader, 2, 0);
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   943
    VERIFY_EXT(GL_ARB_shading_language_100, 2, 0);
420
bfcebc3bf560 Corrected test for nv2 profile support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   944
    VERIFY_EXT(GL_NV_vertex_program2_option, -1, -1);
bfcebc3bf560 Corrected test for nv2 profile support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   945
    VERIFY_EXT(GL_NV_fragment_program2, -1, -1);
421
bfd3d95273ec First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 420
diff changeset
   946
    VERIFY_EXT(GL_NV_vertex_program3, -1, -1);
236
8e2fc535b210 Support for half-float attribute arrays.
Ryan C. Gordon <icculus@icculus.org>
parents: 230
diff changeset
   947
    VERIFY_EXT(GL_NV_half_float, -1, -1);
449
5a978f37e750 Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents: 448
diff changeset
   948
    VERIFY_EXT(GL_ARB_half_float_vertex, 3, 0);
5a978f37e750 Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents: 448
diff changeset
   949
    VERIFY_EXT(GL_OES_vertex_half_float, -1, -1);
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   950
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   951
    #undef VERIFY_EXT
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   952
} // load_extensions
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   953
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   954
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   955
static int valid_profile(const char *profile)
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   956
{
808
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 807
diff changeset
   957
#if SUPPORT_PROFILE_GLSL
457
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   958
    // If running on Mac OS X <= 10.4, don't ever pick GLSL, even if
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   959
    //  the system claims it is available.
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   960
    #if PLATFORM_MACOSX
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   961
    const int allow_glsl = macosx_version_atleast(10, 5, 0);
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   962
    #else
501
314aa5c32820 Fixed wrong value for allow_glsl on non-Mac platforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   963
    const int allow_glsl = 1;
457
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   964
    #endif
808
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 807
diff changeset
   965
#endif
457
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   966
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   967
    if (!ctx->have_base_opengl)
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   968
        return 0;
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   969
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   970
    #define MUST_HAVE(p, x) \
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   971
        if (!ctx->have_##x) { set_error(#p " profile needs " #x); return 0; }
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   972
291
2453590bae1b Fix/disable annoying Visual C++ level 4 warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 285
diff changeset
   973
    if (profile == NULL)
2453590bae1b Fix/disable annoying Visual C++ level 4 warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 285
diff changeset
   974
    {
2453590bae1b Fix/disable annoying Visual C++ level 4 warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 285
diff changeset
   975
        set_error("NULL profile");
2453590bae1b Fix/disable annoying Visual C++ level 4 warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 285
diff changeset
   976
        return 0;
2453590bae1b Fix/disable annoying Visual C++ level 4 warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 285
diff changeset
   977
    } // if
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   978
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   979
    #if SUPPORT_PROFILE_ARB1
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   980
    else if (strcmp(profile, MOJOSHADER_PROFILE_ARB1) == 0)
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   981
    {
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   982
        MUST_HAVE(MOJOSHADER_PROFILE_ARB1, GL_ARB_vertex_program);
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   983
        MUST_HAVE(MOJOSHADER_PROFILE_ARB1, GL_ARB_fragment_program);
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   984
    } // else if
808
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 807
diff changeset
   985
    #endif
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   986
808
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 807
diff changeset
   987
    #if SUPPORT_PROFILE_ARB1_NV
361
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 359
diff changeset
   988
    else if (strcmp(profile, MOJOSHADER_PROFILE_NV2) == 0)
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 359
diff changeset
   989
    {
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 359
diff changeset
   990
        MUST_HAVE(MOJOSHADER_PROFILE_NV2, GL_ARB_vertex_program);
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 359
diff changeset
   991
        MUST_HAVE(MOJOSHADER_PROFILE_NV2, GL_ARB_fragment_program);
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 359
diff changeset
   992
        MUST_HAVE(MOJOSHADER_PROFILE_NV2, GL_NV_vertex_program2_option);
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 359
diff changeset
   993
        MUST_HAVE(MOJOSHADER_PROFILE_NV2, GL_NV_fragment_program2);
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 359
diff changeset
   994
    } // else if
421
bfd3d95273ec First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 420
diff changeset
   995
bfd3d95273ec First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 420
diff changeset
   996
    else if (strcmp(profile, MOJOSHADER_PROFILE_NV3) == 0)
bfd3d95273ec First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 420
diff changeset
   997
    {
bfd3d95273ec First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 420
diff changeset
   998
        MUST_HAVE(MOJOSHADER_PROFILE_NV3, GL_ARB_vertex_program);
bfd3d95273ec First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 420
diff changeset
   999
        MUST_HAVE(MOJOSHADER_PROFILE_NV3, GL_ARB_fragment_program);
bfd3d95273ec First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 420
diff changeset
  1000
        MUST_HAVE(MOJOSHADER_PROFILE_NV3, GL_NV_vertex_program3);
bfd3d95273ec First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 420
diff changeset
  1001
        MUST_HAVE(MOJOSHADER_PROFILE_NV3, GL_NV_fragment_program2);
bfd3d95273ec First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 420
diff changeset
  1002
    } // else if
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
  1003
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
  1004
    else if (strcmp(profile, MOJOSHADER_PROFILE_NV4) == 0)
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
  1005
    {
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
  1006
        MUST_HAVE(MOJOSHADER_PROFILE_NV4, GL_NV_gpu_program4);
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
  1007
    } // else if
361
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 359
diff changeset
  1008
    #endif
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 359
diff changeset
  1009
808
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 807
diff changeset
  1010
    #if SUPPORT_PROFILE_GLSL120
457
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
  1011
    else if ((allow_glsl) && (strcmp(profile, MOJOSHADER_PROFILE_GLSL120) == 0))
407
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
  1012
    {
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
  1013
        MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_shader_objects);
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
  1014
        MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_vertex_shader);
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
  1015
        MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_fragment_shader);
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
  1016
        MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_shading_language_100);
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
  1017
        // if you got here, you have all the extensions.
413
618b677f4581 Fixed glsl120 profile test in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 411
diff changeset
  1018
        if (!glsl_version_atleast(1, 20))
407
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
  1019
            return 0;
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
  1020
    } // else if
808
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 807
diff changeset
  1021
    #endif
407
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
  1022
808
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 807
diff changeset
  1023
    #if SUPPORT_PROFILE_GLSL
457
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
  1024
    else if ((allow_glsl) && (strcmp(profile, MOJOSHADER_PROFILE_GLSL) == 0))
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
  1025
    {
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1026
        MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_shader_objects);
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1027
        MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_vertex_shader);
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1028
        MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_fragment_shader);
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1029
        MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_shading_language_100);
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1030
    } // else if
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1031
    #endif
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
  1032
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
  1033
    else
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
  1034
    {
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1035
        set_error("unknown or unsupported profile");
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
  1036
        return 0;
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
  1037
    } // else
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
  1038
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1039
    #undef MUST_HAVE
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
  1040
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
  1041
    return 1;
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1042
} // valid_profile
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
  1043
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
  1044
422
1d5eaf3a4c98 Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents: 421
diff changeset
  1045
static const char *profile_priorities[] = {
808
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 807
diff changeset
  1046
#if SUPPORT_PROFILE_GLSL120
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 807
diff changeset
  1047
    MOJOSHADER_PROFILE_GLSL120,
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 807
diff changeset
  1048
#endif
422
1d5eaf3a4c98 Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents: 421
diff changeset
  1049
#if SUPPORT_PROFILE_GLSL
1d5eaf3a4c98 Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents: 421
diff changeset
  1050
    MOJOSHADER_PROFILE_GLSL,
1d5eaf3a4c98 Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents: 421
diff changeset
  1051
#endif
808
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 807
diff changeset
  1052
#if SUPPORT_PROFILE_ARB1_NV
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
  1053
    MOJOSHADER_PROFILE_NV4,
422
1d5eaf3a4c98 Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents: 421
diff changeset
  1054
    MOJOSHADER_PROFILE_NV3,
1d5eaf3a4c98 Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents: 421
diff changeset
  1055
    MOJOSHADER_PROFILE_NV2,
808
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 807
diff changeset
  1056
#endif
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 807
diff changeset
  1057
#if SUPPORT_PROFILE_ARB1
422
1d5eaf3a4c98 Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents: 421
diff changeset
  1058
    MOJOSHADER_PROFILE_ARB1,
1d5eaf3a4c98 Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents: 421
diff changeset
  1059
#endif
1d5eaf3a4c98 Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents: 421
diff changeset
  1060
};
1d5eaf3a4c98 Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents: 421
diff changeset
  1061
904
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
  1062
int MOJOSHADER_glAvailableProfiles(MOJOSHADER_glGetProcAddress lookup, void *d,
422
1d5eaf3a4c98 Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents: 421
diff changeset
  1063
                                   const char **profs, const int size)
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1064
{
422
1d5eaf3a4c98 Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents: 421
diff changeset
  1065
    int retval = 0;
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1066
    MOJOSHADER_glContext _ctx;
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1067
    MOJOSHADER_glContext *current_ctx = ctx;
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1068
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1069
    ctx = &_ctx;
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1070
    memset(ctx, '\0', sizeof (MOJOSHADER_glContext));
904
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
  1071
    load_extensions(lookup, d);
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1072
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1073
    if (ctx->have_base_opengl)
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1074
    {
798
5dd67cc04cf9 Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 797
diff changeset
  1075
        size_t i;
422
1d5eaf3a4c98 Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents: 421
diff changeset
  1076
        for (i = 0; i < STATICARRAYLEN(profile_priorities); i++)
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1077
        {
422
1d5eaf3a4c98 Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents: 421
diff changeset
  1078
            const char *profile = profile_priorities[i];
1d5eaf3a4c98 Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents: 421
diff changeset
  1079
            if (valid_profile(profile))
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1080
            {
422
1d5eaf3a4c98 Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents: 421
diff changeset
  1081
                if (retval < size)
1d5eaf3a4c98 Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents: 421
diff changeset
  1082
                    profs[retval] = profile;
1d5eaf3a4c98 Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents: 421
diff changeset
  1083
                retval++;
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1084
            } // if