author | Ryan C. Gordon <icculus@icculus.org> |
Wed, 11 Feb 2009 21:28:48 -0500 | |
changeset 564 | c669568326fb |
parent 553 | 288ed486e5c3 |
child 581 | 53ef64f219a2 |
permissions | -rw-r--r-- |
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 |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 |
#include <stdio.h> |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 |
#include <string.h> |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 |
#include <stdlib.h> |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 |
#include <stdarg.h> |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 |
#include <assert.h> |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 |
|
254 | 16 |
#ifdef _MSC_VER |
17 |
#define WIN32_LEAN_AND_MEAN 1 |
|
18 |
#include <windows.h> // GL headers need this for WINGDIAPI definition. |
|
443
7293df09c373
Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
442
diff
changeset
|
19 |
#include <malloc.h> // for alloca(). |
254 | 20 |
#endif |
21 |
||
457
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
22 |
#if (defined(__APPLE__) && defined(__MACH__)) |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
23 |
#define PLATFORM_MACOSX 1 |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
24 |
#endif |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
25 |
|
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
26 |
#if PLATFORM_MACOSX |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
27 |
#include <Carbon/Carbon.h> |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
28 |
#endif |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
29 |
|
464
eba4cf79437f
Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
463
diff
changeset
|
30 |
#define __MOJOSHADER_INTERNAL__ 1 |
eba4cf79437f
Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
463
diff
changeset
|
31 |
#include "mojoshader_internal.h" |
eba4cf79437f
Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
463
diff
changeset
|
32 |
|
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
33 |
#define GL_GLEXT_LEGACY 1 |
246
897868fdd958
Moved gl*.h into GL directory.
Ryan C. Gordon <icculus@icculus.org>
parents:
245
diff
changeset
|
34 |
#include "GL/gl.h" |
897868fdd958
Moved gl*.h into GL directory.
Ryan C. Gordon <icculus@icculus.org>
parents:
245
diff
changeset
|
35 |
#include "GL/glext.h" |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 |
|
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
|
37 |
#ifndef GL_HALF_FLOAT |
5a978f37e750
Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents:
448
diff
changeset
|
38 |
#define GL_HALF_FLOAT 0x140B |
5a978f37e750
Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents:
448
diff
changeset
|
39 |
#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
|
40 |
|
5a978f37e750
Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents:
448
diff
changeset
|
41 |
#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
|
42 |
#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
|
43 |
#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
|
44 |
|
5a978f37e750
Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents:
448
diff
changeset
|
45 |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 |
struct MOJOSHADER_glShader |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 |
{ |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 |
const MOJOSHADER_parseData *parseData; |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
49 |
GLuint handle; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 |
uint32 refcount; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 |
}; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 |
|
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
53 |
typedef struct |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
54 |
{ |
206
7027d889acdd
Implemented MOJOSHADER_glProgramReady().
Ryan C. Gordon <icculus@icculus.org>
parents:
205
diff
changeset
|
55 |
MOJOSHADER_shaderType shader_type; |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
56 |
const MOJOSHADER_uniform *uniform; |
215
f2e508f08997
Fixed wrong type for uniform/attribute locations.
Ryan C. Gordon <icculus@icculus.org>
parents:
213
diff
changeset
|
57 |
GLuint location; |
392
6e08aab912f6
Try to only push uniforms when changed.
Ryan C. Gordon <icculus@icculus.org>
parents:
391
diff
changeset
|
58 |
union { |
6e08aab912f6
Try to only push uniforms when changed.
Ryan C. Gordon <icculus@icculus.org>
parents:
391
diff
changeset
|
59 |
GLint b; |
6e08aab912f6
Try to only push uniforms when changed.
Ryan C. Gordon <icculus@icculus.org>
parents:
391
diff
changeset
|
60 |
GLint i[4]; |
6e08aab912f6
Try to only push uniforms when changed.
Ryan C. Gordon <icculus@icculus.org>
parents:
391
diff
changeset
|
61 |
GLfloat f[4]; |
6e08aab912f6
Try to only push uniforms when changed.
Ryan C. Gordon <icculus@icculus.org>
parents:
391
diff
changeset
|
62 |
} value; |
6e08aab912f6
Try to only push uniforms when changed.
Ryan C. Gordon <icculus@icculus.org>
parents:
391
diff
changeset
|
63 |
GLfloat *uniform_array_buffer; |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
64 |
} UniformMap; |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
65 |
|
213
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
66 |
typedef struct |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
67 |
{ |
284
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
68 |
MOJOSHADER_shaderType shader_type; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
69 |
const MOJOSHADER_sampler *sampler; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
70 |
GLuint location; |
392
6e08aab912f6
Try to only push uniforms when changed.
Ryan C. Gordon <icculus@icculus.org>
parents:
391
diff
changeset
|
71 |
GLint value; |
284
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
72 |
} SamplerMap; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
73 |
|
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
74 |
typedef struct |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
75 |
{ |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
76 |
const MOJOSHADER_attribute *attribute; |
215
f2e508f08997
Fixed wrong type for uniform/attribute locations.
Ryan C. Gordon <icculus@icculus.org>
parents:
213
diff
changeset
|
77 |
GLuint location; |
213
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
78 |
} AttributeMap; |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
79 |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
80 |
struct MOJOSHADER_glProgram |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
81 |
{ |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
82 |
MOJOSHADER_glShader *vertex; |
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
83 |
MOJOSHADER_glShader *fragment; |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
84 |
GLuint handle; |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
85 |
uint32 uniform_count; |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
86 |
UniformMap *uniforms; |
284
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
87 |
uint32 sampler_count; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
88 |
SamplerMap *samplers; |
213
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
89 |
uint32 attribute_count; |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
90 |
AttributeMap *attributes; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
91 |
uint32 refcount; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
92 |
}; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
93 |
|
277
49a6571cac6d
Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents:
276
diff
changeset
|
94 |
#ifndef WINGDIAPI |
49a6571cac6d
Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents:
276
diff
changeset
|
95 |
#define WINGDIAPI |
49a6571cac6d
Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents:
276
diff
changeset
|
96 |
#endif |
49a6571cac6d
Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents:
276
diff
changeset
|
97 |
|
242
c3c5693ba179
Fixed vertex attribute aliasing in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
241
diff
changeset
|
98 |
// 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
|
99 |
typedef WINGDIAPI void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params); |
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
100 |
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
|
101 |
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
|
102 |
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
|
103 |
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
|
104 |
|
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
105 |
struct MOJOSHADER_glContext |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
106 |
{ |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
107 |
// Allocators... |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
108 |
MOJOSHADER_malloc malloc_fn; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
109 |
MOJOSHADER_free free_fn; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
110 |
void *malloc_data; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
111 |
|
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
112 |
// The constant register files... |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
113 |
// Man, it kills me how much memory this takes... |
249
7f928921766c
Cleanups for building as C++ code.
Ryan C. Gordon <icculus@icculus.org>
parents:
246
diff
changeset
|
114 |
GLfloat vs_reg_file_f[8192 * 4]; |
7f928921766c
Cleanups for building as C++ code.
Ryan C. Gordon <icculus@icculus.org>
parents:
246
diff
changeset
|
115 |
GLint vs_reg_file_i[2047 * 4]; |
7f928921766c
Cleanups for building as C++ code.
Ryan C. Gordon <icculus@icculus.org>
parents:
246
diff
changeset
|
116 |
GLint vs_reg_file_b[2047]; |
7f928921766c
Cleanups for building as C++ code.
Ryan C. Gordon <icculus@icculus.org>
parents:
246
diff
changeset
|
117 |
GLfloat ps_reg_file_f[8192 * 4]; |
7f928921766c
Cleanups for building as C++ code.
Ryan C. Gordon <icculus@icculus.org>
parents:
246
diff
changeset
|
118 |
GLint ps_reg_file_i[2047 * 4]; |
7f928921766c
Cleanups for building as C++ code.
Ryan C. Gordon <icculus@icculus.org>
parents:
246
diff
changeset
|
119 |
GLint ps_reg_file_b[2047]; |
284
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
120 |
GLuint sampler_reg_file[16]; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
121 |
|
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
122 |
// GL stuff... |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
123 |
int opengl_major; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
124 |
int opengl_minor; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
125 |
MOJOSHADER_glProgram *bound_program; |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
126 |
char profile[16]; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
127 |
|
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
128 |
// Extensions... |
463
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
129 |
int have_base_opengl; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
130 |
int have_GL_ARB_vertex_program; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
131 |
int have_GL_ARB_fragment_program; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
132 |
int have_GL_NV_vertex_program2_option; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
133 |
int have_GL_NV_fragment_program2; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
134 |
int have_GL_NV_vertex_program3; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
135 |
int have_GL_NV_gpu_program4; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
136 |
int have_GL_ARB_shader_objects; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
137 |
int have_GL_ARB_vertex_shader; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
138 |
int have_GL_ARB_fragment_shader; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
139 |
int have_GL_ARB_shading_language_100; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
140 |
int have_GL_NV_half_float; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
141 |
int have_GL_ARB_half_float_vertex; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
142 |
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
|
143 |
|
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
144 |
// Entry points... |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
145 |
PFNGLGETSTRINGPROC glGetString; |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
146 |
PFNGLGETERRORPROC glGetError; |
276
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
147 |
PFNGLGETINTEGERVPROC glGetIntegerv; |
358
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
148 |
PFNGLENABLEPROC glEnable; |
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
149 |
PFNGLDISABLEPROC glDisable; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
150 |
PFNGLDELETEOBJECTARBPROC glDeleteObject; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
151 |
PFNGLATTACHOBJECTARBPROC glAttachObject; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
152 |
PFNGLCOMPILESHADERARBPROC glCompileShader; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
153 |
PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObject; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
154 |
PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObject; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
155 |
PFNGLDISABLEVERTEXATTRIBARRAYARBPROC glDisableVertexAttribArray; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
156 |
PFNGLENABLEVERTEXATTRIBARRAYARBPROC glEnableVertexAttribArray; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
157 |
PFNGLGETATTRIBLOCATIONARBPROC glGetAttribLocation; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
158 |
PFNGLGETINFOLOGARBPROC glGetInfoLog; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
159 |
PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameteriv; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
160 |
PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocation; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
161 |
PFNGLLINKPROGRAMARBPROC glLinkProgram; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
162 |
PFNGLSHADERSOURCEARBPROC glShaderSource; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
163 |
PFNGLUNIFORM1IARBPROC glUniform1i; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
164 |
PFNGLUNIFORM4FVARBPROC glUniform4fv; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
165 |
PFNGLUNIFORM4IVARBPROC glUniform4iv; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
166 |
PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObject; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
167 |
PFNGLVERTEXATTRIBPOINTERARBPROC glVertexAttribPointer; |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
168 |
PFNGLGETPROGRAMIVARBPROC glGetProgramivARB; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
169 |
PFNGLGETPROGRAMSTRINGARBPROC glGetProgramStringARB; |
395
d2307cc5d6e7
Use local parameters, not environment params, in the arb1/nv2 profiles.
Ryan C. Gordon <icculus@icculus.org>
parents:
394
diff
changeset
|
170 |
PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB; |
431
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
171 |
PFNGLPROGRAMLOCALPARAMETERI4IVNVPROC glProgramLocalParameterI4ivNV; |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
172 |
PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
173 |
PFNGLGENPROGRAMSARBPROC glGenProgramsARB; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
174 |
PFNGLBINDPROGRAMARBPROC glBindProgramARB; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
175 |
PFNGLPROGRAMSTRINGARBPROC glProgramStringARB; |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
176 |
|
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
177 |
// interface for profile-specific things. |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
178 |
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
|
179 |
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
|
180 |
void (*profileDeleteShader)(const GLuint shader); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
181 |
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
|
182 |
GLint (*profileGetAttribLocation)(MOJOSHADER_glProgram *program, int idx); |
f8d9d0ae6ba8
Bunch more work (ARB1 profile, OpenGL glue, and general fixes).
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
183 |
GLint (*profileGetUniformLocation)(MOJOSHADER_glProgram *, MOJOSHADER_glShader *, int); |
f8d9d0ae6ba8
Bunch more work (ARB1 profile, OpenGL glue, and general fixes).
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
184 |
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
|
185 |
GLuint (*profileLinkProgram)(MOJOSHADER_glShader *, MOJOSHADER_glShader *); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
186 |
void (*profileUseProgramObject)(MOJOSHADER_glProgram *program); |
347
f8d9d0ae6ba8
Bunch more work (ARB1 profile, OpenGL glue, and general fixes).
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
187 |
void (*profileUniform4fv)(const MOJOSHADER_parseData *, GLint, GLsizei, GLfloat *); |
f8d9d0ae6ba8
Bunch more work (ARB1 profile, OpenGL glue, and general fixes).
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
188 |
void (*profileUniform4iv)(const MOJOSHADER_parseData *, GLint, GLsizei, GLint *); |
f8d9d0ae6ba8
Bunch more work (ARB1 profile, OpenGL glue, and general fixes).
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
189 |
void (*profileUniform1i)(const MOJOSHADER_parseData *, GLint, GLint); |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
190 |
void (*profileSetSampler)(GLint loc, GLuint sampler); |
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
|
191 |
int (*profileMustLoadConstantArrays)(void); |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
192 |
}; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
193 |
|
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
194 |
|
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
195 |
static MOJOSHADER_glContext *ctx = NULL; |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
196 |
|
219
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
197 |
// Error state... |
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
198 |
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
|
199 |
|
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
200 |
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
|
201 |
{ |
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
202 |
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
|
203 |
} // set_error |
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
204 |
|
457
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
205 |
#if PLATFORM_MACOSX |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
206 |
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
|
207 |
{ |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
208 |
static int checked = 0; |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
209 |
static int combined = 0; |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
210 |
|
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
211 |
if (!checked) |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
212 |
{ |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
213 |
long ver, major, minor, patch; |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
214 |
int convert = 0; |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
215 |
|
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
216 |
if (Gestalt(gestaltSystemVersion, &ver) != noErr) |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
217 |
ver = 0x1000; // oh well. |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
218 |
else if (ver < 0x1030) |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
219 |
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
|
220 |
else |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
221 |
{ |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
222 |
// 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
|
223 |
// 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
|
224 |
// 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
|
225 |
if (Gestalt(gestaltSystemVersionMajor, &major) != noErr) |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
226 |
convert = 1; |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
227 |
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
|
228 |
convert = 1; |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
229 |
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
|
230 |
convert = 1; |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
231 |
} // else |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
232 |
|
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
233 |
if (convert) |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
234 |
{ |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
235 |
major = ((ver & 0xFF00) >> 8); |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
236 |
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
|
237 |
minor = ((ver & 0xF0) >> 4); |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
238 |
patch = (ver & 0xF); |
533 | 239 |
} // if |
457
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
240 |
|
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
241 |
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
|
242 |
checked = 1; |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
243 |
} // if |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
244 |
|
460
54c614f0fcb0
Fixed OS X detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
459
diff
changeset
|
245 |
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
|
246 |
} // macosx_version_atleast |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
247 |
#endif |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
248 |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
249 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
250 |
static inline void *Malloc(const size_t len) |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
251 |
{ |
307
42f6a7ba69e2
Fixes for Visual Studio level 4 compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
291
diff
changeset
|
252 |
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
|
253 |
if (retval == NULL) |
df5ea69833d5
Fixes to Malloc() and Free() in mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
254 |
set_error("out of memory"); |
df5ea69833d5
Fixes to Malloc() and Free() in mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
255 |
return retval; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
256 |
} // Malloc |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
257 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
258 |
static inline void Free(void *ptr) |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
259 |
{ |
220
df5ea69833d5
Fixes to Malloc() and Free() in mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
260 |
if (ptr != NULL) |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
261 |
ctx->free_fn(ptr, ctx->malloc_data); |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
262 |
} // Free |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
263 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
264 |
|
358
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
265 |
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
|
266 |
{ |
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
267 |
if (val) |
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
268 |
ctx->glEnable(state); |
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
269 |
else |
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
270 |
ctx->glDisable(state); |
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
271 |
} // toggle_gl_state |
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
272 |
|
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
273 |
|
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
274 |
// profile-specific implementations... |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
275 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
276 |
#if SUPPORT_PROFILE_GLSL |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
277 |
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
|
278 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
279 |
if (t == MOJOSHADER_TYPE_VERTEX) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
280 |
return GL_VERTEX_SHADER; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
281 |
else if (t == MOJOSHADER_TYPE_PIXEL) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
282 |
return GL_FRAGMENT_SHADER; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
283 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
284 |
// !!! FIXME: geometry shaders? |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
285 |
return GL_NONE; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
286 |
} // glsl_shader_type |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
287 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
288 |
|
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
|
289 |
static int impl_GLSL_MustLoadConstantArrays(void) { return 1; } |
73492129c1af
Expose true constant arrays in parseData, load them at link time for GLSL.
Ryan C. Gordon <icculus@icculus.org>
parents:
436
diff
changeset
|
290 |
|
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
291 |
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
|
292 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
293 |
GLenum pname = GL_NONE; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
294 |
GLint val = 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
295 |
if (shader_type == MOJOSHADER_TYPE_VERTEX) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
296 |
pname = GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
297 |
else if (shader_type == MOJOSHADER_TYPE_PIXEL) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
298 |
pname = GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
299 |
else |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
300 |
return -1; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
301 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
302 |
ctx->glGetIntegerv(pname, &val); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
303 |
return (int) val; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
304 |
} // impl_GLSL_MaxUniforms |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
305 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
306 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
307 |
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
|
308 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
309 |
GLint ok = 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
310 |
GLint shaderlen = (GLint) pd->output_len; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
311 |
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
|
312 |
GLuint shader = ctx->glCreateShaderObject(shader_type); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
313 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
314 |
ctx->glShaderSource(shader, 1, (const GLchar **) &pd->output, &shaderlen); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
315 |
ctx->glCompileShader(shader); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
316 |
ctx->glGetObjectParameteriv(shader, GL_OBJECT_COMPILE_STATUS_ARB, &ok); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
317 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
318 |
if (!ok) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
319 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
320 |
GLsizei len = 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
321 |
ctx->glGetInfoLog(shader, sizeof (error_buffer), &len, |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
322 |
(GLchar *) error_buffer); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
323 |
*s = 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
324 |
return 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
325 |
} // if |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
326 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
327 |
*s = shader; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
328 |
return 1; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
329 |
} // impl_GLSL_CompileShader |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
330 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
331 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
332 |
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
|
333 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
334 |
ctx->glDeleteObject(shader); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
335 |
} // impl_GLSL_DeleteShader |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
336 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
337 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
338 |
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
|
339 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
340 |
ctx->glDeleteObject(program); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
341 |
} // impl_GLSL_DeleteProgram |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
342 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
343 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
344 |
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
|
345 |
MOJOSHADER_glShader *shader, int idx) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
346 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
347 |
return ctx->glGetUniformLocation(program->handle, |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
348 |
shader->parseData->uniforms[idx].name); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
349 |
} // impl_GLSL_GetUniformLocation |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
350 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
351 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
352 |
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
|
353 |
MOJOSHADER_glShader *shader, int idx) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
354 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
355 |
return ctx->glGetUniformLocation(program->handle, |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
356 |
shader->parseData->samplers[idx].name); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
357 |
} // impl_GLSL_GetSamplerLocation |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
358 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
359 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
360 |
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
|
361 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
362 |
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
|
363 |
const MOJOSHADER_attribute *a = pd->attributes; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
364 |
return ctx->glGetAttribLocation(program->handle, a[idx].name); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
365 |
} // impl_GLSL_GetAttribLocation |
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 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
368 |
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
|
369 |
MOJOSHADER_glShader *pshader) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
370 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
371 |
const GLuint program = ctx->glCreateProgramObject(); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
372 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
373 |
if (vshader != NULL) ctx->glAttachObject(program, vshader->handle); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
374 |
if (pshader != NULL) ctx->glAttachObject(program, pshader->handle); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
375 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
376 |
ctx->glLinkProgram(program); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
377 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
378 |
GLint ok = 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
379 |
ctx->glGetObjectParameteriv(program, GL_OBJECT_LINK_STATUS_ARB, &ok); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
380 |
if (!ok) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
381 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
382 |
GLsizei len = 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
383 |
ctx->glGetInfoLog(program, sizeof (error_buffer), &len, (GLchar *) error_buffer); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
384 |
ctx->glDeleteObject(program); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
385 |
return 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
386 |
} // if |
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 |
return program; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
389 |
} // impl_GLSL_LinkProgram |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
390 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
391 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
392 |
static void impl_GLSL_UseProgramObject(MOJOSHADER_glProgram *program) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
393 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
394 |
ctx->glUseProgramObject((program != NULL) ? program->handle : 0); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
395 |
} // impl_GLSL_UseProgramObject |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
396 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
397 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
398 |
static void impl_GLSL_Uniform4fv(const MOJOSHADER_parseData *pd, GLint loc, |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
399 |
GLsizei siz, GLfloat *v) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
400 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
401 |
ctx->glUniform4fv(loc, siz, v); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
402 |
} // impl_GLSL_Uniform4fv |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
403 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
404 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
405 |
static void impl_GLSL_Uniform4iv(const MOJOSHADER_parseData *pd, GLint loc, |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
406 |
GLsizei siz, GLint *v) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
407 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
408 |
ctx->glUniform4iv(loc, siz, v); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
409 |
} // impl_GLSL_Uniform4iv |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
410 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
411 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
412 |
static void impl_GLSL_Uniform1i(const MOJOSHADER_parseData *pd, GLint loc, |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
413 |
GLint v) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
414 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
415 |
ctx->glUniform1i(loc, v); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
416 |
} // impl_GLSL_Uniform1i |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
417 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
418 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
419 |
static void impl_GLSL_SetSampler(GLint loc, GLuint sampler) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
420 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
421 |
ctx->glUniform1i(loc, sampler); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
422 |
} // impl_GLSL_SetSampler |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
423 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
424 |
#endif // SUPPORT_PROFILE_GLSL |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
425 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
426 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
427 |
#if SUPPORT_PROFILE_ARB1 |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
428 |
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
|
429 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
430 |
if (t == MOJOSHADER_TYPE_VERTEX) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
431 |
return GL_VERTEX_PROGRAM_ARB; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
432 |
else if (t == MOJOSHADER_TYPE_PIXEL) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
433 |
return GL_FRAGMENT_PROGRAM_ARB; |
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 |
// !!! FIXME: geometry shaders? |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
436 |
return GL_NONE; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
437 |
} // arb1_shader_type |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
438 |
|
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
|
439 |
static int impl_ARB1_MustLoadConstantArrays(void) { return 0; } |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
440 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
441 |
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
|
442 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
443 |
GLint retval = 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
444 |
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
|
445 |
if (program_type == GL_NONE) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
446 |
return -1; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
447 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
448 |
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
|
449 |
return (int) retval; // !!! FIXME: times four? |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
450 |
} // impl_ARB1_MaxUniforms |
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 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
|
454 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
455 |
GLint shaderlen = (GLint) pd->output_len; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
456 |
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
|
457 |
GLuint shader = 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
458 |
ctx->glGenProgramsARB(1, &shader); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
459 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
460 |
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
|
461 |
ctx->glBindProgramARB(shader_type, shader); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
462 |
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
|
463 |
shaderlen, pd->output); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
464 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
465 |
if (ctx->glGetError() == GL_INVALID_OPERATION) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
466 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
467 |
GLint pos = 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
468 |
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
|
469 |
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
|
470 |
snprintf(error_buffer, sizeof (error_buffer), |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
471 |
"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
|
472 |
(int) pos, (const char *) errstr); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
473 |
ctx->glBindProgramARB(shader_type, 0); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
474 |
ctx->glDeleteProgramsARB(1, &shader); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
475 |
*s = 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
476 |
return 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
477 |
} // if |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
478 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
479 |
*s = shader; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
480 |
return 1; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
481 |
} // impl_ARB1_CompileShader |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
482 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
483 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
484 |
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
|
485 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
486 |
GLuint shader = _shader; // const removal. |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
487 |
ctx->glDeleteProgramsARB(1, &shader); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
488 |
} // impl_ARB1_DeleteShader |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
489 |
|
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 |
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
|
492 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
493 |
// 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
|
494 |
} // impl_GLSL_DeleteProgram |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
495 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
496 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
497 |
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
|
498 |
MOJOSHADER_glShader *shader, int idx) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
499 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
500 |
assert(shader->parseData->uniforms[idx].type == MOJOSHADER_UNIFORM_FLOAT); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
501 |
return shader->parseData->uniforms[idx].index; // !!! FIXME: doesn't work if there are int or bool uniforms! |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
502 |
} // impl_ARB1_GetUniformLocation |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
503 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
504 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
505 |
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
|
506 |
MOJOSHADER_glShader *shader, int idx) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
507 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
508 |
return shader->parseData->samplers[idx].index; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
509 |
} // impl_ARB1_GetSamplerLocation |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
510 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
511 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
512 |
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
|
513 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
514 |
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
|
515 |
} // impl_ARB1_GetAttribLocation |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
516 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
517 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
518 |
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
|
519 |
MOJOSHADER_glShader *pshader) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
520 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
521 |
// 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
|
522 |
static GLuint retval = 1; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
523 |
return retval++; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
524 |
} // impl_ARB1_LinkProgram |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
525 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
526 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
527 |
static void impl_ARB1_UseProgramObject(MOJOSHADER_glProgram *program) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
528 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
529 |
GLuint vhandle = 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
530 |
GLuint phandle = 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
531 |
if (program != NULL) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
532 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
533 |
if (program->vertex != NULL) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
534 |
vhandle = program->vertex->handle; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
535 |
if (program->fragment != NULL) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
536 |
phandle = program->fragment->handle; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
537 |
} // if |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
538 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
539 |
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
|
540 |
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
|
541 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
542 |
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
|
543 |
ctx->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, phandle); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
544 |
} // impl_ARB1_UseProgramObject |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
545 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
546 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
547 |
static void impl_ARB1_Uniform4fv(const MOJOSHADER_parseData *pd, GLint loc, |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
548 |
GLsizei siz, GLfloat *v) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
549 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
550 |
int i; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
551 |
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
|
552 |
for (i = 0; i < siz; i++, v += 4) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
553 |
ctx->glProgramLocalParameter4fvARB(shader_type, loc + i, v); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
554 |
} // impl_ARB1_Uniform4fv |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
555 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
556 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
557 |
static void impl_ARB1_Uniform4iv(const MOJOSHADER_parseData *pd, GLint loc, |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
558 |
GLsizei siz, GLint *v) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
559 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
560 |
int i; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
561 |
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
|
562 |
for (i = 0; i < siz; i++, v += 4) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
563 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
564 |
GLfloat f[4] = { |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
565 |
(GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3] |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
566 |
}; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
567 |
ctx->glProgramLocalParameter4fvARB(shader_type, loc + i, f); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
568 |
} // for |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
569 |
} // impl_ARB1_Uniform4iv |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
570 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
571 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
572 |
static void impl_ARB1_Uniform1i(const MOJOSHADER_parseData *pd, GLint loc, |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
573 |
GLint _v) |
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 |
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
|
576 |
const GLfloat v = (GLfloat) _v; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
577 |
GLfloat f[4] = { v, v, v, v }; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
578 |
ctx->glProgramLocalParameter4fvARB(shader_type, loc, f); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
579 |
} // impl_ARB1_Uniform1i |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
580 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
581 |
|
431
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
582 |
static void impl_NV4_Uniform4iv(const MOJOSHADER_parseData *pd, GLint loc, |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
583 |
GLsizei siz, GLint *v) |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
584 |
{ |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
585 |
int i; |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
586 |
const GLenum shader_type = arb1_shader_type(pd->shader_type); |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
587 |
for (i = 0; i < siz; i++, v += 4) |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
588 |
ctx->glProgramLocalParameterI4ivNV(shader_type, loc + i, v); |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
589 |
} // impl_NV4_Uniform4iv |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
590 |
|
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
591 |
|
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
592 |
static void impl_NV4_Uniform1i(const MOJOSHADER_parseData *pd, GLint loc, |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
593 |
GLint _v) |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
594 |
{ |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
595 |
const GLenum shader_type = arb1_shader_type(pd->shader_type); |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
596 |
GLint v[4] = { _v, _v, _v, _v }; |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
597 |
ctx->glProgramLocalParameterI4ivNV(shader_type, loc, v); |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
598 |
} // impl_NV4_Uniform1i |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
599 |
|
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
600 |
|
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
601 |
static void impl_ARB1_SetSampler(GLint loc, GLuint sampler) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
602 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
603 |
// 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
|
604 |
assert(loc == (GLint) sampler); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
605 |
} // impl_ARB1_SetSampler |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
606 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
607 |
#endif // SUPPORT_PROFILE_ARB1 |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
608 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
609 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
610 |
const char *MOJOSHADER_glGetError(void) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
611 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
612 |
return error_buffer; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
613 |
} // MOJOSHADER_glGetError |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
614 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
615 |
|
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
616 |
static void *loadsym(void *(*lookup)(const char *fn), const char *fn, int *ext) |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
617 |
{ |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
618 |
void *retval = NULL; |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
619 |
if (lookup != NULL) |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
620 |
{ |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
621 |
retval = lookup(fn); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
622 |
if (retval == NULL) |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
623 |
{ |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
624 |
char arbfn[64]; |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
625 |
snprintf(arbfn, sizeof (arbfn), "%sARB", fn); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
626 |
retval = lookup(arbfn); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
627 |
} // if |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
628 |
} // if |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
629 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
630 |
if (retval == NULL) |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
631 |
*ext = 0; |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
632 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
633 |
return retval; |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
634 |
} // loadsym |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
635 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
636 |
static void lookup_entry_points(void *(*lookup)(const char *fnname)) |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
637 |
{ |
363 | 638 |
#define DO_LOOKUP(ext, typ, fn) { \ |
639 |
int exist = ctx->have_##ext; \ |
|
640 |
ctx->fn = (typ) loadsym(lookup, #fn, &exist); \ |
|
641 |
ctx->have_##ext = exist; \ |
|
642 |
} |
|
643 |
||
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
644 |
DO_LOOKUP(base_opengl, PFNGLGETSTRINGPROC, glGetString); |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
645 |
DO_LOOKUP(base_opengl, PFNGLGETERRORPROC, glGetError); |
276
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
646 |
DO_LOOKUP(base_opengl, PFNGLGETINTEGERVPROC, glGetIntegerv); |
358
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
647 |
DO_LOOKUP(base_opengl, PFNGLENABLEPROC, glEnable); |
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
648 |
DO_LOOKUP(base_opengl, PFNGLDISABLEPROC, glDisable); |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
649 |
DO_LOOKUP(GL_ARB_shader_objects, PFNGLDELETEOBJECTARBPROC, glDeleteObject); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
650 |
DO_LOOKUP(GL_ARB_shader_objects, PFNGLATTACHOBJECTARBPROC, glAttachObject); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
651 |
DO_LOOKUP(GL_ARB_shader_objects, PFNGLCOMPILESHADERARBPROC, glCompileShader); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
652 |
DO_LOOKUP(GL_ARB_shader_objects, PFNGLCREATEPROGRAMOBJECTARBPROC, glCreateProgramObject); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
653 |
DO_LOOKUP(GL_ARB_shader_objects, PFNGLCREATESHADEROBJECTARBPROC, glCreateShaderObject); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
654 |
DO_LOOKUP(GL_ARB_shader_objects, PFNGLGETINFOLOGARBPROC, glGetInfoLog); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
655 |
DO_LOOKUP(GL_ARB_shader_objects, PFNGLGETOBJECTPARAMETERIVARBPROC, glGetObjectParameteriv); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
656 |
DO_LOOKUP(GL_ARB_shader_objects, PFNGLGETUNIFORMLOCATIONARBPROC, glGetUniformLocation); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
657 |
DO_LOOKUP(GL_ARB_shader_objects, PFNGLLINKPROGRAMARBPROC, glLinkProgram); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
658 |
DO_LOOKUP(GL_ARB_shader_objects, PFNGLSHADERSOURCEARBPROC, glShaderSource); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
659 |
DO_LOOKUP(GL_ARB_shader_objects, PFNGLUNIFORM1IARBPROC, glUniform1i); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
660 |
DO_LOOKUP(GL_ARB_shader_objects, PFNGLUNIFORM4FVARBPROC, glUniform4fv); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
661 |
DO_LOOKUP(GL_ARB_shader_objects, PFNGLUNIFORM4IVARBPROC, glUniform4iv); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
662 |
DO_LOOKUP(GL_ARB_shader_objects, PFNGLUSEPROGRAMOBJECTARBPROC, glUseProgramObject); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
663 |
DO_LOOKUP(GL_ARB_vertex_shader, PFNGLDISABLEVERTEXATTRIBARRAYARBPROC, glDisableVertexAttribArray); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
664 |
DO_LOOKUP(GL_ARB_vertex_shader, PFNGLENABLEVERTEXATTRIBARRAYARBPROC, glEnableVertexAttribArray); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
665 |
DO_LOOKUP(GL_ARB_vertex_shader, PFNGLGETATTRIBLOCATIONARBPROC, glGetAttribLocation); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
666 |
DO_LOOKUP(GL_ARB_vertex_shader, PFNGLVERTEXATTRIBPOINTERARBPROC, glVertexAttribPointer); |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
667 |
DO_LOOKUP(GL_ARB_vertex_program, PFNGLVERTEXATTRIBPOINTERARBPROC, glVertexAttribPointer); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
668 |
DO_LOOKUP(GL_ARB_vertex_program, PFNGLGETPROGRAMIVARBPROC, glGetProgramivARB); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
669 |
DO_LOOKUP(GL_ARB_vertex_program, PFNGLGETPROGRAMSTRINGARBPROC, glGetProgramStringARB); |
395
d2307cc5d6e7
Use local parameters, not environment params, in the arb1/nv2 profiles.
Ryan C. Gordon <icculus@icculus.org>
parents:
394
diff
changeset
|
670 |
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
|
671 |
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
|
672 |
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
|
673 |
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
|
674 |
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
|
675 |
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
|
676 |
|
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
677 |
#undef DO_LOOKUP |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
678 |
} // lookup_entry_points |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
679 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
680 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
681 |
static int verify_extension(const char *ext, int have, const char *extlist, |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
682 |
int major, int minor) |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
683 |
{ |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
684 |
if (have == 0) |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
685 |
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
|
686 |
|
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
687 |
else if (!ctx->have_base_opengl) |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
688 |
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
|
689 |
|
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
690 |
// See if it's in the spec for this GL implementation's version. |
236
8e2fc535b210
Support for half-float attribute arrays.
Ryan C. Gordon <icculus@icculus.org>
parents:
230
diff
changeset
|
691 |
if (major >= 0) |
8e2fc535b210
Support for half-float attribute arrays.
Ryan C. Gordon <icculus@icculus.org>
parents:
230
diff
changeset
|
692 |
{ |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
693 |
if ( ((ctx->opengl_major << 16) | (ctx->opengl_minor & 0xFFFF)) >= |
236
8e2fc535b210
Support for half-float attribute arrays.
Ryan C. Gordon <icculus@icculus.org>
parents:
230
diff
changeset
|
694 |
((major << 16) | (minor & 0xFFFF)) ) |
8e2fc535b210
Support for half-float attribute arrays.
Ryan C. Gordon <icculus@icculus.org>
parents:
230
diff
changeset
|
695 |
return 1; |
8e2fc535b210
Support for half-float attribute arrays.
Ryan C. Gordon <icculus@icculus.org>
parents:
230
diff
changeset
|
696 |
} // if |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
697 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
698 |
// Not available in the GL version, check the extension list. |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
699 |
const char *ptr = strstr(extlist, ext); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
700 |
if (ptr == NULL) |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
701 |
return 0; |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
702 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
703 |
const char endchar = ptr[strlen(ext)]; |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
704 |
if ((endchar == '\0') || (endchar == ' ')) |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
705 |
return 1; // extension is in the list. |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
706 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
707 |
return 0; // just not supported, fail. |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
708 |
} // verify_extension |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
709 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
710 |
|
407
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
711 |
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
|
712 |
{ |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
713 |
if (verstr == NULL) |
407
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
714 |
*maj = *min = 0; |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
715 |
else |
407
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
716 |
sscanf(verstr, "%d.%d", maj, min); |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
717 |
} // parse_opengl_version_str |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
718 |
|
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
719 |
|
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
720 |
static inline void parse_opengl_version(const char *verstr) |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
721 |
{ |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
722 |
parse_opengl_version_str(verstr, &ctx->opengl_major, &ctx->opengl_minor); |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
723 |
} // parse_opengl_version |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
724 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
725 |
|
407
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
726 |
static int glsl_version_atleast(int maj, int min) |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
727 |
{ |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
728 |
int glslmin = 0; |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
729 |
int glslmaj = 0; |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
730 |
ctx->glGetError(); // flush any existing error state. |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
731 |
const GLenum enumval = GL_SHADING_LANGUAGE_VERSION_ARB; |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
732 |
const char *str = (const char *) ctx->glGetString(enumval); |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
733 |
if (ctx->glGetError() == GL_INVALID_ENUM) |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
734 |
return 0; // this is a basic, 1.0-compliant implementation. |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
735 |
parse_opengl_version_str(str, &glslmaj, &glslmin); |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
736 |
return ( (glslmaj > maj) || ((glslmaj == maj) && (glslmin >= min)) ); |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
737 |
} // glsl_version_atleast |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
738 |
|
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
739 |
|
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
740 |
static void load_extensions(void *(*lookup)(const char *fnname)) |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
741 |
{ |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
742 |
const char *extlist = NULL; |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
743 |
|
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
744 |
ctx->have_base_opengl = 1; |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
745 |
ctx->have_GL_ARB_vertex_program = 1; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
746 |
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
|
747 |
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
|
748 |
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
|
749 |
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
|
750 |
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
|
751 |
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
|
752 |
ctx->have_GL_ARB_vertex_shader = 1; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
753 |
ctx->have_GL_ARB_fragment_shader = 1; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
754 |
ctx->have_GL_ARB_shading_language_100 = 1; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
755 |
ctx->have_GL_NV_half_float = 1; |
449
5a978f37e750
Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents:
448
diff
changeset
|
756 |
ctx->have_GL_ARB_half_float_vertex = 1; |
5a978f37e750
Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents:
448
diff
changeset
|
757 |
ctx->have_GL_OES_vertex_half_float = 1; |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
758 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
759 |
lookup_entry_points(lookup); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
760 |
|
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
761 |
if (!ctx->have_base_opengl) |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
762 |
set_error("missing basic OpenGL entry points"); |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
763 |
else |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
764 |
{ |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
765 |
parse_opengl_version((const char *) ctx->glGetString(GL_VERSION)); |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
766 |
extlist = (const char *) ctx->glGetString(GL_EXTENSIONS); |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
767 |
} // else |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
768 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
769 |
if (extlist == NULL) |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
770 |
extlist = ""; // just in case. |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
771 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
772 |
#define VERIFY_EXT(ext, major, minor) \ |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
773 |
ctx->have_##ext = verify_extension(#ext, ctx->have_##ext, extlist, major, minor) |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
774 |
|
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
775 |
VERIFY_EXT(GL_ARB_vertex_program, -1, -1); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
776 |
VERIFY_EXT(GL_ARB_fragment_program, -1, -1); |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
777 |
VERIFY_EXT(GL_ARB_shader_objects, 2, 0); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
778 |
VERIFY_EXT(GL_ARB_vertex_shader, 2, 0); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
779 |
VERIFY_EXT(GL_ARB_fragment_shader, 2, 0); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
780 |
VERIFY_EXT(GL_ARB_shading_language_100, 2, 0); |
420
bfcebc3bf560
Corrected test for nv2 profile support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
781 |
VERIFY_EXT(GL_NV_vertex_program2_option, -1, -1); |
bfcebc3bf560
Corrected test for nv2 profile support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
782 |
VERIFY_EXT(GL_NV_fragment_program2, -1, -1); |
421
bfd3d95273ec
First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
420
diff
changeset
|
783 |
VERIFY_EXT(GL_NV_vertex_program3, -1, -1); |
236
8e2fc535b210
Support for half-float attribute arrays.
Ryan C. Gordon <icculus@icculus.org>
parents:
230
diff
changeset
|
784 |
VERIFY_EXT(GL_NV_half_float, -1, -1); |
449
5a978f37e750
Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents:
448
diff
changeset
|
785 |
VERIFY_EXT(GL_ARB_half_float_vertex, 3, 0); |
5a978f37e750
Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents:
448
diff
changeset
|
786 |
VERIFY_EXT(GL_OES_vertex_half_float, -1, -1); |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
787 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
788 |
#undef VERIFY_EXT |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
789 |
} // load_extensions |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
790 |
|
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
791 |
|
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
792 |
static int valid_profile(const char *profile) |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
793 |
{ |
457
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
794 |
// If running on Mac OS X <= 10.4, don't ever pick GLSL, even if |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
795 |
// the system claims it is available. |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
796 |
#if PLATFORM_MACOSX |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
797 |
const int allow_glsl = macosx_version_atleast(10, 5, 0); |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
798 |
#else |
501
314aa5c32820
Fixed wrong value for allow_glsl on non-Mac platforms.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
799 |
const int allow_glsl = 1; |
457
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
800 |
#endif |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
801 |
|
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
802 |
if (!ctx->have_base_opengl) |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
803 |
return 0; |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
804 |
|
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
805 |
#define MUST_HAVE(p, x) \ |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
806 |
if (!ctx->have_##x) { set_error(#p " profile needs " #x); return 0; } |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
807 |
|
291
2453590bae1b
Fix/disable annoying Visual C++ level 4 warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
285
diff
changeset
|
808 |
if (profile == NULL) |
2453590bae1b
Fix/disable annoying Visual C++ level 4 warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
285
diff
changeset
|
809 |
{ |
2453590bae1b
Fix/disable annoying Visual C++ level 4 warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
285
diff
changeset
|
810 |
set_error("NULL profile"); |
2453590bae1b
Fix/disable annoying Visual C++ level 4 warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
285
diff
changeset
|
811 |
return 0; |
2453590bae1b
Fix/disable annoying Visual C++ level 4 warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
285
diff
changeset
|
812 |
} // if |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
813 |
|
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
814 |
#if SUPPORT_PROFILE_ARB1 |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
815 |
else if (strcmp(profile, MOJOSHADER_PROFILE_ARB1) == 0) |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
816 |
{ |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
817 |
MUST_HAVE(MOJOSHADER_PROFILE_ARB1, GL_ARB_vertex_program); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
818 |
MUST_HAVE(MOJOSHADER_PROFILE_ARB1, GL_ARB_fragment_program); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
819 |
} // else if |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
820 |
|
361
9fa6652cacbd
First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
359
diff
changeset
|
821 |
else if (strcmp(profile, MOJOSHADER_PROFILE_NV2) == 0) |
9fa6652cacbd
First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
359
diff
changeset
|
822 |
{ |
9fa6652cacbd
First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
359
diff
changeset
|
823 |
MUST_HAVE(MOJOSHADER_PROFILE_NV2, GL_ARB_vertex_program); |
9fa6652cacbd
First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
359
diff
changeset
|
824 |
MUST_HAVE(MOJOSHADER_PROFILE_NV2, GL_ARB_fragment_program); |
9fa6652cacbd
First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
359
diff
changeset
|
825 |
MUST_HAVE(MOJOSHADER_PROFILE_NV2, GL_NV_vertex_program2_option); |
9fa6652cacbd
First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
359
diff
changeset
|
826 |
MUST_HAVE(MOJOSHADER_PROFILE_NV2, GL_NV_fragment_program2); |
9fa6652cacbd
First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
359
diff
changeset
|
827 |
} // else if |
421
bfd3d95273ec
First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
420
diff
changeset
|
828 |
|
bfd3d95273ec
First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
420
diff
changeset
|
829 |
else if (strcmp(profile, MOJOSHADER_PROFILE_NV3) == 0) |
bfd3d95273ec
First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
420
diff
changeset
|
830 |
{ |
bfd3d95273ec
First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
420
diff
changeset
|
831 |
MUST_HAVE(MOJOSHADER_PROFILE_NV3, GL_ARB_vertex_program); |
bfd3d95273ec
First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
420
diff
changeset
|
832 |
MUST_HAVE(MOJOSHADER_PROFILE_NV3, GL_ARB_fragment_program); |
bfd3d95273ec
First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
420
diff
changeset
|
833 |
MUST_HAVE(MOJOSHADER_PROFILE_NV3, GL_NV_vertex_program3); |
bfd3d95273ec
First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
420
diff
changeset
|
834 |
MUST_HAVE(MOJOSHADER_PROFILE_NV3, GL_NV_fragment_program2); |
bfd3d95273ec
First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
420
diff
changeset
|
835 |
} // else if |
431
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
836 |
|
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
837 |
else if (strcmp(profile, MOJOSHADER_PROFILE_NV4) == 0) |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
838 |
{ |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
839 |
MUST_HAVE(MOJOSHADER_PROFILE_NV4, GL_NV_gpu_program4); |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
840 |
} // else if |
361
9fa6652cacbd
First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
359
diff
changeset
|
841 |
#endif |
9fa6652cacbd
First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
359
diff
changeset
|
842 |
|
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
843 |
#if SUPPORT_PROFILE_GLSL |
457
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
844 |
else if ((allow_glsl) && (strcmp(profile, MOJOSHADER_PROFILE_GLSL120) == 0)) |
407
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
845 |
{ |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
846 |
MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_shader_objects); |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
847 |
MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_vertex_shader); |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
848 |
MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_fragment_shader); |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
849 |
MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_shading_language_100); |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
850 |
// if you got here, you have all the extensions. |
413
618b677f4581
Fixed glsl120 profile test in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
411
diff
changeset
|
851 |
if (!glsl_version_atleast(1, 20)) |
407
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
852 |
return 0; |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
853 |
} // else if |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
854 |
|
457
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
855 |
else if ((allow_glsl) && (strcmp(profile, MOJOSHADER_PROFILE_GLSL) == 0)) |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
856 |
{ |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
857 |
MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_shader_objects); |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
858 |
MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_vertex_shader); |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
859 |
MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_fragment_shader); |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
860 |
MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_shading_language_100); |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
861 |
} // else if |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
862 |
#endif |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
863 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
864 |
else |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
865 |
{ |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
866 |
set_error("unknown or unsupported profile"); |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
867 |
return 0; |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
868 |
} // else |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
869 |
|
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
870 |
#undef MUST_HAVE |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
871 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
872 |
return 1; |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
873 |
} // valid_profile |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
874 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
875 |
|
422
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
876 |
static const char *profile_priorities[] = { |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
877 |
#if SUPPORT_PROFILE_GLSL |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
878 |
MOJOSHADER_PROFILE_GLSL120, |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
879 |
MOJOSHADER_PROFILE_GLSL, |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
880 |
#endif |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
881 |
#if SUPPORT_PROFILE_ARB1 |
431
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
882 |
MOJOSHADER_PROFILE_NV4, |
422
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
883 |
MOJOSHADER_PROFILE_NV3, |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
884 |
MOJOSHADER_PROFILE_NV2, |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
885 |
MOJOSHADER_PROFILE_ARB1, |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
886 |
#endif |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
887 |
}; |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
888 |
|
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
889 |
int MOJOSHADER_glAvailableProfiles(void *(*lookup)(const char *fnname), |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
890 |
const char **profs, const int size) |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
891 |
{ |
422
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
892 |
int retval = 0; |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
893 |
MOJOSHADER_glContext _ctx; |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
894 |
MOJOSHADER_glContext *current_ctx = ctx; |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
895 |
|
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
896 |
ctx = &_ctx; |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
897 |
memset(ctx, '\0', sizeof (MOJOSHADER_glContext)); |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
898 |
load_extensions(lookup); |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
899 |
|
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
900 |
if (ctx->have_base_opengl) |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
901 |
{ |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
902 |
int i; |
422
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
903 |
for (i = 0; i < STATICARRAYLEN(profile_priorities); i++) |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
904 |
{ |
422
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
905 |
const char *profile = profile_priorities[i]; |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
906 |
if (valid_profile(profile)) |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
907 |
{ |
422
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
908 |
if (retval < size) |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
909 |
profs[retval] = profile; |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
910 |
retval++; |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
911 |
} // if |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
912 |
} // for |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
913 |
} // if |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
914 |
|
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
915 |
ctx = current_ctx; |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
916 |
return retval; |
422
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
917 |
} // MOJOSHADER_glAvailableProfiles |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
918 |
|
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
919 |
|
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
920 |
const char *MOJOSHADER_glBestProfile(void *(*lookup)(const char *fnname)) |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
921 |
{ |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
922 |
const char *prof[STATICARRAYLEN(profile_priorities)]; |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
923 |
if (MOJOSHADER_glAvailableProfiles(lookup, prof, STATICARRAYLEN(prof)) <= 0) |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
924 |
{ |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
925 |
set_error("no profiles available"); |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
926 |
return NULL; |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
927 |
} // if |
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
928 |
|
1d5eaf3a4c98
Added MOJOSHADER_glAvailableProfiles().
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
929 |
return prof[0]; // profiles are sorted "best" to "worst." |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
930 |
} // MOJOSHADER_glBestProfile |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
931 |
|
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
932 |
|
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
933 |
MOJOSHADER_glContext *MOJOSHADER_glCreateContext(const char *profile, |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
934 |
void *(*lookup)(const char *fnname), |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
935 |
MOJOSHADER_malloc m, MOJOSHADER_free f, |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
936 |
void *d) |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
937 |
{ |
249
7f928921766c
Cleanups for building as C++ code.
Ryan C. Gordon <icculus@icculus.org>
parents:
246
diff
changeset
|
938 |
MOJOSHADER_glContext *retval = NULL; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
939 |
MOJOSHADER_glContext *current_ctx = ctx; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
940 |
ctx = NULL; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
941 |
|
553
288ed486e5c3
Renamed internal_malloc() and internal_free().
Ryan C. Gordon <icculus@icculus.org>
parents:
537
diff
changeset
|
942 |
if (m == NULL) m = MOJOSHADER_internal_malloc; |
288ed486e5c3
Renamed internal_malloc() and internal_free().
Ryan C. Gordon <icculus@icculus.org>
parents:
537
diff
changeset
|
943 |
if (f == NULL) f = MOJOSHADER_internal_free; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
944 |
|
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
945 |
ctx = (MOJOSHADER_glContext *) m(sizeof (MOJOSHADER_glContext), d); |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
946 |
if (ctx == NULL) |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
947 |
{ |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
948 |
set_error("out of memory"); |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
949 |
goto init_fail; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
950 |
} // if |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
951 |
|
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
952 |
memset(ctx, '\0', sizeof (MOJOSHADER_glContext)); |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
953 |
ctx->malloc_fn = m; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
954 |
ctx->free_fn = f; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
955 |
ctx->malloc_data = d; |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
956 |
snprintf(ctx->profile, sizeof (ctx->profile), "%s", profile); |
219
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
957 |
|
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
958 |
load_extensions(lookup); |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
959 |
if (!valid_profile(profile)) |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
960 |
goto init_fail; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
961 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
962 |
MOJOSHADER_glBindProgram(NULL); |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
963 |
|
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
964 |
// !!! FIXME: generalize this part. |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
965 |
if (profile == NULL) {} |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
966 |
|
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
967 |
#if SUPPORT_PROFILE_GLSL |
407
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
968 |
else if ( (strcmp(profile, MOJOSHADER_PROFILE_GLSL) == 0) || |
620d48c5d13a
Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
969 |
(strcmp(profile, MOJOSHADER_PROFILE_GLSL120) == 0) ) |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
970 |
{ |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
971 |
ctx->profileMaxUniforms = impl_GLSL_MaxUniforms; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
972 |
ctx->profileCompileShader = impl_GLSL_CompileShader; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
973 |
ctx->profileDeleteShader = impl_GLSL_DeleteShader; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
974 |
ctx->profileDeleteProgram = impl_GLSL_DeleteProgram; |
347
f8d9d0ae6ba8
Bunch more work (ARB1 profile, OpenGL glue, and general fixes).
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
975 |
ctx->profileGetAttribLocation = impl_GLSL_GetAttribLocation; |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
976 |
ctx->profileGetUniformLocation = impl_GLSL_GetUniformLocation; |
347
f8d9d0ae6ba8
Bunch more work (ARB1 profile, OpenGL glue, and general fixes).
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
977 |
ctx->profileGetSamplerLocation = impl_GLSL_GetSamplerLocation; |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
978 |
ctx->profileLinkProgram = impl_GLSL_LinkProgram; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
979 |
ctx->profileUseProgramObject = impl_GLSL_UseProgramObject; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
980 |
ctx->profileUniform4fv = impl_GLSL_Uniform4fv; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
981 |
ctx->profileUniform4iv = impl_GLSL_Uniform4iv; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
982 |
ctx->profileUniform1i = impl_GLSL_Uniform1i; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
983 |
ctx->profileSetSampler = impl_GLSL_SetSampler; |
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
|
984 |
ctx->profileMustLoadConstantArrays = impl_GLSL_MustLoadConstantArrays; |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
985 |
} // if |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
986 |
#endif |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
987 |
|
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
988 |
#if SUPPORT_PROFILE_ARB1 |
361
9fa6652cacbd
First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
359
diff
changeset
|
989 |
else if ( (strcmp(profile, MOJOSHADER_PROFILE_ARB1) == 0) || |
421
bfd3d95273ec
First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
420
diff
changeset
|
990 |
(strcmp(profile, MOJOSHADER_PROFILE_NV2) == 0) || |
431
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
991 |
(strcmp(profile, MOJOSHADER_PROFILE_NV3) == 0) || |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
992 |
(strcmp(profile, MOJOSHADER_PROFILE_NV4) == 0) ) |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
993 |
{ |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
994 |
ctx->profileMaxUniforms = impl_ARB1_MaxUniforms; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
995 |
ctx->profileCompileShader = impl_ARB1_CompileShader; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
996 |
ctx->profileDeleteShader = impl_ARB1_DeleteShader; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
997 |
ctx->profileDeleteProgram = impl_ARB1_DeleteProgram; |
347
f8d9d0ae6ba8
Bunch more work (ARB1 profile, OpenGL glue, and general fixes).
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
998 |
ctx->profileGetAttribLocation = impl_ARB1_GetAttribLocation; |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
999 |
ctx->profileGetUniformLocation = impl_ARB1_GetUniformLocation; |
347
f8d9d0ae6ba8
Bunch more work (ARB1 profile, OpenGL glue, and general fixes).
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
1000 |
ctx->profileGetSamplerLocation = impl_ARB1_GetSamplerLocation; |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1001 |
ctx->profileLinkProgram = impl_ARB1_LinkProgram; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1002 |
ctx->profileUseProgramObject = impl_ARB1_UseProgramObject; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1003 |
ctx->profileUniform4fv = impl_ARB1_Uniform4fv; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1004 |
ctx->profileUniform4iv = impl_ARB1_Uniform4iv; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1005 |
ctx->profileUniform1i = impl_ARB1_Uniform1i; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1006 |
ctx->profileSetSampler = impl_ARB1_SetSampler; |
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
|
1007 |
ctx->profileMustLoadConstantArrays = impl_ARB1_MustLoadConstantArrays; |
431
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
1008 |
|
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
1009 |
// GL_NV_gpu_program4 has integer uniform loading support. |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
1010 |
if (strcmp(profile, MOJOSHADER_PROFILE_NV4) == 0) |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
1011 |
{ |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
1012 |
ctx->profileUniform4iv = impl_NV4_Uniform4iv; |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
1013 |
ctx->profileUniform1i = impl_NV4_Uniform1i; |
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
1014 |
} // if |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
1015 |
} // if |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
1016 |
#endif |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
1017 |
|
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
1018 |
assert(ctx->profileMaxUniforms != NULL); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
1019 |
assert(ctx->profileCompileShader != NULL); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
1020 |
assert(ctx->profileDeleteShader != NULL); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
1021 |
assert(ctx->profileDeleteProgram != NULL); |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1022 |
assert(ctx->profileMaxUniforms != NULL); |
347
f8d9d0ae6ba8
Bunch more work (ARB1 profile, OpenGL glue, and general fixes).
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
1023 |
assert(ctx->profileGetAttribLocation != NULL); |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1024 |
assert(ctx->profileGetUniformLocation != NULL); |
347
f8d9d0ae6ba8
Bunch more work (ARB1 profile, OpenGL glue, and general fixes).
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
1025 |
assert(ctx->profileGetSamplerLocation != NULL); |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1026 |
assert(ctx->profileLinkProgram != NULL); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1027 |
assert(ctx->profileUseProgramObject != NULL); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1028 |
assert(ctx->profileUniform4fv != NULL); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1029 |
assert(ctx->profileUniform4iv != NULL); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1030 |
assert(ctx->profileUniform1i != NULL); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1031 |
assert(ctx->profileSetSampler != NULL); |
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
|
1032 |
assert(ctx->profileMustLoadConstantArrays != NULL); |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
1033 |
|
249
7f928921766c
Cleanups for building as C++ code.
Ryan C. Gordon <icculus@icculus.org>
parents:
246
diff
changeset
|
1034 |
retval = ctx; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1035 |
ctx = current_ctx; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1036 |
return retval; |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
1037 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
1038 |
init_fail: |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1039 |
if (ctx != NULL) |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1040 |
f(ctx, d); |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1041 |
ctx = current_ctx; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1042 |
return NULL; |
238
e98f14da2897
Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents:
237
diff
changeset
|
1043 |
} // MOJOSHADER_glCreateContext |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1044 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1045 |
|
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1046 |
void MOJOSHADER_glMakeContextCurrent(MOJOSHADER_glContext *_ctx) |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1047 |
{ |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1048 |
ctx = _ctx; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1049 |
} // MOJOSHADER_glMakeContextCurrent |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1050 |
|
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1051 |
|
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
1052 |
int MOJOSHADER_glMaxUniforms(MOJOSHADER_shaderType shader_type) |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
1053 |
{ |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
1054 |
return ctx->profileMaxUniforms(shader_type); |
276
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
1055 |
} // MOJOSHADER_glMaxUniforms |
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
1056 |
|
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
1057 |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1058 |
MOJOSHADER_glShader *MOJOSHADER_glCompileShader(const unsigned char *tokenbuf, |
450
6a9faf398c1d
Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
449
diff
changeset
|
1059 |
const unsigned int bufsize, |
6a9faf398c1d
Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
449
diff
changeset
|
1060 |
const MOJOSHADER_swizzle *swiz, |
6a9faf398c1d
Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
449
diff
changeset
|
1061 |
const unsigned int swizcount) |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1062 |
{ |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1063 |
MOJOSHADER_glShader *retval = NULL; |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
1064 |
GLuint shader = 0; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1065 |
const MOJOSHADER_parseData *pd = MOJOSHADER_parse(ctx->profile, tokenbuf, |
450
6a9faf398c1d
Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
449
diff
changeset
|
1066 |
bufsize, swiz, swizcount, |
6a9faf398c1d
Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
449
diff
changeset
|
1067 |
ctx->malloc_fn, |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1068 |
ctx->free_fn, |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1069 |
ctx->malloc_data); |
537 | 1070 |
if (pd->error_count > 0) |
219
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
1071 |
{ |
536
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
533
diff
changeset
|
1072 |
set_error(pd->errors[0].error); |
207
d9cee469e080
Cleaned up GLSL shader compile code with some gotos.
Ryan C. Gordon <icculus@icculus.org>
parents:
206
diff
changeset
|
1073 |
goto compile_shader_fail; |
219
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
1074 |
} // if |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1075 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1076 |
retval = (MOJOSHADER_glShader *) Malloc(sizeof (MOJOSHADER_glShader)); |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1077 |
if (retval == NULL) |
207
d9cee469e080
Cleaned up GLSL shader compile code with some gotos.
Ryan C. Gordon <icculus@icculus.org>
parents:
206
diff
changeset
|
1078 |
goto compile_shader_fail; |
d9cee469e080
Cleaned up GLSL shader compile code with some gotos.
Ryan C. Gordon <icculus@icculus.org>
parents:
206
diff
changeset
|
1079 |
|
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
1080 |
if (!ctx->profileCompileShader(pd, &shader)) |
207
d9cee469e080
Cleaned up GLSL shader compile code with some gotos.
Ryan C. Gordon <icculus@icculus.org>
parents:
206
diff
changeset
|
1081 |
goto compile_shader_fail; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1082 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1083 |
retval->parseData = pd; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1084 |
retval->handle = shader; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1085 |
retval->refcount = 1; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1086 |
return retval; |
207
d9cee469e080
Cleaned up GLSL shader compile code with some gotos.
Ryan C. Gordon <icculus@icculus.org>
parents:
206
diff
changeset
|
1087 |
|
d9cee469e080
Cleaned up GLSL shader compile code with some gotos.
Ryan C. Gordon <icculus@icculus.org>
parents:
206
diff
changeset
|
1088 |
compile_shader_fail: |
d9cee469e080
Cleaned up GLSL shader compile code with some gotos.
Ryan C. Gordon <icculus@icculus.org>
parents:
206
diff
changeset
|
1089 |
MOJOSHADER_freeParseData(pd); |
d9cee469e080
Cleaned up GLSL shader compile code with some gotos.
Ryan C. Gordon <icculus@icculus.org>
parents:
206
diff
changeset
|
1090 |
Free(retval); |
d9cee469e080
Cleaned up GLSL shader compile code with some gotos.
Ryan C. Gordon <icculus@icculus.org>
parents:
206
diff
changeset
|
1091 |
if (shader != 0) |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
1092 |
ctx->profileDeleteShader(shader); |
207
d9cee469e080
Cleaned up GLSL shader compile code with some gotos.
Ryan C. Gordon <icculus@icculus.org>
parents:
206
diff
changeset
|
1093 |
return NULL; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1094 |
} // MOJOSHADER_glCompileShader |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1095 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1096 |
|
245
1f04b805a4f2
Added MOJOSHADER_glGetShaderParseData().
Ryan C. Gordon <icculus@icculus.org>
parents:
243
diff
changeset
|
1097 |
const MOJOSHADER_parseData *MOJOSHADER_glGetShaderParseData( |
1f04b805a4f2
Added MOJOSHADER_glGetShaderParseData().
Ryan C. Gordo |