aboutsummaryrefslogtreecommitdiff
path: root/third_party/ktx
diff options
context:
space:
mode:
authorkrajcevski <krajcevski@google.com>2014-08-05 14:13:36 -0700
committerCommit bot <commit-bot@chromium.org>2014-08-05 14:13:36 -0700
commit40a1e11ebebe81586f3fec96408fdfd4b51123d2 (patch)
treec2174293e43c71dd1d7de3d3568a4dc965f9e462 /third_party/ktx
parent07544757c9fcf0f359f1686a3779eb2e75dd5b36 (diff)
downloadskia-40a1e11ebebe81586f3fec96408fdfd4b51123d2.tar.gz
Add support for all compressed formats in KTX file format
R=robertphillips@google.com Author: krajcevski@google.com Review URL: https://codereview.chromium.org/440783004
Diffstat (limited to 'third_party/ktx')
-rw-r--r--third_party/ktx/ktx.cpp33
-rw-r--r--third_party/ktx/ktx.h3
2 files changed, 33 insertions, 3 deletions
diff --git a/third_party/ktx/ktx.cpp b/third_party/ktx/ktx.cpp
index a05498b7e..ebcc5eb18 100644
--- a/third_party/ktx/ktx.cpp
+++ b/third_party/ktx/ktx.cpp
@@ -12,9 +12,27 @@
#include "SkEndian.h"
#include "gl/GrGLDefines.h"
+#include "GrConfig.h"
#include "etc1.h"
+static inline uint32_t compressed_fmt_to_gl_define(SkTextureCompressor::Format fmt) {
+ static const uint32_t kGLDefineMap[SkTextureCompressor::kFormatCnt] = {
+ GR_GL_COMPRESSED_LUMINANCE_LATC1, // kLATC_Format
+ GR_GL_COMPRESSED_R11, // kR11_EAC_Format
+ GR_GL_COMPRESSED_RGB8_ETC1, // kETC1_Format
+ GR_GL_COMPRESSED_RGBA_ASTC_12x12, // kASTC_12x12_Format
+ };
+
+ GR_STATIC_ASSERT(0 == SkTextureCompressor::kLATC_Format);
+ GR_STATIC_ASSERT(1 == SkTextureCompressor::kR11_EAC_Format);
+ GR_STATIC_ASSERT(2 == SkTextureCompressor::kETC1_Format);
+ GR_STATIC_ASSERT(3 == SkTextureCompressor::kASTC_12x12_Format);
+ GR_STATIC_ASSERT(SK_ARRAY_COUNT(kGLDefineMap) == SkTextureCompressor::kFormatCnt);
+
+ return kGLDefineMap[fmt];
+}
+
#define KTX_FILE_IDENTIFIER_SIZE 12
static const uint8_t KTX_FILE_IDENTIFIER[KTX_FILE_IDENTIFIER_SIZE] = {
0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A
@@ -123,8 +141,19 @@ SkString SkKTXFile::getValueForKey(const SkString& key) const {
return SkString();
}
-bool SkKTXFile::isETC1() const {
- return this->valid() && GR_GL_COMPRESSED_RGB8_ETC1 == fHeader.fGLInternalFormat;
+bool SkKTXFile::isCompressedFormat(SkTextureCompressor::Format fmt) const {
+ if (!this->valid()) {
+ return false;
+ }
+
+ // This has many aliases
+ bool isFmt = false;
+ if (fmt == SkTextureCompressor::kLATC_Format) {
+ isFmt = GR_GL_COMPRESSED_RED_RGTC1 == fHeader.fGLInternalFormat ||
+ GR_GL_COMPRESSED_3DC_X == fHeader.fGLInternalFormat;
+ }
+
+ return isFmt || compressed_fmt_to_gl_define(fmt) == fHeader.fGLInternalFormat;
}
bool SkKTXFile::isRGBA8() const {
diff --git a/third_party/ktx/ktx.h b/third_party/ktx/ktx.h
index 2f445a817..1114b49bf 100644
--- a/third_party/ktx/ktx.h
+++ b/third_party/ktx/ktx.h
@@ -11,6 +11,7 @@
#define SkKTXFile_DEFINED
#include "SkData.h"
+#include "SkTextureCompressor.h"
#include "SkTypes.h"
#include "SkTDArray.h"
#include "SkString.h"
@@ -58,7 +59,7 @@ public:
int numMipmaps() const { return static_cast<int>(fHeader.fNumberOfMipmapLevels); }
- bool isETC1() const;
+ bool isCompressedFormat(SkTextureCompressor::Format fmt) const;
bool isRGBA8() const;
bool isRGB8() const;