3
3
// found in the LICENSE file.
4
4
5
5
#include " flutter/testing/testing.h"
6
+ #include " fml/logging.h"
6
7
#include " impeller/base/strings.h"
7
8
#include " impeller/core/device_buffer_descriptor.h"
8
9
#include " impeller/core/formats.h"
@@ -1046,6 +1047,54 @@ TEST_P(RendererTest, VertexBufferBuilder) {
1046
1047
ASSERT_EQ (vertex_builder.GetVertexCount (), 4u );
1047
1048
}
1048
1049
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
+
1049
1098
TEST_P (RendererTest, StencilMask) {
1050
1099
using VS = BoxFadeVertexShader;
1051
1100
using FS = BoxFadeFragmentShader;
@@ -1083,6 +1132,10 @@ TEST_P(RendererTest, StencilMask) {
1083
1132
static int stencil_reference_read = 0x1 ;
1084
1133
std::vector<uint8_t > stencil_contents;
1085
1134
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 );
1086
1139
Renderer::RenderCallback callback = [&](RenderTarget& render_target) {
1087
1140
auto buffer = context->CreateCommandBuffer ();
1088
1141
if (!buffer) {
@@ -1133,11 +1186,20 @@ TEST_P(RendererTest, StencilMask) {
1133
1186
0xFF );
1134
1187
ImGui::SliderInt (" Stencil Compare Value" , &stencil_reference_read, 0 ,
1135
1188
0xFF );
1136
- ImGui::Checkbox (" Mirror" , &mirror);
1189
+ ImGui::Checkbox (" Back face mode" , &mirror);
1190
+ ImGui::ListBox (" Front face compare function" , ¤t_front_compare,
1191
+ CompareFunctionUI ().labels (), CompareFunctionUI ().size ());
1192
+ ImGui::ListBox (" Back face compare function" , ¤t_back_compare,
1193
+ CompareFunctionUI ().labels (), CompareFunctionUI ().size ());
1137
1194
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);
1141
1203
auto pipeline = context->GetPipelineLibrary ()->GetPipeline (desc).Get ();
1142
1204
1143
1205
assert (pipeline && pipeline->IsValid ());
@@ -1153,7 +1215,7 @@ TEST_P(RendererTest, StencilMask) {
1153
1215
uniforms.mvp = Matrix::MakeOrthographic (pass->GetRenderTargetSize ()) *
1154
1216
Matrix::MakeScale (GetContentScale ());
1155
1217
if (mirror) {
1156
- uniforms.mvp = Matrix::MakeScale (Vector2 (-1 , - 1 )) * uniforms.mvp ;
1218
+ uniforms.mvp = Matrix::MakeScale (Vector2 (-1 , 1 )) * uniforms.mvp ;
1157
1219
}
1158
1220
VS::BindUniformBuffer (
1159
1221
cmd, pass->GetTransientsBuffer ().EmplaceUniform (uniforms));
0 commit comments