GLUtil_GL.cs 5.39 KB
Newer Older
pcy's avatar
initial  
pcy committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System;
using System.Collections.Generic;
using System.Linq;

using GLenum     = System.UInt32;
using GLboolean  = System.Byte  ;
using GLbitfield = System.UInt32;
using GLvoid     = System.Void  ;
using GLbyte     = System.SByte ;
using GLshort    = System.Int16 ;
using GLint      = System.Int32 ;
using GLubyte    = System.Byte  ;
using GLushort   = System.UInt16;
using GLuint     = System.UInt32;
using GLsizei    = System.Int32 ;
using GLfloat    = System.Single;
using GLclampf   = System.Single;
using GLdouble   = System.Double;
using GLclampd   = System.Double;
using GLchar     = System.SByte ;

namespace PoroCYon.FNAGLSL {
	public static unsafe partial class GL {
		public const GLenum
			COMPILE_STATUS  = 0x8B81,
			INFO_LOG_LENGTH = 0x8B84,
27
28
			LINK_STATUS     = 0x8B82,
			CURRENT_PROGRAM = 0x8B8D;
pcy's avatar
initial  
pcy committed
29
30

		static void InitProcs() {
pcy's avatar
pcy committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
			_GetError      = GetProcAddress<GetError_T>("GetError");
			_CreateProgram = GetProcAddress<CreateProgram_T>("CreateProgram");
			_CreateShader  = GetProcAddress<CreateShader_T>("CreateShader");
			_ShaderSource  = GetProcAddress<ShaderSource_T>("ShaderSource");
			_CompileShader = GetProcAddress<CompileShader_T>("CompileShader");
			_GetShaderiv   = GetProcAddress<GetShaderiv_T>("GetShaderiv");
			_GetShaderInfoLog = GetProcAddress<GetShaderInfoLog_T>("GetShaderInfoLog");
			_AttachShader  = GetProcAddress<AttachShader_T>("AttachShader");
			_LinkProgram   = GetProcAddress<LinkProgram_T>("LinkProgram");
			_GetProgramiv  = GetProcAddress<GetProgramiv_T>("GetProgramiv");
			_GetProgramInfoLog = GetProcAddress<GetProgramInfoLog_T>("GetProgramInfoLog");
			_DeleteShader  = GetProcAddress<DeleteShader_T>("DeleteShader");
			_DeleteProgram = GetProcAddress<DeleteProgram_T>("DeleteProgram");
			_UseProgram    = GetProcAddress<UseProgram_T>("UseProgram");
			_GetIntegerv   = GetProcAddress<GetIntegerv_T>("GetIntegerv");
pcy's avatar
initial  
pcy committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
		}
		static void DeinitProcs() {
			_GetError      = null;
			_CreateProgram = null;
			_CreateShader  = null;
			_ShaderSource  = null;
			_CompileShader = null;
			_GetShaderiv   = null;
			_GetShaderInfoLog = null;
			_AttachShader  = null;
			_LinkProgram   = null;
			_GetProgramiv  = null;
			_GetProgramInfoLog = null;
			_DeleteShader  = null;
			_DeleteProgram = null;
61
62
			_UseProgram    = null;
			_GetIntegerv   = null;
pcy's avatar
initial  
pcy committed
63
64
		}

pcy's avatar
pcy committed
65
66
		delegate GLenum GetError_T();
		static GetError_T _GetError;
pcy's avatar
initial  
pcy committed
67
68
		public static GLError GetError() => (GLError)_GetError();

pcy's avatar
pcy committed
69
70
		delegate GLuint CreateProgram_T();
		static CreateProgram_T _CreateProgram;
pcy's avatar
initial  
pcy committed
71
72
		public static GLuint CreateProgram() => _CreateProgram();

pcy's avatar
pcy committed
73
74
		delegate GLuint CreateShader_T(GLenum shtyp);
		static CreateShader_T _CreateShader;
pcy's avatar
initial  
pcy committed
75
76
77
		public static GLuint CreateShader(GLSLPurpose shtyp)
			=> _CreateShader((GLenum)shtyp);

pcy's avatar
pcy committed
78
79
80
		delegate void ShaderSource_T(GLuint sh, GLsizei count,
				GLchar** str, GLint* len);
		static ShaderSource_T _ShaderSource;
pcy's avatar
initial  
pcy committed
81
82
		public static void ShaderSource(GLuint sh, GLsizei count,
				GLchar** str, GLint* len) {
pcy's avatar
pcy committed
83
			_ShaderSource(sh, count, str, len);
pcy's avatar
initial  
pcy committed
84
85
		}

pcy's avatar
pcy committed
86
87
		delegate void CompileShader_T(GLuint sh);
		static CompileShader_T _CompileShader;
pcy's avatar
initial  
pcy committed
88
89
		public static void CompileShader(GLuint sh) { _CompileShader(sh); }

pcy's avatar
pcy committed
90
91
		delegate void GetShaderiv_T(GLuint sh, GLenum pname, GLint* parm);
		static GetShaderiv_T _GetShaderiv;
pcy's avatar
initial  
pcy committed
92
93
94
		public static GLint GetShaderiv(GLuint sh, GLenum pname) {
			GLint* parm = stackalloc GLint[1];
			*parm = 0;
pcy's avatar
pcy committed
95
			_GetShaderiv(sh, pname, parm);
pcy's avatar
initial  
pcy committed
96
97
98
			return *parm;
		}

pcy's avatar
pcy committed
99
100
101
		delegate void GetShaderInfoLog_T(GLuint sh, GLsizei maxl, GLsizei* len,
				GLchar* infolog);
		static GetShaderInfoLog_T _GetShaderInfoLog;
pcy's avatar
initial  
pcy committed
102
103
		public static void GetShaderInfoLog(GLuint sh, GLsizei maxl,
				GLsizei* len, GLchar* infolog) {
pcy's avatar
pcy committed
104
			_GetShaderInfoLog(sh, maxl, len, infolog);
pcy's avatar
initial  
pcy committed
105
106
		}

pcy's avatar
pcy committed
107
108
		delegate void AttachShader_T(GLuint pr, GLuint sh);
		static AttachShader_T _AttachShader;
pcy's avatar
initial  
pcy committed
109
110
111
112
		public static void AttachShader(GLuint prgm, GLuint sh) {
			_AttachShader(prgm, sh);
		}

pcy's avatar
pcy committed
113
114
		delegate void LinkProgram_T(GLuint pr);
		static LinkProgram_T _LinkProgram;
pcy's avatar
initial  
pcy committed
115
116
		public static void LinkProgram(GLuint prgm) { _LinkProgram(prgm); }

pcy's avatar
pcy committed
117
118
		delegate void GetProgramiv_T(GLuint pr, GLuint pnam, GLint* parm);
		static GetProgramiv_T _GetProgramiv;
pcy's avatar
initial  
pcy committed
119
120
121
122
		// FIXME: won't work with GL_COMPUTE_WORK_GROUP_SIZE
		public static GLint GetProgramiv(GLuint prgm, GLenum pname) {
			GLint* parm = stackalloc GLint[3];
			parm[2] = parm[1] = parm[0] = 0;
pcy's avatar
pcy committed
123
			_GetProgramiv(prgm, pname, parm);
pcy's avatar
initial  
pcy committed
124
125
126
			return parm[0];
		}

pcy's avatar
pcy committed
127
128
129
		delegate void GetProgramInfoLog_T(GLuint pr, GLsizei maxl,
				GLsizei* len, GLchar* infolog);
		static GetProgramInfoLog_T _GetProgramInfoLog;
pcy's avatar
initial  
pcy committed
130
131
		public static void GetProgramInfoLog(GLuint prgm, GLsizei maxl,
				GLsizei* len, GLchar* infolog) {
pcy's avatar
pcy committed
132
			_GetProgramInfoLog(prgm, maxl, len, infolog);
pcy's avatar
initial  
pcy committed
133
134
		}

pcy's avatar
pcy committed
135
136
		delegate void DeleteShader_T(GLuint sh);
		static DeleteShader_T _DeleteShader;
pcy's avatar
initial  
pcy committed
137
138
		public static void DeleteShader(GLuint sh) { _DeleteShader(sh); }

pcy's avatar
pcy committed
139
140
		delegate void DeleteProgram_T(GLuint pr);
		static DeleteProgram_T _DeleteProgram;
pcy's avatar
initial  
pcy committed
141
		public static void DeleteProgram(GLuint prgm) { _DeleteProgram(prgm); }
142

pcy's avatar
pcy committed
143
144
		delegate void UseProgram_T(GLuint pr);
		static UseProgram_T _UseProgram;
145
146
		public static void UseProgram(GLuint prgm) { _UseProgram(prgm); }

pcy's avatar
pcy committed
147
148
		delegate void GetIntegerv_T(GLenum n, GLint* parm);
		static GetIntegerv_T _GetIntegerv;
149
		public static GLint GetIntegerv(GLenum name) {
pcy's avatar
pcy committed
150
			GLint* parm = stackalloc GLint[4]; // let's hope 4 is good enough
151
			parm[3] = parm[2] = parm[1] = parm[0] = 0;
pcy's avatar
pcy committed
152
			_GetIntegerv(name, parm);
153
154
			return parm[0];
		}
pcy's avatar
initial  
pcy committed
155
156
157
	}
}