author | Ethan Lee <flibitijibibo@flibitijibibo.com> |
Fri, 24 Apr 2020 09:13:10 -0400 | |
changeset 1245 | ad9a16c8b023 |
parent 1243 | 0092b6c389d4 |
child 1251 | cee4402d5ab8 |
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 |
|
1195
f4ef8606c68d
Apply some MSC_VER special cases to WIN32 as well (thanks Vincent!)
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1192
diff
changeset
|
10 |
#ifdef _WIN32 |
254 | 11 |
#define WIN32_LEAN_AND_MEAN 1 |
12 |
#include <windows.h> // GL headers need this for WINGDIAPI definition. |
|
13 |
#endif |
|
14 |
||
457
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
15 |
#if (defined(__APPLE__) && defined(__MACH__)) |
1192
706e4d246ca1
iOS support (thanks Caleb!)
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1188
diff
changeset
|
16 |
#include "TargetConditionals.h" |
706e4d246ca1
iOS support (thanks Caleb!)
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1188
diff
changeset
|
17 |
#if !TARGET_OS_IPHONE && !TARGET_OS_TV |
457
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
18 |
#define PLATFORM_MACOSX 1 |
1192
706e4d246ca1
iOS support (thanks Caleb!)
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1188
diff
changeset
|
19 |
#endif /* !TARGET_OS_IPHONE && !TARGET_OS_TV */ |
706e4d246ca1
iOS support (thanks Caleb!)
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1188
diff
changeset
|
20 |
#endif /* (defined(__APPLE__) && defined(__MACH__)) */ |
457
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
21 |
|
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
22 |
#if PLATFORM_MACOSX |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
23 |
#include <Carbon/Carbon.h> |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
24 |
#endif |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
25 |
|
464
eba4cf79437f
Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
463
diff
changeset
|
26 |
#define __MOJOSHADER_INTERNAL__ 1 |
eba4cf79437f
Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
463
diff
changeset
|
27 |
#include "mojoshader_internal.h" |
eba4cf79437f
Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
463
diff
changeset
|
28 |
|
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
29 |
#define GL_GLEXT_LEGACY 1 |
246
897868fdd958
Moved gl*.h into GL directory.
Ryan C. Gordon <icculus@icculus.org>
parents:
245
diff
changeset
|
30 |
#include "GL/gl.h" |
897868fdd958
Moved gl*.h into GL directory.
Ryan C. Gordon <icculus@icculus.org>
parents:
245
diff
changeset
|
31 |
#include "GL/glext.h" |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 |
|
1225
50b8dd7e0b1a
Add GLSPIRV profile, to allow for both GL- and VK-friendly SPIR-V output
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1224
diff
changeset
|
33 |
#if SUPPORT_PROFILE_GLSPIRV |
1224
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
34 |
#include "spirv/spirv.h" |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
35 |
#endif |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
36 |
|
1073
6eccf031c7e6
Cleaned up half-float stuff.
Ryan C. Gordon <icculus@icculus.org>
parents:
1072
diff
changeset
|
37 |
#ifndef GL_HALF_FLOAT_NV |
6eccf031c7e6
Cleaned up half-float stuff.
Ryan C. Gordon <icculus@icculus.org>
parents:
1072
diff
changeset
|
38 |
#define GL_HALF_FLOAT_NV 0x140B |
6eccf031c7e6
Cleaned up half-float stuff.
Ryan C. Gordon <icculus@icculus.org>
parents:
1072
diff
changeset
|
39 |
#endif |
6eccf031c7e6
Cleaned up half-float stuff.
Ryan C. Gordon <icculus@icculus.org>
parents:
1072
diff
changeset
|
40 |
|
6eccf031c7e6
Cleaned up half-float stuff.
Ryan C. Gordon <icculus@icculus.org>
parents:
1072
diff
changeset
|
41 |
#ifndef GL_HALF_FLOAT_ARB |
6eccf031c7e6
Cleaned up half-float stuff.
Ryan C. Gordon <icculus@icculus.org>
parents:
1072
diff
changeset
|
42 |
#define GL_HALF_FLOAT_ARB 0x140B |
449
5a978f37e750
Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents:
448
diff
changeset
|
43 |
#endif |
5a978f37e750
Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents:
448
diff
changeset
|
44 |
|
5a978f37e750
Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents:
448
diff
changeset
|
45 |
#ifndef GL_HALF_FLOAT_OES |
5a978f37e750
Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents:
448
diff
changeset
|
46 |
#define GL_HALF_FLOAT_OES 0x8D61 |
5a978f37e750
Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents:
448
diff
changeset
|
47 |
#endif |
5a978f37e750
Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents:
448
diff
changeset
|
48 |
|
1056
73c697a7e950
Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1043
diff
changeset
|
49 |
// this happens to be the same value for ARB1 and GLSL. |
73c697a7e950
Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1043
diff
changeset
|
50 |
#ifndef GL_PROGRAM_POINT_SIZE |
73c697a7e950
Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1043
diff
changeset
|
51 |
#define GL_PROGRAM_POINT_SIZE 0x8642 |
73c697a7e950
Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1043
diff
changeset
|
52 |
#endif |
449
5a978f37e750
Added support for GL_ARB_half_float_vertex and GL_OES_vertex_half_float.
Ryan C. Gordon <icculus@icculus.org>
parents:
448
diff
changeset
|
53 |
|
1224
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
54 |
// FIXME: ARB_gl_spirv in glext.h? -flibit |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
55 |
#ifndef GL_ARB_gl_spirv |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
56 |
#define GL_ARB_gl_spirv 1 |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
57 |
#define GL_SHADER_BINARY_FORMAT_SPIR_V_ARB 0x9551 |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
58 |
typedef void (APIENTRYP PFNGLSPECIALIZESHADERARBPROC) ( |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
59 |
GLuint shader, |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
60 |
const GLchar* pEntryPoint, |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
61 |
GLuint numSpecializationConstants, |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
62 |
const GLuint* pConstantIndex, |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
63 |
const GLuint* pConstantValue |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
64 |
); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
65 |
#endif |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
66 |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 |
struct MOJOSHADER_glShader |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 |
{ |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 |
const MOJOSHADER_parseData *parseData; |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
70 |
GLuint handle; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 |
uint32 refcount; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 |
}; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 |
|
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
74 |
typedef struct |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
75 |
{ |
206
7027d889acdd
Implemented MOJOSHADER_glProgramReady().
Ryan C. Gordon <icculus@icculus.org>
parents:
205
diff
changeset
|
76 |
MOJOSHADER_shaderType shader_type; |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
77 |
const MOJOSHADER_uniform *uniform; |
798
5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
797
diff
changeset
|
78 |
GLint location; |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
79 |
} UniformMap; |
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
80 |
|
213
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
81 |
typedef struct |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
82 |
{ |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
83 |
const MOJOSHADER_attribute *attribute; |
798
5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
797
diff
changeset
|
84 |
GLint location; |
213
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
85 |
} AttributeMap; |
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
86 |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
87 |
struct MOJOSHADER_glProgram |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
88 |
{ |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
89 |
MOJOSHADER_glShader *vertex; |
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
90 |
MOJOSHADER_glShader *fragment; |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
91 |
GLuint handle; |
774
9ac0e5ad0205
Don't push uniforms if they've definitely not changed.
Ryan C. Gordon <icculus@icculus.org>
parents:
773
diff
changeset
|
92 |
uint32 generation; |
205
8583f89985df
Cache uniform locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
204
diff
changeset
|
93 |
uint32 uniform_count; |
1090
636ffcd3f14a
First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
94 |
uint32 texbem_count; |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
95 |
UniformMap *uniforms; |
213
73935330a973
Cache attribute locations for GLSL programs at link time.
Ryan C. Gordon <icculus@icculus.org>
parents:
212
diff
changeset
|
96 |
uint32 attribute_count; |
226
4a2b3d0b535f
Patched mojoshader_opengl.c to compile, mostly.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
97 |
AttributeMap *attributes; |
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
98 |
size_t vs_uniforms_float4_count; |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
99 |
GLfloat *vs_uniforms_float4; |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
100 |
size_t vs_uniforms_int4_count; |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
101 |
GLint *vs_uniforms_int4; |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
102 |
size_t vs_uniforms_bool_count; |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
103 |
GLint *vs_uniforms_bool; |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
104 |
size_t ps_uniforms_float4_count; |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
105 |
GLfloat *ps_uniforms_float4; |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
106 |
size_t ps_uniforms_int4_count; |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
107 |
GLint *ps_uniforms_int4; |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
108 |
size_t ps_uniforms_bool_count; |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
109 |
GLint *ps_uniforms_bool; |
1043
6227066350b4
Preshader input registers are separate from the actual shader constant file!
Ryan C. Gordon <icculus@icculus.org>
parents:
1040
diff
changeset
|
110 |
|
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
111 |
uint32 refcount; |
1056
73c697a7e950
Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1043
diff
changeset
|
112 |
|
73c697a7e950
Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1043
diff
changeset
|
113 |
int uses_pointsize; |
73c697a7e950
Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1043
diff
changeset
|
114 |
|
1232
eec14d60f416
Better value for max vertex_attrib_loc
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1225
diff
changeset
|
115 |
// According to MSDN... |
eec14d60f416
Better value for max vertex_attrib_loc
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1225
diff
changeset
|
116 |
// |
eec14d60f416
Better value for max vertex_attrib_loc
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1225
diff
changeset
|
117 |
// n is an optional integer between 0 and the number of resources supported. |
eec14d60f416
Better value for max vertex_attrib_loc
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1225
diff
changeset
|
118 |
// For example, POSITION0, TEXCOOR1, etc. |
eec14d60f416
Better value for max vertex_attrib_loc
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1225
diff
changeset
|
119 |
// |
eec14d60f416
Better value for max vertex_attrib_loc
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1225
diff
changeset
|
120 |
// The input registers consist of 16 four-component floating-point vectors, |
eec14d60f416
Better value for max vertex_attrib_loc
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1225
diff
changeset
|
121 |
// designated as v0 through v15. |
eec14d60f416
Better value for max vertex_attrib_loc
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1225
diff
changeset
|
122 |
GLint vertex_attrib_loc[MOJOSHADER_USAGE_TOTAL][16]; |
1150
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
123 |
|
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
124 |
// GLSL uses these...location of uniform arrays. |
797
58d15db2881e
GLSL Uniform locations are signed ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
791
diff
changeset
|
125 |
GLint vs_float4_loc; |
58d15db2881e
GLSL Uniform locations are signed ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
791
diff
changeset
|
126 |
GLint vs_int4_loc; |
58d15db2881e
GLSL Uniform locations are signed ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
791
diff
changeset
|
127 |
GLint vs_bool_loc; |
58d15db2881e
GLSL Uniform locations are signed ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
791
diff
changeset
|
128 |
GLint ps_float4_loc; |
58d15db2881e
GLSL Uniform locations are signed ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
791
diff
changeset
|
129 |
GLint ps_int4_loc; |
58d15db2881e
GLSL Uniform locations are signed ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
791
diff
changeset
|
130 |
GLint ps_bool_loc; |
1210
c586d4590241
Replace glProgramViewportFlip with glProgramViewportInfo
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1207
diff
changeset
|
131 |
|
c586d4590241
Replace glProgramViewportFlip with glProgramViewportInfo
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1207
diff
changeset
|
132 |
// Numerous fixes for coordinate system mismatches |
c586d4590241
Replace glProgramViewportFlip with glProgramViewportInfo
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1207
diff
changeset
|
133 |
GLint ps_vpos_flip_loc; |
c586d4590241
Replace glProgramViewportFlip with glProgramViewportInfo
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1207
diff
changeset
|
134 |
int current_vpos_flip[2]; |
1150
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
135 |
#ifdef MOJOSHADER_FLIP_RENDERTARGET |
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
136 |
GLint vs_flip_loc; |
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
137 |
int current_flip; |
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
138 |
#endif |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
139 |
}; |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
140 |
|
277
49a6571cac6d
Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents:
276
diff
changeset
|
141 |
#ifndef WINGDIAPI |
49a6571cac6d
Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents:
276
diff
changeset
|
142 |
#define WINGDIAPI |
49a6571cac6d
Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents:
276
diff
changeset
|
143 |
#endif |
49a6571cac6d
Patched to compile on older (?) GL headers.
Ryan C. Gordon <icculus@icculus.org>
parents:
276
diff
changeset
|
144 |
|
242
c3c5693ba179
Fixed vertex attribute aliasing in OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
241
diff
changeset
|
145 |
// 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
|
146 |
typedef WINGDIAPI void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params); |
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
147 |
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
|
148 |
typedef WINGDIAPI GLenum (APIENTRYP PFNGLGETERRORPROC) (void); |
358
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
149 |
typedef WINGDIAPI void (APIENTRYP PFNGLENABLEPROC) (GLenum cap); |
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
150 |
typedef WINGDIAPI void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap); |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
151 |
|
773
3e3638be6e2b
Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents:
772
diff
changeset
|
152 |
// Max entries for each register file type... |
3e3638be6e2b
Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents:
772
diff
changeset
|
153 |
#define MAX_REG_FILE_F 8192 |
3e3638be6e2b
Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents:
772
diff
changeset
|
154 |
#define MAX_REG_FILE_I 2047 |
3e3638be6e2b
Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents:
772
diff
changeset
|
155 |
#define MAX_REG_FILE_B 2047 |
1090
636ffcd3f14a
First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
156 |
#define MAX_TEXBEMS 3 // ps_1_1 allows 4 texture stages, texbem can't use t0. |
773
3e3638be6e2b
Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents:
772
diff
changeset
|
157 |
|
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
158 |
struct MOJOSHADER_glContext |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
159 |
{ |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
160 |
// Allocators... |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
161 |
MOJOSHADER_malloc malloc_fn; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
162 |
MOJOSHADER_free free_fn; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
163 |
void *malloc_data; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
164 |
|
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
165 |
// The constant register files... |
806 | 166 |
// !!! FIXME: Man, it kills me how much memory this takes... |
167 |
// !!! FIXME: ... make this dynamically allocated on demand. |
|
773
3e3638be6e2b
Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents:
772
diff
changeset
|
168 |
GLfloat vs_reg_file_f[MAX_REG_FILE_F * 4]; |
3e3638be6e2b
Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents:
772
diff
changeset
|
169 |
GLint vs_reg_file_i[MAX_REG_FILE_I * 4]; |
3e3638be6e2b
Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents:
772
diff
changeset
|
170 |
uint8 vs_reg_file_b[MAX_REG_FILE_B]; |
3e3638be6e2b
Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents:
772
diff
changeset
|
171 |
GLfloat ps_reg_file_f[MAX_REG_FILE_F * 4]; |
3e3638be6e2b
Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents:
772
diff
changeset
|
172 |
GLint ps_reg_file_i[MAX_REG_FILE_I * 4]; |
3e3638be6e2b
Replaced some constants with #defines.
Ryan C. Gordon <icculus@icculus.org>
parents:
772
diff
changeset
|
173 |
uint8 ps_reg_file_b[MAX_REG_FILE_B]; |
284
ea52f9707795
Sampler loading support in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
281
diff
changeset
|
174 |
GLuint sampler_reg_file[16]; |
1090
636ffcd3f14a
First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
175 |
GLfloat texbem_state[MAX_TEXBEMS * 6]; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
176 |
|
774
9ac0e5ad0205
Don't push uniforms if they've definitely not changed.
Ryan C. Gordon <icculus@icculus.org>
parents:
773
diff
changeset
|
177 |
// This increments every time we change the register files. |
9ac0e5ad0205
Don't push uniforms if they've definitely not changed.
Ryan C. Gordon <icculus@icculus.org>
parents:
773
diff
changeset
|
178 |
uint32 generation; |
9ac0e5ad0205
Don't push uniforms if they've definitely not changed.
Ryan C. Gordon <icculus@icculus.org>
parents:
773
diff
changeset
|
179 |
|
1066
ff14db741834
Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents:
1063
diff
changeset
|
180 |
// This keeps track of implicitly linked programs. |
ff14db741834
Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents:
1063
diff
changeset
|
181 |
HashTable *linker_cache; |
ff14db741834
Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents:
1063
diff
changeset
|
182 |
|
775
2c93dcb14687
Only enable/disable vertex arrays when forced to.
Ryan C. Gordon <icculus@icculus.org>
parents:
774
diff
changeset
|
183 |
// This tells us which vertex attribute arrays we have enabled. |
798
5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
797
diff
changeset
|
184 |
GLint max_attrs; |
775
2c93dcb14687
Only enable/disable vertex arrays when forced to.
Ryan C. Gordon <icculus@icculus.org>
parents:
774
diff
changeset
|
185 |
uint8 want_attr[32]; |
2c93dcb14687
Only enable/disable vertex arrays when forced to.
Ryan C. Gordon <icculus@icculus.org>
parents:
774
diff
changeset
|
186 |
uint8 have_attr[32]; |
2c93dcb14687
Only enable/disable vertex arrays when forced to.
Ryan C. Gordon <icculus@icculus.org>
parents:
774
diff
changeset
|
187 |
|
1150
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
188 |
// This shadows vertex attribute and divisor states. |
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
189 |
GLuint attr_divisor[32]; |
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
190 |
|
1056
73c697a7e950
Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1043
diff
changeset
|
191 |
// rarely used, so we don't touch when we don't have to. |
73c697a7e950
Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1043
diff
changeset
|
192 |
int pointsize_enabled; |
73c697a7e950
Toggle pointsize support as necessary in the OpenGL bindings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1043
diff
changeset
|
193 |
|
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
194 |
// GL stuff... |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
195 |
int opengl_major; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
196 |
int opengl_minor; |
1070
32eb4fe78351
Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
1069
diff
changeset
|
197 |
int glsl_major; |
32eb4fe78351
Reworked GLSL extension and version detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
1069
diff
changeset
|
198 |
int glsl_minor; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
199 |
MOJOSHADER_glProgram *bound_program; |
262
0f1531ac2578
Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
200 |
char profile[16]; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
201 |
|
1150
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
202 |
#ifdef MOJOSHADER_XNA4_VERTEX_TEXTURES |
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
203 |
// Vertex texture sampler offset... |
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
204 |
int vertex_sampler_offset; |
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
205 |
#endif |
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
206 |
|
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
207 |
// Extensions... |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
208 |
int have_core_opengl; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
209 |
int have_opengl_2; // different entry points than ARB extensions. |
1117
f6712bf72c19
Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents:
1111
diff
changeset
|
210 |
int have_opengl_3; // different extension query. |
1150
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
211 |
int have_opengl_es; // different extension requirements |
463
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
212 |
int have_GL_ARB_vertex_program; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
213 |
int have_GL_ARB_fragment_program; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
214 |
int have_GL_NV_vertex_program2_option; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
215 |
int have_GL_NV_fragment_program2; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
216 |
int have_GL_NV_vertex_program3; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
217 |
int have_GL_NV_gpu_program4; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
218 |
int have_GL_ARB_shader_objects; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
219 |
int have_GL_ARB_vertex_shader; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
220 |
int have_GL_ARB_fragment_shader; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
221 |
int have_GL_ARB_shading_language_100; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
222 |
int have_GL_NV_half_float; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
223 |
int have_GL_ARB_half_float_vertex; |
6f3a82d7e3d2
Removed bitfields for full ints.
Ryan C. Gordon <icculus@icculus.org>
parents:
460
diff
changeset
|
224 |
int have_GL_OES_vertex_half_float; |
1150
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
225 |
int have_GL_ARB_instanced_arrays; |
1224
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
226 |
int have_GL_ARB_ES2_compatibility; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
227 |
int have_GL_ARB_gl_spirv; |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
228 |
|
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
229 |
// Entry points... |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
230 |
PFNGLGETSTRINGPROC glGetString; |
1117
f6712bf72c19
Allow looking up OpenGL extensions in the way appropriate for GL3+.
Ryan C. Gordon <icculus@icculus.org>
parents:
1111
diff
changeset
|
231 |
PFNGLGETSTRINGIPROC glGetStringi; |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
232 |
PFNGLGETERRORPROC glGetError; |
276
1d7437469c94
Added MOJOSHADER_glMaxUniforms().
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
233 |
PFNGLGETINTEGERVPROC glGetIntegerv; |
358
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
234 |
PFNGLENABLEPROC glEnable; |
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
235 |
PFNGLDISABLEPROC glDisable; |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
236 |
PFNGLDELETESHADERPROC glDeleteShader; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
237 |
PFNGLDELETEPROGRAMPROC glDeleteProgram; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
238 |
PFNGLATTACHSHADERPROC glAttachShader; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
239 |
PFNGLCOMPILESHADERPROC glCompileShader; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
240 |
PFNGLCREATESHADERPROC glCreateShader; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
241 |
PFNGLCREATEPROGRAMPROC glCreateProgram; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
242 |
PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
243 |
PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
244 |
PFNGLGETATTRIBLOCATIONPROC glGetAttribLocation; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
245 |
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog; |
1125
3de60f597ebd
Don't use the extension entry point glGetInfoLogARB() in the core GL2 path.
Ryan C. Gordon <icculus@icculus.org>
parents:
1124
diff
changeset
|
246 |
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog; |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
247 |
PFNGLGETSHADERIVPROC glGetShaderiv; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
248 |
PFNGLGETPROGRAMIVPROC glGetProgramiv; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
249 |
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
250 |
PFNGLLINKPROGRAMPROC glLinkProgram; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
251 |
PFNGLSHADERSOURCEPROC glShaderSource; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
252 |
PFNGLUNIFORM1IPROC glUniform1i; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
253 |
PFNGLUNIFORM1IVPROC glUniform1iv; |
1210
c586d4590241
Replace glProgramViewportFlip with glProgramViewportInfo
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1207
diff
changeset
|
254 |
PFNGLUNIFORM2FPROC glUniform2f; |
1150
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
255 |
#ifdef MOJOSHADER_FLIP_RENDERTARGET |
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
256 |
PFNGLUNIFORM1FPROC glUniform1f; |
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
257 |
#endif |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
258 |
PFNGLUNIFORM4FVPROC glUniform4fv; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
259 |
PFNGLUNIFORM4IVPROC glUniform4iv; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
260 |
PFNGLUSEPROGRAMPROC glUseProgram; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
261 |
PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
262 |
PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
263 |
PFNGLATTACHOBJECTARBPROC glAttachObjectARB; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
264 |
PFNGLCOMPILESHADERARBPROC glCompileShaderARB; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
265 |
PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
266 |
PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
267 |
PFNGLDISABLEVERTEXATTRIBARRAYARBPROC glDisableVertexAttribArrayARB; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
268 |
PFNGLENABLEVERTEXATTRIBARRAYARBPROC glEnableVertexAttribArrayARB; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
269 |
PFNGLGETATTRIBLOCATIONARBPROC glGetAttribLocationARB; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
270 |
PFNGLGETINFOLOGARBPROC glGetInfoLogARB; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
271 |
PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
272 |
PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
273 |
PFNGLLINKPROGRAMARBPROC glLinkProgramARB; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
274 |
PFNGLSHADERSOURCEARBPROC glShaderSourceARB; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
275 |
PFNGLUNIFORM1IARBPROC glUniform1iARB; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
276 |
PFNGLUNIFORM1IVARBPROC glUniform1ivARB; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
277 |
PFNGLUNIFORM4FVARBPROC glUniform4fvARB; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
278 |
PFNGLUNIFORM4IVARBPROC glUniform4ivARB; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
279 |
PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
280 |
PFNGLVERTEXATTRIBPOINTERARBPROC glVertexAttribPointerARB; |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
281 |
PFNGLGETPROGRAMIVARBPROC glGetProgramivARB; |
395
d2307cc5d6e7
Use local parameters, not environment params, in the arb1/nv2 profiles.
Ryan C. Gordon <icculus@icculus.org>
parents:
394
diff
changeset
|
282 |
PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB; |
431
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
283 |
PFNGLPROGRAMLOCALPARAMETERI4IVNVPROC glProgramLocalParameterI4ivNV; |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
284 |
PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
285 |
PFNGLGENPROGRAMSARBPROC glGenProgramsARB; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
286 |
PFNGLBINDPROGRAMARBPROC glBindProgramARB; |
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
287 |
PFNGLPROGRAMSTRINGARBPROC glProgramStringARB; |
1150
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
288 |
PFNGLVERTEXATTRIBDIVISORARBPROC glVertexAttribDivisorARB; |
1224
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
289 |
PFNGLSHADERBINARYPROC glShaderBinary; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
290 |
PFNGLSPECIALIZESHADERARBPROC glSpecializeShaderARB; |
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
291 |
|
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
292 |
// interface for profile-specific things. |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
293 |
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
|
294 |
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
|
295 |
void (*profileDeleteShader)(const GLuint shader); |
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
296 |
void (*profileDeleteProgram)(const GLuint program); |
347
f8d9d0ae6ba8
Bunch more work (ARB1 profile, OpenGL glue, and general fixes).
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
297 |
GLint (*profileGetAttribLocation)(MOJOSHADER_glProgram *program, int idx); |
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
298 |
GLint (*profileGetUniformLocation)(MOJOSHADER_glProgram *program, MOJOSHADER_glShader *shader, int idx); |
347
f8d9d0ae6ba8
Bunch more work (ARB1 profile, OpenGL glue, and general fixes).
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
299 |
GLint (*profileGetSamplerLocation)(MOJOSHADER_glProgram *, MOJOSHADER_glShader *, int); |
333
2b36a1d72fa1
Wrote most of the arb1 OpenGL glue code.
Ryan C. Gordon <icculus@icculus.org>
parents:
323
diff
changeset
|
300 |
GLuint (*profileLinkProgram)(MOJOSHADER_glShader *, MOJOSHADER_glShader *); |
765
076f3bd42329
Moved profileInitProgram to profileFinalInitProgram.
Ryan C. Gordon <icculus@icculus.org>
parents:
764
diff
changeset
|
301 |
void (*profileFinalInitProgram)(MOJOSHADER_glProgram *program); |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
302 |
void (*profileUseProgram)(MOJOSHADER_glProgram *program); |
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
303 |
void (*profilePushConstantArray)(MOJOSHADER_glProgram *, const MOJOSHADER_uniform *, const GLfloat *); |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
304 |
void (*profilePushUniforms)(void); |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
305 |
void (*profilePushSampler)(GLint loc, GLuint sampler); |
760
6dc8d2cafc58
"Must Push" seemed more correct than "Must Load".
Ryan C. Gordon <icculus@icculus.org>
parents:
759
diff
changeset
|
306 |
int (*profileMustPushConstantArrays)(void); |
6dc8d2cafc58
"Must Push" seemed more correct than "Must Load".
Ryan C. Gordon <icculus@icculus.org>
parents:
759
diff
changeset
|
307 |
int (*profileMustPushSamplers)(void); |
1197
4883fc7d3751
Skip GL_PROGRAM_POINT_SIZE for ES contexts
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1196
diff
changeset
|
308 |
void (*profileToggleProgramPointSize)(int enable); |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
309 |
}; |
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
310 |
|
323
b60c88ec8182
Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
321
diff
changeset
|
311 |
|
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
312 |
static MOJOSHADER_glContext *ctx = NULL; |
229
67a3d459d865
OpenGL extension lookup and entry point loading.
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
313 |
|
219
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
314 |
// Error state... |
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
315 |
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
|
316 |
|
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
317 |
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
|
318 |
{ |
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
319 |
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
|
320 |
} // set_error |
61167fc96790
Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
321 |
|
457
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
322 |
#if PLATFORM_MACOSX |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
323 |
static inline int macosx_version_atleast(int x, int y, int z) |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
324 |
{ |
1243
0092b6c389d4
Skip Gestalt when min version is 10.5+
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1237
diff
changeset
|
325 |
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 |
0092b6c389d4
Skip Gestalt when min version is 10.5+
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1237
diff
changeset
|
326 |
return 1; |
0092b6c389d4
Skip Gestalt when min version is 10.5+
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1237
diff
changeset
|
327 |
#else |
457
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
328 |
static int checked = 0; |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
329 |
static int combined = 0; |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
330 |
|
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
331 |
if (!checked) |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
332 |
{ |
1133 | 333 |
SInt32 ver = 0; |
334 |
SInt32 major = 0; |
|
335 |
SInt32 minor = 0; |
|
336 |
SInt32 patch = 0; |
|
457
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
337 |
int convert = 0; |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
338 |
|
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
339 |
if (Gestalt(gestaltSystemVersion, &ver) != noErr) |
1133 | 340 |
{ |
457
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
341 |
ver = 0x1000; // oh well. |
1133 | 342 |
convert = 1; // split (ver) into (major),(minor),(patch). |
343 |
} |
|
457
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
344 |
else if (ver < 0x1030) |
1133 | 345 |
{ |
457
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
346 |
convert = 1; // split (ver) into (major),(minor),(patch). |
1133 | 347 |
} |
457
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
348 |
else |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
349 |
{ |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
350 |
// presumably this won't fail. But if it does, we'll just use the |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
351 |
// original version value. This might cut the value--10.12.11 will |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
352 |
// come out to 10.9.9, for example--but it's better than nothing. |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
353 |
if (Gestalt(gestaltSystemVersionMajor, &major) != noErr) |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
354 |
convert = 1; |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
355 |
else if (Gestalt(gestaltSystemVersionMinor, &minor) != noErr) |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
356 |
convert = 1; |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
357 |
else if (Gestalt(gestaltSystemVersionBugFix, &patch) != noErr) |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
358 |
convert = 1; |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
359 |
} // else |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
360 |
|
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
361 |
if (convert) |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
362 |
{ |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
363 |
major = ((ver & 0xFF00) >> 8); |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
364 |
major = (((major / 16) * 10) + (major % 16)); |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
365 |
minor = ((ver & 0xF0) >> 4); |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
366 |
patch = (ver & 0xF); |
533 | 367 |
} // if |
457
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
368 |
|
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
369 |
combined = (major << 16) | (minor << 8) | patch; |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
370 |
checked = 1; |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
371 |
} // if |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
372 |
|
460
54c614f0fcb0
Fixed OS X detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
459
diff
changeset
|
373 |
return (combined >= ((x << 16) | (y << 8) | z)); |
1243
0092b6c389d4
Skip Gestalt when min version is 10.5+
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1237
diff
changeset
|
374 |
#endif |
457
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
375 |
} // macosx_version_atleast |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
376 |
#endif |
96552d8041bf
Forbid GLSL on Mac OS X Tiger systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
450
diff
changeset
|
377 |
|
1066
ff14db741834
Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents:
1063
diff
changeset
|
378 |
static inline void out_of_memory(void) |
ff14db741834
Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents:
1063
diff
changeset
|
379 |
{ |
ff14db741834
Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents:
1063
diff
changeset
|
380 |
set_error("out of memory"); |
ff14db741834
Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents:
1063
diff
changeset
|
381 |
} // out_of_memory |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
382 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
383 |
static inline void *Malloc(const size_t len) |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
384 |
{ |
1188
25000edc0176
Move zeromalloc trickery to internal malloc/free functions
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1182
diff
changeset
|
385 |
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
|
386 |
if (retval == NULL) |
1066
ff14db741834
Added MOJOSHADER_glBindShaders().
Ryan C. Gordon <icculus@icculus.org>
parents:
1063
diff
changeset
|
387 |
out_of_memory(); |
220
df5ea69833d5
Fixes to Malloc() and Free() in mojoshader_opengl.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
388 |
return retval; |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
389 |
} // Malloc |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
390 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
391 |
static inline void Free(void *ptr) |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
392 |
{ |
1188
25000edc0176
Move zeromalloc trickery to internal malloc/free functions
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1182
diff
changeset
|
393 |
if (ptr != NULL) |
237
09f35dfc1d7e
OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents:
236
diff
changeset
|
394 |
ctx->free_fn(ptr, ctx->malloc_data); |
202
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
395 |
} // Free |
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
396 |
|
20bdf2d7036e
Initial add of mojoshader_opengl.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
397 |
|
358
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
398 |
static inline void toggle_gl_state(GLenum state, int val) |
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
399 |
{ |
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
400 |
if (val) |
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
401 |
ctx->glEnable(state); |
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
402 |
else |
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
403 |
ctx->glDisable(state); |
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
404 |
} // toggle_gl_state |
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
405 |
|
f63e18cf642f
Fixed MOJOSHADER_glBindProgram() for arb1 profile (thanks, Nicholas!).
Ryan C. Gordon <icculus@icculus.org>
parents:
355
diff
changeset
|
406 |
|
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
407 |
// profile-specific implementations... |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
408 |
|
1225
50b8dd7e0b1a
Add GLSPIRV profile, to allow for both GL- and VK-friendly SPIR-V output
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1224
diff
changeset
|
409 |
#if SUPPORT_PROFILE_GLSL || SUPPORT_PROFILE_GLSPIRV |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
410 |
static inline GLenum glsl_shader_type(const MOJOSHADER_shaderType t) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
411 |
{ |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
412 |
// these enums match between core 2.0 and the ARB extensions. |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
413 |
if (t == MOJOSHADER_TYPE_VERTEX) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
414 |
return GL_VERTEX_SHADER; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
415 |
else if (t == MOJOSHADER_TYPE_PIXEL) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
416 |
return GL_FRAGMENT_SHADER; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
417 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
418 |
// !!! FIXME: geometry shaders? |
1207
c4a393403859
Assert of unknown GLSL shader type (thanks Kate!)
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1197
diff
changeset
|
419 |
assert(0 && "Unknown GLSL shader type!"); |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
420 |
return GL_NONE; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
421 |
} // glsl_shader_type |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
422 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
423 |
|
760
6dc8d2cafc58
"Must Push" seemed more correct than "Must Load".
Ryan C. Gordon <icculus@icculus.org>
parents:
759
diff
changeset
|
424 |
static int impl_GLSL_MustPushConstantArrays(void) { return 1; } |
6dc8d2cafc58
"Must Push" seemed more correct than "Must Load".
Ryan C. Gordon <icculus@icculus.org>
parents:
759
diff
changeset
|
425 |
static int impl_GLSL_MustPushSamplers(void) { return 1; } |
438
73492129c1af
Expose true constant arrays in parseData, load them at link time for GLSL.
Ryan C. Gordon <icculus@icculus.org>
parents:
436
diff
changeset
|
426 |
|
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
427 |
static int impl_GLSL_MaxUniforms(MOJOSHADER_shaderType shader_type) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
428 |
{ |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
429 |
// these enums match between core 2.0 and the ARB extensions. |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
430 |
GLenum pname = GL_NONE; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
431 |
GLint val = 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
432 |
if (shader_type == MOJOSHADER_TYPE_VERTEX) |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
433 |
pname = GL_MAX_VERTEX_UNIFORM_COMPONENTS; |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
434 |
else if (shader_type == MOJOSHADER_TYPE_PIXEL) |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
435 |
pname = GL_MAX_FRAGMENT_UNIFORM_COMPONENTS; |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
436 |
else |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
437 |
return -1; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
438 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
439 |
ctx->glGetIntegerv(pname, &val); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
440 |
return (int) val; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
441 |
} // impl_GLSL_MaxUniforms |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
442 |
|
1225
50b8dd7e0b1a
Add GLSPIRV profile, to allow for both GL- and VK-friendly SPIR-V output
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1224
diff
changeset
|
443 |
#if SUPPORT_PROFILE_GLSPIRV |
1224
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
444 |
static const SpirvPatchTable* spv_getPatchTable(MOJOSHADER_glShader *shader) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
445 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
446 |
const MOJOSHADER_parseData *pd = shader->parseData; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
447 |
size_t table_offset = pd->output_len - sizeof(SpirvPatchTable); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
448 |
return (const SpirvPatchTable *) (pd->output + table_offset); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
449 |
} // spv_getPatchTable |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
450 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
451 |
static int spv_CompileShader(const MOJOSHADER_parseData *pd, int32 base_location, GLuint *s, int32 patch_pcoord) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
452 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
453 |
GLint ok = 0; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
454 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
455 |
GLsizei data_len = pd->output_len - sizeof(SpirvPatchTable); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
456 |
const GLvoid* data = pd->output; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
457 |
uint32 *patched_data = NULL; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
458 |
if (base_location || patch_pcoord) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
459 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
460 |
size_t i, max; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
461 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
462 |
patched_data = (uint32 *) Malloc(data_len); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
463 |
memcpy(patched_data, data, data_len); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
464 |
const SpirvPatchTable *table = (const SpirvPatchTable *) &pd->output[data_len]; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
465 |
if (table->vpflip.offset) patched_data[table->vpflip.offset] += base_location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
466 |
if (table->array_vec4.offset) patched_data[table->array_vec4.offset] += base_location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
467 |
if (table->array_ivec4.offset) patched_data[table->array_ivec4.offset] += base_location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
468 |
if (table->array_bool.offset) patched_data[table->array_bool.offset] += base_location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
469 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
470 |
for (i = 0, max = STATICARRAYLEN(table->samplers); i < max; i++) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
471 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
472 |
SpirvPatchEntry entry = table->samplers[i]; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
473 |
if (entry.offset) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
474 |
patched_data[entry.offset] += base_location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
475 |
} // for |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
476 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
477 |
if (patch_pcoord && table->ps_texcoord0_offset) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
478 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
479 |
// Subtract 3 to get from Location value offset to start of op. |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
480 |
uint32 op_base = table->ps_texcoord0_offset - 3; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
481 |
assert(patched_data[op_base+0] == (SpvOpDecorate | (4 << 16))); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
482 |
assert(patched_data[op_base+2] == SpvDecorationLocation); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
483 |
patched_data[op_base+2] = SpvDecorationBuiltIn; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
484 |
patched_data[op_base+3] = SpvBuiltInPointCoord; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
485 |
} // if |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
486 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
487 |
data = patched_data; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
488 |
} // if |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
489 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
490 |
const GLuint shader = ctx->glCreateShader(glsl_shader_type(pd->shader_type)); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
491 |
ctx->glShaderBinary(1, &shader, GL_SHADER_BINARY_FORMAT_SPIR_V_ARB, data, data_len); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
492 |
ctx->glSpecializeShaderARB(shader, pd->mainfn, 0, NULL, NULL); // FIXME: Spec Constants? -flibit |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
493 |
ctx->glGetShaderiv(shader, GL_COMPILE_STATUS, &ok); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
494 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
495 |
if (patched_data) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
496 |
Free(patched_data); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
497 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
498 |
if (!ok) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
499 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
500 |
GLsizei len = 0; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
501 |
ctx->glGetShaderInfoLog(shader, sizeof(error_buffer), &len, |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
502 |
(GLchar *) error_buffer); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
503 |
ctx->glDeleteShader(shader); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
504 |
*s = 0; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
505 |
return 0; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
506 |
} // if |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
507 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
508 |
*s = shader; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
509 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
510 |
return 1; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
511 |
} // spv_CompileShader |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
512 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
513 |
static int impl_SPIRV_CompileShader(const MOJOSHADER_parseData *pd, GLuint *s) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
514 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
515 |
// Compilation postponed until linking, but generate dummy shader id so hash table lookups work. |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
516 |
*s = ctx->glCreateShader(glsl_shader_type(pd->shader_type)); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
517 |
return 1; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
518 |
} // impl_SPIRV_CompileShader |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
519 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
520 |
static GLuint impl_SPIRV_LinkProgram(MOJOSHADER_glShader *vshader, |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
521 |
MOJOSHADER_glShader *pshader) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
522 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
523 |
GLint ok = 0; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
524 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
525 |
// Shader compilation postponed until linking due to uniform locations being global in program. |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
526 |
// To avoid overlap between VS and PS, we need to know about other shader stages to assign final |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
527 |
// uniform locations before compilation. |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
528 |
GLuint vs_handle = 0; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
529 |
int32 base_location = 0; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
530 |
int32 patch_pcoord = 0; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
531 |
if (vshader) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
532 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
533 |
if (!spv_CompileShader(vshader->parseData, base_location, &vs_handle, patch_pcoord)) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
534 |
return 0; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
535 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
536 |
const SpirvPatchTable* patch_table = spv_getPatchTable(vshader); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
537 |
base_location += patch_table->location_count; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
538 |
patch_pcoord = patch_table->vs_has_psize; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
539 |
} // if |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
540 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
541 |
GLuint ps_handle = 0; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
542 |
if (pshader) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
543 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
544 |
if (!spv_CompileShader(pshader->parseData, base_location, &ps_handle, patch_pcoord)) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
545 |
return 0; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
546 |
} // if |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
547 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
548 |
if (ctx->have_opengl_2) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
549 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
550 |
const GLuint program = ctx->glCreateProgram(); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
551 |
if (vs_handle) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
552 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
553 |
ctx->glAttachShader(program, vs_handle); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
554 |
ctx->glDeleteShader(vs_handle); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
555 |
} // if |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
556 |
if (ps_handle) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
557 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
558 |
ctx->glAttachShader(program, ps_handle); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
559 |
ctx->glDeleteShader(ps_handle); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
560 |
} // if |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
561 |
ctx->glLinkProgram(program); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
562 |
ctx->glGetProgramiv(program, GL_LINK_STATUS, &ok); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
563 |
if (!ok) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
564 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
565 |
GLsizei len = 0; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
566 |
ctx->glGetProgramInfoLog(program, sizeof (error_buffer), |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
567 |
&len, (GLchar *) error_buffer); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
568 |
ctx->glDeleteProgram(program); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
569 |
return 0; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
570 |
} // if |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
571 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
572 |
return program; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
573 |
} // if |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
574 |
else |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
575 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
576 |
const GLhandleARB program = ctx->glCreateProgramObjectARB(); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
577 |
assert(sizeof(program) == sizeof(GLuint)); // not always true on OS X! |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
578 |
if (vs_handle) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
579 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
580 |
ctx->glAttachObjectARB(program, (GLhandleARB) vs_handle); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
581 |
ctx->glDeleteObjectARB((GLhandleARB) vs_handle); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
582 |
} // if |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
583 |
if (ps_handle) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
584 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
585 |
ctx->glAttachObjectARB(program, (GLhandleARB) ps_handle); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
586 |
ctx->glDeleteObjectARB((GLhandleARB) ps_handle); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
587 |
} // if |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
588 |
ctx->glLinkProgramARB(program); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
589 |
ctx->glGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB, &ok); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
590 |
if (!ok) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
591 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
592 |
GLsizei len = 0; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
593 |
ctx->glGetInfoLogARB(program, sizeof (error_buffer), |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
594 |
&len, (GLcharARB *) error_buffer); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
595 |
ctx->glDeleteObjectARB(program); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
596 |
return 0; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
597 |
} // if |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
598 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
599 |
return (GLuint) program; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
600 |
} // else |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
601 |
} // impl_SPIRV_LinkProgram |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
602 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
603 |
static void impl_SPIRV_DeleteShader(const GLuint shader) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
604 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
605 |
ctx->glDeleteShader(shader); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
606 |
} // impl_SPIRV_DeleteShader |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
607 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
608 |
static void impl_SPIRV_DeleteProgram(const GLuint program) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
609 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
610 |
if (ctx->have_opengl_2) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
611 |
ctx->glDeleteProgram(program); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
612 |
else |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
613 |
ctx->glDeleteObjectARB((GLhandleARB) program); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
614 |
} // impl_SPIRV_DeleteProgram |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
615 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
616 |
static GLint impl_SPIRV_GetAttribLocation(MOJOSHADER_glProgram *program, int idx) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
617 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
618 |
return idx; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
619 |
} // impl_SPIRV_GetAttribLocation |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
620 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
621 |
static GLint impl_SPIRV_GetUniformLocation(MOJOSHADER_glProgram *program, MOJOSHADER_glShader *shader, int idx) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
622 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
623 |
return 0; // no-op, we push this as one big-ass array now. |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
624 |
} // impl_SPIRV_GetUniformLocation |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
625 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
626 |
static GLint impl_SPIRV_GetSamplerLocation(MOJOSHADER_glProgram *program, MOJOSHADER_glShader *shader, int idx) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
627 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
628 |
const SpirvPatchTable *table = spv_getPatchTable(shader); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
629 |
GLint location = table->samplers[idx].location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
630 |
if (location == -1) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
631 |
return location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
632 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
633 |
assert(location >= 0); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
634 |
if (shader->parseData->shader_type == MOJOSHADER_TYPE_PIXEL) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
635 |
location += spv_getPatchTable(program->vertex)->location_count; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
636 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
637 |
return location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
638 |
} // impl_SPIRV_GetSamplerLocation |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
639 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
640 |
static void impl_SPIRV_FinalInitProgram(MOJOSHADER_glProgram *program) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
641 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
642 |
const SpirvPatchTable *vs_table = spv_getPatchTable(program->vertex); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
643 |
const SpirvPatchTable *ps_table = spv_getPatchTable(program->fragment); |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
644 |
program->vs_float4_loc = vs_table->array_vec4.location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
645 |
program->vs_int4_loc = vs_table->array_ivec4.location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
646 |
program->vs_bool_loc = vs_table->array_bool.location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
647 |
program->ps_float4_loc = ps_table->array_vec4.location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
648 |
program->ps_int4_loc = ps_table->array_ivec4.location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
649 |
program->ps_bool_loc = ps_table->array_bool.location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
650 |
program->ps_vpos_flip_loc = ps_table->vpflip.location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
651 |
#ifdef MOJOSHADER_FLIP_RENDERTARGET |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
652 |
program->vs_flip_loc = vs_table->vpflip.location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
653 |
#endif |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
654 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
655 |
int32 ps_base_location = vs_table->location_count; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
656 |
if (ps_base_location) |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
657 |
{ |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
658 |
if (program->ps_float4_loc != -1) program->ps_float4_loc += ps_base_location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
659 |
if (program->ps_int4_loc != -1) program->ps_int4_loc += ps_base_location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
660 |
if (program->ps_bool_loc != -1) program->ps_bool_loc += ps_base_location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
661 |
if (program->ps_vpos_flip_loc != -1) program->ps_vpos_flip_loc += ps_base_location; |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
662 |
} // if |
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
663 |
} // impl_SPIRV_FinalInitProgram |
1225
50b8dd7e0b1a
Add GLSPIRV profile, to allow for both GL- and VK-friendly SPIR-V output
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1224
diff
changeset
|
664 |
#endif // SUPPORT_PROFILE_GLSPIRV |
1224
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
665 |
|
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
666 |
#if SUPPORT_PROFILE_GLSL |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
667 |
static int impl_GLSL_CompileShader(const MOJOSHADER_parseData *pd, GLuint *s) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
668 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
669 |
GLint ok = 0; |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
670 |
const GLint codelen = (GLint) pd->output_len; |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
671 |
const GLenum shader_type = glsl_shader_type(pd->shader_type); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
672 |
|
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
673 |
if (ctx->have_opengl_2) |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
674 |
{ |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
675 |
const GLuint shader = ctx->glCreateShader(shader_type); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
676 |
ctx->glShaderSource(shader, 1, (const GLchar**) &pd->output, &codelen); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
677 |
ctx->glCompileShader(shader); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
678 |
ctx->glGetShaderiv(shader, GL_COMPILE_STATUS, &ok); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
679 |
if (!ok) |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
680 |
{ |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
681 |
GLsizei len = 0; |
1125
3de60f597ebd
Don't use the extension entry point glGetInfoLogARB() in the core GL2 path.
Ryan C. Gordon <icculus@icculus.org>
parents:
1124
diff
changeset
|
682 |
ctx->glGetShaderInfoLog(shader, sizeof (error_buffer), &len, |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
683 |
(GLchar *) error_buffer); |
1124
464fc9101a7e
Leak fix: delete GLSL shader objects if we fail to compile.
Ryan C. Gordon <icculus@icculus.org>
parents:
1118
diff
changeset
|
684 |
ctx->glDeleteShader(shader); |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
685 |
*s = 0; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
686 |
return 0; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
687 |
} // if |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
688 |
|
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
689 |
*s = shader; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
690 |
} // if |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
691 |
else |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
692 |
{ |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
693 |
const GLhandleARB shader = ctx->glCreateShaderObjectARB(shader_type); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
694 |
assert(sizeof (shader) == sizeof (*s)); // not always true on OS X! |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
695 |
ctx->glShaderSourceARB(shader, 1, |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
696 |
(const GLcharARB **) &pd->output, &codelen); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
697 |
ctx->glCompileShaderARB(shader); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
698 |
ctx->glGetObjectParameterivARB(shader,GL_OBJECT_COMPILE_STATUS_ARB,&ok); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
699 |
if (!ok) |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
700 |
{ |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
701 |
GLsizei len = 0; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
702 |
ctx->glGetInfoLogARB(shader, sizeof (error_buffer), &len, |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
703 |
(GLcharARB *) error_buffer); |
1124
464fc9101a7e
Leak fix: delete GLSL shader objects if we fail to compile.
Ryan C. Gordon <icculus@icculus.org>
parents:
1118
diff
changeset
|
704 |
ctx->glDeleteObjectARB(shader); |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
705 |
*s = 0; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
706 |
return 0; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
707 |
} // if |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
708 |
|
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
709 |
*s = (GLuint) shader; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
710 |
} // else |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
711 |
|
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
712 |
return 1; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
713 |
} // impl_GLSL_CompileShader |
1224
21cd84f1aa0a
Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
1223
diff
changeset
|
714 |
#endif // SUPPORT_PROFILE_GLSL |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
715 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
716 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
717 |
static void impl_GLSL_DeleteShader(const GLuint shader) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
718 |
{ |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
719 |
if (ctx->have_opengl_2) |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
720 |
ctx->glDeleteShader(shader); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
721 |
else |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
722 |
ctx->glDeleteObjectARB((GLhandleARB) shader); |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
723 |
} // impl_GLSL_DeleteShader |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
724 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
725 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
726 |
static void impl_GLSL_DeleteProgram(const GLuint program) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
727 |
{ |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
728 |
if (ctx->have_opengl_2) |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
729 |
ctx->glDeleteProgram(program); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
730 |
else |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
731 |
ctx->glDeleteObjectARB((GLhandleARB) program); |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
732 |
} // impl_GLSL_DeleteProgram |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
733 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
734 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
735 |
static GLint impl_GLSL_GetUniformLocation(MOJOSHADER_glProgram *program, |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
736 |
MOJOSHADER_glShader *shader, int idx) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
737 |
{ |
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
738 |
return 0; // no-op, we push this as one big-ass array now. |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
739 |
} // impl_GLSL_GetUniformLocation |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
740 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
741 |
|
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
742 |
static inline GLint glsl_uniform_loc(MOJOSHADER_glProgram *program, |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
743 |
const char *name) |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
744 |
{ |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
745 |
return ctx->have_opengl_2 ? |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
746 |
ctx->glGetUniformLocation(program->handle, name) : |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
747 |
ctx->glGetUniformLocationARB((GLhandleARB) program->handle, name); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
748 |
} // glsl_uniform_loc |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
749 |
|
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
750 |
|
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
751 |
static GLint impl_GLSL_GetSamplerLocation(MOJOSHADER_glProgram *program, |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
752 |
MOJOSHADER_glShader *shader, int idx) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
753 |
{ |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
754 |
return glsl_uniform_loc(program, shader->parseData->samplers[idx].name); |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
755 |
} // impl_GLSL_GetSamplerLocation |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
756 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
757 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
758 |
static GLint impl_GLSL_GetAttribLocation(MOJOSHADER_glProgram *program, int idx) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
759 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
760 |
const MOJOSHADER_parseData *pd = program->vertex->parseData; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
761 |
const MOJOSHADER_attribute *a = pd->attributes; |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
762 |
|
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
763 |
if (ctx->have_opengl_2) |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
764 |
{ |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
765 |
return ctx->glGetAttribLocation(program->handle, |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
766 |
(const GLchar *) a[idx].name); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
767 |
} // if |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
768 |
|
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
769 |
return ctx->glGetAttribLocationARB((GLhandleARB) program->handle, |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
770 |
(const GLcharARB *) a[idx].name); |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
771 |
} // impl_GLSL_GetAttribLocation |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
772 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
773 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
774 |
static GLuint impl_GLSL_LinkProgram(MOJOSHADER_glShader *vshader, |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
775 |
MOJOSHADER_glShader *pshader) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
776 |
{ |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
777 |
GLint ok = 0; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
778 |
|
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
779 |
if (ctx->have_opengl_2) |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
780 |
{ |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
781 |
const GLuint program = ctx->glCreateProgram(); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
782 |
|
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
783 |
if (vshader != NULL) ctx->glAttachShader(program, vshader->handle); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
784 |
if (pshader != NULL) ctx->glAttachShader(program, pshader->handle); |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
785 |
|
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
786 |
ctx->glLinkProgram(program); |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
787 |
|
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
788 |
ctx->glGetProgramiv(program, GL_LINK_STATUS, &ok); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
789 |
if (!ok) |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
790 |
{ |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
791 |
GLsizei len = 0; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
792 |
ctx->glGetProgramInfoLog(program, sizeof (error_buffer), |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
793 |
&len, (GLchar *) error_buffer); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
794 |
ctx->glDeleteProgram(program); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
795 |
return 0; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
796 |
} // if |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
797 |
|
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
798 |
return program; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
799 |
} // if |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
800 |
else |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
801 |
{ |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
802 |
const GLhandleARB program = ctx->glCreateProgramObjectARB(); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
803 |
assert(sizeof(program) == sizeof(GLuint)); // not always true on OS X! |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
804 |
|
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
805 |
if (vshader != NULL) |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
806 |
ctx->glAttachObjectARB(program, (GLhandleARB) vshader->handle); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
807 |
|
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
808 |
if (pshader != NULL) |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
809 |
ctx->glAttachObjectARB(program, (GLhandleARB) pshader->handle); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
810 |
|
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
811 |
ctx->glLinkProgramARB(program); |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
812 |
|
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
813 |
ctx->glGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB, &ok); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
814 |
if (!ok) |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
815 |
{ |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
816 |
GLsizei len = 0; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
817 |
ctx->glGetInfoLogARB(program, sizeof (error_buffer), |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
818 |
&len, (GLcharARB *) error_buffer); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
819 |
ctx->glDeleteObjectARB(program); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
820 |
return 0; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
821 |
} // if |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
822 |
|
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
823 |
return (GLuint) program; |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
824 |
} // else |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
825 |
} // impl_GLSL_LinkProgram |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
826 |
|
765
076f3bd42329
Moved profileInitProgram to profileFinalInitProgram.
Ryan C. Gordon <icculus@icculus.org>
parents:
764
diff
changeset
|
827 |
static void impl_GLSL_FinalInitProgram(MOJOSHADER_glProgram *program) |
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
828 |
{ |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
829 |
program->vs_float4_loc = glsl_uniform_loc(program, "vs_uniforms_vec4"); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
830 |
program->vs_int4_loc = glsl_uniform_loc(program, "vs_uniforms_ivec4"); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
831 |
program->vs_bool_loc = glsl_uniform_loc(program, "vs_uniforms_bool"); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
832 |
program->ps_float4_loc = glsl_uniform_loc(program, "ps_uniforms_vec4"); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
833 |
program->ps_int4_loc = glsl_uniform_loc(program, "ps_uniforms_ivec4"); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
834 |
program->ps_bool_loc = glsl_uniform_loc(program, "ps_uniforms_bool"); |
1210
c586d4590241
Replace glProgramViewportFlip with glProgramViewportInfo
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1207
diff
changeset
|
835 |
program->ps_vpos_flip_loc = glsl_uniform_loc(program, "vposFlip"); |
1150
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
836 |
#ifdef MOJOSHADER_FLIP_RENDERTARGET |
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
837 |
program->vs_flip_loc = glsl_uniform_loc(program, "vpFlip"); |
02c0f0afb39a
- Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1149
diff
changeset
|
838 |
#endif |
765
076f3bd42329
Moved profileInitProgram to profileFinalInitProgram.
Ryan C. Gordon <icculus@icculus.org>
parents:
764
diff
changeset
|
839 |
} // impl_GLSL_FinalInitProgram |
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
840 |
|
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
841 |
|
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
842 |
static void impl_GLSL_UseProgram(MOJOSHADER_glProgram *program) |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
843 |
{ |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
844 |
if (ctx->have_opengl_2) |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
845 |
ctx->glUseProgram(program ? program->handle : 0); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
846 |
else |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
847 |
ctx->glUseProgramObjectARB((GLhandleARB) (program ? program->handle : 0)); |
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
848 |
} // impl_GLSL_UseProgram |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
849 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
850 |
|
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
851 |
static void impl_GLSL_PushConstantArray(MOJOSHADER_glProgram *program, |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
852 |
const MOJOSHADER_uniform *u, |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
853 |
const GLfloat *f) |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
854 |
{ |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
855 |
const GLint loc = glsl_uniform_loc(program, u->name); |
798
5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
797
diff
changeset
|
856 |
if (loc >= 0) // not optimized out? |
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
857 |
ctx->glUniform4fv(loc, u->array_count, f); |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
858 |
} // impl_GLSL_PushConstantArray |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
859 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
860 |
|
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
861 |
static void impl_GLSL_PushUniforms(void) |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
862 |
{ |
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
863 |
const MOJOSHADER_glProgram *program = ctx->bound_program; |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
864 |
|
768
9ba81386bd4d
Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents:
767
diff
changeset
|
865 |
assert(program->uniform_count > 0); // don't call with nothing to do! |
9ba81386bd4d
Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents:
767
diff
changeset
|
866 |
|
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
867 |
if (program->vs_float4_loc != -1) |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
868 |
{ |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
869 |
ctx->glUniform4fv(program->vs_float4_loc, |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
870 |
program->vs_uniforms_float4_count, |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
871 |
program->vs_uniforms_float4); |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
872 |
} // if |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
873 |
|
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
874 |
if (program->vs_int4_loc != -1) |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
875 |
{ |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
876 |
ctx->glUniform4iv(program->vs_int4_loc, |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
877 |
program->vs_uniforms_int4_count, |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
878 |
program->vs_uniforms_int4); |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
879 |
} // if |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
880 |
|
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
881 |
if (program->vs_bool_loc != -1) |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
882 |
{ |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
883 |
ctx->glUniform1iv(program->vs_bool_loc, |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
884 |
program->vs_uniforms_bool_count, |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
885 |
program->vs_uniforms_bool); |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
886 |
} // if |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
887 |
|
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
888 |
if (program->ps_float4_loc != -1) |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
889 |
{ |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
890 |
ctx->glUniform4fv(program->ps_float4_loc, |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
891 |
program->ps_uniforms_float4_count, |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
892 |
program->ps_uniforms_float4); |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
893 |
} // if |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
894 |
|
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
895 |
if (program->ps_int4_loc != -1) |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
896 |
{ |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
897 |
ctx->glUniform4iv(program->ps_int4_loc, |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
898 |
program->ps_uniforms_int4_count, |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
899 |
program->ps_uniforms_int4); |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
900 |
} // if |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
901 |
|
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
902 |
if (program->ps_bool_loc != -1) |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
903 |
{ |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
904 |
ctx->glUniform1iv(program->ps_bool_loc, |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
905 |
program->ps_uniforms_bool_count, |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
906 |
program->ps_uniforms_bool); |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
907 |
} // if |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
908 |
} // impl_GLSL_PushUniforms |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
909 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
910 |
|
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
911 |
static void impl_GLSL_PushSampler(GLint loc, GLuint sampler) |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
912 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
913 |
ctx->glUniform1i(loc, sampler); |
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
914 |
} // impl_GLSL_PushSampler |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
915 |
|
1225
50b8dd7e0b1a
Add GLSPIRV profile, to allow for both GL- and VK-friendly SPIR-V output
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1224
diff
changeset
|
916 |
#endif // SUPPORT_PROFILE_GLSL || SUPPORT_PROFILE_GLSPIRV |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
917 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
918 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
919 |
#if SUPPORT_PROFILE_ARB1 |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
920 |
static inline GLenum arb1_shader_type(const MOJOSHADER_shaderType t) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
921 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
922 |
if (t == MOJOSHADER_TYPE_VERTEX) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
923 |
return GL_VERTEX_PROGRAM_ARB; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
924 |
else if (t == MOJOSHADER_TYPE_PIXEL) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
925 |
return GL_FRAGMENT_PROGRAM_ARB; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
926 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
927 |
// !!! FIXME: geometry shaders? |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
928 |
return GL_NONE; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
929 |
} // arb1_shader_type |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
930 |
|
760
6dc8d2cafc58
"Must Push" seemed more correct than "Must Load".
Ryan C. Gordon <icculus@icculus.org>
parents:
759
diff
changeset
|
931 |
static int impl_ARB1_MustPushConstantArrays(void) { return 0; } |
6dc8d2cafc58
"Must Push" seemed more correct than "Must Load".
Ryan C. Gordon <icculus@icculus.org>
parents:
759
diff
changeset
|
932 |
static int impl_ARB1_MustPushSamplers(void) { return 0; } |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
933 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
934 |
static int impl_ARB1_MaxUniforms(MOJOSHADER_shaderType shader_type) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
935 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
936 |
GLint retval = 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
937 |
const GLenum program_type = arb1_shader_type(shader_type); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
938 |
if (program_type == GL_NONE) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
939 |
return -1; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
940 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
941 |
ctx->glGetProgramivARB(program_type, GL_MAX_PROGRAM_PARAMETERS_ARB, &retval); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
942 |
return (int) retval; // !!! FIXME: times four? |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
943 |
} // impl_ARB1_MaxUniforms |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
944 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
945 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
946 |
static int impl_ARB1_CompileShader(const MOJOSHADER_parseData *pd, GLuint *s) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
947 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
948 |
GLint shaderlen = (GLint) pd->output_len; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
949 |
const GLenum shader_type = arb1_shader_type(pd->shader_type); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
950 |
GLuint shader = 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
951 |
ctx->glGenProgramsARB(1, &shader); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
952 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
953 |
ctx->glGetError(); // flush any existing error state. |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
954 |
ctx->glBindProgramARB(shader_type, shader); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
955 |
ctx->glProgramStringARB(shader_type, GL_PROGRAM_FORMAT_ASCII_ARB, |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
956 |
shaderlen, pd->output); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
957 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
958 |
if (ctx->glGetError() == GL_INVALID_OPERATION) |
1223
32ab7e4fbdc6
Various style/redundancy fixes found during SPIR-V work
Martin Krošlák <kroslakma@gmail.com>
parents:
1210
diff
changeset
|
959 |
{ |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
960 |
GLint pos = 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
961 |
ctx->glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
962 |
const GLubyte *errstr = ctx->glGetString(GL_PROGRAM_ERROR_STRING_ARB); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
963 |
snprintf(error_buffer, sizeof (error_buffer), |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
964 |
"ARB1 compile error at position %d: %s", |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
965 |
(int) pos, (const char *) errstr); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
966 |
ctx->glBindProgramARB(shader_type, 0); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
967 |
ctx->glDeleteProgramsARB(1, &shader); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
968 |
*s = 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
969 |
return 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
970 |
} // if |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
971 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
972 |
*s = shader; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
973 |
return 1; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
974 |
} // impl_ARB1_CompileShader |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
975 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
976 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
977 |
static void impl_ARB1_DeleteShader(const GLuint _shader) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
978 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
979 |
GLuint shader = _shader; // const removal. |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
980 |
ctx->glDeleteProgramsARB(1, &shader); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
981 |
} // impl_ARB1_DeleteShader |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
982 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
983 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
984 |
static void impl_ARB1_DeleteProgram(const GLuint program) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
985 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
986 |
// no-op. ARB1 doesn't have real linked programs. |
1173
4b2f745c643b
GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1156
diff
changeset
|
987 |
} // impl_ARB1_DeleteProgram |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
988 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
989 |
static GLint impl_ARB1_GetUniformLocation(MOJOSHADER_glProgram *program, |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
990 |
MOJOSHADER_glShader *shader, int idx) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
991 |
{ |
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
992 |
return 0; // no-op, we push this as one big-ass array now. |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
993 |
} // impl_ARB1_GetUniformLocation |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
994 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
995 |
static GLint impl_ARB1_GetSamplerLocation(MOJOSHADER_glProgram *program, |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
996 |
MOJOSHADER_glShader *shader, int idx) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
997 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
998 |
return shader->parseData->samplers[idx].index; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
999 |
} // impl_ARB1_GetSamplerLocation |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1000 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1001 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1002 |
static GLint impl_ARB1_GetAttribLocation(MOJOSHADER_glProgram *program, int idx) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1003 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1004 |
return idx; // map to vertex arrays in the same order as the parseData. |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1005 |
} // impl_ARB1_GetAttribLocation |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1006 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1007 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1008 |
static GLuint impl_ARB1_LinkProgram(MOJOSHADER_glShader *vshader, |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1009 |
MOJOSHADER_glShader *pshader) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1010 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1011 |
// there is no formal linking in ARB1...just return a unique value. |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1012 |
static GLuint retval = 1; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1013 |
return retval++; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1014 |
} // impl_ARB1_LinkProgram |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1015 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1016 |
|
765
076f3bd42329
Moved profileInitProgram to profileFinalInitProgram.
Ryan C. Gordon <icculus@icculus.org>
parents:
764
diff
changeset
|
1017 |
static void impl_ARB1_FinalInitProgram(MOJOSHADER_glProgram *program) |
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1018 |
{ |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1019 |
// no-op. |
765
076f3bd42329
Moved profileInitProgram to profileFinalInitProgram.
Ryan C. Gordon <icculus@icculus.org>
parents:
764
diff
changeset
|
1020 |
} // impl_ARB1_FinalInitProgram |
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1021 |
|
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1022 |
|
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
1023 |
static void impl_ARB1_UseProgram(MOJOSHADER_glProgram *program) |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1024 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1025 |
GLuint vhandle = 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1026 |
GLuint phandle = 0; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1027 |
if (program != NULL) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1028 |
{ |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1029 |
if (program->vertex != NULL) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1030 |
vhandle = program->vertex->handle; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1031 |
if (program->fragment != NULL) |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1032 |
phandle = program->fragment->handle; |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1033 |
} // if |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1034 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1035 |
toggle_gl_state(GL_VERTEX_PROGRAM_ARB, vhandle != 0); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1036 |
toggle_gl_state(GL_FRAGMENT_PROGRAM_ARB, phandle != 0); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1037 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1038 |
ctx->glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vhandle); |
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1039 |
ctx->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, phandle); |
1072
3400f252c4e0
Fixed up calling GL2 vs ARB extension entry points.
Ryan C. Gordon <icculus@icculus.org>
parents:
1071
diff
changeset
|
1040 |
} // impl_ARB1_UseProgram |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1041 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1042 |
|
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1043 |
static void impl_ARB1_PushConstantArray(MOJOSHADER_glProgram *program, |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1044 |
const MOJOSHADER_uniform *u, |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1045 |
const GLfloat *f) |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1046 |
{ |
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1047 |
// no-op. Constant arrays are defined in source code for arb1. |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1048 |
} // impl_ARB1_PushConstantArray |
411
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1049 |
|
01bc1352c047
Rearranged profile-specific functions in OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents:
410
diff
changeset
|
1050 |
|
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1051 |
static void impl_ARB1_PushUniforms(void) |
431
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
1052 |
{ |
768
9ba81386bd4d
Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents:
767
diff
changeset
|
1053 |
// vertex shader uniforms come first in program->uniforms array. |
9ba81386bd4d
Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents:
767
diff
changeset
|
1054 |
MOJOSHADER_shaderType shader_type = MOJOSHADER_TYPE_VERTEX; |
9ba81386bd4d
Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents:
767
diff
changeset
|
1055 |
GLenum arb_shader_type = arb1_shader_type(shader_type); |
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1056 |
const MOJOSHADER_glProgram *program = ctx->bound_program; |
768
9ba81386bd4d
Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents:
767
diff
changeset
|
1057 |
const uint32 count = program->uniform_count; |
9ba81386bd4d
Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents:
767
diff
changeset
|
1058 |
const GLfloat *srcf = program->vs_uniforms_float4; |
9ba81386bd4d
Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents:
767
diff
changeset
|
1059 |
const GLint *srci = program->vs_uniforms_int4; |
9ba81386bd4d
Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents:
767
diff
changeset
|
1060 |
const GLint *srcb = program->vs_uniforms_bool; |
9ba81386bd4d
Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents:
767
diff
changeset
|
1061 |
GLint loc = 0; |
1090
636ffcd3f14a
First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
1062 |
GLint texbem_loc = 0; |
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1063 |
uint32 i; |
431
0d0cbe10db02
First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents:
424
diff
changeset
|
1064 |
|
768
9ba81386bd4d
Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents:
767
diff
changeset
|
1065 |
assert(count > 0); // shouldn't call this with nothing to do! |
9ba81386bd4d
Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents:
767
diff
changeset
|
1066 |
|
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1067 |
for (i = 0; i < count; i++) |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1068 |
{ |
767
806ba18f23aa
Cleanups and fixes in ARB1 uniform pushing.
Ryan C. Gordon <icculus@icculus.org>
parents:
766
diff
changeset
|
1069 |
UniformMap *map = &program->uniforms[i]; |
770
b5e545408b02
Fixed incorrect variable name.
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
1070 |
const MOJOSHADER_shaderType uniform_shader_type = map->shader_type; |
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1071 |
const MOJOSHADER_uniform *u = map->uniform; |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1072 |
const MOJOSHADER_uniformType type = u->type; |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1073 |
const int size = u->array_count ? u->array_count : 1; |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1074 |
|
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1075 |
assert(!u->constant); |
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1076 |
|
768
9ba81386bd4d
Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents:
767
diff
changeset
|
1077 |
// Did we switch from vertex to pixel (to geometry, etc)? |
770
b5e545408b02
Fixed incorrect variable name.
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
1078 |
if (shader_type != uniform_shader_type) |
763
ef6489e7e263
Serious OpenGL glue surgery to push uniforms as one big array.
Ryan C. Gordon <icculus@icculus.org>
parents:
761
diff
changeset
|
1079 |
{ |
1090
636ffcd3f14a
First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
1080 |
if (shader_type == MOJOSHADER_TYPE_PIXEL) |
636ffcd3f14a
First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
1081 |
texbem_loc = loc; |
636ffcd3f14a
First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
1082 |
|
768
9ba81386bd4d
Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents:
767
diff
changeset
|
1083 |
// we start with vertex, move to pixel, then to geometry, etc. |
9ba81386bd4d
Optimize/cleanup in uniform array iteration work.
Ryan C. Gordon <icculus@icculus.org>
parents:
767
diff
changeset
|
1084 |
// The array should always be sorted as such. |
770 |