mojoshader_opengl.c
author Ryan C. Gordon <icculus@icculus.org>
Wed, 10 Oct 2012 22:47:27 -0400
changeset 1118 c383aebc9f13
parent 1117 f6712bf72c19
child 1124 464fc9101a7e
permissions -rw-r--r--
Whoops, dropped last extension from the list in legacy GL extension codepath.
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
1073
6eccf031c7e6 Cleaned up half-float stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 1072
diff changeset
    40
#ifndef GL_HALF_FLOAT_NV
6eccf031c7e6 Cleaned up half-float stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 1072
diff changeset
    41
#define GL_HALF_FLOAT_NV 0x140B
6eccf031c7e6 Cleaned up half-float stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 1072
diff changeset
    42
#endif
6eccf031c7e6 Cleaned up half-float stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 1072
diff changeset
    43
6eccf031c7e6 Cleaned up half-float stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 1072
diff changeset
    44
#ifndef GL_HALF_FLOAT_ARB
6eccf031c7e6 Cleaned up half-float stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 1072
diff changeset
    45
#define GL_HALF_FLOAT_ARB 0x140B
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
    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
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
    48
#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
    49
#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
    50
#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
    51
1056
73c697a7e950 Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
    52
// 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
    53
#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
    54
#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
    55
#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
    56
202
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
struct MOJOSHADER_glShader
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
    const MOJOSHADER_parseData *parseData;
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
    60
    GLuint handle;
202
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
    uint32 refcount;
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
};
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
205
8583f89985df Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 204
diff changeset
    64
typedef struct
8583f89985df Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 204
diff changeset
    65
{
206
7027d889acdd Implemented MOJOSHADER_glProgramReady().
Ryan C. Gordon <icculus@icculus.org>
parents: 205
diff changeset
    66
    MOJOSHADER_shaderType shader_type;
226
4a2b3d0b535f Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
    67
    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
    68
    GLint location;
205
8583f89985df Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 204
diff changeset
    69
} UniformMap;
8583f89985df Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 204
diff changeset
    70
213
73935330a973 Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 212
diff changeset
    71
typedef struct
73935330a973 Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 212
diff changeset
    72
{
226
4a2b3d0b535f Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
    73
    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
    74
    GLint location;
213
73935330a973 Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 212
diff changeset
    75
} AttributeMap;
73935330a973 Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 212
diff changeset
    76
202
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
struct MOJOSHADER_glProgram
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
{
226
4a2b3d0b535f Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
    79
    MOJOSHADER_glShader *vertex;
4a2b3d0b535f Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
    80
    MOJOSHADER_glShader *fragment;
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
    81
    GLuint handle;
774
9ac0e5ad0205 Don't push uniforms if they've definitely not changed.
Ryan C. Gordon <icculus@icculus.org>
parents: 773
diff changeset
    82
    uint32 generation;
205
8583f89985df Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 204
diff changeset
    83
    uint32 uniform_count;
1090
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
    84
    uint32 texbem_count;
226
4a2b3d0b535f Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
    85
    UniformMap *uniforms;
213
73935330a973 Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents: 212
diff changeset
    86
    uint32 attribute_count;
226
4a2b3d0b535f Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents: 223
diff changeset
    87
    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
    88
    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
    89
    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
    90
    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
    91
    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
    92
    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
    93
    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
    94
    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
    95
    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
    96
    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
    97
    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
    98
    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
    99
    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
   100
6227066350b4 Preshader input registers are separate from the actual shader constant file!
Ryan C. Gordon <icculus@icculus.org>
parents: 1040
diff changeset
   101
    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
   102
    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
   103
    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
   104
    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
   105
202
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
    uint32 refcount;
1056
73c697a7e950 Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   107
73c697a7e950 Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   108
    int uses_pointsize;
73c697a7e950 Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   109
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   110
    // 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
   111
    GLint vs_float4_loc;
58d15db2881e GLSL Uniform locations are signed ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 791
diff changeset
   112
    GLint vs_int4_loc;
58d15db2881e GLSL Uniform locations are signed ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 791
diff changeset
   113
    GLint vs_bool_loc;
58d15db2881e GLSL Uniform locations are signed ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 791
diff changeset
   114
    GLint ps_float4_loc;
58d15db2881e GLSL Uniform locations are signed ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 791
diff changeset
   115
    GLint ps_int4_loc;
58d15db2881e GLSL Uniform locations are signed ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 791
diff changeset
   116
    GLint ps_bool_loc;
202
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
};
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
277
49a6571cac6d Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   119
#ifndef WINGDIAPI
49a6571cac6d Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   120
#define WINGDIAPI
49a6571cac6d Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   121
#endif
49a6571cac6d Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   122
242
c3c5693ba179 Fixed vertex attribute aliasing in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 241
diff changeset
   123
// 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
   124
typedef WINGDIAPI void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params);
1d7437469c94 Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   125
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
   126
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
   127
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
   128
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
   129
773
3e3638be6e2b Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents: 772
diff changeset
   130
// Max entries for each register file type...
3e3638be6e2b Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents: 772
diff changeset
   131
#define MAX_REG_FILE_F 8192
3e3638be6e2b Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents: 772
diff changeset
   132
#define MAX_REG_FILE_I 2047
3e3638be6e2b Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents: 772
diff changeset
   133
#define MAX_REG_FILE_B 2047
1090
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   134
#define MAX_TEXBEMS 3  // ps_1_1 allows 4 texture stages, texbem can't use t0.
773
3e3638be6e2b Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents: 772
diff changeset
   135
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   136
struct MOJOSHADER_glContext
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   137
{
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   138
    // Allocators...
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   139
    MOJOSHADER_malloc malloc_fn;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   140
    MOJOSHADER_free free_fn;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   141
    void *malloc_data;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   142
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   143
    // The constant register files...
806
facbf9d3f1ce Added a FIXME.
Ryan C. Gordon <icculus@icculus.org>
parents: 798
diff changeset
   144
    // !!! FIXME: Man, it kills me how much memory this takes...
facbf9d3f1ce Added a FIXME.
Ryan C. Gordon <icculus@icculus.org>
parents: 798
diff changeset
   145
    // !!! FIXME:  ... make this dynamically allocated on demand.
773
3e3638be6e2b Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents: 772
diff changeset
   146
    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
   147
    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
   148
    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
   149
    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
   150
    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
   151
    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
   152
    GLuint sampler_reg_file[16];
1090
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   153
    GLfloat texbem_state[MAX_TEXBEMS * 6];
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   154
774
9ac0e5ad0205 Don't push uniforms if they've definitely not changed.
Ryan C. Gordon <icculus@icculus.org>
parents: 773
diff changeset
   155
    // 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
   156
    uint32 generation;
9ac0e5ad0205 Don't push uniforms if they've definitely not changed.
Ryan C. Gordon <icculus@icculus.org>
parents: 773
diff changeset
   157
1066
ff14db741834 Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   158
    // This keeps track of implicitly linked programs.
ff14db741834 Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   159
    HashTable *linker_cache;
ff14db741834 Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   160
775
2c93dcb14687 Only enable/disable vertex arrays when forced to.
Ryan C. Gordon <icculus@icculus.org>
parents: 774
diff changeset
   161
    // 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
   162
    GLint max_attrs;
775
2c93dcb14687 Only enable/disable vertex arrays when forced to.
Ryan C. Gordon <icculus@icculus.org>
parents: 774
diff changeset
   163
    uint8 want_attr[32];
2c93dcb14687 Only enable/disable vertex arrays when forced to.
Ryan C. Gordon <icculus@icculus.org>
parents: 774
diff changeset
   164
    uint8 have_attr[32];
2c93dcb14687 Only enable/disable vertex arrays when forced to.
Ryan C. Gordon <icculus@icculus.org>
parents: 774
diff changeset
   165
1056
73c697a7e950 Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   166
    // 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
   167
    int pointsize_enabled;
73c697a7e950 Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   168
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   169
    // GL stuff...
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   170
    int opengl_major;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   171
    int opengl_minor;
1070
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
   172
    int glsl_major;
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
   173
    int glsl_minor;
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   174
    MOJOSHADER_glProgram *bound_program;
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   175
    char profile[16];
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   176
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   177
    // Extensions...
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   178
    int have_core_opengl;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   179
    int have_opengl_2;  // different entry points than ARB extensions.
1117
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
   180
    int have_opengl_3;  // different extension query.
463
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   181
    int have_GL_ARB_vertex_program;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   182
    int have_GL_ARB_fragment_program;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   183
    int have_GL_NV_vertex_program2_option;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   184
    int have_GL_NV_fragment_program2;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   185
    int have_GL_NV_vertex_program3;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   186
    int have_GL_NV_gpu_program4;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   187
    int have_GL_ARB_shader_objects;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   188
    int have_GL_ARB_vertex_shader;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   189
    int have_GL_ARB_fragment_shader;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   190
    int have_GL_ARB_shading_language_100;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   191
    int have_GL_NV_half_float;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   192
    int have_GL_ARB_half_float_vertex;
6f3a82d7e3d2 Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents: 460
diff changeset
   193
    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
   194
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   195
    // Entry points...
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   196
    PFNGLGETSTRINGPROC glGetString;
1117
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
   197
    PFNGLGETSTRINGIPROC glGetStringi;
333
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   198
    PFNGLGETERRORPROC glGetError;
276
1d7437469c94 Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   199
    PFNGLGETINTEGERVPROC glGetIntegerv;
358
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   200
    PFNGLENABLEPROC glEnable;
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   201
    PFNGLDISABLEPROC glDisable;
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   202
    PFNGLDELETESHADERPROC glDeleteShader;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   203
    PFNGLDELETEPROGRAMPROC glDeleteProgram;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   204
    PFNGLATTACHSHADERPROC glAttachShader;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   205
    PFNGLCOMPILESHADERPROC glCompileShader;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   206
    PFNGLCREATESHADERPROC glCreateShader;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   207
    PFNGLCREATEPROGRAMPROC glCreateProgram;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   208
    PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   209
    PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   210
    PFNGLGETATTRIBLOCATIONPROC glGetAttribLocation;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   211
    PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   212
    PFNGLGETSHADERIVPROC glGetShaderiv;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   213
    PFNGLGETPROGRAMIVPROC glGetProgramiv;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   214
    PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   215
    PFNGLLINKPROGRAMPROC glLinkProgram;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   216
    PFNGLSHADERSOURCEPROC glShaderSource;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   217
    PFNGLUNIFORM1IPROC glUniform1i;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   218
    PFNGLUNIFORM1IVPROC glUniform1iv;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   219
    PFNGLUNIFORM4FVPROC glUniform4fv;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   220
    PFNGLUNIFORM4IVPROC glUniform4iv;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   221
    PFNGLUSEPROGRAMPROC glUseProgram;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   222
    PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   223
    PFNGLDELETEOBJECTARBPROC glDeleteObjectARB;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   224
    PFNGLATTACHOBJECTARBPROC glAttachObjectARB;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   225
    PFNGLCOMPILESHADERARBPROC glCompileShaderARB;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   226
    PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   227
    PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   228
    PFNGLDISABLEVERTEXATTRIBARRAYARBPROC glDisableVertexAttribArrayARB;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   229
    PFNGLENABLEVERTEXATTRIBARRAYARBPROC glEnableVertexAttribArrayARB;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   230
    PFNGLGETATTRIBLOCATIONARBPROC glGetAttribLocationARB;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   231
    PFNGLGETINFOLOGARBPROC glGetInfoLogARB;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   232
    PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   233
    PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   234
    PFNGLLINKPROGRAMARBPROC glLinkProgramARB;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   235
    PFNGLSHADERSOURCEARBPROC glShaderSourceARB;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   236
    PFNGLUNIFORM1IARBPROC glUniform1iARB;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   237
    PFNGLUNIFORM1IVARBPROC glUniform1ivARB;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   238
    PFNGLUNIFORM4FVARBPROC glUniform4fvARB;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   239
    PFNGLUNIFORM4IVARBPROC glUniform4ivARB;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   240
    PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   241
    PFNGLVERTEXATTRIBPOINTERARBPROC glVertexAttribPointerARB;
333
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   242
    PFNGLGETPROGRAMIVARBPROC glGetProgramivARB;
395
d2307cc5d6e7 Use local parameters, not environment params, in the arb1/nv2 profiles.
Ryan C. Gordon <icculus@icculus.org>
parents: 394
diff changeset
   243
    PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB;
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   244
    PFNGLPROGRAMLOCALPARAMETERI4IVNVPROC glProgramLocalParameterI4ivNV;
333
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   245
    PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB;
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   246
    PFNGLGENPROGRAMSARBPROC glGenProgramsARB;
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   247
    PFNGLBINDPROGRAMARBPROC glBindProgramARB;
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   248
    PFNGLPROGRAMSTRINGARBPROC glProgramStringARB;
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   249
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   250
    // interface for profile-specific things.
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   251
    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
   252
    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
   253
    void (*profileDeleteShader)(const GLuint shader);
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   254
    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
   255
    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
   256
    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
   257
    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
   258
    GLuint (*profileLinkProgram)(MOJOSHADER_glShader *, MOJOSHADER_glShader *);
765
076f3bd42329 Moved profileInitProgram to profileFinalInitProgram.
Ryan C. Gordon <icculus@icculus.org>
parents: 764
diff changeset
   259
    void (*profileFinalInitProgram)(MOJOSHADER_glProgram *program);
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   260
    void (*profileUseProgram)(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
   261
    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
   262
    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
   263
    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
   264
    int (*profileMustPushConstantArrays)(void);
6dc8d2cafc58 "Must Push" seemed more correct than "Must Load".
Ryan C. Gordon <icculus@icculus.org>
parents: 759
diff changeset
   265
    int (*profileMustPushSamplers)(void);
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   266
};
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   267
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
   268
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   269
static MOJOSHADER_glContext *ctx = NULL;
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   270
219
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
   271
// Error state...
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
   272
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
   273
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
   274
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
   275
{
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
   276
    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
   277
} // set_error
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 216
diff changeset
   278
457
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   279
#if PLATFORM_MACOSX
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   280
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
   281
{
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   282
    static int checked = 0;
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   283
    static int combined = 0;
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   284
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   285
    if (!checked)
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   286
    {
807
138d76f766d1 Fixed compiler warnings on 64-bit Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 806
diff changeset
   287
        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
   288
        int convert = 0;
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   289
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   290
        if (Gestalt(gestaltSystemVersion, &ver) != noErr)
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   291
            ver = 0x1000;  // oh well.
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   292
        else if (ver < 0x1030)
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   293
            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
   294
        else
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   295
        {
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   296
            // 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
   297
            //  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
   298
            //  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
   299
            if (Gestalt(gestaltSystemVersionMajor, &major) != noErr)
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   300
                convert = 1;
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   301
            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
   302
                convert = 1;
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   303
            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
   304
                convert = 1;
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   305
        } // else
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   306
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   307
        if (convert)
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   308
        {
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   309
            major = ((ver & 0xFF00) >> 8);
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   310
            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
   311
            minor = ((ver & 0xF0) >> 4);
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   312
            patch = (ver & 0xF);
533
177b9242d08a Fixed a comment.
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   313
        } // if
457
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   314
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   315
        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
   316
        checked = 1;
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   317
    } // if
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   318
460
54c614f0fcb0 Fixed OS X detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 459
diff changeset
   319
    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
   320
} // macosx_version_atleast
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   321
#endif
96552d8041bf Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   322
1066
ff14db741834 Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   323
static inline void out_of_memory(void)
ff14db741834 Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   324
{
ff14db741834 Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   325
    set_error("out of memory");
ff14db741834 Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   326
} // out_of_memory
202
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
static inline void *Malloc(const size_t len)
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
{
307
42f6a7ba69e2 Fixes for Visual Studio level 4 compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 291
diff changeset
   330
    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
   331
    if (retval == NULL)
1066
ff14db741834 Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   332
        out_of_memory();
220
df5ea69833d5 Fixes to Malloc() and Free() in mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
   333
    return retval;
202
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
} // Malloc
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
static inline void Free(void *ptr)
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
{
220
df5ea69833d5 Fixes to Malloc() and Free() in mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
   338
    if (ptr != NULL)
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   339
        ctx->free_fn(ptr, ctx->malloc_data);
202
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
} // Free
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
20bdf2d7036e Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
358
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   343
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
   344
{
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   345
    if (val)
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   346
        ctx->glEnable(state);
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   347
    else
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   348
        ctx->glDisable(state);
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   349
} // toggle_gl_state
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   350
f63e18cf642f Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 355
diff changeset
   351
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   352
// profile-specific implementations...
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
#if SUPPORT_PROFILE_GLSL
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   355
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
   356
{
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   357
    // these enums match between core 2.0 and the ARB extensions.
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   358
    if (t == MOJOSHADER_TYPE_VERTEX)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   359
        return GL_VERTEX_SHADER;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   360
    else if (t == MOJOSHADER_TYPE_PIXEL)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   361
        return GL_FRAGMENT_SHADER;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   362
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   363
    // !!! FIXME: geometry shaders?
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   364
    return GL_NONE;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   365
} // glsl_shader_type
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
760
6dc8d2cafc58 "Must Push" seemed more correct than "Must Load".
Ryan C. Gordon <icculus@icculus.org>
parents: 759
diff changeset
   368
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
   369
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
   370
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   371
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
   372
{
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   373
    // these enums match between core 2.0 and the ARB extensions.
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   374
    GLenum pname = GL_NONE;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   375
    GLint val = 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   376
    if (shader_type == MOJOSHADER_TYPE_VERTEX)
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   377
        pname = GL_MAX_VERTEX_UNIFORM_COMPONENTS;
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   378
    else if (shader_type == MOJOSHADER_TYPE_PIXEL)
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   379
        pname = GL_MAX_FRAGMENT_UNIFORM_COMPONENTS;
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   380
    else
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   381
        return -1;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   382
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   383
    ctx->glGetIntegerv(pname, &val);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   384
    return (int) val;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   385
} // impl_GLSL_MaxUniforms
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
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   388
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
   389
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   390
    GLint ok = 0;
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   391
    const GLint codelen = (GLint) pd->output_len;
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   392
    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
   393
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   394
    if (ctx->have_opengl_2)
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   395
    {
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   396
        const GLuint shader = ctx->glCreateShader(shader_type);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   397
        ctx->glShaderSource(shader, 1, (const GLchar**) &pd->output, &codelen);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   398
        ctx->glCompileShader(shader);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   399
        ctx->glGetShaderiv(shader, GL_COMPILE_STATUS, &ok);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   400
        if (!ok)
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   401
        {
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   402
            GLsizei len = 0;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   403
            ctx->glGetInfoLogARB(shader, sizeof (error_buffer), &len,
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   404
                                 (GLchar *) error_buffer);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   405
            *s = 0;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   406
            return 0;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   407
        } // if
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   408
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   409
        *s = shader;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   410
    } // if
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   411
    else
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   412
    {
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   413
        const GLhandleARB shader = ctx->glCreateShaderObjectARB(shader_type);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   414
        assert(sizeof (shader) == sizeof (*s));  // not always true on OS X!
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   415
        ctx->glShaderSourceARB(shader, 1,
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   416
                              (const GLcharARB **) &pd->output, &codelen);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   417
        ctx->glCompileShaderARB(shader);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   418
        ctx->glGetObjectParameterivARB(shader,GL_OBJECT_COMPILE_STATUS_ARB,&ok);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   419
        if (!ok)
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   420
        {
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   421
            GLsizei len = 0;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   422
            ctx->glGetInfoLogARB(shader, sizeof (error_buffer), &len,
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   423
                                 (GLcharARB *) error_buffer);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   424
            *s = 0;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   425
            return 0;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   426
        } // if
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   427
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   428
        *s = (GLuint) shader;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   429
    } // else
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   430
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   431
    return 1;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   432
} // impl_GLSL_CompileShader
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
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   435
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
   436
{
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   437
    if (ctx->have_opengl_2)
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   438
        ctx->glDeleteShader(shader);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   439
    else
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   440
        ctx->glDeleteObjectARB((GLhandleARB) shader);
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   441
} // impl_GLSL_DeleteShader
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   442
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   443
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   444
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
   445
{
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   446
    if (ctx->have_opengl_2)
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   447
        ctx->glDeleteProgram(program);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   448
    else
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   449
        ctx->glDeleteObjectARB((GLhandleARB) program);
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   450
} // impl_GLSL_DeleteProgram
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   451
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   452
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   453
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
   454
                                          MOJOSHADER_glShader *shader, int idx)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   455
{
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   456
    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
   457
} // impl_GLSL_GetUniformLocation
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   458
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   459
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   460
static inline GLint glsl_uniform_loc(MOJOSHADER_glProgram *program,
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   461
                                          const char *name)
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   462
{
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   463
    return ctx->have_opengl_2 ?
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   464
        ctx->glGetUniformLocation(program->handle, name) :
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   465
        ctx->glGetUniformLocationARB((GLhandleARB) program->handle, name);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   466
} // glsl_uniform_loc
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   467
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   468
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   469
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
   470
                                          MOJOSHADER_glShader *shader, int idx)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   471
{
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   472
    return glsl_uniform_loc(program, shader->parseData->samplers[idx].name);
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   473
} // impl_GLSL_GetSamplerLocation
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   474
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   475
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   476
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
   477
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   478
    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
   479
    const MOJOSHADER_attribute *a = pd->attributes;
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   480
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   481
    if (ctx->have_opengl_2)
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   482
    {
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   483
        return ctx->glGetAttribLocation(program->handle,
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   484
                                        (const GLchar *) a[idx].name);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   485
    } // if
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   486
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   487
    return ctx->glGetAttribLocationARB((GLhandleARB) program->handle,
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   488
                                        (const GLcharARB *) a[idx].name);
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   489
} // impl_GLSL_GetAttribLocation
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   490
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   491
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   492
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
   493
                                    MOJOSHADER_glShader *pshader)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   494
{
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   495
    GLint ok = 0;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   496
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   497
    if (ctx->have_opengl_2)
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   498
    {
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   499
        const GLuint program = ctx->glCreateProgram();
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   500
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   501
        if (vshader != NULL) ctx->glAttachShader(program, vshader->handle);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   502
        if (pshader != NULL) ctx->glAttachShader(program, pshader->handle);
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   503
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   504
        ctx->glLinkProgram(program);
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   505
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   506
        ctx->glGetProgramiv(program, GL_LINK_STATUS, &ok);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   507
        if (!ok)
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   508
        {
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   509
            GLsizei len = 0;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   510
            ctx->glGetProgramInfoLog(program, sizeof (error_buffer),
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   511
                                     &len, (GLchar *) error_buffer);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   512
            ctx->glDeleteProgram(program);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   513
            return 0;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   514
        } // if
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   515
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   516
        return program;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   517
    } // if
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   518
    else
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   519
    {
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   520
        const GLhandleARB program = ctx->glCreateProgramObjectARB();
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   521
        assert(sizeof(program) == sizeof(GLuint));  // not always true on OS X!
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   522
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   523
        if (vshader != NULL)
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   524
            ctx->glAttachObjectARB(program, (GLhandleARB) vshader->handle);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   525
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   526
        if (pshader != NULL)
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   527
            ctx->glAttachObjectARB(program, (GLhandleARB) pshader->handle);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   528
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   529
        ctx->glLinkProgramARB(program);
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   530
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   531
        ctx->glGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB, &ok);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   532
        if (!ok)
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   533
        {
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   534
            GLsizei len = 0;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   535
            ctx->glGetInfoLogARB(program, sizeof (error_buffer),
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   536
                                 &len, (GLcharARB *) error_buffer);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   537
            ctx->glDeleteObjectARB(program);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   538
            return 0;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   539
        } // if
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   540
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   541
        return (GLuint) program;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   542
    } // else
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   543
} // impl_GLSL_LinkProgram
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   544
765
076f3bd42329 Moved profileInitProgram to profileFinalInitProgram.
Ryan C. Gordon <icculus@icculus.org>
parents: 764
diff changeset
   545
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
   546
{
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   547
    
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   548
    program->vs_float4_loc = glsl_uniform_loc(program, "vs_uniforms_vec4");
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   549
    program->vs_int4_loc = glsl_uniform_loc(program, "vs_uniforms_ivec4");
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   550
    program->vs_bool_loc = glsl_uniform_loc(program, "vs_uniforms_bool");
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   551
    program->ps_float4_loc = glsl_uniform_loc(program, "ps_uniforms_vec4");
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   552
    program->ps_int4_loc = glsl_uniform_loc(program, "ps_uniforms_ivec4");
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   553
    program->ps_bool_loc = glsl_uniform_loc(program, "ps_uniforms_bool");
765
076f3bd42329 Moved profileInitProgram to profileFinalInitProgram.
Ryan C. Gordon <icculus@icculus.org>
parents: 764
diff changeset
   554
} // 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
   555
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   556
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   557
static void impl_GLSL_UseProgram(MOJOSHADER_glProgram *program)
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   558
{
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   559
    if (ctx->have_opengl_2)
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   560
        ctx->glUseProgram(program ? program->handle : 0);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   561
    else
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   562
        ctx->glUseProgramObjectARB((GLhandleARB) (program ? program->handle : 0));
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   563
} // impl_GLSL_UseProgram
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   564
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   565
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   566
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
   567
                                        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
   568
                                        const GLfloat *f)
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   569
{
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   570
    const GLint loc = glsl_uniform_loc(program, 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
   571
    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
   572
        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
   573
} // impl_GLSL_PushConstantArray
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   574
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   575
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   576
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
   577
{
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   578
    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
   579
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   580
    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
   581
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   582
    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
   583
    {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   584
        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
   585
                          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
   586
                          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
   587
    } // if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   588
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   589
    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
   590
    {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   591
        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
   592
                          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
   593
                          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
   594
    } // if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   595
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   596
    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
   597
    {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   598
        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
   599
                          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
   600
                          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
   601
    } // if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   602
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   603
    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
   604
    {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   605
        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
   606
                          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
   607
                          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
   608
    } // if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   609
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   610
    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
   611
    {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   612
        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
   613
                          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
   614
                          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
   615
    } // if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   616
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   617
    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
   618
    {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   619
        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
   620
                          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
   621
                          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
   622
    } // if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   623
} // impl_GLSL_PushUniforms
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   624
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   625
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   626
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
   627
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   628
    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
   629
} // impl_GLSL_PushSampler
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   630
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   631
#endif  // SUPPORT_PROFILE_GLSL
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   632
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   633
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   634
#if SUPPORT_PROFILE_ARB1
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   635
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
   636
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   637
    if (t == MOJOSHADER_TYPE_VERTEX)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   638
        return GL_VERTEX_PROGRAM_ARB;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   639
    else if (t == MOJOSHADER_TYPE_PIXEL)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   640
        return GL_FRAGMENT_PROGRAM_ARB;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   641
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   642
    // !!! FIXME: geometry shaders?
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   643
    return GL_NONE;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   644
} // arb1_shader_type
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   645
760
6dc8d2cafc58 "Must Push" seemed more correct than "Must Load".
Ryan C. Gordon <icculus@icculus.org>
parents: 759
diff changeset
   646
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
   647
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
   648
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   649
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
   650
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   651
    GLint retval = 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   652
    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
   653
    if (program_type == GL_NONE)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   654
        return -1;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   655
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   656
    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
   657
    return (int) retval;  // !!! FIXME: times four?
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   658
} // impl_ARB1_MaxUniforms
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
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   661
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
   662
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   663
    GLint shaderlen = (GLint) pd->output_len;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   664
    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
   665
    GLuint shader = 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   666
    ctx->glGenProgramsARB(1, &shader);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   667
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   668
    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
   669
    ctx->glBindProgramARB(shader_type, shader);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   670
    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
   671
                                shaderlen, pd->output);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   672
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   673
    if (ctx->glGetError() == GL_INVALID_OPERATION)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   674
    { 
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   675
        GLint pos = 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   676
        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
   677
        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
   678
        snprintf(error_buffer, sizeof (error_buffer),
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   679
                  "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
   680
                  (int) pos, (const char *) errstr);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   681
        ctx->glBindProgramARB(shader_type, 0);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   682
        ctx->glDeleteProgramsARB(1, &shader);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   683
        *s = 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   684
        return 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   685
    } // if
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   686
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   687
    *s = shader;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   688
    return 1;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   689
} // impl_ARB1_CompileShader
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   690
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   691
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   692
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
   693
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   694
    GLuint shader = _shader;  // const removal.
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   695
    ctx->glDeleteProgramsARB(1, &shader);
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   696
} // impl_ARB1_DeleteShader
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   697
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   698
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   699
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
   700
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   701
    // 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
   702
} // impl_GLSL_DeleteProgram
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   703
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   704
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
   705
                                          MOJOSHADER_glShader *shader, int idx)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   706
{
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   707
    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
   708
} // impl_ARB1_GetUniformLocation
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   709
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   710
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
   711
                                          MOJOSHADER_glShader *shader, int idx)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   712
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   713
    return shader->parseData->samplers[idx].index;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   714
} // impl_ARB1_GetSamplerLocation
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   715
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   716
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   717
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
   718
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   719
    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
   720
} // impl_ARB1_GetAttribLocation
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   721
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   722
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   723
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
   724
                                    MOJOSHADER_glShader *pshader)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   725
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   726
    // 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
   727
    static GLuint retval = 1;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   728
    return retval++;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   729
} // impl_ARB1_LinkProgram
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   730
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   731
765
076f3bd42329 Moved profileInitProgram to profileFinalInitProgram.
Ryan C. Gordon <icculus@icculus.org>
parents: 764
diff changeset
   732
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
   733
{
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   734
    // no-op.
765
076f3bd42329 Moved profileInitProgram to profileFinalInitProgram.
Ryan C. Gordon <icculus@icculus.org>
parents: 764
diff changeset
   735
} // 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
   736
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   737
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   738
static void impl_ARB1_UseProgram(MOJOSHADER_glProgram *program)
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   739
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   740
    GLuint vhandle = 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   741
    GLuint phandle = 0;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   742
    if (program != NULL)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   743
    {
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   744
        if (program->vertex != NULL)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   745
            vhandle = program->vertex->handle;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   746
        if (program->fragment != NULL)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   747
            phandle = program->fragment->handle;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   748
    } // if
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   749
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   750
    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
   751
    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
   752
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   753
    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
   754
    ctx->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, phandle);
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   755
} // impl_ARB1_UseProgram
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   756
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   757
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   758
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
   759
                                        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
   760
                                        const GLfloat *f)
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
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
    // 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
   763
} // impl_ARB1_PushConstantArray
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   764
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   765
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   766
static void impl_ARB1_PushUniforms(void)
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   767
{
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   768
    // 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
   769
    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
   770
    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
   771
    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
   772
    const uint32 count = program->uniform_count;
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   773
    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
   774
    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
   775
    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
   776
    GLint loc = 0;
1090
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   777
    GLint texbem_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
   778
    uint32 i;
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   779
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   780
    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
   781
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   782
    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
   783
    {
767
806ba18f23aa Cleanups and fixes in ARB1 uniform pushing.
Ryan C. Gordon <icculus@icculus.org>
parents: 766
diff changeset
   784
        UniformMap *map = &program->uniforms[i];
770
b5e545408b02 Fixed incorrect variable name.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   785
        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
   786
        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
   787
        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
   788
        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
   789
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   790
        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
   791
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   792
        // 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
   793
        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
   794
        {
1090
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   795
            if (shader_type == MOJOSHADER_TYPE_PIXEL)
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   796
                texbem_loc = loc;
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   797
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   798
            // 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
   799
            //  The array should always be sorted as such.
770
b5e545408b02 Fixed incorrect variable name.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   800
            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
   801
            {
770
b5e545408b02 Fixed incorrect variable name.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   802
                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
   803
                srcf = program->ps_uniforms_float4;
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   804
                srci = program->ps_uniforms_int4;
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   805
                srcb = program->ps_uniforms_bool;
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   806
                loc = 0;
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   807
            } // if
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   808
            else
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   809
            {
769
0627038d2032 Fixed wrong assert; triggered if there were no vertex shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 768
diff changeset
   810
                // 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
   811
                assert(0 && "Unexpected shader type");
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   812
            } // else
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   813
770
b5e545408b02 Fixed incorrect variable name.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   814
            shader_type = uniform_shader_type;
b5e545408b02 Fixed incorrect variable name.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   815
            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
   816
        } // if
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   817
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   818
        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
   819
        {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   820
            int i;
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   821
            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
   822
                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
   823
        } // if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   824
        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
   825
        {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   826
            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
   827
            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
   828
            {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   829
                // 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
   830
                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
   831
                    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
   832
            } // if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   833
            else
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   834
            {
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   835
                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
   836
                {
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   837
                    const GLfloat fv[4] = {
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   838
                        (GLfloat) srci[0], (GLfloat) srci[1],
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   839
                        (GLfloat) srci[2], (GLfloat) srci[3]
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   840
                    };
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   841
                    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
   842
                } // for
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   843
            } // else
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   844
        } // else if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   845
        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
   846
        {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   847
            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
   848
            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
   849
            {
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   850
                // 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
   851
                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
   852
                {
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   853
                    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
   854
                    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
   855
                    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
   856
                } // for
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   857
            } // if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   858
            else
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   859
            {
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   860
                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
   861
                {
768
9ba81386bd4d Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents: 767
diff changeset
   862
                    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
   863
                    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
   864
                    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
   865
                } // for
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   866
            } // else
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   867
        } // else if
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   868
    } // for
1090
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   869
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   870
    if (program->texbem_count)
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   871
    {
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   872
        const GLenum target = GL_FRAGMENT_PROGRAM_ARB;
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   873
        GLfloat *srcf = program->ps_uniforms_float4;
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   874
        srcf += (program->ps_uniforms_float4_count * 4) -
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   875
                (program->texbem_count * 8);
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   876
        loc = texbem_loc;
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   877
        for (i = 0; i < program->texbem_count; i++, srcf += 8)
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   878
        {
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   879
            ctx->glProgramLocalParameter4fvARB(target, loc++, srcf);
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   880
            ctx->glProgramLocalParameter4fvARB(target, loc++, srcf + 4);
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   881
        } // for
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   882
    } // if
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   883
} // impl_ARB1_PushUniforms
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   884
763
ef6489e7e263 Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents: 761
diff changeset
   885
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
   886
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   887
    // 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
   888
    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
   889
} // impl_ARB1_PushSampler
411
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   890
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   891
#endif  // SUPPORT_PROFILE_ARB1
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   892
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   893
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   894
const char *MOJOSHADER_glGetError(void)
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   895
{
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   896
    return error_buffer;
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   897
} // MOJOSHADER_glGetError
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   898
01bc1352c047 Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
   899
904
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   900
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
   901
                     const char *fn, int *ext)
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   902
{
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   903
    void *retval = NULL;
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   904
    if (lookup != NULL)
904
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   905
        retval = lookup(fn, d);
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   906
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   907
    if (retval == NULL)
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   908
        *ext = 0;
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   909
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   910
    return retval;
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   911
} // loadsym
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   912
904
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   913
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
   914
{
363
bea8bf9e5536 Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   915
    #define DO_LOOKUP(ext, typ, fn) { \
1023
8f4d16a3b380 Cleaned up GL symbol lookup slightly.
Ryan C. Gordon <icculus@icculus.org>
parents: 906
diff changeset
   916
        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
   917
    }
bea8bf9e5536 Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   918
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   919
    DO_LOOKUP(core_opengl, PFNGLGETSTRINGPROC, glGetString);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   920
    DO_LOOKUP(core_opengl, PFNGLGETERRORPROC, glGetError);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   921
    DO_LOOKUP(core_opengl, PFNGLGETINTEGERVPROC, glGetIntegerv);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   922
    DO_LOOKUP(core_opengl, PFNGLENABLEPROC, glEnable);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   923
    DO_LOOKUP(core_opengl, PFNGLDISABLEPROC, glDisable);
1117
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
   924
    DO_LOOKUP(opengl_3, PFNGLGETSTRINGIPROC, glGetStringi);
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   925
    DO_LOOKUP(opengl_2, PFNGLDELETESHADERPROC, glDeleteShader);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   926
    DO_LOOKUP(opengl_2, PFNGLDELETEPROGRAMPROC, glDeleteProgram);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   927
    DO_LOOKUP(opengl_2, PFNGLATTACHSHADERPROC, glAttachShader);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   928
    DO_LOOKUP(opengl_2, PFNGLCOMPILESHADERPROC, glCompileShader);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   929
    DO_LOOKUP(opengl_2, PFNGLCREATESHADERPROC, glCreateShader);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   930
    DO_LOOKUP(opengl_2, PFNGLCREATEPROGRAMPROC, glCreateProgram);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   931
    DO_LOOKUP(opengl_2, PFNGLDISABLEVERTEXATTRIBARRAYPROC, glDisableVertexAttribArray);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   932
    DO_LOOKUP(opengl_2, PFNGLENABLEVERTEXATTRIBARRAYPROC, glEnableVertexAttribArray);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   933
    DO_LOOKUP(opengl_2, PFNGLGETATTRIBLOCATIONPROC, glGetAttribLocation);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   934
    DO_LOOKUP(opengl_2, PFNGLGETPROGRAMINFOLOGPROC, glGetProgramInfoLog);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   935
    DO_LOOKUP(opengl_2, PFNGLGETSHADERIVPROC, glGetShaderiv);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   936
    DO_LOOKUP(opengl_2, PFNGLGETPROGRAMIVPROC, glGetProgramiv);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   937
    DO_LOOKUP(opengl_2, PFNGLGETUNIFORMLOCATIONPROC, glGetUniformLocation);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   938
    DO_LOOKUP(opengl_2, PFNGLLINKPROGRAMPROC, glLinkProgram);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   939
    DO_LOOKUP(opengl_2, PFNGLSHADERSOURCEPROC, glShaderSource);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   940
    DO_LOOKUP(opengl_2, PFNGLUNIFORM1IPROC, glUniform1i);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   941
    DO_LOOKUP(opengl_2, PFNGLUNIFORM1IVPROC, glUniform1iv);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   942
    DO_LOOKUP(opengl_2, PFNGLUNIFORM4FVPROC, glUniform4fv);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   943
    DO_LOOKUP(opengl_2, PFNGLUNIFORM4IVPROC, glUniform4iv);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   944
    DO_LOOKUP(opengl_2, PFNGLUSEPROGRAMPROC, glUseProgram);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   945
    DO_LOOKUP(opengl_2, PFNGLVERTEXATTRIBPOINTERPROC, glVertexAttribPointer);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   946
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLDELETEOBJECTARBPROC, glDeleteObjectARB);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   947
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLATTACHOBJECTARBPROC, glAttachObjectARB);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   948
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLCOMPILESHADERARBPROC, glCompileShaderARB);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   949
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLCREATEPROGRAMOBJECTARBPROC, glCreateProgramObjectARB);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   950
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLCREATESHADEROBJECTARBPROC, glCreateShaderObjectARB);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   951
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLGETINFOLOGARBPROC, glGetInfoLogARB);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   952
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLGETOBJECTPARAMETERIVARBPROC, glGetObjectParameterivARB);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   953
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLGETUNIFORMLOCATIONARBPROC, glGetUniformLocationARB);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   954
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLLINKPROGRAMARBPROC, glLinkProgramARB);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   955
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLSHADERSOURCEARBPROC, glShaderSourceARB);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   956
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLUNIFORM1IARBPROC, glUniform1iARB);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   957
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLUNIFORM1IVARBPROC, glUniform1ivARB);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   958
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLUNIFORM4FVARBPROC, glUniform4fvARB);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   959
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLUNIFORM4IVARBPROC, glUniform4ivARB);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   960
    DO_LOOKUP(GL_ARB_shader_objects, PFNGLUSEPROGRAMOBJECTARBPROC, glUseProgramObjectARB);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   961
    DO_LOOKUP(GL_ARB_vertex_shader, PFNGLDISABLEVERTEXATTRIBARRAYARBPROC, glDisableVertexAttribArrayARB);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   962
    DO_LOOKUP(GL_ARB_vertex_shader, PFNGLENABLEVERTEXATTRIBARRAYARBPROC, glEnableVertexAttribArrayARB);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   963
    DO_LOOKUP(GL_ARB_vertex_shader, PFNGLGETATTRIBLOCATIONARBPROC, glGetAttribLocationARB);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   964
    DO_LOOKUP(GL_ARB_vertex_shader, PFNGLVERTEXATTRIBPOINTERARBPROC, glVertexAttribPointerARB);
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   965
    DO_LOOKUP(GL_ARB_vertex_program, PFNGLVERTEXATTRIBPOINTERARBPROC, glVertexAttribPointerARB);
333
2b36a1d72fa1 Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   966
    DO_LOOKUP(GL_ARB_vertex_program, PFNGLGETPROGRAMIVARBPROC, glGetProgramivARB);
395
d2307cc5d6e7 Use local parameters, not environment params, in the arb1/nv2 profiles.
Ryan C. Gordon <icculus@icculus.org>
parents: 394
diff changeset
   967
    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
   968
    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
   969
    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
   970
    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
   971
    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
   972
    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
   973
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   974
    #undef DO_LOOKUP
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   975
} // lookup_entry_points
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   976
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   977
static inline int opengl_version_atleast(const int major, const int minor)
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   978
{
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   979
    return ( ((ctx->opengl_major << 16) | (ctx->opengl_minor & 0xFFFF)) >=
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   980
             ((major << 16) | (minor & 0xFFFF)) );
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   981
} // opengl_version_atleast
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   982
1117
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
   983
static int verify_extension(const char *ext, int have, StringCache *exts,
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   984
                            int major, int minor)
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   985
{
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   986
    if (have == 0)
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   987
        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
   988
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   989
    else if (!ctx->have_core_opengl)
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   990
        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
   991
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   992
    // See if it's in the spec for this GL implementation's version.
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   993
    if ((major > 0) && (opengl_version_atleast(major, minor)))
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
   994
        return 1;
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   995
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   996
    // Not available in the GL version, check the extension list.
1117
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
   997
    return stringcache_iscached(exts, ext);
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   998
} // verify_extension
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
   999
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
  1000
407
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
  1001
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
  1002
{
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
  1003
    if (verstr == NULL)
407
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
  1004
        *maj = *min = 0;
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
  1005
    else
407
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
  1006
        sscanf(verstr, "%d.%d", maj, min);
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
  1007
} // parse_opengl_version_str
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
  1008
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
  1009
1070
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1010
#if SUPPORT_PROFILE_GLSL
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1011
static inline int glsl_version_atleast(const int major, const int minor)
407
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
  1012
{
1070
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1013
    return ( ((ctx->glsl_major << 16) | (ctx->glsl_minor & 0xFFFF)) >=
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1014
             ((major << 16) | (minor & 0xFFFF)) );
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1015
} // glsl_version_atleast
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1016
#endif
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
  1017
1070
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1018
static void detect_glsl_version(void)
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1019
{
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1020
    ctx->glsl_major = ctx->glsl_minor = 0;
229
67a3d459d865 OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 226
diff changeset
  1021
808
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 807
diff changeset
  1022
#if SUPPORT_PROFILE_GLSL
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
  1023
    if (!ctx->have_core_opengl)
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
  1024
        return;  // everything's busted, give up.
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
  1025
1070
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1026
    #if PLATFORM_MACOSX
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1027
    // If running on Mac OS X <= 10.4, don't ever use GLSL, even if
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1028
    //  the system claims it is available.
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1029
    if (!macosx_version_atleast(10, 5, 0))
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1030
        return;
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1031
    #endif
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1032
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
  1033
    if ( ctx->have_opengl_2 ||
1070
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1034
         ( ctx->have_GL_ARB_shader_objects &&
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1035
           ctx->have_GL_ARB_vertex_shader &&
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1036
           ctx->have_GL_ARB_fragment_shader &&
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1037
           ctx->have_GL_ARB_shading_language_100 ) )
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1038
    {
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1039
        // the GL2.0 and ARB enum is the same value.
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
  1040
        const GLenum enumval = GL_SHADING_LANGUAGE_VERSION;
1070
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1041
        ctx->glGetError();  // flush any existing error state.
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1042
        const char *str = (const char *) ctx->glGetString(enumval);
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1043
        if (ctx->glGetError() == GL_INVALID_ENUM)
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1044
            str = NULL;
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1045
        parse_opengl_version_str(str, &ctx->glsl_major, &ctx->glsl_minor);
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1046
    } // 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
  1047
#endif
1070
32eb4fe78351 Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 1069
diff changeset
  1048
} // detect_glsl_version
407
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
  1049
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 396
diff changeset
  1050
1117
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
  1051
static int iswhitespace(const char ch)
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
  1052
{
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
  1053
    switch (ch)
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
  1054
    {
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
  1055
        case ' ': case '\t': case '\r': case '\n': return 1;
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
  1056
        default: return 0;
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
  1057
    } // switch
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
  1058
} // iswhitespace
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
  1059
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
  1060
904
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
  1061
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
  1062
{
1117
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
  1063
    StringCache *exts = stringcache_create(ctx->malloc_fn, ctx->free_fn, ctx->malloc_data);
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
  1064
    if (!exts)
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
  1065
    {
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
  1066
        out_of_memory();
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
  1067
        return;
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
  1068
    } // if
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
  1069
1072
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
  1070
    ctx->have_core_opengl = 1;
3400f252c4e0 Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents: 1071
diff changeset
  1071
    ctx->have_opengl_2 = 1;
1117
f6712bf72c19 Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents: 1111
diff changeset
  1072
    ctx->have_opengl_3 = 1;
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
  1073
    ctx->have_GL_ARB_vertex_program = 1;
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 321
diff changeset
  1074
    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
  1075
    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
  1076
    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
  1077
    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
  1078
    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
  1079
    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
  1080
    ctx->have_GL_ARB_vertex_shader = 1;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff