'../tests/FitsInTest.cpp',
'../tests/FlatDataTest.cpp',
'../tests/FlateTest.cpp',
+ '../tests/FloatingPointTextureTest.cpp',
'../tests/FontHostStreamTest.cpp',
'../tests/FontHostTest.cpp',
'../tests/FontMgrTest.cpp',
kRGB_GrColorComponentFlags, // kETC1_GrPixelConfig
kA_GrColorComponentFlag, // kLATC_GrPixelConfig
kA_GrColorComponentFlag, // kR11_EAC_GrPixelConfig
+ kRGBA_GrColorComponentFlags, // kRGBA_float_GrPixelConfig
};
return kFlags[config];
GR_STATIC_ASSERT(7 == kETC1_GrPixelConfig);
GR_STATIC_ASSERT(8 == kLATC_GrPixelConfig);
GR_STATIC_ASSERT(9 == kR11_EAC_GrPixelConfig);
+ GR_STATIC_ASSERT(10 == kRGBA_float_GrPixelConfig);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFlags) == kGrPixelConfigCnt);
}
* Premultiplied. Byte order is b,g,r,a.
*/
kBGRA_8888_GrPixelConfig,
- /**
+ /**
* ETC1 Compressed Data
*/
kETC1_GrPixelConfig,
* LATC/RGTC/3Dc/BC4 Compressed Data
*/
kLATC_GrPixelConfig,
-
/**
* R11 EAC Compressed Data
* (Corresponds to section C.3.5 of the OpenGL 4.4 core profile spec)
*/
kR11_EAC_GrPixelConfig,
-
- kLast_GrPixelConfig = kR11_EAC_GrPixelConfig
+ /**
+ * Byte order is r, g, b, a. This color format is 32 bits per channel
+ */
+ kRGBA_float_GrPixelConfig,
+ kLast_GrPixelConfig = kRGBA_float_GrPixelConfig
};
static const int kGrPixelConfigCnt = kLast_GrPixelConfig + 1;
case kRGBA_8888_GrPixelConfig:
case kBGRA_8888_GrPixelConfig:
return 4;
+ case kRGBA_float_GrPixelConfig:
+ return 16;
+ default:
+ return 0;
+ }
+}
+
+static inline size_t GrUnpackAlignment(GrPixelConfig config) {
+ switch (config) {
+ case kAlpha_8_GrPixelConfig:
+ case kIndex_8_GrPixelConfig:
+ return 1;
+ case kRGB_565_GrPixelConfig:
+ case kRGBA_4444_GrPixelConfig:
+ return 2;
+ case kRGBA_8888_GrPixelConfig:
+ case kBGRA_8888_GrPixelConfig:
+ case kRGBA_float_GrPixelConfig:
+ return 4;
default:
return 0;
}
/**
* Returns the data size for the given compressed pixel config
- */
+ */
static inline size_t GrCompressedFormatDataSize(GrPixelConfig config,
int width, int height) {
SkASSERT(GrPixelConfigIsCompressed(config));
"ETC1", // kETC1_GrPixelConfig,
"LATC", // kLATC_GrPixelConfig,
"R11EAC", // kR11_EAC_GrPixelConfig,
+ "RGBAFloat", // kRGBA_float_GrPixelConfig
};
GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
GR_STATIC_ASSERT(7 == kETC1_GrPixelConfig);
GR_STATIC_ASSERT(8 == kLATC_GrPixelConfig);
GR_STATIC_ASSERT(9 == kR11_EAC_GrPixelConfig);
+ GR_STATIC_ASSERT(10 == kRGBA_float_GrPixelConfig);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt);
SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]);
if (kUnknown_GrPixelConfig == fDesc.fConfig) {
colorBits = 32; // don't know, make a guess
} else {
- colorBits = GrBytesPerPixel(fDesc.fConfig);
+ colorBits = GrBytesPerPixel(fDesc.fConfig) * 8;
}
uint64_t size = fDesc.fWidth;
size *= fDesc.fHeight;
}
}
+ if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
+ fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
+ }
+
// If we don't support MSAA then undo any places above where we set a config as renderable with
// msaa.
if (kNone_MSFBOType == fMSFBOType) {
// First check version for support
if (kGL_GrGLStandard == standard) {
hasETC1 = hasCompressTex2D &&
- (version >= GR_GL_VER(4, 3) ||
+ (version >= GR_GL_VER(4, 3) ||
ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
} else {
hasETC1 = hasCompressTex2D &&
} else {
fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
}
+
+ // Check for floating point texture support
+ // NOTE: We disallow floating point textures on ES devices if linear
+ // filtering modes are not supported. This is for simplicity, but a more
+ // granular approach is possible. Coincidentally, floating point textures became part of
+ // the standard in ES3.1 / OGL 3.1, hence the shorthand
+ bool hasFPTextures = version >= GR_GL_VER(3, 1);
+ if (!hasFPTextures) {
+ hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
+ (ctxInfo.hasExtension("OES_texture_float_linear") &&
+ ctxInfo.hasExtension("GL_OES_texture_float"));
+ }
+ fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
}
bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
#define GR_GL_RGB5_A1 0x8057
#define GR_GL_RGB565 0x8D62
#define GR_GL_RGBA8 0x8058
+#define GR_GL_RGBA32F 0x8814
#define GR_GL_RGB8 0x8051
#define GR_GL_BGRA8 0x93A1
#define GR_GL_SRGB 0x8C40
if (glFlipY) {
GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE));
}
- GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, static_cast<GrGLint>(bpp)));
+ GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT,
+ static_cast<GrGLint>(GrUnpackAlignment(dataConfig))));
}
bool succeeded = true;
if (isNewTexture &&
case kR11_EAC_GrPixelConfig:
*internalFormat = GR_GL_COMPRESSED_R11;
break;
+ case kRGBA_float_GrPixelConfig:
+ *internalFormat = GR_GL_RGBA32F;
+ *externalFormat = GR_GL_RGBA;
+ *externalType = GR_GL_FLOAT;
+ break;
default:
return false;
}
--- /dev/null
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/*
+ * This is a straightforward test of floating point textures, which are
+ * supported on some platforms. As of right now, this test only supports
+ * 32 bit floating point textures, and indeed floating point test values
+ * have been selected to require 32 bits of precision and full IEEE conformance
+ */
+#if SK_SUPPORT_GPU
+#include <float.h>
+#include "Test.h"
+#include "GrContext.h"
+#include "GrTexture.h"
+#include "GrContextFactory.h"
+#include "SkGpuDevice.h"
+
+static const int DEV_W = 100, DEV_H = 100;
+static const int FP_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * sizeof(float);
+static const float kMaxIntegerRepresentableInSPFloatingPoint = 16777216; // 2 ^ 24
+
+static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H);
+
+DEF_GPUTEST(FloatingPointTextureTest, reporter, factory) {
+ float controlPixelData[FP_CONTROL_ARRAY_SIZE];
+ float readBuffer[FP_CONTROL_ARRAY_SIZE];
+ for (int i = 0; i < FP_CONTROL_ARRAY_SIZE; i += 4) {
+ controlPixelData[i] = FLT_MIN;
+ controlPixelData[i + 1] = FLT_MAX;
+ controlPixelData[i + 2] = FLT_EPSILON;
+ controlPixelData[i + 3] = kMaxIntegerRepresentableInSPFloatingPoint;
+ }
+
+ for (int origin = 0; origin < 2; ++origin) {
+ int glCtxTypeCnt = 1;
+ glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt;
+ for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) {
+ GrTextureDesc desc;
+ desc.fFlags = kRenderTarget_GrTextureFlagBit;
+ desc.fWidth = DEV_W;
+ desc.fHeight = DEV_H;
+ desc.fConfig = kRGBA_float_GrPixelConfig;
+ desc.fOrigin = 0 == origin ?
+ kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin;
+
+ GrContext* context = NULL;
+ GrContextFactory::GLContextType type =
+ static_cast<GrContextFactory::GLContextType>(glCtxType);
+ if (!GrContextFactory::IsRenderingGLContext(type)) {
+ continue;
+ }
+ context = factory->get(type);
+ if (NULL == context){
+ continue;
+ }
+
+ SkAutoTUnref<GrTexture> fpTexture(context->createUncachedTexture(desc,
+ NULL,
+ 0));
+
+ // Floating point textures are NOT supported everywhere
+ if (NULL == fpTexture) {
+ continue;
+ }
+
+ // write square
+ context->writeTexturePixels(fpTexture, 0, 0, DEV_W, DEV_H, desc.fConfig,
+ controlPixelData, 0);
+ context->readTexturePixels(fpTexture, 0, 0, DEV_W, DEV_H, desc.fConfig, readBuffer, 0);
+ for (int j = 0; j < FP_CONTROL_ARRAY_SIZE; ++j) {
+ REPORTER_ASSERT(reporter, readBuffer[j] == controlPixelData[j]);
+ }
+ }
+ }
+}
+
+#endif