pathfinder/demo/client/src/aa-strategy.ts

82 lines
2.6 KiB
TypeScript
Raw Normal View History

// pathfinder/client/src/aa-strategy.ts
//
// Copyright © 2017 The Pathfinder Project Developers.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
import * as glmatrix from 'gl-matrix';
2017-09-02 01:29:05 -04:00
import {PathfinderDemoView} from './view';
export type AntialiasingStrategyName = 'none' | 'ssaa' | 'ecaa';
2017-08-29 15:29:16 -04:00
export abstract class AntialiasingStrategy {
// Prepares any OpenGL data. This is only called on startup and canvas resize.
2017-09-02 01:29:05 -04:00
init(view: PathfinderDemoView): void {
2017-08-29 15:29:16 -04:00
this.setFramebufferSize(view);
}
// Uploads any mesh data. This is called whenever a new set of meshes is supplied.
2017-09-02 01:29:05 -04:00
abstract attachMeshes(view: PathfinderDemoView): void;
// This is called whenever the framebuffer has changed.
2017-09-02 01:29:05 -04:00
abstract setFramebufferSize(view: PathfinderDemoView): void;
// Returns the transformation matrix that should be applied when directly rendering.
2017-08-29 15:29:16 -04:00
abstract get transform(): glmatrix.mat4;
// Called before direct rendering.
//
// Typically, this redirects direct rendering to a framebuffer of some sort.
2017-09-02 01:29:05 -04:00
abstract prepare(view: PathfinderDemoView): void;
// Called after direct rendering.
//
// This usually performs the actual antialiasing and blits to the real framebuffer.
2017-09-02 01:29:05 -04:00
abstract resolve(view: PathfinderDemoView): void;
// True if direct rendering should occur.
shouldRenderDirect: boolean;
}
2017-08-29 15:29:16 -04:00
export class NoAAStrategy extends AntialiasingStrategy {
constructor(level: number) {
2017-08-29 15:29:16 -04:00
super();
this.framebufferSize = glmatrix.vec2.create();
}
2017-09-02 01:29:05 -04:00
attachMeshes(view: PathfinderDemoView) {}
2017-09-02 01:29:05 -04:00
setFramebufferSize(view: PathfinderDemoView) {
2017-08-29 15:29:16 -04:00
this.framebufferSize = view.destAllocatedSize;
}
2017-08-29 15:29:16 -04:00
get transform(): glmatrix.mat4 {
return glmatrix.mat4.create();
}
2017-09-02 01:29:05 -04:00
prepare(view: PathfinderDemoView) {
view.gl.bindFramebuffer(view.gl.FRAMEBUFFER, view.destFramebuffer);
view.gl.viewport(0, 0, this.framebufferSize[0], this.framebufferSize[1]);
view.gl.disable(view.gl.SCISSOR_TEST);
// Clear.
view.gl.clearColor(1.0, 1.0, 1.0, 1.0);
view.gl.clearDepth(0.0);
view.gl.depthMask(true);
view.gl.clear(view.gl.COLOR_BUFFER_BIT | view.gl.DEPTH_BUFFER_BIT);
}
2017-09-02 01:29:05 -04:00
resolve(view: PathfinderDemoView) {}
get shouldRenderDirect() {
return true;
}
framebufferSize: glmatrix.vec2;
}