| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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(); |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2017 SkASSERT(texture); | 2063 SkASSERT(texture); |
| 2018 | 2064 |
| 2019 // If we created a rt/tex and rendered to it without using a texture and now
we're texturing | 2065 // If we created a rt/tex and rendered to it without using a texture and now
we're texturing |
| 2020 // from the rt it will still be the last bound texture, but it needs resolvi
ng. So keep this | 2066 // from the rt it will still be the last bound texture, but it needs resolvi
ng. So keep this |
| 2021 // out of the "last != next" check. | 2067 // out of the "last != next" check. |
| 2022 GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderT
arget()); | 2068 GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderT
arget()); |
| 2023 if (texRT) { | 2069 if (texRT) { |
| 2024 this->onResolveRenderTarget(texRT); | 2070 this->onResolveRenderTarget(texRT); |
| 2025 } | 2071 } |
| 2026 | 2072 |
| 2073 GrGLenum textureType = (texture->desc().fDepth > 0) ? GR_GL_TEXTURE_3D : GR_
GL_TEXTURE_2D; |
| 2074 |
| 2027 uint32_t textureID = texture->getUniqueID(); | 2075 uint32_t textureID = texture->getUniqueID(); |
| 2028 if (fHWBoundTextureUniqueIDs[unitIdx] != textureID) { | 2076 if (fHWBoundTextureUniqueIDs[unitIdx] != textureID) { |
| 2029 this->setTextureUnit(unitIdx); | 2077 this->setTextureUnit(unitIdx); |
| 2030 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, texture->textureID())); | 2078 GL_CALL(BindTexture(textureType, texture->textureID())); |
| 2031 fHWBoundTextureUniqueIDs[unitIdx] = textureID; | 2079 fHWBoundTextureUniqueIDs[unitIdx] = textureID; |
| 2032 } | 2080 } |
| 2033 | 2081 |
| 2034 ResetTimestamp timestamp; | 2082 ResetTimestamp timestamp; |
| 2035 const GrGLTexture::TexParams& oldTexParams = texture->getCachedTexParams(&ti
mestamp); | 2083 const GrGLTexture::TexParams& oldTexParams = texture->getCachedTexParams(&ti
mestamp); |
| 2036 bool setAll = timestamp < this->getResetTimestamp(); | 2084 bool setAll = timestamp < this->getResetTimestamp(); |
| 2037 GrGLTexture::TexParams newTexParams; | 2085 GrGLTexture::TexParams newTexParams; |
| 2038 | 2086 |
| 2039 static GrGLenum glMinFilterModes[] = { | 2087 static GrGLenum glMinFilterModes[] = { |
| 2040 GR_GL_NEAREST, | 2088 GR_GL_NEAREST, |
| 2041 GR_GL_LINEAR, | 2089 GR_GL_LINEAR, |
| 2042 GR_GL_LINEAR_MIPMAP_LINEAR | 2090 GR_GL_LINEAR_MIPMAP_LINEAR |
| 2043 }; | 2091 }; |
| 2044 static GrGLenum glMagFilterModes[] = { | 2092 static GrGLenum glMagFilterModes[] = { |
| 2045 GR_GL_NEAREST, | 2093 GR_GL_NEAREST, |
| 2046 GR_GL_LINEAR, | 2094 GR_GL_LINEAR, |
| 2047 GR_GL_LINEAR | 2095 GR_GL_LINEAR |
| 2048 }; | 2096 }; |
| 2049 GrTextureParams::FilterMode filterMode = params.filterMode(); | 2097 GrTextureParams::FilterMode filterMode = params.filterMode(); |
| 2050 if (!this->caps()->mipMapSupport() && GrTextureParams::kMipMap_FilterMode ==
filterMode) { | 2098 if (!this->caps()->mipMapSupport() && GrTextureParams::kMipMap_FilterMode ==
filterMode) { |
| 2051 filterMode = GrTextureParams::kBilerp_FilterMode; | 2099 filterMode = GrTextureParams::kBilerp_FilterMode; |
| 2052 } | 2100 } |
| 2053 newTexParams.fMinFilter = glMinFilterModes[filterMode]; | 2101 newTexParams.fMinFilter = glMinFilterModes[filterMode]; |
| 2054 newTexParams.fMagFilter = glMagFilterModes[filterMode]; | 2102 newTexParams.fMagFilter = glMagFilterModes[filterMode]; |
| 2055 | 2103 |
| 2056 if (GrTextureParams::kMipMap_FilterMode == filterMode && | 2104 if (GrTextureParams::kMipMap_FilterMode == filterMode && |
| 2057 texture->mipMapsAreDirty() && !GrPixelConfigIsCompressed(texture->config
())) { | 2105 texture->mipMapsAreDirty() && !GrPixelConfigIsCompressed(texture->config
())) { |
| 2058 GL_CALL(GenerateMipmap(GR_GL_TEXTURE_2D)); | 2106 GL_CALL(GenerateMipmap(textureType)); |
| 2059 texture->dirtyMipMaps(false); | 2107 texture->dirtyMipMaps(false); |
| 2060 } | 2108 } |
| 2061 | 2109 |
| 2062 newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX()); | 2110 newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX()); |
| 2063 newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY()); | 2111 newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY()); |
| 2064 memcpy(newTexParams.fSwizzleRGBA, | 2112 memcpy(newTexParams.fSwizzleRGBA, |
| 2065 GrGLShaderBuilder::GetTexParamSwizzle(texture->config(), this->glCaps
()), | 2113 GrGLShaderBuilder::GetTexParamSwizzle(texture->config(), this->glCaps
()), |
| 2066 sizeof(newTexParams.fSwizzleRGBA)); | 2114 sizeof(newTexParams.fSwizzleRGBA)); |
| 2067 if (setAll || newTexParams.fMagFilter != oldTexParams.fMagFilter) { | 2115 if (setAll || newTexParams.fMagFilter != oldTexParams.fMagFilter) { |
| 2068 this->setTextureUnit(unitIdx); | 2116 this->setTextureUnit(unitIdx); |
| 2069 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 2117 GL_CALL(TexParameteri(textureType, |
| 2070 GR_GL_TEXTURE_MAG_FILTER, | 2118 GR_GL_TEXTURE_MAG_FILTER, |
| 2071 newTexParams.fMagFilter)); | 2119 newTexParams.fMagFilter)); |
| 2072 } | 2120 } |
| 2073 if (setAll || newTexParams.fMinFilter != oldTexParams.fMinFilter) { | 2121 if (setAll || newTexParams.fMinFilter != oldTexParams.fMinFilter) { |
| 2074 this->setTextureUnit(unitIdx); | 2122 this->setTextureUnit(unitIdx); |
| 2075 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 2123 GL_CALL(TexParameteri(textureType, |
| 2076 GR_GL_TEXTURE_MIN_FILTER, | 2124 GR_GL_TEXTURE_MIN_FILTER, |
| 2077 newTexParams.fMinFilter)); | 2125 newTexParams.fMinFilter)); |
| 2078 } | 2126 } |
| 2079 if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) { | 2127 if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) { |
| 2080 this->setTextureUnit(unitIdx); | 2128 this->setTextureUnit(unitIdx); |
| 2081 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 2129 GL_CALL(TexParameteri(textureType, |
| 2082 GR_GL_TEXTURE_WRAP_S, | 2130 GR_GL_TEXTURE_WRAP_S, |
| 2083 newTexParams.fWrapS)); | 2131 newTexParams.fWrapS)); |
| 2084 } | 2132 } |
| 2085 if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) { | 2133 if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) { |
| 2086 this->setTextureUnit(unitIdx); | 2134 this->setTextureUnit(unitIdx); |
| 2087 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 2135 GL_CALL(TexParameteri(textureType, |
| 2088 GR_GL_TEXTURE_WRAP_T, | 2136 GR_GL_TEXTURE_WRAP_T, |
| 2089 newTexParams.fWrapT)); | 2137 newTexParams.fWrapT)); |
| 2138 if (GR_GL_TEXTURE_3D == textureType) { |
| 2139 GL_CALL(TexParameteri(textureType, |
| 2140 GR_GL_TEXTURE_WRAP_R, |
| 2141 newTexParams.fWrapT)); |
| 2142 } |
| 2090 } | 2143 } |
| 2091 if (this->glCaps().textureSwizzleSupport() && | 2144 if (this->glCaps().textureSwizzleSupport() && |
| 2092 (setAll || memcmp(newTexParams.fSwizzleRGBA, | 2145 (setAll || memcmp(newTexParams.fSwizzleRGBA, |
| 2093 oldTexParams.fSwizzleRGBA, | 2146 oldTexParams.fSwizzleRGBA, |
| 2094 sizeof(newTexParams.fSwizzleRGBA)))) { | 2147 sizeof(newTexParams.fSwizzleRGBA)))) { |
| 2095 this->setTextureUnit(unitIdx); | 2148 this->setTextureUnit(unitIdx); |
| 2096 if (this->glStandard() == kGLES_GrGLStandard) { | 2149 if (this->glStandard() == kGLES_GrGLStandard) { |
| 2097 // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA. | 2150 // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA. |
| 2098 const GrGLenum* swizzle = newTexParams.fSwizzleRGBA; | 2151 const GrGLenum* swizzle = newTexParams.fSwizzleRGBA; |
| 2099 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_R, swi
zzle[0])); | 2152 GL_CALL(TexParameteri(textureType, GR_GL_TEXTURE_SWIZZLE_R, swizzle[
0])); |
| 2100 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_G, swi
zzle[1])); | 2153 GL_CALL(TexParameteri(textureType, GR_GL_TEXTURE_SWIZZLE_G, swizzle[
1])); |
| 2101 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_B, swi
zzle[2])); | 2154 GL_CALL(TexParameteri(textureType, GR_GL_TEXTURE_SWIZZLE_B, swizzle[
2])); |
| 2102 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_A, swi
zzle[3])); | 2155 GL_CALL(TexParameteri(textureType, GR_GL_TEXTURE_SWIZZLE_A, swizzle[
3])); |
| 2103 } else { | 2156 } else { |
| 2104 GR_STATIC_ASSERT(sizeof(newTexParams.fSwizzleRGBA[0]) == sizeof(GrGL
int)); | 2157 GR_STATIC_ASSERT(sizeof(newTexParams.fSwizzleRGBA[0]) == sizeof(GrGL
int)); |
| 2105 const GrGLint* swizzle = reinterpret_cast<const GrGLint*>(newTexPara
ms.fSwizzleRGBA); | 2158 const GrGLint* swizzle = reinterpret_cast<const GrGLint*>(newTexPara
ms.fSwizzleRGBA); |
| 2106 GL_CALL(TexParameteriv(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_RGBA,
swizzle)); | 2159 GL_CALL(TexParameteriv(textureType, GR_GL_TEXTURE_SWIZZLE_RGBA, swiz
zle)); |
| 2107 } | 2160 } |
| 2108 } | 2161 } |
| 2109 texture->setCachedTexParams(newTexParams, this->getResetTimestamp()); | 2162 texture->setCachedTexParams(newTexParams, this->getResetTimestamp()); |
| 2110 } | 2163 } |
| 2111 | 2164 |
| 2112 void GrGpuGL::flushMiscFixedFunctionState() { | 2165 void GrGpuGL::flushMiscFixedFunctionState() { |
| 2113 | 2166 |
| 2114 const GrDrawState& drawState = this->getDrawState(); | 2167 const GrDrawState& drawState = this->getDrawState(); |
| 2115 | 2168 |
| 2116 if (drawState.isDitherState()) { | 2169 if (drawState.isDitherState()) { |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2603 this->setVertexArrayID(gpu, 0); | 2656 this->setVertexArrayID(gpu, 0); |
| 2604 } | 2657 } |
| 2605 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2658 int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 2606 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2659 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 2607 fDefaultVertexArrayAttribState.resize(attrCount); | 2660 fDefaultVertexArrayAttribState.resize(attrCount); |
| 2608 } | 2661 } |
| 2609 attribState = &fDefaultVertexArrayAttribState; | 2662 attribState = &fDefaultVertexArrayAttribState; |
| 2610 } | 2663 } |
| 2611 return attribState; | 2664 return attribState; |
| 2612 } | 2665 } |
| OLD | NEW |