Skip to content

Commit

Permalink
feat: allow specifying WebGLContextAttributes when creating Rendering…
Browse files Browse the repository at this point in the history
…Context

feat: optimize LayerCompositor engine via now required antialias, depth and stencil
  • Loading branch information
bhouston committed Aug 28, 2020
1 parent 9aa7100 commit 254afb9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/lib/engines/layerCompositor/Layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export class Layer {
const uvToTextureScale = makeMatrix3Scale(this.uvScale);
const uvToTextureTranslation = makeMatrix3Translation(this.uvOffset);
this.uvToTexture = makeMatrix3Concatenation(uvToTextureTranslation, uvToTextureScale);
}
}
8 changes: 7 additions & 1 deletion src/lib/engines/layerCompositor/LayerCompositor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ export class LayerCompositor {
framebufferScreenToView = new Matrix4();

constructor(canvas: HTMLCanvasElement) {
this.context = new RenderingContext(canvas);
this.context = new RenderingContext(canvas, {
alpha: true,
antialias: false,
depth: false,
premultipliedAlpha: true,
stencil: false,
});
const plane = planeGeometry(1, 1, 1, 1);
transformGeometry(plane, makeMatrix4Translation(new Vector3(0.5, 0.5, -1.0)));
this.#bufferGeometry = makeBufferGeometryFromGeometry(this.context, plane);
Expand Down
18 changes: 10 additions & 8 deletions src/lib/renderers/webgl/RenderingContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ export class RenderingContext {
#maskState: MaskState = new MaskState();
#cullingState: CullingState = new CullingState();

constructor(public canvas: HTMLCanvasElement) {
const options: WebGLContextAttributes = {};
options.alpha = true;
options.antialias = true;
options.depth = true;
options.premultipliedAlpha = true;
options.stencil = true;
constructor(public canvas: HTMLCanvasElement, attributes: WebGLContextAttributes | undefined = undefined) {
if (attributes === undefined) {
attributes = {};
attributes.alpha = true;
attributes.antialias = true;
attributes.depth = true;
attributes.premultipliedAlpha = true;
attributes.stencil = true;
}
{
const gl = canvas.getContext("webgl", options);
const gl = canvas.getContext("webgl", attributes);
if (gl === null) {
throw new Error("webgl not supported");
}
Expand Down

0 comments on commit 254afb9

Please sign in to comment.