[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | """code generator for GL/GLES extension wrangler.""" |
| 8 | |
| 9 | import os |
| 10 | import re |
| 11 | import sys |
| 12 | |
| 13 | GL_FUNCTIONS = [ |
| 14 | ['void', ['glActiveTexture'], 'GLenum texture'], |
| 15 | ['void', ['glAttachShader'], 'GLuint program, GLuint shader'], |
| 16 | ['void', ['glBindAttribLocation'], |
| 17 | 'GLuint program, GLuint index, const char* name'], |
| 18 | ['void', ['glBindBuffer'], 'GLenum target, GLuint buffer'], |
| 19 | ['void', ['glBindFramebufferEXT', 'glBindFramebuffer'], |
| 20 | 'GLenum target, GLuint framebuffer'], |
| 21 | ['void', ['glBindRenderbufferEXT', 'glBindRenderbuffer'], |
| 22 | 'GLenum target, GLuint renderbuffer'], |
| 23 | ['void', ['glBindTexture'], 'GLenum target, GLuint texture'], |
| 24 | ['void', ['glBlendColor'], |
| 25 | 'GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha'], |
| 26 | ['void', ['glBlendEquation'], ' GLenum mode '], |
| 27 | ['void', ['glBlendEquationSeparate'], 'GLenum modeRGB, GLenum modeAlpha'], |
| 28 | ['void', ['glBlendFunc'], 'GLenum sfactor, GLenum dfactor'], |
| 29 | ['void', ['glBlendFuncSeparate'], |
| 30 | 'GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha'], |
[email protected] | ce2d412 | 2010-08-09 20:45:07 | [diff] [blame] | 31 | ['void', ['glBlitFramebufferEXT', 'BlitFramebuffer'], |
| 32 | 'GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, ' |
| 33 | 'GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, ' |
| 34 | 'GLbitfield mask, GLenum filter'], |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame^] | 35 | ['void', ['glBlitFramebufferANGLE', 'BlitFramebuffer'], |
| 36 | 'GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, ' |
| 37 | 'GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, ' |
| 38 | 'GLbitfield mask, GLenum filter'], |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 39 | ['void', ['glBufferData'], |
| 40 | 'GLenum target, GLsizei size, const void* data, GLenum usage'], |
| 41 | ['void', ['glBufferSubData'], |
| 42 | 'GLenum target, GLint offset, GLsizei size, const void* data'], |
| 43 | ['GLenum', ['glCheckFramebufferStatusEXT', |
| 44 | 'glCheckFramebufferStatus'], 'GLenum target'], |
| 45 | ['void', ['glClear'], 'GLbitfield mask'], |
| 46 | ['void', ['glClearColor'], |
| 47 | 'GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha'], |
| 48 | ['void', ['glClearDepth'], 'GLclampd depth'], |
| 49 | ['void', ['glClearDepthf'], 'GLclampf depth'], |
| 50 | ['void', ['glClearStencil'], 'GLint s'], |
| 51 | ['void', ['glColorMask'], |
| 52 | 'GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha'], |
| 53 | ['void', ['glCompileShader'], 'GLuint shader'], |
| 54 | ['void', ['glCompressedTexImage2D'], |
| 55 | 'GLenum target, GLint level, GLenum internalformat, GLsizei width, ' |
| 56 | 'GLsizei height, GLint border, GLsizei imageSize, const void* data'], |
| 57 | ['void', ['glCompressedTexSubImage2D'], |
| 58 | 'GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, ' |
| 59 | 'GLsizei height, GLenum format, GLsizei imageSize, const void* data'], |
| 60 | ['void', ['glCopyTexImage2D'], |
| 61 | 'GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, ' |
| 62 | 'GLsizei width, GLsizei height, GLint border'], |
| 63 | ['void', ['glCopyTexSubImage2D'], 'GLenum target, GLint level, GLint xoffset, ' |
| 64 | 'GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height'], |
| 65 | ['GLuint', ['glCreateProgram'], 'void'], |
| 66 | ['GLuint', ['glCreateShader'], 'GLenum type'], |
| 67 | ['void', ['glCullFace'], 'GLenum mode'], |
| 68 | ['void', ['glDeleteBuffersARB', 'glDeleteBuffers'], |
| 69 | 'GLsizei n, const GLuint* buffers'], |
| 70 | ['void', ['glDeleteFramebuffersEXT', 'glDeleteFramebuffers'], |
| 71 | 'GLsizei n, const GLuint* framebuffers'], |
| 72 | ['void', ['glDeleteProgram'], 'GLuint program'], |
| 73 | ['void', ['glDeleteRenderbuffersEXT', 'glDeleteRenderbuffers'], |
| 74 | 'GLsizei n, const GLuint* renderbuffers'], |
| 75 | ['void', ['glDeleteShader'], 'GLuint shader'], |
| 76 | ['void', ['glDeleteTextures'], 'GLsizei n, const GLuint* textures'], |
| 77 | ['void', ['glDepthFunc'], 'GLenum func'], |
| 78 | ['void', ['glDepthMask'], 'GLboolean flag'], |
| 79 | ['void', ['glDepthRange'], 'GLclampd zNear, GLclampd zFar'], |
| 80 | ['void', ['glDepthRangef'], 'GLclampf zNear, GLclampf zFar'], |
| 81 | ['void', ['glDetachShader'], 'GLuint program, GLuint shader'], |
| 82 | ['void', ['glDisable'], 'GLenum cap'], |
| 83 | ['void', ['glDisableVertexAttribArray'], 'GLuint index'], |
| 84 | ['void', ['glDrawArrays'], 'GLenum mode, GLint first, GLsizei count'], |
| 85 | ['void', ['glDrawElements'], |
| 86 | 'GLenum mode, GLsizei count, GLenum type, const void* indices'], |
| 87 | ['void', ['glEnable'], 'GLenum cap'], |
| 88 | ['void', ['glEnableVertexAttribArray'], 'GLuint index'], |
| 89 | ['void', ['glFinish'], 'void'], |
| 90 | ['void', ['glFlush'], 'void'], |
| 91 | ['void', ['glFramebufferRenderbufferEXT', 'glFramebufferRenderbuffer'], |
| 92 | 'GLenum target, GLenum attachment, GLenum renderbuffertarget, ' |
| 93 | 'GLuint renderbuffer'], |
| 94 | ['void', ['glFramebufferTexture2DEXT', 'glFramebufferTexture2D'], |
| 95 | 'GLenum target, GLenum attachment, GLenum textarget, GLuint texture, ' |
| 96 | 'GLint level'], |
| 97 | ['void', ['glFrontFace'], 'GLenum mode'], |
| 98 | ['void', ['glGenBuffersARB', 'glGenBuffers'], 'GLsizei n, GLuint* buffers'], |
| 99 | ['void', ['glGenerateMipmapEXT', 'glGenerateMipmap'], 'GLenum target'], |
| 100 | ['void', ['glGenFramebuffersEXT', 'glGenFramebuffers'], |
| 101 | 'GLsizei n, GLuint* framebuffers'], |
| 102 | ['void', ['glGenRenderbuffersEXT', 'glGenRenderbuffers'], |
| 103 | 'GLsizei n, GLuint* renderbuffers'], |
| 104 | ['void', ['glGenTextures'], 'GLsizei n, GLuint* textures'], |
| 105 | ['void', ['glGetActiveAttrib'], |
| 106 | 'GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, ' |
| 107 | 'GLint* size, GLenum* type, char* name'], |
| 108 | ['void', ['glGetActiveUniform'], |
| 109 | 'GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, ' |
| 110 | 'GLint* size, GLenum* type, char* name'], |
| 111 | ['void', ['glGetAttachedShaders'], |
| 112 | 'GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders'], |
| 113 | ['GLint', ['glGetAttribLocation'], 'GLuint program, const char* name'], |
| 114 | ['void', ['glGetBooleanv'], 'GLenum pname, GLboolean* params'], |
[email protected] | ce2d412 | 2010-08-09 20:45:07 | [diff] [blame] | 115 | ['void', ['glGetBufferParameteriv'], |
| 116 | 'GLenum target, GLenum pname, GLint* params'], |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 117 | ['GLenum', ['glGetError'], 'void'], |
| 118 | ['void', ['glGetFloatv'], 'GLenum pname, GLfloat* params'], |
| 119 | ['void', ['glGetFramebufferAttachmentParameterivEXT', |
| 120 | 'glGetFramebufferAttachmentParameteriv'], 'GLenum target, ' |
| 121 | 'GLenum attachment, GLenum pname, GLint* params'], |
| 122 | ['void', ['glGetIntegerv'], 'GLenum pname, GLint* params'], |
| 123 | ['void', ['glGetProgramiv'], 'GLuint program, GLenum pname, GLint* params'], |
| 124 | ['void', ['glGetProgramInfoLog'], |
| 125 | 'GLuint program, GLsizei bufsize, GLsizei* length, char* infolog'], |
| 126 | ['void', ['glGetRenderbufferParameterivEXT', 'glGetRenderbufferParameteriv'], |
| 127 | 'GLenum target, GLenum pname, GLint* params'], |
| 128 | ['void', ['glGetShaderiv'], 'GLuint shader, GLenum pname, GLint* params'], |
| 129 | ['void', ['glGetShaderInfoLog'], |
| 130 | 'GLuint shader, GLsizei bufsize, GLsizei* length, char* infolog'], |
| 131 | ['void', ['glGetShaderPrecisionFormat'], |
| 132 | 'GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision'], |
| 133 | ['void', ['glGetShaderSource'], |
| 134 | 'GLuint shader, GLsizei bufsize, GLsizei* length, char* source'], |
| 135 | ['const GLubyte*', ['glGetString'], 'GLenum name'], |
| 136 | ['void', ['glGetTexParameterfv'], |
| 137 | 'GLenum target, GLenum pname, GLfloat* params'], |
| 138 | ['void', ['glGetTexParameteriv'], 'GLenum target, GLenum pname, GLint* params'], |
| 139 | ['void', ['glGetUniformfv'], 'GLuint program, GLint location, GLfloat* params'], |
| 140 | ['void', ['glGetUniformiv'], 'GLuint program, GLint location, GLint* params'], |
| 141 | ['GLint', ['glGetUniformLocation'], 'GLuint program, const char* name'], |
| 142 | ['void', ['glGetVertexAttribfv'], |
| 143 | 'GLuint index, GLenum pname, GLfloat* params'], |
| 144 | ['void', ['glGetVertexAttribiv'], 'GLuint index, GLenum pname, GLint* params'], |
| 145 | ['void', ['glGetVertexAttribPointerv'], |
| 146 | 'GLuint index, GLenum pname, void** pointer'], |
| 147 | ['void', ['glHint'], 'GLenum target, GLenum mode'], |
| 148 | ['GLboolean', ['glIsBuffer'], 'GLuint buffer'], |
| 149 | ['GLboolean', ['glIsEnabled'], 'GLenum cap'], |
[email protected] | 0f000f3 | 2010-08-10 17:59:09 | [diff] [blame] | 150 | ['GLboolean', ['glIsFramebufferEXT', 'glIsFramebuffer'], |
| 151 | 'GLuint framebuffer'], |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 152 | ['GLboolean', ['glIsProgram'], 'GLuint program'], |
[email protected] | 0f000f3 | 2010-08-10 17:59:09 | [diff] [blame] | 153 | ['GLboolean', ['glIsRenderbufferEXT', 'glIsRenderbuffer'], |
| 154 | 'GLuint renderbuffer'], |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 155 | ['GLboolean', ['glIsShader'], 'GLuint shader'], |
| 156 | ['GLboolean', ['glIsTexture'], 'GLuint texture'], |
| 157 | ['void', ['glLineWidth'], 'GLfloat width'], |
| 158 | ['void', ['glLinkProgram'], 'GLuint program'], |
| 159 | ['void', ['glPixelStorei'], 'GLenum pname, GLint param'], |
| 160 | ['void', ['glPolygonOffset'], 'GLfloat factor, GLfloat units'], |
| 161 | ['void', ['glReadPixels'], |
| 162 | 'GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, ' |
| 163 | 'GLenum type, void* pixels'], |
| 164 | ['void', ['glReleaseShaderCompiler'], 'void'], |
[email protected] | ce2d412 | 2010-08-09 20:45:07 | [diff] [blame] | 165 | ['void', ['glRenderbufferStorageMultisampleEXT', |
| 166 | 'glRenderbufferStorageMultisample'], |
| 167 | 'GLenum target, GLsizei samples, GLenum internalformat, ' |
| 168 | 'GLsizei width, GLsizei height'], |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame^] | 169 | ['void', ['glRenderbufferStorageMultisampleANGLE', |
| 170 | 'glRenderbufferStorageMultisample'], |
| 171 | 'GLenum target, GLsizei samples, GLenum internalformat, ' |
| 172 | 'GLsizei width, GLsizei height'], |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 173 | ['void', ['glRenderbufferStorageEXT', 'glRenderbufferStorage'], |
| 174 | 'GLenum target, GLenum internalformat, GLsizei width, GLsizei height'], |
| 175 | ['void', ['glSampleCoverage'], 'GLclampf value, GLboolean invert'], |
| 176 | ['void', ['glScissor'], 'GLint x, GLint y, GLsizei width, GLsizei height'], |
| 177 | ['void', ['glShaderBinary'], |
| 178 | 'GLsizei n, const GLuint* shaders, GLenum binaryformat, ' |
| 179 | 'const void* binary, GLsizei length'], |
| 180 | ['void', ['glShaderSource'], |
| 181 | 'GLuint shader, GLsizei count, const char** str, const GLint* length'], |
| 182 | ['void', ['glStencilFunc'], 'GLenum func, GLint ref, GLuint mask'], |
| 183 | ['void', ['glStencilFuncSeparate'], |
| 184 | 'GLenum face, GLenum func, GLint ref, GLuint mask'], |
| 185 | ['void', ['glStencilMask'], 'GLuint mask'], |
| 186 | ['void', ['glStencilMaskSeparate'], 'GLenum face, GLuint mask'], |
| 187 | ['void', ['glStencilOp'], 'GLenum fail, GLenum zfail, GLenum zpass'], |
| 188 | ['void', ['glStencilOpSeparate'], |
| 189 | 'GLenum face, GLenum fail, GLenum zfail, GLenum zpass'], |
| 190 | ['void', ['glTexImage2D'], |
| 191 | 'GLenum target, GLint level, GLint internalformat, GLsizei width, ' |
| 192 | 'GLsizei height, GLint border, GLenum format, GLenum type, ' |
| 193 | 'const void* pixels'], |
| 194 | ['void', ['glTexParameterf'], 'GLenum target, GLenum pname, GLfloat param'], |
| 195 | ['void', ['glTexParameterfv'], |
| 196 | 'GLenum target, GLenum pname, const GLfloat* params'], |
| 197 | ['void', ['glTexParameteri'], 'GLenum target, GLenum pname, GLint param'], |
| 198 | ['void', ['glTexParameteriv'], |
| 199 | 'GLenum target, GLenum pname, const GLint* params'], |
| 200 | ['void', ['glTexSubImage2D'], |
| 201 | 'GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, ' |
| 202 | 'GLsizei height, GLenum format, GLenum type, const void* pixels'], |
| 203 | ['void', ['glUniform1f'], 'GLint location, GLfloat x'], |
| 204 | ['void', ['glUniform1fv'], 'GLint location, GLsizei count, const GLfloat* v'], |
| 205 | ['void', ['glUniform1i'], 'GLint location, GLint x'], |
| 206 | ['void', ['glUniform1iv'], 'GLint location, GLsizei count, const GLint* v'], |
| 207 | ['void', ['glUniform2f'], 'GLint location, GLfloat x, GLfloat y'], |
| 208 | ['void', ['glUniform2fv'], 'GLint location, GLsizei count, const GLfloat* v'], |
| 209 | ['void', ['glUniform2i'], 'GLint location, GLint x, GLint y'], |
| 210 | ['void', ['glUniform2iv'], 'GLint location, GLsizei count, const GLint* v'], |
| 211 | ['void', ['glUniform3f'], 'GLint location, GLfloat x, GLfloat y, GLfloat z'], |
| 212 | ['void', ['glUniform3fv'], 'GLint location, GLsizei count, const GLfloat* v'], |
| 213 | ['void', ['glUniform3i'], 'GLint location, GLint x, GLint y, GLint z'], |
| 214 | ['void', ['glUniform3iv'], 'GLint location, GLsizei count, const GLint* v'], |
| 215 | ['void', ['glUniform4f'], |
| 216 | 'GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w'], |
| 217 | ['void', ['glUniform4fv'], 'GLint location, GLsizei count, const GLfloat* v'], |
| 218 | ['void', ['glUniform4i'], 'GLint location, GLint x, GLint y, GLint z, GLint w'], |
| 219 | ['void', ['glUniform4iv'], 'GLint location, GLsizei count, const GLint* v'], |
| 220 | ['void', ['glUniformMatrix2fv'], |
| 221 | 'GLint location, GLsizei count, GLboolean transpose, const GLfloat* value'], |
| 222 | ['void', ['glUniformMatrix3fv'], |
| 223 | 'GLint location, GLsizei count, GLboolean transpose, const GLfloat* value'], |
| 224 | ['void', ['glUniformMatrix4fv'], |
| 225 | 'GLint location, GLsizei count, GLboolean transpose, const GLfloat* value'], |
| 226 | ['void', ['glUseProgram'], 'GLuint program'], |
| 227 | ['void', ['glValidateProgram'], 'GLuint program'], |
| 228 | ['void', ['glVertexAttrib1f'], 'GLuint indx, GLfloat x'], |
| 229 | ['void', ['glVertexAttrib1fv'], 'GLuint indx, const GLfloat* values'], |
| 230 | ['void', ['glVertexAttrib2f'], 'GLuint indx, GLfloat x, GLfloat y'], |
| 231 | ['void', ['glVertexAttrib2fv'], 'GLuint indx, const GLfloat* values'], |
| 232 | ['void', ['glVertexAttrib3f'], 'GLuint indx, GLfloat x, GLfloat y, GLfloat z'], |
| 233 | ['void', ['glVertexAttrib3fv'], 'GLuint indx, const GLfloat* values'], |
| 234 | ['void', ['glVertexAttrib4f'], |
| 235 | 'GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w'], |
| 236 | ['void', ['glVertexAttrib4fv'], 'GLuint indx, const GLfloat* values'], |
| 237 | ['void', ['glVertexAttribPointer'], |
| 238 | 'GLuint indx, GLint size, GLenum type, GLboolean normalized, ' |
| 239 | 'GLsizei stride, const void* ptr'], |
| 240 | ['void', ['glViewport'], 'GLint x, GLint y, GLsizei width, GLsizei height'], |
| 241 | ] |
| 242 | |
| 243 | OSMESA_FUNCTIONS = [ |
| 244 | ['OSMesaContext', ['OSMesaCreateContext'], |
| 245 | 'GLenum format, OSMesaContext sharelist'], |
| 246 | ['OSMesaContext', ['OSMesaCreateContextExt'], |
| 247 | 'GLenum format, GLint depthBits, GLint stencilBits, GLint accumBits, ' |
| 248 | 'OSMesaContext sharelist'], |
| 249 | ['void', ['OSMesaDestroyContext'], 'OSMesaContext ctx'], |
| 250 | ['GLboolean', ['OSMesaMakeCurrent'], |
| 251 | 'OSMesaContext ctx, void* buffer, GLenum type, GLsizei width, ' |
| 252 | 'GLsizei height'], |
| 253 | ['OSMesaContext', ['OSMesaGetCurrentContext'], 'void'], |
| 254 | ['void', ['OSMesaPixelStore'], 'GLint pname, GLint value'], |
| 255 | ['void', ['OSMesaGetIntegerv'], 'GLint pname, GLint* value'], |
| 256 | ['GLboolean', ['OSMesaGetDepthBuffer'], |
| 257 | 'OSMesaContext c, GLint* width, GLint* height, GLint* bytesPerValue, ' |
| 258 | 'void** buffer'], |
| 259 | ['GLboolean', ['OSMesaGetColorBuffer'], |
| 260 | 'OSMesaContext c, GLint* width, GLint* height, GLint* format, ' |
| 261 | 'void** buffer'], |
| 262 | ['OSMESAproc', ['OSMesaGetProcAddress'], 'const char* funcName'], |
| 263 | ['void', ['OSMesaColorClamp'], 'GLboolean enable'], |
| 264 | ] |
| 265 | |
| 266 | EGL_FUNCTIONS = [ |
| 267 | ['EGLint', ['eglGetError'], 'void'], |
[email protected] | 0bec8e2 | 2010-06-21 22:20:02 | [diff] [blame] | 268 | ['EGLDisplay', ['eglGetDisplay'], 'EGLNativeDisplayType display_id'], |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 269 | ['EGLBoolean', ['eglInitialize'], |
| 270 | 'EGLDisplay dpy, EGLint* major, EGLint* minor'], |
| 271 | ['EGLBoolean', ['eglTerminate'], 'EGLDisplay dpy'], |
| 272 | ['const char*', ['eglQueryString'], 'EGLDisplay dpy, EGLint name'], |
| 273 | ['EGLBoolean', ['eglGetConfigs'], |
| 274 | 'EGLDisplay dpy, EGLConfig* configs, EGLint config_size, ' |
| 275 | 'EGLint* num_config'], |
| 276 | ['EGLBoolean', ['eglChooseConfig'], |
| 277 | 'EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs, ' |
| 278 | 'EGLint config_size, EGLint* num_config'], |
| 279 | ['EGLBoolean', ['eglGetConfigAttrib'], |
| 280 | 'EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint* value'], |
| 281 | ['EGLSurface', ['eglCreateWindowSurface'], |
[email protected] | ce2d412 | 2010-08-09 20:45:07 | [diff] [blame] | 282 | 'EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, ' |
| 283 | 'const EGLint* attrib_list'], |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 284 | ['EGLSurface', ['eglCreatePbufferSurface'], |
| 285 | 'EGLDisplay dpy, EGLConfig config, const EGLint* attrib_list'], |
| 286 | ['EGLSurface', ['eglCreatePixmapSurface'], |
[email protected] | 0bec8e2 | 2010-06-21 22:20:02 | [diff] [blame] | 287 | 'EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, ' |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 288 | 'const EGLint* attrib_list'], |
| 289 | ['EGLBoolean', ['eglDestroySurface'], 'EGLDisplay dpy, EGLSurface surface'], |
| 290 | ['EGLBoolean', ['eglQuerySurface'], |
| 291 | 'EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint* value'], |
| 292 | ['EGLBoolean', ['eglBindAPI'], 'EGLenum api'], |
| 293 | ['EGLenum', ['eglQueryAPI'], 'void'], |
| 294 | ['EGLBoolean', ['eglWaitClient'], 'void'], |
| 295 | ['EGLBoolean', ['eglReleaseThread'], 'void'], |
| 296 | ['EGLSurface', ['eglCreatePbufferFromClientBuffer'], |
| 297 | 'EGLDisplay dpy, EGLenum buftype, void* buffer, EGLConfig config, ' |
| 298 | 'const EGLint* attrib_list'], |
| 299 | ['EGLBoolean', ['eglSurfaceAttrib'], |
| 300 | 'EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value'], |
| 301 | ['EGLBoolean', ['eglBindTexImage'], |
| 302 | 'EGLDisplay dpy, EGLSurface surface, EGLint buffer'], |
| 303 | ['EGLBoolean', ['eglReleaseTexImage'], |
| 304 | 'EGLDisplay dpy, EGLSurface surface, EGLint buffer'], |
| 305 | ['EGLBoolean', ['eglSwapInterval'], 'EGLDisplay dpy, EGLint interval'], |
| 306 | ['EGLContext', ['eglCreateContext'], |
| 307 | 'EGLDisplay dpy, EGLConfig config, EGLContext share_context, ' |
| 308 | 'const EGLint* attrib_list'], |
| 309 | ['EGLBoolean', ['eglDestroyContext'], 'EGLDisplay dpy, EGLContext ctx'], |
| 310 | ['EGLBoolean', ['eglMakeCurrent'], |
| 311 | 'EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx'], |
| 312 | ['EGLContext', ['eglGetCurrentContext'], 'void'], |
| 313 | ['EGLSurface', ['eglGetCurrentSurface'], 'EGLint readdraw'], |
| 314 | ['EGLDisplay', ['eglGetCurrentDisplay'], 'void'], |
| 315 | ['EGLBoolean', ['eglQueryContext'], |
| 316 | 'EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* value'], |
| 317 | ['EGLBoolean', ['eglWaitGL'], 'void'], |
| 318 | ['EGLBoolean', ['eglWaitNative'], 'EGLint engine'], |
| 319 | ['EGLBoolean', ['eglSwapBuffers'], 'EGLDisplay dpy, EGLSurface surface'], |
| 320 | ['EGLBoolean', ['eglCopyBuffers'], |
[email protected] | 0bec8e2 | 2010-06-21 22:20:02 | [diff] [blame] | 321 | 'EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target'], |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 322 | ['__eglMustCastToProperFunctionPointerType', ['eglGetProcAddress'], |
| 323 | 'const char* procname'], |
| 324 | ] |
| 325 | |
| 326 | WGL_FUNCTIONS = [ |
| 327 | ['HGLRC', ['wglCreateContext'], 'HDC hdc'], |
| 328 | ['HGLRC', ['wglCreateLayerContext'], 'HDC hdc, int iLayerPlane'], |
| 329 | ['BOOL', ['wglCopyContext'], 'HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask'], |
| 330 | ['BOOL', ['wglDeleteContext'], 'HGLRC hglrc'], |
| 331 | ['HGLRC', ['wglGetCurrentContext'], ''], |
| 332 | ['HDC', ['wglGetCurrentDC'], ''], |
| 333 | ['BOOL', ['wglMakeCurrent'], 'HDC hdc, HGLRC hglrc'], |
| 334 | ['BOOL', ['wglShareLists'], 'HGLRC hglrc1, HGLRC hglrc2'], |
| 335 | ['BOOL', ['wglSwapLayerBuffers'], 'HDC hdc, UINT fuPlanes'], |
| 336 | ['const char*', ['wglGetExtensionsStringARB', 'wglGetExtensionsStringEXT'], |
| 337 | 'HDC hDC'], |
| 338 | ['BOOL', ['wglChoosePixelFormatARB'], |
| 339 | 'HDC dc, const int* int_attrib_list, const float* float_attrib_list, ' |
| 340 | 'UINT max_formats, int* formats, UINT* num_formats'], |
| 341 | ['HPBUFFERARB', ['wglCreatePbufferARB'], |
| 342 | 'HDC hDC, int iPixelFormat, int iWidth, int iHeight, ' |
| 343 | 'const int* piAttribList'], |
| 344 | ['HDC', ['wglGetPbufferDCARB'], 'HPBUFFERARB hPbuffer'], |
| 345 | ['int', ['wglReleasePbufferDCARB'], 'HPBUFFERARB hPbuffer, HDC hDC'], |
| 346 | ['BOOL', ['wglDestroyPbufferARB'], 'HPBUFFERARB hPbuffer'], |
| 347 | ['BOOL', ['wglQueryPbufferARB'], |
| 348 | 'HPBUFFERARB hPbuffer, int iAttribute, int* piValue'], |
| 349 | ] |
| 350 | |
| 351 | GLX_FUNCTIONS = [ |
| 352 | ['XVisualInfo*', ['glXChooseVisual'], |
| 353 | 'Display* dpy, int screen, int* attribList'], |
| 354 | ['GLXContext', ['glXCreateContext'], |
| 355 | 'Display* dpy, XVisualInfo* vis, GLXContext shareList, int direct'], |
| 356 | ['void', ['glXDestroyContext'], 'Display* dpy, GLXContext ctx'], |
| 357 | ['int', ['glXMakeCurrent'], |
| 358 | 'Display* dpy, GLXDrawable drawable, GLXContext ctx'], |
| 359 | ['void', ['glXCopyContext'], |
| 360 | 'Display* dpy, GLXContext src, GLXContext dst, unsigned long mask'], |
| 361 | ['void', ['glXSwapBuffers'], 'Display* dpy, GLXDrawable drawable'], |
| 362 | ['GLXPixmap', ['glXCreateGLXPixmap'], |
| 363 | 'Display* dpy, XVisualInfo* visual, Pixmap pixmap'], |
| 364 | ['void', ['glXDestroyGLXPixmap'], 'Display* dpy, GLXPixmap pixmap'], |
| 365 | ['int', ['glXQueryExtension'], 'Display* dpy, int* errorb, int* event'], |
| 366 | ['int', ['glXQueryVersion'], 'Display* dpy, int* maj, int* min'], |
| 367 | ['int', ['glXIsDirect'], 'Display* dpy, GLXContext ctx'], |
| 368 | ['int', ['glXGetConfig'], |
| 369 | 'Display* dpy, XVisualInfo* visual, int attrib, int* value'], |
| 370 | ['GLXContext', ['glXGetCurrentContext'], 'void'], |
| 371 | ['GLXDrawable', ['glXGetCurrentDrawable'], 'void'], |
| 372 | ['void', ['glXWaitGL'], 'void'], |
| 373 | ['void', ['glXWaitX'], 'void'], |
| 374 | ['void', ['glXUseXFont'], 'Font font, int first, int count, int list'], |
| 375 | ['const char*', ['glXQueryExtensionsString'], 'Display* dpy, int screen'], |
| 376 | ['const char*', ['glXQueryServerString'], 'Display* dpy, int screen, int name'], |
| 377 | ['const char*', ['glXGetClientString'], 'Display* dpy, int name'], |
| 378 | ['Display*', ['glXGetCurrentDisplay'], 'void'], |
| 379 | ['GLXFBConfig*', ['glXChooseFBConfig'], |
| 380 | 'Display* dpy, int screen, const int* attribList, int* nitems'], |
| 381 | ['int', ['glXGetFBConfigAttrib'], |
| 382 | 'Display* dpy, GLXFBConfig config, int attribute, int* value'], |
| 383 | ['GLXFBConfig*', ['glXGetFBConfigs'], |
| 384 | 'Display* dpy, int screen, int* nelements'], |
| 385 | ['XVisualInfo*', ['glXGetVisualFromFBConfig'], |
| 386 | 'Display* dpy, GLXFBConfig config'], |
| 387 | ['GLXWindow', ['glXCreateWindow'], |
| 388 | 'Display* dpy, GLXFBConfig config, Window win, const int* attribList'], |
| 389 | ['void', ['glXDestroyWindow'], 'Display* dpy, GLXWindow window'], |
| 390 | ['GLXPixmap', ['glXCreatePixmap'], |
| 391 | 'Display* dpy, GLXFBConfig config, Pixmap pixmap, const int* attribList'], |
| 392 | ['void', ['glXDestroyPixmap'], 'Display* dpy, GLXPixmap pixmap'], |
| 393 | ['GLXPbuffer', ['glXCreatePbuffer'], |
| 394 | 'Display* dpy, GLXFBConfig config, const int* attribList'], |
| 395 | ['void', ['glXDestroyPbuffer'], 'Display* dpy, GLXPbuffer pbuf'], |
| 396 | ['void', ['glXQueryDrawable'], |
| 397 | 'Display* dpy, GLXDrawable draw, int attribute, unsigned int* value'], |
| 398 | ['GLXContext', ['glXCreateNewContext'], |
| 399 | 'Display* dpy, GLXFBConfig config, int renderType, ' |
| 400 | 'GLXContext shareList, int direct'], |
| 401 | ['int', ['glXMakeContextCurrent'], |
| 402 | 'Display* dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx'], |
| 403 | ['GLXDrawable', ['glXGetCurrentReadDrawable'], 'void'], |
| 404 | ['int', ['glXQueryContext'], |
| 405 | 'Display* dpy, GLXContext ctx, int attribute, int* value'], |
| 406 | ['void', ['glXSelectEvent'], |
| 407 | 'Display* dpy, GLXDrawable drawable, unsigned long mask'], |
| 408 | ['void', ['glXGetSelectedEvent'], |
| 409 | 'Display* dpy, GLXDrawable drawable, unsigned long* mask'], |
| 410 | ] |
| 411 | |
| 412 | FUNCTION_SETS = [ |
| 413 | [GL_FUNCTIONS, 'gl'], |
| 414 | [OSMESA_FUNCTIONS, 'osmesa'], |
| 415 | [EGL_FUNCTIONS, 'egl'], |
| 416 | [WGL_FUNCTIONS, 'wgl'], |
| 417 | [GLX_FUNCTIONS, 'glx'], |
| 418 | ] |
| 419 | |
| 420 | def GenerateHeader(file, functions, setName): |
| 421 | """Generates gl_binding_autogen_x.h""" |
| 422 | |
| 423 | # Write file header. |
| 424 | file.write('// Copyright (c) 2010 The Chromium Authors. All rights reserved.\n') |
| 425 | file.write('// Use of this source code is governed by a BSD-style license that can be\n') |
| 426 | file.write('// found in the LICENSE file.\n') |
| 427 | file.write('\n') |
| 428 | file.write('// This file is automatically generated.\n') |
| 429 | file.write('\n') |
| 430 | file.write('#ifndef APP_GFX_GL_GL_BINDINGS_AUTOGEN_%s_H_\n' % setName.upper()) |
| 431 | file.write('#define APP_GFX_GL_GL_BINDINGS_AUTOGEN_%s_H_\n' % setName.upper()) |
| 432 | |
| 433 | # Write prototype for initialization function. |
| 434 | file.write('\n') |
| 435 | file.write('namespace gfx {\n') |
| 436 | file.write('\n') |
| 437 | file.write('void InitializeGLBindings%s();\n' % setName.upper()) |
| 438 | |
| 439 | # Write typedefs for function pointer types. Always use the GL name for the |
| 440 | # typedef. |
| 441 | file.write('\n') |
| 442 | for [returnType, names, arguments] in functions: |
| 443 | file.write('typedef %s (GL_BINDING_CALL *%sProc)(%s);\n' % |
| 444 | (returnType, names[0], arguments)) |
| 445 | |
| 446 | # Write declarations for function pointers. Always use the GL name for the |
| 447 | # declaration. |
| 448 | file.write('\n') |
| 449 | for [returnType, names, arguments] in functions: |
| 450 | file.write('extern %sProc g_%s;\n' % (names[0], names[0])) |
| 451 | file.write('\n') |
| 452 | file.write( '} // namespace gfx\n') |
| 453 | |
| 454 | # Write macros to invoke function pointers. Always use the GL name for the |
| 455 | # macro. |
| 456 | file.write('\n') |
| 457 | for [returnType, names, arguments] in functions: |
| 458 | file.write('#define %s ::gfx::g_%s\n' % |
| 459 | (names[0], names[0])) |
| 460 | |
| 461 | file.write('\n') |
| 462 | file.write('#endif // APP_GFX_GL_GL_BINDINGS_AUTOGEN_%s_H_\n' % |
| 463 | setName.upper()) |
| 464 | |
| 465 | def GenerateSource(file, functions, setName): |
| 466 | """Generates gl_binding_autogen_x.cc""" |
| 467 | |
| 468 | # Write file header. |
| 469 | file.write('// Copyright (c) 2010 The Chromium Authors. All rights reserved.\n') |
| 470 | file.write('// Use of this source code is governed by a BSD-style license that can be\n') |
| 471 | file.write('// found in the LICENSE file.\n') |
| 472 | file.write('\n') |
| 473 | file.write('// This file is automatically generated.\n') |
| 474 | file.write('\n') |
| 475 | file.write('#include "app/gfx/gl/gl_bindings.h"\n') |
| 476 | file.write('#include "app/gfx/gl/gl_implementation.h"\n') |
| 477 | |
| 478 | # Write definitions of function pointers. |
| 479 | file.write('\n') |
| 480 | file.write('namespace gfx {\n') |
| 481 | file.write('\n') |
| 482 | for [returnType, names, arguments] in functions: |
| 483 | file.write('%sProc g_%s;\n' % (names[0], names[0])) |
| 484 | |
| 485 | # Write function to initialize the function pointers. |
| 486 | file.write('\n') |
| 487 | file.write('void InitializeGLBindings%s() {\n' % setName.upper()) |
| 488 | for [returnType, names, arguments] in functions: |
| 489 | for name in names: |
| 490 | file.write(' if (!g_%s)\n' % names[0]) |
| 491 | file.write( |
| 492 | ' g_%s = reinterpret_cast<%sProc>(GetGLProcAddress("%s"));\n' % |
| 493 | (names[0], names[0], name)) |
| 494 | file.write('}\n') |
| 495 | file.write('\n') |
| 496 | file.write( '} // namespace gfx\n') |
| 497 | |
| 498 | def GenerateMockSource(file, functions): |
| 499 | """Generates functions that invoke a mock GLInterface""" |
| 500 | |
| 501 | file.write('// Copyright (c) 2010 The Chromium Authors. All rights reserved.\n') |
| 502 | file.write('// Use of this source code is governed by a BSD-style license that can be\n') |
| 503 | file.write('// found in the LICENSE file.\n') |
| 504 | file.write('\n') |
| 505 | file.write('// This file is automatically generated.\n') |
| 506 | file.write('\n') |
| 507 | file.write('#include <string.h>\n') |
| 508 | file.write('\n') |
| 509 | file.write('#include "app/gfx/gl/gl_interface.h"\n') |
| 510 | |
| 511 | file.write('\n') |
| 512 | file.write('namespace gfx {\n') |
| 513 | |
| 514 | # Write function that trampoline into the GLInterface. |
| 515 | for [returnType, names, arguments] in functions: |
| 516 | file.write('\n') |
| 517 | file.write('%s GL_BINDING_CALL Mock_%s(%s) {\n' % |
| 518 | (returnType, names[0], arguments)) |
| 519 | argumentNames = re.sub(r'(const )?[a-zA-Z0-9]+\** ([a-zA-Z0-9]+)', r'\2', |
| 520 | arguments) |
| 521 | if argumentNames == 'void': |
| 522 | argumentNames = '' |
| 523 | functionName = names[0][2:] |
| 524 | if returnType == 'void': |
| 525 | file.write(' GLInterface::GetGLInterface()->%s(%s);\n' % |
| 526 | (functionName, argumentNames)) |
| 527 | else: |
| 528 | file.write(' return GLInterface::GetGLInterface()->%s(%s);\n' % |
| 529 | (functionName, argumentNames)) |
| 530 | file.write('}\n') |
| 531 | |
| 532 | # Write a function to lookup a mock GL function based on its name. |
| 533 | file.write('\n') |
| 534 | file.write('void* GL_BINDING_CALL GetMockGLProcAddress(const char* name) {\n') |
| 535 | for [returnType, names, arguments] in functions: |
| 536 | file.write(' if (strcmp(name, "%s") == 0)\n' % names[0]) |
| 537 | file.write(' return reinterpret_cast<void*>(Mock_%s);\n' % names[0]) |
| 538 | file.write(' return NULL;\n') |
| 539 | file.write('}\n'); |
| 540 | |
| 541 | file.write('\n') |
| 542 | file.write('} // namespace gfx\n') |
| 543 | |
| 544 | def main(argv): |
| 545 | """This is the main function.""" |
| 546 | |
| 547 | if len(argv) >= 1: |
| 548 | dir = argv[0] |
| 549 | else: |
| 550 | dir = '.' |
| 551 | |
| 552 | for [functions, setName] in FUNCTION_SETS: |
| 553 | headerFile = open( |
| 554 | os.path.join(dir, 'gl_bindings_autogen_%s.h' % setName), 'wb') |
| 555 | GenerateHeader(headerFile, functions, setName) |
| 556 | headerFile.close() |
| 557 | |
| 558 | sourceFile = open( |
| 559 | os.path.join(dir, 'gl_bindings_autogen_%s.cc' % setName), 'wb') |
| 560 | GenerateSource(sourceFile, functions, setName) |
| 561 | sourceFile.close() |
| 562 | |
| 563 | sourceFile = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb') |
| 564 | GenerateMockSource(sourceFile, GL_FUNCTIONS) |
| 565 | sourceFile.close() |
| 566 | |
| 567 | if __name__ == '__main__': |
| 568 | main(sys.argv[1:]) |