Fixed offscreen unit tests (#1723)

This commit is contained in:
Alex Cristici
2023-10-04 19:12:38 +03:00
committed by GitHub
parent ef351964a1
commit 4001b1bb4d
3 changed files with 27 additions and 11 deletions

View File

@@ -4,12 +4,17 @@
#include <mbgl/gfx/backend_scope.hpp>
#include <mbgl/gfx/render_pass.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/texture.hpp>
#include <mbgl/gl/defines.hpp>
#include <mbgl/gl/renderable_resource.hpp>
#include <mbgl/gl/headless_backend.hpp>
#include <mbgl/gl/offscreen_texture.hpp>
#if MLN_LEGACY_RENDERER
#include <mbgl/gl/texture.hpp>
#else
#include <mbgl/gl/texture2d.hpp>
#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<gl::RenderableResource>().bind();
offscreenTexture.getResource<gl::RenderableResource>().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<gl::Texture2D>(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));