Fixed offscreen unit tests (#1723)
This commit is contained in:
@@ -24,11 +24,13 @@ void ImageSourceRenderData::upload(gfx::UploadPass& uploadPass) const {
|
|||||||
bucket->upload(uploadPass);
|
bucket->upload(uploadPass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MLN_LEGACY_RENDERER
|
||||||
if (!debugTexture) {
|
if (!debugTexture) {
|
||||||
std::array<uint8_t, 4> data{{0, 0, 0, 0}};
|
std::array<uint8_t, 4> data{{0, 0, 0, 0}};
|
||||||
static const PremultipliedImage emptyImage{Size(1, 1), data.data(), data.size()};
|
static const PremultipliedImage emptyImage{Size(1, 1), data.data(), data.size()};
|
||||||
debugTexture = uploadPass.createTexture(emptyImage);
|
debugTexture = uploadPass.createTexture(emptyImage);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageSourceRenderData::render(PaintParameters& parameters) const {
|
void ImageSourceRenderData::render(PaintParameters& parameters) const {
|
||||||
|
|||||||
@@ -207,7 +207,11 @@ TEST(ShaderRegistry, NamedReplace) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test replacing an actual program instance with a similar instance
|
// Test replacing an actual program instance with a similar instance
|
||||||
|
#if MLN_LEGACY_RENDERER
|
||||||
TEST(ShaderRegistry, GLSLReplacement_NoOp) {
|
TEST(ShaderRegistry, GLSLReplacement_NoOp) {
|
||||||
|
#else
|
||||||
|
TEST(ShaderRegistry, DISABLED_GLSLReplacement_NoOp) {
|
||||||
|
#endif
|
||||||
MapInstance::ShaderAndStyleObserver observer;
|
MapInstance::ShaderAndStyleObserver observer;
|
||||||
util::RunLoop runLoop;
|
util::RunLoop runLoop;
|
||||||
auto map = MapInstance(1.0f, observer);
|
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
|
// Test replacing an actual program with a similar instance using a different
|
||||||
// fragment shader
|
// fragment shader
|
||||||
|
#if MLN_LEGACY_RENDERER
|
||||||
TEST(ShaderRegistry, GLSLReplacement1) {
|
TEST(ShaderRegistry, GLSLReplacement1) {
|
||||||
|
#else
|
||||||
|
TEST(ShaderRegistry, DISABLED_GLSLReplacement1) {
|
||||||
|
#endif
|
||||||
MapInstance::ShaderAndStyleObserver observer;
|
MapInstance::ShaderAndStyleObserver observer;
|
||||||
util::RunLoop runLoop;
|
util::RunLoop runLoop;
|
||||||
auto map = MapInstance(1.0f, observer);
|
auto map = MapInstance(1.0f, observer);
|
||||||
@@ -267,7 +275,11 @@ void main() {
|
|||||||
|
|
||||||
// Test replacing an actual program with a similar instance using a different
|
// Test replacing an actual program with a similar instance using a different
|
||||||
// fragment shader
|
// fragment shader
|
||||||
|
#if MLN_LEGACY_RENDERER
|
||||||
TEST(ShaderRegistry, GLSLReplacement2) {
|
TEST(ShaderRegistry, GLSLReplacement2) {
|
||||||
|
#else
|
||||||
|
TEST(ShaderRegistry, DISABLED_GLSLReplacement2) {
|
||||||
|
#endif
|
||||||
MapInstance::ShaderAndStyleObserver observer;
|
MapInstance::ShaderAndStyleObserver observer;
|
||||||
util::RunLoop runLoop;
|
util::RunLoop runLoop;
|
||||||
auto map = MapInstance(1.0f, observer);
|
auto map = MapInstance(1.0f, observer);
|
||||||
|
|||||||
@@ -4,12 +4,17 @@
|
|||||||
#include <mbgl/gfx/backend_scope.hpp>
|
#include <mbgl/gfx/backend_scope.hpp>
|
||||||
#include <mbgl/gfx/render_pass.hpp>
|
#include <mbgl/gfx/render_pass.hpp>
|
||||||
#include <mbgl/gl/context.hpp>
|
#include <mbgl/gl/context.hpp>
|
||||||
#include <mbgl/gl/texture.hpp>
|
|
||||||
#include <mbgl/gl/defines.hpp>
|
#include <mbgl/gl/defines.hpp>
|
||||||
#include <mbgl/gl/renderable_resource.hpp>
|
#include <mbgl/gl/renderable_resource.hpp>
|
||||||
#include <mbgl/gl/headless_backend.hpp>
|
#include <mbgl/gl/headless_backend.hpp>
|
||||||
#include <mbgl/gl/offscreen_texture.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;
|
||||||
using namespace mbgl::platform;
|
using namespace mbgl::platform;
|
||||||
|
|
||||||
@@ -75,11 +80,7 @@ struct Buffer {
|
|||||||
GLuint buffer = 0;
|
GLuint buffer = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if MLN_LEGACY_RENDERER
|
|
||||||
TEST(OffscreenTexture, RenderToTexture) {
|
TEST(OffscreenTexture, RenderToTexture) {
|
||||||
#else
|
|
||||||
TEST(OffscreenTexture, DISABLED_RenderToTexture) {
|
|
||||||
#endif
|
|
||||||
if (gfx::Backend::GetType() != gfx::Backend::Type::OpenGL) {
|
if (gfx::Backend::GetType() != gfx::Backend::Type::OpenGL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -145,13 +146,13 @@ void main() {
|
|||||||
|
|
||||||
// Then, create a texture, bind it, and render yellow to that texture. This
|
// Then, create a texture, bind it, and render yellow to that texture. This
|
||||||
// should not affect the originally bound FBO.
|
// 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().
|
// Scissor test shouldn't leak after OffscreenTexture::bind().
|
||||||
MBGL_CHECK_ERROR(glScissor(32, 32, 64, 64));
|
MBGL_CHECK_ERROR(glScissor(32, 32, 64, 64));
|
||||||
context.scissorTest.setCurrentValue(true);
|
context.scissorTest.setCurrentValue(true);
|
||||||
|
|
||||||
texture.getResource<gl::RenderableResource>().bind();
|
offscreenTexture.getResource<gl::RenderableResource>().bind();
|
||||||
|
|
||||||
context.clear(Color(), {}, {});
|
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(glVertexAttribPointer(paintShader.a_pos, 2, GL_FLOAT, GL_FALSE, 0, nullptr));
|
||||||
MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, 3));
|
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);
|
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.
|
// 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.
|
// Now, composite the Framebuffer texture we've rendered to onto the main FBO.
|
||||||
#if MLN_LEGACY_RENDERER
|
#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
|
#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
|
#endif
|
||||||
MBGL_CHECK_ERROR(glUseProgram(compositeShader.program));
|
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(glBindBuffer(GL_ARRAY_BUFFER, viewportBuffer.buffer));
|
||||||
MBGL_CHECK_ERROR(glEnableVertexAttribArray(compositeShader.a_pos));
|
MBGL_CHECK_ERROR(glEnableVertexAttribArray(compositeShader.a_pos));
|
||||||
MBGL_CHECK_ERROR(glVertexAttribPointer(compositeShader.a_pos, 2, GL_FLOAT, GL_FALSE, 0, nullptr));
|
MBGL_CHECK_ERROR(glVertexAttribPointer(compositeShader.a_pos, 2, GL_FLOAT, GL_FALSE, 0, nullptr));
|
||||||
|
|||||||
Reference in New Issue
Block a user