2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 * This is a straightforward test of floating point textures, which are
10 * supported on some platforms. As of right now, this test only supports
11 * 32 bit floating point textures, and indeed floating point test values
12 * have been selected to require 32 bits of precision and full IEEE conformance
17 #include "GrContext.h"
18 #include "GrTexture.h"
19 #include "GrContextFactory.h"
20 #include "SkGpuDevice.h"
22 static const int DEV_W = 100, DEV_H = 100;
23 static const int FP_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * sizeof(float);
24 static const float kMaxIntegerRepresentableInSPFloatingPoint = 16777216; // 2 ^ 24
26 static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H);
28 DEF_GPUTEST(FloatingPointTextureTest, reporter, factory) {
29 float controlPixelData[FP_CONTROL_ARRAY_SIZE];
30 float readBuffer[FP_CONTROL_ARRAY_SIZE];
31 for (int i = 0; i < FP_CONTROL_ARRAY_SIZE; i += 4) {
32 controlPixelData[i] = FLT_MIN;
33 controlPixelData[i + 1] = FLT_MAX;
34 controlPixelData[i + 2] = FLT_EPSILON;
35 controlPixelData[i + 3] = kMaxIntegerRepresentableInSPFloatingPoint;
38 for (int origin = 0; origin < 2; ++origin) {
40 glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt;
41 for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) {
43 desc.fFlags = kRenderTarget_GrTextureFlagBit;
46 desc.fConfig = kRGBA_float_GrPixelConfig;
47 desc.fOrigin = 0 == origin ?
48 kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin;
50 GrContext* context = NULL;
51 GrContextFactory::GLContextType type =
52 static_cast<GrContextFactory::GLContextType>(glCtxType);
53 if (!GrContextFactory::IsRenderingGLContext(type)) {
56 context = factory->get(type);
61 SkAutoTUnref<GrTexture> fpTexture(context->createUncachedTexture(desc,
65 // Floating point textures are NOT supported everywhere
66 if (NULL == fpTexture) {
71 context->writeTexturePixels(fpTexture, 0, 0, DEV_W, DEV_H, desc.fConfig,
73 context->readTexturePixels(fpTexture, 0, 0, DEV_W, DEV_H, desc.fConfig, readBuffer, 0);
74 for (int j = 0; j < FP_CONTROL_ARRAY_SIZE; ++j) {
75 REPORTER_ASSERT(reporter, readBuffer[j] == controlPixelData[j]);