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