WebGLRenderingContextBase.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. Optional<Vector<String>> get_supported_extensions() const;
  21. JS::Object* get_extension(String const& name) const;
  22. void clear(GLbitfield mask);
  23. void clear_color(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
  24. protected:
  25. WebGLRenderingContextBase(HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters);
  26. private:
  27. WeakPtr<HTML::HTMLCanvasElement> m_canvas_element;
  28. NonnullOwnPtr<GL::GLContext> m_context;
  29. // https://www.khronos.org/registry/webgl/specs/latest/1.0/#context-creation-parameters
  30. // Each WebGLRenderingContext has context creation parameters, set upon creation, in a WebGLContextAttributes object.
  31. WebGLContextAttributes m_context_creation_parameters {};
  32. // https://www.khronos.org/registry/webgl/specs/latest/1.0/#actual-context-parameters
  33. // Each WebGLRenderingContext has actual context parameters, set each time the drawing buffer is created, in a WebGLContextAttributes object.
  34. WebGLContextAttributes m_actual_context_parameters {};
  35. // https://www.khronos.org/registry/webgl/specs/latest/1.0/#webgl-context-lost-flag
  36. // Each WebGLRenderingContext has a webgl context lost flag, which is initially unset.
  37. bool m_context_lost { false };
  38. // 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:
  39. // - Context creation
  40. // - Canvas resize
  41. // - clear, drawArrays, or drawElements has been called while the drawing buffer is the currently bound framebuffer
  42. bool m_should_present { true };
  43. void needs_to_present();
  44. };
  45. }