|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include "ofFramebufferBinding.h" |
| 4 | +#include <deque> |
| 5 | +#include <string> |
| 6 | + |
| 7 | +// Runs the framebuffer stack the same way the GL renderers do, with no GL context. |
| 8 | +// Returns the number of failed checks. details receives one line per failure. |
| 9 | +inline int runFboBindCases(std::string & details) { |
| 10 | + using Id = std::uint32_t; |
| 11 | + const Id window = 0; |
| 12 | + const Id fboA = 7; |
| 13 | + const Id fboB = 8; |
| 14 | + int failed = 0; |
| 15 | + |
| 16 | + auto check = [&](bool ok, const char * name) { |
| 17 | + if (!ok) { |
| 18 | + details += name; |
| 19 | + details += "\n"; |
| 20 | + ++failed; |
| 21 | + } |
| 22 | + }; |
| 23 | + |
| 24 | + { |
| 25 | + std::deque<Id> stack; |
| 26 | + Id current = window; |
| 27 | + const auto start = ofFramebufferStartRender(stack, current, window); |
| 28 | + const auto began = ofFramebufferPush(stack, current, fboA); |
| 29 | + const auto ended = ofFramebufferPop(stack, current, window); |
| 30 | + check(start.warning == ofFramebufferBindWarning::None && start.bind && start.framebufferId == window, "start binds the window"); |
| 31 | + check(began.warning == ofFramebufferBindWarning::None && ended.warning == ofFramebufferBindWarning::None, "balanced end is quiet"); |
| 32 | + check(ended.framebufferId == window && stack.size() == 1 && current == window, "balanced end returns to the window"); |
| 33 | + const auto finish = ofFramebufferFinishRender(stack, current, window); |
| 34 | + check(finish.warning == ofFramebufferBindWarning::None && !finish.bind && stack.empty() && current == window, "balanced frame does not warn"); |
| 35 | + } |
| 36 | + |
| 37 | + { |
| 38 | + std::deque<Id> stack; |
| 39 | + Id current = window; |
| 40 | + ofFramebufferStartRender(stack, current, window); |
| 41 | + ofFramebufferPush(stack, current, fboA); |
| 42 | + const Id left = current; |
| 43 | + const auto finish = ofFramebufferFinishRender(stack, current, window); |
| 44 | + const auto late = ofFramebufferPop(stack, current, window); |
| 45 | + check(finish.warning == ofFramebufferBindWarning::LeftBound && finish.bind && left == fboA, "missing end is reported when the frame ends"); |
| 46 | + check(current == window && stack.empty(), "missing end rebinds the window"); |
| 47 | + check(late.warning == ofFramebufferBindWarning::None && late.framebufferId == window, "end after the frame recovered stays quiet"); |
| 48 | + } |
| 49 | + |
| 50 | + { |
| 51 | + std::deque<Id> stack; |
| 52 | + Id current = window; |
| 53 | + ofFramebufferStartRender(stack, current, window); |
| 54 | + ofFramebufferPush(stack, current, fboA); |
| 55 | + ofFramebufferPop(stack, current, window); |
| 56 | + const auto extra = ofFramebufferPop(stack, current, window); |
| 57 | + check(extra.warning == ofFramebufferBindWarning::NoMatchingBegin && stack.size() == 1 && current == window, "extra end warns and keeps the window entry"); |
| 58 | + const auto finish = ofFramebufferFinishRender(stack, current, window); |
| 59 | + check(finish.warning == ofFramebufferBindWarning::None, "extra end does not warn again at the end of the frame"); |
| 60 | + } |
| 61 | + |
| 62 | + { |
| 63 | + std::deque<Id> stack; |
| 64 | + Id current = window; |
| 65 | + ofFramebufferFinishRender(stack, current, window); |
| 66 | + const auto began = ofFramebufferPush(stack, current, fboA); |
| 67 | + const auto ended = ofFramebufferPop(stack, current, window); |
| 68 | + check(began.warning == ofFramebufferBindWarning::None && ended.warning == ofFramebufferBindWarning::None, "begin/end outside a frame is quiet"); |
| 69 | + check(stack.empty() && current == window, "begin/end outside a frame restores the window"); |
| 70 | + } |
| 71 | + |
| 72 | + { |
| 73 | + std::deque<Id> stack; |
| 74 | + Id current = window; |
| 75 | + ofFramebufferStartRender(stack, current, window); |
| 76 | + ofFramebufferPush(stack, current, fboA); |
| 77 | + const auto nested = ofFramebufferPush(stack, current, fboA); |
| 78 | + const auto inner = ofFramebufferPop(stack, current, window); |
| 79 | + const auto outer = ofFramebufferPop(stack, current, window); |
| 80 | + const auto finish = ofFramebufferFinishRender(stack, current, window); |
| 81 | + check(nested.warning == ofFramebufferBindWarning::BoundOntoSelf && inner.framebufferId == fboA && inner.warning == ofFramebufferBindWarning::None, "binding an fbo onto itself still has a matching end"); |
| 82 | + check(outer.framebufferId == window && finish.warning == ofFramebufferBindWarning::None, "self-bind end returns to the window"); |
| 83 | + } |
| 84 | + |
| 85 | + { |
| 86 | + std::deque<Id> stack; |
| 87 | + Id current = window; |
| 88 | + ofFramebufferStartRender(stack, current, window); |
| 89 | + ofFramebufferPush(stack, current, fboA); |
| 90 | + ofFramebufferPush(stack, current, fboB); |
| 91 | + const auto inner = ofFramebufferPop(stack, current, window); |
| 92 | + const auto outer = ofFramebufferPop(stack, current, window); |
| 93 | + check(inner.framebufferId == fboA && outer.framebufferId == window, "nested fbos pop in order"); |
| 94 | + } |
| 95 | + |
| 96 | + { |
| 97 | + std::deque<Id> stack; |
| 98 | + Id current = fboA; |
| 99 | + const auto late = ofFramebufferPop(stack, current, window); |
| 100 | + check(late.warning == ofFramebufferBindWarning::NoMatchingBegin && current == window, "end while another fbo is current and the stack is empty warns"); |
| 101 | + } |
| 102 | + |
| 103 | + return failed; |
| 104 | +} |
0 commit comments