2022-06-04 04:22:42 +01:00
/*
* Copyright ( c ) 2022 , Luke Wilde < lukew @ serenityos . org >
2024-01-18 20:29:09 +01:00
* Copyright ( c ) 2024 , Aliaksandr Kalenik < kalenik . aliaksandr @ gmail . com >
2022-06-04 04:22:42 +01:00
*
* SPDX - License - Identifier : BSD - 2 - Clause
*/
# pragma once
2022-06-19 19:45:33 +01:00
# include <AK/RefCountForwarder.h>
2022-06-04 04:22:42 +01:00
# include <AK/WeakPtr.h>
# include <AK/Weakable.h>
2022-09-13 16:02:25 +02:00
# include <LibJS/Heap/GCPtr.h>
# include <LibWeb/Bindings/PlatformObject.h>
2022-06-04 04:22:42 +01:00
# include <LibWeb/Forward.h>
2024-01-18 20:29:09 +01:00
# include <LibWeb/WebGL/OpenGLContext.h>
2022-06-04 04:22:42 +01:00
# include <LibWeb/WebGL/WebGLContextAttributes.h>
namespace Web : : WebGL {
2024-01-18 20:29:09 +01:00
# define GL_NO_ERROR 0
2022-09-02 15:53:02 +02:00
class WebGLRenderingContextBase : public Bindings : : PlatformObject {
WEB_PLATFORM_OBJECT ( WebGLRenderingContextBase , Bindings : : PlatformObject ) ;
2022-06-04 04:22:42 +01:00
public :
virtual ~ WebGLRenderingContextBase ( ) ;
2022-06-04 04:27:48 +01:00
void present ( ) ;
2022-08-28 13:42:07 +02:00
JS : : NonnullGCPtr < HTML : : HTMLCanvasElement > canvas_for_binding ( ) const ;
2022-06-19 20:11:10 +01:00
2022-06-04 04:38:22 +01:00
bool is_context_lost ( ) const ;
2023-08-26 17:32:20 +12:00
Optional < Vector < String > > get_supported_extensions ( ) const ;
JS : : Object * get_extension ( String const & name ) const ;
2022-06-04 04:33:00 +01:00
2022-06-04 04:37:10 +01:00
void active_texture ( GLenum texture ) ;
2022-06-04 04:27:48 +01:00
void clear ( GLbitfield mask ) ;
void clear_color ( GLclampf red , GLclampf green , GLclampf blue , GLclampf alpha ) ;
2022-06-04 04:37:10 +01:00
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 ) ;
2022-06-13 16:55:57 +01:00
void depth_range ( GLclampf z_near , GLclampf z_far ) ;
2022-06-04 04:37:10 +01:00
void finish ( ) ;
void flush ( ) ;
void front_face ( GLenum mode ) ;
2022-06-13 16:54:27 +01:00
GLenum get_error ( ) ;
2022-06-13 16:55:21 +01:00
void line_width ( GLfloat width ) ;
2022-06-04 04:37:10 +01:00
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 ) ;
2022-06-04 04:27:48 +01:00
2022-06-04 04:22:42 +01:00
protected :
2024-01-18 20:29:09 +01:00
WebGLRenderingContextBase ( JS : : Realm & , HTML : : HTMLCanvasElement & canvas_element , NonnullOwnPtr < OpenGLContext > context , WebGLContextAttributes context_creation_parameters , WebGLContextAttributes actual_context_parameters ) ;
2022-06-04 04:22:42 +01:00
private :
2022-09-02 15:53:02 +02:00
virtual void visit_edges ( Cell : : Visitor & ) override ;
JS : : NonnullGCPtr < HTML : : HTMLCanvasElement > m_canvas_element ;
2022-08-28 13:42:07 +02:00
2024-01-18 20:29:09 +01:00
NonnullOwnPtr < OpenGLContext > m_context ;
2022-06-04 04:22:42 +01:00
// 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 } ;
2022-06-04 04:27:48 +01:00
2022-06-13 16:54:27 +01:00
GLenum m_error { GL_NO_ERROR } ;
2022-06-19 19:45:33 +01:00
HTML : : HTMLCanvasElement & canvas_element ( ) ;
HTML : : HTMLCanvasElement const & canvas_element ( ) const ;
2022-06-04 04:27:48 +01:00
void needs_to_present ( ) ;
2022-06-13 16:54:27 +01:00
void set_error ( GLenum error ) ;
2022-06-04 04:22:42 +01:00
} ;
}