Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: src/gpu/gl/GrGLCaps.cpp

Issue 1535153002: Move config table to GrGLCaps from GrGLGpu. (Closed) Base URL: https://skia.googlesource.com/skia.git@rmc2glf
Patch Set: Address comments Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/gl/GrGLCaps.h ('k') | src/gpu/gl/GrGLGpu.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #include "GrGLCaps.h" 9 #include "GrGLCaps.h"
10 10
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 version >= GR_GL_VER(3, 0) || 476 version >= GR_GL_VER(3, 0) ||
477 (ctxInfo.hasExtension("GL_EXT_draw_instanced") && 477 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
478 ctxInfo.hasExtension("GL_EXT_instanced_arrays")); 478 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
479 } 479 }
480 480
481 this->initConfigTexturableTable(ctxInfo, gli, srgbSupport); 481 this->initConfigTexturableTable(ctxInfo, gli, srgbSupport);
482 this->initConfigRenderableTable(ctxInfo, srgbSupport); 482 this->initConfigRenderableTable(ctxInfo, srgbSupport);
483 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps); 483 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
484 // Requires fTexutreSwizzleSupport and fTextureRedSupport to be set before t his point. 484 // Requires fTexutreSwizzleSupport and fTextureRedSupport to be set before t his point.
485 this->initConfigSwizzleTable(ctxInfo, glslCaps); 485 this->initConfigSwizzleTable(ctxInfo, glslCaps);
486 // Requires various members are already correctly initialized (e.g. fTexture RedSupport).
487 this->initConfigTable(ctxInfo);
486 488
487 this->applyOptionsOverrides(contextOptions); 489 this->applyOptionsOverrides(contextOptions);
488 glslCaps->applyOptionsOverrides(contextOptions); 490 glslCaps->applyOptionsOverrides(contextOptions);
489 } 491 }
490 492
491 const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation, 493 const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
492 bool isCoreProfile) { 494 bool isCoreProfile) {
493 switch (generation) { 495 switch (generation) {
494 case k110_GrGLSLGeneration: 496 case k110_GrGLSLGeneration:
495 if (kGLES_GrGLStandard == standard) { 497 if (kGLES_GrGLStandard == standard) {
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true; 719 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
718 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true; 720 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
719 } 721 }
720 722
721 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) { 723 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
722 // On iOS, BGRA is not supported as a renderable target on ES 3.0+ 724 // On iOS, BGRA is not supported as a renderable target on ES 3.0+
723 if (!ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888") || 725 if (!ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888") ||
724 ctxInfo.version() < GR_GL_VER(3,0)) { 726 ctxInfo.version() < GR_GL_VER(3,0)) {
725 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true; 727 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
726 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of 728 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
727 // configs that are color-renderable and can be passed to glRenderBu fferStorageMultisample. 729 // configs that are color-renderable and can be passed to
728 // Chromium may have an extension to allow BGRA renderbuffers to wor k on desktop platforms. 730 // glRenderBufferStorageMultisample. Chromium may have an extension to allow BGRA
731 // renderbuffers to work on desktop platforms.
729 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") ) { 732 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") ) {
730 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true ; 733 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true ;
731 } else { 734 } else {
732 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = 735 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
733 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers(); 736 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
734 } 737 }
735 } 738 }
736 } 739 }
737 740
738 if (this->fRGBA8RenderbufferSupport && srgbSupport) { 741 if (this->fRGBA8RenderbufferSupport && srgbSupport) {
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 glslCaps->fConfigSwizzle[kSRGBA_8888_GrPixelConfig] = "rgba"; 1340 glslCaps->fConfigSwizzle[kSRGBA_8888_GrPixelConfig] = "rgba";
1338 glslCaps->fConfigSwizzle[kETC1_GrPixelConfig] = "rgba"; 1341 glslCaps->fConfigSwizzle[kETC1_GrPixelConfig] = "rgba";
1339 glslCaps->fConfigSwizzle[kLATC_GrPixelConfig] = "rrrr"; 1342 glslCaps->fConfigSwizzle[kLATC_GrPixelConfig] = "rrrr";
1340 glslCaps->fConfigSwizzle[kR11_EAC_GrPixelConfig] = "rrrr"; 1343 glslCaps->fConfigSwizzle[kR11_EAC_GrPixelConfig] = "rrrr";
1341 glslCaps->fConfigSwizzle[kASTC_12x12_GrPixelConfig] = "rgba"; 1344 glslCaps->fConfigSwizzle[kASTC_12x12_GrPixelConfig] = "rgba";
1342 glslCaps->fConfigSwizzle[kRGBA_float_GrPixelConfig] = "rgba"; 1345 glslCaps->fConfigSwizzle[kRGBA_float_GrPixelConfig] = "rgba";
1343 glslCaps->fConfigSwizzle[kRGBA_half_GrPixelConfig] = "rgba"; 1346 glslCaps->fConfigSwizzle[kRGBA_half_GrPixelConfig] = "rgba";
1344 1347
1345 } 1348 }
1346 1349
1350 void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo) {
1351 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1352 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
1353 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat = 0;
1354 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
1355
1356 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ RGBA;
1357 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL _RGBA8;
1358 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat = GR_GL_RGBA ;
1359 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGN ED_BYTE;
1360
1361 if (this->bgraIsInternalFormat()) {
1362 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR _GL_BGRA;
1363 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = G R_GL_BGRA8;
1364 } else {
1365 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR _GL_RGBA;
1366 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = G R_GL_RGBA8;
1367 }
1368 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat= GR_GL_BGRA;
1369 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIG NED_BYTE;
1370
1371
1372 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL _SRGB_ALPHA;
1373 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_G L_SRGB8_ALPHA8;
1374 // GL does not do srgb<->rgb conversions when transferring between cpu and g pu. Thus, the
1375 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub] Image.
1376 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat = GR_GL_RGB A;
1377 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIG NED_BYTE;
1378
1379
1380 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RG B;
1381 if (this->ES2CompatibilitySupport()) {
1382 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_ GL_RGB565;
1383 } else {
1384 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_ GL_RGB5;
1385 }
1386 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat = GR_GL_RGB;
1387 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED _SHORT_5_6_5;
1388
1389 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ RGBA;
1390 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL _RGBA4;
1391 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat = GR_GL_RGBA ;
1392 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGN ED_SHORT_4_4_4_4;
1393
1394
1395 if (this->textureRedSupport()) {
1396 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_G L_RED;
1397 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_ GL_R8;
1398 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat = GR_GL_RE D;
1399 } else {
1400 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_G L_ALPHA;
1401 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_ GL_ALPHA8;
1402 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat = GR_GL_AL PHA;
1403 }
1404 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED _BYTE;
1405
1406 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL _RGBA;
1407 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fSizedInternalFormat = GR_G L_RGBA32F;
1408 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalFormat = GR_GL_RGB A;
1409 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalType = GR_GL_FLOAT ;
1410
1411 if (this->textureRedSupport()) {
1412 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = G R_GL_RED;
1413 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
1414 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat = GR_GL _RED;
1415 } else {
1416 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = G R_GL_ALPHA;
1417 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
1418 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat = GR_GL _ALPHA;
1419 }
1420 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER (3, 0)) {
1421 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_H ALF_FLOAT;
1422 } else {
1423 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_H ALF_FLOAT_OES;
1424 }
1425
1426 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ RGBA;
1427 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL _RGBA16F;
1428 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat = GR_GL_RGBA ;
1429 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER (3, 0)) {
1430 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HA LF_FLOAT;
1431 } else {
1432 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HA LF_FLOAT_OES;
1433 }
1434
1435 // No sized/unsized internal format distinction for compressed formats, no e xternal format.
1436
1437 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_PA LETTE8_RGBA8;
1438 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_P ALETTE8_RGBA8;
1439 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalFormat = 0;
1440 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalType = 0;
1441
1442 switch(this->latcAlias()) {
1443 case GrGLCaps::kLATC_LATCAlias:
1444 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1445 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1446 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1447 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1448 break;
1449 case GrGLCaps::kRGTC_LATCAlias:
1450 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1451 GR_GL_COMPRESSED_RED_RGTC1;
1452 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1453 GR_GL_COMPRESSED_RED_RGTC1;
1454 break;
1455 case GrGLCaps::k3DC_LATCAlias:
1456 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_ GL_COMPRESSED_3DC_X;
1457 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1458 GR_GL_COMPRESSED_3DC_X;
1459 break;
1460 }
1461 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalFormat = 0;
1462 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalType = 0;
1463
1464 fConfigTable[kETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPR ESSED_ETC1_RGB8;
1465 fConfigTable[kETC1_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMP RESSED_ETC1_RGB8;
1466 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalFormat = 0;
1467 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalType = 0;
1468
1469 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_CO MPRESSED_R11_EAC;
1470 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_C OMPRESSED_R11_EAC;
1471 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalFormat = 0;
1472 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalType = 0;
1473
1474 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fBaseInternalFormat =
1475 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1476 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fSizedInternalFormat =
1477 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1478 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalFormat = 0;
1479 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalType = 0;
1480
1481 // Bulk populate the texture internal/external formats here and then deal wi th exceptions below.
1482
1483 // ES 2.0 requires that the internal/external formats match.
1484 bool useSizedFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1485 ctxInfo.version() >= GR_GL_VER(3,0));
1486 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1487 // Almost always we want to pass fExternalFormat as the <format> param t o glTex[Sub]Image.
1488 fConfigTable[i].fFormats.fExternalFormatForTexImage =
1489 fConfigTable[i].fFormats.fExternalFormat;
1490 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedFormats ?
1491 fConfigTable[i].fFormats.fSizedInternalFormat :
1492 fConfigTable[i].fFormats.fBaseInternalFormat;
1493 }
1494 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the < format>
1495 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1496 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1497 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1498 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_V ER(2,0)) {
1499 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormatForTexIm age =
1500 GR_GL_SRGB_ALPHA;
1501 }
1502
1503 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1504 // as a base format.
1505 // GL_EXT_texture_format_BGRA8888:
1506 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1507 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1508 // formats.
1509 // GL_APPLE_texture_format_BGRA8888:
1510 // ES 2.0: the extension makes BGRA an external format but not an intern al format.
1511 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid inter nal format for
1512 // glTexImage (just for glTexStorage).
1513 if (useSizedFormats && this->bgraIsInternalFormat()) {
1514 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1515 }
1516
1517 #ifdef SK_DEBUG
1518 // Make sure we initialized everything.
1519 ConfigFormats defaultEntry;
1520 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1521 SkASSERT(defaultEntry.fBaseInternalFormat != fConfigTable[i].fFormats.fB aseInternalFormat);
1522 SkASSERT(defaultEntry.fSizedInternalFormat !=
1523 fConfigTable[i].fFormats.fSizedInternalFormat);
1524 SkASSERT(defaultEntry.fExternalFormat != fConfigTable[i].fFormats.fExter nalFormat);
1525 SkASSERT(defaultEntry.fExternalType != fConfigTable[i].fFormats.fExterna lType);
1526 }
1527 #endif
1528 }
1529
1347 void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {} 1530 void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}
1348 1531
1349 1532
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLCaps.h ('k') | src/gpu/gl/GrGLGpu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698