library_godot_webgl2.js 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**************************************************************************/
  2. /* library_godot_webgl2.js */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. const GodotWebGL2 = {
  31. $GodotWebGL2__deps: ['$GL', '$GodotRuntime'],
  32. $GodotWebGL2: {},
  33. // This is implemented as "glGetBufferSubData" in new emscripten versions.
  34. // Since we have to support older (pre 2.0.17) emscripten versions, we add this wrapper function instead.
  35. godot_webgl2_glGetBufferSubData__proxy: 'sync',
  36. godot_webgl2_glGetBufferSubData__sig: 'vippp',
  37. godot_webgl2_glGetBufferSubData__deps: ['$GL', 'emscripten_webgl_get_current_context'],
  38. godot_webgl2_glGetBufferSubData: function (target, offset, size, data) {
  39. const gl_context_handle = _emscripten_webgl_get_current_context();
  40. const gl = GL.getContext(gl_context_handle);
  41. if (gl) {
  42. gl.GLctx['getBufferSubData'](target, offset, HEAPU8, data, size);
  43. }
  44. },
  45. godot_webgl2_glFramebufferTextureMultiviewOVR__deps: ['emscripten_webgl_get_current_context'],
  46. godot_webgl2_glFramebufferTextureMultiviewOVR__proxy: 'sync',
  47. godot_webgl2_glFramebufferTextureMultiviewOVR__sig: 'viiiiii',
  48. godot_webgl2_glFramebufferTextureMultiviewOVR: function (target, attachment, texture, level, base_view_index, num_views) {
  49. const context = GL.currentContext;
  50. if (typeof context.multiviewExt === 'undefined') {
  51. const /** OVR_multiview2 */ ext = context.GLctx.getExtension('OVR_multiview2');
  52. if (!ext) {
  53. GodotRuntime.error('Trying to call glFramebufferTextureMultiviewOVR() without the OVR_multiview2 extension');
  54. return;
  55. }
  56. context.multiviewExt = ext;
  57. }
  58. const /** OVR_multiview2 */ ext = context.multiviewExt;
  59. ext.framebufferTextureMultiviewOVR(target, attachment, GL.textures[texture], level, base_view_index, num_views);
  60. },
  61. godot_webgl2_glFramebufferTextureMultisampleMultiviewOVR__deps: ['emscripten_webgl_get_current_context'],
  62. godot_webgl2_glFramebufferTextureMultisampleMultiviewOVR__proxy: 'sync',
  63. godot_webgl2_glFramebufferTextureMultisampleMultiviewOVR__sig: 'viiiiiii',
  64. godot_webgl2_glFramebufferTextureMultisampleMultiviewOVR: function (target, attachment, texture, level, samples, base_view_index, num_views) {
  65. const context = GL.currentContext;
  66. if (typeof context.oculusMultiviewExt === 'undefined') {
  67. const /** OCULUS_multiview */ ext = context.GLctx.getExtension('OCULUS_multiview');
  68. if (!ext) {
  69. GodotRuntime.error('Trying to call glFramebufferTextureMultisampleMultiviewOVR() without the OCULUS_multiview extension');
  70. return;
  71. }
  72. context.oculusMultiviewExt = ext;
  73. }
  74. const /** OCULUS_multiview */ ext = context.oculusMultiviewExt;
  75. ext.framebufferTextureMultisampleMultiviewOVR(target, attachment, GL.textures[texture], level, samples, base_view_index, num_views);
  76. },
  77. };
  78. autoAddDeps(GodotWebGL2, '$GodotWebGL2');
  79. mergeInto(LibraryManager.library, GodotWebGL2);