Skip to content

Commit

Permalink
fix: [#3234] Expose ex.RendererPlugin type to devs
Browse files Browse the repository at this point in the history
closes: #3234
  • Loading branch information
eonarheim committed Oct 14, 2024
1 parent 0566663 commit 39c2d3e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ are doing mtv adjustments during precollision.

### Fixed

- Fixed issue where users could not easily define a custom `RendererPlugin` because the type was not exposed
- Fixed issue where `ex.Fade` sometimes would not complete depending on the elapsed time
- Fixed issue where `ex.PolygonColliders` would get trapped in infinite loop for degenerate polygons (< 3 vertices)
- Fixed issue where certain devices that support large numbers of texture slots exhaust the maximum number of if statements (complexity) in the shader.
Expand Down
25 changes: 25 additions & 0 deletions sandbox/src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,38 @@ game.currentScene.onPreDraw = (ctx: ex.ExcaliburGraphicsContext) => {
bb.right--;
bb.draw(ctx, ex.Color.Yellow);

// (ctx as ex.ExcaliburGraphicsContextWebGL).draw('custom', 1, 2, 3, 'custom args');

ctx.drawCircle(ex.vec(bb.left + 6, bb.top + 6), 10, green);
ctx.drawCircle(ex.vec(bb.right - 6, bb.top + 6), 10, blue);
ctx.drawCircle(ex.vec(bb.left + 6, bb.bottom - 6), 10, yellow);
ctx.drawCircle(ex.vec(bb.right - 6, bb.bottom - 6), 10, red);
ctx.restore();
};

class CustomRenderer implements ex.RendererPlugin {
type = 'custom';
priority = 99;
initialize(gl: WebGL2RenderingContext, context: ex.ExcaliburGraphicsContextWebGL): void {
console.log('custom init');
}
draw(...args: any[]): void {
console.log('custom draw', ...args);
}
hasPendingDraws(): boolean {
return false;
}
flush(): void {
// pass
}
dispose(): void {
// pass
}
}
const customRenderer = new CustomRenderer();

(game.graphicsContext as ex.ExcaliburGraphicsContextWebGL).register(customRenderer);

game.on('fallbackgraphicscontext', (ctx) => {
console.log('fallback triggered', ctx);
});
Expand Down
1 change: 1 addition & 0 deletions src/engine/Graphics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export * from './Context/vertex-buffer';
export * from './Context/vertex-layout';
export * from './Context/quad-index-buffer';
export * from './Context/material';
export * from './Context/renderer';

// Debug
export * from './Debug';
Expand Down

0 comments on commit 39c2d3e

Please sign in to comment.