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 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-15 04:01:23 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibGC/Ptr.h> 
  
						 
					
						
							
								
									
										
										
										
											2022-09-13 16:02:25 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibWeb/Bindings/PlatformObject.h> 
  
						 
					
						
							
								
									
										
										
										
											2024-11-29 20:49:59 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibWeb/Forward.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <LibWeb/WebGL/Types.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <LibWeb/WebGL/WebGLContextAttributes.h> 
  
						 
					
						
							
								
									
										
										
										
											2024-11-29 22:34:46 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibWeb/WebGL/WebGLRenderingContextImpl.h> 
  
						 
					
						
							
								
									
										
										
										
											2022-06-04 04:22:42 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								namespace  Web : : WebGL  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-29 22:34:46 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class  WebGLRenderingContext  :  public  Bindings : : PlatformObject  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ,  public  WebGLRenderingContextImpl  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-29 20:49:59 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    WEB_PLATFORM_OBJECT ( WebGLRenderingContext ,  Bindings : : PlatformObject ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-15 04:01:23 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    GC_DECLARE_ALLOCATOR ( WebGLRenderingContext ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-04 04:22:42 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 15:53:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								public :  
						 
					
						
							
								
									
										
										
										
											2024-11-15 04:01:23 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    static  JS : : ThrowCompletionOr < GC : : Ptr < WebGLRenderingContext > >  create ( JS : : Realm & ,  HTML : : HTMLCanvasElement &  canvas_element ,  JS : : Value  options ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-04 04:22:42 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 15:53:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    virtual  ~ WebGLRenderingContext ( )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-04 04:22:42 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-17 06:15:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // FIXME: This is a hack required to visit context from WebGLObject.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    //        It should be gone once WebGLRenderingContextBase inherits from PlatformObject.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    GC : : Cell  const *  gc_cell ( )  const  override  {  return  this ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-29 22:34:46 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    void  present ( )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    void  needs_to_present ( )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-29 20:49:59 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    GC : : Ref < HTML : : HTMLCanvasElement >  canvas_for_binding ( )  const ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    bool  is_context_lost ( )  const ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-05 02:59:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    Optional < WebGLContextAttributes >  get_context_attributes ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-29 20:49:59 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    RefPtr < Gfx : : PaintingSurface >  surface ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-29 22:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    void  allocate_painting_surface_if_needed ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-29 20:49:59 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    void  set_size ( Gfx : : IntSize  const & ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    void  reset_to_default_state ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-10 05:49:33 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    Optional < Vector < String > >  get_supported_extensions ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-02 21:25:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    JS : : Object *  get_extension ( String  const &  name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-10 04:52:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    WebIDL : : Long  drawing_buffer_width ( )  const ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    WebIDL : : Long  drawing_buffer_height ( )  const ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-04 04:22:42 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								private :  
						 
					
						
							
								
									
										
										
										
											2023-08-07 08:41:28 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    virtual  void  initialize ( JS : : Realm & )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-10 06:28:20 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-18 20:29:09 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    WebGLRenderingContext ( JS : : Realm & ,  HTML : : HTMLCanvasElement & ,  NonnullOwnPtr < OpenGLContext >  context ,  WebGLContextAttributes  context_creation_parameters ,  WebGLContextAttributes  actual_context_parameters ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-29 20:49:59 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    virtual  void  visit_edges ( Cell : : Visitor & )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    GC : : Ref < HTML : : HTMLCanvasElement >  m_canvas_element ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 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  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    GLenum  m_error  {  0  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-05 23:30:17 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    virtual  void  set_error ( GLenum  error )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-04 04:22:42 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-05 20:56:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  fire_webgl_context_event ( HTML : : HTMLCanvasElement &  canvas_element ,  FlyString  const &  type ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  fire_webgl_context_creation_error ( HTML : : HTMLCanvasElement &  canvas_element ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-04 04:22:42 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}