From 4001b1bb4d54f1885fcd90650ec1f817adfe1117 Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Wed, 4 Oct 2023 19:12:38 +0300 Subject: [PATCH] Fixed offscreen unit tests (#1723) --- .../renderer/sources/render_image_source.cpp | 2 ++ test/renderer/shader_registry.test.cpp | 12 ++++++++++ test/util/offscreen_texture.test.cpp | 24 ++++++++++--------- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/mbgl/renderer/sources/render_image_source.cpp b/src/mbgl/renderer/sources/render_image_source.cpp index 5fd73e490..6c23c386c 100644 --- a/src/mbgl/renderer/sources/render_image_source.cpp +++ b/src/mbgl/renderer/sources/render_image_source.cpp @@ -24,11 +24,13 @@ void ImageSourceRenderData::upload(gfx::UploadPass& uploadPass) const { bucket->upload(uploadPass); } +#if MLN_LEGACY_RENDERER if (!debugTexture) { std::array data{{0, 0, 0, 0}}; static const PremultipliedImage emptyImage{Size(1, 1), data.data(), data.size()}; debugTexture = uploadPass.createTexture(emptyImage); } +#endif } void ImageSourceRenderData::render(PaintParameters& parameters) const { diff --git a/test/renderer/shader_registry.test.cpp b/test/renderer/shader_registry.test.cpp index ee362370a..d9ecd1ee3 100644 --- a/test/renderer/shader_registry.test.cpp +++ b/test/renderer/shader_registry.test.cpp @@ -207,7 +207,11 @@ TEST(ShaderRegistry, NamedReplace) { } // Test replacing an actual program instance with a similar instance +#if MLN_LEGACY_RENDERER TEST(ShaderRegistry, GLSLReplacement_NoOp) { +#else +TEST(ShaderRegistry, DISABLED_GLSLReplacement_NoOp) { +#endif MapInstance::ShaderAndStyleObserver observer; util::RunLoop runLoop; auto map = MapInstance(1.0f, observer); @@ -233,7 +237,11 @@ TEST(ShaderRegistry, GLSLReplacement_NoOp) { // Test replacing an actual program with a similar instance using a different // fragment shader +#if MLN_LEGACY_RENDERER TEST(ShaderRegistry, GLSLReplacement1) { +#else +TEST(ShaderRegistry, DISABLED_GLSLReplacement1) { +#endif MapInstance::ShaderAndStyleObserver observer; util::RunLoop runLoop; auto map = MapInstance(1.0f, observer); @@ -267,7 +275,11 @@ void main() { // Test replacing an actual program with a similar instance using a different // fragment shader +#if MLN_LEGACY_RENDERER TEST(ShaderRegistry, GLSLReplacement2) { +#else +TEST(ShaderRegistry, DISABLED_GLSLReplacement2) { +#endif MapInstance::ShaderAndStyleObserver observer; util::RunLoop runLoop; auto map = MapInstance(1.0f, observer); diff --git a/test/util/offscreen_texture.test.cpp b/test/util/offscreen_texture.test.cpp index adf3f3dce..282579101 100644 --- a/test/util/offscreen_texture.test.cpp +++ b/test/util/offscreen_texture.test.cpp @@ -4,12 +4,17 @@ #include #include #include -#include #include #include #include #include +#if MLN_LEGACY_RENDERER +#include +#else +#include +#endif + using namespace mbgl; using namespace mbgl::platform; @@ -75,11 +80,7 @@ struct Buffer { GLuint buffer = 0; }; -#if MLN_LEGACY_RENDERER TEST(OffscreenTexture, RenderToTexture) { -#else -TEST(OffscreenTexture, DISABLED_RenderToTexture) { -#endif if (gfx::Backend::GetType() != gfx::Backend::Type::OpenGL) { return; } @@ -145,13 +146,13 @@ void main() { // Then, create a texture, bind it, and render yellow to that texture. This // should not affect the originally bound FBO. - gl::OffscreenTexture texture(context, {128, 128}); + gl::OffscreenTexture offscreenTexture(context, {128, 128}); // Scissor test shouldn't leak after OffscreenTexture::bind(). MBGL_CHECK_ERROR(glScissor(32, 32, 64, 64)); context.scissorTest.setCurrentValue(true); - texture.getResource().bind(); + offscreenTexture.getResource().bind(); context.clear(Color(), {}, {}); @@ -161,7 +162,7 @@ void main() { MBGL_CHECK_ERROR(glVertexAttribPointer(paintShader.a_pos, 2, GL_FLOAT, GL_FALSE, 0, nullptr)); MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, 3)); - auto image = texture.readStillImage(); + auto image = offscreenTexture.readStillImage(); test::checkImage("test/fixtures/offscreen_texture/render-to-texture", image, 0, 0); // Now reset the FBO back to normal and retrieve the original (restored) framebuffer. @@ -172,12 +173,13 @@ void main() { // Now, composite the Framebuffer texture we've rendered to onto the main FBO. #if MLN_LEGACY_RENDERER - gl::bindTexture(context, 0, {texture.getTexture().getResource(), gfx::TextureFilterType::Linear}); + gl::bindTexture(context, 0, {offscreenTexture.getTexture().getResource(), gfx::TextureFilterType::Linear}); + MBGL_CHECK_ERROR(glUniform1i(u_texture, 0)); #else - // TODO: Implement based on gfx::Texture2D + offscreenTexture.getTexture()->setSamplerConfiguration({gfx::TextureFilterType::Linear}); + std::static_pointer_cast(offscreenTexture.getTexture())->bind(u_texture, 0); #endif MBGL_CHECK_ERROR(glUseProgram(compositeShader.program)); - MBGL_CHECK_ERROR(glUniform1i(u_texture, 0)); MBGL_CHECK_ERROR(glBindBuffer(GL_ARRAY_BUFFER, viewportBuffer.buffer)); MBGL_CHECK_ERROR(glEnableVertexAttribArray(compositeShader.a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(compositeShader.a_pos, 2, GL_FLOAT, GL_FALSE, 0, nullptr));