From 9ebf727f56819f259a7a0771b1ed58b14c3adea3 Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Thu, 13 Jul 2017 15:35:02 +0300 Subject: [core] BackendScope prevent double (de-)activation - Guards against duplicate activations by checking wether the backend of the prior scope is the same as the current ones - Makes sure that only the most outer backend scope deactivates by tracking activation state --- test/renderer/backend_scope.test.cpp | 111 +++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 test/renderer/backend_scope.test.cpp (limited to 'test/renderer/backend_scope.test.cpp') diff --git a/test/renderer/backend_scope.test.cpp b/test/renderer/backend_scope.test.cpp new file mode 100644 index 0000000000..a8c92bb31f --- /dev/null +++ b/test/renderer/backend_scope.test.cpp @@ -0,0 +1,111 @@ +#include + +#include +#include + +#include + +using namespace mbgl; + +class StubRendererBackend: public RendererBackend { +public: + + void activate() override { + if (activateFunction) activateFunction(); + } + + void deactivate() override { + if (deactivateFunction) deactivateFunction(); + } + + void updateAssumedState() override { + if (updateAssumedStateFunction) updateAssumedStateFunction(); + } + + gl::ProcAddress initializeExtension(const char* ext) override { + if (initializeExtensionFunction) { + return initializeExtensionFunction(ext); + } else { + return {}; + } + } + + std::function activateFunction; + std::function deactivateFunction; + std::function updateAssumedStateFunction; + std::function initializeExtensionFunction; +}; + +// A scope should activate on construction +// and deactivate on descruction (going out +// of scope) +TEST(BackendScope, SingleScope) { + bool activated; + bool deactivated; + + StubRendererBackend backend; + backend.activateFunction = [&] { activated = true; }; + backend.deactivateFunction = [&] { deactivated = true; }; + + { + BackendScope test { backend }; + } + + ASSERT_TRUE(activated); + ASSERT_TRUE(deactivated); +} + +// With nested scopes, only the outer scope +// should activate/deactivate +TEST(BackendScope, NestedScopes) { + int activated = 0; + int deactivated = 0; + + StubRendererBackend backend; + backend.activateFunction = [&] { activated++; }; + backend.deactivateFunction = [&] { deactivated++; }; + + { + BackendScope outer { backend }; + ASSERT_EQ(1, activated); + { + BackendScope inner { backend }; + ASSERT_EQ(1, activated); + } + ASSERT_EQ(0, deactivated); + } + + ASSERT_EQ(1, deactivated); +} + +// With chained scopes, where scopes have +// different backends, the scopes should each +// activate the scope on entering and de-activating +// on leaving the scope +TEST(BackendScope, ChainedScopes) { + bool activatedA = false; + bool activatedB = false; + + StubRendererBackend backendA; + backendA.activateFunction = [&] { activatedA = true; }; + backendA.deactivateFunction = [&] { activatedA = false; }; + + StubRendererBackend backendB; + backendB.activateFunction = [&] { activatedB = true; }; + backendB.deactivateFunction = [&] { activatedB = false; }; + + { + BackendScope scopeA { backendA }; + ASSERT_TRUE(activatedA); + { + BackendScope scopeB { backendB }; + ASSERT_FALSE(activatedA); + ASSERT_TRUE(activatedB); + } + ASSERT_FALSE(activatedB); + ASSERT_TRUE(activatedA); + } + + ASSERT_FALSE(activatedA); + ASSERT_FALSE(activatedB); +} -- cgit v1.2.1 From d4cb498d7abc612029c575fb290eb649a4697d57 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 21 Jul 2017 16:36:31 -0700 Subject: [all] Merge View into RendererBackend --- test/renderer/backend_scope.test.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/renderer/backend_scope.test.cpp') diff --git a/test/renderer/backend_scope.test.cpp b/test/renderer/backend_scope.test.cpp index a8c92bb31f..06bf1e7750 100644 --- a/test/renderer/backend_scope.test.cpp +++ b/test/renderer/backend_scope.test.cpp @@ -9,6 +9,8 @@ using namespace mbgl; class StubRendererBackend: public RendererBackend { public: + void bind() override { + } void activate() override { if (activateFunction) activateFunction(); -- cgit v1.2.1 From a9ddf5b7fd311ffb9215a682ab2387181189071e Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Thu, 21 Sep 2017 14:26:48 -0700 Subject: Preserve depth buffer between 3D layers + optimize render order (#9931) Port of https://github.com/mapbox/mapbox-gl-js/pull/5101: adds a new render pass `Pass3D` before any other rendering wherein we render layers with 3D passes (fill-extrusion layers) to offscreen framebuffers, sharing a depth renderbuffer between those layers in order to render 3D space correctly. Those framebuffers are saved on the RenderLayers and copied back to the map during the translucent pass. Rendering to offscreen framebuffers before we do any clear + draw means we can avoid expensive framebuffer restores. --- test/renderer/backend_scope.test.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'test/renderer/backend_scope.test.cpp') diff --git a/test/renderer/backend_scope.test.cpp b/test/renderer/backend_scope.test.cpp index 06bf1e7750..66cf88a9c6 100644 --- a/test/renderer/backend_scope.test.cpp +++ b/test/renderer/backend_scope.test.cpp @@ -12,6 +12,10 @@ public: void bind() override { } + mbgl::Size getFramebufferSize() const override { + return mbgl::Size{}; + } + void activate() override { if (activateFunction) activateFunction(); } @@ -87,15 +91,15 @@ TEST(BackendScope, NestedScopes) { TEST(BackendScope, ChainedScopes) { bool activatedA = false; bool activatedB = false; - + StubRendererBackend backendA; backendA.activateFunction = [&] { activatedA = true; }; backendA.deactivateFunction = [&] { activatedA = false; }; - + StubRendererBackend backendB; backendB.activateFunction = [&] { activatedB = true; }; backendB.deactivateFunction = [&] { activatedB = false; }; - + { BackendScope scopeA { backendA }; ASSERT_TRUE(activatedA); @@ -107,7 +111,7 @@ TEST(BackendScope, ChainedScopes) { ASSERT_FALSE(activatedB); ASSERT_TRUE(activatedA); } - + ASSERT_FALSE(activatedA); ASSERT_FALSE(activatedB); } -- cgit v1.2.1 From 2eec5a19803a01e21d5793706ae69ac0d886cee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Mon, 27 Nov 2017 17:25:20 +0100 Subject: [core] move HeadlessBackend extension initialization code into Impl --- test/renderer/backend_scope.test.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'test/renderer/backend_scope.test.cpp') diff --git a/test/renderer/backend_scope.test.cpp b/test/renderer/backend_scope.test.cpp index 66cf88a9c6..05b82695b2 100644 --- a/test/renderer/backend_scope.test.cpp +++ b/test/renderer/backend_scope.test.cpp @@ -28,18 +28,13 @@ public: if (updateAssumedStateFunction) updateAssumedStateFunction(); } - gl::ProcAddress initializeExtension(const char* ext) override { - if (initializeExtensionFunction) { - return initializeExtensionFunction(ext); - } else { - return {}; - } + gl::ProcAddress getExtensionFunctionPointer(const char*) override { + return {}; } std::function activateFunction; std::function deactivateFunction; std::function updateAssumedStateFunction; - std::function initializeExtensionFunction; }; // A scope should activate on construction -- cgit v1.2.1