WebGLRenderingContextBase.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 active_texture(GLenum texture);
  23. void clear(GLbitfield mask);
  24. void clear_color(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
  25. void clear_depth(GLclampf depth);
  26. void clear_stencil(GLint s);
  27. void color_mask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
  28. void cull_face(GLenum mode);
  29. void depth_func(GLenum func);
  30. void depth_mask(GLboolean mask);
  31. void finish();
  32. void flush();
  33. void front_face(GLenum mode);
  34. void polygon_offset(GLfloat factor, GLfloat units);
  35. void scissor(GLint x, GLint y, GLsizei width, GLsizei height);
  36. void stencil_op(GLenum fail, GLenum zfail, GLenum zpass);
  37. void stencil_op_separate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass);
  38. void viewport(GLint x, GLint y, GLsizei width, GLsizei height);
  39. protected:
  40. WebGLRenderingContextBase(HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters);
  41. private:
  42. WeakPtr<HTML::HTMLCanvasElement> m_canvas_element;
  43. NonnullOwnPtr<GL::GLContext> m_context;
  44. // https://www.khronos.org/registry/webgl/specs/latest/1.0/#context-creation-parameters
  45. // Each WebGLRenderingContext has context creation parameters, set upon creation, in a WebGLContextAttributes object.
  46. WebGLContextAttributes m_context_creation_parameters {};
  47. // https://www.khronos.org/registry/webgl/specs/latest/1.0/#actual-context-parameters
  48. // Each WebGLRenderingContext has actual context parameters, set each time the drawing buffer is created, in a WebGLContextAttributes object.
  49. WebGLContextAttributes m_actual_context_parameters {};
  50. // https://www.khronos.org/registry/webgl/specs/latest/1.0/#webgl-context-lost-flag
  51. // Each WebGLRenderingContext has a webgl context lost flag, which is initially unset.
  52. bool m_context_lost { false };
  53. // 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:
  54. // - Context creation
  55. // - Canvas resize
  56. // - clear, drawArrays, or drawElements has been called while the drawing buffer is the currently bound framebuffer
  57. bool m_should_present { true };
  58. void needs_to_present();
  59. };
  60. }