Improve rendering context typing and speed
This commit is contained in:
parent
4629cfd469
commit
e53ca905af
4 changed files with 14 additions and 13 deletions
|
|
@ -1,9 +1,8 @@
|
|||
import { Insights } from '../../rendering/insights';
|
||||
import { UniversalRenderingContext } from '../universal-rendering-context';
|
||||
|
||||
/** @internal */
|
||||
export const tryEnableExtension = (
|
||||
gl: UniversalRenderingContext,
|
||||
gl: WebGL2RenderingContext | WebGLRenderingContext,
|
||||
name: string
|
||||
): any | null => {
|
||||
let extension = null;
|
||||
|
|
@ -17,7 +16,10 @@ export const tryEnableExtension = (
|
|||
};
|
||||
|
||||
/** @internal */
|
||||
export const enableExtension = (gl: UniversalRenderingContext, name: string): any => {
|
||||
export const enableExtension = (
|
||||
gl: WebGL2RenderingContext | WebGLRenderingContext,
|
||||
name: string
|
||||
): any => {
|
||||
const extension = tryEnableExtension(gl, name);
|
||||
|
||||
if (extension === null) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import { UniversalRenderingContext } from '../universal-rendering-context';
|
||||
import { enableExtension } from './enable-extension';
|
||||
|
||||
/** @internal */
|
||||
|
|
@ -16,7 +15,7 @@ export class WebGlStopwatch {
|
|||
private timerExtension: any;
|
||||
private timerQuery?: WebGLQuery;
|
||||
|
||||
constructor(private readonly gl: UniversalRenderingContext) {
|
||||
constructor(private readonly gl: WebGL2RenderingContext) {
|
||||
this.timerExtension = enableExtension(gl, 'EXT_disjoint_timer_query_webgl2');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,6 @@ export class FragmentShaderOnlyProgram extends Program {
|
|||
);
|
||||
|
||||
if (this.gl.isWebGL2) {
|
||||
// can only return null on lost context
|
||||
this.vao = this.gl.createVertexArray()!;
|
||||
this.gl.bindVertexArray(this.vao!);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { Insights } from '../rendering/insights';
|
||||
|
||||
/** @internal */
|
||||
export type UniversalRenderingContext = WebGL2RenderingContext &
|
||||
WebGLRenderingContext & { isWebGL2: boolean };
|
||||
export type UniversalRenderingContext =
|
||||
| (WebGL2RenderingContext & { isWebGL2: true })
|
||||
| (WebGLRenderingContext & { isWebGL2: false });
|
||||
|
||||
/** @internal */
|
||||
export const getUniversalRenderingContext = (
|
||||
|
|
@ -43,14 +44,14 @@ export const getUniversalRenderingContext = (
|
|||
|
||||
const contextLostHandler = {
|
||||
get: function (target: UniversalRenderingContext, prop: string) {
|
||||
if (isDestroyed || target.isContextLost()) {
|
||||
isDestroyed = true;
|
||||
throw new Error('Context lost');
|
||||
}
|
||||
|
||||
const value = (target as any)[prop];
|
||||
|
||||
if (typeof value === 'function') {
|
||||
if (isDestroyed || target.isContextLost()) {
|
||||
isDestroyed = true;
|
||||
throw new Error('Context lost');
|
||||
}
|
||||
|
||||
return value.bind(target);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue