OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "GrGLAssembleInterface.h" | 10 #include "GrGLAssembleInterface.h" |
11 #include "GrGLUtil.h" | 11 #include "GrGLUtil.h" |
12 | 12 |
13 #define GET_PROC(F) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F) | 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) | 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) | 15 #define GET_PROC_LOCAL(F) GrGL ## F ## Proc F = (GrGL ## F ## Proc) get(ctx, "gl
" #F) |
16 | 16 |
| 17 const GrGLInterface* GrGLAssembleInterface(void* ctx, GrGLGetProc get) { |
| 18 GET_PROC_LOCAL(GetString); |
| 19 if (NULL == GetString) { |
| 20 return NULL; |
| 21 } |
| 22 |
| 23 const char* verStr = reinterpret_cast<const char*>(GetString(GR_GL_VERSION))
; |
| 24 if (NULL == verStr) { |
| 25 return NULL; |
| 26 } |
| 27 |
| 28 GrGLStandard standard = GrGLGetStandardInUseFromString(verStr); |
| 29 |
| 30 if (kGLES_GrGLStandard == standard) { |
| 31 return GrGLAssembleGLESInterface(ctx, get); |
| 32 } else if (kGL_GrGLStandard == standard) { |
| 33 return GrGLAssembleGLInterface(ctx, get); |
| 34 } |
| 35 return NULL; |
| 36 } |
| 37 |
17 const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) { | 38 const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) { |
18 GET_PROC_LOCAL(GetString); | 39 GET_PROC_LOCAL(GetString); |
19 GET_PROC_LOCAL(GetStringi); | 40 GET_PROC_LOCAL(GetStringi); |
20 GET_PROC_LOCAL(GetIntegerv); | 41 GET_PROC_LOCAL(GetIntegerv); |
21 | 42 |
22 // GetStringi may be NULL depending on the GL version. | 43 // GetStringi may be NULL depending on the GL version. |
23 if (NULL == GetString || NULL == GetIntegerv) { | 44 if (NULL == GetString || NULL == GetIntegerv) { |
24 return NULL; | 45 return NULL; |
25 } | 46 } |
26 | 47 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 286 |
266 if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_program_interface_quer
y")) { | 287 if (glVer >= GR_GL_VER(4,3) || extensions.has("GL_ARB_program_interface_quer
y")) { |
267 GET_PROC(GetProgramResourceLocation); | 288 GET_PROC(GetProgramResourceLocation); |
268 } | 289 } |
269 | 290 |
270 interface->fStandard = kGL_GrGLStandard; | 291 interface->fStandard = kGL_GrGLStandard; |
271 interface->fExtensions.swap(&extensions); | 292 interface->fExtensions.swap(&extensions); |
272 | 293 |
273 return interface; | 294 return interface; |
274 } | 295 } |
| 296 |
| 297 const GrGLInterface* GrGLAssembleGLESInterface(void* ctx, GrGLGetProc get) { |
| 298 GET_PROC_LOCAL(GetString); |
| 299 if (NULL == GetString) { |
| 300 return NULL; |
| 301 } |
| 302 |
| 303 const char* verStr = reinterpret_cast<const char*>(GetString(GR_GL_VERSION))
; |
| 304 GrGLVersion version = GrGLGetVersionFromString(verStr); |
| 305 |
| 306 if (version < GR_GL_VER(2,0)) { |
| 307 return NULL; |
| 308 } |
| 309 |
| 310 GET_PROC_LOCAL(GetIntegerv); |
| 311 GET_PROC_LOCAL(GetStringi); |
| 312 GrGLExtensions extensions; |
| 313 if (!extensions.init(kGLES_GrGLStandard, GetString, GetStringi, GetIntegerv)
) { |
| 314 return NULL; |
| 315 } |
| 316 |
| 317 GrGLInterface* interface = SkNEW(GrGLInterface); |
| 318 GrGLInterface::Functions* functions = &interface->fFunctions; |
| 319 |
| 320 GET_PROC(ActiveTexture); |
| 321 GET_PROC(AttachShader); |
| 322 GET_PROC(BindAttribLocation); |
| 323 GET_PROC(BindBuffer); |
| 324 GET_PROC(BindTexture); |
| 325 GET_PROC_SUFFIX(BindVertexArray, OES); |
| 326 GET_PROC(BlendColor); |
| 327 GET_PROC(BlendFunc); |
| 328 GET_PROC(BufferData); |
| 329 GET_PROC(BufferSubData); |
| 330 GET_PROC(Clear); |
| 331 GET_PROC(ClearColor); |
| 332 GET_PROC(ClearStencil); |
| 333 GET_PROC(ColorMask); |
| 334 GET_PROC(CompileShader); |
| 335 GET_PROC(CompressedTexImage2D); |
| 336 GET_PROC(CompressedTexSubImage2D); |
| 337 GET_PROC(CopyTexSubImage2D); |
| 338 GET_PROC(CreateProgram); |
| 339 GET_PROC(CreateShader); |
| 340 GET_PROC(CullFace); |
| 341 GET_PROC(DeleteBuffers); |
| 342 GET_PROC(DeleteProgram); |
| 343 GET_PROC(DeleteShader); |
| 344 GET_PROC(DeleteTextures); |
| 345 GET_PROC_SUFFIX(DeleteVertexArrays, OES); |
| 346 GET_PROC(DepthMask); |
| 347 GET_PROC(Disable); |
| 348 GET_PROC(DisableVertexAttribArray); |
| 349 GET_PROC(DrawArrays); |
| 350 GET_PROC(DrawElements); |
| 351 GET_PROC(Enable); |
| 352 GET_PROC(EnableVertexAttribArray); |
| 353 GET_PROC(Finish); |
| 354 GET_PROC(Flush); |
| 355 GET_PROC(FrontFace); |
| 356 GET_PROC(GenBuffers); |
| 357 GET_PROC(GenerateMipmap); |
| 358 GET_PROC(GenTextures); |
| 359 GET_PROC_SUFFIX(GenVertexArrays, OES); |
| 360 GET_PROC(GetBufferParameteriv); |
| 361 GET_PROC(GetError); |
| 362 GET_PROC(GetIntegerv); |
| 363 GET_PROC(GetProgramInfoLog); |
| 364 GET_PROC(GetProgramiv); |
| 365 GET_PROC(GetShaderInfoLog); |
| 366 GET_PROC(GetShaderiv); |
| 367 GET_PROC(GetString); |
| 368 GET_PROC(GetStringi); |
| 369 GET_PROC(GetUniformLocation); |
| 370 GET_PROC(LineWidth); |
| 371 GET_PROC(LinkProgram); |
| 372 GET_PROC(PixelStorei); |
| 373 GET_PROC(ReadPixels); |
| 374 GET_PROC(Scissor); |
| 375 GET_PROC(ShaderSource); |
| 376 GET_PROC(StencilFunc); |
| 377 GET_PROC(StencilFuncSeparate); |
| 378 GET_PROC(StencilMask); |
| 379 GET_PROC(StencilMaskSeparate); |
| 380 GET_PROC(StencilOp); |
| 381 GET_PROC(StencilOpSeparate); |
| 382 GET_PROC(TexImage2D); |
| 383 GET_PROC(TexParameteri); |
| 384 GET_PROC(TexParameteriv); |
| 385 GET_PROC(TexSubImage2D); |
| 386 |
| 387 if (version >= GR_GL_VER(3,0)) { |
| 388 GET_PROC(TexStorage2D); |
| 389 } else { |
| 390 GET_PROC_SUFFIX(TexStorage2D, EXT); |
| 391 } |
| 392 |
| 393 GET_PROC_SUFFIX(DiscardFramebuffer, EXT); |
| 394 GET_PROC(Uniform1f); |
| 395 GET_PROC(Uniform1i); |
| 396 GET_PROC(Uniform1fv); |
| 397 GET_PROC(Uniform1iv); |
| 398 GET_PROC(Uniform2f); |
| 399 GET_PROC(Uniform2i); |
| 400 GET_PROC(Uniform2fv); |
| 401 GET_PROC(Uniform2iv); |
| 402 GET_PROC(Uniform3f); |
| 403 GET_PROC(Uniform3i); |
| 404 GET_PROC(Uniform3fv); |
| 405 GET_PROC(Uniform3iv); |
| 406 GET_PROC(Uniform4f); |
| 407 GET_PROC(Uniform4i); |
| 408 GET_PROC(Uniform4fv); |
| 409 GET_PROC(Uniform4iv); |
| 410 GET_PROC(UniformMatrix2fv); |
| 411 GET_PROC(UniformMatrix3fv); |
| 412 GET_PROC(UniformMatrix4fv); |
| 413 GET_PROC(UseProgram); |
| 414 GET_PROC(VertexAttrib4fv); |
| 415 GET_PROC(VertexAttribPointer); |
| 416 GET_PROC(Viewport); |
| 417 GET_PROC(BindFramebuffer); |
| 418 GET_PROC(BindRenderbuffer); |
| 419 GET_PROC(CheckFramebufferStatus); |
| 420 GET_PROC(DeleteFramebuffers); |
| 421 GET_PROC(DeleteRenderbuffers); |
| 422 GET_PROC(FramebufferRenderbuffer); |
| 423 GET_PROC(FramebufferTexture2D); |
| 424 |
| 425 if (version >= GR_GL_VER(3,0)) { |
| 426 GET_PROC(RenderbufferStorageMultisample); |
| 427 GET_PROC(BlitFramebuffer); |
| 428 } |
| 429 |
| 430 if (extensions.has("GL_EXT_multisampled_render_to_texture")) { |
| 431 GET_PROC_SUFFIX(FramebufferTexture2DMultisample, EXT); |
| 432 functions->fRenderbufferStorageMultisampleES2EXT = (GrGLRenderbufferStor
ageMultisampleProc) get(ctx, "glRenderbufferStorageMultisampleEXT"); |
| 433 } else if (extensions.has("GL_IMG_multisampled_render_to_texture")) { |
| 434 GET_PROC_SUFFIX(FramebufferTexture2DMultisample, IMG); |
| 435 functions->fRenderbufferStorageMultisampleES2EXT = (GrGLRenderbufferStor
ageMultisampleProc) get(ctx, "glRenderbufferStorageMultisampleIMG"); |
| 436 } else if (extensions.has("GL_APPLE_framebuffer_multisample")) { |
| 437 functions->fRenderbufferStorageMultisampleES2APPLE = (GrGLRenderbufferSt
orageMultisampleProc) get(ctx, "glRenderbufferStorageMultisampleAPPLE"); |
| 438 GET_PROC_SUFFIX(ResolveMultisampleFramebuffer, APPLE); |
| 439 } |
| 440 |
| 441 GET_PROC(GenFramebuffers); |
| 442 GET_PROC(GenRenderbuffers); |
| 443 GET_PROC(GetFramebufferAttachmentParameteriv); |
| 444 GET_PROC(GetRenderbufferParameteriv); |
| 445 GET_PROC(RenderbufferStorage); |
| 446 |
| 447 GET_PROC_SUFFIX(MapBuffer, OES); |
| 448 GET_PROC_SUFFIX(UnmapBuffer, OES); |
| 449 |
| 450 if (version >= GR_GL_VER(3,0)) { |
| 451 GET_PROC(MapBufferRange); |
| 452 GET_PROC(FlushMappedBufferRange); |
| 453 } else if (extensions.has("GL_EXT_map_buffer_range")) { |
| 454 GET_PROC_SUFFIX(MapBufferRange, EXT); |
| 455 GET_PROC_SUFFIX(FlushMappedBufferRange, EXT); |
| 456 } |
| 457 |
| 458 if (extensions.has("GL_EXT_debug_marker")) { |
| 459 GET_PROC(InsertEventMarker); |
| 460 GET_PROC(PushGroupMarker); |
| 461 GET_PROC(PopGroupMarker); |
| 462 // The below check is here because a device has been found that has the
extension string but |
| 463 // returns NULL from the eglGetProcAddress for the functions |
| 464 if (NULL == functions->fInsertEventMarker || |
| 465 NULL == functions->fPushGroupMarker || |
| 466 NULL == functions->fPopGroupMarker) { |
| 467 extensions.remove("GL_EXT_debug_marker"); |
| 468 } |
| 469 } |
| 470 |
| 471 GET_PROC(InvalidateFramebuffer); |
| 472 GET_PROC(InvalidateSubFramebuffer); |
| 473 GET_PROC(InvalidateBufferData); |
| 474 GET_PROC(InvalidateBufferSubData); |
| 475 GET_PROC(InvalidateTexImage); |
| 476 GET_PROC(InvalidateTexSubImage); |
| 477 |
| 478 if (version >= GR_GL_VER(3,1)) { |
| 479 GET_PROC(GetProgramResourceLocation); |
| 480 } |
| 481 |
| 482 if (extensions.has("GL_NV_path_rendering")) { |
| 483 GET_PROC_SUFFIX(MatrixLoadf, EXT); |
| 484 GET_PROC_SUFFIX(MatrixLoadIdentity, EXT); |
| 485 GET_PROC_SUFFIX(PathCommands, NV); |
| 486 GET_PROC_SUFFIX(PathCoords, NV); |
| 487 GET_PROC_SUFFIX(PathParameteri, NV); |
| 488 GET_PROC_SUFFIX(PathParameterf, NV); |
| 489 GET_PROC_SUFFIX(GenPaths, NV); |
| 490 GET_PROC_SUFFIX(DeletePaths, NV); |
| 491 GET_PROC_SUFFIX(IsPath, NV); |
| 492 GET_PROC_SUFFIX(PathStencilFunc, NV); |
| 493 GET_PROC_SUFFIX(StencilFillPath, NV); |
| 494 GET_PROC_SUFFIX(StencilStrokePath, NV); |
| 495 GET_PROC_SUFFIX(StencilFillPathInstanced, NV); |
| 496 GET_PROC_SUFFIX(StencilStrokePathInstanced, NV); |
| 497 GET_PROC_SUFFIX(CoverFillPath, NV); |
| 498 GET_PROC_SUFFIX(CoverStrokePath, NV); |
| 499 GET_PROC_SUFFIX(CoverFillPathInstanced, NV); |
| 500 GET_PROC_SUFFIX(CoverStrokePathInstanced, NV); |
| 501 GET_PROC_SUFFIX(StencilThenCoverFillPath, NV); |
| 502 GET_PROC_SUFFIX(StencilThenCoverStrokePath, NV); |
| 503 GET_PROC_SUFFIX(StencilThenCoverFillPathInstanced, NV); |
| 504 GET_PROC_SUFFIX(StencilThenCoverStrokePathInstanced, NV); |
| 505 GET_PROC_SUFFIX(ProgramPathFragmentInputGen, NV); |
| 506 } |
| 507 |
| 508 interface->fStandard = kGLES_GrGLStandard; |
| 509 interface->fExtensions.swap(&extensions); |
| 510 |
| 511 return interface; |
| 512 } |
OLD | NEW |