-
Notifications
You must be signed in to change notification settings - Fork 3
/
GLES2Man.lua
219 lines (148 loc) · 3.66 KB
/
GLES2Man.lua
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
local ffi = require "ffi"
require "gl2"
--require "gl2ext"
local gl = ffi.load( "GLESv2" )
function GetFunctionProtoName(fname)
local upname = fname:upper();
local protoname = string.format("PFN%sPROC", upname);
return protoname;
end
function CastFunctionPointer(fname, funcptr)
local protoname = GetFunctionProtoName(fname);
local castfunc = ffi.cast(protoname, funcptr);
return castfunc;
end
function GetWglFunction(fname)
local funcptr = gl.wglGetProcAddress(fname);
if funcptr == nil then
return nil
end
local castfunc = CastFunctionPointer(fname, funcptr);
return castfunc;
end
OglMan={
Lib = gl;
}
OglMan_mt = {
__index = function(tbl, key)
local funcptr = GetWglFunction(key)
-- Set the function into the table of
-- known functions, so next time around,
-- it this code will not need to execute
rawset(tbl, key, funcptr)
return funcptr;
end,
--[[
__newindex = function(tbl, idx, value)
if idx == "Execute" then
rawset(tbl, idx, value)
end
end,
--]]
}
setmetatable(OglMan, OglMan_mt)
--[[
Convenience aliases
--]]
--[[
glActiveTexture = gl.glActiveTexture;
glAttachShader = gl.glAttachShader;
glBegin = gl.glBegin;
glBlendFunc = gl.glBlendFunc;
glClear = gl.glClear;
glClearColor = gl.glClearColor;
function glClearDepth (depth)
gl.glClearDepth(depth);
end
function glColor(...)
local arg={...};
if #arg == 3 then
gl.glColor3d(arg[1], arg[2], arg[3]);
elseif #arg == 4 then
gl.glColor4d(arg[1], arg[2], arg[3], arg[4]);
elseif #arg == 2 then
gl.glColor4d(arg[1], arg[1], arg[1], arg[2]);
elseif #arg == 1 then
if type(arg[1] == "number") then
gl.glColor3d(arg[1], arg[1], arg[1]);
elseif type(arg[1]) == "table" then
if #arg[1] == 3 then
gl.glColor3d(arg[1], arg[2], arg[3]);
elseif #arg[1] == 4 then
gl.glColor4d(arg[1], arg[2], arg[3], arg[4]);
end
end
end
end
glColor3f = gl.glColor3f;
glColor4f = gl.glColor4f;
glColorMaterial = gl.glColorMaterial;
glCullFace = gl.glCullFace;
glDeleteLists = gl.glDeleteLists;
glDepthFunc = gl.glDepthFunc;
glDepthRange = gl.glDepthRange;
glDisable = gl.glDisable;
glEnable = gl.glEnable;
glDrawPixels = gl.glDrawPixels;
glEnd = gl.glEnd;
glEndList = gl.glEndList;
glFinish = gl.glFinish;
glFlush = gl.glFlush;
glGenLists = gl.glGenLists;
glGetError = gl.glGetError;
glHint = gl.glHint;
glLineWidth = gl.glLineWidth;
glLoadIdentity = gl.glLoadIdentity;
glMatrixMode = gl.glMatrixMode;
glPopMatrix = gl.glPopMatrix;
glPushMatrix = gl.glPushMatrix;
glOrtho = gl.glOrtho;
glFrustum = gl.glFrustum;
glPixelStorei = gl.glPixelStorei;
glPointSize = gl.glPointSize;
glPolygonMode = gl.glPolygonMode;
function glRasterPos(x, y)
gl.glRasterPos2d(x, y);
end
glRasterPos2i = gl.glRasterPos2i;
function glRotate(angle, x, y, z)
gl.glRotated(angle, x, y, z);
end
glRotatef = gl.glRotatef;
function glScale(x, y, z)
gl.glScaled (x, y, z);
end
glScalef = gl.glScalef;
glShadeModel = gl.glShadeModel;
function glTexCoord(s, t, r, q)
gl.glTexCoord2d(s, t);
end
glTexCoord2f = glTexCoord;
glTexCoord2d = gl.glTexCoord2d;
function glTranslate(x, y, z)
gl.glTranslated(x, y, z);
end
glTranslatef = gl.glTranslatef;
function glVertex(...)
local arg={...};
if #arg == 3 then
gl.glVertex3d(arg[1], arg[2], arg[3]);
elseif #arg == 4 then
gl.glVertex4d(arg[1], arg[2], arg[3], arg[4]);
elseif #arg == 1 then
if type(arg[1]) == "table" then
if #arg[1] == 3 then
gl.glVertex3d(arg[1], arg[2], arg[3]);
elseif #arg[1] == 4 then
gl.glVertex4d(arg[1], arg[2], arg[3], arg[4]);
end
end
end
end
glVertex2f = gl.glVertex2f;
glVertex3f = gl.glVertex3f;
glVertex4f = gl.glVertex4f;
glVertex2d = gl.glVertex2d;
glViewport = gl.glViewport;
--]]
return OglMan;