Remove render tasks entirely.
This commit is contained in:
parent
473cb38fb3
commit
9515451e7a
|
@ -1,59 +0,0 @@
|
||||||
// pathfinder/client/src/render-task.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 {Renderer} from "./renderer";
|
|
||||||
import {Range} from "./utils";
|
|
||||||
|
|
||||||
export type RenderTaskType = 'color' | 'clip';
|
|
||||||
|
|
||||||
export class RenderTask {
|
|
||||||
type: RenderTaskType;
|
|
||||||
instanceIndices: Range;
|
|
||||||
compositingOperation: CompositingOperation | null;
|
|
||||||
|
|
||||||
constructor(type: RenderTaskType,
|
|
||||||
instanceIndices: Range,
|
|
||||||
compositingOperation?: CompositingOperation) {
|
|
||||||
this.type = type;
|
|
||||||
this.instanceIndices = instanceIndices;
|
|
||||||
this.compositingOperation = compositingOperation != null ? compositingOperation : null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export type CompositingOperation = AlphaMaskCompositingOperation;
|
|
||||||
|
|
||||||
export class AlphaMaskCompositingOperation {
|
|
||||||
alphaFramebufferIndex: number;
|
|
||||||
|
|
||||||
constructor(alphaFramebufferIndex: number) {
|
|
||||||
this.alphaFramebufferIndex = alphaFramebufferIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
composite(renderer: Renderer, sourceTextureIndex: number, textures: WebGLTexture[]): void {
|
|
||||||
const renderContext = renderer.renderContext;
|
|
||||||
const gl = renderContext.gl;
|
|
||||||
|
|
||||||
const program = renderContext.shaderPrograms.compositeAlphaMask;
|
|
||||||
|
|
||||||
gl.useProgram(program.program);
|
|
||||||
renderContext.initQuadVAO(program.attributes);
|
|
||||||
|
|
||||||
// Composite to the current framebuffer.
|
|
||||||
gl.activeTexture(gl.TEXTURE0);
|
|
||||||
gl.bindTexture(gl.TEXTURE_2D, textures[sourceTextureIndex]);
|
|
||||||
gl.uniform1i(program.uniforms.uSource, 0);
|
|
||||||
gl.activeTexture(gl.TEXTURE1);
|
|
||||||
gl.bindTexture(gl.TEXTURE_2D, textures[this.alphaFramebufferIndex]);
|
|
||||||
gl.uniform1i(program.uniforms.uMask, 1);
|
|
||||||
renderer.setTransformAndTexScaleUniformsForDest(program.uniforms);
|
|
||||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, renderContext.quadElementsBuffer);
|
|
||||||
gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_BYTE, 0);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -18,7 +18,6 @@ import {AAOptions} from './app-controller';
|
||||||
import PathfinderBufferTexture from "./buffer-texture";
|
import PathfinderBufferTexture from "./buffer-texture";
|
||||||
import {UniformMap} from './gl-utils';
|
import {UniformMap} from './gl-utils';
|
||||||
import {PathfinderMeshBuffers, PathfinderMeshData} from "./meshes";
|
import {PathfinderMeshBuffers, PathfinderMeshData} from "./meshes";
|
||||||
import {CompositingOperation, RenderTaskType} from './render-task';
|
|
||||||
import {ShaderMap} from './shader-loader';
|
import {ShaderMap} from './shader-loader';
|
||||||
import {FLOAT32_SIZE, Range, UINT16_SIZE, UINT32_SIZE, unwrapNull, unwrapUndef} from './utils';
|
import {FLOAT32_SIZE, Range, UINT16_SIZE, UINT32_SIZE, unwrapNull, unwrapUndef} from './utils';
|
||||||
import {RenderContext, Timings} from "./view";
|
import {RenderContext, Timings} from "./view";
|
||||||
|
@ -338,10 +337,6 @@ export abstract class Renderer {
|
||||||
gl.uniform2f(uniforms.uEmboldenAmount, emboldenAmount[0], emboldenAmount[1]);
|
gl.uniform2f(uniforms.uEmboldenAmount, emboldenAmount[0], emboldenAmount[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderTaskTypeForObject(objectIndex: number): RenderTaskType {
|
|
||||||
return 'color';
|
|
||||||
}
|
|
||||||
|
|
||||||
meshIndexForObject(objectIndex: number): number {
|
meshIndexForObject(objectIndex: number): number {
|
||||||
return objectIndex;
|
return objectIndex;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ import {expectNotNull, PathfinderError, unwrapNull} from './utils';
|
||||||
export interface ShaderMap<T> {
|
export interface ShaderMap<T> {
|
||||||
blitLinear: T;
|
blitLinear: T;
|
||||||
blitGamma: T;
|
blitGamma: T;
|
||||||
compositeAlphaMask: T;
|
|
||||||
demo3DDistantGlyph: T;
|
demo3DDistantGlyph: T;
|
||||||
demo3DMonument: T;
|
demo3DMonument: T;
|
||||||
directCurve: T;
|
directCurve: T;
|
||||||
|
@ -43,7 +42,6 @@ const COMMON_SHADER_URL: string = '/glsl/gles2/common.inc.glsl';
|
||||||
export const SHADER_NAMES: Array<keyof ShaderMap<void>> = [
|
export const SHADER_NAMES: Array<keyof ShaderMap<void>> = [
|
||||||
'blitLinear',
|
'blitLinear',
|
||||||
'blitGamma',
|
'blitGamma',
|
||||||
'compositeAlphaMask',
|
|
||||||
'directCurve',
|
'directCurve',
|
||||||
'directInterior',
|
'directInterior',
|
||||||
'direct3DCurve',
|
'direct3DCurve',
|
||||||
|
@ -71,10 +69,6 @@ const SHADER_URLS: ShaderMap<ShaderProgramURLs> = {
|
||||||
fragment: "/glsl/gles2/blit-linear.fs.glsl",
|
fragment: "/glsl/gles2/blit-linear.fs.glsl",
|
||||||
vertex: "/glsl/gles2/blit.vs.glsl",
|
vertex: "/glsl/gles2/blit.vs.glsl",
|
||||||
},
|
},
|
||||||
compositeAlphaMask: {
|
|
||||||
fragment: "/glsl/gles2/composite-alpha-mask.fs.glsl",
|
|
||||||
vertex: "/glsl/gles2/composite-alpha-mask.vs.glsl",
|
|
||||||
},
|
|
||||||
demo3DDistantGlyph: {
|
demo3DDistantGlyph: {
|
||||||
fragment: "/glsl/gles2/demo-3d-distant-glyph.fs.glsl",
|
fragment: "/glsl/gles2/demo-3d-distant-glyph.fs.glsl",
|
||||||
vertex: "/glsl/gles2/demo-3d-distant-glyph.vs.glsl",
|
vertex: "/glsl/gles2/demo-3d-distant-glyph.vs.glsl",
|
||||||
|
|
|
@ -14,7 +14,6 @@ import * as _ from 'lodash';
|
||||||
|
|
||||||
import 'path-data-polyfill.js';
|
import 'path-data-polyfill.js';
|
||||||
import {parseServerTiming, PathfinderMeshData} from "./meshes";
|
import {parseServerTiming, PathfinderMeshData} from "./meshes";
|
||||||
import {AlphaMaskCompositingOperation, RenderTask, RenderTaskType} from './render-task';
|
|
||||||
import {lerp, panic, Range, unwrapNull, unwrapUndef} from "./utils";
|
import {lerp, panic, Range, unwrapNull, unwrapUndef} from "./utils";
|
||||||
|
|
||||||
export const BUILTIN_SVG_URI: string = "/svg/demo";
|
export const BUILTIN_SVG_URI: string = "/svg/demo";
|
||||||
|
@ -92,7 +91,6 @@ interface ClipPathIDTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SVGLoader {
|
export class SVGLoader {
|
||||||
renderTasks: RenderTask[];
|
|
||||||
pathInstances: SVGPath[];
|
pathInstances: SVGPath[];
|
||||||
scale: number;
|
scale: number;
|
||||||
pathBounds: glmatrix.vec4[];
|
pathBounds: glmatrix.vec4[];
|
||||||
|
@ -106,7 +104,6 @@ export class SVGLoader {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.scale = 1.0;
|
this.scale = 1.0;
|
||||||
this.renderTasks = [];
|
|
||||||
this.pathInstances = [];
|
this.pathInstances = [];
|
||||||
this.pathBounds = [];
|
this.pathBounds = [];
|
||||||
this.svgBounds = glmatrix.vec4.create();
|
this.svgBounds = glmatrix.vec4.create();
|
||||||
|
@ -148,12 +145,9 @@ export class SVGLoader {
|
||||||
this.svg.appendChild(kid);
|
this.svg.appendChild(kid);
|
||||||
|
|
||||||
// Scan for geometry elements.
|
// Scan for geometry elements.
|
||||||
this.renderTasks.length = 0;
|
|
||||||
this.pathInstances.length = 0;
|
this.pathInstances.length = 0;
|
||||||
this.clipPathIDs = {};
|
this.clipPathIDs = {};
|
||||||
this.pushNewRenderTask('color');
|
|
||||||
this.scanElement(this.svg);
|
this.scanElement(this.svg);
|
||||||
this.popTopRenderTaskIfEmpty();
|
|
||||||
|
|
||||||
this.paths = [];
|
this.paths = [];
|
||||||
|
|
||||||
|
@ -214,22 +208,8 @@ export class SVGLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
private scanElement(element: Element): void {
|
private scanElement(element: Element): void {
|
||||||
const currentRenderTask = unwrapUndef(_.last(this.renderTasks));
|
|
||||||
const style = window.getComputedStyle(element);
|
const style = window.getComputedStyle(element);
|
||||||
|
|
||||||
let hasClip = style.clipPath != null && style.clipPath !== 'none';
|
|
||||||
if (hasClip) {
|
|
||||||
const matches = /^url\("#([^"]+)"\)$/.exec(unwrapNull(style.clipPath));
|
|
||||||
if (matches == null ||
|
|
||||||
matches[1] == null ||
|
|
||||||
!this.clipPathIDs.hasOwnProperty(matches[1])) {
|
|
||||||
hasClip = false;
|
|
||||||
} else {
|
|
||||||
currentRenderTask.compositingOperation =
|
|
||||||
new AlphaMaskCompositingOperation(this.clipPathIDs[matches[1]]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (element instanceof SVGPathElement) {
|
if (element instanceof SVGPathElement) {
|
||||||
if (colorFromStyle(style.fill) != null)
|
if (colorFromStyle(style.fill) != null)
|
||||||
this.addPathInstance(new SVGFill(element));
|
this.addPathInstance(new SVGFill(element));
|
||||||
|
@ -237,37 +217,14 @@ export class SVGLoader {
|
||||||
this.addPathInstance(new SVGStroke(element));
|
this.addPathInstance(new SVGStroke(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element instanceof SVGClipPathElement) {
|
|
||||||
this.pushNewRenderTask('clip');
|
|
||||||
this.clipPathIDs[element.id] = this.renderTasks.length - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const kid of element.childNodes) {
|
for (const kid of element.childNodes) {
|
||||||
if (kid instanceof Element)
|
if (kid instanceof Element)
|
||||||
this.scanElement(kid);
|
this.scanElement(kid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element instanceof SVGClipPathElement || hasClip)
|
|
||||||
this.pushNewRenderTask('color');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private addPathInstance(pathInstance: SVGPath): void {
|
private addPathInstance(pathInstance: SVGPath): void {
|
||||||
const currentRenderTask = unwrapUndef(_.last(this.renderTasks));
|
|
||||||
this.pathInstances.push(pathInstance);
|
this.pathInstances.push(pathInstance);
|
||||||
currentRenderTask.instanceIndices.end = Math.max(currentRenderTask.instanceIndices.end,
|
|
||||||
this.pathInstances.length + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private popTopRenderTaskIfEmpty(): void {
|
|
||||||
const lastRenderTask = _.last(this.renderTasks);
|
|
||||||
if (lastRenderTask != null && lastRenderTask.instanceIndices.isEmpty)
|
|
||||||
this.renderTasks.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
private pushNewRenderTask(taskType: RenderTaskType): void {
|
|
||||||
this.popTopRenderTaskIfEmpty();
|
|
||||||
const emptyRange = new Range(this.pathInstances.length + 1, this.pathInstances.length + 1);
|
|
||||||
this.renderTasks.push(new RenderTask(taskType, emptyRange));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ import {SubpixelAAType} from './aa-strategy';
|
||||||
import {OrthographicCamera} from "./camera";
|
import {OrthographicCamera} from "./camera";
|
||||||
import {UniformMap} from './gl-utils';
|
import {UniformMap} from './gl-utils';
|
||||||
import {PathfinderMeshData} from './meshes';
|
import {PathfinderMeshData} from './meshes';
|
||||||
import {CompositingOperation, RenderTaskType} from './render-task';
|
|
||||||
import {PathTransformBuffers, Renderer} from "./renderer";
|
import {PathTransformBuffers, Renderer} from "./renderer";
|
||||||
import {ShaderMap} from './shader-loader';
|
import {ShaderMap} from './shader-loader';
|
||||||
import SSAAStrategy from './ssaa-strategy';
|
import SSAAStrategy from './ssaa-strategy';
|
||||||
|
@ -71,7 +70,7 @@ export abstract class SVGRenderer extends Renderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected get objectCount(): number {
|
protected get objectCount(): number {
|
||||||
return this.loader.renderTasks.length;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract get loader(): SVGLoader;
|
protected abstract get loader(): SVGLoader;
|
||||||
|
@ -109,20 +108,12 @@ export abstract class SVGRenderer extends Renderer {
|
||||||
this.camera.zoomToFit();
|
this.camera.zoomToFit();
|
||||||
}
|
}
|
||||||
|
|
||||||
renderTaskTypeForObject(objectIndex: number): RenderTaskType {
|
|
||||||
return this.loader.renderTasks[objectIndex].type;
|
|
||||||
}
|
|
||||||
|
|
||||||
compositingOperationForObject(objectIndex: number): CompositingOperation | null {
|
|
||||||
return this.loader.renderTasks[objectIndex].compositingOperation;
|
|
||||||
}
|
|
||||||
|
|
||||||
meshIndexForObject(objectIndex: number): number {
|
meshIndexForObject(objectIndex: number): number {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pathRangeForObject(objectIndex: number): Range {
|
pathRangeForObject(objectIndex: number): Range {
|
||||||
return this.loader.renderTasks[objectIndex].instanceIndices;
|
return new Range(1, this.loader.pathInstances.length + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected get usedSizeFactor(): glmatrix.vec2 {
|
protected get usedSizeFactor(): glmatrix.vec2 {
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
// pathfinder/shaders/gles2/composite-alpha-mask.fs.glsl
|
|
||||||
//
|
|
||||||
// Copyright (c) 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.
|
|
||||||
|
|
||||||
precision mediump float;
|
|
||||||
|
|
||||||
uniform sampler2D uSource;
|
|
||||||
uniform sampler2D uMask;
|
|
||||||
|
|
||||||
varying vec2 vTexCoord;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
vec4 color = texture2D(uSource, vTexCoord);
|
|
||||||
float alpha = texture2D(uMask, vTexCoord).a;
|
|
||||||
gl_FragColor = vec4(color.rgb, color.a * alpha);
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
// pathfinder/shaders/gles2/composite-alpha-mask.vs.glsl
|
|
||||||
//
|
|
||||||
// Copyright (c) 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.
|
|
||||||
|
|
||||||
precision mediump float;
|
|
||||||
|
|
||||||
/// A 3D transform to apply to the scene.
|
|
||||||
uniform mat4 uTransform;
|
|
||||||
|
|
||||||
/// The 2D vertex position.
|
|
||||||
attribute vec2 aPosition;
|
|
||||||
/// The texture coordinate.
|
|
||||||
attribute vec2 aTexCoord;
|
|
||||||
|
|
||||||
varying vec2 vTexCoord;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
gl_Position = uTransform * vec4(aPosition, 0.0, 1.0);
|
|
||||||
vTexCoord = aTexCoord;
|
|
||||||
}
|
|
Loading…
Reference in New Issue