Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/gpu/formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,25 @@ constexpr impeller::CullMode ToImpellerCullMode(int value) {
return ToImpellerCullMode(static_cast<FlutterGPUCullMode>(value));
}

enum class FlutterGPUWindingOrder {
kClockwise,
kCounterClockwise,
};

constexpr impeller::WindingOrder ToImpellerWindingOrder(
FlutterGPUWindingOrder value) {
switch (value) {
case FlutterGPUWindingOrder::kClockwise:
return impeller::WindingOrder::kClockwise;
case FlutterGPUWindingOrder::kCounterClockwise:
return impeller::WindingOrder::kCounterClockwise;
}
}

constexpr impeller::WindingOrder ToImpellerWindingOrder(int value) {
return ToImpellerWindingOrder(static_cast<FlutterGPUWindingOrder>(value));
}

} // namespace gpu
} // namespace flutter

Expand Down
5 changes: 5 additions & 0 deletions lib/gpu/lib/src/formats.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ enum CullMode {
backFace,
}

enum WindingOrder {
clockwise,
counterClockwise,
}

enum CompareFunction {
/// Comparison test never passes.
never,
Expand Down
8 changes: 8 additions & 0 deletions lib/gpu/lib/src/render_pass.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ base class RenderPass extends NativeFieldWrapperClass1 {
_setCullMode(cullMode.index);
}

void setWindingOrder(WindingOrder windingOrder) {
_setWindingOrder(windingOrder.index);
}

void draw() {
if (!_draw()) {
throw Exception("Failed to append draw");
Expand Down Expand Up @@ -410,6 +414,10 @@ base class RenderPass extends NativeFieldWrapperClass1 {
symbol: 'InternalFlutterGpu_RenderPass_SetCullMode')
external void _setCullMode(int cullMode);

@Native<Void Function(Pointer<Void>, Int)>(
symbol: 'InternalFlutterGpu_RenderPass_SetWindingOrder')
external void _setWindingOrder(int windingOrder);

@Native<Bool Function(Pointer<Void>)>(
symbol: 'InternalFlutterGpu_RenderPass_Draw')
external bool _draw();
Expand Down
9 changes: 9 additions & 0 deletions lib/gpu/render_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,15 @@ void InternalFlutterGpu_RenderPass_SetCullMode(
pipeline_descriptor.SetCullMode(flutter::gpu::ToImpellerCullMode(cull_mode));
}

void InternalFlutterGpu_RenderPass_SetWindingOrder(
flutter::gpu::RenderPass* wrapper,
int winding_order) {
impeller::PipelineDescriptor& pipeline_descriptor =
wrapper->GetPipelineDescriptor();
pipeline_descriptor.SetWindingOrder(
flutter::gpu::ToImpellerWindingOrder(winding_order));
}

bool InternalFlutterGpu_RenderPass_Draw(flutter::gpu::RenderPass* wrapper) {
return wrapper->Draw();
}
5 changes: 5 additions & 0 deletions lib/gpu/render_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ extern void InternalFlutterGpu_RenderPass_SetCullMode(
flutter::gpu::RenderPass* wrapper,
int cull_mode);

FLUTTER_GPU_EXPORT
extern void InternalFlutterGpu_RenderPass_SetWindingOrder(
flutter::gpu::RenderPass* wrapper,
int winding_order);

FLUTTER_GPU_EXPORT
extern bool InternalFlutterGpu_RenderPass_Draw(
flutter::gpu::RenderPass* wrapper);
Expand Down
10 changes: 10 additions & 0 deletions testing/dart/gpu_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,21 @@ void main() async {
state.renderPass.draw();
}

// Draw the green rectangle.
// Defaults to clockwise winding order. So frontface culling should not
// impact the green triangle.
state.renderPass.setCullMode(gpu.CullMode.frontFace);
drawTriangle(Colors.lime);

// Backface cull a red triangle.
state.renderPass.setCullMode(gpu.CullMode.backFace);
drawTriangle(Colors.red);

// Invert the winding mode and frontface cull a red rectangle.
state.renderPass.setWindingOrder(gpu.WindingOrder.counterClockwise);
state.renderPass.setCullMode(gpu.CullMode.frontFace);
drawTriangle(Colors.red);

state.commandBuffer.submit();

final ui.Image image = state.renderTexture.asImage();
Expand Down