diff --git a/src/mol-gl/webgl/compat.ts b/src/mol-gl/webgl/compat.ts index 8fa3aab180bfd5d0ffdded37f45290bb553c964f..48f6b2b67e73dee7c6e4959d8a1eb827cf352df6 100644 --- a/src/mol-gl/webgl/compat.ts +++ b/src/mol-gl/webgl/compat.ts @@ -19,6 +19,9 @@ export function isWebGL2(gl: any): gl is WebGL2RenderingContext { return typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext; } +/** + * See https://registry.khronos.org/webgl/extensions/ANGLE_instanced_arrays/ + */ export interface COMPAT_instanced_arrays { drawArraysInstanced(mode: number, first: number, count: number, primcount: number): void; drawElementsInstanced(mode: number, count: number, type: number, offset: number, primcount: number): void; @@ -46,6 +49,9 @@ export function getInstancedArrays(gl: GLRenderingContext): COMPAT_instanced_arr } } +/** + * See https://registry.khronos.org/webgl/extensions/OES_standard_derivatives/ + */ export interface COMPAT_standard_derivatives { readonly FRAGMENT_SHADER_DERIVATIVE_HINT: number; } @@ -60,6 +66,9 @@ export function getStandardDerivatives(gl: GLRenderingContext): COMPAT_standard_ } } +/** + * See https://registry.khronos.org/webgl/extensions/OES_element_index_uint/ + */ export interface COMPAT_element_index_uint { } @@ -67,6 +76,9 @@ export function getElementIndexUint(gl: GLRenderingContext): COMPAT_element_inde return isWebGL2(gl) ? {} : gl.getExtension('OES_element_index_uint'); } +/** + * See https://registry.khronos.org/webgl/extensions/OES_vertex_array_object/ + */ export interface COMPAT_vertex_array_object { readonly VERTEX_ARRAY_BINDING: number; bindVertexArray(arrayObject: WebGLVertexArrayObject | null): void; @@ -132,6 +144,9 @@ export function getTextureHalfFloatLinear(gl: GLRenderingContext): COMPAT_textur return gl.getExtension('OES_texture_half_float_linear'); } +/** + * See https://registry.khronos.org/webgl/extensions/EXT_blend_minmax/ + */ export interface COMPAT_blend_minmax { readonly MIN: number readonly MAX: number @@ -147,6 +162,9 @@ export function getBlendMinMax(gl: GLRenderingContext): COMPAT_blend_minmax | nu } } +/** + * See https://registry.khronos.org/webgl/extensions/EXT_frag_depth/ + */ export interface COMPAT_frag_depth { } @@ -196,6 +214,9 @@ export function getColorBufferHalfFloat(gl: GLRenderingContext): COMPAT_color_bu } } +/** + * See https://registry.khronos.org/webgl/extensions/WEBGL_draw_buffers/ + */ export interface COMPAT_draw_buffers { drawBuffers(buffers: number[]): void; readonly COLOR_ATTACHMENT0: number; @@ -268,6 +289,73 @@ export function getDrawBuffers(gl: GLRenderingContext): COMPAT_draw_buffers | nu } } +/** + * See https://registry.khronos.org/webgl/extensions/OES_draw_buffers_indexed/ + */ +export interface COMPAT_draw_buffers_indexed { + /** + * Enables blending for an individual draw buffer. + * + * @param target must be BLEND. + * @param index is an integer i specifying the draw buffer associated with the symbolic constant DRAW_BUFFERi. + */ + enablei: (target: number, index: number) => void; + /** + * Disables blending for an individual draw buffer. + * + * @param target must be BLEND. + * @param index is an integer i specifying the draw buffer associated with the symbolic constant DRAW_BUFFERi. + */ + disablei: (buf: number, mode: number) => void; + /** + * The buf argument is an integer i that indicates that the blend equations should be modified for DRAW_BUFFERi. + * + * mode accepts the same tokens as mode in blendEquation. + */ + blendEquationi: (target: number, index: number) => void; + /** + * The buf argument is an integer i that indicates that the blend equations should be modified for DRAW_BUFFERi. + * + * modeRGB and modeAlpha accept the same tokens as modeRGB and modeAlpha in blendEquationSeparate. + */ + blendEquationSeparatei: (buf: number, modeRGB: number, modeAlpha: number) => void; + /** + * The buf argument is an integer i that indicates that the blend functions should be modified for DRAW_BUFFERi. + * + * src and dst accept the same tokens as src and dst in blendFunc. + */ + blendFunci: (buf: number, src: number, dst: number) => void; + /** + * The buf argument is an integer i that indicates that the blend functions should be modified for DRAW_BUFFERi. + * + * srcRGB, dstRGB, srcAlpha, and dstAlpha accept the same tokens as srcRGB, dstRGB, srcAlpha, and dstAlpha parameters in blendEquationSeparate. + */ + blendFuncSeparatei: (buf: number, srcRGB: number, dstRGB: number, srcAlpha: number, dstAlpha: number) => void; + /** + * The buf argument is an integer i that indicates that the write mask should be modified for DRAW_BUFFERi. + * + * r, g, b, and a indicate whether R, G, B, or A values, respectively, are written or not (a value of TRUE means that the corresponding value is written). + */ + colorMaski: (buf: number, r: boolean, g: boolean, b: boolean, a: boolean) => void; +} + +export function getDrawBuffersIndexed(gl: GLRenderingContext): COMPAT_draw_buffers_indexed | null { + const ext = gl.getExtension('OES_draw_buffers_indexed'); + if (ext === null) return null; + return { + enablei: ext.enableiOES.bind(ext), + disablei: ext.disableiOES.bind(ext), + blendEquationi: ext.blendEquationiOES.bind(ext), + blendEquationSeparatei: ext.blendEquationSeparateiOES.bind(ext), + blendFunci: ext.blendFunciOES.bind(ext), + blendFuncSeparatei: ext.blendFuncSeparateiOES.bind(ext), + colorMaski: ext.colorMaskiOES.bind(ext), + }; +} + +/** + * See https://registry.khronos.org/webgl/extensions/EXT_shader_texture_lod/ + */ export interface COMPAT_shader_texture_lod { } @@ -275,6 +363,9 @@ export function getShaderTextureLod(gl: GLRenderingContext): COMPAT_shader_textu return isWebGL2(gl) ? {} : gl.getExtension('EXT_shader_texture_lod'); } +/** + * See https://registry.khronos.org/webgl/extensions/WEBGL_depth_texture/ + */ export interface COMPAT_depth_texture { readonly UNSIGNED_INT_24_8: number; } @@ -293,6 +384,9 @@ export function getDepthTexture(gl: GLRenderingContext): COMPAT_depth_texture | } } +/** + * See https://registry.khronos.org/webgl/extensions/EXT_sRGB/ + */ export interface COMPAT_sRGB { readonly FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: number; readonly SRGB8_ALPHA8: number; @@ -320,6 +414,9 @@ export function getSRGB(gl: GLRenderingContext): COMPAT_sRGB | null { } } +/** + * See https://registry.khronos.org/webgl/extensions/EXT_disjoint_timer_query/ and https://registry.khronos.org/webgl/extensions/EXT_disjoint_timer_query_webgl2/ + */ export interface COMPAT_disjoint_timer_query { /** A GLint indicating the number of bits used to hold the query result for the given target. */ QUERY_COUNTER_BITS: number @@ -401,6 +498,31 @@ export function getDisjointTimerQuery(gl: GLRenderingContext): COMPAT_disjoint_t } } +/** + * See https://registry.khronos.org/webgl/extensions/KHR_parallel_shader_compile/ + */ +export interface COMPAT_parallel_shader_compile { + readonly COMPLETION_STATUS: number; +} + +export function getParallelShaderCompile(gl: GLRenderingContext): COMPAT_parallel_shader_compile | null { + const ext = gl.getExtension('KHR_parallel_shader_compile'); + if (ext === null) return null; + return { + COMPLETION_STATUS: ext.COMPLETION_STATUS_KHR, + }; +} + +/** + * See https://registry.khronos.org/webgl/extensions/OES_fbo_render_mipmap/ + */ +export interface COMPAT_fboRenderMipmap { +} + +export function getFboRenderMipmap(gl: GLRenderingContext): COMPAT_fboRenderMipmap | null { + return isWebGL2(gl) ? {} : gl.getExtension('OES_fbo_render_mipmap'); +} + export function getNoNonInstancedActiveAttribs(gl: GLRenderingContext): boolean { if (!isWebGL2(gl)) return false; diff --git a/src/mol-gl/webgl/extensions.ts b/src/mol-gl/webgl/extensions.ts index 0d360170b9a09676ff594f1737ed9d949e806fec..e4a4eaf97ac181d14452ac55e7c72d0f1f268dcf 100644 --- a/src/mol-gl/webgl/extensions.ts +++ b/src/mol-gl/webgl/extensions.ts @@ -4,14 +4,14 @@ * @author Alexander Rose <alexander.rose@weirdbyte.de> */ -import { GLRenderingContext, COMPAT_instanced_arrays, COMPAT_standard_derivatives, COMPAT_vertex_array_object, getInstancedArrays, getStandardDerivatives, COMPAT_element_index_uint, getElementIndexUint, COMPAT_texture_float, getTextureFloat, COMPAT_texture_float_linear, getTextureFloatLinear, COMPAT_blend_minmax, getBlendMinMax, getFragDepth, COMPAT_frag_depth, COMPAT_color_buffer_float, getColorBufferFloat, COMPAT_draw_buffers, getDrawBuffers, getShaderTextureLod, COMPAT_shader_texture_lod, getDepthTexture, COMPAT_depth_texture, COMPAT_sRGB, getSRGB, getTextureHalfFloat, getTextureHalfFloatLinear, COMPAT_texture_half_float, COMPAT_texture_half_float_linear, COMPAT_color_buffer_half_float, getColorBufferHalfFloat, getVertexArrayObject, getDisjointTimerQuery, COMPAT_disjoint_timer_query, getNoNonInstancedActiveAttribs } from './compat'; +import { GLRenderingContext, COMPAT_instanced_arrays, COMPAT_standard_derivatives, COMPAT_vertex_array_object, getInstancedArrays, getStandardDerivatives, COMPAT_element_index_uint, getElementIndexUint, COMPAT_texture_float, getTextureFloat, COMPAT_texture_float_linear, getTextureFloatLinear, COMPAT_blend_minmax, getBlendMinMax, getFragDepth, COMPAT_frag_depth, COMPAT_color_buffer_float, getColorBufferFloat, COMPAT_draw_buffers, getDrawBuffers, getShaderTextureLod, COMPAT_shader_texture_lod, getDepthTexture, COMPAT_depth_texture, COMPAT_sRGB, getSRGB, getTextureHalfFloat, getTextureHalfFloatLinear, COMPAT_texture_half_float, COMPAT_texture_half_float_linear, COMPAT_color_buffer_half_float, getColorBufferHalfFloat, getVertexArrayObject, getDisjointTimerQuery, COMPAT_disjoint_timer_query, getNoNonInstancedActiveAttribs, getDrawBuffersIndexed, COMPAT_draw_buffers_indexed, getParallelShaderCompile, COMPAT_parallel_shader_compile, getFboRenderMipmap, COMPAT_fboRenderMipmap } from './compat'; import { isDebugMode } from '../../mol-util/debug'; export type WebGLExtensions = { instancedArrays: COMPAT_instanced_arrays elementIndexUint: COMPAT_element_index_uint + standardDerivatives: COMPAT_standard_derivatives - standardDerivatives: COMPAT_standard_derivatives | null textureFloat: COMPAT_texture_float | null textureFloatLinear: COMPAT_texture_float_linear | null textureHalfFloat: COMPAT_texture_half_float | null @@ -23,9 +23,12 @@ export type WebGLExtensions = { colorBufferFloat: COMPAT_color_buffer_float | null colorBufferHalfFloat: COMPAT_color_buffer_half_float | null drawBuffers: COMPAT_draw_buffers | null + drawBuffersIndexed: COMPAT_draw_buffers_indexed | null shaderTextureLod: COMPAT_shader_texture_lod | null sRGB: COMPAT_sRGB | null disjointTimerQuery: COMPAT_disjoint_timer_query | null + parallelShaderCompile: COMPAT_parallel_shader_compile | null + fboRenderMipmap: COMPAT_fboRenderMipmap | null noNonInstancedActiveAttribs: boolean } @@ -94,6 +97,10 @@ export function createExtensions(gl: GLRenderingContext): WebGLExtensions { if (isDebugMode && drawBuffers === null) { console.log('Could not find support for "draw_buffers"'); } + const drawBuffersIndexed = getDrawBuffersIndexed(gl); + if (isDebugMode && drawBuffersIndexed === null) { + console.log('Could not find support for "draw_buffers_indexed"'); + } const shaderTextureLod = getShaderTextureLod(gl); if (isDebugMode && shaderTextureLod === null) { console.log('Could not find support for "shader_texture_lod"'); @@ -106,28 +113,39 @@ export function createExtensions(gl: GLRenderingContext): WebGLExtensions { if (isDebugMode && disjointTimerQuery === null) { console.log('Could not find support for "disjoint_timer_query"'); } + const parallelShaderCompile = getParallelShaderCompile(gl); + if (isDebugMode && parallelShaderCompile === null) { + console.log('Could not find support for "parallel_shader_compile"'); + } + const fboRenderMipmap = getFboRenderMipmap(gl); + if (isDebugMode && fboRenderMipmap === null) { + console.log('Could not find support for "fbo_render_mipmap"'); + } const noNonInstancedActiveAttribs = getNoNonInstancedActiveAttribs(gl); return { instancedArrays, standardDerivatives, + elementIndexUint, + textureFloat, textureFloatLinear, textureHalfFloat, textureHalfFloatLinear, - elementIndexUint, depthTexture, - blendMinMax, vertexArrayObject, fragDepth, colorBufferFloat, colorBufferHalfFloat, drawBuffers, + drawBuffersIndexed, shaderTextureLod, sRGB, disjointTimerQuery, + parallelShaderCompile, + fboRenderMipmap, noNonInstancedActiveAttribs, };