Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rotu committed Dec 11, 2022
1 parent 4ccbab6 commit 8c3e426
Showing 1 changed file with 41 additions and 72 deletions.
113 changes: 41 additions & 72 deletions src/gl/timing.ts
Original file line number Diff line number Diff line change
@@ -1,83 +1,52 @@
import {isWebGL2} from './webgl2';

interface Timing {
QUERY_COUNTER_BITS: 0x8864;
CURRENT_QUERY: 0x8865;
QUERY_RESULT: 0x8866;
QUERY_RESULT_AVAILABLE: 0x8867;
TIMESTAMP: 0x8E28;
TIME_ELAPSED: 0x88BF;
GPU_DISJOINT: 0x8FBB;

createQuery(): WebGLQuery;
deleteQuery(query: WebGLQuery): void;
isQueryEXT(query: WebGLQuery): boolean;
beginQuery(target: GLenum, query: WebGLQuery): void;
endQuery(target: GLenum): void;

getQuery(target: Timing['TIME_ELAPSED'], pname: Timing['CURRENT_QUERY']): WebGLQuery | null;
getQuery(target: Timing['TIMESTAMP'], pname: Timing['CURRENT_QUERY']): null;
getQuery(target: Timing['TIME_ELAPSED'], pname: Timing['QUERY_COUNTER_BITS']): GLint;
getQuery(target: Timing['TIMESTAMP'], pname: Timing['QUERY_COUNTER_BITS']): GLint;

getQueryParameter(query: WebGLQuery, pname: Timing['QUERY_RESULT_AVAILABLE']): GLboolean;
getQueryParameter(query: WebGLQuery, pname: Timing['QUERY_RESULT']): GLuint64;

queryCounter(query: WebGLQuery, target: Timing['TIMESTAMP']): void;
}

export type {Timing};

export function getTimingAPI(gl: WebGLRenderingContext) : null | Timing {
const result = {} as Partial<Timing>;

export function getTimingAPI(gl: WebGLRenderingContext) {
if (isWebGL2(gl)) {
const ext = gl.getExtension('EXT_disjoint_timer_query_webgl2');
if (!ext) return null;
for (const m of [
'createQuery',
'deleteQuery',
'isQuery',
'beginQuery',
'endQuery',
'getQuery',
'getQueryParameter',
]) {
result[m] = gl[m].bind(gl);
}
for (const p of ['GPU_DISJOINT', 'QUERY_COUNTER_BITS', 'TIMESTAMP', 'TIME_ELAPSED']) {
result[p] = ext[`${p}_EXT`];
}
for (const p of ['queryCounter']) {
result[p] = ext[`${p}EXT`].bind(ext);
}
for (const p of ['CURRENT_QUERY', 'QUERY_RESULT', 'QUERY_RESULT_AVAILABLE']) {
result[p] = gl[p];
}

return result as Timing;
return {
CURRENT_QUERY: gl.CURRENT_QUERY,
QUERY_RESULT: gl.QUERY_RESULT,
QUERY_RESULT_AVAILABLE: gl.QUERY_RESULT_AVAILABLE,

GPU_DISJOINT: ext.GPU_DISJOINT_EXT,
QUERY_COUNTER_BITS: ext.QUERY_COUNTER_BITS_EXT,
TIMESTAMP: ext.TIMESTAMP_EXT,
TIME_ELAPSED: ext.TIME_ELAPSED_EXT,

createQuery: gl.createQuery.bind(gl),
deleteQuery: gl.deleteQuery.bind(gl),
isQuery: gl.isQuery.bind(gl),
beginQuery: gl.beginQuery.bind(gl),
endQuery: gl.endQuery.bind(gl),
getQuery: gl.getQuery.bind(gl),
getQueryParameter: gl.getQueryParameter.bind(gl),

queryCounter: ext.queryCounterEXT.bind(ext),
};
}
{
const ext = gl.getExtension('EXT_disjoint_timer_query');
if (!ext) return null;
for (const m of [
'createQuery',
'deleteQuery',
'isQuery',
'beginQuery',
'endQuery',
'getQuery',
'queryCounter'
]) {
result[m] = ext[`${m}EXT`].bind(ext);
}
result.getQueryParameter = ext.getQueryObjectEXT.bind(ext);

for (const p of ['QUERY_COUNTER_BITS', 'CURRENT_QUERY', 'QUERY_RESULT', 'QUERY_RESULT_AVAILABLE',
'TIME_ELAPSED', 'TIMESTAMP', 'GPU_DISJOINT']) {
result[p] = ext[`${p}_EXT`];
}

return result as Timing;
return {
CURRENT_QUERY: ext.CURRENT_QUERY_EXT,
QUERY_RESULT: ext.QUERY_RESULT_EXT,
QUERY_RESULT_AVAILABLE: ext.QUERY_RESULT_AVAILABLE_EXT,

GPU_DISJOINT: ext.GPU_DISJOINT_EXT,
QUERY_COUNTER_BITS: ext.QUERY_COUNTER_BITS_EXT,
TIMESTAMP: ext.TIMESTAMP_EXT,
TIME_ELAPSED: ext.TIME_ELAPSED_EXT,

createQuery: ext.createQueryEXT.bind(ext),
deleteQuery: ext.deleteQueryEXT.bind(ext),
isQuery: ext.isQueryEXT.bind(ext),
beginQuery: ext.beginQueryEXT.bind(ext),
endQuery: ext.endQueryEXT.bind(ext),
getQuery: ext.getQueryEXT.bind(ext),
getQueryParameter: ext.getQueryObjectEXT.bind(ext),

queryCounter: ext.queryCounterEXT.bind(ext),
};
}
}

0 comments on commit 8c3e426

Please sign in to comment.