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 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
691 if (restoreGLRowLength) { | 691 if (restoreGLRowLength) { |
692 SkASSERT(this->glCaps().unpackRowLengthSupport()); | 692 SkASSERT(this->glCaps().unpackRowLengthSupport()); |
693 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); | 693 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
694 } | 694 } |
695 if (glFlipY) { | 695 if (glFlipY) { |
696 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); | 696 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); |
697 } | 697 } |
698 return succeeded; | 698 return succeeded; |
699 } | 699 } |
700 | 700 |
701 bool GrGpuGL::compressedFormatToGLFormats(GrCompressedFormat fmt, GrGLenum *inte rnal) { | |
702 switch(fmt) { | |
703 case kETC1_GrCompressedFormat: | |
704 *internal = GR_GL_COMPRESSED_RGB8_ETC1; | |
705 return true; | |
706 default: | |
707 SkASSERT(!"Not a compressed format!"); | |
708 break; | |
709 } | |
710 return false; | |
711 } | |
712 | |
713 bool GrGpuGL::uploadCompressedTexData(const GrGLTexture::Desc& desc, | |
714 GrCompressedFormat fmt, | |
715 const void* data) { | |
716 SkASSERT(NULL != data); | |
717 | |
718 // No support for software flip y, yet... | |
719 SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin); | |
720 | |
721 // Make sure that the width and height that we pass to OpenGL | |
722 // is a multiple of the block size. | |
723 GrCompressedFormatDesc ctDesc = GrGetCompressedFormatDesc(fmt); | |
724 SkASSERT((desc.fWidth % ctDesc.fBlockSizeX) == 0); | |
725 SkASSERT((desc.fHeight % ctDesc.fBlockSizeY) == 0); | |
726 | |
727 int dataSize = | |
728 (desc.fWidth / ctDesc.fBlockSizeX) * | |
729 (desc.fHeight / ctDesc.fBlockSizeY) * | |
730 ctDesc.fBytesPerBlock; | |
731 | |
robertphillips
2014/05/27 22:01:50
Remove this (tempStorage) ?
krajcevski
2014/05/27 22:19:29
Done.
| |
732 SkAutoSMalloc<128 * 128> tempStorage; | |
733 | |
734 GrGLenum internalFormat; | |
735 if (!this->compressedFormatToGLFormats(fmt, &internalFormat)) { | |
736 return false; | |
737 } | |
738 | |
739 bool succeeded = true; | |
740 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | |
741 GL_ALLOC_CALL(this->glInterface(), | |
742 CompressedTexImage2D(GR_GL_TEXTURE_2D, | |
743 0, // level | |
744 internalFormat, | |
745 desc.fWidth, desc.fHeight, | |
746 0, // border | |
747 dataSize, | |
748 data)); | |
749 | |
750 GrGLenum error = check_alloc_error(desc, this->glInterface()); | |
751 if (error != GR_GL_NO_ERROR) { | |
752 succeeded = false; | |
753 } | |
754 return succeeded; | |
755 } | |
756 | |
701 static bool renderbuffer_storage_msaa(GrGLContext& ctx, | 757 static bool renderbuffer_storage_msaa(GrGLContext& ctx, |
702 int sampleCount, | 758 int sampleCount, |
703 GrGLenum format, | 759 GrGLenum format, |
704 int width, int height) { | 760 int width, int height) { |
705 CLEAR_ERROR_BEFORE_ALLOC(ctx.interface()); | 761 CLEAR_ERROR_BEFORE_ALLOC(ctx.interface()); |
706 SkASSERT(GrGLCaps::kNone_MSFBOType != ctx.caps()->msFBOType()); | 762 SkASSERT(GrGLCaps::kNone_MSFBOType != ctx.caps()->msFBOType()); |
707 switch (ctx.caps()->msFBOType()) { | 763 switch (ctx.caps()->msFBOType()) { |
708 case GrGLCaps::kDesktop_ARB_MSFBOType: | 764 case GrGLCaps::kDesktop_ARB_MSFBOType: |
709 case GrGLCaps::kDesktop_EXT_MSFBOType: | 765 case GrGLCaps::kDesktop_EXT_MSFBOType: |
710 case GrGLCaps::kES_3_0_MSFBOType: | 766 case GrGLCaps::kES_3_0_MSFBOType: |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
970 tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc)); | 1026 tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc)); |
971 } | 1027 } |
972 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); | 1028 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); |
973 #ifdef TRACE_TEXTURE_CREATION | 1029 #ifdef TRACE_TEXTURE_CREATION |
974 GrPrintf("--- new texture [%d] size=(%d %d) config=%d\n", | 1030 GrPrintf("--- new texture [%d] size=(%d %d) config=%d\n", |
975 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); | 1031 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); |
976 #endif | 1032 #endif |
977 return tex; | 1033 return tex; |
978 } | 1034 } |
979 | 1035 |
1036 GrTexture* GrGpuGL::onCreateCompressedTexture(const GrTextureDesc& desc, | |
1037 const void* srcData, | |
1038 GrCompressedFormat format) { | |
1039 | |
1040 if(SkToBool(desc.fFlags & kRenderTarget_GrTextureFlagBit)) { | |
1041 return return_null_texture(); | |
1042 } | |
1043 | |
1044 // Make sure that we're not flipping Y. | |
1045 GrSurfaceOrigin texOrigin = resolve_origin(desc.fOrigin, false); | |
1046 if (kBottomLeft_GrSurfaceOrigin == texOrigin) { | |
1047 return return_null_texture(); | |
1048 } | |
1049 | |
1050 // Make sure that the width and height are multiples of the block | |
1051 // size for the associated format. | |
1052 GrCompressedFormatDesc ctDesc = GrGetCompressedFormatDesc(format); | |
1053 if ((desc.fWidth % ctDesc.fBlockSizeX) != 0 || | |
1054 (desc.fHeight % ctDesc.fBlockSizeY) != 0) { | |
1055 return return_null_texture(); | |
1056 } | |
1057 | |
1058 GrGLTexture::Desc glTexDesc; | |
1059 | |
1060 glTexDesc.fFlags = desc.fFlags; | |
1061 glTexDesc.fWidth = desc.fWidth; | |
1062 glTexDesc.fHeight = desc.fHeight; | |
1063 glTexDesc.fConfig = desc.fConfig; | |
1064 glTexDesc.fIsWrapped = false; | |
1065 glTexDesc.fOrigin = texOrigin; | |
1066 | |
1067 int maxSize = this->caps()->maxTextureSize(); | |
1068 if (glTexDesc.fWidth > maxSize || glTexDesc.fHeight > maxSize) { | |
1069 return return_null_texture(); | |
1070 } | |
1071 | |
1072 GL_CALL(GenTextures(1, &glTexDesc.fTextureID)); | |
1073 | |
1074 if (!glTexDesc.fTextureID) { | |
1075 return return_null_texture(); | |
1076 } | |
1077 | |
1078 this->setScratchTextureUnit(); | |
1079 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTexDesc.fTextureID)); | |
1080 | |
1081 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some | |
1082 // drivers have a bug where an FBO won't be complete if it includes a | |
1083 // texture that is not mipmap complete (considering the filter in use). | |
1084 GrGLTexture::TexParams initialTexParams; | |
1085 // we only set a subset here so invalidate first | |
1086 initialTexParams.invalidate(); | |
1087 initialTexParams.fMinFilter = GR_GL_NEAREST; | |
1088 initialTexParams.fMagFilter = GR_GL_NEAREST; | |
1089 initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE; | |
1090 initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE; | |
1091 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | |
1092 GR_GL_TEXTURE_MAG_FILTER, | |
1093 initialTexParams.fMagFilter)); | |
1094 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | |
1095 GR_GL_TEXTURE_MIN_FILTER, | |
1096 initialTexParams.fMinFilter)); | |
1097 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | |
1098 GR_GL_TEXTURE_WRAP_S, | |
1099 initialTexParams.fWrapS)); | |
1100 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | |
1101 GR_GL_TEXTURE_WRAP_T, | |
1102 initialTexParams.fWrapT)); | |
1103 | |
1104 if (!this->uploadCompressedTexData(glTexDesc, format, srcData)) { | |
1105 GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID)); | |
1106 return return_null_texture(); | |
1107 } | |
1108 | |
1109 GrGLTexture* tex; | |
1110 tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc)); | |
1111 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); | |
1112 #ifdef TRACE_TEXTURE_CREATION | |
1113 GrPrintf("--- new compressed texture [%d] format=%d size=(%d %d) config=%d\n ", | |
1114 glTexDesc.fTextureID, format, desc.fWidth, desc.fHeight, desc.fConf ig); | |
1115 #endif | |
1116 return tex; | |
1117 } | |
1118 | |
980 namespace { | 1119 namespace { |
981 | 1120 |
982 const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount; | 1121 const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount; |
983 | 1122 |
984 void inline get_stencil_rb_sizes(const GrGLInterface* gl, | 1123 void inline get_stencil_rb_sizes(const GrGLInterface* gl, |
985 GrGLStencilBuffer::Format* format) { | 1124 GrGLStencilBuffer::Format* format) { |
986 | 1125 |
987 // we shouldn't ever know one size and not the other | 1126 // we shouldn't ever know one size and not the other |
988 SkASSERT((kUnknownBitCount == format->fStencilBits) == | 1127 SkASSERT((kUnknownBitCount == format->fStencilBits) == |
989 (kUnknownBitCount == format->fTotalBits)); | 1128 (kUnknownBitCount == format->fTotalBits)); |
(...skipping 1813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2803 this->setVertexArrayID(gpu, 0); | 2942 this->setVertexArrayID(gpu, 0); |
2804 } | 2943 } |
2805 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2944 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2806 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2945 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2807 fDefaultVertexArrayAttribState.resize(attrCount); | 2946 fDefaultVertexArrayAttribState.resize(attrCount); |
2808 } | 2947 } |
2809 attribState = &fDefaultVertexArrayAttribState; | 2948 attribState = &fDefaultVertexArrayAttribState; |
2810 } | 2949 } |
2811 return attribState; | 2950 return attribState; |
2812 } | 2951 } |
OLD | NEW |