From 39c2d3ef588d2503530719e32df81df0dc22dba1 Mon Sep 17 00:00:00 2001 From: Erik Onarheim Date: Mon, 14 Oct 2024 10:55:18 -0500 Subject: [PATCH] fix: [#3234] Expose `ex.RendererPlugin` type to devs closes: #3234 --- CHANGELOG.md | 1 + sandbox/src/game.ts | 25 +++++++++++++++++++++++++ src/engine/Graphics/index.ts | 1 + 3 files changed, 27 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3daa505b..65c591fe5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/sandbox/src/game.ts b/sandbox/src/game.ts index 35b697fde..31aba0d9e 100644 --- a/sandbox/src/game.ts +++ b/sandbox/src/game.ts @@ -109,6 +109,8 @@ 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); @@ -116,6 +118,29 @@ game.currentScene.onPreDraw = (ctx: ex.ExcaliburGraphicsContext) => { 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); }); diff --git a/src/engine/Graphics/index.ts b/src/engine/Graphics/index.ts index df5d2b8fd..6ab82bae7 100644 --- a/src/engine/Graphics/index.ts +++ b/src/engine/Graphics/index.ts @@ -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';