-
-
Notifications
You must be signed in to change notification settings - Fork 657
Remove all internal global renderer imports #1344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e5e094c
41eeba1
81be977
11b7bc9
e5d8c68
830d37c
06e0bae
a5ccfb4
42738d0
f0dd7ff
9a658eb
75eba90
3be1e6b
b59b913
9e99c99
b1b89ba
48bcdbb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,6 @@ import { | |
| VIEWPORT_ONRESIZE, | ||
| } from "../system/event.ts"; | ||
| import * as stringUtil from "./../utils/string.ts"; | ||
| import { renderer } from "./../video/video.js"; | ||
| import Sprite from "./sprite.js"; | ||
|
|
||
| /** | ||
|
|
@@ -160,7 +159,10 @@ export default class ImageLayer extends Sprite { | |
| * @ignore | ||
| */ | ||
| createPattern() { | ||
| this._pattern = renderer.createPattern(this.image, this._repeat); | ||
| const renderer = this.parentApp?.renderer ?? game.renderer; | ||
| if (renderer) { | ||
| this._pattern = renderer.createPattern(this.image, this._repeat); | ||
| } | ||
|
Comment on lines
161
to
+165
|
||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,6 @@ | ||||||||||||||||||||||||||||
| import { game } from "../application/application.ts"; | ||||||||||||||||||||||||||||
| import { ellipsePool } from "./../geometries/ellipse.ts"; | ||||||||||||||||||||||||||||
| import { colorPool } from "./../math/color.ts"; | ||||||||||||||||||||||||||||
| import pool from "../system/legacy_pool.js"; | ||||||||||||||||||||||||||||
| import CanvasRenderTarget from "../video/rendertarget/canvasrendertarget.js"; | ||||||||||||||||||||||||||||
| import Renderable from "./renderable.js"; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -205,8 +205,8 @@ export default class Light2d extends Renderable { | |||||||||||||||||||||||||||
| destroy() { | ||||||||||||||||||||||||||||
| colorPool.release(this.color); | ||||||||||||||||||||||||||||
| this.color = undefined; | ||||||||||||||||||||||||||||
| pool.push(this.texture); | ||||||||||||||||||||||||||||
| this.texture.destroy(); | ||||||||||||||||||||||||||||
| const renderer = this.parentApp?.renderer ?? game.renderer; | ||||||||||||||||||||||||||||
| this.texture.destroy(renderer); | ||||||||||||||||||||||||||||
|
Comment on lines
205
to
+209
|
||||||||||||||||||||||||||||
| this.texture = undefined; | ||||||||||||||||||||||||||||
|
Comment on lines
+209
to
210
|
||||||||||||||||||||||||||||
| this.texture.destroy(renderer); | |
| this.texture = undefined; | |
| if (this.texture !== undefined && this.texture !== null) { | |
| // Ensure the CanvasRenderTarget is invalidated before destruction, | |
| // so any WebGL-related state (e.g. glTextureUnit) is correctly handled. | |
| if (renderer && typeof this.texture.invalidate === "function") { | |
| this.texture.invalidate(renderer); | |
| } | |
| this.texture.destroy(renderer); | |
| this.texture = undefined; | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,7 @@ | ||
| import { game } from "../../application/application.ts"; | ||
| import { Color, colorPool } from "../../math/color.ts"; | ||
| import { nextPowerOfTwo } from "../../math/math.ts"; | ||
| import pool from "../../system/legacy_pool.js"; | ||
| import CanvasRenderTarget from "../../video/rendertarget/canvasrendertarget.js"; | ||
| import { renderer as globalRenderer } from "../../video/video.js"; | ||
| import Renderable from "../renderable.js"; | ||
|
Comment on lines
+1
to
5
|
||
| import TextMetrics from "./textmetrics.js"; | ||
| import setContextStyle from "./textstyle.js"; | ||
|
|
@@ -165,7 +164,7 @@ export default class Text extends Renderable { | |
| // font name and type | ||
| this.setFont(settings.font, settings.size); | ||
|
|
||
| // aditional | ||
| // additional font styles | ||
| if (settings.bold === true) { | ||
| this.bold(); | ||
| } | ||
|
|
@@ -192,8 +191,13 @@ export default class Text extends Renderable { | |
| * @returns {Text} this object for chaining | ||
| */ | ||
| bold() { | ||
| this.font = "bold " + this.font; | ||
| this.isDirty = true; | ||
| if ( | ||
| !this.font.startsWith("bold ") && | ||
| !this.font.startsWith("italic bold ") | ||
| ) { | ||
| this.font = "bold " + this.font; | ||
| this.isDirty = true; | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
|
|
@@ -202,8 +206,13 @@ export default class Text extends Renderable { | |
| * @returns {Text} this object for chaining | ||
| */ | ||
| italic() { | ||
| this.font = "italic " + this.font; | ||
| this.isDirty = true; | ||
| if ( | ||
| !this.font.startsWith("italic ") && | ||
| !this.font.startsWith("bold italic ") | ||
| ) { | ||
| this.font = "italic " + this.font; | ||
| this.isDirty = true; | ||
| } | ||
| return this; | ||
obiot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
|
|
@@ -278,18 +287,14 @@ export default class Text extends Renderable { | |
| true, | ||
| ); | ||
|
|
||
| // update the offScreenCanvas texture if required | ||
| let width = Math.ceil(this.metrics.width); | ||
| let height = Math.ceil(this.metrics.height); | ||
|
|
||
| if (globalRenderer.WebGLVersion === 1) { | ||
| // round size to next Pow2 | ||
| width = nextPowerOfTwo(this.metrics.width); | ||
| height = nextPowerOfTwo(this.metrics.height); | ||
| } | ||
| // round the offscreen canvas size to the next power of two | ||
| // (required for WebGL1, harmless for WebGL2/Canvas) | ||
| const width = nextPowerOfTwo(this.metrics.width); | ||
| const height = nextPowerOfTwo(this.metrics.height); | ||
|
|
||
obiot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // invalidate the texture | ||
| this.canvasTexture.invalidate(globalRenderer); | ||
| const renderer = this.parentApp?.renderer ?? game.renderer; | ||
| this.canvasTexture.invalidate(renderer); | ||
obiot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // resize the cache canvas if necessary | ||
| if ( | ||
|
|
@@ -330,7 +335,8 @@ export default class Text extends Renderable { | |
| * @param {number} [y] | ||
| */ | ||
| draw(renderer, text, x = this.pos.x, y = this.pos.y) { | ||
| // "hacky patch" for backward compatibilty | ||
| // @deprecated since 10.6.0 — standalone draw without a parent container | ||
| // TODO: remove in 19.0.0 | ||
| if (typeof this.ancestor === "undefined") { | ||
| // update position if changed | ||
| if (this.pos.x !== x || this.pos.y !== y) { | ||
|
|
@@ -362,7 +368,7 @@ export default class Text extends Renderable { | |
| // draw the text | ||
| renderer.drawImage(this.canvasTexture.canvas, x, y); | ||
|
|
||
| // for backward compatibilty | ||
| // @deprecated since 10.6.0 — TODO: remove in 19.0.0 | ||
| if (typeof this.ancestor === "undefined") { | ||
| // restore previous context | ||
| renderer.restore(); | ||
|
|
@@ -396,17 +402,8 @@ export default class Text extends Renderable { | |
| * @ignore | ||
| */ | ||
| destroy() { | ||
| if (typeof globalRenderer.gl !== "undefined") { | ||
| // make sure the right batcher is active | ||
| globalRenderer.setBatcher("quad"); | ||
| globalRenderer.currentBatcher.deleteTexture2D( | ||
| globalRenderer.currentBatcher.getTexture2D(this.glTextureUnit), | ||
| ); | ||
| this.glTextureUnit = undefined; | ||
| } | ||
| globalRenderer.cache.delete(this.canvasTexture.canvas); | ||
| pool.push(this.canvasTexture); | ||
| this.canvasTexture.destroy(); | ||
| const renderer = this.parentApp?.renderer ?? game.renderer; | ||
| this.canvasTexture.destroy(renderer); | ||
| this.canvasTexture = undefined; | ||
| colorPool.release(this.fillStyle); | ||
| colorPool.release(this.strokeStyle); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.