WebGLRenderingContextBase.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/RefCounted.h>
  8. #include <AK/WeakPtr.h>
  9. #include <AK/Weakable.h>
  10. #include <LibGL/GLContext.h>
  11. #include <LibWeb/Forward.h>
  12. #include <LibWeb/WebGL/WebGLContextAttributes.h>
  13. namespace Web::WebGL {
  14. class WebGLRenderingContextBase
  15. : public RefCounted<WebGLRenderingContextBase>
  16. , public Weakable<WebGLRenderingContextBase> {
  17. public:
  18. virtual ~WebGLRenderingContextBase();
  19. void present();
  20. bool is_context_lost() const;
  21. Optional<Vector<String>> get_supported_extensions() const;
  22. JS::Object* get_extension(String const& name) const;
  23. void active_texture(GLenum texture);
  24. void clear(GLbitfield mask);
  25. void clear_color(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
  26. void clear_depth(GLclampf depth);
  27. void clear_stencil(GLint s);
  28. void color_mask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
  29. void cull_face(GLenum mode);
  30. void depth_func(GLenum func);
  31. void depth_mask(GLboolean mask);
  32. void finish();
  33. void flush();
  34. void front_face(GLenum mode);
  35. void polygon_offset(GLfloat factor, GLfloat units);
  36. void scissor(GLint x, GLint y, GLsizei width, GLsizei height);
  37. void stencil_op(GLenum fail, GLenum zfail, GLenum zpass);
  38. void stencil_op_separate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass);
  39. void viewport(GLint x, GLint y, GLsizei width, GLsizei height);
  40. protected:
  41. WebGLRenderingContextBase(HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters);
  42. private:
  43. WeakPtr<HTML::HTMLCanvasElement> m_canvas_element;
  44. NonnullOwnPtr<GL::GLContext> m_context;
  45. // https://www.khronos.org/registry/webgl/specs/latest/1.0/#context-creation-parameters
  46. // Each WebGLRenderingContext has context creation parameters, set upon creation, in a WebGLContextAttributes object.
  47. WebGLContextAttributes m_context_creation_parameters {};
  48. // https://www.khronos.org/registry/webgl/specs/latest/1.0/#actual-context-parameters
  49. // Each WebGLRenderingContext has actual context parameters, set each time the drawing buffer is created, in a WebGLContextAttributes object.
  50. WebGLContextAttributes m_actual_context_parameters {};
  51. // https://www.khronos.org/registry/webgl/specs/latest/1.0/#webgl-context-lost-flag
  52. // Each WebGLRenderingContext has a webgl context lost flag, which is initially unset.
  53. bool m_context_lost { false };
  54. // WebGL presents its drawing buffer to the HTML page compositor immediately before a compositing operation, but only if at least one of the following has occurred since the previous compositing operation:
  55. // - Context creation
  56. // - Canvas resize
  57. // - clear, drawArrays, or drawElements has been called while the drawing buffer is the currently bound framebuffer
  58. bool m_should_present { true };
  59. void needs_to_present();
  60. };
  61. }