2017-08-26 16:47:18 -04:00
|
|
|
// 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-10-03 18:24:56 -04:00
|
|
|
import {DemoView} from './view';
|
2017-08-26 16:47:18 -04:00
|
|
|
|
2017-08-28 20:18:44 -04:00
|
|
|
export type AntialiasingStrategyName = 'none' | 'ssaa' | 'ecaa';
|
|
|
|
|
2017-09-30 01:12:09 -04:00
|
|
|
export type SubpixelAAType = 'none' | 'medium' | 'strong';
|
|
|
|
|
2017-08-29 15:29:16 -04:00
|
|
|
export abstract class AntialiasingStrategy {
|
2017-09-28 17:34:48 -04:00
|
|
|
// True if direct rendering should occur.
|
|
|
|
shouldRenderDirect: boolean;
|
|
|
|
|
2017-08-26 16:47:18 -04:00
|
|
|
// Prepares any OpenGL data. This is only called on startup and canvas resize.
|
2017-10-03 18:24:56 -04:00
|
|
|
init(view: DemoView): void {
|
2017-08-29 15:29:16 -04:00
|
|
|
this.setFramebufferSize(view);
|
|
|
|
}
|
2017-08-26 16:47:18 -04:00
|
|
|
|
|
|
|
// Uploads any mesh data. This is called whenever a new set of meshes is supplied.
|
2017-10-03 18:24:56 -04:00
|
|
|
abstract attachMeshes(view: DemoView): void;
|
2017-08-26 16:47:18 -04:00
|
|
|
|
|
|
|
// This is called whenever the framebuffer has changed.
|
2017-10-03 18:24:56 -04:00
|
|
|
abstract setFramebufferSize(view: DemoView): void;
|
2017-08-26 16:47:18 -04:00
|
|
|
|
|
|
|
// Returns the transformation matrix that should be applied when directly rendering.
|
2017-08-29 15:29:16 -04:00
|
|
|
abstract get transform(): glmatrix.mat4;
|
2017-08-26 16:47:18 -04:00
|
|
|
|
|
|
|
// Called before direct rendering.
|
|
|
|
//
|
|
|
|
// Typically, this redirects direct rendering to a framebuffer of some sort.
|
2017-10-03 18:24:56 -04:00
|
|
|
abstract prepare(view: DemoView): void;
|
2017-08-26 16:47:18 -04:00
|
|
|
|
|
|
|
// Called after direct rendering.
|
|
|
|
//
|
2017-09-26 16:34:40 -04:00
|
|
|
// This usually performs the actual antialiasing.
|
2017-10-03 18:24:56 -04:00
|
|
|
abstract antialias(view: DemoView): void;
|
2017-09-26 16:34:40 -04:00
|
|
|
|
|
|
|
// Called after antialiasing.
|
|
|
|
//
|
|
|
|
// This usually blits to the real framebuffer.
|
2017-10-03 18:24:56 -04:00
|
|
|
abstract resolve(view: DemoView): void;
|
2017-08-26 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
2017-08-29 15:29:16 -04:00
|
|
|
export class NoAAStrategy extends AntialiasingStrategy {
|
2017-09-28 17:34:48 -04:00
|
|
|
framebufferSize: glmatrix.vec2;
|
|
|
|
|
2017-09-30 01:12:09 -04:00
|
|
|
constructor(level: number, subpixelAA: SubpixelAAType) {
|
2017-08-29 15:29:16 -04:00
|
|
|
super();
|
2017-08-26 16:47:18 -04:00
|
|
|
this.framebufferSize = glmatrix.vec2.create();
|
|
|
|
}
|
|
|
|
|
2017-10-03 18:24:56 -04:00
|
|
|
attachMeshes(view: DemoView) {}
|
2017-08-26 16:47:18 -04:00
|
|
|
|
2017-10-03 18:24:56 -04:00
|
|
|
setFramebufferSize(view: DemoView) {
|
2017-08-29 15:29:16 -04:00
|
|
|
this.framebufferSize = view.destAllocatedSize;
|
2017-08-26 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
2017-08-29 15:29:16 -04:00
|
|
|
get transform(): glmatrix.mat4 {
|
2017-08-26 16:47:18 -04:00
|
|
|
return glmatrix.mat4.create();
|
|
|
|
}
|
|
|
|
|
2017-10-03 18:24:56 -04:00
|
|
|
prepare(view: DemoView) {
|
2017-08-26 16:47:18 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-10-03 18:24:56 -04:00
|
|
|
antialias(view: DemoView) {}
|
2017-09-26 16:34:40 -04:00
|
|
|
|
2017-10-03 18:24:56 -04:00
|
|
|
resolve(view: DemoView) {}
|
2017-08-26 16:47:18 -04:00
|
|
|
|
|
|
|
get shouldRenderDirect() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|