GLUtil_GL.cs 4.28 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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,
			LINK_STATUS     = 0x8B82;

		static void InitProcs() {
			_GetError      = GetProcAddress<Func<GLenum>>("GetError");
			_CreateProgram = GetProcAddress<Func<GLuint>>("CreateProgram");
			_CreateShader  = GetProcAddress<Func<GLenum, GLuint>>("CreateShader");
			_ShaderSource  = GetProcAddress<Action<GLuint, GLsizei, IntPtr, IntPtr>>("ShaderSource");
			_CompileShader = GetProcAddress<Action<GLuint>>("CompileShader");
			_GetShaderiv   = GetProcAddress<Action<GLuint, GLenum, IntPtr>>("GetShaderiv");
			_GetShaderInfoLog = GetProcAddress<Action<GLuint, GLsizei, IntPtr, IntPtr>>("GetShaderInfoLog");
			_AttachShader  = GetProcAddress<Action<GLuint, GLuint>>("AttachShader");
			_LinkProgram   = GetProcAddress<Action<GLuint>>("LinkProgram");
			_GetProgramiv  = GetProcAddress<Action<GLuint, GLenum, IntPtr>>("GetProgramiv");
			_GetProgramInfoLog = GetProcAddress<Action<GLuint, GLsizei, IntPtr, IntPtr>>("GetProgramInfoLog");
			_DeleteShader  = GetProcAddress<Action<GLuint>>("DeleteShader");
			_DeleteProgram = GetProcAddress<Action<GLuint>>("DeleteProgram");
		}
		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;
		}

		static Func<GLenum> _GetError;
		public static GLError GetError() => (GLError)_GetError();

		static Func<GLuint> _CreateProgram;
		public static GLuint CreateProgram() => _CreateProgram();

		static Func<GLenum, GLuint> _CreateShader;
		public static GLuint CreateShader(GLSLPurpose shtyp)
			=> _CreateShader((GLenum)shtyp);

		static Action<GLuint, GLsizei, IntPtr, IntPtr> _ShaderSource;
		public static void ShaderSource(GLuint sh, GLsizei count,
				GLchar** str, GLint* len) {
			_ShaderSource(sh, count, (IntPtr)str, (IntPtr)len);
		}

		static Action<GLuint> _CompileShader;
		public static void CompileShader(GLuint sh) { _CompileShader(sh); }

		static Action<GLuint, GLenum, IntPtr> _GetShaderiv;
		public static GLint GetShaderiv(GLuint sh, GLenum pname) {
			GLint* parm = stackalloc GLint[1];
			*parm = 0;
			_GetShaderiv(sh, pname, (IntPtr)parm);
			return *parm;
		}

		static Action<GLuint, GLsizei, IntPtr, IntPtr> _GetShaderInfoLog;
		public static void GetShaderInfoLog(GLuint sh, GLsizei maxl,
				GLsizei* len, GLchar* infolog) {
			_GetShaderInfoLog(sh, maxl, (IntPtr)len, (IntPtr)infolog);
		}

		static Action<GLuint, GLuint> _AttachShader;
		public static void AttachShader(GLuint prgm, GLuint sh) {
			_AttachShader(prgm, sh);
		}

		static Action<GLuint> _LinkProgram;
		public static void LinkProgram(GLuint prgm) { _LinkProgram(prgm); }

		static Action<GLuint, GLenum, IntPtr> _GetProgramiv;
		// 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;
			_GetProgramiv(prgm, pname, (IntPtr)parm);
			return parm[0];
		}

		static Action<GLuint, GLsizei, IntPtr, IntPtr> _GetProgramInfoLog;
		public static void GetProgramInfoLog(GLuint prgm, GLsizei maxl,
				GLsizei* len, GLchar* infolog) {
			_GetProgramInfoLog(prgm, maxl, (IntPtr)len, (IntPtr)infolog);
		}

		static Action<GLuint> _DeleteShader;
		public static void DeleteShader(GLuint sh) { _DeleteShader(sh); }

		static Action<GLuint> _DeleteProgram;
		public static void DeleteProgram(GLuint prgm) { _DeleteProgram(prgm); }
	}
}