Commit 1d688763 by Jamie Madill Committed by Commit Bot

D3D11: Fix loading of RGBA4 textures for ubyte.

BUG=angleproject:1407 BUG=chromium:616176 Change-Id: Ibb7c5e71b4cf8afe7b7d0092e7d019b87d507ba6 Reviewed-on: https://chromium-review.googlesource.com/350905Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 193c671d
...@@ -1032,6 +1032,11 @@ ...@@ -1032,6 +1032,11 @@
"loadFunction": "LoadToNative<GLubyte,4>", "loadFunction": "LoadToNative<GLubyte,4>",
"dxgiFormat": "DXGI_FORMAT_R8G8B8A8_UNORM", "dxgiFormat": "DXGI_FORMAT_R8G8B8A8_UNORM",
"requiresConversion": "false" "requiresConversion": "false"
},
{
"loadFunction": "LoadRGBA8ToBGRA4",
"dxgiFormat": "DXGI_FORMAT_B4G4R4A4_UNORM",
"requiresConversion": "true"
} }
], ],
"GL_UNSIGNED_SHORT_4_4_4_4": [ "GL_UNSIGNED_SHORT_4_4_4_4": [
......
...@@ -1813,6 +1813,7 @@ const std::map<GLenum, LoadImageFunctionInfo> &GetLoadFunctionsMap(GLenum intern ...@@ -1813,6 +1813,7 @@ const std::map<GLenum, LoadImageFunctionInfo> &GetLoadFunctionsMap(GLenum intern
{ {
static const std::map<GLenum, LoadImageFunctionInfo> loadFunctionsMap = { static const std::map<GLenum, LoadImageFunctionInfo> loadFunctionsMap = {
{ GL_UNSIGNED_SHORT_4_4_4_4, LoadImageFunctionInfo(LoadRGBA4ToARGB4, true) }, { GL_UNSIGNED_SHORT_4_4_4_4, LoadImageFunctionInfo(LoadRGBA4ToARGB4, true) },
{ GL_UNSIGNED_BYTE, LoadImageFunctionInfo(LoadRGBA8ToBGRA4, true) },
}; };
return loadFunctionsMap; return loadFunctionsMap;
......
...@@ -348,6 +348,37 @@ void LoadRGBA8ToBGRA8(size_t width, size_t height, size_t depth, ...@@ -348,6 +348,37 @@ void LoadRGBA8ToBGRA8(size_t width, size_t height, size_t depth,
} }
} }
void LoadRGBA8ToBGRA4(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch)
{
for (size_t z = 0; z < depth; z++)
{
for (size_t y = 0; y < height; y++)
{
const uint32_t *source =
OffsetDataPointer<uint32_t>(input, y, z, inputRowPitch, inputDepthPitch);
uint16_t *dest =
OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch);
for (size_t x = 0; x < width; x++)
{
uint32_t rgba8 = source[x];
auto r4 = static_cast<uint16_t>((rgba8 & 0x000000FF) >> 4);
auto g4 = static_cast<uint16_t>((rgba8 & 0x0000FF00) >> 12);
auto b4 = static_cast<uint16_t>((rgba8 & 0x00FF0000) >> 20);
auto a4 = static_cast<uint16_t>((rgba8 & 0xFF000000) >> 28);
dest[x] = (a4 << 12) | (r4 << 8) | (g4 << 4) | b4;
}
}
}
}
void LoadRGBA4ToARGB4(size_t width, size_t height, size_t depth, void LoadRGBA4ToARGB4(size_t width, size_t height, size_t depth,
const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
......
...@@ -108,6 +108,16 @@ void LoadRGBA4ToRGBA8(size_t width, size_t height, size_t depth, ...@@ -108,6 +108,16 @@ void LoadRGBA4ToRGBA8(size_t width, size_t height, size_t depth,
const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch); uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch);
void LoadRGBA8ToBGRA4(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch);
void LoadBGRA4ToBGRA8(size_t width, size_t height, size_t depth, void LoadBGRA4ToBGRA8(size_t width, size_t height, size_t depth,
const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch); uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch);
......
...@@ -126,6 +126,10 @@ class SixteenBppTextureTest : public ANGLETest ...@@ -126,6 +126,10 @@ class SixteenBppTextureTest : public ANGLETest
GLint mTexture2DUniformLocation; GLint mTexture2DUniformLocation;
}; };
class SixteenBppTextureTestES3 : public SixteenBppTextureTest
{
};
// Simple validation test for GL_RGB565 textures. // Simple validation test for GL_RGB565 textures.
// Samples from the texture, renders to it, generates mipmaps etc. // Samples from the texture, renders to it, generates mipmaps etc.
TEST_P(SixteenBppTextureTest, RGB565Validation) TEST_P(SixteenBppTextureTest, RGB565Validation)
...@@ -281,6 +285,24 @@ TEST_P(SixteenBppTextureTest, RGBA4444Validation) ...@@ -281,6 +285,24 @@ TEST_P(SixteenBppTextureTest, RGBA4444Validation)
simpleValidationBase(tex.get()); simpleValidationBase(tex.get());
} }
// Test uploading RGBA8 data to RGBA4 textures.
TEST_P(SixteenBppTextureTestES3, RGBA4UploadRGBA8)
{
std::vector<GLColor> fourColors;
fourColors.push_back(GLColor::red);
fourColors.push_back(GLColor::green);
fourColors.push_back(GLColor::blue);
fourColors.push_back(GLColor::yellow);
GLTexture tex;
glBindTexture(GL_TEXTURE_2D, tex.get());
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA4, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, fourColors.data());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
ASSERT_GL_NO_ERROR();
simpleValidationBase(tex.get());
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
ANGLE_INSTANTIATE_TEST(SixteenBppTextureTest, ANGLE_INSTANTIATE_TEST(SixteenBppTextureTest,
ES2_D3D9(), ES2_D3D9(),
...@@ -289,4 +311,6 @@ ANGLE_INSTANTIATE_TEST(SixteenBppTextureTest, ...@@ -289,4 +311,6 @@ ANGLE_INSTANTIATE_TEST(SixteenBppTextureTest,
ES2_OPENGL(), ES2_OPENGL(),
ES2_OPENGLES()); ES2_OPENGLES());
ANGLE_INSTANTIATE_TEST(SixteenBppTextureTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
} // namespace } // namespace
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment