From 94f06877d8d611fe15aee3733b6b6a1789cbbdd1 Mon Sep 17 00:00:00 2001 From: domrjchen Date: Thu, 3 Mar 2022 13:42:39 +0800 Subject: [PATCH] Clean up the references to the internal classes of tgfx. --- CMakeLists.txt | 4 +- .../filters/DisplacementMapFilter.cpp | 2 +- src/rendering/filters/LayerFilter.cpp | 13 +- src/rendering/filters/MotionBlurFilter.cpp | 6 +- .../filters/glow/GlowMergeFilter.cpp | 2 +- src/rendering/filters/utils/FilterBuffer.cpp | 9 +- src/rendering/filters/utils/FilterBuffer.h | 1 - src/rendering/filters/utils/FilterHelper.cpp | 134 +++++++++++++++++- src/rendering/filters/utils/FilterHelper.h | 17 ++- src/rendering/renderers/FilterRenderer.cpp | 1 - test/framework/utils/PAGTestUtils.cpp | 19 +++ test/framework/utils/PAGTestUtils.h | 2 + tgfx/{src => include}/gpu/Caps.h | 1 + tgfx/include/gpu/Context.h | 3 +- tgfx/src/gpu/opengl/GLCaps.h | 1 - tgfx/src/gpu/opengl/GLUtil.cpp | 61 -------- tgfx/src/gpu/opengl/GLUtil.h | 6 - 17 files changed, 186 insertions(+), 96 deletions(-) rename tgfx/{src => include}/gpu/Caps.h (96%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 84387b364b..c3cb5cfae4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,7 +119,7 @@ set(TGFX_USE_WEBP_ENCODE ${PAG_USE_WEBP_ENCODE}) set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) add_subdirectory(tgfx/ EXCLUDE_FROM_ALL) -list(APPEND PAG_INCLUDES tgfx/include tgfx/src) +list(APPEND PAG_INCLUDES tgfx/include) if (PAG_USE_LIBAVC) add_definitions(-DPAG_USE_LIBAVC) @@ -352,7 +352,7 @@ if (PAG_BUILD_TESTS) file(GLOB FFAVC_LIB vendor/ffavc/${LIBRARY_ENTRY}/*${CMAKE_SHARED_LIBRARY_SUFFIX}) list(APPEND TEST_PLATFORM_LIBS ${FFAVC_LIB}) - list(APPEND TEST_INCLUDES vendor/ffavc/include) + list(APPEND TEST_INCLUDES tgfx/src vendor/ffavc/include) add_executable(PAGUnitTest ${Test_VENDOR_TARGET} ${PAG_TEST_FILES}) target_include_directories(PAGUnitTest PUBLIC ${TEST_INCLUDES}) diff --git a/src/rendering/filters/DisplacementMapFilter.cpp b/src/rendering/filters/DisplacementMapFilter.cpp index 8cc7bbbe8a..b964c51a0f 100644 --- a/src/rendering/filters/DisplacementMapFilter.cpp +++ b/src/rendering/filters/DisplacementMapFilter.cpp @@ -121,7 +121,7 @@ void DisplacementMapFilter::updateMapTexture(RenderCache* cache, const Graphic* void DisplacementMapFilter::onUpdateParams(tgfx::Context* context, const tgfx::Rect& contentBounds, const tgfx::Point&) { auto* pagEffect = reinterpret_cast(effect); - tgfx::GLContext::Unwrap(context)->bindTexture(1, mapSurface->getTexture()->getSampler()); + ActiveGLTexture(context, 1, mapSurface->getTexture()->getSampler()); auto gl = tgfx::GLFunctions::Get(context); gl->uniform2f(useForDisplacementHandle, pagEffect->useForHorizontalDisplacement->getValueAt(layerFrame), diff --git a/src/rendering/filters/LayerFilter.cpp b/src/rendering/filters/LayerFilter.cpp index 8065d24bab..1ca5095999 100644 --- a/src/rendering/filters/LayerFilter.cpp +++ b/src/rendering/filters/LayerFilter.cpp @@ -81,14 +81,13 @@ std::shared_ptr FilterProgram::Make(tgfx::Context* context, const std::string& vertex, const std::string& fragment) { auto gl = tgfx::GLFunctions::Get(context); - auto caps = tgfx::GLCaps::Get(context); - auto program = tgfx::CreateGLProgram(context, vertex, fragment); + auto program = CreateGLProgram(context, vertex, fragment); if (program == 0) { return nullptr; } auto filterProgram = new FilterProgram(); filterProgram->program = program; - if (caps->vertexArrayObjectSupport) { + if (gl->bindVertexArray != nullptr) { gl->genVertexArrays(1, &filterProgram->vertexArray); } gl->genBuffers(1, &filterProgram->vertexBuffer); @@ -205,16 +204,14 @@ void LayerFilter::update(Frame frame, const tgfx::Rect& inputBounds, const tgfx: } static void EnableMultisample(tgfx::Context* context, bool usesMSAA) { - auto caps = tgfx::GLCaps::Get(context); - if (usesMSAA && caps->multisampleDisableSupport) { + if (usesMSAA && context->caps()->multisampleDisableSupport) { auto gl = tgfx::GLFunctions::Get(context); gl->enable(GL_MULTISAMPLE); } } static void DisableMultisample(tgfx::Context* context, bool usesMSAA) { - auto caps = tgfx::GLCaps::Get(context); - if (usesMSAA && caps->multisampleDisableSupport) { + if (usesMSAA && context->caps()->multisampleDisableSupport) { auto gl = tgfx::GLFunctions::Get(context); gl->disable(GL_MULTISAMPLE); } @@ -237,7 +234,7 @@ void LayerFilter::draw(tgfx::Context* context, const FilterSource* source, gl->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); gl->bindFramebuffer(GL_FRAMEBUFFER, target->frameBuffer.id); gl->viewport(0, 0, target->width, target->height); - tgfx::GLContext::Unwrap(context)->bindTexture(0, &source->sampler); + ActiveGLTexture(context, 0, &source->sampler); gl->uniformMatrix3fv(vertexMatrixHandle, 1, GL_FALSE, target->vertexMatrix.data()); gl->uniformMatrix3fv(textureMatrixHandle, 1, GL_FALSE, source->textureMatrix.data()); onUpdateParams(context, contentBounds, filterScale); diff --git a/src/rendering/filters/MotionBlurFilter.cpp b/src/rendering/filters/MotionBlurFilter.cpp index be92a2cfb9..929ea8a672 100644 --- a/src/rendering/filters/MotionBlurFilter.cpp +++ b/src/rendering/filters/MotionBlurFilter.cpp @@ -131,10 +131,8 @@ void MotionBlurFilter::onUpdateParams(tgfx::Context* context, const tgfx::Rect& previousMatrix.preTranslate(contentBounds.left, contentBounds.top); currentMatrix.preTranslate(contentBounds.left, contentBounds.top); - std::array previousGLMatrix = - tgfx::ToGLTextureMatrix(previousMatrix, width, height, origin); - std::array currentGLMatrix = - tgfx::ToGLTextureMatrix(currentMatrix, width, height, origin); + std::array previousGLMatrix = ToGLTextureMatrix(previousMatrix, width, height, origin); + std::array currentGLMatrix = ToGLTextureMatrix(currentMatrix, width, height, origin); auto scaling = (previousMatrix.getScaleX() != currentMatrix.getScaleX() || previousMatrix.getScaleY() != currentMatrix.getScaleY()); diff --git a/src/rendering/filters/glow/GlowMergeFilter.cpp b/src/rendering/filters/glow/GlowMergeFilter.cpp index 366f72894a..9f5fe60888 100644 --- a/src/rendering/filters/glow/GlowMergeFilter.cpp +++ b/src/rendering/filters/glow/GlowMergeFilter.cpp @@ -70,6 +70,6 @@ void GlowMergeFilter::onUpdateParams(tgfx::Context* context, const tgfx::Rect&, // TODO(domrjchen): 下面这行之前写成了 gl->uniform1i(progressHandle, 1), 会导致 glError, // 暂时注释掉。目前的发光效果跟 AE 也没有对齐,后面重写发光效果时时再修复。 // gl->uniform1i(blurTextureHandle, 1); - tgfx::GLContext::Unwrap(context)->bindTexture(1, &blurTexture); + ActiveGLTexture(context, 1, &blurTexture); } } // namespace pag diff --git a/src/rendering/filters/utils/FilterBuffer.cpp b/src/rendering/filters/utils/FilterBuffer.cpp index ae261543eb..c19d8c0443 100644 --- a/src/rendering/filters/utils/FilterBuffer.cpp +++ b/src/rendering/filters/utils/FilterBuffer.cpp @@ -17,6 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "FilterBuffer.h" +#include "FilterHelper.h" namespace pag { std::shared_ptr FilterBuffer::Make(tgfx::Context* context, int width, int height, @@ -52,8 +53,8 @@ std::unique_ptr FilterBuffer::toFilterSource(const tgfx::Point& sc filterSource->height = surface->height(); filterSource->scale = scale; // TODO(domrjchen): 这里的 ImageOrigin 是错的 - filterSource->textureMatrix = tgfx::ToGLTextureMatrix( - tgfx::Matrix::I(), surface->width(), surface->height(), tgfx::ImageOrigin::BottomLeft); + filterSource->textureMatrix = ToGLTextureMatrix(tgfx::Matrix::I(), surface->width(), + surface->height(), tgfx::ImageOrigin::BottomLeft); return std::unique_ptr(filterSource); } @@ -63,8 +64,8 @@ std::unique_ptr FilterBuffer::toFilterTarget( filterTarget->frameBuffer = getFramebuffer(); filterTarget->width = surface->width(); filterTarget->height = surface->height(); - filterTarget->vertexMatrix = tgfx::ToGLVertexMatrix( - drawingMatrix, surface->width(), surface->height(), tgfx::ImageOrigin::BottomLeft); + filterTarget->vertexMatrix = ToGLVertexMatrix(drawingMatrix, surface->width(), surface->height(), + tgfx::ImageOrigin::BottomLeft); return std::unique_ptr(filterTarget); } } // namespace pag diff --git a/src/rendering/filters/utils/FilterBuffer.h b/src/rendering/filters/utils/FilterBuffer.h index f353608f3e..2acf460cbc 100644 --- a/src/rendering/filters/utils/FilterBuffer.h +++ b/src/rendering/filters/utils/FilterBuffer.h @@ -20,7 +20,6 @@ #include "gpu/Surface.h" #include "gpu/opengl/GLRenderTarget.h" -#include "gpu/opengl/GLUtil.h" #include "pag/file.h" #include "pag/pag.h" #include "rendering/filters/Filter.h" diff --git a/src/rendering/filters/utils/FilterHelper.cpp b/src/rendering/filters/utils/FilterHelper.cpp index 88813f58cf..e85abb328a 100644 --- a/src/rendering/filters/utils/FilterHelper.cpp +++ b/src/rendering/filters/utils/FilterHelper.cpp @@ -17,10 +17,62 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "FilterHelper.h" -#include "gpu/opengl/GLSurface.h" +#include "base/utils/USE.h" +#include "gpu/Surface.h" +#include "gpu/opengl/GLRenderTarget.h" #include "gpu/opengl/GLTexture.h" namespace pag { +static std::array ToGLMatrix(const tgfx::Matrix& matrix) { + float values[9]; + matrix.get9(values); + return {values[0], values[3], values[6], values[1], values[4], + values[7], values[2], values[5], values[8]}; +} + +std::array ToGLVertexMatrix(const tgfx::Matrix& matrix, int width, int height, + tgfx::ImageOrigin origin) { + auto w = static_cast(width); + auto h = static_cast(height); + auto result = matrix; + tgfx::Matrix convertMatrix = {}; + // The following is equivalent: + // convertMatrix.setScale(1.0f, -1.0f); + // convertMatrix.postTranslate(1.0f, 1.0f); + // convertMatrix.postScale(width/2.0f, height/2f); + convertMatrix.setAll(w * 0.5f, 0.0f, w * 0.5f, 0.0f, h * -0.5f, h * 0.5f, 0.0f, 0.0f, 1.0f); + result.preConcat(convertMatrix); + if (convertMatrix.invert(&convertMatrix)) { + result.postConcat(convertMatrix); + } + if (origin == tgfx::ImageOrigin::TopLeft) { + result.postScale(1.0f, -1.0f); + } + return ToGLMatrix(result); +} + +std::array ToGLTextureMatrix(const tgfx::Matrix& matrix, int width, int height, + tgfx::ImageOrigin origin) { + auto w = static_cast(width); + auto h = static_cast(height); + auto result = matrix; + tgfx::Matrix convertMatrix = {}; + // The following is equivalent: + // convertMatrix.setScale(1.0f, -1.0f); + // convertMatrix.postTranslate(0.0f, 1.0f); + // convertMatrix.postScale(width, height); + convertMatrix.setAll(w, 0.0f, 0.0f, 0.0f, -h, h, 0.0f, 0.0f, 1.0f); + result.preConcat(convertMatrix); + if (convertMatrix.invert(&convertMatrix)) { + result.postConcat(convertMatrix); + } + if (origin == tgfx::ImageOrigin::TopLeft) { + result.postScale(1.0f, -1.0f); + result.postTranslate(0.0f, 1.0f); + } + return ToGLMatrix(result); +} + tgfx::Matrix ToMatrix(const FilterTarget* target, bool flipY) { tgfx::Matrix matrix = {}; auto values = target->vertexMatrix; @@ -90,7 +142,83 @@ tgfx::Point ToGLVertexPoint(const FilterTarget* target, const FilterSource* sour void PreConcatMatrix(FilterTarget* target, const tgfx::Matrix& matrix) { auto vertexMatrix = ToMatrix(target); vertexMatrix.preConcat(matrix); - target->vertexMatrix = tgfx::ToGLVertexMatrix(vertexMatrix, target->width, target->height, - tgfx::ImageOrigin::BottomLeft); + target->vertexMatrix = + ToGLVertexMatrix(vertexMatrix, target->width, target->height, tgfx::ImageOrigin::BottomLeft); +} + +static unsigned LoadGLShader(tgfx::Context* context, unsigned shaderType, + const std::string& source) { + auto gl = tgfx::GLFunctions::Get(context); + auto shader = gl->createShader(shaderType); + const char* files[] = {source.c_str()}; + gl->shaderSource(shader, 1, files, nullptr); + gl->compileShader(shader); + int success; + gl->getShaderiv(shader, GL_COMPILE_STATUS, &success); + if (!success) { + char infoLog[512]; + gl->getShaderInfoLog(shader, 512, nullptr, infoLog); + LOGE("Could not compile shader: %d %s", shaderType, infoLog); + gl->deleteShader(shader); + shader = 0; + } + return shader; +} + +unsigned CreateGLProgram(tgfx::Context* context, const std::string& vertex, + const std::string& fragment) { + auto vertexShader = LoadGLShader(context, GL_VERTEX_SHADER, vertex); + if (vertexShader == 0) { + return 0; + } + auto fragmentShader = LoadGLShader(context, GL_FRAGMENT_SHADER, fragment); + if (fragmentShader == 0) { + return 0; + } + auto gl = tgfx::GLFunctions::Get(context); + auto programHandle = gl->createProgram(); + gl->attachShader(programHandle, vertexShader); + gl->attachShader(programHandle, fragmentShader); + gl->linkProgram(programHandle); + int success; + gl->getProgramiv(programHandle, GL_LINK_STATUS, &success); + if (!success) { + char infoLog[512]; + gl->getProgramInfoLog(programHandle, 512, nullptr, infoLog); + gl->deleteProgram(programHandle); + } + gl->deleteShader(vertexShader); + gl->deleteShader(fragmentShader); + return programHandle; +} + +void ActiveGLTexture(tgfx::Context* context, int unitIndex, const tgfx::TextureSampler* sampler) { + if (sampler == nullptr) { + return; + } + auto glSampler = static_cast(sampler); + auto gl = tgfx::GLFunctions::Get(context); + gl->activeTexture(GL_TEXTURE0 + unitIndex); + gl->bindTexture(glSampler->target, glSampler->id); + gl->texParameteri(glSampler->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gl->texParameteri(glSampler->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + gl->texParameteri(glSampler->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + gl->texParameteri(glSampler->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +} + +bool CheckGLError(tgfx::Context* context) { +#ifdef PAG_BUILD_FOR_WEB + USE(context); + return true; +#else + auto gl = tgfx::GLFunctions::Get(context); + bool success = true; + unsigned errorCode; + while ((errorCode = gl->getError()) != GL_NO_ERROR) { + success = false; + LOGE("glCheckError: %d", errorCode); + } + return success; +#endif } } // namespace pag diff --git a/src/rendering/filters/utils/FilterHelper.h b/src/rendering/filters/utils/FilterHelper.h index 6dbf4aee6a..00af1dc68a 100644 --- a/src/rendering/filters/utils/FilterHelper.h +++ b/src/rendering/filters/utils/FilterHelper.h @@ -18,14 +18,21 @@ #pragma once +#include "base/utils/Log.h" #include "base/utils/TGFXCast.h" #include "gpu/Texture.h" -#include "gpu/opengl/GLUtil.h" +#include "gpu/opengl/GLFunctions.h" #include "pag/file.h" #include "pag/pag.h" #include "rendering/filters/Filter.h" namespace pag { +std::array ToGLVertexMatrix(const tgfx::Matrix& matrix, int width, int height, + tgfx::ImageOrigin origin); + +std::array ToGLTextureMatrix(const tgfx::Matrix& matrix, int width, int height, + tgfx::ImageOrigin origin); + tgfx::Matrix ToMatrix(const FilterTarget* target, bool flipY = false); std::unique_ptr ToFilterSource(const tgfx::Texture* texture, @@ -40,4 +47,12 @@ tgfx::Point ToGLVertexPoint(const FilterTarget* target, const FilterSource* sour const tgfx::Rect& contentBounds, const tgfx::Point& contentPoint); void PreConcatMatrix(FilterTarget* target, const tgfx::Matrix& matrix); + +unsigned CreateGLProgram(tgfx::Context* context, const std::string& vertex, + const std::string& fragment); + +void ActiveGLTexture(tgfx::Context* context, int unitIndex, const tgfx::TextureSampler* sampler); + +bool CheckGLError(tgfx::Context* context); + } // namespace pag diff --git a/src/rendering/renderers/FilterRenderer.cpp b/src/rendering/renderers/FilterRenderer.cpp index 7bfa190ec2..78910c1f54 100644 --- a/src/rendering/renderers/FilterRenderer.cpp +++ b/src/rendering/renderers/FilterRenderer.cpp @@ -19,7 +19,6 @@ #include "FilterRenderer.h" #include "base/utils/MatrixUtil.h" #include "gpu/Surface.h" -#include "gpu/opengl/GLContext.h" #include "rendering/caches/LayerCache.h" #include "rendering/caches/RenderCache.h" #include "rendering/filters/DisplacementMapFilter.h" diff --git a/test/framework/utils/PAGTestUtils.cpp b/test/framework/utils/PAGTestUtils.cpp index 70ea8e7183..1411dc3efe 100644 --- a/test/framework/utils/PAGTestUtils.cpp +++ b/test/framework/utils/PAGTestUtils.cpp @@ -19,6 +19,7 @@ #include "PAGTestUtils.h" #include "base/utils/TGFXCast.h" #include "core/Image.h" +#include "gpu/opengl/GLFunctions.h" namespace pag { using namespace tgfx; @@ -56,4 +57,22 @@ std::shared_ptr GetLayer(std::shared_ptr root, LayerTy } return nullptr; } + +bool CreateGLTexture(Context* context, int width, int height, GLSampler* texture) { + texture->target = GL_TEXTURE_2D; + texture->format = PixelFormat::RGBA_8888; + auto gl = GLFunctions::Get(context); + gl->genTextures(1, &texture->id); + if (texture->id <= 0) { + return false; + } + gl->bindTexture(texture->target, texture->id); + gl->texParameteri(texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gl->texParameteri(texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + gl->texParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + gl->texParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + gl->texImage2D(texture->target, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); + gl->bindTexture(texture->target, 0); + return true; +} } // namespace pag \ No newline at end of file diff --git a/test/framework/utils/PAGTestUtils.h b/test/framework/utils/PAGTestUtils.h index 102f20cce0..696013dd93 100644 --- a/test/framework/utils/PAGTestUtils.h +++ b/test/framework/utils/PAGTestUtils.h @@ -30,4 +30,6 @@ std::shared_ptr MakeSnapshot(std::shared_ptr pagS std::shared_ptr GetLayer(std::shared_ptr root, LayerType type, int& targetIndex); + +bool CreateGLTexture(tgfx::Context* context, int width, int height, tgfx::GLSampler* texture); } // namespace pag diff --git a/tgfx/src/gpu/Caps.h b/tgfx/include/gpu/Caps.h similarity index 96% rename from tgfx/src/gpu/Caps.h rename to tgfx/include/gpu/Caps.h index 97571d0e7a..6b0f27d27b 100644 --- a/tgfx/src/gpu/Caps.h +++ b/tgfx/include/gpu/Caps.h @@ -23,5 +23,6 @@ class Caps { public: bool floatIs32Bits = true; int maxTextureSize = 0; + bool multisampleDisableSupport = false; }; } // namespace tgfx diff --git a/tgfx/include/gpu/Context.h b/tgfx/include/gpu/Context.h index 39f73b7eae..a784e1a44f 100644 --- a/tgfx/include/gpu/Context.h +++ b/tgfx/include/gpu/Context.h @@ -21,6 +21,7 @@ #include "core/BytesKey.h" #include "core/Color.h" #include "gpu/Backend.h" +#include "gpu/Caps.h" #include "gpu/Device.h" namespace tgfx { @@ -30,8 +31,6 @@ class GradientCache; class ResourceCache; -class Caps; - class Context { public: virtual ~Context(); diff --git a/tgfx/src/gpu/opengl/GLCaps.h b/tgfx/src/gpu/opengl/GLCaps.h index 0eb4870288..2633fa9a5a 100644 --- a/tgfx/src/gpu/opengl/GLCaps.h +++ b/tgfx/src/gpu/opengl/GLCaps.h @@ -117,7 +117,6 @@ class GLCaps : public Caps { bool packRowLengthSupport = false; bool unpackRowLengthSupport = false; bool textureRedSupport = false; - bool multisampleDisableSupport = false; MSFBOType msFBOType = MSFBOType::None; bool frameBufferFetchSupport = false; bool frameBufferFetchRequiresEnablePerSample = false; diff --git a/tgfx/src/gpu/opengl/GLUtil.cpp b/tgfx/src/gpu/opengl/GLUtil.cpp index e50296043e..c53023a43d 100644 --- a/tgfx/src/gpu/opengl/GLUtil.cpp +++ b/tgfx/src/gpu/opengl/GLUtil.cpp @@ -51,24 +51,6 @@ GLVersion GetGLVersion(const char* versionString) { return {}; } -bool CreateGLTexture(Context* context, int width, int height, GLSampler* texture) { - texture->target = GL_TEXTURE_2D; - texture->format = PixelFormat::RGBA_8888; - auto gl = GLFunctions::Get(context); - gl->genTextures(1, &texture->id); - if (texture->id <= 0) { - return false; - } - gl->bindTexture(texture->target, texture->id); - gl->texParameteri(texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - gl->texParameteri(texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - gl->texParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - gl->texParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - gl->texImage2D(texture->target, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); - gl->bindTexture(texture->target, 0); - return true; -} - void SubmitGLTexture(Context* context, const GLSampler& sampler, int width, int height, size_t rowBytes, int bytesPerPixel, void* pixels) { if (pixels == nullptr || rowBytes == 0) { @@ -167,47 +149,4 @@ std::array ToGLMatrix(const Matrix& matrix) { return {values[0], values[3], values[6], values[1], values[4], values[7], values[2], values[5], values[8]}; } - -std::array ToGLVertexMatrix(const Matrix& matrix, int width, int height, - ImageOrigin origin) { - auto w = static_cast(width); - auto h = static_cast(height); - auto result = matrix; - Matrix convertMatrix = {}; - // The following is equivalent: - // convertMatrix.setScale(1.0f, -1.0f); - // convertMatrix.postTranslate(1.0f, 1.0f); - // convertMatrix.postScale(width/2.0f, height/2f); - convertMatrix.setAll(w * 0.5f, 0.0f, w * 0.5f, 0.0f, h * -0.5f, h * 0.5f, 0.0f, 0.0f, 1.0f); - result.preConcat(convertMatrix); - if (convertMatrix.invert(&convertMatrix)) { - result.postConcat(convertMatrix); - } - if (origin == ImageOrigin::TopLeft) { - result.postScale(1.0f, -1.0f); - } - return ToGLMatrix(result); -} - -std::array ToGLTextureMatrix(const Matrix& matrix, int width, int height, - ImageOrigin origin) { - auto w = static_cast(width); - auto h = static_cast(height); - auto result = matrix; - Matrix convertMatrix = {}; - // The following is equivalent: - // convertMatrix.setScale(1.0f, -1.0f); - // convertMatrix.postTranslate(0.0f, 1.0f); - // convertMatrix.postScale(width, height); - convertMatrix.setAll(w, 0.0f, 0.0f, 0.0f, -h, h, 0.0f, 0.0f, 1.0f); - result.preConcat(convertMatrix); - if (convertMatrix.invert(&convertMatrix)) { - result.postConcat(convertMatrix); - } - if (origin == ImageOrigin::TopLeft) { - result.postScale(1.0f, -1.0f); - result.postTranslate(0.0f, 1.0f); - } - return ToGLMatrix(result); -} } // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLUtil.h b/tgfx/src/gpu/opengl/GLUtil.h index 6d63506ec3..2a4e534abe 100644 --- a/tgfx/src/gpu/opengl/GLUtil.h +++ b/tgfx/src/gpu/opengl/GLUtil.h @@ -44,14 +44,8 @@ unsigned LoadGLShader(Context* context, unsigned shaderType, const std::string& bool CheckGLError(Context* context); -bool CreateGLTexture(Context* context, int width, int height, GLSampler* texture); - void SubmitGLTexture(Context* context, const GLSampler& sampler, int width, int height, size_t rowBytes, int bytesPerPixel, void* pixels); std::array ToGLMatrix(const Matrix& matrix); -std::array ToGLVertexMatrix(const Matrix& matrix, int width, int height, - ImageOrigin origin); -std::array ToGLTextureMatrix(const Matrix& matrix, int width, int height, - ImageOrigin origin); } // namespace tgfx