diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-10-10 17:16:37 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-10-25 13:52:36 -0700 |
commit | a4d259c33f9bb890bba97fd89552720e3e0ec09b (patch) | |
tree | 342ecc27a6993c48f3a2e1d739fce890350bc44d /test/util | |
parent | 5cc390d694fc7510d445310d8eb9e32429a5e67b (diff) | |
download | qtlocation-mapboxgl-a4d259c33f9bb890bba97fd89552720e3e0ec09b.tar.gz |
[core] move gl::Context to Backend and refactor View
Diffstat (limited to 'test/util')
-rw-r--r-- | test/util/memory.test.cpp | 42 | ||||
-rw-r--r-- | test/util/offscreen_texture.test.cpp | 20 |
2 files changed, 28 insertions, 34 deletions
diff --git a/test/util/memory.test.cpp b/test/util/memory.test.cpp index 2ab3a03799..a1e47d6c2b 100644 --- a/test/util/memory.test.cpp +++ b/test/util/memory.test.cpp @@ -3,7 +3,7 @@ #include <mbgl/map/map.hpp> #include <mbgl/platform/default/headless_backend.hpp> -#include <mbgl/platform/default/headless_view.hpp> +#include <mbgl/platform/default/offscreen_view.hpp> #include <mbgl/platform/default/thread_pool.hpp> #include <mbgl/util/io.hpp> #include <mbgl/util/run_loop.hpp> @@ -57,7 +57,7 @@ public: util::RunLoop runLoop; HeadlessBackend backend; - HeadlessView view{ 2 }; + OffscreenView view{ backend.getContext(), {{ 512, 512 }} }; StubFileSource fileSource; ThreadPool threadPool { 4 }; @@ -93,22 +93,20 @@ private: TEST(Memory, Vector) { MemoryTest test; - Map map(test.backend, test.view, test.view.getPixelRatio(), test.fileSource, test.threadPool, - MapMode::Still); + Map map(test.backend, { { 256, 256 } }, 2, test.fileSource, test.threadPool, MapMode::Still); map.setZoom(16); // more map features map.setStyleURL("mapbox://streets"); - test::render(map); + test::render(map, test.view); } TEST(Memory, Raster) { MemoryTest test; - Map map(test.backend, test.view, test.view.getPixelRatio(), test.fileSource, test.threadPool, - MapMode::Still); + Map map(test.backend, { { 256, 256 } }, 2, test.fileSource, test.threadPool, MapMode::Still); map.setStyleURL("mapbox://satellite"); - test::render(map); + test::render(map, test.view); } // This test will measure the size of a Map object @@ -123,19 +121,17 @@ TEST(Memory, Footprint) { MemoryTest test; - auto renderMap = [](Map* map, const char* style){ - map->setZoom(16); - - map->setStyleURL(style); - test::render(*map); + auto renderMap = [&](Map& map, const char* style){ + map.setZoom(16); + map.setStyleURL(style); + test::render(map, test.view); }; // Warm up buffers and cache. for (unsigned i = 0; i < 10; ++i) { - Map map(test.backend, test.view, test.view.getPixelRatio(), test.fileSource, - test.threadPool, MapMode::Still); - renderMap(&map, "mapbox://streets"); - renderMap(&map, "mapbox://satellite"); + Map map(test.backend, {{ 256, 256 }}, 2, test.fileSource, test.threadPool, MapMode::Still); + renderMap(map, "mapbox://streets"); + renderMap(map, "mapbox://satellite"); }; // Process close callbacks, mostly needed by @@ -147,9 +143,9 @@ TEST(Memory, Footprint) { long vectorInitialRSS = getRSS(); for (unsigned i = 0; i < runs; ++i) { - auto vector = std::make_unique<Map>(test.backend, test.view, test.view.getPixelRatio(), - test.fileSource, test.threadPool, MapMode::Still); - renderMap(vector.get(), "mapbox://streets"); + auto vector = std::make_unique<Map>(test.backend, std::array<uint16_t, 2>{ { 256, 256 } }, + 2, test.fileSource, test.threadPool, MapMode::Still); + renderMap(*vector, "mapbox://streets"); maps.push_back(std::move(vector)); }; @@ -157,9 +153,9 @@ TEST(Memory, Footprint) { long rasterInitialRSS = getRSS(); for (unsigned i = 0; i < runs; ++i) { - auto raster = std::make_unique<Map>(test.backend, test.view, test.view.getPixelRatio(), - test.fileSource, test.threadPool, MapMode::Still); - renderMap(raster.get(), "mapbox://satellite"); + auto raster = std::make_unique<Map>(test.backend, std::array<uint16_t, 2>{ { 256, 256 } }, + 2, test.fileSource, test.threadPool, MapMode::Still); + renderMap(*raster, "mapbox://satellite"); maps.push_back(std::move(raster)); }; diff --git a/test/util/offscreen_texture.test.cpp b/test/util/offscreen_texture.test.cpp index e281a3d65b..bd4eab69a8 100644 --- a/test/util/offscreen_texture.test.cpp +++ b/test/util/offscreen_texture.test.cpp @@ -2,7 +2,7 @@ #include <mbgl/gl/context.hpp> #include <mbgl/platform/default/headless_backend.hpp> -#include <mbgl/platform/default/headless_view.hpp> +#include <mbgl/platform/default/offscreen_view.hpp> #include <mbgl/gl/gl.hpp> #include <mbgl/util/offscreen_texture.hpp> @@ -11,7 +11,7 @@ using namespace mbgl; TEST(OffscreenTexture, EmptyRed) { HeadlessBackend backend; - HeadlessView view(1.0f, 512, 256); + OffscreenView view(backend.getContext(), {{ 512, 256 }}); view.bind(); MBGL_CHECK_ERROR(glClearColor(1.0f, 0.0f, 0.0f, 1.0f)); @@ -68,10 +68,7 @@ struct Buffer { TEST(OffscreenTexture, RenderToTexture) { HeadlessBackend backend; - HeadlessView view(1.0f, 512, 256); - view.bind(); - gl::Context context; - context.viewport.setDefaultValue(gl::value::Viewport::Get()); + auto& context = backend.getContext(); MBGL_CHECK_ERROR(glEnable(GL_BLEND)); MBGL_CHECK_ERROR(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); @@ -109,14 +106,17 @@ void main() { // Make sure the texture gets destructed before we call context.reset(); { + OffscreenView view(context, {{ 512, 256 }}); + // First, draw red to the bound FBO. context.clearColor = { 1, 0, 0, 1 }; + view.bind(); MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT)); // Then, create a texture, bind it, and render yellow to that texture. This should not // affect the originally bound FBO. - OffscreenTexture texture; - texture.bind(context, {{ 128, 128 }}); + OffscreenTexture texture(context, {{ 128, 128 }}); + texture.bind(); context.clearColor = { 0, 0, 0, 0 }; MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT)); @@ -128,12 +128,10 @@ void main() { glVertexAttribPointer(paintShader.a_pos, 2, GL_FLOAT, GL_FALSE, 0, nullptr)); MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, 3)); - auto image = view.readStillImage(texture.getSize()); + 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. - context.resetState(); - context.bindFramebuffer.setDirty(); view.bind(); image = view.readStillImage(); |