Commit 133a2ecb by Corentin Wallez Committed by Commit Bot

Implement CHROMIUM_copy_texture for OpenGL.

This also makes BlitGL work correctly on OpenGL ES (provided vertex arrays are available) BUG=angleproject:1356 Change-Id: Icb7cef35bebfe6672220aa0b312ab89187dbf585 Reviewed-on: https://chromium-review.googlesource.com/412452 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 6c1cbf51
......@@ -25,6 +25,7 @@ namespace rx
class FramebufferGL;
class FunctionsGL;
class StateManagerGL;
class TextureGL;
struct WorkaroundsGL;
class BlitGL : public angle::NonCopyable
......@@ -43,6 +44,7 @@ class BlitGL : public angle::NonCopyable
const gl::Rectangle &sourceArea,
GLenum internalFormat,
const gl::Framebuffer *source);
gl::Error copySubImageToLUMAWorkaroundTexture(GLuint texture,
GLenum textureType,
GLenum target,
......@@ -58,6 +60,22 @@ class BlitGL : public angle::NonCopyable
const gl::Rectangle &destArea,
GLenum filter);
gl::Error copySubTexture(TextureGL *source,
TextureGL *dest,
const gl::Extents &sourceSize,
const gl::Rectangle &sourceArea,
const gl::Offset &destOffset,
bool needsLumaWorkaround,
GLenum lumaFormat,
bool unpackFlipY,
bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha);
gl::Error copyTexSubImage(TextureGL *source,
TextureGL *dest,
const gl::Rectangle &sourceArea,
const gl::Offset &destOffset);
gl::Error initializeResources();
private:
......@@ -69,14 +87,18 @@ class BlitGL : public angle::NonCopyable
StateManagerGL *mStateManager;
GLuint mBlitProgram;
GLint mTexCoordAttributeLocation;
GLint mSourceTextureLocation;
GLint mScaleLocation;
GLint mOffsetLocation;
GLint mMultiplyAlphaLocation;
GLint mUnMultiplyAlphaLocation;
GLuint mScratchTextures[2];
GLuint mScratchFBO;
GLuint mVAO;
GLuint mVertexBuffer;
};
}
......
......@@ -74,6 +74,26 @@ class TextureGL : public TextureImpl
gl::Error copySubImage(GLenum target, size_t level, const gl::Offset &destOffset, const gl::Rectangle &sourceArea,
const gl::Framebuffer *source) override;
gl::Error copyTexture(GLenum internalFormat,
GLenum type,
bool unpackFlipY,
bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha,
const gl::Texture *source) override;
gl::Error copySubTexture(const gl::Offset &destOffset,
const gl::Rectangle &sourceArea,
bool unpackFlipY,
bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha,
const gl::Texture *source) override;
gl::Error copySubTextureHelper(const gl::Offset &destOffset,
const gl::Rectangle &sourceArea,
GLenum destFormat,
bool unpackFlipY,
bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha,
const gl::Texture *source);
gl::Error setStorage(GLenum target, size_t levels, GLenum internalFormat, const gl::Extents &size) override;
gl::Error setImageExternal(GLenum target,
......@@ -88,6 +108,7 @@ class TextureGL : public TextureImpl
gl::Error setEGLImageTarget(GLenum target, egl::Image *image) override;
GLuint getTextureID() const;
GLenum getTarget() const;
void setBaseLevel(GLuint) override {}
......@@ -107,6 +128,7 @@ class TextureGL : public TextureImpl
GLenum format,
GLenum type,
const uint8_t *pixels);
// This changes the current pixel unpack state that will have to be reapplied.
void reserveTexImageToBeFilled(GLenum target,
size_t level,
GLenum internalFormat,
......
......@@ -859,6 +859,8 @@ void GenerateCaps(const FunctionsGL *functions, gl::Caps *caps, gl::TextureCapsM
functions->hasGLESExtension("GL_KHR_robustness") ||
functions->hasGLESExtension("GL_EXT_robustness");
extensions->copyTexture = true;
// NV_path_rendering
// We also need interface query which is available in
// >= 4.3 core or ARB_interface_query or >= GLES 3.1
......
......@@ -532,7 +532,7 @@ TEST_P(CopyTextureTest, UnmultiplyAlpha)
}
// Test that unmultipying and premultiplying the alpha is the same as doing neither
TEST_P(CopyTextureTest, UnmultiplyAndPremultplyAlpha)
TEST_P(CopyTextureTest, UnmultiplyAndPremultiplyAlpha)
{
if (!checkExtensions())
{
......@@ -559,6 +559,74 @@ TEST_P(CopyTextureTest, UnmultiplyAndPremultplyAlpha)
EXPECT_GL_NO_ERROR();
}
// Test to ensure that CopyTexture works with LUMINANCE_ALPHA texture
TEST_P(CopyTextureTest, LuminanceAlpha)
{
if (!checkExtensions())
{
return;
}
uint8_t originalPixels[] = {163u, 67u};
GLColor expectedPixels(163u, 163u, 163u, 67u);
glBindTexture(GL_TEXTURE_2D, mTextures[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
GL_UNSIGNED_BYTE, &originalPixels);
glCopyTextureCHROMIUM(mTextures[0], mTextures[1], GL_RGBA, GL_UNSIGNED_BYTE, false, false,
false);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, expectedPixels);
}
// Test to ensure that CopyTexture works with LUMINANCE texture
TEST_P(CopyTextureTest, Luminance)
{
if (!checkExtensions())
{
return;
}
uint8_t originalPixels[] = {57u};
GLColor expectedPixels(57u, 57u, 57u, 255u);
glBindTexture(GL_TEXTURE_2D, mTextures[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE,
&originalPixels);
glCopyTextureCHROMIUM(mTextures[0], mTextures[1], GL_RGBA, GL_UNSIGNED_BYTE, false, false,
false);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, expectedPixels);
}
// Test to ensure that CopyTexture works with ALPHA texture
TEST_P(CopyTextureTest, Alpha)
{
if (!checkExtensions())
{
return;
}
uint8_t originalPixels[] = {77u};
GLColor expectedPixels(0u, 0u, 0u, 77u);
glBindTexture(GL_TEXTURE_2D, mTextures[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 1, 1, 0, GL_ALPHA, GL_UNSIGNED_BYTE, &originalPixels);
glCopyTextureCHROMIUM(mTextures[0], mTextures[1], GL_RGBA, GL_UNSIGNED_BYTE, false, false,
false);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, expectedPixels);
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these
// tests should be run against.
ANGLE_INSTANTIATE_TEST(CopyTextureTest, ES2_D3D9(), ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());
......
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