Hash :
ff7aa214
Author :
Date :
2022-09-29T19:56:28
GL_PALETTE* sampling Implement GL_PALETTE* formats by decoding them into a R8G8B8A8_UNORM image at load time. Test: angle_end2end_tests --gtest_filter="PalettedTextureTest.*" Bug: angleproject:7599 Bug: angleproject:7688 Bug: angleproject:7710 Change-Id: I94d51e2c480fcdd39f1a0ad241b311d3b4de1579 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3863251 Reviewed-by: Cody Northrop <cnorthrop@google.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Constantine Shablya <constantine.shablya@collabora.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
//
// Copyright 2022 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// PalettedTextureTest.cpp: Tests paletted texture decompression
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include "common/matrix_utils.h"
#include "common/vector_utils.h"
#include "util/random_utils.h"
#include <stdint.h>
#include <vector>
using namespace angle;
class PalettedTextureTest : public ANGLETest<>
{
protected:
PalettedTextureTest()
{
setWindowWidth(32);
setWindowHeight(32);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
setConfigDepthBits(24);
}
};
// Check that paletted formats are reported as supported.
TEST_P(PalettedTextureTest, PalettedFormatsAreSupported)
{
ANGLE_SKIP_TEST_IF(!IsVulkan());
std::vector<GLint> mustSupportFormats{
GL_PALETTE4_RGB8_OES, GL_PALETTE4_RGBA8_OES, GL_PALETTE4_R5_G6_B5_OES,
GL_PALETTE4_RGBA4_OES, GL_PALETTE4_RGB5_A1_OES, GL_PALETTE8_RGB8_OES,
GL_PALETTE8_RGBA8_OES, GL_PALETTE8_R5_G6_B5_OES, GL_PALETTE8_RGBA4_OES,
GL_PALETTE8_RGB5_A1_OES,
};
GLint numSupportedFormats;
glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numSupportedFormats);
std::vector<GLint> supportedFormats(numSupportedFormats, 0);
glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, supportedFormats.data());
for (GLint format : mustSupportFormats)
{
EXPECT_TRUE(std::find(supportedFormats.begin(), supportedFormats.end(), format) !=
supportedFormats.end());
}
}
// Check that sampling a paletted texture works.
TEST_P(PalettedTextureTest, PalettedTextureSampling)
{
ANGLE_SKIP_TEST_IF(!IsVulkan());
struct Vertex
{
GLfloat position[3];
GLfloat uv[2];
};
glEnable(GL_TEXTURE_2D);
GLTexture texture;
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
struct TestImage
{
GLColor palette[16];
uint8_t texels[2]; // 2x2, each texel is 4-bit
};
TestImage testImage = {
{
GLColor::cyan,
GLColor::yellow,
GLColor::magenta,
GLColor::red,
},
{
0x01,
0x23,
},
};
glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_PALETTE4_RGBA8_OES, 2, 2, 0, sizeof testImage,
&testImage);
EXPECT_GL_NO_ERROR();
glClearColor(0.4f, 0.4f, 0.4f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustumf(-1, 1, -1, 1, 5.0, 60.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -8.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
std::vector<Vertex> vertices = {
{{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f}},
{{-1.0f, 1.0f, 0.0f}, {0.0f, 1.0f}},
{{1.0f, -1.0f, 0.0f}, {1.0f, 0.0f}},
{{1.0f, 1.0f, 0.0f}, {1.0f, 1.0f}},
};
glVertexPointer(3, GL_FLOAT, sizeof vertices[0], &vertices[0].position);
glTexCoordPointer(2, GL_FLOAT, sizeof vertices[0], &vertices[0].uv);
glDrawArrays(GL_TRIANGLE_STRIP, 0, vertices.size());
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_NEAR(8, 8, testImage.palette[0], 0);
EXPECT_PIXEL_COLOR_NEAR(24, 8, testImage.palette[1], 0);
EXPECT_PIXEL_COLOR_NEAR(8, 24, testImage.palette[2], 0);
EXPECT_PIXEL_COLOR_NEAR(24, 24, testImage.palette[3], 0);
}
ANGLE_INSTANTIATE_TEST_ES1(PalettedTextureTest);