Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 21467f7

Browse files
committed
Improve Stencil Playground test
- Add UI to select front and back face comparision functions. - Fix back face.
1 parent 88b8581 commit 21467f7

File tree

1 file changed

+67
-5
lines changed

1 file changed

+67
-5
lines changed

impeller/renderer/renderer_unittests.cc

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
#include "flutter/testing/testing.h"
6+
#include "fml/logging.h"
67
#include "impeller/base/strings.h"
78
#include "impeller/core/device_buffer_descriptor.h"
89
#include "impeller/core/formats.h"
@@ -1046,6 +1047,54 @@ TEST_P(RendererTest, VertexBufferBuilder) {
10461047
ASSERT_EQ(vertex_builder.GetVertexCount(), 4u);
10471048
}
10481049

1050+
class CompareFunctionUIData {
1051+
public:
1052+
CompareFunctionUIData() {
1053+
labels_.push_back("Never");
1054+
functions_.push_back(CompareFunction::kNever);
1055+
labels_.push_back("Always");
1056+
functions_.push_back(CompareFunction::kAlways);
1057+
labels_.push_back("Less");
1058+
functions_.push_back(CompareFunction::kLess);
1059+
labels_.push_back("Equal");
1060+
functions_.push_back(CompareFunction::kEqual);
1061+
labels_.push_back("LessEqual");
1062+
functions_.push_back(CompareFunction::kLessEqual);
1063+
labels_.push_back("Greater");
1064+
functions_.push_back(CompareFunction::kGreater);
1065+
labels_.push_back("NotEqual");
1066+
functions_.push_back(CompareFunction::kNotEqual);
1067+
labels_.push_back("GreaterEqual");
1068+
functions_.push_back(CompareFunction::kGreaterEqual);
1069+
assert(labels_.size() == functions_.size());
1070+
}
1071+
1072+
const char* const* labels() const { return &labels_[0]; }
1073+
1074+
int size() const { return labels_.size(); }
1075+
1076+
int IndexOf(CompareFunction func) const {
1077+
for (size_t i = 0; i < functions_.size(); i++) {
1078+
if (functions_[i] == func) {
1079+
return i;
1080+
}
1081+
}
1082+
FML_UNREACHABLE();
1083+
return -1;
1084+
}
1085+
1086+
CompareFunction FunctionOf(int index) const { return functions_[index]; }
1087+
1088+
private:
1089+
std::vector<const char*> labels_;
1090+
std::vector<CompareFunction> functions_;
1091+
};
1092+
1093+
static const CompareFunctionUIData& CompareFunctionUI() {
1094+
static CompareFunctionUIData data;
1095+
return data;
1096+
}
1097+
10491098
TEST_P(RendererTest, StencilMask) {
10501099
using VS = BoxFadeVertexShader;
10511100
using FS = BoxFadeFragmentShader;
@@ -1083,6 +1132,10 @@ TEST_P(RendererTest, StencilMask) {
10831132
static int stencil_reference_read = 0x1;
10841133
std::vector<uint8_t> stencil_contents;
10851134
static int last_stencil_contents_reference_value = 0;
1135+
static int current_front_compare =
1136+
CompareFunctionUI().IndexOf(CompareFunction::kLessEqual);
1137+
static int current_back_compare =
1138+
CompareFunctionUI().IndexOf(CompareFunction::kLessEqual);
10861139
Renderer::RenderCallback callback = [&](RenderTarget& render_target) {
10871140
auto buffer = context->CreateCommandBuffer();
10881141
if (!buffer) {
@@ -1133,11 +1186,20 @@ TEST_P(RendererTest, StencilMask) {
11331186
0xFF);
11341187
ImGui::SliderInt("Stencil Compare Value", &stencil_reference_read, 0,
11351188
0xFF);
1136-
ImGui::Checkbox("Mirror", &mirror);
1189+
ImGui::Checkbox("Back face mode", &mirror);
1190+
ImGui::ListBox("Front face compare function", &current_front_compare,
1191+
CompareFunctionUI().labels(), CompareFunctionUI().size());
1192+
ImGui::ListBox("Back face compare function", &current_back_compare,
1193+
CompareFunctionUI().labels(), CompareFunctionUI().size());
11371194
ImGui::End();
1138-
StencilAttachmentDescriptor front_and_back;
1139-
front_and_back.stencil_compare = CompareFunction::kLessEqual;
1140-
desc->SetStencilAttachmentDescriptors(front_and_back);
1195+
1196+
StencilAttachmentDescriptor front;
1197+
front.stencil_compare =
1198+
CompareFunctionUI().FunctionOf(current_front_compare);
1199+
StencilAttachmentDescriptor back;
1200+
back.stencil_compare =
1201+
CompareFunctionUI().FunctionOf(current_back_compare);
1202+
desc->SetStencilAttachmentDescriptors(front, back);
11411203
auto pipeline = context->GetPipelineLibrary()->GetPipeline(desc).Get();
11421204

11431205
assert(pipeline && pipeline->IsValid());
@@ -1153,7 +1215,7 @@ TEST_P(RendererTest, StencilMask) {
11531215
uniforms.mvp = Matrix::MakeOrthographic(pass->GetRenderTargetSize()) *
11541216
Matrix::MakeScale(GetContentScale());
11551217
if (mirror) {
1156-
uniforms.mvp = Matrix::MakeScale(Vector2(-1, -1)) * uniforms.mvp;
1218+
uniforms.mvp = Matrix::MakeScale(Vector2(-1, 1)) * uniforms.mvp;
11571219
}
11581220
VS::BindUniformBuffer(
11591221
cmd, pass->GetTransientsBuffer().EmplaceUniform(uniforms));

0 commit comments

Comments
 (0)