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 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 if (restoreGLRowLength) { | 695 if (restoreGLRowLength) { |
696 SkASSERT(this->glCaps().unpackRowLengthSupport()); | 696 SkASSERT(this->glCaps().unpackRowLengthSupport()); |
697 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); | 697 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
698 } | 698 } |
699 if (glFlipY) { | 699 if (glFlipY) { |
700 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); | 700 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); |
701 } | 701 } |
702 return succeeded; | 702 return succeeded; |
703 } | 703 } |
704 | 704 |
| 705 bool GrGpuGL::uploadCompressedTexData(const GrGLTexture::Desc& desc, |
| 706 const void* data) { |
| 707 SkASSERT(NULL != data); |
| 708 |
| 709 // No support for software flip y, yet... |
| 710 SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin); |
| 711 |
| 712 // Make sure that the width and height that we pass to OpenGL |
| 713 // is a multiple of the block size. |
| 714 int dataSize = GrCompressedFormatDataSize(desc.fConfig, desc.fWidth, desc.fH
eight); |
| 715 |
| 716 // We only need the internal format for compressed 2D textures. |
| 717 GrGLenum internalFormat = 0; |
| 718 if (!this->configToGLFormats(desc.fConfig, false, &internalFormat, NULL, NUL
L)) { |
| 719 return false; |
| 720 } |
| 721 |
| 722 bool succeeded = true; |
| 723 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
| 724 GL_ALLOC_CALL(this->glInterface(), |
| 725 CompressedTexImage2D(GR_GL_TEXTURE_2D, |
| 726 0, // level |
| 727 internalFormat, |
| 728 desc.fWidth, desc.fHeight, |
| 729 0, // border |
| 730 dataSize, |
| 731 data)); |
| 732 |
| 733 GrGLenum error = check_alloc_error(desc, this->glInterface()); |
| 734 if (error != GR_GL_NO_ERROR) { |
| 735 succeeded = false; |
| 736 } |
| 737 return succeeded; |
| 738 } |
| 739 |
705 static bool renderbuffer_storage_msaa(GrGLContext& ctx, | 740 static bool renderbuffer_storage_msaa(GrGLContext& ctx, |
706 int sampleCount, | 741 int sampleCount, |
707 GrGLenum format, | 742 GrGLenum format, |
708 int width, int height) { | 743 int width, int height) { |
709 CLEAR_ERROR_BEFORE_ALLOC(ctx.interface()); | 744 CLEAR_ERROR_BEFORE_ALLOC(ctx.interface()); |
710 SkASSERT(GrGLCaps::kNone_MSFBOType != ctx.caps()->msFBOType()); | 745 SkASSERT(GrGLCaps::kNone_MSFBOType != ctx.caps()->msFBOType()); |
711 switch (ctx.caps()->msFBOType()) { | 746 switch (ctx.caps()->msFBOType()) { |
712 case GrGLCaps::kDesktop_ARB_MSFBOType: | 747 case GrGLCaps::kDesktop_ARB_MSFBOType: |
713 case GrGLCaps::kDesktop_EXT_MSFBOType: | 748 case GrGLCaps::kDesktop_EXT_MSFBOType: |
714 case GrGLCaps::kES_3_0_MSFBOType: | 749 case GrGLCaps::kES_3_0_MSFBOType: |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc)); | 1009 tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc)); |
975 } | 1010 } |
976 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); | 1011 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); |
977 #ifdef TRACE_TEXTURE_CREATION | 1012 #ifdef TRACE_TEXTURE_CREATION |
978 GrPrintf("--- new texture [%d] size=(%d %d) config=%d\n", | 1013 GrPrintf("--- new texture [%d] size=(%d %d) config=%d\n", |
979 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); | 1014 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); |
980 #endif | 1015 #endif |
981 return tex; | 1016 return tex; |
982 } | 1017 } |
983 | 1018 |
| 1019 GrTexture* GrGpuGL::onCreateCompressedTexture(const GrTextureDesc& desc, |
| 1020 const void* srcData) { |
| 1021 |
| 1022 if(SkToBool(desc.fFlags & kRenderTarget_GrTextureFlagBit)) { |
| 1023 return return_null_texture(); |
| 1024 } |
| 1025 |
| 1026 // Make sure that we're not flipping Y. |
| 1027 GrSurfaceOrigin texOrigin = resolve_origin(desc.fOrigin, false); |
| 1028 if (kBottomLeft_GrSurfaceOrigin == texOrigin) { |
| 1029 return return_null_texture(); |
| 1030 } |
| 1031 |
| 1032 GrGLTexture::Desc glTexDesc; |
| 1033 |
| 1034 glTexDesc.fFlags = desc.fFlags; |
| 1035 glTexDesc.fWidth = desc.fWidth; |
| 1036 glTexDesc.fHeight = desc.fHeight; |
| 1037 glTexDesc.fConfig = desc.fConfig; |
| 1038 glTexDesc.fIsWrapped = false; |
| 1039 glTexDesc.fOrigin = texOrigin; |
| 1040 |
| 1041 int maxSize = this->caps()->maxTextureSize(); |
| 1042 if (glTexDesc.fWidth > maxSize || glTexDesc.fHeight > maxSize) { |
| 1043 return return_null_texture(); |
| 1044 } |
| 1045 |
| 1046 GL_CALL(GenTextures(1, &glTexDesc.fTextureID)); |
| 1047 |
| 1048 if (!glTexDesc.fTextureID) { |
| 1049 return return_null_texture(); |
| 1050 } |
| 1051 |
| 1052 this->setScratchTextureUnit(); |
| 1053 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTexDesc.fTextureID)); |
| 1054 |
| 1055 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some |
| 1056 // drivers have a bug where an FBO won't be complete if it includes a |
| 1057 // texture that is not mipmap complete (considering the filter in use). |
| 1058 GrGLTexture::TexParams initialTexParams; |
| 1059 // we only set a subset here so invalidate first |
| 1060 initialTexParams.invalidate(); |
| 1061 initialTexParams.fMinFilter = GR_GL_NEAREST; |
| 1062 initialTexParams.fMagFilter = GR_GL_NEAREST; |
| 1063 initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE; |
| 1064 initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE; |
| 1065 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1066 GR_GL_TEXTURE_MAG_FILTER, |
| 1067 initialTexParams.fMagFilter)); |
| 1068 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1069 GR_GL_TEXTURE_MIN_FILTER, |
| 1070 initialTexParams.fMinFilter)); |
| 1071 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1072 GR_GL_TEXTURE_WRAP_S, |
| 1073 initialTexParams.fWrapS)); |
| 1074 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1075 GR_GL_TEXTURE_WRAP_T, |
| 1076 initialTexParams.fWrapT)); |
| 1077 |
| 1078 if (!this->uploadCompressedTexData(glTexDesc, srcData)) { |
| 1079 GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID)); |
| 1080 return return_null_texture(); |
| 1081 } |
| 1082 |
| 1083 GrGLTexture* tex; |
| 1084 tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc)); |
| 1085 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); |
| 1086 #ifdef TRACE_TEXTURE_CREATION |
| 1087 GrPrintf("--- new compressed texture [%d] size=(%d %d) config=%d\n", |
| 1088 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); |
| 1089 #endif |
| 1090 return tex; |
| 1091 } |
| 1092 |
984 namespace { | 1093 namespace { |
985 | 1094 |
986 const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount; | 1095 const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount; |
987 | 1096 |
988 void inline get_stencil_rb_sizes(const GrGLInterface* gl, | 1097 void inline get_stencil_rb_sizes(const GrGLInterface* gl, |
989 GrGLStencilBuffer::Format* format) { | 1098 GrGLStencilBuffer::Format* format) { |
990 | 1099 |
991 // we shouldn't ever know one size and not the other | 1100 // we shouldn't ever know one size and not the other |
992 SkASSERT((kUnknownBitCount == format->fStencilBits) == | 1101 SkASSERT((kUnknownBitCount == format->fStencilBits) == |
993 (kUnknownBitCount == format->fTotalBits)); | 1102 (kUnknownBitCount == format->fTotalBits)); |
(...skipping 1832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2826 this->setVertexArrayID(gpu, 0); | 2935 this->setVertexArrayID(gpu, 0); |
2827 } | 2936 } |
2828 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2937 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2829 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2938 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2830 fDefaultVertexArrayAttribState.resize(attrCount); | 2939 fDefaultVertexArrayAttribState.resize(attrCount); |
2831 } | 2940 } |
2832 attribState = &fDefaultVertexArrayAttribState; | 2941 attribState = &fDefaultVertexArrayAttribState; |
2833 } | 2942 } |
2834 return attribState; | 2943 return attribState; |
2835 } | 2944 } |
OLD | NEW |