[email protected] | 328ce55f | 2012-04-07 00:33:04 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 5 | #ifndef UI_GL_GL_BINDINGS_H_ |
| 6 | #define UI_GL_GL_BINDINGS_H_ |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 7 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 8 | // Includes the platform independent and platform dependent GL headers. |
| 9 | // Only include this in cc files. It pulls in system headers, including |
| 10 | // the X11 headers on linux, which define all kinds of macros that are |
| 11 | // liable to cause conflicts. |
| 12 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 13 | #include <GL/gl.h> |
| 14 | #include <GL/glext.h> |
[email protected] | b040f9d | 2013-01-19 04:27:00 | [diff] [blame] | 15 | #include <EGL/egl.h> |
| 16 | #include <EGL/eglext.h> |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 17 | |
[email protected] | 218a5a2 | 2010-11-04 19:27:49 | [diff] [blame] | 18 | #include "base/logging.h" |
[email protected] | 06a1a692 | 2013-07-26 11:51:52 | [diff] [blame^] | 19 | #include "base/threading/thread_local.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 20 | #include "build/build_config.h" |
| 21 | #include "ui/gl/gl_export.h" |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 22 | |
| 23 | // The standard OpenGL native extension headers are also included. |
| 24 | #if defined(OS_WIN) |
| 25 | #include <GL/wglext.h> |
[email protected] | 2ec8df5 | 2011-05-25 23:44:58 | [diff] [blame] | 26 | #elif defined(OS_MACOSX) |
| 27 | #include <OpenGL/OpenGL.h> |
| 28 | #elif defined(USE_X11) |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 29 | #include <GL/glx.h> |
| 30 | #include <GL/glxext.h> |
[email protected] | 31c31b2b | 2011-09-27 18:58:29 | [diff] [blame] | 31 | |
| 32 | // Undefine some macros defined by X headers. This is why this file should only |
| 33 | // be included in .cc files. |
| 34 | #undef Bool |
| 35 | #undef None |
| 36 | #undef Status |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 37 | #endif |
| 38 | |
[email protected] | cb68eca | 2013-02-15 07:38:38 | [diff] [blame] | 39 | |
| 40 | // GLES2 defines not part of Desktop GL |
| 41 | // Shader Precision-Specified Types |
| 42 | #define GL_LOW_FLOAT 0x8DF0 |
| 43 | #define GL_MEDIUM_FLOAT 0x8DF1 |
| 44 | #define GL_HIGH_FLOAT 0x8DF2 |
| 45 | #define GL_LOW_INT 0x8DF3 |
| 46 | #define GL_MEDIUM_INT 0x8DF4 |
| 47 | #define GL_HIGH_INT 0x8DF5 |
| 48 | #define GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A |
| 49 | #define GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B |
| 50 | #define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD |
| 51 | #define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB |
| 52 | #define GL_MAX_VARYING_VECTORS 0x8DFC |
| 53 | #define GL_SHADER_BINARY_FORMATS 0x8DF8 |
| 54 | #define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9 |
| 55 | #define GL_SHADER_COMPILER 0x8DFA |
| 56 | #define GL_RGB565 0x8D62 |
| 57 | #define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES 0x8B8B |
| 58 | #define GL_RGB8_OES 0x8051 |
| 59 | #define GL_RGBA8_OES 0x8058 |
| 60 | #define GL_HALF_FLOAT_OES 0x8D61 |
| 61 | |
| 62 | // GL_OES_EGL_image_external |
| 63 | #define GL_TEXTURE_EXTERNAL_OES 0x8D65 |
| 64 | #define GL_SAMPLER_EXTERNAL_OES 0x8D66 |
| 65 | #define GL_TEXTURE_BINDING_EXTERNAL_OES 0x8D67 |
| 66 | #define GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES 0x8D68 |
| 67 | |
| 68 | // GL_ANGLE_translated_shader_source |
| 69 | #define GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE 0x93A0 |
| 70 | |
| 71 | // GL_CHROMIUM_flipy |
| 72 | #define GL_UNPACK_FLIP_Y_CHROMIUM 0x9240 |
| 73 | |
| 74 | #define GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM 0x9241 |
| 75 | #define GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM 0x9242 |
| 76 | #define GL_UNPACK_COLORSPACE_CONVERSION_CHROMIUM 0x9243 |
| 77 | |
| 78 | // GL_CHROMIUM_gpu_memory_manager |
| 79 | #define GL_TEXTURE_POOL_CHROMIUM 0x6000 |
| 80 | #define GL_TEXTURE_POOL_MANAGED_CHROMIUM 0x6001 |
| 81 | #define GL_TEXTURE_POOL_UNMANAGED_CHROMIUM 0x6002 |
| 82 | |
| 83 | // GL_ANGLE_pack_reverse_row_order |
| 84 | #define GL_PACK_REVERSE_ROW_ORDER_ANGLE 0x93A4 |
| 85 | |
| 86 | // GL_ANGLE_texture_usage |
| 87 | #define GL_TEXTURE_USAGE_ANGLE 0x93A2 |
| 88 | #define GL_FRAMEBUFFER_ATTACHMENT_ANGLE 0x93A3 |
| 89 | |
| 90 | // GL_EXT_texture_storage |
| 91 | #define GL_TEXTURE_IMMUTABLE_FORMAT_EXT 0x912F |
| 92 | #define GL_ALPHA8_EXT 0x803C |
| 93 | #define GL_LUMINANCE8_EXT 0x8040 |
| 94 | #define GL_LUMINANCE8_ALPHA8_EXT 0x8045 |
| 95 | #define GL_RGBA32F_EXT 0x8814 |
| 96 | #define GL_RGB32F_EXT 0x8815 |
| 97 | #define GL_ALPHA32F_EXT 0x8816 |
| 98 | #define GL_LUMINANCE32F_EXT 0x8818 |
| 99 | #define GL_LUMINANCE_ALPHA32F_EXT 0x8819 |
| 100 | #define GL_RGBA16F_EXT 0x881A |
| 101 | #define GL_RGB16F_EXT 0x881B |
| 102 | #define GL_ALPHA16F_EXT 0x881C |
| 103 | #define GL_LUMINANCE16F_EXT 0x881E |
| 104 | #define GL_LUMINANCE_ALPHA16F_EXT 0x881F |
| 105 | #define GL_BGRA8_EXT 0x93A1 |
| 106 | |
| 107 | // GL_ANGLE_instanced_arrays |
| 108 | #define GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE 0x88FE |
| 109 | |
| 110 | // GL_EXT_occlusion_query_boolean |
| 111 | #define GL_ANY_SAMPLES_PASSED_EXT 0x8C2F |
| 112 | #define GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT 0x8D6A |
| 113 | #define GL_CURRENT_QUERY_EXT 0x8865 |
| 114 | #define GL_QUERY_RESULT_EXT 0x8866 |
| 115 | #define GL_QUERY_RESULT_AVAILABLE_EXT 0x8867 |
| 116 | |
| 117 | // GL_CHROMIUM_command_buffer_query |
| 118 | #define GL_COMMANDS_ISSUED_CHROMIUM 0x84F2 |
| 119 | |
| 120 | /* GL_CHROMIUM_get_error_query */ |
| 121 | #define GL_GET_ERROR_QUERY_CHROMIUM 0x84F3 |
| 122 | |
| 123 | /* GL_CHROMIUM_command_buffer_latency_query */ |
| 124 | #define GL_LATENCY_QUERY_CHROMIUM 0x84F4 |
| 125 | |
| 126 | /* GL_CHROMIUM_async_pixel_transfers */ |
| 127 | #define GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM 0x84F5 |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 128 | #define GL_ASYNC_READ_PIXELS_COMPLETED_CHROMIUM 0x84F6 |
[email protected] | cb68eca | 2013-02-15 07:38:38 | [diff] [blame] | 129 | |
| 130 | // GL_OES_texure_3D |
| 131 | #define GL_SAMPLER_3D_OES 0x8B5F |
| 132 | |
| 133 | // GL_OES_depth24 |
| 134 | #define GL_DEPTH_COMPONENT24_OES 0x81A6 |
| 135 | |
| 136 | // GL_OES_depth32 |
| 137 | #define GL_DEPTH_COMPONENT32_OES 0x81A7 |
| 138 | |
| 139 | // GL_OES_packed_depth_stencil |
| 140 | #ifndef GL_DEPTH24_STENCIL8_OES |
| 141 | #define GL_DEPTH24_STENCIL8_OES 0x88F0 |
| 142 | #endif |
| 143 | |
| 144 | #ifndef GL_DEPTH24_STENCIL8 |
| 145 | #define GL_DEPTH24_STENCIL8 0x88F0 |
| 146 | #endif |
| 147 | |
| 148 | // GL_OES_compressed_ETC1_RGB8_texture |
| 149 | #define GL_ETC1_RGB8_OES 0x8D64 |
| 150 | |
| 151 | // GL_OES_vertex_array_object |
| 152 | #define GL_VERTEX_ARRAY_BINDING_OES 0x85B5 |
| 153 | |
| 154 | // GL_CHROMIUM_pixel_transfer_buffer_object |
| 155 | #define GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM 0x78EC |
[email protected] | de43f08 | 2013-04-02 01:16:10 | [diff] [blame] | 156 | #define GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM 0x78ED |
| 157 | #define GL_PIXEL_PACK_TRANSFER_BUFFER_BINDING_CHROMIUM 0x78EE |
[email protected] | cb68eca | 2013-02-15 07:38:38 | [diff] [blame] | 158 | #define GL_PIXEL_UNPACK_TRANSFER_BUFFER_BINDING_CHROMIUM 0x78EF |
| 159 | |
| 160 | /* GL_EXT_discard_framebuffer */ |
| 161 | #ifndef GL_EXT_discard_framebuffer |
| 162 | #define GL_COLOR_EXT 0x1800 |
| 163 | #define GL_DEPTH_EXT 0x1801 |
| 164 | #define GL_STENCIL_EXT 0x1802 |
| 165 | #endif |
| 166 | |
| 167 | // GL_ARB_get_program_binary |
| 168 | #define PROGRAM_BINARY_RETRIEVABLE_HINT 0x8257 |
| 169 | // GL_OES_get_program_binary |
| 170 | #define GL_PROGRAM_BINARY_LENGTH_OES 0x8741 |
| 171 | #define GL_NUM_PROGRAM_BINARY_FORMATS_OES 0x87FE |
| 172 | #define GL_PROGRAM_BINARY_FORMATS_OES 0x87FF |
| 173 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 174 | #ifndef GL_EXT_multisampled_render_to_texture |
| 175 | #define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB |
| 176 | #define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56 |
| 177 | #define GL_MAX_SAMPLES_EXT 0x8D57 |
| 178 | #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT 0x8D6C |
| 179 | #endif |
| 180 | |
| 181 | #ifndef GL_IMG_multisampled_render_to_texture |
| 182 | #define GL_RENDERBUFFER_SAMPLES_IMG 0x9133 |
| 183 | #define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_IMG 0x9134 |
| 184 | #define GL_MAX_SAMPLES_IMG 0x9135 |
| 185 | #define GL_TEXTURE_SAMPLES_IMG 0x9136 |
| 186 | #endif |
[email protected] | cb68eca | 2013-02-15 07:38:38 | [diff] [blame] | 187 | |
| 188 | #define GL_GLEXT_PROTOTYPES 1 |
| 189 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 190 | #if defined(OS_WIN) |
| 191 | #define GL_BINDING_CALL WINAPI |
| 192 | #else |
| 193 | #define GL_BINDING_CALL |
| 194 | #endif |
| 195 | |
[email protected] | 218a5a2 | 2010-11-04 19:27:49 | [diff] [blame] | 196 | #define GL_SERVICE_LOG(args) DLOG(INFO) << args; |
[email protected] | 5a83fca | 2012-04-22 02:05:08 | [diff] [blame] | 197 | #if defined(NDEBUG) |
[email protected] | 92afb77 | 2011-12-09 01:49:56 | [diff] [blame] | 198 | #define GL_SERVICE_LOG_CODE_BLOCK(code) |
| 199 | #else |
| 200 | #define GL_SERVICE_LOG_CODE_BLOCK(code) code |
| 201 | #endif |
[email protected] | 218a5a2 | 2010-11-04 19:27:49 | [diff] [blame] | 202 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 203 | // Forward declare OSMesa types. |
| 204 | typedef struct osmesa_context *OSMesaContext; |
| 205 | typedef void (*OSMESAproc)(); |
| 206 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 207 | // Forward declare EGL types. |
[email protected] | 83f48ae | 2013-01-14 14:12:53 | [diff] [blame] | 208 | typedef uint64 EGLuint64CHROMIUM; |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 209 | |
[email protected] | 165f23d | 2013-04-09 23:50:07 | [diff] [blame] | 210 | #ifndef EGL_ANDROID_image_native_buffer |
| 211 | #define EGL_ANDROID_image_native_buffer 1 |
| 212 | #define EGL_NATIVE_BUFFER_ANDROID 0x3140 |
| 213 | #endif |
| 214 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 215 | #include "gl_bindings_autogen_gl.h" |
| 216 | #include "gl_bindings_autogen_osmesa.h" |
| 217 | |
| 218 | #if defined(OS_WIN) |
| 219 | #include "gl_bindings_autogen_egl.h" |
| 220 | #include "gl_bindings_autogen_wgl.h" |
[email protected] | 2ec8df5 | 2011-05-25 23:44:58 | [diff] [blame] | 221 | #elif defined(USE_X11) |
[email protected] | 0bec8e2 | 2010-06-21 22:20:02 | [diff] [blame] | 222 | #include "gl_bindings_autogen_egl.h" |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 223 | #include "gl_bindings_autogen_glx.h" |
[email protected] | efcf2059 | 2013-05-24 06:55:56 | [diff] [blame] | 224 | #elif defined(USE_OZONE) |
| 225 | #include "gl_bindings_autogen_egl.h" |
[email protected] | c8e295b | 2011-11-21 21:24:14 | [diff] [blame] | 226 | #elif defined(OS_ANDROID) |
| 227 | #include "gl_bindings_autogen_egl.h" |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 228 | #endif |
| 229 | |
| 230 | namespace gfx { |
| 231 | |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 232 | struct GL_EXPORT DriverGL { |
| 233 | void Initialize(); |
| 234 | void InitializeExtensions(GLContext* context); |
| 235 | void InitializeDebugBindings(); |
| 236 | void ClearBindings(); |
| 237 | void UpdateDebugExtensionBindings(); |
| 238 | |
| 239 | ProcsGL fn; |
| 240 | ProcsGL orig_fn; |
| 241 | ProcsGL debug_fn; |
| 242 | ExtensionsGL ext; |
| 243 | |
| 244 | private: |
| 245 | void InitializeBindings(); |
| 246 | void InitializeExtensionBindings(GLContext* context); |
| 247 | }; |
| 248 | |
| 249 | struct GL_EXPORT DriverOSMESA { |
| 250 | void InitializeBindings(); |
| 251 | void InitializeExtensionBindings(GLContext* context); |
| 252 | void InitializeDebugBindings(); |
| 253 | void ClearBindings(); |
| 254 | void UpdateDebugExtensionBindings(); |
| 255 | |
| 256 | ProcsOSMESA fn; |
| 257 | ProcsOSMESA debug_fn; |
| 258 | ExtensionsOSMESA ext; |
| 259 | }; |
| 260 | |
| 261 | #if defined(OS_WIN) |
| 262 | struct GL_EXPORT DriverWGL { |
| 263 | void InitializeBindings(); |
| 264 | void InitializeExtensionBindings(GLContext* context); |
| 265 | void InitializeDebugBindings(); |
| 266 | void ClearBindings(); |
| 267 | void UpdateDebugExtensionBindings(); |
| 268 | |
| 269 | ProcsWGL fn; |
| 270 | ProcsWGL debug_fn; |
| 271 | ExtensionsWGL ext; |
| 272 | }; |
| 273 | #endif |
| 274 | |
[email protected] | efcf2059 | 2013-05-24 06:55:56 | [diff] [blame] | 275 | #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || defined(USE_OZONE) |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 276 | struct GL_EXPORT DriverEGL { |
| 277 | void InitializeBindings(); |
| 278 | void InitializeExtensionBindings(GLContext* context); |
| 279 | void InitializeDebugBindings(); |
| 280 | void ClearBindings(); |
| 281 | void UpdateDebugExtensionBindings(); |
| 282 | |
| 283 | ProcsEGL fn; |
| 284 | ProcsEGL debug_fn; |
| 285 | ExtensionsEGL ext; |
| 286 | }; |
| 287 | #endif |
| 288 | |
| 289 | #if defined(USE_X11) |
| 290 | struct GL_EXPORT DriverGLX { |
| 291 | void InitializeBindings(); |
| 292 | void InitializeExtensionBindings(GLContext* context); |
| 293 | void InitializeDebugBindings(); |
| 294 | void ClearBindings(); |
| 295 | void UpdateDebugExtensionBindings(); |
| 296 | |
| 297 | ProcsGLX fn; |
| 298 | ProcsGLX debug_fn; |
| 299 | ExtensionsGLX ext; |
| 300 | }; |
| 301 | #endif |
| 302 | |
[email protected] | 06a1a692 | 2013-07-26 11:51:52 | [diff] [blame^] | 303 | // This #define is here to support autogenerated code. |
| 304 | #define g_current_gl_context g_current_gl_context_tls->Get() |
| 305 | GL_EXPORT extern base::ThreadLocalPointer<GLApi>* g_current_gl_context_tls; |
| 306 | |
[email protected] | b97c908 | 2012-10-25 17:21:38 | [diff] [blame] | 307 | GL_EXPORT extern OSMESAApi* g_current_osmesa_context; |
| 308 | GL_EXPORT extern DriverGL g_driver_gl; |
| 309 | GL_EXPORT extern DriverOSMESA g_driver_osmesa; |
| 310 | |
| 311 | #if defined(OS_WIN) |
| 312 | |
| 313 | GL_EXPORT extern EGLApi* g_current_egl_context; |
| 314 | GL_EXPORT extern WGLApi* g_current_wgl_context; |
| 315 | GL_EXPORT extern DriverEGL g_driver_egl; |
| 316 | GL_EXPORT extern DriverWGL g_driver_wgl; |
| 317 | |
| 318 | #elif defined(USE_X11) |
| 319 | |
| 320 | GL_EXPORT extern EGLApi* g_current_egl_context; |
| 321 | GL_EXPORT extern GLXApi* g_current_glx_context; |
| 322 | GL_EXPORT extern DriverEGL g_driver_egl; |
| 323 | GL_EXPORT extern DriverGLX g_driver_glx; |
| 324 | |
[email protected] | efcf2059 | 2013-05-24 06:55:56 | [diff] [blame] | 325 | #elif defined(USE_OZONE) |
| 326 | |
| 327 | GL_EXPORT extern EGLApi* g_current_egl_context; |
| 328 | GL_EXPORT extern DriverEGL g_driver_egl; |
| 329 | |
[email protected] | b97c908 | 2012-10-25 17:21:38 | [diff] [blame] | 330 | #elif defined(OS_ANDROID) |
| 331 | |
| 332 | GL_EXPORT extern EGLApi* g_current_egl_context; |
| 333 | GL_EXPORT extern DriverEGL g_driver_egl; |
| 334 | |
| 335 | #endif |
| 336 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 337 | // Find an entry point to the mock GL implementation. |
| 338 | void* GL_BINDING_CALL GetMockGLProcAddress(const char* name); |
| 339 | |
| 340 | } // namespace gfx |
| 341 | |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 342 | #endif // UI_GL_GL_BINDINGS_H_ |