summaryrefslogtreecommitdiff
path: root/test/util
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-02-17 10:57:21 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-02-20 12:04:21 -0800
commit535457262011f3790069c8426e7b143f3aba26d0 (patch)
tree5b78cc5fc1d8215fb315952af4a0960b70e26b52 /test/util
parented7844d08f3cffaba00cc974c4ab6b26c84dd98d (diff)
downloadqtlocation-mapboxgl-535457262011f3790069c8426e7b143f3aba26d0.tar.gz
[core] Eliminate manual HeadlessBackend activation management
Diffstat (limited to 'test/util')
-rw-r--r--test/util/offscreen_texture.test.cpp88
1 files changed, 43 insertions, 45 deletions
diff --git a/test/util/offscreen_texture.test.cpp b/test/util/offscreen_texture.test.cpp
index 31fb985394..feaabf2630 100644
--- a/test/util/offscreen_texture.test.cpp
+++ b/test/util/offscreen_texture.test.cpp
@@ -4,6 +4,7 @@
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/headless_backend.hpp>
#include <mbgl/gl/offscreen_view.hpp>
+#include <mbgl/map/backend_scope.hpp>
#include <mbgl/util/offscreen_texture.hpp>
@@ -11,6 +12,7 @@ using namespace mbgl;
TEST(OffscreenTexture, EmptyRed) {
HeadlessBackend backend { test::sharedDisplay() };
+ BackendScope scope { backend };
OffscreenView view(backend.getContext(), { 512, 256 });
view.bind();
@@ -68,6 +70,7 @@ struct Buffer {
TEST(OffscreenTexture, RenderToTexture) {
HeadlessBackend backend { test::sharedDisplay() };
+ BackendScope scope { backend };
auto& context = backend.getContext();
MBGL_CHECK_ERROR(glEnable(GL_BLEND));
@@ -116,50 +119,45 @@ void main() {
Buffer triangleBuffer({ 0, 0.5, 0.5, -0.5, -0.5, -0.5 });
Buffer viewportBuffer({ -1, -1, 1, -1, -1, 1, 1, 1 });
- // Make sure the texture gets destructed before we call context.reset();
- {
- OffscreenView view(context, { 512, 256 });
- view.bind();
-
- // First, draw red to the bound FBO.
- context.clear(Color::red(), {}, {});
-
- // Then, create a texture, bind it, and render yellow to that texture. This should not
- // affect the originally bound FBO.
- OffscreenTexture texture(context, { 128, 128 });
- texture.bind();
-
- context.clear(Color(), {}, {});
-
- MBGL_CHECK_ERROR(glUseProgram(paintShader.program));
- MBGL_CHECK_ERROR(glBindBuffer(GL_ARRAY_BUFFER, triangleBuffer.buffer));
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(paintShader.a_pos));
- 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();
- 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.
- view.bind();
-
- image = view.readStillImage();
- test::checkImage("test/fixtures/offscreen_texture/render-to-fbo", image, 0, 0);
-
- // Now, composite the Framebuffer texture we've rendered to onto the main FBO.
- context.bindTexture(texture.getTexture(), 0, gl::TextureFilter::Linear);
- 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));
- MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
-
- image = view.readStillImage();
- test::checkImage("test/fixtures/offscreen_texture/render-to-fbo-composited", image, 0, 0.1);
- }
+ OffscreenView view(context, { 512, 256 });
+ view.bind();
+
+ // First, draw red to the bound FBO.
+ context.clear(Color::red(), {}, {});
+
+ // Then, create a texture, bind it, and render yellow to that texture. This should not
+ // affect the originally bound FBO.
+ OffscreenTexture texture(context, { 128, 128 });
+ texture.bind();
+
+ context.clear(Color(), {}, {});
+
+ MBGL_CHECK_ERROR(glUseProgram(paintShader.program));
+ MBGL_CHECK_ERROR(glBindBuffer(GL_ARRAY_BUFFER, triangleBuffer.buffer));
+ MBGL_CHECK_ERROR(glEnableVertexAttribArray(paintShader.a_pos));
+ 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();
+ 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.
+ view.bind();
- context.reset();
+ image = view.readStillImage();
+ test::checkImage("test/fixtures/offscreen_texture/render-to-fbo", image, 0, 0);
+
+ // Now, composite the Framebuffer texture we've rendered to onto the main FBO.
+ context.bindTexture(texture.getTexture(), 0, gl::TextureFilter::Linear);
+ 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));
+ MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
+
+ image = view.readStillImage();
+ test::checkImage("test/fixtures/offscreen_texture/render-to-fbo-composited", image, 0, 0.1);
}