Add WebGL compatibility

This commit is contained in:
schmelczerandras 2020-09-22 16:41:59 +02:00
parent 3725f56c78
commit 1d4980ae28
29 changed files with 567 additions and 212 deletions

View file

@ -1,7 +1,8 @@
import { UniversalRenderingContext } from '../universal-rendering-context';
import { FrameBuffer } from './frame-buffer';
export class DefaultFrameBuffer extends FrameBuffer {
constructor(gl: WebGL2RenderingContext) {
constructor(gl: UniversalRenderingContext) {
super(gl);
this.frameBuffer = null;
this.setSize();

View file

@ -1,4 +1,5 @@
import { vec2 } from 'gl-matrix';
import { UniversalRenderingContext } from '../universal-rendering-context';
export abstract class FrameBuffer {
public renderScale = 1;
@ -9,7 +10,7 @@ export abstract class FrameBuffer {
// null means the default framebuffer
protected frameBuffer: WebGLFramebuffer | null = null;
constructor(protected gl: WebGL2RenderingContext) {}
constructor(protected gl: UniversalRenderingContext) {}
public bindAndClear(colorInput?: WebGLTexture) {
this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.frameBuffer);

View file

@ -1,14 +1,17 @@
import { enableExtension } from '../helper/enable-extension';
import { UniversalRenderingContext } from '../universal-rendering-context';
import { FrameBuffer } from './frame-buffer';
export class IntermediateFrameBuffer extends FrameBuffer {
private frameTexture: WebGLTexture;
private floatLinearEnabled = false;
constructor(gl: WebGL2RenderingContext) {
constructor(gl: UniversalRenderingContext) {
super(gl);
enableExtension(gl, 'EXT_color_buffer_float');
if (gl.isWebGL2) {
enableExtension(gl, 'EXT_color_buffer_float');
}
try {
enableExtension(gl, 'OES_texture_float_linear');
@ -45,12 +48,12 @@ export class IntermediateFrameBuffer extends FrameBuffer {
this.gl.texImage2D(
this.gl.TEXTURE_2D,
0,
this.gl.RG16F,
this.gl.isWebGL2 ? this.gl.RG16F : this.gl.RGBA,
this.size.x,
this.size.y,
0,
this.gl.RG,
this.gl.FLOAT,
this.gl.isWebGL2 ? this.gl.RG : this.gl.RGBA,
this.gl.isWebGL2 ? this.gl.FLOAT : this.gl.UNSIGNED_BYTE,
null
);
}