Skip to content

Commit

Permalink
fix sdf multiple text issue
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodBoyDigital committed May 22, 2024
1 parent b3eb12a commit 0997370
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
21 changes: 11 additions & 10 deletions src/scene/text-bitmap/BitmapTextPipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class BitmapTextPipe implements RenderPipe<BitmapText>

private _renderer: Renderer;
private _gpuBitmapText: Record<number, Graphics> = {};
private _sdfShader: SdfShader;
// private _sdfShader: SdfShader;

constructor(renderer: Renderer)
{
Expand Down Expand Up @@ -81,6 +81,15 @@ export class BitmapTextPipe implements RenderPipe<BitmapText>

private _destroyRenderableByUid(renderableUid: number)
{
const context = this._gpuBitmapText[renderableUid].context;

if (context.customShader)
{
BigPool.return(context.customShader as PoolItem);

context.customShader = null;
}

BigPool.return(this._gpuBitmapText[renderableUid] as PoolItem);
this._gpuBitmapText[renderableUid] = null;
}
Expand Down Expand Up @@ -112,12 +121,7 @@ export class BitmapTextPipe implements RenderPipe<BitmapText>
{
if (!context.customShader)
{
if (!this._sdfShader)
{
this._sdfShader = new SdfShader();
}

context.customShader = this._sdfShader;
context.customShader = BigPool.get(SdfShader);
}
}

Expand Down Expand Up @@ -221,9 +225,6 @@ export class BitmapTextPipe implements RenderPipe<BitmapText>

this._gpuBitmapText = null;

this._sdfShader?.destroy(true);
this._sdfShader = null;

this._renderer = null;
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/scene/text/sdfShader/SdfShader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import { maxRecommendedTextures } from '../../../rendering/renderers/shared/text
import { localUniformMSDFBit, localUniformMSDFBitGl } from './shader-bits/localUniformMSDFBit';
import { mSDFBit, mSDFBitGl } from './shader-bits/mSDFBit';

import type { GlProgram, GpuProgram } from '../../../rendering';

Check failure on line 19 in src/scene/text/sdfShader/SdfShader.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module '../../../rendering' or its corresponding type declarations.

let gpuProgram: GpuProgram;
let glProgram: GlProgram;

export class SdfShader extends Shader
{
constructor()
Expand All @@ -29,7 +34,7 @@ export class SdfShader extends Shader

const maxTextures = maxRecommendedTextures();

const gpuProgram = compileHighShaderGpuProgram({
gpuProgram ??= compileHighShaderGpuProgram({
name: 'sdf-shader',
bits: [
colorBit,
Expand All @@ -40,7 +45,7 @@ export class SdfShader extends Shader
]
});

const glProgram = compileHighShaderGlProgram({
glProgram ??= compileHighShaderGlProgram({
name: 'sdf-shader',
bits: [
colorBitGl,
Expand Down

0 comments on commit 0997370

Please sign in to comment.