forked from BSVino/docs.gl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
opengl.py
350 lines (320 loc) · 18.9 KB
/
opengl.py
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
from collections import OrderedDict
import opengl_spec
version_commands = {}
commands_version = {}
version_commands_flat = {}
commands_version_flat = {}
# Maps glColor2d to glColor
function_aliases = {}
# Maps glColor to glColor2d
aliased_functions = {}
example_functions = {}
examples = {
'vertexarray_draw': {
'description': 'Render a vertex array (not loaded into OpenGL) using texture UV, color, and normal vertex attributes.',
'commands': [ 'glDrawArrays' ],
},
'vertexarray_draw_indexed': {
'description': 'Render an indexed vertex array (not loaded into OpenGL) using texture UV and normal vertex attributes.',
'commands': [ 'glVertexAttribPointer', 'glDrawElements' ],
},
'vbo_load': {
'description': 'Load a vertex buffer into OpenGL for later rendering.',
'commands': [ 'glGenBuffers', 'glBindBuffer', 'glBufferData', 'glBufferSubData', 'glGetBufferParameteriv', 'glDeleteBuffers' ],
},
'vbo_load_index': {
'description': 'Load an index buffer into OpenGL for later rendering.',
'commands': [ 'glGenBuffers', 'glBindBuffer', 'glBufferData', 'glBufferSubData', 'glGetBufferParameteriv', 'glDeleteBuffers' ],
},
'vbo_draw_indexed': {
'description': 'Render an indexed buffer object using texture UV and normal vertex attributes.',
'commands': [ 'glBindBuffer', 'glEnableVertexAttribArray', 'glVertexAttribPointer', 'glDrawElements' ],
},
'shader_compile': {
'description': 'Compile a program from a vertex shader and a fragment shader.',
'commands': [ 'glCreateShader', 'glShaderSource', 'glCompileShader', 'glGetShaderiv', 'glGetShaderInfoLog', 'glCreateProgram', 'glBindAttribLocation', 'glAttachShader', 'glLinkProgram', 'glGetProgramiv' ],
},
'shader_setup': {
'description': 'Retrieve uniform data after the shader has been compiled',
'commands': [ 'glGetAttribLocation', 'glBindFragDataLocation', 'glGetProgramiv', 'glGetActiveUniform' ],
},
'fbo_create_texture': {
'versions': [ 'gl3', 'gl4', 'es2', 'es3' ],
'description': 'Create a framebuffer object with a texture-based color attachment and a texture-based depth attachment. Using texture-based attachments allows sampling of those textures in shaders.',
'commands': [ 'glGenTextures', 'glBindTexture', 'glTexParameteri', 'glTexImage2D', 'glGenFramebuffers', 'glBindFramebuffer', 'glFramebufferTexture2D', 'glCheckFramebufferStatus' ],
},
'fbo_create_renderbuffer': {
'versions': [ 'gl3', 'gl4', 'es2', 'es3' ],
'description': 'Create a framebuffer object with a renderbuffer-based color attachment and a renderbuffer-based depth attachment.',
'commands': [ 'glGenRenderbuffers', 'glBindRenderbuffer', 'glRenderbufferStorage', 'glGenFramebuffers', 'glFramebufferRenderbuffer' ],
},
'fbo_blit': {
'versions': [ 'gl3', 'gl4', 'es3' ],
'description': 'Create a framebuffer object with a renderbuffer-based color attachment and a renderbuffer-based depth attachment.',
'commands': [ 'glBindFramebuffer', 'glBlitFramebuffer' ],
},
'texture_create': {
'description': 'Create a texture object with linear mipmaps and edge clamping.',
'commands': [ 'glGenTextures', 'glBindTexture', 'glTexParameteri', 'glTexImage2D', 'glGenerateMipmap' ],
},
'texture_read': {
'description': 'Read the texture from GPU memory into a buffer.',
'commands': [ 'glGetTexImage' ],
},
}
def get_major_versions(all_versions):
major_versions = []
for v in all_versions:
major_version = v[:3]
if not major_version in major_versions:
major_versions.append(major_version)
return major_versions
def get_major_versions_available(command):
global commands_version_flat
versions_available = commands_version_flat[command]
versions_available.sort()
return get_major_versions(versions_available)
def reverse_version_index(command_list):
reversed = {}
for version in command_list:
for command in command_list[version]:
if not command in reversed:
reversed[command] = []
reversed[command].append(version)
reversed[command].sort()
return reversed
def generate_versions():
print "Generating version index..."
global version_commands
global commands_version
global version_commands_flat
global commands_version_flat
global function_aliases
global aliased_functions
version_commands = opengl_spec.version_commands
for version in version_commands:
version_commands_flat[version] = []
for command in version_commands[version]:
if int(version[2]) >= 2:
if not command in function_aliases:
function_aliases[command] = version_commands[version][command]
if not version_commands[version][command] in aliased_functions:
aliased_functions[version_commands[version][command]] = []
if not command in aliased_functions[version_commands[version][command]]:
aliased_functions[version_commands[version][command]].append(command)
if not command in version_commands_flat[version]:
version_commands_flat[version].append(version_commands[version][command])
commands_version = reverse_version_index(version_commands)
commands_version_flat = reverse_version_index(version_commands_flat)
for example in examples:
fp = open('html/examples/' + example + ".htm")
examples[example]['code'] = fp.read()
fp.close()
for command in examples[example]['commands']:
aliased_command = ""
if command in function_aliases:
aliased_command = function_aliases[command]
assert aliased_command in commands_version_flat or command in commands_version_flat # This command was typed in wrong.
if not command in example_functions:
example_functions[command] = []
example_functions_entry = {'example': example}
if 'versions' in examples[example]:
example_functions_entry['versions'] = examples[example]['versions']
else:
example_functions_entry['versions'] = get_major_versions(version_commands.keys())
example_functions[command].append(example_functions_entry)
if not aliased_command in example_functions:
example_functions[aliased_command] = []
example_functions_entry = {'example': example}
if 'versions' in examples[example]:
example_functions_entry['versions'] = examples[example]['versions']
else:
example_functions_entry['versions'] = get_major_versions(version_commands.keys())
example_functions[aliased_command].append(example_functions_entry)
print "Done."
command_categories = OrderedDict([
( "Textures", [
"glBindTexture", "glTexImage1D", "glTexImage2D", "glTexImage2DMultisample", "glTexImage3D",
"glTexImage3DMultisample", "glTexParameter", "glCopyTexImage1D", "glCopyTexImage2D",
"glCopyTexSubImage1D", "glCopyTexSubImage2D", "glCopyTexSubImage3D", "glGetTexParameter",
"glGetTexImage", "glGetTexLevelParameter", "glDeleteTextures", "glGenTextures", "glIsTexture",
"glTexSubImage1D", "glTexSubImage2D", "glTexSubImage3D", "glActiveTexture", "glCompressedTexImage1D",
"glCompressedTexImage2D", "glCompressedTexImage3D", "glCompressedTexSubImage1D",
"glCompressedTexSubImage2D", "glCompressedTexSubImage3D", "glGetCompressedTexImage",
"glBindImageTexture", "glBindImageTextures", "glBindTextureUnit", "glBindTextures", "glCreateTextures",
"glGetCompressedTextureSubImage", "glGetTextureSubImage", "glTextureView", "glClearTexImage",
"glClearTexSubImage", "glCopyImageSubData", "glTexStorage1D", "glTexStorage2D", "glTexStorage3D",
"glTexStorage2DMultisample", "glTexStorage3DMultisample", "glTexBuffer", "glTexBufferRange",
"glInvalidateTexImage", "glInvalidateTexSubImage",
] ),
( "Rendering", [
"glReadPixels", "glReadBuffer", "glDrawBuffer", "glClearDepth", "glClearDepthf", "glClearColor",
"glClear", "glClearStencil", "glFinish", "glFlush", "glClearBuffer",
] ),
( "Frame Buffers", [
"glIsRenderbuffer", "glBindRenderbuffer", "glDeleteRenderbuffers", "glGenRenderbuffers",
"glRenderbufferStorage", "glGetRenderbufferParameter", "glGetRenderbufferParameteriv",
"glIsFramebuffer", "glBindFramebuffer", "glDeleteFramebuffers", "glGenFramebuffers",
"glCheckFramebufferStatus", "glFramebufferTexture", "glFramebufferRenderbuffer",
"glGetFramebufferAttachmentParameter", "glGenerateMipmap", "glRenderbufferStorageMultisample",
"glBlitFramebuffer", "glFramebufferTextureLayer", "glCreateFramebuffers", "glCreateRenderbuffers",
"glDrawBuffers", "glFramebufferParameteri", "glGetFramebufferParameter",
"glGetFramebufferParameteriv", "glInvalidateFramebuffer", "glInvalidateSubFramebuffer",
"glSampleMaski", "glFramebufferTexture2D", "glGetFramebufferAttachmentParameteriv",
] ),
( "Shaders", [
"glUniform", "glGetUniform", "glBindFragDataLocation", "glGetFragDataLocation",
"glAttachShader", "glBindAttribLocation", "glCompileShader", "glCreateProgram", "glCreateShader",
"glDeleteProgram", "glDeleteShader", "glDetachShader", "glGetActiveAttrib", "glGetActiveUniform",
"glGetAttachedShaders", "glGetAttribLocation", "glGetProgram", "glGetProgramiv", "glGetProgramInfoLog",
"glGetShader", "glGetShaderiv", "glGetShaderInfoLog", "glGetShaderSource", "glGetUniformLocation",
"glIsProgram", "glIsShader", "glLinkProgram", "glShaderSource", "glUseProgram",
"glValidateProgram", "glBindFragDataLocationIndexed", "glCreateShaderProgram",
"glGetActiveAtomicCounterBufferiv", "glGetActiveSubroutineName", "glGetActiveSubroutineUniform",
"glGetActiveSubroutineUniformName", "glGetActiveUniformBlock", "glGetActiveUniformBlockiv",
"glGetActiveUniformBlockName", "glGetActiveUniformName", "glGetActiveUniformsiv",
"glGetFragDataIndex", "glGetProgramBinary", "glProgramBinary", "glGetProgramResource",
"glGetProgramResourceIndex", "glGetProgramResourceLocation", "glGetProgramResourceLocationIndex",
"glGetProgramResourceName", "glGetProgramStage", "glGetShaderPrecisionFormat", "glGetSubroutineIndex",
"glGetSubroutineUniformLocation", "glGetUniformBlockIndex", "glGetUniformIndices",
"glGetUniformSubroutine", "glMinSampleShading", "glProgramParameter", "glProgramParameteri",
"glProgramUniform", "glReleaseShaderCompiler", "glShaderBinary", "glShaderStorageBlockBinding",
"glUniformBlockBinding", "glUniformSubroutines", "glUseProgramStages",
] ),
( "Buffer Objects", [
"glBindBuffer", "glDeleteBuffers", "glGenBuffers", "glIsBuffer", "glBufferData", "glBufferSubData",
"glGetBufferSubData", "glMapBuffer", "glUnmapBuffer", "glGetBufferParameter", "glGetBufferParameteriv",
"glGetBufferPointerv", "glFlushMappedBufferRange", "glBindBufferRange", "glBindBufferBase",
"glDrawArrays", "glDrawElements", "glDrawRangeElements", "glCreateBuffers",
"glMultiDrawArrays", "glMultiDrawElements", "glEnableVertexAttribArray", "glDisableVertexAttribArray",
"glGetVertexAttrib", "glGetVertexAttribPointerv", "glVertexAttrib", "glVertexAttribPointer",
"glBindBuffersBase", "glBindBuffersRange", "glBindVertexBuffer", "glBindVertexBuffers",
"glBufferStorage", "glClearBufferData", "glClearBufferSubData", "glCopyBufferSubData",
"glCreateVertexArrays", "glVertexArrayElementBuffer", "glVertexAttribBinding", "glVertexAttribDivisor",
"glVertexAttribFormat", "glVertexBindingDivisor", "glDrawArraysIndirect", "glDrawArraysInstanced",
"glDrawArraysInstancedBaseInstance", "glDrawElementsBaseVertex", "glDrawElementsInstanced",
"glDrawElementsInstancedBaseInstance", "glDrawRangeElementsBaseVertex", "glDrawElementsIndirect",
"glDrawElementsInstancedBaseVertex", "glDrawElementsInstancedBaseVertexBaseInstance",
"glGetVertexArrayIndexed", "glGetVertexArrayiv", "glInvalidateBufferData", "glInvalidateBufferSubData",
"glMapBufferRange", "glMultiDrawArraysIndirect", "glMultiDrawElementsBaseVertex",
"glMultiDrawElementsIndirect", "glPatchParameter", "glPrimitiveRestartIndex", "glProvokingVertex",
] ),
( "State Management", [
# Anything that affects the state machine
"glEnable", "glDisable", "glLogicOp", "glStencilFunc", "glStencilMask", "glColorMask", "glDepthMask",
"glDepthRange", "glDepthRangef", "glHint", "glFrontFace", "glLineWidth", "glCullFace",
"glPolygonMode", "glScissor", "glPointSize", "glBlendFunc", "glStencilOp", "glDepthFunc",
"glPixelStore", "glPixelStorei", "glGet", "glGetError", "glIsEnabled", "glViewport",
"glPolygonOffset", "glSampleCoverage", "glBlendFuncSeparate", "glPointParameter", "glBlendColor",
"glBlendEquation", "glStencilOpSeparate", "glStencilFuncSeparate", "glStencilMaskSeparate",
"glClampColor", "glBlendEquationSeparate", "glClipControl", "glDepthRangeArray",
"glDepthRangeIndexed", "glDisablei", "glScissorArray", "glScissorIndexed", "glViewportArray",
"glViewportIndexed",
] ),
( "Transform Feedback", [
"glBeginTransformFeedback", "glEndTransformFeedback", "glTransformFeedbackVaryings",
"glGetTransformFeedbackVarying", "glGenTransformFeedbacks", "glDeleteTransformFeedbacks",
"glIsTransformFeedback", "glPauseTransformFeedback", "glResumeTransformFeedback",
"glBindTransformFeedback", "glCreateTransformFeedbacks", "glDrawTransformFeedback",
"glDrawTransformFeedbackInstanced", "glDrawTransformFeedbackStream",
"glDrawTransformFeedbackStreamInstanced", "glGetTransformFeedback", "glTransformFeedbackBufferBase",
"glTransformFeedbackBufferRange",
] ),
( "Utility", [
"glGetGraphicsResetStatus", "glGetString", "glGetInternalformat", "glGetInternalformativ",
"glGetMultisample", "glGetMultisamplefv", "glDispatchCompute", "glDispatchComputeIndirect",
"glMemoryBarrier",
] ),
( "Queries", [
"glGetQueryiv", "glGenQueries", "glDeleteQueries", "glBeginQuery", "glEndQuery", "glGetQueryObject",
"glGetQueryObjectuiv", "glIsQuery", "glBeginQueryIndexed", "glEndQueryIndexed", "glGetQueryIndexed",
"glQueryCounter", "glCreateQueries", "glBeginConditionalRender", "glEndConditionalRender",
] ),
( "Syncing", [
"glTextureBarrier", "glClientWaitSync", "glDeleteSync", "glFenceSync", "glGetSync", "glGetSynciv",
"glIsSync", "glWaitSync"
] ),
( "Vertex Array Objects", [
"glBindVertexArray", "glDeleteVertexArrays", "glGenVertexArrays", "glIsVertexArray"
] ),
( "Samplers", [
"glGenSamplers", "glDeleteSamplers", "glSamplerParameter", "glGetSamplerParameter", "glBindSampler",
"glBindSamplers", "glCreateSamplers", "glIsSampler",
] ),
( "Program Pipelines", [
"glActiveShaderProgram", "glBindProgramPipeline", "glCreateProgramPipelines",
"glDeleteProgramPipelines", "glGenProgramPipelines", "glGetProgramPipeline",
"glGetProgramPipelineInfoLog", "glIsProgramPipeline", "glValidateProgramPipeline"
] ),
( "Immediate Mode", [
# Stuff you can call between glBegin and glEnd
"glBegin", "glEnd", "glVertex", "glColor", "glTexCoord", "glFogCoord", "glIndex", "glMaterial",
"glMultiTexCoord", "glNormal", "glSecondaryColor", "glArrayElement", "glEvalCoord", "glEvalMesh",
"glEvalPoint"
] ),
( "GL2 Rasterization", [
# Anything render related that doesn't exist anymore
"glRenderMode", "glFeedbackBuffer", "glPushName", "glLoadName", "glPassThrough", "glSelectBuffer",
"glInitNames", "glLineStipple", "glPolygonStipple", "glDrawPixels", "glCopyPixels", "glRasterPos",
"glWindowPos", "glRect", "glBitmap", "glClipPlane", "glClearIndex", "glFog", "glGetClipPlane",
"glGetMap", "glGetPixelMap", "glGetPolygonStipple","glMap1", "glMap2", "glMapGrid", "glPopName",
"glPixelZoom",
] ),
( "Client Arrays", [
"glVertexPointer", "glEnableClientState", "glDisableClientState", "glFogCoordPointer",
"glIndexPointer", "glInterleavedArrays", "glNormalPointer", "glPopClientAttrib", "glPushClientAttrib",
"glSecondaryColorPointer", "glColorPointer", "glTexCoordPointer",
] ),
( "Fixed Function", [
# Stuff that got moved into shaders
"glEdgeFlag", "glEdgeFlagPointer", "glAlphaFunc", "glLight", "glColorMaterial",
"glLightModel", "glAccum", "glClearAccum", "glGetLight", "glGetMaterial", "glGetTexEnv",
"glTexEnv", "glTexGen", "glGetTexGen", "glIndexMask", "glPushAttrib", "glPopAttrib", "glShadeModel"
] ),
( "Matrix State", [
"glLoadMatrix", "glLoadIdentity", "glMatrixMode", "glMultMatrix", "glMultTransposeMatrix",
"glPushMatrix", "glPopMatrix", "glLoadTransposeMatrix", "glFrustum", "glOrtho", "glRotate",
"glScale", "glTranslate"
] ),
( "GL2 Textures", [
"glAreTexturesResident", "glPrioritizeTextures", "glClientActiveTexture", "glPixelMap",
"glPixelTransfer"
] ),
( "Call Lists", [
"glCallList", "glCallLists", "glIsList", "glDeleteLists", "glGenLists", "glNewList", "glEndList",
"glListBase"
] ),
#( "GLX", [
# "glXChooseFBConfig", "glXChooseVisual", "glXCopyContext", "glXCreateContext", "glXCreateGLXPixmap",
# "glXCreateNewContext", "glXCreatePbuffer", "glXCreatePixmap", "glXCreateWindow", "glXDestroyContext",
# "glXDestroyGLXPixmap", "glXDestroyPbuffer", "glXDestroyPixmap", "glXDestroyWindow",
# "glXFreeContextEXT", "glXGetClientString", "glXGetConfig", "glXGetContextIDEXT",
# "glXGetCurrentContext", "glXGetCurrentDisplay", "glXGetCurrentDrawable", "glXGetCurrentReadDrawable",
# "glXGetFBConfigAttrib", "glXGetFBConfigs", "glXGetProcAddress", "glXGetSelectedEvent",
# "glXGetVisualFromFBConfig", "glXImportContextEXT", "glXIntro", "glXIsDirect", "glXMakeContextCurrent",
# "glXMakeCurrent", "glXQueryContextInfoEXT", "glXQueryContext", "glXQueryDrawable",
# "glXQueryExtensionsString", "glXQueryExtension", "glXQueryServerString", "glXQueryVersion",
# "glXSelectEvent", "glXSwapBuffers", "glXUseXFont", "glXWaitGL", "glXWaitX",
#] ),
#( "GLU", [
# "gluBeginCurve", "gluBeginPolygon", "gluBeginSurface", "gluBeginTrim", "gluBuild1DMipmapLevels",
# "gluBuild1DMipmaps", "gluBuild2DMipmapLevels", "gluBuild2DMipmaps", "gluBuild3DMipmapLevels",
# "gluBuild3DMipmaps", "gluCheckExtension", "gluCylinder", "gluDeleteNurbsRenderer", "gluDeleteQuadric",
# "gluDeleteTess", "gluDisk", "gluEndCurve", "gluEndPolygon", "gluEndSurface", "gluEndTrim",
# "gluErrorString", "gluGetNurbsProperty", "gluGetString", "gluGetTessProperty",
# "gluLoadSamplingMatrices", "gluLookAt", "gluNewNurbsRenderer", "gluNewQuadric", "gluNewTess",
# "gluNextContour", "gluNurbsCallbackDataEXT", "gluNurbsCallbackData", "gluNurbsCallback",
# "gluNurbsCurve", "gluNurbsProperty", "gluNurbsSurface", "gluOrtho2D", "gluPartialDisk",
# "gluPerspective", "gluPickMatrix", "gluProject", "gluPwlCurve", "gluQuadricCallback",
# "gluQuadricDrawStyle", "gluQuadricNormals", "gluQuadricOrientation", "gluQuadricTexture",
# "gluScaleImage", "gluSphere", "gluTessBeginContour", "gluTessBeginPolygon", "gluTessCallback",
# "gluTessEndContour", "gluTessEndPolygon", "gluTessNormal", "gluTessProperty", "gluTessVertex",
# "gluUnProject4", "gluUnProject",
#] ),
( "Debug", [
"glDebugMessageCallback", "glDebugMessageControl", "glDebugMessageInsert",
"glGetDebugMessageLog", "glGetObjectLabel", "glGetObjectPtrLabel", "glGetPointerv",
"glGetProgramInterface", "glObjectLabel", "glObjectPtrLabel", "glPopDebugGroup", "glPushDebugGroup"
] ),
])
generate_versions()