Hash :
ef8350a6
Author :
Date :
2022-10-21T06:30:51
GLES1Renderer: Handle GL_BGRA the same way we handle GL_RGBA Fixes minetest Bug: angleproject:7774 Change-Id: Iacbe8cb9aa434ec624bfaf056092b77bda468b3f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3970417 Commit-Queue: Constantine Shablya <constantine.shablya@collabora.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Auto-Submit: 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 137 138 139 140 141 142 143 144 145 146 147 148
//
// Copyright 2018 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.
//
// BGRATextureTest.cpp: Tests GLES1-specific usage of BGRA textures
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include "util/random_utils.h"
#include <stdint.h>
using namespace angle;
class BGRATextureTest : public ANGLETest<>
{
protected:
BGRATextureTest()
{
setWindowWidth(32);
setWindowHeight(32);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
setConfigDepthBits(24);
}
GLColor rgbswap(GLColor x)
{
GLColor y;
y.B = x.R;
y.G = x.G;
y.R = x.B;
y.A = x.A;
return y;
}
void clearGLColor(GLColor color)
{
Vector4 colorF = color.toNormalizedVector();
glClearColor(colorF.x(), colorF.y(), colorF.z(), colorF.w());
}
};
// Test that BGRA sampling samples color components and alpha correctly.
TEST_P(BGRATextureTest, BGRATextureSampling)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_format_BGRA8888"));
struct Vertex
{
GLfloat position[3];
GLfloat uv[2];
};
glEnable(GL_TEXTURE_2D);
std::array<GLColor, 4> testImage = {
GLColor::cyan,
GLColor::yellow,
GLColor::magenta,
GLColor(1, 2, 3, 0),
};
GLTexture texRGBA;
{
glBindTexture(GL_TEXTURE_2D, texRGBA);
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);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
testImage.data());
EXPECT_GL_NO_ERROR();
}
GLTexture texBGRA;
{
std::array<GLColor, 4> testImage2 = testImage;
for (auto &color : testImage2)
{
color = rgbswap(color);
}
glBindTexture(GL_TEXTURE_2D, texBGRA);
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);
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, 2, 2, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE,
testImage2.data());
EXPECT_GL_NO_ERROR();
}
GLColor clearColor = GLColor(102, 102, 102, 255);
clearGLColor(clearColor);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GEQUAL, 0.9f);
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);
std::array<GLuint, 8> draws = {
texRGBA.get(), texBGRA.get(), texRGBA.get(), texRGBA.get(),
texBGRA.get(), texBGRA.get(), texRGBA.get(), texBGRA.get(),
};
for (auto tex : draws)
{
glBindTexture(GL_TEXTURE_2D, tex);
glDrawArrays(GL_TRIANGLE_STRIP, 0, vertices.size());
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_NEAR(8, 8, testImage[0], 0);
EXPECT_PIXEL_COLOR_NEAR(24, 8, testImage[1], 0);
EXPECT_PIXEL_COLOR_NEAR(8, 24, testImage[2], 0);
EXPECT_PIXEL_COLOR_NEAR(24, 24, clearColor, 0);
}
}
ANGLE_INSTANTIATE_TEST_ES1(BGRATextureTest);