extensions.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. * Copyright (c) 2018-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. 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 } from './compat';
  7. import { isDebugMode } from '../../mol-util/debug';
  8. export type WebGLExtensions = {
  9. instancedArrays: COMPAT_instanced_arrays
  10. elementIndexUint: COMPAT_element_index_uint
  11. standardDerivatives: COMPAT_standard_derivatives | null
  12. textureFloat: COMPAT_texture_float | null
  13. textureFloatLinear: COMPAT_texture_float_linear | null
  14. textureHalfFloat: COMPAT_texture_half_float | null
  15. textureHalfFloatLinear: COMPAT_texture_half_float_linear | null
  16. depthTexture: COMPAT_depth_texture | null
  17. blendMinMax: COMPAT_blend_minmax | null
  18. vertexArrayObject: COMPAT_vertex_array_object | null
  19. fragDepth: COMPAT_frag_depth | null
  20. colorBufferFloat: COMPAT_color_buffer_float | null
  21. colorBufferHalfFloat: COMPAT_color_buffer_half_float | null
  22. drawBuffers: COMPAT_draw_buffers | null
  23. shaderTextureLod: COMPAT_shader_texture_lod | null
  24. sRGB: COMPAT_sRGB | null
  25. }
  26. export function createExtensions(gl: GLRenderingContext): WebGLExtensions {
  27. const instancedArrays = getInstancedArrays(gl);
  28. if (instancedArrays === null) {
  29. throw new Error('Could not find support for "instanced_arrays"');
  30. }
  31. const elementIndexUint = getElementIndexUint(gl);
  32. if (elementIndexUint === null) {
  33. throw new Error('Could not find support for "element_index_uint"');
  34. }
  35. const standardDerivatives = getStandardDerivatives(gl);
  36. if (isDebugMode && standardDerivatives === null) {
  37. // - non-support handled downstream (flat shading option is ignored)
  38. // - can't be a required extension because it is not supported by `headless-gl`
  39. console.log('Could not find support for "standard_derivatives"');
  40. }
  41. const textureFloat = getTextureFloat(gl);
  42. if (isDebugMode && textureFloat === null) {
  43. console.log('Could not find support for "texture_float"');
  44. }
  45. const textureFloatLinear = getTextureFloatLinear(gl);
  46. if (isDebugMode && textureFloatLinear === null) {
  47. // TODO handle non-support downstream (no gpu gaussian calc, no gpu mc???)
  48. // - can't be a required extension because it is not supported by `headless-gl`
  49. console.log('Could not find support for "texture_float_linear"');
  50. }
  51. const textureHalfFloat = getTextureHalfFloat(gl);
  52. if (isDebugMode && textureHalfFloat === null) {
  53. console.log('Could not find support for "texture_half_float"');
  54. }
  55. const textureHalfFloatLinear = getTextureHalfFloatLinear(gl);
  56. if (isDebugMode && textureHalfFloatLinear === null) {
  57. // TODO handle non-support downstream (no gpu gaussian calc, no gpu mc???)
  58. // - can't be a required extension because it is not supported by `headless-gl`
  59. console.log('Could not find support for "texture_half_float_linear"');
  60. }
  61. const depthTexture = getDepthTexture(gl);
  62. if (isDebugMode && depthTexture === null) {
  63. console.log('Could not find support for "depth_texture"');
  64. }
  65. const blendMinMax = getBlendMinMax(gl);
  66. if (isDebugMode && blendMinMax === null) {
  67. // TODO handle non-support downstream (e.g. no gpu gaussian calc)
  68. // - can't be a required extension because it is not supported by `headless-gl`
  69. console.log('Could not find support for "blend_minmax"');
  70. }
  71. // TODO: revisit
  72. // switch off VAO support for now
  73. // - https://bugs.chromium.org/p/angleproject/issues/detail?id=6599
  74. // - https://bugs.chromium.org/p/chromium/issues/detail?id=1272238
  75. const vertexArrayObject = null; // getVertexArrayObject(gl);
  76. if (isDebugMode && vertexArrayObject === null) {
  77. console.log('Could not find support for "vertex_array_object"');
  78. }
  79. const fragDepth = getFragDepth(gl);
  80. if (isDebugMode && fragDepth === null) {
  81. console.log('Could not find support for "frag_depth"');
  82. }
  83. const colorBufferFloat = getColorBufferFloat(gl);
  84. if (isDebugMode && colorBufferFloat === null) {
  85. console.log('Could not find support for "color_buffer_float"');
  86. }
  87. const colorBufferHalfFloat = getColorBufferHalfFloat(gl);
  88. if (isDebugMode && colorBufferHalfFloat === null) {
  89. console.log('Could not find support for "color_buffer_half_float"');
  90. }
  91. const drawBuffers = getDrawBuffers(gl);
  92. if (isDebugMode && drawBuffers === null) {
  93. console.log('Could not find support for "draw_buffers"');
  94. }
  95. const shaderTextureLod = getShaderTextureLod(gl);
  96. if (isDebugMode && shaderTextureLod === null) {
  97. console.log('Could not find support for "shader_texture_lod"');
  98. }
  99. const sRGB = getSRGB(gl);
  100. if (isDebugMode && sRGB === null) {
  101. console.log('Could not find support for "sRGB"');
  102. }
  103. return {
  104. instancedArrays,
  105. standardDerivatives,
  106. textureFloat,
  107. textureFloatLinear,
  108. textureHalfFloat,
  109. textureHalfFloatLinear,
  110. elementIndexUint,
  111. depthTexture,
  112. blendMinMax,
  113. vertexArrayObject,
  114. fragDepth,
  115. colorBufferFloat,
  116. colorBufferHalfFloat,
  117. drawBuffers,
  118. shaderTextureLod,
  119. sRGB,
  120. };
  121. }