Skip to content

Commit

Permalink
Merge pull request #15300 from CedricGuillemet/NativeTriangleFan
Browse files Browse the repository at this point in the history
[Native] Warning for non supported fill modes
  • Loading branch information
sebavan authored Jul 18, 2024
2 parents b0b8e72 + bc21518 commit b8d0df6
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/dev/core/src/Engines/nativeEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ export class NativeEngine extends Engine {
private _zOffset: number = 0;
private _zOffsetUnits: number = 0;
private _depthWrite: boolean = true;
// warning for non supported fill mode has already been displayed
private _fillModeWarningDisplayed = false;

public override setHardwareScalingLevel(level: number): void {
super.setHardwareScalingLevel(level);
Expand Down Expand Up @@ -642,6 +644,22 @@ export class NativeEngine extends Engine {
return this._engine.getAttributes(nativePipelineContext.program, remappedAttributesNames);
}

/**
* Triangle Fan and Line Loop are not supported by modern rendering API
* @param fillMode defines the primitive to use
* @returns true if supported
*/
private _checkSupportedFillMode(fillMode: number): boolean {
if (fillMode == Constants.MATERIAL_LineLoopDrawMode || fillMode == Constants.MATERIAL_TriangleFanDrawMode) {
if (!this._fillModeWarningDisplayed) {
Logger.Warn("Line Loop and Triangle Fan are not supported fill modes with Babylon Native. Elements with these fill mode will not be visible.");
this._fillModeWarningDisplayed = true;
}
return false;
}
return true;
}

/**
* Draw a list of indexed primitives
* @param fillMode defines the primitive to use
Expand All @@ -650,6 +668,9 @@ export class NativeEngine extends Engine {
* @param instancesCount defines the number of instances to draw (if instantiation is enabled)
*/
public override drawElementsType(fillMode: number, indexStart: number, indexCount: number, instancesCount?: number): void {
if (!this._checkSupportedFillMode(fillMode)) {
return;
}
// Apply states
this._drawCalls.addCount(1, false);

Expand Down Expand Up @@ -678,6 +699,9 @@ export class NativeEngine extends Engine {
* @param instancesCount defines the number of instances to draw (if instantiation is enabled)
*/
public override drawArraysType(fillMode: number, verticesStart: number, verticesCount: number, instancesCount?: number): void {
if (!this._checkSupportedFillMode(fillMode)) {
return;
}
// Apply states
this._drawCalls.addCount(1, false);

Expand Down

0 comments on commit b8d0df6

Please sign in to comment.