1 2 /* 3 * Copyright 2014 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10 #include "GrGLAssembleInterface.h" 11 #include "GrGLUtil.h" 12 13 #define GET_PROC(F) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F) 14 #define GET_PROC_SUFFIX(F, S) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F #S) 15 #define GET_PROC_LOCAL(F) GrGL ## F ## Proc F = (GrGL ## F ## Proc) get(ctx, "gl" #F) 16 17 #define GET_EGL_PROC_SUFFIX(F, S) functions->fEGL ## F = (GrEGL ## F ## Proc) get(ctx, "egl" #F #S) 18 19 const GrGLInterface* GrGLAssembleInterface(void* ctx, GrGLGetProc get) { 20 GET_PROC_LOCAL(GetString); 21 if (nullptr == GetString) { 22 return nullptr; 23 } 24 25 const char* verStr = reinterpret_cast<const char*>(GetString(GR_GL_VERSION)); 26 if (nullptr == verStr) { 27 return nullptr; 28 } 29 30 GrGLStandard standard = GrGLGetStandardInUseFromString(verStr); 31 32 if (kGLES_GrGLStandard == standard) { 33 return GrGLAssembleGLESInterface(ctx, get); 34 } else if (kGL_GrGLStandard == standard) { 35 return GrGLAssembleGLInterface(ctx, get); 36 } 37 return nullptr; 38 } 39 40 static void get_egl_query_and_display(GrEGLQueryStringProc* queryString, GrEGLDisplay* display, 41 void* ctx, GrGLGetProc get) { 42 *queryString = (GrEGLQueryStringProc) get(ctx, "eglQueryString"); 43 *display = GR_EGL_NO_DISPLAY; 44 if (*queryString) { 45 GrEGLGetCurrentDisplayProc getCurrentDisplay = 46 (GrEGLGetCurrentDisplayProc) get(ctx, "eglGetCurrentDisplay"); 47 if (getCurrentDisplay) { 48 *display = getCurrentDisplay(); 49 } else { 50 *queryString = nullptr; 51 } 52 } 53 } 54 55 const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) { 56 GET_PROC_LOCAL(GetString); 57 GET_PROC_LOCAL(GetStringi); 58 GET_PROC_LOCAL(GetIntegerv); 59 60 // GetStringi may be nullptr depending on the GL version. 61 if (nullptr == GetString || nullptr == GetIntegerv) { 62 return nullptr; 63 } 64 65 const char* versionString = (const char*) GetString(GR_GL_VERSION); 66 GrGLVersion glVer = GrGLGetVersionFromString(versionString); 67 68 if (glVer < GR_GL_VER(1,5) || GR_GL_INVALID_VER == glVer) { 69 // We must have array and element_array buffer objects. 70 return nullptr; 71 } 72 73 GrEGLQueryStringProc queryString; 74 GrEGLDisplay display; 75 get_egl_query_and_display(&queryString, &display, ctx, get); 76 GrGLExtensions extensions; 77 if (!extensions.init(kGL_GrGLStandard, GetString, GetStringi, GetIntegerv, queryString, 78 display)) { 79 return nullptr; 80 } 81 82 GrGLInterface* interface = new GrGLInterface(); 83 GrGLInterface::Functions* functions = &interface->fFunctions; 84 85 GET_PROC(ActiveTexture); 86 GET_PROC(AttachShader); 87 GET_PROC(BindAttribLocation); 88 GET_PROC(BindBuffer); 89 if (glVer >= GR_GL_VER(3,0)) { 90 GET_PROC(BindFragDataLocation); 91 } 92 GET_PROC(BeginQuery); 93 GET_PROC(BindTexture); 94 95 if (extensions.has("GL_KHR_blend_equation_advanced")) { 96 GET_PROC_SUFFIX(BlendBarrier, KHR); 97 } else if (extensions.has("GL_NV_blend_equation_advanced")) { 98 GET_PROC_SUFFIX(BlendBarrier, NV); 99 } 100 101 if (glVer >= GR_GL_VER(1,4) || 102 extensions.has("GL_ARB_imaging")) { 103 GET_PROC(BlendColor); 104 } else if (extensions.has("GL_EXT_blend_color")) { 105 GET_PROC_SUFFIX(BlendColor, EXT); 106 } 107 108 if (glVer >= GR_GL_VER(1,4) || 109 extensions.has("GL_ARB_imaging")) { 110 GET_PROC(BlendEquation); 111 } else if (extensions.has("GL_EXT_blend_subtract")) { 112 GET_PROC_SUFFIX(BlendEquation, EXT); 113 } 114 115 GET_PROC(BlendFunc); 116 GET_PROC(BufferData); 117 GET_PROC(BufferSubData); 118 GET_PROC(Clear); 119 GET_PROC(ClearColor); 120 GET_PROC(ClearStencil); 121 GET_PROC(ColorMask); 122 GET_PROC(CompileShader); 123 GET_PROC(CompressedTexImage2D); 124 GET_PROC(CompressedTexSubImage2D); 125 GET_PROC(CopyTexSubImage2D); 126 GET_PROC(CreateProgram); 127 GET_PROC(CreateShader); 128 GET_PROC(CullFace); 129 GET_PROC(DeleteBuffers); 130 GET_PROC(DeleteProgram); 131 GET_PROC(DeleteQueries); 132 GET_PROC(DeleteShader); 133 GET_PROC(DeleteTextures); 134 GET_PROC(DepthMask); 135 GET_PROC(Disable); 136 GET_PROC(DisableVertexAttribArray); 137 GET_PROC(DrawArrays); 138 GET_PROC(DrawBuffer); 139 GET_PROC(DrawBuffers); 140 GET_PROC(DrawElements); 141 142 if (glVer >= GR_GL_VER(3,1) || extensions.has("GL_ARB_draw_instanced") || 143 extensions.has("GL_EXT_draw_instanced")) { 144 GET_PROC(DrawArraysInstanced); 145 GET_PROC(DrawElementsInstanced); 146 } 147 148 if (glVer >= GR_GL_VER(4,0)) { 149 // We don't use ARB_draw_indirect because it does not support a base instance. 150 GET_PROC(DrawArraysIndirect); 151 GET_PROC(DrawElementsIndirect); 152 } 153 154 GET_PROC(Enable); 155 GET_PROC(EnableVertexAttribArray); 156 GET_PROC(EndQuery); 157 GET_PROC(Finish); 158 GET_PROC(Flush); 159 GET_PROC(FrontFace); 160 GET_PROC(GenBuffers); 161 GET_PROC(GenerateMipmap); 162 GET_PROC(GetBufferParameteriv); 163 GET_PROC(GetError); 164 GET_PROC(GetIntegerv); 165 GET_PROC(GetQueryObjectiv); 166 GET_PROC(GetQueryObjectuiv); 167 if (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) { 168 GET_PROC(GetQueryObjecti64v); 169 GET_PROC(GetQueryObjectui64v); 170 GET_PROC(QueryCounter); 171 } else if (extensions.has("GL_EXT_timer_query")) { 172 GET_PROC_SUFFIX(GetQueryObjecti64v, EXT); 173 GET_PROC_SUFFIX(GetQueryObjectui64v, EXT); 174 } 175 GET_PROC(GetQueryiv); 176 GET_PROC(GetProgramInfoLog); 177 GET_PROC(GetProgramiv); 178 GET_PROC(GetShaderInfoLog); 179 GET_PROC(GetShaderiv); 180 GET_PROC(GetString); 181 GET_PROC(GetStringi); 182 GET_PROC(GetShaderPrecisionFormat); 183 GET_PROC(GetTexLevelParameteriv); 184 GET_PROC(GenQueries); 185 GET_PROC(GenTextures); 186 GET_PROC(GetUniformLocation); 187 GET_PROC(IsTexture); 188 GET_PROC(LineWidth); 189 GET_PROC(LinkProgram); 190 GET_PROC(MapBuffer); 191 GET_PROC(PixelStorei); 192 if (extensions.has("GL_EXT_raster_multisample")) { 193 GET_PROC_SUFFIX(RasterSamples, EXT); 194 } 195 GET_PROC(ReadBuffer); 196 GET_PROC(ReadPixels); 197 GET_PROC(Scissor); 198 GET_PROC(ShaderSource); 199 GET_PROC(StencilFunc); 200 GET_PROC(StencilFuncSeparate); 201 GET_PROC(StencilMask); 202 GET_PROC(StencilMaskSeparate); 203 GET_PROC(StencilOp); 204 GET_PROC(StencilOpSeparate); 205 GET_PROC(TexImage2D); 206 GET_PROC(TexParameteri); 207 GET_PROC(TexParameteriv); 208 if (glVer >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage")) { 209 GET_PROC(TexStorage2D); 210 } else if (extensions.has("GL_EXT_texture_storage")) { 211 GET_PROC_SUFFIX(TexStorage2D, EXT); 212 } 213 GET_PROC(TexSubImage2D); 214 if (glVer >= GR_GL_VER(4,5) || extensions.has("GL_ARB_texture_barrier")) { 215 GET_PROC(TextureBarrier); 216 } else if (extensions.has("GL_NV_texture_barrier")) { 217 GET_PROC_SUFFIX(TextureBarrier, NV); 218 } 219 GET_PROC(Uniform1f); 220 GET_PROC(Uniform1i); 221 GET_PROC(Uniform1fv); 222 GET_PROC(Uniform1iv); 223 GET_PROC(Uniform2f); 224 GET_PROC(Uniform2i); 225 GET_PROC(Uniform2fv); 226 GET_PROC(Uniform2iv); 227 GET_PROC(Uniform3f); 228 GET_PROC(Uniform3i); 229 GET_PROC(Uniform3fv); 230 GET_PROC(Uniform3iv); 231 GET_PROC(Uniform4f); 232 GET_PROC(Uniform4i); 233 GET_PROC(Uniform4fv); 234 GET_PROC(Uniform4iv); 235 GET_PROC(UniformMatrix2fv); 236 GET_PROC(UniformMatrix3fv); 237 GET_PROC(UniformMatrix4fv); 238 GET_PROC(UnmapBuffer); 239 GET_PROC(UseProgram); 240 GET_PROC(VertexAttrib1f); 241 GET_PROC(VertexAttrib2fv); 242 GET_PROC(VertexAttrib3fv); 243 GET_PROC(VertexAttrib4fv); 244 245 if (glVer >= GR_GL_VER(3,2) || extensions.has("GL_ARB_instanced_arrays")) { 246 GET_PROC(VertexAttribDivisor); 247 } 248 249 if (glVer >= GR_GL_VER(3,0)) { 250 GET_PROC(VertexAttribIPointer); 251 } 252 253 GET_PROC(VertexAttribPointer); 254 GET_PROC(Viewport); 255 GET_PROC(BindFragDataLocationIndexed); 256 257 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_object")) { 258 // no ARB suffix for GL_ARB_vertex_array_object 259 GET_PROC(BindVertexArray); 260 GET_PROC(GenVertexArrays); 261 GET_PROC(DeleteVertexArrays); 262 } else if (extensions.has("GL_APPLE_vertex_array_object")) { 263 GET_PROC_SUFFIX(BindVertexArray, APPLE); 264 GET_PROC_SUFFIX(GenVertexArrays, APPLE); 265 GET_PROC_SUFFIX(DeleteVertexArrays, APPLE); 266 } 267 268 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_map_buffer_range")) { 269 GET_PROC(MapBufferRange); 270 GET_PROC(FlushMappedBufferRange); 271 } 272 273 // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since 274 // GL_ARB_framebuffer_object doesn't use ARB suffix.) 275 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) { 276 GET_PROC(GenFramebuffers); 277 GET_PROC(GetFramebufferAttachmentParameteriv); 278 GET_PROC(GetRenderbufferParameteriv); 279 GET_PROC(BindFramebuffer); 280 GET_PROC(FramebufferTexture2D); 281 GET_PROC(CheckFramebufferStatus); 282 GET_PROC(DeleteFramebuffers); 283 GET_PROC(RenderbufferStorage); 284 GET_PROC(GenRenderbuffers); 285 GET_PROC(DeleteRenderbuffers); 286 GET_PROC(FramebufferRenderbuffer); 287 GET_PROC(BindRenderbuffer); 288 GET_PROC(RenderbufferStorageMultisample); 289 GET_PROC(BlitFramebuffer); 290 } else if (extensions.has("GL_EXT_framebuffer_object")) { 291 GET_PROC_SUFFIX(GenFramebuffers, EXT); 292 GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT); 293 GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT); 294 GET_PROC_SUFFIX(BindFramebuffer, EXT); 295 GET_PROC_SUFFIX(FramebufferTexture2D, EXT); 296 GET_PROC_SUFFIX(CheckFramebufferStatus, EXT); 297 GET_PROC_SUFFIX(DeleteFramebuffers, EXT); 298 GET_PROC_SUFFIX(RenderbufferStorage, EXT); 299 GET_PROC_SUFFIX(GenRenderbuffers, EXT); 300 GET_PROC_SUFFIX(DeleteRenderbuffers, EXT); 301 GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT); 302 GET_PROC_SUFFIX(BindRenderbuffer, EXT); 303 if (extensions.has("GL_EXT_framebuffer_multisample")) { 304 GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT); 305 } 306 if (extensions.has("GL_EXT_framebuffer_blit")) { 307 GET_PROC_SUFFIX(BlitFramebuffer, EXT); 308 } 309 } else { 310 // we must have FBOs 311 delete interface; 312 return nullptr; 313 } 314 315 if (extensions.has("GL_NV_path_rendering")) { 316 GET_PROC_SUFFIX(MatrixLoadf, EXT); 317 GET_PROC_SUFFIX(MatrixLoadIdentity, EXT); 318 GET_PROC_SUFFIX(PathCommands, NV); 319 GET_PROC_SUFFIX(PathParameteri, NV); 320 GET_PROC_SUFFIX(PathParameterf, NV); 321 GET_PROC_SUFFIX(GenPaths, NV); 322 GET_PROC_SUFFIX(DeletePaths, NV); 323 GET_PROC_SUFFIX(IsPath, NV); 324 GET_PROC_SUFFIX(PathStencilFunc, NV); 325 GET_PROC_SUFFIX(StencilFillPath, NV); 326 GET_PROC_SUFFIX(StencilStrokePath, NV); 327 GET_PROC_SUFFIX(StencilFillPathInstanced, NV); 328 GET_PROC_SUFFIX(StencilStrokePathInstanced, NV); 329 GET_PROC_SUFFIX(CoverFillPath, NV); 330 GET_PROC_SUFFIX(CoverStrokePath, NV); 331 GET_PROC_SUFFIX(CoverFillPathInstanced, NV); 332 GET_PROC_SUFFIX(CoverStrokePathInstanced, NV); 333 GET_PROC_SUFFIX(StencilThenCoverFillPath, NV); 334 GET_PROC_SUFFIX(StencilThenCoverStrokePath, NV); 335 GET_PROC_SUFFIX(StencilThenCoverFillPathInstanced, NV); 336 GET_PROC_SUFFIX(StencilThenCoverStrokePathInstanced, NV); 337 GET_PROC_SUFFIX(ProgramPathFragmentInputGen, NV); 338 } 339 340 if (extensions.has("GL_NV_framebuffer_mixed_samples")) { 341 GET_PROC_SUFFIX(CoverageModulation, NV); 342 } 343 344 if (extensions.has("GL_EXT_debug_marker")) { 345 GET_PROC_SUFFIX(InsertEventMarker, EXT); 346 GET_PROC_SUFFIX(PushGroupMarker, EXT); 347 GET_PROC_SUFFIX(PopGroupMarker, EXT); 348 } 349 350 if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_invalidate_subdata")) { 351 GET_PROC(InvalidateBufferData); 352 GET_PROC(InvalidateBufferSubData); 353 GET_PROC(InvalidateFramebuffer); 354 GET_PROC(InvalidateSubFramebuffer); 355 GET_PROC(InvalidateTexImage); 356 GET_PROC(InvalidateTexSubImage); 357 } 358 359 if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_program_interface_query")) { 360 GET_PROC(GetProgramResourceLocation); 361 } 362 363 if (glVer >= GR_GL_VER(4,3)) { 364 // We don't use ARB_multi_draw_indirect because it does not support GL_DRAW_INDIRECT_BUFFER. 365 GET_PROC(MultiDrawArraysIndirect); 366 GET_PROC(MultiDrawElementsIndirect); 367 } 368 369 if (extensions.has("GL_NV_bindless_texture")) { 370 GET_PROC_SUFFIX(GetTextureHandle, NV); 371 GET_PROC_SUFFIX(GetTextureSamplerHandle, NV); 372 GET_PROC_SUFFIX(MakeTextureHandleResident, NV); 373 GET_PROC_SUFFIX(MakeTextureHandleNonResident, NV); 374 GET_PROC_SUFFIX(GetImageHandle, NV); 375 GET_PROC_SUFFIX(MakeImageHandleResident, NV); 376 GET_PROC_SUFFIX(MakeImageHandleNonResident, NV); 377 GET_PROC_SUFFIX(IsTextureHandleResident, NV); 378 GET_PROC_SUFFIX(IsImageHandleResident, NV); 379 GET_PROC_SUFFIX(UniformHandleui64, NV); 380 GET_PROC_SUFFIX(UniformHandleui64v, NV); 381 GET_PROC_SUFFIX(ProgramUniformHandleui64, NV); 382 GET_PROC_SUFFIX(ProgramUniformHandleui64v, NV); 383 } 384 385 if (extensions.has("GL_EXT_direct_state_access")) { 386 GET_PROC_SUFFIX(TextureParameteri, EXT); 387 GET_PROC_SUFFIX(TextureParameteriv, EXT); 388 GET_PROC_SUFFIX(TextureParameterf, EXT); 389 GET_PROC_SUFFIX(TextureParameterfv, EXT); 390 GET_PROC_SUFFIX(TextureImage1D, EXT); 391 GET_PROC_SUFFIX(TextureImage2D, EXT); 392 GET_PROC_SUFFIX(TextureSubImage1D, EXT); 393 GET_PROC_SUFFIX(TextureSubImage2D, EXT); 394 GET_PROC_SUFFIX(CopyTextureImage1D, EXT); 395 GET_PROC_SUFFIX(CopyTextureImage2D, EXT); 396 GET_PROC_SUFFIX(CopyTextureSubImage1D, EXT); 397 GET_PROC_SUFFIX(CopyTextureSubImage2D, EXT); 398 GET_PROC_SUFFIX(GetTextureImage, EXT); 399 GET_PROC_SUFFIX(GetTextureParameterfv, EXT); 400 GET_PROC_SUFFIX(GetTextureParameteriv, EXT); 401 GET_PROC_SUFFIX(GetTextureLevelParameterfv, EXT); 402 GET_PROC_SUFFIX(GetTextureLevelParameteriv, EXT); 403 if (glVer >= GR_GL_VER(1,2)) { 404 GET_PROC_SUFFIX(TextureImage3D, EXT); 405 GET_PROC_SUFFIX(TextureSubImage3D, EXT); 406 GET_PROC_SUFFIX(CopyTextureSubImage3D, EXT); 407 GET_PROC_SUFFIX(CompressedTextureImage3D, EXT); 408 GET_PROC_SUFFIX(CompressedTextureImage2D, EXT); 409 GET_PROC_SUFFIX(CompressedTextureImage1D, EXT); 410 GET_PROC_SUFFIX(CompressedTextureSubImage3D, EXT); 411 GET_PROC_SUFFIX(CompressedTextureSubImage2D, EXT); 412 GET_PROC_SUFFIX(CompressedTextureSubImage1D, EXT); 413 GET_PROC_SUFFIX(GetCompressedTextureImage, EXT); 414 } 415 if (glVer >= GR_GL_VER(1,5)) { 416 GET_PROC_SUFFIX(NamedBufferData, EXT); 417 GET_PROC_SUFFIX(NamedBufferSubData, EXT); 418 GET_PROC_SUFFIX(MapNamedBuffer, EXT); 419 GET_PROC_SUFFIX(UnmapNamedBuffer, EXT); 420 GET_PROC_SUFFIX(GetNamedBufferParameteriv, EXT); 421 GET_PROC_SUFFIX(GetNamedBufferPointerv, EXT); 422 GET_PROC_SUFFIX(GetNamedBufferSubData, EXT); 423 } 424 if (glVer >= GR_GL_VER(2,0)) { 425 GET_PROC_SUFFIX(ProgramUniform1f, EXT); 426 GET_PROC_SUFFIX(ProgramUniform2f, EXT); 427 GET_PROC_SUFFIX(ProgramUniform3f, EXT); 428 GET_PROC_SUFFIX(ProgramUniform4f, EXT); 429 GET_PROC_SUFFIX(ProgramUniform1i, EXT); 430 GET_PROC_SUFFIX(ProgramUniform2i, EXT); 431 GET_PROC_SUFFIX(ProgramUniform3i, EXT); 432 GET_PROC_SUFFIX(ProgramUniform4i, EXT); 433 GET_PROC_SUFFIX(ProgramUniform1fv, EXT); 434 GET_PROC_SUFFIX(ProgramUniform2fv, EXT); 435 GET_PROC_SUFFIX(ProgramUniform3fv, EXT); 436 GET_PROC_SUFFIX(ProgramUniform4fv, EXT); 437 GET_PROC_SUFFIX(ProgramUniform1iv, EXT); 438 GET_PROC_SUFFIX(ProgramUniform2iv, EXT); 439 GET_PROC_SUFFIX(ProgramUniform3iv, EXT); 440 GET_PROC_SUFFIX(ProgramUniform4iv, EXT); 441 GET_PROC_SUFFIX(ProgramUniformMatrix2fv, EXT); 442 GET_PROC_SUFFIX(ProgramUniformMatrix3fv, EXT); 443 GET_PROC_SUFFIX(ProgramUniformMatrix4fv, EXT); 444 } 445 if (glVer >= GR_GL_VER(2,1)) { 446 GET_PROC_SUFFIX(ProgramUniformMatrix2x3fv, EXT); 447 GET_PROC_SUFFIX(ProgramUniformMatrix3x2fv, EXT); 448 GET_PROC_SUFFIX(ProgramUniformMatrix2x4fv, EXT); 449 GET_PROC_SUFFIX(ProgramUniformMatrix4x2fv, EXT); 450 GET_PROC_SUFFIX(ProgramUniformMatrix3x4fv, EXT); 451 GET_PROC_SUFFIX(ProgramUniformMatrix4x3fv, EXT); 452 } 453 if (glVer >= GR_GL_VER(3,0)) { 454 GET_PROC_SUFFIX(NamedRenderbufferStorage, EXT); 455 GET_PROC_SUFFIX(GetNamedRenderbufferParameteriv, EXT); 456 GET_PROC_SUFFIX(NamedRenderbufferStorageMultisample, EXT); 457 GET_PROC_SUFFIX(CheckNamedFramebufferStatus, EXT); 458 GET_PROC_SUFFIX(NamedFramebufferTexture1D, EXT); 459 GET_PROC_SUFFIX(NamedFramebufferTexture2D, EXT); 460 GET_PROC_SUFFIX(NamedFramebufferTexture3D, EXT); 461 GET_PROC_SUFFIX(NamedFramebufferRenderbuffer, EXT); 462 GET_PROC_SUFFIX(GetNamedFramebufferAttachmentParameteriv, EXT); 463 GET_PROC_SUFFIX(GenerateTextureMipmap, EXT); 464 GET_PROC_SUFFIX(FramebufferDrawBuffer, EXT); 465 GET_PROC_SUFFIX(FramebufferDrawBuffers, EXT); 466 GET_PROC_SUFFIX(FramebufferReadBuffer, EXT); 467 GET_PROC_SUFFIX(GetFramebufferParameteriv, EXT); 468 GET_PROC_SUFFIX(NamedCopyBufferSubData, EXT); 469 GET_PROC_SUFFIX(VertexArrayVertexOffset, EXT); 470 GET_PROC_SUFFIX(VertexArrayColorOffset, EXT); 471 GET_PROC_SUFFIX(VertexArrayEdgeFlagOffset, EXT); 472 GET_PROC_SUFFIX(VertexArrayIndexOffset, EXT); 473 GET_PROC_SUFFIX(VertexArrayNormalOffset, EXT); 474 GET_PROC_SUFFIX(VertexArrayTexCoordOffset, EXT); 475 GET_PROC_SUFFIX(VertexArrayMultiTexCoordOffset, EXT); 476 GET_PROC_SUFFIX(VertexArrayFogCoordOffset, EXT); 477 GET_PROC_SUFFIX(VertexArraySecondaryColorOffset, EXT); 478 GET_PROC_SUFFIX(VertexArrayVertexAttribOffset, EXT); 479 GET_PROC_SUFFIX(VertexArrayVertexAttribIOffset, EXT); 480 GET_PROC_SUFFIX(EnableVertexArray, EXT); 481 GET_PROC_SUFFIX(DisableVertexArray, EXT); 482 GET_PROC_SUFFIX(EnableVertexArrayAttrib, EXT); 483 GET_PROC_SUFFIX(DisableVertexArrayAttrib, EXT); 484 GET_PROC_SUFFIX(GetVertexArrayIntegerv, EXT); 485 GET_PROC_SUFFIX(GetVertexArrayPointerv, EXT); 486 GET_PROC_SUFFIX(GetVertexArrayIntegeri_v, EXT); 487 GET_PROC_SUFFIX(GetVertexArrayPointeri_v, EXT); 488 GET_PROC_SUFFIX(MapNamedBufferRange, EXT); 489 GET_PROC_SUFFIX(FlushMappedNamedBufferRange, EXT); 490 } 491 } 492 493 if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_KHR_debug")) { 494 // KHR_debug defines these methods to have no suffix in an OpenGL (not ES) context. 495 GET_PROC(DebugMessageControl); 496 GET_PROC(DebugMessageInsert); 497 GET_PROC(DebugMessageCallback); 498 GET_PROC(GetDebugMessageLog); 499 GET_PROC(PushDebugGroup); 500 GET_PROC(PopDebugGroup); 501 GET_PROC(ObjectLabel); 502 } 503 504 if (extensions.has("EGL_KHR_image") || extensions.has("EGL_KHR_image_base")) { 505 GET_EGL_PROC_SUFFIX(CreateImage, KHR); 506 GET_EGL_PROC_SUFFIX(DestroyImage, KHR); 507 } 508 509 interface->fStandard = kGL_GrGLStandard; 510 interface->fExtensions.swap(&extensions); 511 512 return interface; 513 } 514 515 const GrGLInterface* GrGLAssembleGLESInterface(void* ctx, GrGLGetProc get) { 516 GET_PROC_LOCAL(GetString); 517 if (nullptr == GetString) { 518 return nullptr; 519 } 520 521 const char* verStr = reinterpret_cast<const char*>(GetString(GR_GL_VERSION)); 522 GrGLVersion version = GrGLGetVersionFromString(verStr); 523 524 if (version < GR_GL_VER(2,0)) { 525 return nullptr; 526 } 527 528 GET_PROC_LOCAL(GetIntegerv); 529 GET_PROC_LOCAL(GetStringi); 530 GrEGLQueryStringProc queryString; 531 GrEGLDisplay display; 532 get_egl_query_and_display(&queryString, &display, ctx, get); 533 GrGLExtensions extensions; 534 if (!extensions.init(kGLES_GrGLStandard, GetString, GetStringi, GetIntegerv, queryString, 535 display)) { 536 return nullptr; 537 } 538 539 GrGLInterface* interface = new GrGLInterface; 540 GrGLInterface::Functions* functions = &interface->fFunctions; 541 542 GET_PROC(ActiveTexture); 543 GET_PROC(AttachShader); 544 GET_PROC(BindAttribLocation); 545 GET_PROC(BindBuffer); 546 GET_PROC(BindTexture); 547 GET_PROC_SUFFIX(BindVertexArray, OES); 548 549 if (version >= GR_GL_VER(3,0) && extensions.has("GL_EXT_blend_func_extended")) { 550 GET_PROC_SUFFIX(BindFragDataLocation, EXT); 551 GET_PROC_SUFFIX(BindFragDataLocationIndexed, EXT); 552 } 553 554 if (extensions.has("GL_KHR_blend_equation_advanced")) { 555 GET_PROC_SUFFIX(BlendBarrier, KHR); 556 } else if (extensions.has("GL_NV_blend_equation_advanced")) { 557 GET_PROC_SUFFIX(BlendBarrier, NV); 558 } 559 560 GET_PROC(BlendColor); 561 GET_PROC(BlendEquation); 562 GET_PROC(BlendFunc); 563 GET_PROC(BufferData); 564 GET_PROC(BufferSubData); 565 GET_PROC(Clear); 566 GET_PROC(ClearColor); 567 GET_PROC(ClearStencil); 568 GET_PROC(ColorMask); 569 GET_PROC(CompileShader); 570 GET_PROC(CompressedTexImage2D); 571 GET_PROC(CompressedTexSubImage2D); 572 GET_PROC(CopyTexSubImage2D); 573 GET_PROC(CreateProgram); 574 GET_PROC(CreateShader); 575 GET_PROC(CullFace); 576 GET_PROC(DeleteBuffers); 577 GET_PROC(DeleteProgram); 578 GET_PROC(DeleteShader); 579 GET_PROC(DeleteTextures); 580 GET_PROC_SUFFIX(DeleteVertexArrays, OES); 581 GET_PROC(DepthMask); 582 GET_PROC(Disable); 583 GET_PROC(DisableVertexAttribArray); 584 GET_PROC(DrawArrays); 585 586 if (version >= GR_GL_VER(3,0)) { 587 GET_PROC(DrawArraysInstanced); 588 GET_PROC(DrawElementsInstanced); 589 } else if (extensions.has("GL_EXT_draw_instanced")) { 590 GET_PROC_SUFFIX(DrawArraysInstanced, EXT); 591 GET_PROC_SUFFIX(DrawElementsInstanced, EXT); 592 } 593 594 if (version >= GR_GL_VER(3,1)) { 595 GET_PROC(DrawArraysIndirect); 596 GET_PROC(DrawElementsIndirect); 597 } 598 599 GET_PROC(DrawElements); 600 GET_PROC(Enable); 601 GET_PROC(EnableVertexAttribArray); 602 GET_PROC(Finish); 603 GET_PROC(Flush); 604 GET_PROC(FrontFace); 605 GET_PROC(GenBuffers); 606 GET_PROC(GenerateMipmap); 607 GET_PROC(GenTextures); 608 GET_PROC_SUFFIX(GenVertexArrays, OES); 609 GET_PROC(GetBufferParameteriv); 610 GET_PROC(GetError); 611 GET_PROC(GetIntegerv); 612 GET_PROC(GetProgramInfoLog); 613 GET_PROC(GetProgramiv); 614 GET_PROC(GetShaderInfoLog); 615 GET_PROC(GetShaderPrecisionFormat); 616 GET_PROC(GetShaderiv); 617 GET_PROC(GetString); 618 GET_PROC(GetStringi); 619 GET_PROC(GetUniformLocation); 620 GET_PROC(IsTexture); 621 GET_PROC(LineWidth); 622 GET_PROC(LinkProgram); 623 GET_PROC(PixelStorei); 624 625 if (extensions.has("GL_EXT_raster_multisample")) { 626 GET_PROC_SUFFIX(RasterSamples, EXT); 627 } 628 629 GET_PROC(ReadPixels); 630 GET_PROC(Scissor); 631 GET_PROC(ShaderSource); 632 GET_PROC(StencilFunc); 633 GET_PROC(StencilFuncSeparate); 634 GET_PROC(StencilMask); 635 GET_PROC(StencilMaskSeparate); 636 GET_PROC(StencilOp); 637 GET_PROC(StencilOpSeparate); 638 GET_PROC(TexImage2D); 639 GET_PROC(TexParameteri); 640 GET_PROC(TexParameteriv); 641 GET_PROC(TexSubImage2D); 642 643 if (version >= GR_GL_VER(3,0)) { 644 GET_PROC(TexStorage2D); 645 } else { 646 GET_PROC_SUFFIX(TexStorage2D, EXT); 647 } 648 649 if (extensions.has("GL_NV_texture_barrier")) { 650 GET_PROC_SUFFIX(TextureBarrier, NV); 651 } 652 653 GET_PROC_SUFFIX(DiscardFramebuffer, EXT); 654 GET_PROC(Uniform1f); 655 GET_PROC(Uniform1i); 656 GET_PROC(Uniform1fv); 657 GET_PROC(Uniform1iv); 658 GET_PROC(Uniform2f); 659 GET_PROC(Uniform2i); 660 GET_PROC(Uniform2fv); 661 GET_PROC(Uniform2iv); 662 GET_PROC(Uniform3f); 663 GET_PROC(Uniform3i); 664 GET_PROC(Uniform3fv); 665 GET_PROC(Uniform3iv); 666 GET_PROC(Uniform4f); 667 GET_PROC(Uniform4i); 668 GET_PROC(Uniform4fv); 669 GET_PROC(Uniform4iv); 670 GET_PROC(UniformMatrix2fv); 671 GET_PROC(UniformMatrix3fv); 672 GET_PROC(UniformMatrix4fv); 673 GET_PROC(UseProgram); 674 GET_PROC(VertexAttrib1f); 675 GET_PROC(VertexAttrib2fv); 676 GET_PROC(VertexAttrib3fv); 677 GET_PROC(VertexAttrib4fv); 678 679 if (version >= GR_GL_VER(3,0)) { 680 GET_PROC(VertexAttribDivisor); 681 } else if (extensions.has("GL_EXT_instanced_arrays")) { 682 GET_PROC_SUFFIX(VertexAttribDivisor, EXT); 683 } 684 685 if (version >= GR_GL_VER(3,0)) { 686 GET_PROC(VertexAttribIPointer); 687 } 688 689 GET_PROC(VertexAttribPointer); 690 GET_PROC(Viewport); 691 GET_PROC(BindFramebuffer); 692 GET_PROC(BindRenderbuffer); 693 GET_PROC(CheckFramebufferStatus); 694 GET_PROC(DeleteFramebuffers); 695 GET_PROC(DeleteRenderbuffers); 696 GET_PROC(FramebufferRenderbuffer); 697 GET_PROC(FramebufferTexture2D); 698 699 if (extensions.has("GL_CHROMIUM_framebuffer_multisample")) { 700 GET_PROC_SUFFIX(RenderbufferStorageMultisample, CHROMIUM); 701 GET_PROC_SUFFIX(BlitFramebuffer, CHROMIUM); 702 } else if (version >= GR_GL_VER(3,0)) { 703 GET_PROC(RenderbufferStorageMultisample); 704 GET_PROC(BlitFramebuffer); 705 } 706 707 if (extensions.has("GL_CHROMIUM_map_sub")) { 708 GET_PROC_SUFFIX(MapBufferSubData, CHROMIUM); 709 GET_PROC_SUFFIX(MapTexSubImage2D, CHROMIUM); 710 GET_PROC_SUFFIX(UnmapBufferSubData, CHROMIUM); 711 GET_PROC_SUFFIX(UnmapTexSubImage2D, CHROMIUM); 712 } 713 714 if (extensions.has("GL_EXT_multisampled_render_to_texture")) { 715 GET_PROC_SUFFIX(FramebufferTexture2DMultisample, EXT); 716 functions->fRenderbufferStorageMultisampleES2EXT = (GrGLRenderbufferStorageMultisampleProc) get(ctx, "glRenderbufferStorageMultisampleEXT"); 717 } else if (extensions.has("GL_IMG_multisampled_render_to_texture")) { 718 GET_PROC_SUFFIX(FramebufferTexture2DMultisample, IMG); 719 functions->fRenderbufferStorageMultisampleES2EXT = (GrGLRenderbufferStorageMultisampleProc) get(ctx, "glRenderbufferStorageMultisampleIMG"); 720 } else if (extensions.has("GL_APPLE_framebuffer_multisample")) { 721 functions->fRenderbufferStorageMultisampleES2APPLE = (GrGLRenderbufferStorageMultisampleProc) get(ctx, "glRenderbufferStorageMultisampleAPPLE"); 722 GET_PROC_SUFFIX(ResolveMultisampleFramebuffer, APPLE); 723 } 724 725 GET_PROC(GenFramebuffers); 726 GET_PROC(GenRenderbuffers); 727 GET_PROC(GetFramebufferAttachmentParameteriv); 728 GET_PROC(GetRenderbufferParameteriv); 729 GET_PROC(RenderbufferStorage); 730 731 GET_PROC_SUFFIX(MapBuffer, OES); 732 GET_PROC_SUFFIX(UnmapBuffer, OES); 733 734 if (version >= GR_GL_VER(3,0)) { 735 GET_PROC(MapBufferRange); 736 GET_PROC(FlushMappedBufferRange); 737 } else if (extensions.has("GL_EXT_map_buffer_range")) { 738 GET_PROC_SUFFIX(MapBufferRange, EXT); 739 GET_PROC_SUFFIX(FlushMappedBufferRange, EXT); 740 } 741 742 if (extensions.has("GL_EXT_debug_marker")) { 743 GET_PROC(InsertEventMarker); 744 GET_PROC(PushGroupMarker); 745 GET_PROC(PopGroupMarker); 746 // The below check is here because a device has been found that has the extension string but 747 // returns nullptr from the eglGetProcAddress for the functions 748 if (nullptr == functions->fInsertEventMarker || 749 nullptr == functions->fPushGroupMarker || 750 nullptr == functions->fPopGroupMarker) { 751 extensions.remove("GL_EXT_debug_marker"); 752 } 753 } 754 755 GET_PROC(InvalidateFramebuffer); 756 GET_PROC(InvalidateSubFramebuffer); 757 GET_PROC(InvalidateBufferData); 758 GET_PROC(InvalidateBufferSubData); 759 GET_PROC(InvalidateTexImage); 760 GET_PROC(InvalidateTexSubImage); 761 762 if (version >= GR_GL_VER(3,1)) { 763 GET_PROC(GetProgramResourceLocation); 764 } 765 766 if (extensions.has("GL_NV_path_rendering")) { 767 GET_PROC_SUFFIX(MatrixLoadf, EXT); 768 GET_PROC_SUFFIX(MatrixLoadIdentity, EXT); 769 GET_PROC_SUFFIX(PathCommands, NV); 770 GET_PROC_SUFFIX(PathParameteri, NV); 771 GET_PROC_SUFFIX(PathParameterf, NV); 772 GET_PROC_SUFFIX(GenPaths, NV); 773 GET_PROC_SUFFIX(DeletePaths, NV); 774 GET_PROC_SUFFIX(IsPath, NV); 775 GET_PROC_SUFFIX(PathStencilFunc, NV); 776 GET_PROC_SUFFIX(StencilFillPath, NV); 777 GET_PROC_SUFFIX(StencilStrokePath, NV); 778 GET_PROC_SUFFIX(StencilFillPathInstanced, NV); 779 GET_PROC_SUFFIX(StencilStrokePathInstanced, NV); 780 GET_PROC_SUFFIX(CoverFillPath, NV); 781 GET_PROC_SUFFIX(CoverStrokePath, NV); 782 GET_PROC_SUFFIX(CoverFillPathInstanced, NV); 783 GET_PROC_SUFFIX(CoverStrokePathInstanced, NV); 784 GET_PROC_SUFFIX(StencilThenCoverFillPath, NV); 785 GET_PROC_SUFFIX(StencilThenCoverStrokePath, NV); 786 GET_PROC_SUFFIX(StencilThenCoverFillPathInstanced, NV); 787 GET_PROC_SUFFIX(StencilThenCoverStrokePathInstanced, NV); 788 GET_PROC_SUFFIX(ProgramPathFragmentInputGen, NV); 789 } 790 791 if (extensions.has("GL_CHROMIUM_path_rendering")) { 792 GET_PROC_SUFFIX(MatrixLoadf, CHROMIUM); 793 GET_PROC_SUFFIX(MatrixLoadIdentity, CHROMIUM); 794 GET_PROC_SUFFIX(PathCommands, CHROMIUM); 795 GET_PROC_SUFFIX(PathParameteri, CHROMIUM); 796 GET_PROC_SUFFIX(PathParameterf, CHROMIUM); 797 GET_PROC_SUFFIX(GenPaths, CHROMIUM); 798 GET_PROC_SUFFIX(DeletePaths, CHROMIUM); 799 GET_PROC_SUFFIX(IsPath, CHROMIUM); 800 GET_PROC_SUFFIX(PathStencilFunc, CHROMIUM); 801 GET_PROC_SUFFIX(StencilFillPath, CHROMIUM); 802 GET_PROC_SUFFIX(StencilStrokePath, CHROMIUM); 803 GET_PROC_SUFFIX(StencilFillPathInstanced, CHROMIUM); 804 GET_PROC_SUFFIX(StencilStrokePathInstanced, CHROMIUM); 805 GET_PROC_SUFFIX(CoverFillPath, CHROMIUM); 806 GET_PROC_SUFFIX(CoverStrokePath, CHROMIUM); 807 GET_PROC_SUFFIX(CoverFillPathInstanced, CHROMIUM); 808 GET_PROC_SUFFIX(CoverStrokePathInstanced, CHROMIUM); 809 GET_PROC_SUFFIX(StencilThenCoverFillPath, CHROMIUM); 810 GET_PROC_SUFFIX(StencilThenCoverStrokePath, CHROMIUM); 811 GET_PROC_SUFFIX(StencilThenCoverFillPathInstanced, CHROMIUM); 812 GET_PROC_SUFFIX(StencilThenCoverStrokePathInstanced, CHROMIUM); 813 GET_PROC_SUFFIX(ProgramPathFragmentInputGen, CHROMIUM); 814 // GL_CHROMIUM_path_rendering additions: 815 GET_PROC_SUFFIX(BindFragmentInputLocation, CHROMIUM); 816 } 817 818 if (extensions.has("GL_NV_framebuffer_mixed_samples")) { 819 GET_PROC_SUFFIX(CoverageModulation, NV); 820 } 821 if (extensions.has("GL_CHROMIUM_framebuffer_mixed_samples")) { 822 GET_PROC_SUFFIX(CoverageModulation, CHROMIUM); 823 } 824 825 if (extensions.has("GL_EXT_multi_draw_indirect")) { 826 GET_PROC_SUFFIX(MultiDrawArraysIndirect, EXT); 827 GET_PROC_SUFFIX(MultiDrawElementsIndirect, EXT); 828 } 829 830 if (extensions.has("GL_NV_bindless_texture")) { 831 GET_PROC_SUFFIX(GetTextureHandle, NV); 832 GET_PROC_SUFFIX(GetTextureSamplerHandle, NV); 833 GET_PROC_SUFFIX(MakeTextureHandleResident, NV); 834 GET_PROC_SUFFIX(MakeTextureHandleNonResident, NV); 835 GET_PROC_SUFFIX(GetImageHandle, NV); 836 GET_PROC_SUFFIX(MakeImageHandleResident, NV); 837 GET_PROC_SUFFIX(MakeImageHandleNonResident, NV); 838 GET_PROC_SUFFIX(IsTextureHandleResident, NV); 839 GET_PROC_SUFFIX(IsImageHandleResident, NV); 840 GET_PROC_SUFFIX(UniformHandleui64, NV); 841 GET_PROC_SUFFIX(UniformHandleui64v, NV); 842 GET_PROC_SUFFIX(ProgramUniformHandleui64, NV); 843 GET_PROC_SUFFIX(ProgramUniformHandleui64v, NV); 844 } 845 846 if (extensions.has("GL_KHR_debug")) { 847 GET_PROC_SUFFIX(DebugMessageControl, KHR); 848 GET_PROC_SUFFIX(DebugMessageInsert, KHR); 849 GET_PROC_SUFFIX(DebugMessageCallback, KHR); 850 GET_PROC_SUFFIX(GetDebugMessageLog, KHR); 851 GET_PROC_SUFFIX(PushDebugGroup, KHR); 852 GET_PROC_SUFFIX(PopDebugGroup, KHR); 853 GET_PROC_SUFFIX(ObjectLabel, KHR); 854 // In general we have a policy against removing extension strings when the driver does 855 // not provide function pointers for an advertised extension. However, because there is a 856 // known device that advertises GL_KHR_debug but fails to provide the functions and this is 857 // a debugging- only extension we've made an exception. This also can happen when using 858 // APITRACE. 859 if (!interface->fFunctions.fDebugMessageControl) { 860 extensions.remove("GL_KHR_debug"); 861 } 862 } 863 864 if (extensions.has("GL_CHROMIUM_bind_uniform_location")) { 865 GET_PROC_SUFFIX(BindUniformLocation, CHROMIUM); 866 } 867 868 if (extensions.has("EGL_KHR_image") || extensions.has("EGL_KHR_image_base")) { 869 GET_EGL_PROC_SUFFIX(CreateImage, KHR); 870 GET_EGL_PROC_SUFFIX(DestroyImage, KHR); 871 } 872 873 interface->fStandard = kGLES_GrGLStandard; 874 interface->fExtensions.swap(&extensions); 875 876 return interface; 877 } 878