Skip to content

Commit

Permalink
fix: non-batched pixel line in graphics (pixijs#11099)
Browse files Browse the repository at this point in the history
* fix non-batched pixel line in graphics

* lint

* fix type

---------

Co-authored-by: Zyie <[email protected]>
  • Loading branch information
GoodBoyDigital and Zyie authored Nov 27, 2024
1 parent de1fa21 commit fbef0a8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/scene/graphics/gl/GlGraphicsAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class GlGraphicsAdaptor implements GraphicsAdaptor
renderer.texture.bind(batch.textures.textures[j], j);
}

renderer.geometry.draw('triangle-list', batch.size, batch.start);
renderer.geometry.draw(batch.topology, batch.size, batch.start);
}
}
}
Expand Down
21 changes: 15 additions & 6 deletions src/scene/graphics/gpu/GpuGraphicsAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { UniformGroup } from '../../../rendering/renderers/shared/shader/Uniform
import type { Batch } from '../../../rendering/batcher/shared/Batcher';
import type { GpuEncoderSystem } from '../../../rendering/renderers/gpu/GpuEncoderSystem';
import type { WebGPURenderer } from '../../../rendering/renderers/gpu/WebGPURenderer';
import type { Topology } from '../../../rendering/renderers/shared/geometry/const';
import type { Graphics } from '../shared/Graphics';
import type { GraphicsAdaptor, GraphicsPipe } from '../shared/GraphicsPipe';

Expand Down Expand Up @@ -77,12 +78,6 @@ export class GpuGraphicsAdaptor implements GraphicsAdaptor
// TODO perf test this a bit...
const encoder = renderer.encoder as GpuEncoderSystem;

encoder.setPipelineFromGeometryProgramAndState(
batcher.geometry,
shader.gpuProgram,
graphicsPipe.state
);

encoder.setGeometry(batcher.geometry, shader.gpuProgram);

const globalUniformsBindGroup = renderer.globalUniforms.bindGroup;
Expand All @@ -96,10 +91,24 @@ export class GpuGraphicsAdaptor implements GraphicsAdaptor

const batches = instructions.instructions as Batch[];

let topology: Topology = null;

for (let i = 0; i < instructions.instructionSize; i++)
{
const batch = batches[i];

if (batch.topology !== topology)
{
topology = batch.topology;

encoder.setPipelineFromGeometryProgramAndState(
batcher.geometry,
shader.gpuProgram,
graphicsPipe.state,
batch.topology
);
}

shader.groups[1] = batch.bindGroup;

if (!batch.gpuBindGroup)
Expand Down
10 changes: 10 additions & 0 deletions tests/visual/scenes/graphics/graphics-pixel-line.scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,15 @@ export const scene: TestScene = {
.stroke({ color: 0x0, pixelLine: true, alpha: 0.5 });

scene.addChild(graphics);

const graphics2 = new Graphics();

graphics2.context.batchMode = 'no-batch';

graphics2
.circle(128 / 2, 128 / 2, 128 / 3)
.stroke({ color: 0x00FF00, pixelLine: true, alpha: 1 });

scene.addChild(graphics, graphics2);
},
};
Binary file modified tests/visual/snapshots/graphics-pixel-line-scene-ts-webgl1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/visual/snapshots/graphics-pixel-line-scene-ts-webgl2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/visual/snapshots/graphics-pixel-line-scene-ts-webgpu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fbef0a8

Please sign in to comment.