author | Ryan C. Gordon <icculus@icculus.org> |
Wed, 28 May 2008 10:27:47 -0400 | |
branch | trunk |
changeset 334 | 5aebcea77f47 |
parent 333 | 2b36a1d72fa1 |
child 339 | 4b1e0c45a6b8 |
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. |
|
19 |
#endif |
|
20 |
||
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
21 |
#include "mojoshader.h" |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
22 |
#define GL_GLEXT_LEGACY 1 |
246
897868fdd958
Moved gl*.h into GL directory.
Ryan C. Gordon <icculus@icculus.org>
parents:
245
diff
changeset
|
23 |
#include "GL/gl.h" |
897868fdd958
Moved gl*.h into GL directory.
Ryan C. Gordon <icculus@icculus.org>
parents:
245
diff
changeset
|
24 |
#include "GL/glext.h" |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 |
// Get basic wankery out of the way here... |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 |
|
250 | 28 |
typedef unsigned int uint; // this is a printf() helper. don't use for code. |
208
30fe7b63db09
Added STATICARRAYLEN macro to mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
207
diff
changeset
|
29 |
|
250 | 30 |
#ifdef _MSC_VER |
31 |
#define snprintf _snprintf |
|
32 |
typedef unsigned __int8 uint8; |
|
33 |
typedef unsigned __int32 uint32; |
|
34 |
typedef unsigned __int32 int32; |
|
291
2453590bae1b
Fix/disable annoying Visual C++ level 4 warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
285
diff
changeset
|
35 |
// Warning Level 4 considered harmful. :) |
2453590bae1b
Fix/disable annoying Visual C++ level 4 warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
285
diff
changeset
|
36 |
#pragma warning(disable: 4100) // "unreferenced formal parameter" |
2453590bae1b
Fix/disable annoying Visual C++ level 4 warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
285
diff
changeset
|
37 |
#pragma warning(disable: 4389) // "signed/unsigned mismatch" |
250 | 38 |
#else |
39 |
#include <stdint.h> |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 |
typedef uint8_t uint8; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 |
typedef uint32_t uint32; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 |
typedef int32_t int32; |
250 | 43 |
#endif |
44 |
||
45 |
#define STATICARRAYLEN(x) ( (sizeof ((x))) / (sizeof ((x)[0])) ) |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 |
|
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
47 |
#ifndef SUPPORT_PROFILE_GLSL |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
48 |
#define SUPPORT_PROFILE_GLSL 1 |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
49 |
#endif |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
50 |
|
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
51 |
#ifndef SUPPORT_PROFILE_ARB1 |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
52 |
#define SUPPORT_PROFILE_ARB1 1 |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
53 |
#endif |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
54 |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
55 |
struct MOJOSHADER_glShader |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
56 |
{ |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 |
const MOJOSHADER_parseData *parseData; |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
58 |
GLuint handle; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 |
uint32 refcount; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 |
}; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 |
|
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
62 |
typedef struct |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
63 |
{ |
206
7027d889acdd
Implemented MOJOSHADER_glProgramReady().
Ryan C. Gordon <icculus@icculus.org>
parents:
205
diff
changeset
|
64 |
MOJOSHADER_shaderType shader_type; |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
65 |
const MOJOSHADER_uniform *uniform; |
215
f2e508f08997
Fixed wrong type for uniform/attribute locations.
Ryan C. Gordon <icculus@icculus.org>
parents:
213
diff
changeset
|
66 |
GLuint location; |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
67 |
} UniformMap; |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
68 |
|
213
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
69 |
typedef struct |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
70 |
{ |
284
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
71 |
MOJOSHADER_shaderType shader_type; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
72 |
const MOJOSHADER_sampler *sampler; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
73 |
GLuint location; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
74 |
} SamplerMap; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
75 |
|
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
76 |
typedef struct |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
77 |
{ |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
78 |
const MOJOSHADER_attribute *attribute; |
215
f2e508f08997
Fixed wrong type for uniform/attribute locations.
Ryan C. Gordon <icculus@icculus.org>
parents:
213
diff
changeset
|
79 |
GLuint location; |
213
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
80 |
} AttributeMap; |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
81 |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
82 |
struct MOJOSHADER_glProgram |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
83 |
{ |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
84 |
MOJOSHADER_glShader *vertex; |
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
85 |
MOJOSHADER_glShader *fragment; |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
86 |
GLuint handle; |
281
cb0ee573a33d
OpenGL glue now handles Uniform arrays.
Ryan C. Gordon <icculus@icculus.org>
parents:
277
diff
changeset
|
87 |
uint32 constant_count; // !!! FIXME: misnamed. |
cb0ee573a33d
OpenGL glue now handles Uniform arrays.
Ryan C. Gordon <icculus@icculus.org>
parents:
277
diff
changeset
|
88 |
GLfloat *constants; // !!! FIXME: misnamed. |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
89 |
uint32 uniform_count; |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
90 |
UniformMap *uniforms; |
284
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
91 |
uint32 sampler_count; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
92 |
SamplerMap *samplers; |
213
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
93 |
uint32 attribute_count; |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
94 |
AttributeMap *attributes; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
95 |
uint32 refcount; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
96 |
}; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
97 |
|
277
49a6571cac6d
Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents:
276
diff
changeset
|
98 |
#ifndef WINGDIAPI |
49a6571cac6d
Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents:
276
diff
changeset
|
99 |
#define WINGDIAPI |
49a6571cac6d
Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents:
276
diff
changeset
|
100 |
#endif |
49a6571cac6d
Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents:
276
diff
changeset
|
101 |
|
242
c3c5693ba179
Fixed vertex attribute aliasing in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
241
diff
changeset
|
102 |
// 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
|
103 |
typedef WINGDIAPI void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params); |
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
104 |
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
|
105 |
typedef WINGDIAPI GLenum (APIENTRYP PFNGLGETERRORPROC) (void); |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
106 |
|
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
107 |
struct MOJOSHADER_glContext |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
108 |
{ |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
109 |
// Allocators... |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
110 |
MOJOSHADER_malloc malloc_fn; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
111 |
MOJOSHADER_free free_fn; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
112 |
void *malloc_data; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
113 |
|
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
114 |
// The constant register files... |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
115 |
// 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
|
116 |
GLfloat vs_reg_file_f[8192 * 4]; |
7f928921766c
Cleanups for building as C++ code.
Ryan C. Gordon <icculus@icculus.org>
parents:
246
diff
changeset
|
117 |
GLint vs_reg_file_i[2047 * 4]; |
7f928921766c
Cleanups for building as C++ code.
Ryan C. Gordon <icculus@icculus.org>
parents:
246
diff
changeset
|
118 |
GLint vs_reg_file_b[2047]; |
7f928921766c
Cleanups for building as C++ code.
Ryan C. Gordon <icculus@icculus.org>
parents:
246
diff
changeset
|
119 |
GLfloat ps_reg_file_f[8192 * 4]; |
7f928921766c
Cleanups for building as C++ code.
Ryan C. Gordon <icculus@icculus.org>
parents:
246
diff
changeset
|
120 |
GLint ps_reg_file_i[2047 * 4]; |
7f928921766c
Cleanups for building as C++ code.
Ryan C. Gordon <icculus@icculus.org>
parents:
246
diff
changeset
|
121 |
GLint ps_reg_file_b[2047]; |
284
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
122 |
GLuint sampler_reg_file[16]; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
123 |
|
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
124 |
// GL stuff... |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
125 |
int opengl_major; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
126 |
int opengl_minor; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
127 |
MOJOSHADER_glProgram *bound_program; |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
128 |
char profile[16]; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
129 |
|
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
130 |
// Extensions... |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
131 |
int have_base_opengl; |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
132 |
int have_GL_ARB_vertex_program; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
133 |
int have_GL_ARB_fragment_program; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
134 |
int have_GL_ARB_shader_objects; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
135 |
int have_GL_ARB_vertex_shader; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
136 |
int have_GL_ARB_fragment_shader; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
137 |
int have_GL_ARB_shading_language_100; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
138 |
int have_GL_NV_half_float; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
139 |
|
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
140 |
// Entry points... |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
141 |
PFNGLGETSTRINGPROC glGetString; |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
142 |
PFNGLGETERRORPROC glGetError; |
276
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
143 |
PFNGLGETINTEGERVPROC glGetIntegerv; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
144 |
PFNGLDELETEOBJECTARBPROC glDeleteObject; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
145 |
PFNGLATTACHOBJECTARBPROC glAttachObject; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
146 |
PFNGLCOMPILESHADERARBPROC glCompileShader; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
147 |
PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObject; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
148 |
PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObject; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
149 |
PFNGLDISABLEVERTEXATTRIBARRAYARBPROC glDisableVertexAttribArray; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
150 |
PFNGLENABLEVERTEXATTRIBARRAYARBPROC glEnableVertexAttribArray; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
151 |
PFNGLGETATTRIBLOCATIONARBPROC glGetAttribLocation; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
152 |
PFNGLGETINFOLOGARBPROC glGetInfoLog; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
153 |
PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameteriv; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
154 |
PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocation; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
155 |
PFNGLLINKPROGRAMARBPROC glLinkProgram; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
156 |
PFNGLSHADERSOURCEARBPROC glShaderSource; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
157 |
PFNGLUNIFORM1IARBPROC glUniform1i; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
158 |
PFNGLUNIFORM4FVARBPROC glUniform4fv; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
159 |
PFNGLUNIFORM4IVARBPROC glUniform4iv; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
160 |
PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObject; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
161 |
PFNGLVERTEXATTRIBPOINTERARBPROC glVertexAttribPointer; |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
162 |
PFNGLGETPROGRAMIVARBPROC glGetProgramivARB; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
163 |
PFNGLGETPROGRAMSTRINGARBPROC glGetProgramStringARB; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
164 |
PFNGLPROGRAMENVPARAMETER4FVARBPROC glProgramEnvParameter4fvARB; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
165 |
PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
166 |
PFNGLGENPROGRAMSARBPROC glGenProgramsARB; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
167 |
PFNGLBINDPROGRAMARBPROC glBindProgramARB; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
168 |
PFNGLPROGRAMSTRINGARBPROC glProgramStringARB; |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
169 |
|
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
170 |
// interface for profile-specific things. |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
171 |
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
|
172 |
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
|
173 |
void (*profileDeleteShader)(const GLuint shader); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
174 |
void (*profileDeleteProgram)(const GLuint program); |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
175 |
GLint (*profileGetUniformLocation)(GLuint, const MOJOSHADER_parseData *, int); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
176 |
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
|
177 |
void (*profileUseProgramObject)(MOJOSHADER_glProgram *program); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
178 |
void (*profileUniform4fv)(GLint loc, GLsizei siz, GLfloat *v); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
179 |
void (*profileUniform4iv)(GLint loc, GLsizei siz, GLint *v); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
180 |
void (*profileUniform1i)(GLint loc, GLint v); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
181 |
void (*profileSetSampler)(GLint loc, GLuint sampler); |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
182 |
}; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
183 |
|
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
184 |
// predeclare some profile implementation stuff... |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
185 |
static int impl_GLSL_MaxUniforms(MOJOSHADER_shaderType shader_type); |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
186 |
static int impl_GLSL_CompileShader(const MOJOSHADER_parseData *pd, GLuint *s); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
187 |
static void impl_GLSL_DeleteShader(const GLuint shader); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
188 |
static void impl_GLSL_DeleteProgram(const GLuint program); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
189 |
static GLint impl_GLSL_GetUniformLocation(GLuint, const MOJOSHADER_parseData *, int); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
190 |
static GLuint impl_GLSL_LinkProgram(MOJOSHADER_glShader *, MOJOSHADER_glShader *); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
191 |
static void impl_GLSL_UseProgramObject(MOJOSHADER_glProgram *program); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
192 |
static void impl_GLSL_Uniform4fv(GLint loc, GLsizei siz, GLfloat *v); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
193 |
static void impl_GLSL_Uniform4iv(GLint loc, GLsizei siz, GLint *v); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
194 |
static void impl_GLSL_Uniform1i(GLint loc, GLint v); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
195 |
static void impl_GLSL_SetSampler(GLint loc, GLuint sampler); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
196 |
|
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
197 |
static int impl_ARB1_MaxUniforms(MOJOSHADER_shaderType shader_type); |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
198 |
static int impl_ARB1_CompileShader(const MOJOSHADER_parseData *pd, GLuint *s); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
199 |
static void impl_ARB1_DeleteShader(const GLuint shader); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
200 |
static void impl_ARB1_DeleteProgram(const GLuint program); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
201 |
static GLint impl_ARB1_GetUniformLocation(GLuint, const MOJOSHADER_parseData *, int); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
202 |
static GLuint impl_ARB1_LinkProgram(MOJOSHADER_glShader *, MOJOSHADER_glShader *); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
203 |
static void impl_ARB1_UseProgramObject(MOJOSHADER_glProgram *program); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
204 |
static void impl_ARB1_Uniform4fv(GLint loc, GLsizei siz, GLfloat *v); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
205 |
static void impl_ARB1_Uniform4iv(GLint loc, GLsizei siz, GLint *v); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
206 |
static void impl_ARB1_Uniform1i(GLint loc, GLint v); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
207 |
static void impl_ARB1_SetSampler(GLint loc, GLuint sampler); |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
208 |
|
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
209 |
|
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
210 |
|
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
211 |
static MOJOSHADER_glContext *ctx = NULL; |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
212 |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
213 |
|
219
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
214 |
// Error state... |
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
215 |
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
|
216 |
|
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
217 |
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
|
218 |
{ |
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
219 |
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
|
220 |
} // set_error |
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
221 |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
222 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
223 |
// #define this to force app to supply an allocator, so there's no reference |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
224 |
// to the C runtime's malloc() and free()... |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
225 |
#if MOJOSHADER_FORCE_ALLOCATOR |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
226 |
#define internal_malloc NULL |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
227 |
#define internal_free NULL |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
228 |
#else |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
229 |
static void *internal_malloc(int bytes, void *d) { return malloc(bytes); } |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
230 |
static void internal_free(void *ptr, void *d) { free(ptr); } |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
231 |
#endif |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
232 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
233 |
static inline void *Malloc(const size_t len) |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
234 |
{ |
307
42f6a7ba69e2
Fixes for Visual Studio level 4 compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
291
diff
changeset
|
235 |
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
|
236 |
if (retval == NULL) |
df5ea69833d5
Fixes to Malloc() and Free() in mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
237 |
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
|
238 |
return retval; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
239 |
} // Malloc |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
240 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
241 |
static inline void Free(void *ptr) |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
242 |
{ |
220
df5ea69833d5
Fixes to Malloc() and Free() in mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
243 |
if (ptr != NULL) |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
244 |
ctx->free_fn(ptr, ctx->malloc_data); |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
245 |
} // Free |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
246 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
247 |
|
219
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
248 |
const char *MOJOSHADER_glGetError(void) |
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
249 |
{ |
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
250 |
return error_buffer; |
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
251 |
} // MOJOSHADER_glGetError |
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
252 |
|
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
253 |
|
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
254 |
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
|
255 |
{ |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
256 |
void *retval = NULL; |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
257 |
if (lookup != NULL) |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
258 |
{ |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
259 |
retval = lookup(fn); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
260 |
if (retval == NULL) |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
261 |
{ |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
262 |
char arbfn[64]; |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
263 |
snprintf(arbfn, sizeof (arbfn), "%sARB", fn); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
264 |
retval = lookup(arbfn); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
265 |
} // if |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
266 |
} // if |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
267 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
268 |
if (retval == NULL) |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
269 |
*ext = 0; |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
270 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
271 |
return retval; |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
272 |
} // loadsym |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
273 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
274 |
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
|
275 |
{ |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
276 |
#define DO_LOOKUP(ext, typ, fn) ctx->fn = (typ) loadsym(lookup, #fn, &ctx->have_##ext) |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
277 |
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
|
278 |
DO_LOOKUP(base_opengl, PFNGLGETERRORPROC, glGetError); |
276
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
279 |
DO_LOOKUP(base_opengl, PFNGLGETINTEGERVPROC, glGetIntegerv); |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
280 |
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
|
281 |
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
|
282 |
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
|
283 |
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
|
284 |
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
|
285 |
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
|
286 |
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
|
287 |
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
|
288 |
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
|
289 |
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
|
290 |
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
|
291 |
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
|
292 |
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
|
293 |
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
|
294 |
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
|
295 |
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
|
296 |
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
|
297 |
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
|
298 |
DO_LOOKUP(GL_ARB_vertex_program, PFNGLUSEPROGRAMOBJECTARBPROC, glUseProgramObject); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
299 |
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
|
300 |
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
|
301 |
DO_LOOKUP(GL_ARB_vertex_program, PFNGLGETPROGRAMSTRINGARBPROC, glGetProgramStringARB); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
302 |
DO_LOOKUP(GL_ARB_vertex_program, PFNGLPROGRAMENVPARAMETER4FVARBPROC, glProgramEnvParameter4fvARB); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
303 |
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
|
304 |
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
|
305 |
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
|
306 |
DO_LOOKUP(GL_ARB_vertex_program, PFNGLPROGRAMSTRINGARBPROC, glProgramStringARB); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
307 |
|
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
308 |
#undef DO_LOOKUP |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
309 |
} // lookup_entry_points |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
310 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
311 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
312 |
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
|
313 |
int major, int minor) |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
314 |
{ |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
315 |
if (have == 0) |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
316 |
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
|
317 |
|
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
318 |
else if (!ctx->have_base_opengl) |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
319 |
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
|
320 |
|
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
321 |
// 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
|
322 |
if (major >= 0) |
8e2fc535b210
Support for half-float attribute arrays.
Ryan C. Gordon <icculus@icculus.org>
parents:
230
diff
changeset
|
323 |
{ |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
324 |
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
|
325 |
((major << 16) | (minor & 0xFFFF)) ) |
8e2fc535b210
Support for half-float attribute arrays.
Ryan C. Gordon <icculus@icculus.org>
parents:
230
diff
changeset
|
326 |
return 1; |
8e2fc535b210
Support for half-float attribute arrays.
Ryan C. Gordon <icculus@icculus.org>
parents:
230
diff
changeset
|
327 |
} // if |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
328 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
329 |
// 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
|
330 |
const char *ptr = strstr(extlist, ext); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
331 |
if (ptr == NULL) |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
332 |
return 0; |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
333 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
334 |
const char endchar = ptr[strlen(ext)]; |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
335 |
if ((endchar == '\0') || (endchar == ' ')) |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
336 |
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
|
337 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
338 |
return 0; // just not supported, fail. |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
339 |
} // verify_extension |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
340 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
341 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
342 |
static void parse_opengl_version(const char *verstr) |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
343 |
{ |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
344 |
if (verstr == NULL) |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
345 |
ctx->opengl_major = ctx->opengl_minor = 0; |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
346 |
else |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
347 |
sscanf(verstr, "%d.%d", &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
|
348 |
} // parse_opengl_version |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
349 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
350 |
|
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
351 |
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
|
352 |
{ |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
353 |
const char *extlist = NULL; |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
354 |
|
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
355 |
ctx->have_base_opengl = 1; |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
356 |
ctx->have_GL_ARB_vertex_program = 1; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
357 |
ctx->have_GL_ARB_fragment_program = 1; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
358 |
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
|
359 |
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
|
360 |
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
|
361 |
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
|
362 |
ctx->have_GL_NV_half_float = 1; |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
363 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
364 |
lookup_entry_points(lookup); |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
365 |
|
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
366 |
if (!ctx->have_base_opengl) |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
367 |
set_error("missing basic OpenGL entry points"); |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
368 |
else |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
369 |
{ |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
370 |
parse_opengl_version((const char *) ctx->glGetString(GL_VERSION)); |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
371 |
extlist = (const char *) ctx->glGetString(GL_EXTENSIONS); |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
372 |
} // else |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
373 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
374 |
if (extlist == NULL) |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
375 |
extlist = ""; // just in case. |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
376 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
377 |
#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
|
378 |
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
|
379 |
|
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
380 |
VERIFY_EXT(GL_ARB_vertex_program, -1, -1); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
381 |
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
|
382 |
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
|
383 |
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
|
384 |
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
|
385 |
VERIFY_EXT(GL_ARB_shading_language_100, 2, 0); |
236
8e2fc535b210
Support for half-float attribute arrays.
Ryan C. Gordon <icculus@icculus.org>
parents:
230
diff
changeset
|
386 |
VERIFY_EXT(GL_NV_half_float, -1, -1); |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
387 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
388 |
#undef VERIFY_EXT |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
389 |
} // load_extensions |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
390 |
|
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
391 |
|
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
392 |
static int valid_profile(const char *profile) |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
393 |
{ |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
394 |
if (!ctx->have_base_opengl) |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
395 |
return 0; |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
396 |
|
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
397 |
#define MUST_HAVE(p, x) \ |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
398 |
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
|
399 |
|
291
2453590bae1b
Fix/disable annoying Visual C++ level 4 warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
285
diff
changeset
|
400 |
if (profile == NULL) |
2453590bae1b
Fix/disable annoying Visual C++ level 4 warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
285
diff
changeset
|
401 |
{ |
2453590bae1b
Fix/disable annoying Visual C++ level 4 warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
285
diff
changeset
|
402 |
set_error("NULL profile"); |
2453590bae1b
Fix/disable annoying Visual C++ level 4 warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
285
diff
changeset
|
403 |
return 0; |
2453590bae1b
Fix/disable annoying Visual C++ level 4 warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
285
diff
changeset
|
404 |
} // if |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
405 |
|
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
406 |
#if SUPPORT_PROFILE_ARB1 |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
407 |
else if (strcmp(profile, MOJOSHADER_PROFILE_ARB1) == 0) |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
408 |
{ |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
409 |
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
|
410 |
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
|
411 |
} // else if |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
412 |
#endif |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
413 |
|
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
414 |
#if SUPPORT_PROFILE_GLSL |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
415 |
else if (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
|
416 |
{ |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
417 |
MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_shader_objects); |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
418 |
MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_vertex_shader); |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
419 |
MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_fragment_shader); |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
420 |
MUST_HAVE(MOJOSHADER_PROFILE_GLSL, GL_ARB_shading_language_100); |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
421 |
} // else if |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
422 |
#endif |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
423 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
424 |
else |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
425 |
{ |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
426 |
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
|
427 |
return 0; |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
428 |
} // else |
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
429 |
|
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
430 |
#undef MUST_HAVE |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
431 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
432 |
return 1; |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
433 |
} // valid_profile |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
434 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
435 |
|
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
436 |
const char *MOJOSHADER_glBestProfile(void *(*lookup)(const char *fnname)) |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
437 |
{ |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
438 |
const char *retval = NULL; |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
439 |
MOJOSHADER_glContext _ctx; |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
440 |
MOJOSHADER_glContext *current_ctx = ctx; |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
441 |
|
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
442 |
ctx = &_ctx; |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
443 |
memset(ctx, '\0', sizeof (MOJOSHADER_glContext)); |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
444 |
load_extensions(lookup); |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
445 |
|
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
446 |
if (ctx->have_base_opengl) |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
447 |
{ |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
448 |
static const char *priority[] = { |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
449 |
MOJOSHADER_PROFILE_GLSL, |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
450 |
MOJOSHADER_PROFILE_ARB1, |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
451 |
}; |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
452 |
|
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
453 |
int i; |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
454 |
for (i = 0; i < STATICARRAYLEN(priority); i++) |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
455 |
{ |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
456 |
// !!! FIXME: if Mac OS X <= 10.4, don't ever pick GLSL, even if |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
457 |
// !!! FIXME: the system claims it is available. |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
458 |
if (valid_profile(priority[i])) |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
459 |
{ |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
460 |
retval = priority[i]; |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
461 |
break; |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
462 |
} // if |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
463 |
} // for |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
464 |
|
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
465 |
if (retval == NULL) |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
466 |
set_error("no profiles available"); |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
467 |
} // if |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
468 |
|
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
469 |
ctx = current_ctx; |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
470 |
return retval; |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
471 |
} // MOJOSHADER_glBestProfile |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
472 |
|
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
473 |
|
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
474 |
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
|
475 |
void *(*lookup)(const char *fnname), |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
476 |
MOJOSHADER_malloc m, MOJOSHADER_free f, |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
477 |
void *d) |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
478 |
{ |
249
7f928921766c
Cleanups for building as C++ code.
Ryan C. Gordon <icculus@icculus.org>
parents:
246
diff
changeset
|
479 |
MOJOSHADER_glContext *retval = NULL; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
480 |
MOJOSHADER_glContext *current_ctx = ctx; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
481 |
ctx = NULL; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
482 |
|
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
483 |
if (m == NULL) m = internal_malloc; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
484 |
if (f == NULL) f = internal_free; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
485 |
|
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
486 |
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
|
487 |
if (ctx == NULL) |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
488 |
{ |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
489 |
set_error("out of memory"); |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
490 |
goto init_fail; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
491 |
} // if |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
492 |
|
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
493 |
memset(ctx, '\0', sizeof (MOJOSHADER_glContext)); |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
494 |
ctx->malloc_fn = m; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
495 |
ctx->free_fn = f; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
496 |
ctx->malloc_data = d; |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
497 |
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
|
498 |
|
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
499 |
load_extensions(lookup); |
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
500 |
if (!valid_profile(profile)) |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
501 |
goto init_fail; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
502 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
503 |
MOJOSHADER_glBindProgram(NULL); |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
504 |
|
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
505 |
// !!! FIXME: generalize this part. |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
506 |
if (profile == NULL) {} |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
507 |
|
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
508 |
#if SUPPORT_PROFILE_GLSL |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
509 |
else if (strcmp(profile, MOJOSHADER_PROFILE_GLSL) == 0) |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
510 |
{ |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
511 |
ctx->profileMaxUniforms = impl_GLSL_MaxUniforms; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
512 |
ctx->profileCompileShader = impl_GLSL_CompileShader; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
513 |
ctx->profileDeleteShader = impl_GLSL_DeleteShader; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
514 |
ctx->profileDeleteProgram = impl_GLSL_DeleteProgram; |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
515 |
ctx->profileGetUniformLocation = impl_GLSL_GetUniformLocation; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
516 |
ctx->profileLinkProgram = impl_GLSL_LinkProgram; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
517 |
ctx->profileUseProgramObject = impl_GLSL_UseProgramObject; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
518 |
ctx->profileUniform4fv = impl_GLSL_Uniform4fv; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
519 |
ctx->profileUniform4iv = impl_GLSL_Uniform4iv; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
520 |
ctx->profileUniform1i = impl_GLSL_Uniform1i; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
521 |
ctx->profileSetSampler = impl_GLSL_SetSampler; |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
522 |
} // if |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
523 |
#endif |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
524 |
|
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
525 |
#if SUPPORT_PROFILE_ARB1 |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
526 |
else if (strcmp(profile, MOJOSHADER_PROFILE_ARB1) == 0) |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
527 |
{ |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
528 |
ctx->profileMaxUniforms = impl_ARB1_MaxUniforms; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
529 |
ctx->profileCompileShader = impl_ARB1_CompileShader; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
530 |
ctx->profileDeleteShader = impl_ARB1_DeleteShader; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
531 |
ctx->profileDeleteProgram = impl_ARB1_DeleteProgram; |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
532 |
ctx->profileGetUniformLocation = impl_ARB1_GetUniformLocation; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
533 |
ctx->profileLinkProgram = impl_ARB1_LinkProgram; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
534 |
ctx->profileUseProgramObject = impl_ARB1_UseProgramObject; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
535 |
ctx->profileUniform4fv = impl_ARB1_Uniform4fv; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
536 |
ctx->profileUniform4iv = impl_ARB1_Uniform4iv; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
537 |
ctx->profileUniform1i = impl_ARB1_Uniform1i; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
538 |
ctx->profileSetSampler = impl_ARB1_SetSampler; |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
539 |
} // if |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
540 |
#endif |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
541 |
|
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
542 |
assert(ctx->profileMaxUniforms != NULL); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
543 |
assert(ctx->profileCompileShader != NULL); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
544 |
assert(ctx->profileDeleteShader != NULL); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
545 |
assert(ctx->profileDeleteProgram != NULL); |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
546 |
assert(ctx->profileMaxUniforms != NULL); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
547 |
assert(ctx->profileCompileShader != NULL); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
548 |
assert(ctx->profileDeleteShader != NULL); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
549 |
assert(ctx->profileDeleteProgram != NULL); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
550 |
assert(ctx->profileGetUniformLocation != NULL); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
551 |
assert(ctx->profileLinkProgram != NULL); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
552 |
assert(ctx->profileUseProgramObject != NULL); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
553 |
assert(ctx->profileUniform4fv != NULL); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
554 |
assert(ctx->profileUniform4iv != NULL); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
555 |
assert(ctx->profileUniform1i != NULL); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
556 |
assert(ctx->profileSetSampler != NULL); |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
557 |
|
249
7f928921766c
Cleanups for building as C++ code.
Ryan C. Gordon <icculus@icculus.org>
parents:
246
diff
changeset
|
558 |
retval = ctx; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
559 |
ctx = current_ctx; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
560 |
return retval; |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
561 |
|
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
562 |
init_fail: |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
563 |
if (ctx != NULL) |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
564 |
f(ctx, d); |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
565 |
ctx = current_ctx; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
566 |
return NULL; |
238
e98f14da2897
Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents:
237
diff
changeset
|
567 |
} // MOJOSHADER_glCreateContext |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
568 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
569 |
|
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
570 |
void MOJOSHADER_glMakeContextCurrent(MOJOSHADER_glContext *_ctx) |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
571 |
{ |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
572 |
ctx = _ctx; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
573 |
} // MOJOSHADER_glMakeContextCurrent |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
574 |
|
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
575 |
|
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
576 |
static int impl_GLSL_MaxUniforms(MOJOSHADER_shaderType shader_type) |
276
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
577 |
{ |
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
578 |
GLenum pname = GL_NONE; |
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
579 |
GLint val = 0; |
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
580 |
if (shader_type == MOJOSHADER_TYPE_VERTEX) |
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
581 |
pname = GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB; |
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
582 |
else if (shader_type == MOJOSHADER_TYPE_PIXEL) |
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
583 |
pname = GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB; |
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
584 |
else |
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
585 |
return -1; |
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
586 |
|
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
587 |
ctx->glGetIntegerv(pname, &val); |
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
588 |
return (int) val; |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
589 |
} // impl_GLSL_MaxUniforms |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
590 |
|
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
591 |
|
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
592 |
static int impl_ARB1_MaxUniforms(MOJOSHADER_shaderType shader_type) |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
593 |
{ |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
594 |
GLint retval = 0; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
595 |
GLenum program_type = GL_NONE; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
596 |
if (shader_type == MOJOSHADER_TYPE_VERTEX) |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
597 |
program_type = GL_VERTEX_PROGRAM_ARB; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
598 |
else if (shader_type == MOJOSHADER_TYPE_PIXEL) |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
599 |
program_type = GL_FRAGMENT_PROGRAM_ARB; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
600 |
else |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
601 |
return -1; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
602 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
603 |
ctx->glGetProgramivARB(program_type, GL_MAX_PROGRAM_PARAMETERS_ARB, &retval); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
604 |
return (int) retval; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
605 |
} // impl_ARB1_MaxUniforms |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
606 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
607 |
|
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
608 |
int MOJOSHADER_glMaxUniforms(MOJOSHADER_shaderType shader_type) |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
609 |
{ |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
610 |
return ctx->profileMaxUniforms(shader_type); |
276
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
611 |
} // MOJOSHADER_glMaxUniforms |
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
612 |
|
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
613 |
|
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
614 |
static int impl_GLSL_CompileShader(const MOJOSHADER_parseData *pd, GLuint *s) |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
615 |
{ |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
616 |
GLint ok = 0; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
617 |
GLint shaderlen = (GLint) pd->output_len; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
618 |
const GLenum shader_type = (pd->shader_type == MOJOSHADER_TYPE_PIXEL) ? GL_FRAGMENT_SHADER : GL_VERTEX_SHADER; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
619 |
GLuint shader = ctx->glCreateShaderObject(shader_type); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
620 |
|
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
621 |
ctx->glShaderSource(shader, 1, (const GLchar **) &pd->output, &shaderlen); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
622 |
ctx->glCompileShader(shader); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
623 |
ctx->glGetObjectParameteriv(shader, GL_OBJECT_COMPILE_STATUS_ARB, &ok); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
624 |
|
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
625 |
if (!ok) |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
626 |
{ |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
627 |
GLsizei len = 0; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
628 |
ctx->glGetInfoLog(shader, sizeof (error_buffer), &len, |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
629 |
(GLchar *) error_buffer); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
630 |
*s = 0; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
631 |
return 0; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
632 |
} // if |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
633 |
|
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
634 |
*s = shader; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
635 |
return 1; |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
636 |
} // impl_GLSL_CompileShader |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
637 |
|
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
638 |
|
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
639 |
static int impl_ARB1_CompileShader(const MOJOSHADER_parseData *pd, GLuint *s) |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
640 |
{ |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
641 |
GLint shaderlen = (GLint) pd->output_len; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
642 |
const GLenum shader_type = (pd->shader_type == MOJOSHADER_TYPE_PIXEL) ? GL_FRAGMENT_PROGRAM_ARB : GL_VERTEX_PROGRAM_ARB; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
643 |
GLuint shader = 0; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
644 |
ctx->glGenProgramsARB(1, &shader); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
645 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
646 |
ctx->glGetError(); // flush any existing error state. |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
647 |
ctx->glBindProgramARB(shader_type, shader); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
648 |
ctx->glProgramStringARB(shader_type, GL_PROGRAM_FORMAT_ASCII_ARB, |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
649 |
shaderlen, pd->output); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
650 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
651 |
if (ctx->glGetError() == GL_INVALID_OPERATION) |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
652 |
{ |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
653 |
GLint pos = 0; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
654 |
ctx->glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
655 |
const GLubyte *errstr = ctx->glGetString(GL_PROGRAM_ERROR_STRING_ARB); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
656 |
snprintf(error_buffer, sizeof (error_buffer), |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
657 |
"ARB1 compile error at position %d: %s", |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
658 |
(int) pos, (const char *) errstr); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
659 |
ctx->glBindProgramARB(shader_type, 0); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
660 |
ctx->glDeleteProgramsARB(1, &shader); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
661 |
*s = 0; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
662 |
return 0; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
663 |
} // if |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
664 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
665 |
*s = shader; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
666 |
return 1; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
667 |
} // impl_ARB1_CompileShader |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
668 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
669 |
|
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
670 |
static void impl_GLSL_DeleteShader(const GLuint shader) |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
671 |
{ |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
672 |
ctx->glDeleteObject(shader); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
673 |
} // impl_GLSL_DeleteShader |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
674 |
|
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
675 |
|
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
676 |
static void impl_ARB1_DeleteShader(const GLuint _shader) |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
677 |
{ |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
678 |
GLuint shader = _shader; // const removal. |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
679 |
ctx->glDeleteProgramsARB(1, &shader); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
680 |
} // impl_ARB1_DeleteShader |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
681 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
682 |
|
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
683 |
static void impl_GLSL_DeleteProgram(const GLuint program) |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
684 |
{ |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
685 |
ctx->glDeleteObject(program); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
686 |
} // impl_GLSL_DeleteProgram |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
687 |
|
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
688 |
|
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
689 |
static void impl_ARB1_DeleteProgram(const GLuint program) |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
690 |
{ |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
691 |
// no-op. ARB1 doesn't have real linked programs. |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
692 |
} // impl_GLSL_DeleteProgram |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
693 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
694 |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
695 |
MOJOSHADER_glShader *MOJOSHADER_glCompileShader(const unsigned char *tokenbuf, |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
696 |
const unsigned int bufsize) |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
697 |
{ |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
698 |
MOJOSHADER_glShader *retval = NULL; |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
699 |
GLuint shader = 0; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
700 |
const MOJOSHADER_parseData *pd = MOJOSHADER_parse(ctx->profile, tokenbuf, |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
701 |
bufsize, ctx->malloc_fn, |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
702 |
ctx->free_fn, |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
703 |
ctx->malloc_data); |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
704 |
if (pd->error != NULL) |
219
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
705 |
{ |
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
706 |
set_error(pd->error); |
207
d9cee469e080
Cleaned up GLSL shader compile code with some gotos.
Ryan C. Gordon <icculus@icculus.org>
parents:
206
diff
changeset
|
707 |
goto compile_shader_fail; |
219
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
708 |
} // if |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
709 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
710 |
retval = (MOJOSHADER_glShader *) Malloc(sizeof (MOJOSHADER_glShader)); |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
711 |
if (retval == NULL) |
207
d9cee469e080
Cleaned up GLSL shader compile code with some gotos.
Ryan C. Gordon <icculus@icculus.org>
parents:
206
diff
changeset
|
712 |
goto compile_shader_fail; |
d9cee469e080
Cleaned up GLSL shader compile code with some gotos.
Ryan C. Gordon <icculus@icculus.org>
parents:
206
diff
changeset
|
713 |
|
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
714 |
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
|
715 |
goto compile_shader_fail; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
716 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
717 |
retval->parseData = pd; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
718 |
retval->handle = shader; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
719 |
retval->refcount = 1; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
720 |
return retval; |
207
d9cee469e080
Cleaned up GLSL shader compile code with some gotos.
Ryan C. Gordon <icculus@icculus.org>
parents:
206
diff
changeset
|
721 |
|
d9cee469e080
Cleaned up GLSL shader compile code with some gotos.
Ryan C. Gordon <icculus@icculus.org>
parents:
206
diff
changeset
|
722 |
compile_shader_fail: |
d9cee469e080
Cleaned up GLSL shader compile code with some gotos.
Ryan C. Gordon <icculus@icculus.org>
parents:
206
diff
changeset
|
723 |
MOJOSHADER_freeParseData(pd); |
d9cee469e080
Cleaned up GLSL shader compile code with some gotos.
Ryan C. Gordon <icculus@icculus.org>
parents:
206
diff
changeset
|
724 |
Free(retval); |
d9cee469e080
Cleaned up GLSL shader compile code with some gotos.
Ryan C. Gordon <icculus@icculus.org>
parents:
206
diff
changeset
|
725 |
if (shader != 0) |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
726 |
ctx->profileDeleteShader(shader); |
207
d9cee469e080
Cleaned up GLSL shader compile code with some gotos.
Ryan C. Gordon <icculus@icculus.org>
parents:
206
diff
changeset
|
727 |
return NULL; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
728 |
} // MOJOSHADER_glCompileShader |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
729 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
730 |
|
245
1f04b805a4f2
Added MOJOSHADER_glGetShaderParseData().
Ryan C. Gordon <icculus@icculus.org>
parents:
243
diff
changeset
|
731 |
const MOJOSHADER_parseData *MOJOSHADER_glGetShaderParseData( |
1f04b805a4f2
Added MOJOSHADER_glGetShaderParseData().
Ryan C. Gordon <icculus@icculus.org>
parents:
243
diff
changeset
|
732 |
MOJOSHADER_glShader *shader) |
1f04b805a4f2
Added MOJOSHADER_glGetShaderParseData().
Ryan C. Gordon <icculus@icculus.org>
parents:
243
diff
changeset
|
733 |
{ |
1f04b805a4f2
Added MOJOSHADER_glGetShaderParseData().
Ryan C. Gordon <icculus@icculus.org>
parents:
243
diff
changeset
|
734 |
return (shader != NULL) ? shader->parseData : NULL; |
1f04b805a4f2
Added MOJOSHADER_glGetShaderParseData().
Ryan C. Gordon <icculus@icculus.org>
parents:
243
diff
changeset
|
735 |
} // MOJOSHADER_glGetShaderParseData |
1f04b805a4f2
Added MOJOSHADER_glGetShaderParseData().
Ryan C. Gordon <icculus@icculus.org>
parents:
243
diff
changeset
|
736 |
|
1f04b805a4f2
Added MOJOSHADER_glGetShaderParseData().
Ryan C. Gordon <icculus@icculus.org>
parents:
243
diff
changeset
|
737 |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
738 |
static void shader_unref(MOJOSHADER_glShader *shader) |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
739 |
{ |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
740 |
if (shader != NULL) |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
741 |
{ |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
742 |
const uint32 refcount = shader->refcount; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
743 |
if (refcount > 1) |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
744 |
shader->refcount--; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
745 |
else |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
746 |
{ |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
747 |
ctx->profileDeleteShader(shader->handle); |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
748 |
MOJOSHADER_freeParseData(shader->parseData); |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
749 |
Free(shader); |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
750 |
} // else |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
751 |
} // if |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
752 |
} // shader_unref |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
753 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
754 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
755 |
static void program_unref(MOJOSHADER_glProgram *program) |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
756 |
{ |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
757 |
if (program != NULL) |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
758 |
{ |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
759 |
const uint32 refcount = program->refcount; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
760 |
if (refcount > 1) |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
761 |
program->refcount--; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
762 |
else |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
763 |
{ |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
764 |
ctx->profileDeleteProgram(program->handle); |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
765 |
shader_unref(program->vertex); |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
766 |
shader_unref(program->fragment); |
284
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
767 |
Free(program->constants); |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
768 |
Free(program->samplers); |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
769 |
Free(program->uniforms); |
284
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
770 |
Free(program->attributes); |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
771 |
Free(program); |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
772 |
} // else |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
773 |
} // if |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
774 |
} // program_unref |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
775 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
776 |
|
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
777 |
static GLint impl_GLSL_GetUniformLocation(GLuint handle, |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
778 |
const MOJOSHADER_parseData *pd, int idx) |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
779 |
{ |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
780 |
return ctx->glGetUniformLocation(handle, pd->uniforms[idx].name); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
781 |
} // impl_GLSL_GetUniformLocation |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
782 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
783 |
static GLint impl_ARB1_GetUniformLocation(GLuint handle, |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
784 |
const MOJOSHADER_parseData *pd, int idx) |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
785 |
{ |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
786 |
// !!! FIXME: this only works if you have no bool or int uniforms. |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
787 |
return idx; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
788 |
} // impl_ARB1_GetUniformLocation |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
789 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
790 |
|
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
791 |
static void lookup_uniforms(MOJOSHADER_glProgram *program, |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
792 |
MOJOSHADER_glShader *shader) |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
793 |
{ |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
794 |
const MOJOSHADER_parseData *pd = shader->parseData; |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
795 |
const MOJOSHADER_uniform *u = pd->uniforms; |
206
7027d889acdd
Implemented MOJOSHADER_glProgramReady().
Ryan C. Gordon <icculus@icculus.org>
parents:
205
diff
changeset
|
796 |
const MOJOSHADER_shaderType shader_type = pd->shader_type; |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
797 |
const GLuint handle = program->handle; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
798 |
int i; |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
799 |
|
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
800 |
for (i = 0; i < pd->uniform_count; i++) |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
801 |
{ |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
802 |
const GLint loc = ctx->profileGetUniformLocation(handle, pd, i); |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
803 |
if (loc != -1) // maybe the Uniform was optimized out? |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
804 |
{ |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
805 |
UniformMap *map = &program->uniforms[program->uniform_count]; |
206
7027d889acdd
Implemented MOJOSHADER_glProgramReady().
Ryan C. Gordon <icculus@icculus.org>
parents:
205
diff
changeset
|
806 |
map->shader_type = shader_type; |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
807 |
map->uniform = &u[i]; |
215
f2e508f08997
Fixed wrong type for uniform/attribute locations.
Ryan C. Gordon <icculus@icculus.org>
parents:
213
diff
changeset
|
808 |
map->location = (GLuint) loc; |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
809 |
program->uniform_count++; |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
810 |
} // if |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
811 |
} // for |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
812 |
} // lookup_uniforms |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
813 |
|
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
814 |
|
284
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
815 |
static void lookup_samplers(MOJOSHADER_glProgram *program, |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
816 |
MOJOSHADER_glShader *shader) |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
817 |
{ |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
818 |
int i; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
819 |
const MOJOSHADER_parseData *pd = shader->parseData; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
820 |
const MOJOSHADER_sampler *s = pd->samplers; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
821 |
const MOJOSHADER_shaderType shader_type = pd->shader_type; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
822 |
|
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
823 |
for (i = 0; i < pd->sampler_count; i++) |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
824 |
{ |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
825 |
const GLint loc = ctx->glGetUniformLocation(program->handle, s[i].name); |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
826 |
if (loc != -1) // maybe the Sampler was optimized out? |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
827 |
{ |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
828 |
SamplerMap *map = &program->samplers[program->sampler_count]; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
829 |
map->shader_type = shader_type; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
830 |
map->sampler = &s[i]; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
831 |
map->location = (GLuint) loc; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
832 |
program->sampler_count++; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
833 |
} // if |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
834 |
} // for |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
835 |
} // lookup_samplers |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
836 |
|
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
837 |
|
213
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
838 |
static void lookup_attributes(MOJOSHADER_glProgram *program) |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
839 |
{ |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
840 |
int i; |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
841 |
const MOJOSHADER_parseData *pd = program->vertex->parseData; |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
842 |
const MOJOSHADER_attribute *a = pd->attributes; |
213
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
843 |
|
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
844 |
for (i = 0; i < pd->attribute_count; i++) |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
845 |
{ |
321
d7fb4ccecf0b
Fixed incorrect vertex shader attribute location lookup.
Ryan C. Gordon <icculus@icculus.org>
parents:
313
diff
changeset
|
846 |
const GLint loc = ctx->glGetAttribLocation(program->handle, a[i].name); |
213
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
847 |
if (loc != -1) // maybe the Attribute was optimized out? |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
848 |
{ |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
849 |
AttributeMap *map = &program->attributes[program->attribute_count]; |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
850 |
map->attribute = &a[i]; |
215
f2e508f08997
Fixed wrong type for uniform/attribute locations.
Ryan C. Gordon <icculus@icculus.org>
parents:
213
diff
changeset
|
851 |
map->location = (GLuint) loc; |
213
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
852 |
program->attribute_count++; |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
853 |
} // if |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
854 |
} // for |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
855 |
} // lookup_attributes |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
856 |
|
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
857 |
|
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
858 |
static GLuint impl_GLSL_LinkProgram(MOJOSHADER_glShader *vshader, |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
859 |
MOJOSHADER_glShader *pshader) |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
860 |
{ |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
861 |
const GLuint program = ctx->glCreateProgramObject(); |
209
2bd25adf2d3a
Finished implementing MOJOSHADER_glLinkProgram().
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
862 |
|
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
863 |
if (vshader != NULL) ctx->glAttachObject(program, vshader->handle); |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
864 |
if (pshader != NULL) ctx->glAttachObject(program, pshader->handle); |
209
2bd25adf2d3a
Finished implementing MOJOSHADER_glLinkProgram().
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
865 |
|
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
866 |
ctx->glLinkProgram(program); |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
867 |
|
209
2bd25adf2d3a
Finished implementing MOJOSHADER_glLinkProgram().
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
868 |
GLint ok = 0; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
869 |
ctx->glGetObjectParameteriv(program, GL_OBJECT_LINK_STATUS_ARB, &ok); |
209
2bd25adf2d3a
Finished implementing MOJOSHADER_glLinkProgram().
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
870 |
if (!ok) |
2bd25adf2d3a
Finished implementing MOJOSHADER_glLinkProgram().
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
871 |
{ |
2bd25adf2d3a
Finished implementing MOJOSHADER_glLinkProgram().
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
872 |
GLsizei len = 0; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
873 |
ctx->glGetInfoLog(program, sizeof (error_buffer), &len, (GLchar *) error_buffer); |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
874 |
ctx->glDeleteObject(program); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
875 |
return 0; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
876 |
} // if |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
877 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
878 |
return program; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
879 |
} // impl_GLSL_LinkProgram |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
880 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
881 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
882 |
static GLuint impl_ARB1_LinkProgram(MOJOSHADER_glShader *vshader, |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
883 |
MOJOSHADER_glShader *pshader) |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
884 |
{ |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
885 |
// there is no formal linking in ARB1...just return a unique value. |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
886 |
static GLuint retval = 1; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
887 |
return retval++; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
888 |
} // impl_ARB1_LinkProgram |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
889 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
890 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
891 |
MOJOSHADER_glProgram *MOJOSHADER_glLinkProgram(MOJOSHADER_glShader *vshader, |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
892 |
MOJOSHADER_glShader *pshader) |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
893 |
{ |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
894 |
if ((vshader == NULL) && (pshader == NULL)) |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
895 |
return NULL; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
896 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
897 |
int numregs = 0; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
898 |
int consts = 0; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
899 |
MOJOSHADER_glProgram *retval = NULL; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
900 |
const GLuint program = ctx->profileLinkProgram(vshader, pshader); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
901 |
if (program == 0) |
209
2bd25adf2d3a
Finished implementing MOJOSHADER_glLinkProgram().
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
902 |
goto link_program_fail; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
903 |
|
204
5055ac80916e
A little more work on MOJOSHADER_glLinkProgram().
Ryan C. Gordon <icculus@icculus.org>
parents:
203
diff
changeset
|
904 |
retval = (MOJOSHADER_glProgram *) Malloc(sizeof (MOJOSHADER_glProgram)); |
5055ac80916e
A little more work on MOJOSHADER_glLinkProgram().
Ryan C. Gordon <icculus@icculus.org>
parents:
203
diff
changeset
|
905 |
if (retval == NULL) |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
906 |
goto link_program_fail; |
209
2bd25adf2d3a
Finished implementing MOJOSHADER_glLinkProgram().
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
907 |
memset(retval, '\0', sizeof (MOJOSHADER_glProgram)); |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
908 |
|
284
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
909 |
numregs = 0; |
209
2bd25adf2d3a
Finished implementing MOJOSHADER_glLinkProgram().
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
910 |
if (vshader != NULL) numregs += vshader->parseData->uniform_count; |
2bd25adf2d3a
Finished implementing MOJOSHADER_glLinkProgram().
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
911 |
if (pshader != NULL) numregs += pshader->parseData->uniform_count; |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
912 |
retval->uniforms = (UniformMap *) Malloc(sizeof (UniformMap) * numregs); |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
913 |
if (retval->uniforms == NULL) |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
914 |
goto link_program_fail; |
209
2bd25adf2d3a
Finished implementing MOJOSHADER_glLinkProgram().
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
915 |
memset(retval->uniforms, '\0', sizeof (UniformMap) * numregs); |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
916 |
|
284
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
917 |
numregs = 0; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
918 |
if (vshader != NULL) numregs += vshader->parseData->sampler_count; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
919 |
if (pshader != NULL) numregs += pshader->parseData->sampler_count; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
920 |
retval->samplers = (SamplerMap *) Malloc(sizeof (SamplerMap) * numregs); |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
921 |
if (retval->samplers == NULL) |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
922 |
goto link_program_fail; |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
923 |
memset(retval->samplers, '\0', sizeof (SamplerMap) * numregs); |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
924 |
|
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
925 |
retval->handle = program; |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
926 |
retval->vertex = vshader; |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
927 |
retval->fragment = pshader; |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
928 |
retval->refcount = 1; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
929 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
930 |
if (vshader != NULL) |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
931 |
{ |
313
f5aa15de1690
Shrunk variable name to fit draconian 80-char standards.
Ryan C. Gordon <icculus@icculus.org>
parents:
312
diff
changeset
|
932 |
if (consts < vshader->parseData->constant_count) |
f5aa15de1690
Shrunk variable name to fit draconian 80-char standards.
Ryan C. Gordon <icculus@icculus.org>
parents:
312
diff
changeset
|
933 |
consts = vshader->parseData->constant_count; |
213
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
934 |
retval->attributes = (AttributeMap *) Malloc(sizeof (AttributeMap) * |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
935 |
vshader->parseData->attribute_count); |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
936 |
if (retval->attributes == NULL) |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
937 |
goto link_program_fail; |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
938 |
|
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
939 |
lookup_attributes(retval); |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
940 |
lookup_uniforms(retval, vshader); |
284
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
941 |
lookup_samplers(retval, vshader); |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
942 |
vshader->refcount++; |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
943 |
} // if |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
944 |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
945 |
if (pshader != NULL) |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
946 |
{ |
313
f5aa15de1690
Shrunk variable name to fit draconian 80-char standards.
Ryan C. Gordon <icculus@icculus.org>
parents:
312
diff
changeset
|
947 |
if (consts < pshader->parseData->constant_count) |
f5aa15de1690
Shrunk variable name to fit draconian 80-char standards.
Ryan C. Gordon <icculus@icculus.org>
parents:
312
diff
changeset
|
948 |
consts = pshader->parseData->constant_count; |
281
cb0ee573a33d
OpenGL glue now handles Uniform arrays.
Ryan C. Gordon <icculus@icculus.org>
parents:
277
diff
changeset
|
949 |
|
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
950 |
lookup_uniforms(retval, pshader); |
284
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
951 |
lookup_samplers(retval, vshader); |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
952 |
pshader->refcount++; |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
953 |
} // if |
204
5055ac80916e
A little more work on MOJOSHADER_glLinkProgram().
Ryan C. Gordon <icculus@icculus.org>
parents:
203
diff
changeset
|
954 |
|
313
f5aa15de1690
Shrunk variable name to fit draconian 80-char standards.
Ryan C. Gordon <icculus@icculus.org>
parents:
312
diff
changeset
|
955 |
if (consts > 0) |
281
cb0ee573a33d
OpenGL glue now handles Uniform arrays.
Ryan C. Gordon <icculus@icculus.org>
parents:
277
diff
changeset
|
956 |
{ |
313
f5aa15de1690
Shrunk variable name to fit draconian 80-char standards.
Ryan C. Gordon <icculus@icculus.org>
parents:
312
diff
changeset
|
957 |
retval->constants = (GLfloat *) Malloc(sizeof (GLfloat) * consts * 4); |
281
cb0ee573a33d
OpenGL glue now handles Uniform arrays.
Ryan C. Gordon <icculus@icculus.org>
parents:
277
diff
changeset
|
958 |
if (retval->constants == NULL) |
cb0ee573a33d
OpenGL glue now handles Uniform arrays.
Ryan C. Gordon <icculus@icculus.org>
parents:
277
diff
changeset
|
959 |
goto link_program_fail; |
313
f5aa15de1690
Shrunk variable name to fit draconian 80-char standards.
Ryan C. Gordon <icculus@icculus.org>
parents:
312
diff
changeset
|
960 |
retval->constant_count = (uint32) consts; |
281
cb0ee573a33d
OpenGL glue now handles Uniform arrays.
Ryan C. Gordon <icculus@icculus.org>
parents:
277
diff
changeset
|
961 |
} // if |
cb0ee573a33d
OpenGL glue now handles Uniform arrays.
Ryan C. Gordon <icculus@icculus.org>
parents:
277
diff
changeset
|
962 |
|
204
5055ac80916e
A little more work on MOJOSHADER_glLinkProgram().
Ryan C. Gordon <icculus@icculus.org>
parents:
203
diff
changeset
|
963 |
return retval; |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
964 |
|
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
965 |
link_program_fail: |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
966 |
if (retval != NULL) |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
967 |
{ |
284
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
968 |
Free(retval->constants); |
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
969 |
Free(retval->samplers); |
213
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
970 |
Free(retval->uniforms); |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
971 |
Free(retval->attributes); |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
972 |
Free(retval); |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
973 |
} // if |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
974 |
|
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
975 |
if (program != 0) |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
976 |
ctx->profileDeleteProgram(program); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
977 |
|
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
978 |
return NULL; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
979 |
} // MOJOSHADER_glLinkProgram |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
980 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
981 |
|
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
982 |
static void impl_GLSL_UseProgramObject(MOJOSHADER_glProgram *program) |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
983 |
{ |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
984 |
ctx->glUseProgramObject((program != NULL) ? program->handle : 0); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
985 |
} // impl_GLSL_UseProgramObject |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
986 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
987 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
988 |
static void impl_ARB1_UseProgramObject(MOJOSHADER_glProgram *program) |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
989 |
{ |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
990 |
GLuint vhandle = 0; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
991 |
GLuint phandle = 0; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
992 |
if (program != NULL) |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
993 |
{ |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
994 |
if (program->vertex != NULL) |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
995 |
vhandle = program->vertex->handle; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
996 |
if (program->fragment != NULL) |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
997 |
phandle = program->fragment->handle; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
998 |
} // if |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
999 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1000 |
ctx->glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vhandle); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1001 |
ctx->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, vhandle); |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1002 |
} // impl_GLSL_UseProgramObject |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1003 |
|
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1004 |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1005 |
void MOJOSHADER_glBindProgram(MOJOSHADER_glProgram *program) |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1006 |
{ |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
1007 |
GLuint handle = 0; |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
1008 |
int i; |
223
8df4e9545c87
Disable any enabled client-side arrays when binding a new shader.
Ryan C. Gordon <icculus@icculus.org>
parents:
222
diff
changeset
|
1009 |
|
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1010 |
if (program == ctx->bound_program) |
223
8df4e9545c87
Disable any enabled client-side arrays when binding a new shader.
Ryan C. Gordon <icculus@icculus.org>
parents:
222
diff
changeset
|
1011 |
return; // nothing to do. |
8df4e9545c87
Disable any enabled client-side arrays when binding a new shader.
Ryan C. Gordon <icculus@icculus.org>
parents:
222
diff
changeset
|
1012 |
|
8df4e9545c87
Disable any enabled client-side arrays when binding a new shader.
Ryan C. Gordon <icculus@icculus.org>
parents:
222
diff
changeset
|
1013 |
// Disable any client-side arrays the current program could have used. |
242
c3c5693ba179
Fixed vertex attribute aliasing in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
241
diff
changeset
|
1014 |
// !!! FIXME: don't disable yet...see which ones get reused, and disable |
c3c5693ba179
Fixed vertex attribute aliasing in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
241
diff
changeset
|
1015 |
// !!! FIXME: only what we don't need in MOJOSHADER_glProgramReady(). |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1016 |
if (ctx->bound_program != NULL) |
223
8df4e9545c87
Disable any enabled client-side arrays when binding a new shader.
Ryan C. Gordon <icculus@icculus.org>
parents:
222
diff
changeset
|
1017 |
{ |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1018 |
const int count = ctx->bound_program->attribute_count; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1019 |
for (i = 0; i < count; i++) |
223
8df4e9545c87
Disable any enabled client-side arrays when binding a new shader.
Ryan C. Gordon <icculus@icculus.org>
parents:
222
diff
changeset
|
1020 |
{ |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1021 |
const AttributeMap *map = &ctx->bound_program->attributes[i]; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1022 |
ctx->glDisableVertexAttribArray(map->location); |
223
8df4e9545c87
Disable any enabled client-side arrays when binding a new shader.
Ryan C. Gordon <icculus@icculus.org>
parents:
222
diff
changeset
|
1023 |
} // if |
8df4e9545c87
Disable any enabled client-side arrays when binding a new shader.
Ryan C. Gordon <icculus@icculus.org>
parents:
222
diff
changeset
|
1024 |
} // for |
8df4e9545c87
Disable any enabled client-side arrays when binding a new shader.
Ryan C. Gordon <icculus@icculus.org>
parents:
222
diff
changeset
|
1025 |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1026 |
if (program != NULL) |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1027 |
{ |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1028 |
handle = program->handle; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1029 |
program->refcount++; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1030 |
} // if |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1031 |
|
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
1032 |
ctx->profileUseProgramObject(program); |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1033 |
program_unref(ctx->bound_program); |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1034 |
ctx->bound_program = program; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1035 |
} // MOJOSHADER_glBindProgram |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1036 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1037 |
|
255
796394130035
Fixed logic bug in uniform setting.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
1038 |
static inline uint minuint(const uint a, const uint b) |
203
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1039 |
{ |
255
796394130035
Fixed logic bug in uniform setting.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
1040 |
return ((a < b) ? a : b); |
796394130035
Fixed logic bug in uniform setting.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
1041 |
} // minuint |
203
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1042 |
|
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1043 |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1044 |
void MOJOSHADER_glSetVertexShaderUniformF(unsigned int idx, const float *data, |
203
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1045 |
unsigned int vec4n) |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1046 |
{ |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1047 |
const uint maxregs = STATICARRAYLEN(ctx->vs_reg_file_f) / 4; |
203
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1048 |
if (idx < maxregs) |
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1049 |
{ |
249
7f928921766c
Cleanups for building as C++ code.
Ryan C. Gordon <icculus@icculus.org>
parents:
246
diff
changeset
|
1050 |
assert(sizeof (GLfloat) == sizeof (float)); |
255
796394130035
Fixed logic bug in uniform setting.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
1051 |
const uint cpy = (minuint(maxregs - idx, vec4n) * sizeof (*data)) * 4; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1052 |
memcpy(ctx->vs_reg_file_f + (idx * 4), data, cpy); |
203
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1053 |
} // if |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1054 |
} // MOJOSHADER_glSetVertexShaderUniformF |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1055 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1056 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1057 |
void MOJOSHADER_glSetVertexShaderUniformI(unsigned int idx, const int *data, |
203
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1058 |
unsigned int ivec4n) |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1059 |
{ |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1060 |
const uint maxregs = STATICARRAYLEN(ctx->vs_reg_file_i) / 4; |
203
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1061 |
if (idx < maxregs) |
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1062 |
{ |
249
7f928921766c
Cleanups for building as C++ code.
Ryan C. Gordon <icculus@icculus.org>
parents:
246
diff
changeset
|
1063 |
assert(sizeof (GLint) == sizeof (int)); |
255
796394130035
Fixed logic bug in uniform setting.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
1064 |
const uint cpy = (minuint(maxregs - idx, ivec4n) * sizeof (*data)) * 4; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1065 |
memcpy(ctx->vs_reg_file_i + (idx * 4), data, cpy); |
203
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1066 |
} // if |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1067 |
} // MOJOSHADER_glSetVertexShaderUniformI |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1068 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1069 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1070 |
void MOJOSHADER_glSetVertexShaderUniformB(unsigned int idx, const int *data, |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1071 |
unsigned int bcount) |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1072 |
{ |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1073 |
const uint maxregs = STATICARRAYLEN(ctx->vs_reg_file_f) / 4; |
203
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1074 |
if (idx < maxregs) |
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1075 |
{ |
249
7f928921766c
Cleanups for building as C++ code.
Ryan C. Gordon <icculus@icculus.org>
parents:
246
diff
changeset
|
1076 |
GLint *wptr = ctx->vs_reg_file_b + idx; |
255
796394130035
Fixed logic bug in uniform setting.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
1077 |
GLint *endptr = wptr + minuint(maxregs - idx, bcount); |
203
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1078 |
while (wptr != endptr) |
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1079 |
*(wptr++) = *(data++) ? 1 : 0; |
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1080 |
} // if |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1081 |
} // MOJOSHADER_glSetVertexShaderUniformB |
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 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1084 |
void MOJOSHADER_glSetPixelShaderUniformF(unsigned int idx, const float *data, |
212 | 1085 |
unsigned int vec4n) |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1086 |
{ |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1087 |
const uint maxregs = STATICARRAYLEN(ctx->ps_reg_file_f) / 4; |
203
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1088 |
if (idx < maxregs) |
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1089 |
{ |
249
7f928921766c
Cleanups for building as C++ code.
Ryan C. Gordon <icculus@icculus.org>
parents:
246
diff
changeset
|
1090 |
assert(sizeof (GLfloat) == sizeof (float)); |
255
796394130035
Fixed logic bug in uniform setting.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
1091 |
const uint cpy = (minuint(maxregs - idx, vec4n) * sizeof (*data)) * 4; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1092 |
memcpy(ctx->ps_reg_file_f + (idx * 4), data, cpy); |
203
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1093 |
} // if |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1094 |
} // MOJOSHADER_glSetPixelShaderUniformF |
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 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1097 |
void MOJOSHADER_glSetPixelShaderUniformI(unsigned int idx, const int *data, |
203
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1098 |
unsigned int ivec4n) |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1099 |
{ |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
1100 |
const uint maxregs = STATICARRAYLEN(ctx->ps_reg_file_i) / 4; |
203
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1101 |
if (idx < maxregs) |
ff983e373e37
Implemented uniform array setting in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
202
diff
changeset
|
1102 |
{ |
249 |