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

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

Issue 580863004: Adding 3D lut color filter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Added generationID for 3D texture key Created 6 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 "GrGpuGL.h" 9 #include "GrGpuGL.h"
10 #include "GrGLStencilBuffer.h" 10 #include "GrGLStencilBuffer.h"
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 bool GrGpuGL::onWriteTexturePixels(GrTexture* texture, 463 bool GrGpuGL::onWriteTexturePixels(GrTexture* texture,
464 int left, int top, int width, int height, 464 int left, int top, int width, int height,
465 GrPixelConfig config, const void* buffer, 465 GrPixelConfig config, const void* buffer,
466 size_t rowBytes) { 466 size_t rowBytes) {
467 if (NULL == buffer) { 467 if (NULL == buffer) {
468 return false; 468 return false;
469 } 469 }
470 GrGLTexture* glTex = static_cast<GrGLTexture*>(texture); 470 GrGLTexture* glTex = static_cast<GrGLTexture*>(texture);
471 471
472 this->setScratchTextureUnit(); 472 this->setScratchTextureUnit();
473 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTex->textureID()));
474 GrGLTexture::Desc desc; 473 GrGLTexture::Desc desc;
475 desc.fFlags = glTex->desc().fFlags; 474 desc.fFlags = glTex->desc().fFlags;
476 desc.fWidth = glTex->width(); 475 desc.fWidth = glTex->width();
477 desc.fHeight = glTex->height(); 476 desc.fHeight = glTex->height();
477 desc.fDepth = glTex->desc().fDepth;
478 desc.fConfig = glTex->config(); 478 desc.fConfig = glTex->config();
479 desc.fSampleCnt = glTex->desc().fSampleCnt; 479 desc.fSampleCnt = glTex->desc().fSampleCnt;
480 desc.fTextureID = glTex->textureID(); 480 desc.fTextureID = glTex->textureID();
481 desc.fOrigin = glTex->origin(); 481 desc.fOrigin = glTex->origin();
482 GL_CALL(BindTexture((desc.fDepth > 0) ? GR_GL_TEXTURE_3D : GR_GL_TEXTURE_2D, desc.fTextureID));
482 483
483 bool success = false; 484 bool success = false;
484 if (GrPixelConfigIsCompressed(desc.fConfig)) { 485 if (GrPixelConfigIsCompressed(desc.fConfig)) {
485 // We check that config == desc.fConfig in GrGpuGL::canWriteTexturePixel s() 486 // We check that config == desc.fConfig in GrGpuGL::canWriteTexturePixel s()
486 SkASSERT(config == desc.fConfig); 487 SkASSERT(config == desc.fConfig);
487 success = this->uploadCompressedTexData(desc, buffer, false, 488 success = this->uploadCompressedTexData(desc, buffer, false,
488 left, top, width, height); 489 left, top, width, height);
489 } else { 490 } else {
490 success = this->uploadTexData(desc, false, 491 success = this->uploadTexData(desc, false,
491 left, top, width, height, 492 left, top, width, height,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 bool isNewTexture, 542 bool isNewTexture,
542 int left, int top, int width, int height, 543 int left, int top, int width, int height,
543 GrPixelConfig dataConfig, 544 GrPixelConfig dataConfig,
544 const void* data, 545 const void* data,
545 size_t rowBytes) { 546 size_t rowBytes) {
546 SkASSERT(data || isNewTexture); 547 SkASSERT(data || isNewTexture);
547 548
548 // If we're uploading compressed data then we should be using uploadCompress edTexData 549 // If we're uploading compressed data then we should be using uploadCompress edTexData
549 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); 550 SkASSERT(!GrPixelConfigIsCompressed(dataConfig));
550 551
552 bool is3DTexture = (desc.fDepth > 0);
553 if (is3DTexture && !this->glCaps().has3DTexImageSupport()) {
554 return false;
555 }
556
551 size_t bpp = GrBytesPerPixel(dataConfig); 557 size_t bpp = GrBytesPerPixel(dataConfig);
552 if (!adjust_pixel_ops_params(desc.fWidth, desc.fHeight, bpp, &left, &top, 558 if (!adjust_pixel_ops_params(desc.fWidth, desc.fHeight, bpp, &left, &top,
553 &width, &height, &data, &rowBytes)) { 559 &width, &height, &data, &rowBytes)) {
554 return false; 560 return false;
555 } 561 }
556 size_t trimRowBytes = width * bpp; 562 size_t trimRowBytes = width * bpp;
557 563
558 // in case we need a temporary, trimmed copy of the src pixels 564 // in case we need a temporary, trimmed copy of the src pixels
559 GrAutoMalloc<128 * 128> tempStorage; 565 GrAutoMalloc<128 * 128> tempStorage;
560 566
561 // We currently lazily create MIPMAPs when the we see a draw with 567 // We currently lazily create MIPMAPs when the we see a draw with
562 // GrTextureParams::kMipMap_FilterMode. Using texture storage requires that the 568 // GrTextureParams::kMipMap_FilterMode. Using texture storage requires that the
563 // MIP levels are all created when the texture is created. So for now we don 't use 569 // MIP levels are all created when the texture is created. So for now we don 't use
564 // texture storage. 570 // texture storage.
565 bool useTexStorage = false && 571 bool useTexStorage = false &&
566 isNewTexture && 572 isNewTexture && !is3DTexture &&
567 this->glCaps().texStorageSupport(); 573 this->glCaps().texStorageSupport();
bsalomon 2014/09/26 14:23:50 Is texture storage not supported for 3D?
568 574
569 if (useTexStorage && kGL_GrGLStandard == this->glStandard()) { 575 if (useTexStorage && kGL_GrGLStandard == this->glStandard()) {
570 // 565 is not a sized internal format on desktop GL. So on desktop with 576 // 565 is not a sized internal format on desktop GL. So on desktop with
571 // 565 we always use an unsized internal format to let the system pick 577 // 565 we always use an unsized internal format to let the system pick
572 // the best sized format to convert the 565 data to. Since TexStorage 578 // the best sized format to convert the 565 data to. Since TexStorage
573 // only allows sized internal formats we will instead use TexImage2D. 579 // only allows sized internal formats we will instead use TexImage2D.
574 useTexStorage = desc.fConfig != kRGB_565_GrPixelConfig; 580 useTexStorage = desc.fConfig != kRGB_565_GrPixelConfig;
575 } 581 }
576 582
577 GrGLenum internalFormat; 583 GrGLenum internalFormat;
578 GrGLenum externalFormat = 0x0; // suprress warning 584 GrGLenum externalFormat = 0x0; // suppress warning
579 GrGLenum externalType = 0x0;// suprress warning 585 GrGLenum externalType = 0x0;// suppress warning
580 586
581 // glTexStorage requires sized internal formats on both desktop and ES. ES2 requires an unsized 587 // glTexStorage requires sized internal formats on both desktop and ES. ES2 requires an unsized
582 // format for glTexImage, unlike ES3 and desktop. However, we allow the driv er to decide the 588 // format for glTexImage, unlike ES3 and desktop. However, we allow the driv er to decide the
583 // size of the internal format whenever possible and so only use a sized int ernal format when 589 // size of the internal format whenever possible and so only use a sized int ernal format when
584 // using texture storage. 590 // using texture storage.
585 bool useSizedFormat = useTexStorage; 591 bool useSizedFormat = useTexStorage;
586 // At least some versions of the desktop ES3 drivers for NVIDIA won't accept GL_RED in 592 // At least some versions of the desktop ES3 drivers for NVIDIA won't accept GL_RED in
587 // glTexImage2D for the internal format but will accept GL_R8. 593 // glTexImage2D for the internal format but will accept GL_R8.
588 if (!useSizedFormat && kNVIDIA_GrGLVendor == this->glContext().vendor() && 594 if (!useSizedFormat && kNVIDIA_GrGLVendor == this->glContext().vendor() &&
589 kGLES_GrGLStandard == this->glStandard() && this->glVersion() >= GR_GL_V ER(3, 0)) { 595 kGLES_GrGLStandard == this->glStandard() && this->glVersion() >= GR_GL_V ER(3, 0)) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 0 == left && 0 == top && 657 0 == left && 0 == top &&
652 desc.fWidth == width && desc.fHeight == height) { 658 desc.fWidth == width && desc.fHeight == height) {
653 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); 659 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
654 if (useTexStorage) { 660 if (useTexStorage) {
655 // We never resize or change formats of textures. 661 // We never resize or change formats of textures.
656 GL_ALLOC_CALL(this->glInterface(), 662 GL_ALLOC_CALL(this->glInterface(),
657 TexStorage2D(GR_GL_TEXTURE_2D, 663 TexStorage2D(GR_GL_TEXTURE_2D,
658 1, // levels 664 1, // levels
659 internalFormat, 665 internalFormat,
660 desc.fWidth, desc.fHeight)); 666 desc.fWidth, desc.fHeight));
667 } else if (is3DTexture) {
668 GL_ALLOC_CALL(this->glInterface(),
669 TexImage3D(GR_GL_TEXTURE_3D,
670 0, // level
671 internalFormat,
672 desc.fWidth, desc.fHeight, desc.fDepth,
673 0, // border
674 externalFormat, externalType,
675 data));
661 } else { 676 } else {
662 GL_ALLOC_CALL(this->glInterface(), 677 GL_ALLOC_CALL(this->glInterface(),
663 TexImage2D(GR_GL_TEXTURE_2D, 678 TexImage2D(GR_GL_TEXTURE_2D,
664 0, // level 679 0, // level
665 internalFormat, 680 internalFormat,
666 desc.fWidth, desc.fHeight, 681 desc.fWidth, desc.fHeight,
667 0, // border 682 0, // border
668 externalFormat, externalType, 683 externalFormat, externalType,
669 data)); 684 data));
670 } 685 }
671 GrGLenum error = check_alloc_error(desc, this->glInterface()); 686 GrGLenum error = check_alloc_error(desc, this->glInterface());
672 if (error != GR_GL_NO_ERROR) { 687 if (error != GR_GL_NO_ERROR) {
673 succeeded = false; 688 succeeded = false;
674 } else { 689 } else {
675 // if we have data and we used TexStorage to create the texture, we 690 // if we have data and we used TexStorage to create the texture, we
676 // now upload with TexSubImage. 691 // now upload with TexSubImage.
677 if (data && useTexStorage) { 692 if (data && useTexStorage) {
678 GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, 693 if (is3DTexture) {
679 0, // level 694 GL_CALL(TexSubImage3D(GR_GL_TEXTURE_3D,
680 left, top, 695 0, // level,
681 width, height, 696 left, top,
682 externalFormat, externalType, 697 left, // FIXME: left used as Z offset
683 data)); 698 desc.fWidth, desc.fHeight, desc.fDepth ,
699 externalFormat, externalType,
700 data));
701 } else {
702 GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D,
703 0, // level
704 left, top,
705 width, height,
706 externalFormat, externalType,
707 data));
708 }
684 } 709 }
685 } 710 }
686 } else { 711 } else {
687 if (swFlipY || glFlipY) { 712 if (swFlipY || glFlipY) {
688 top = desc.fHeight - (top + height); 713 top = desc.fHeight - (top + height);
689 } 714 }
690 GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, 715 if (is3DTexture) {
691 0, // level 716 GL_CALL(TexSubImage3D(GR_GL_TEXTURE_3D,
692 left, top, 717 0, // level,
693 width, height, 718 left, top,
694 externalFormat, externalType, data)); 719 left, // FIXME: left used as Z offset
720 desc.fWidth, desc.fHeight, desc.fDepth,
721 externalFormat, externalType,
722 data));
723 } else {
724 GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D,
725 0, // level
726 left, top,
727 width, height,
728 externalFormat, externalType, data));
729 }
695 } 730 }
696 731
697 if (restoreGLRowLength) { 732 if (restoreGLRowLength) {
698 SkASSERT(this->glCaps().unpackRowLengthSupport()); 733 SkASSERT(this->glCaps().unpackRowLengthSupport());
699 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); 734 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
700 } 735 }
701 if (glFlipY) { 736 if (glFlipY) {
702 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); 737 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE));
703 } 738 }
704 return succeeded; 739 return succeeded;
(...skipping 30 matching lines...) Expand all
735 SkASSERT(height <= desc.fHeight); 770 SkASSERT(height <= desc.fHeight);
736 } 771 }
737 #endif 772 #endif
738 773
739 // Make sure that the width and height that we pass to OpenGL 774 // Make sure that the width and height that we pass to OpenGL
740 // is a multiple of the block size. 775 // is a multiple of the block size.
741 int dataSize = GrCompressedFormatDataSize(desc.fConfig, width, height); 776 int dataSize = GrCompressedFormatDataSize(desc.fConfig, width, height);
742 777
743 // We only need the internal format for compressed 2D textures. 778 // We only need the internal format for compressed 2D textures.
744 GrGLenum internalFormat = 0; 779 GrGLenum internalFormat = 0;
745 if (!this->configToGLFormats(desc.fConfig, false, &internalFormat, NULL, NUL L)) { 780 if (!this->configToGLFormats(desc.fConfig, false, &internalFormat, NULL, NUL L) ||
781 // Compressed 3D textures not supported
782 (desc.fDepth > 0)) {
746 return false; 783 return false;
747 } 784 }
748 785
749 if (isNewTexture) { 786 if (isNewTexture) {
750 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); 787 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
751 GL_ALLOC_CALL(this->glInterface(), 788 GL_ALLOC_CALL(this->glInterface(),
752 CompressedTexImage2D(GR_GL_TEXTURE_2D, 789 CompressedTexImage2D(GR_GL_TEXTURE_2D,
753 0, // level 790 0, // level
754 internalFormat, 791 internalFormat,
755 width, height, 792 width, height,
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleC nt) { 985 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleC nt) {
949 //GrPrintf("MSAA RT requested but not supported on this platform."); 986 //GrPrintf("MSAA RT requested but not supported on this platform.");
950 return return_null_texture(); 987 return return_null_texture();
951 } 988 }
952 // If the sample count exceeds the max then we clamp it. 989 // If the sample count exceeds the max then we clamp it.
953 glTexDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount( )); 990 glTexDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount( ));
954 991
955 glTexDesc.fFlags = desc.fFlags; 992 glTexDesc.fFlags = desc.fFlags;
956 glTexDesc.fWidth = desc.fWidth; 993 glTexDesc.fWidth = desc.fWidth;
957 glTexDesc.fHeight = desc.fHeight; 994 glTexDesc.fHeight = desc.fHeight;
995 glTexDesc.fDepth = desc.fDepth;
958 glTexDesc.fConfig = desc.fConfig; 996 glTexDesc.fConfig = desc.fConfig;
959 glTexDesc.fIsWrapped = false; 997 glTexDesc.fIsWrapped = false;
960 998
961 glRTDesc.fMSColorRenderbufferID = 0; 999 glRTDesc.fMSColorRenderbufferID = 0;
962 glRTDesc.fRTFBOID = 0; 1000 glRTDesc.fRTFBOID = 0;
963 glRTDesc.fTexFBOID = 0; 1001 glRTDesc.fTexFBOID = 0;
964 glRTDesc.fIsWrapped = false; 1002 glRTDesc.fIsWrapped = false;
965 glRTDesc.fConfig = glTexDesc.fConfig; 1003 glRTDesc.fConfig = glTexDesc.fConfig;
966 glRTDesc.fCheckAllocation = SkToBool(desc.fFlags & kCheckAllocation_GrTextur eFlagBit); 1004 glRTDesc.fCheckAllocation = SkToBool(desc.fFlags & kCheckAllocation_GrTextur eFlagBit);
967 1005
968 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrTextureFlagBit); 1006 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrTextureFlagBit);
969 1007
970 glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); 1008 glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget);
971 glRTDesc.fOrigin = glTexDesc.fOrigin; 1009 glRTDesc.fOrigin = glTexDesc.fOrigin;
972 1010
973 glRTDesc.fSampleCnt = glTexDesc.fSampleCnt; 1011 glRTDesc.fSampleCnt = glTexDesc.fSampleCnt;
974 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && 1012 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() &&
975 desc.fSampleCnt) { 1013 desc.fSampleCnt) {
976 //GrPrintf("MSAA RT requested but not supported on this platform."); 1014 //GrPrintf("MSAA RT requested but not supported on this platform.");
977 return return_null_texture(); 1015 return return_null_texture();
978 } 1016 }
979 1017
980 if (renderTarget) { 1018 if (renderTarget) {
981 int maxRTSize = this->caps()->maxRenderTargetSize(); 1019 int maxRTSize = this->caps()->maxRenderTargetSize();
982 if (glTexDesc.fWidth > maxRTSize || glTexDesc.fHeight > maxRTSize) { 1020 if (glTexDesc.fWidth > maxRTSize || glTexDesc.fHeight > maxRTSize ||
1021 glTexDesc.fDepth > maxRTSize) {
983 return return_null_texture(); 1022 return return_null_texture();
984 } 1023 }
985 } else { 1024 } else {
986 int maxSize = this->caps()->maxTextureSize(); 1025 int maxSize = this->caps()->maxTextureSize();
987 if (glTexDesc.fWidth > maxSize || glTexDesc.fHeight > maxSize) { 1026 if (glTexDesc.fWidth > maxSize || glTexDesc.fHeight > maxSize ||
1027 glTexDesc.fDepth > maxSize) {
988 return return_null_texture(); 1028 return return_null_texture();
989 } 1029 }
990 } 1030 }
991 1031
992 GL_CALL(GenTextures(1, &glTexDesc.fTextureID)); 1032 GL_CALL(GenTextures(1, &glTexDesc.fTextureID));
993 1033
994 if (!glTexDesc.fTextureID) { 1034 if (!glTexDesc.fTextureID) {
995 return return_null_texture(); 1035 return return_null_texture();
996 } 1036 }
997 1037
998 this->setScratchTextureUnit(); 1038 this->setScratchTextureUnit();
999 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTexDesc.fTextureID)); 1039 GrGLenum textureType = (glTexDesc.fDepth > 0) ? GR_GL_TEXTURE_3D : GR_GL_TEX TURE_2D;
1040 GL_CALL(BindTexture(textureType, glTexDesc.fTextureID));
1000 1041
1001 if (renderTarget && this->glCaps().textureUsageSupport()) { 1042 if (renderTarget && this->glCaps().textureUsageSupport()) {
1002 // provides a hint about how this texture will be used 1043 // provides a hint about how this texture will be used
1003 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, 1044 GL_CALL(TexParameteri(textureType,
1004 GR_GL_TEXTURE_USAGE, 1045 GR_GL_TEXTURE_USAGE,
1005 GR_GL_FRAMEBUFFER_ATTACHMENT)); 1046 GR_GL_FRAMEBUFFER_ATTACHMENT));
1006 } 1047 }
1007 1048
1008 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some 1049 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some
1009 // drivers have a bug where an FBO won't be complete if it includes a 1050 // drivers have a bug where an FBO won't be complete if it includes a
1010 // texture that is not mipmap complete (considering the filter in use). 1051 // texture that is not mipmap complete (considering the filter in use).
1011 GrGLTexture::TexParams initialTexParams; 1052 GrGLTexture::TexParams initialTexParams;
1012 // we only set a subset here so invalidate first 1053 // we only set a subset here so invalidate first
1013 initialTexParams.invalidate(); 1054 initialTexParams.invalidate();
1014 initialTexParams.fMinFilter = GR_GL_NEAREST; 1055 initialTexParams.fMinFilter = GR_GL_NEAREST;
1015 initialTexParams.fMagFilter = GR_GL_NEAREST; 1056 initialTexParams.fMagFilter = GR_GL_NEAREST;
1016 initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE; 1057 initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE;
1017 initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE; 1058 initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE;
1018 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, 1059 GL_CALL(TexParameteri(textureType,
1019 GR_GL_TEXTURE_MAG_FILTER, 1060 GR_GL_TEXTURE_MAG_FILTER,
1020 initialTexParams.fMagFilter)); 1061 initialTexParams.fMagFilter));
1021 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, 1062 GL_CALL(TexParameteri(textureType,
1022 GR_GL_TEXTURE_MIN_FILTER, 1063 GR_GL_TEXTURE_MIN_FILTER,
1023 initialTexParams.fMinFilter)); 1064 initialTexParams.fMinFilter));
1024 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, 1065 GL_CALL(TexParameteri(textureType,
1025 GR_GL_TEXTURE_WRAP_S, 1066 GR_GL_TEXTURE_WRAP_S,
1026 initialTexParams.fWrapS)); 1067 initialTexParams.fWrapS));
1027 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, 1068 GL_CALL(TexParameteri(textureType,
1028 GR_GL_TEXTURE_WRAP_T, 1069 GR_GL_TEXTURE_WRAP_T,
1029 initialTexParams.fWrapT)); 1070 initialTexParams.fWrapT));
1071 if (GR_GL_TEXTURE_3D == textureType) {
1072 GL_CALL(TexParameteri(textureType,
1073 GR_GL_TEXTURE_WRAP_R,
1074 initialTexParams.fWrapT));
1075 }
1030 if (!this->uploadTexData(glTexDesc, true, 0, 0, 1076 if (!this->uploadTexData(glTexDesc, true, 0, 0,
1031 glTexDesc.fWidth, glTexDesc.fHeight, 1077 glTexDesc.fWidth, glTexDesc.fHeight,
1032 desc.fConfig, srcData, rowBytes)) { 1078 desc.fConfig, srcData, rowBytes)) {
1033 GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID)); 1079 GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID));
1034 return return_null_texture(); 1080 return return_null_texture();
1035 } 1081 }
1036 1082
1037 GrGLTexture* tex; 1083 GrGLTexture* tex;
1038 if (renderTarget) { 1084 if (renderTarget) {
1039 // unbind the texture from the texture unit before binding it to the fra me buffer 1085 // unbind the texture from the texture unit before binding it to the fra me buffer
1040 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, 0)); 1086 GL_CALL(BindTexture(textureType, 0));
1041 1087
1042 if (!this->createRenderTargetObjects(glTexDesc.fWidth, 1088 if (!this->createRenderTargetObjects(glTexDesc.fWidth,
1043 glTexDesc.fHeight, 1089 glTexDesc.fHeight,
1044 glTexDesc.fTextureID, 1090 glTexDesc.fTextureID,
1045 &glRTDesc)) { 1091 &glRTDesc)) {
1046 GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID)); 1092 GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID));
1047 return return_null_texture(); 1093 return return_null_texture();
1048 } 1094 }
1049 tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc, glRTDesc)); 1095 tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc, glRTDesc));
1050 } else { 1096 } else {
1051 tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc)); 1097 tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc));
1052 } 1098 }
1053 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); 1099 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp());
1054 #ifdef TRACE_TEXTURE_CREATION 1100 #ifdef TRACE_TEXTURE_CREATION
1055 GrPrintf("--- new texture [%d] size=(%d %d) config=%d\n", 1101 GrPrintf("--- new texture [%d] size=(%d %d) config=%d\n",
1056 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); 1102 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig);
1057 #endif 1103 #endif
1058 return tex; 1104 return tex;
1059 } 1105 }
1060 1106
1061 GrTexture* GrGpuGL::onCreateCompressedTexture(const GrTextureDesc& desc, 1107 GrTexture* GrGpuGL::onCreateCompressedTexture(const GrTextureDesc& desc,
1062 const void* srcData) { 1108 const void* srcData) {
1063 1109
1064 if(SkToBool(desc.fFlags & kRenderTarget_GrTextureFlagBit)) { 1110 if(SkToBool(desc.fFlags & kRenderTarget_GrTextureFlagBit) || (desc.fDepth > 0)) {
1065 return return_null_texture(); 1111 return return_null_texture();
1066 } 1112 }
1067 1113
1068 // Make sure that we're not flipping Y. 1114 // Make sure that we're not flipping Y.
1069 GrSurfaceOrigin texOrigin = resolve_origin(desc.fOrigin, false); 1115 GrSurfaceOrigin texOrigin = resolve_origin(desc.fOrigin, false);
1070 if (kBottomLeft_GrSurfaceOrigin == texOrigin) { 1116 if (kBottomLeft_GrSurfaceOrigin == texOrigin) {
1071 return return_null_texture(); 1117 return return_null_texture();
1072 } 1118 }
1073 1119
1074 GrGLTexture::Desc glTexDesc; 1120 GrGLTexture::Desc glTexDesc;
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 SkASSERT(texture); 2062 SkASSERT(texture);
2017 2063
2018 // If we created a rt/tex and rendered to it without using a texture and now we're texturing 2064 // If we created a rt/tex and rendered to it without using a texture and now we're texturing
2019 // from the rt it will still be the last bound texture, but it needs resolvi ng. So keep this 2065 // from the rt it will still be the last bound texture, but it needs resolvi ng. So keep this
2020 // out of the "last != next" check. 2066 // out of the "last != next" check.
2021 GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderT arget()); 2067 GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderT arget());
2022 if (texRT) { 2068 if (texRT) {
2023 this->onResolveRenderTarget(texRT); 2069 this->onResolveRenderTarget(texRT);
2024 } 2070 }
2025 2071
2072 GrGLenum textureType = (texture->desc().fDepth > 0) ? GR_GL_TEXTURE_3D : GR_ GL_TEXTURE_2D;
bsalomon 2014/09/26 14:23:51 Why don't we have GrGLTexture::textureType()? (Act
2073
2026 uint32_t textureID = texture->getUniqueID(); 2074 uint32_t textureID = texture->getUniqueID();
2027 if (fHWBoundTextureUniqueIDs[unitIdx] != textureID) { 2075 if (fHWBoundTextureUniqueIDs[unitIdx] != textureID) {
2028 this->setTextureUnit(unitIdx); 2076 this->setTextureUnit(unitIdx);
2029 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, texture->textureID())); 2077 GL_CALL(BindTexture(textureType, texture->textureID()));
2030 fHWBoundTextureUniqueIDs[unitIdx] = textureID; 2078 fHWBoundTextureUniqueIDs[unitIdx] = textureID;
2031 } 2079 }
2032 2080
2033 ResetTimestamp timestamp; 2081 ResetTimestamp timestamp;
2034 const GrGLTexture::TexParams& oldTexParams = texture->getCachedTexParams(&ti mestamp); 2082 const GrGLTexture::TexParams& oldTexParams = texture->getCachedTexParams(&ti mestamp);
2035 bool setAll = timestamp < this->getResetTimestamp(); 2083 bool setAll = timestamp < this->getResetTimestamp();
2036 GrGLTexture::TexParams newTexParams; 2084 GrGLTexture::TexParams newTexParams;
2037 2085
2038 static GrGLenum glMinFilterModes[] = { 2086 static GrGLenum glMinFilterModes[] = {
2039 GR_GL_NEAREST, 2087 GR_GL_NEAREST,
2040 GR_GL_LINEAR, 2088 GR_GL_LINEAR,
2041 GR_GL_LINEAR_MIPMAP_LINEAR 2089 GR_GL_LINEAR_MIPMAP_LINEAR
2042 }; 2090 };
2043 static GrGLenum glMagFilterModes[] = { 2091 static GrGLenum glMagFilterModes[] = {
2044 GR_GL_NEAREST, 2092 GR_GL_NEAREST,
2045 GR_GL_LINEAR, 2093 GR_GL_LINEAR,
2046 GR_GL_LINEAR 2094 GR_GL_LINEAR
2047 }; 2095 };
2048 GrTextureParams::FilterMode filterMode = params.filterMode(); 2096 GrTextureParams::FilterMode filterMode = params.filterMode();
2049 if (!this->caps()->mipMapSupport() && GrTextureParams::kMipMap_FilterMode == filterMode) { 2097 if (!this->caps()->mipMapSupport() && GrTextureParams::kMipMap_FilterMode == filterMode) {
2050 filterMode = GrTextureParams::kBilerp_FilterMode; 2098 filterMode = GrTextureParams::kBilerp_FilterMode;
2051 } 2099 }
2052 newTexParams.fMinFilter = glMinFilterModes[filterMode]; 2100 newTexParams.fMinFilter = glMinFilterModes[filterMode];
2053 newTexParams.fMagFilter = glMagFilterModes[filterMode]; 2101 newTexParams.fMagFilter = glMagFilterModes[filterMode];
2054 2102
2055 if (GrTextureParams::kMipMap_FilterMode == filterMode && 2103 if (GrTextureParams::kMipMap_FilterMode == filterMode &&
2056 texture->mipMapsAreDirty() && !GrPixelConfigIsCompressed(texture->config ())) { 2104 texture->mipMapsAreDirty() && !GrPixelConfigIsCompressed(texture->config ())) {
2057 GL_CALL(GenerateMipmap(GR_GL_TEXTURE_2D)); 2105 GL_CALL(GenerateMipmap(textureType));
2058 texture->dirtyMipMaps(false); 2106 texture->dirtyMipMaps(false);
2059 } 2107 }
2060 2108
2061 newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX()); 2109 newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX());
2062 newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY()); 2110 newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY());
2063 memcpy(newTexParams.fSwizzleRGBA, 2111 memcpy(newTexParams.fSwizzleRGBA,
2064 GrGLShaderBuilder::GetTexParamSwizzle(texture->config(), this->glCaps ()), 2112 GrGLShaderBuilder::GetTexParamSwizzle(texture->config(), this->glCaps ()),
2065 sizeof(newTexParams.fSwizzleRGBA)); 2113 sizeof(newTexParams.fSwizzleRGBA));
2066 if (setAll || newTexParams.fMagFilter != oldTexParams.fMagFilter) { 2114 if (setAll || newTexParams.fMagFilter != oldTexParams.fMagFilter) {
2067 this->setTextureUnit(unitIdx); 2115 this->setTextureUnit(unitIdx);
2068 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, 2116 GL_CALL(TexParameteri(textureType,
2069 GR_GL_TEXTURE_MAG_FILTER, 2117 GR_GL_TEXTURE_MAG_FILTER,
2070 newTexParams.fMagFilter)); 2118 newTexParams.fMagFilter));
2071 } 2119 }
2072 if (setAll || newTexParams.fMinFilter != oldTexParams.fMinFilter) { 2120 if (setAll || newTexParams.fMinFilter != oldTexParams.fMinFilter) {
2073 this->setTextureUnit(unitIdx); 2121 this->setTextureUnit(unitIdx);
2074 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, 2122 GL_CALL(TexParameteri(textureType,
2075 GR_GL_TEXTURE_MIN_FILTER, 2123 GR_GL_TEXTURE_MIN_FILTER,
2076 newTexParams.fMinFilter)); 2124 newTexParams.fMinFilter));
2077 } 2125 }
2078 if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) { 2126 if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) {
2079 this->setTextureUnit(unitIdx); 2127 this->setTextureUnit(unitIdx);
2080 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, 2128 GL_CALL(TexParameteri(textureType,
2081 GR_GL_TEXTURE_WRAP_S, 2129 GR_GL_TEXTURE_WRAP_S,
2082 newTexParams.fWrapS)); 2130 newTexParams.fWrapS));
2083 } 2131 }
2084 if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) { 2132 if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) {
2085 this->setTextureUnit(unitIdx); 2133 this->setTextureUnit(unitIdx);
2086 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, 2134 GL_CALL(TexParameteri(textureType,
2087 GR_GL_TEXTURE_WRAP_T, 2135 GR_GL_TEXTURE_WRAP_T,
2088 newTexParams.fWrapT)); 2136 newTexParams.fWrapT));
2137 if (GR_GL_TEXTURE_3D == textureType) {
bsalomon 2014/09/26 14:23:51 Do all ES contexts that support 3D textures also s
2138 GL_CALL(TexParameteri(textureType,
2139 GR_GL_TEXTURE_WRAP_R,
2140 newTexParams.fWrapT));
2141 }
2089 } 2142 }
2090 if (this->glCaps().textureSwizzleSupport() && 2143 if (this->glCaps().textureSwizzleSupport() &&
2091 (setAll || memcmp(newTexParams.fSwizzleRGBA, 2144 (setAll || memcmp(newTexParams.fSwizzleRGBA,
2092 oldTexParams.fSwizzleRGBA, 2145 oldTexParams.fSwizzleRGBA,
2093 sizeof(newTexParams.fSwizzleRGBA)))) { 2146 sizeof(newTexParams.fSwizzleRGBA)))) {
2094 this->setTextureUnit(unitIdx); 2147 this->setTextureUnit(unitIdx);
2095 if (this->glStandard() == kGLES_GrGLStandard) { 2148 if (this->glStandard() == kGLES_GrGLStandard) {
2096 // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA. 2149 // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA.
2097 const GrGLenum* swizzle = newTexParams.fSwizzleRGBA; 2150 const GrGLenum* swizzle = newTexParams.fSwizzleRGBA;
2098 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_R, swi zzle[0])); 2151 GL_CALL(TexParameteri(textureType, GR_GL_TEXTURE_SWIZZLE_R, swizzle[ 0]));
2099 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_G, swi zzle[1])); 2152 GL_CALL(TexParameteri(textureType, GR_GL_TEXTURE_SWIZZLE_G, swizzle[ 1]));
2100 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_B, swi zzle[2])); 2153 GL_CALL(TexParameteri(textureType, GR_GL_TEXTURE_SWIZZLE_B, swizzle[ 2]));
2101 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_A, swi zzle[3])); 2154 GL_CALL(TexParameteri(textureType, GR_GL_TEXTURE_SWIZZLE_A, swizzle[ 3]));
2102 } else { 2155 } else {
2103 GR_STATIC_ASSERT(sizeof(newTexParams.fSwizzleRGBA[0]) == sizeof(GrGL int)); 2156 GR_STATIC_ASSERT(sizeof(newTexParams.fSwizzleRGBA[0]) == sizeof(GrGL int));
2104 const GrGLint* swizzle = reinterpret_cast<const GrGLint*>(newTexPara ms.fSwizzleRGBA); 2157 const GrGLint* swizzle = reinterpret_cast<const GrGLint*>(newTexPara ms.fSwizzleRGBA);
2105 GL_CALL(TexParameteriv(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_RGBA, swizzle)); 2158 GL_CALL(TexParameteriv(textureType, GR_GL_TEXTURE_SWIZZLE_RGBA, swiz zle));
2106 } 2159 }
2107 } 2160 }
2108 texture->setCachedTexParams(newTexParams, this->getResetTimestamp()); 2161 texture->setCachedTexParams(newTexParams, this->getResetTimestamp());
2109 } 2162 }
2110 2163
2111 void GrGpuGL::flushMiscFixedFunctionState(const GrOptDrawState& optState) { 2164 void GrGpuGL::flushMiscFixedFunctionState(const GrOptDrawState& optState) {
2112 if (optState.isDitherState()) { 2165 if (optState.isDitherState()) {
2113 if (kYes_TriState != fHWDitherEnabled) { 2166 if (kYes_TriState != fHWDitherEnabled) {
2114 GL_CALL(Enable(GR_GL_DITHER)); 2167 GL_CALL(Enable(GR_GL_DITHER));
2115 fHWDitherEnabled = kYes_TriState; 2168 fHWDitherEnabled = kYes_TriState;
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
2599 this->setVertexArrayID(gpu, 0); 2652 this->setVertexArrayID(gpu, 0);
2600 } 2653 }
2601 int attrCount = gpu->glCaps().maxVertexAttributes(); 2654 int attrCount = gpu->glCaps().maxVertexAttributes();
2602 if (fDefaultVertexArrayAttribState.count() != attrCount) { 2655 if (fDefaultVertexArrayAttribState.count() != attrCount) {
2603 fDefaultVertexArrayAttribState.resize(attrCount); 2656 fDefaultVertexArrayAttribState.resize(attrCount);
2604 } 2657 }
2605 attribState = &fDefaultVertexArrayAttribState; 2658 attribState = &fDefaultVertexArrayAttribState;
2606 } 2659 }
2607 return attribState; 2660 return attribState;
2608 } 2661 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698