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