/* * Copyright (c) 2024, Aliaksandr Kalenik * Copyright (c) 2024-2025, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace Web::WebGL { using namespace Web::HTML; class WebGLRenderingContextImpl : public WebGLRenderingContextBase { public: WebGLRenderingContextImpl(JS::Realm&, NonnullOwnPtr); virtual OpenGLContext& context() override { return *m_context; } virtual void present() = 0; virtual void needs_to_present() = 0; virtual void set_error(GLenum) = 0; void buffer_data(WebIDL::UnsignedLong target, WebIDL::LongLong size, WebIDL::UnsignedLong usage); void buffer_data(WebIDL::UnsignedLong target, GC::Root data, WebIDL::UnsignedLong usage); void buffer_sub_data(WebIDL::UnsignedLong target, WebIDL::LongLong offset, GC::Root data); void compressed_tex_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::UnsignedLong internalformat, WebIDL::Long width, WebIDL::Long height, WebIDL::Long border, GC::Root data); void compressed_tex_sub_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, GC::Root data); void read_pixels(WebIDL::Long x, WebIDL::Long y, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, GC::Root pixels); void tex_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long internalformat, WebIDL::Long width, WebIDL::Long height, WebIDL::Long border, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, GC::Root pixels); void tex_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long internalformat, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, Variant, GC::Root, GC::Root, GC::Root, GC::Root, GC::Root> source); void tex_sub_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, GC::Root pixels); void tex_sub_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, Variant, GC::Root, GC::Root, GC::Root, GC::Root, GC::Root> source); void uniform1fv(GC::Root location, Variant, Vector> v); void uniform2fv(GC::Root location, Variant, Vector> v); void uniform3fv(GC::Root location, Variant, Vector> v); void uniform4fv(GC::Root location, Variant, Vector> v); void uniform1iv(GC::Root location, Variant, Vector> v); void uniform2iv(GC::Root location, Variant, Vector> v); void uniform3iv(GC::Root location, Variant, Vector> v); void uniform4iv(GC::Root location, Variant, Vector> v); void uniform_matrix2fv(GC::Root location, bool transpose, Variant, Vector> value); void uniform_matrix3fv(GC::Root location, bool transpose, Variant, Vector> value); void uniform_matrix4fv(GC::Root location, bool transpose, Variant, Vector> value); void active_texture(WebIDL::UnsignedLong texture); void attach_shader(GC::Root program, GC::Root shader); void bind_attrib_location(GC::Root program, WebIDL::UnsignedLong index, String name); void bind_buffer(WebIDL::UnsignedLong target, GC::Root buffer); void bind_framebuffer(WebIDL::UnsignedLong target, GC::Root framebuffer); void bind_renderbuffer(WebIDL::UnsignedLong target, GC::Root renderbuffer); void bind_texture(WebIDL::UnsignedLong target, GC::Root texture); void blend_color(float red, float green, float blue, float alpha); void blend_equation(WebIDL::UnsignedLong mode); void blend_equation_separate(WebIDL::UnsignedLong mode_rgb, WebIDL::UnsignedLong mode_alpha); void blend_func(WebIDL::UnsignedLong sfactor, WebIDL::UnsignedLong dfactor); void blend_func_separate(WebIDL::UnsignedLong src_rgb, WebIDL::UnsignedLong dst_rgb, WebIDL::UnsignedLong src_alpha, WebIDL::UnsignedLong dst_alpha); WebIDL::UnsignedLong check_framebuffer_status(WebIDL::UnsignedLong target); void clear(WebIDL::UnsignedLong mask); void clear_color(float red, float green, float blue, float alpha); void clear_depth(float depth); void clear_stencil(WebIDL::Long s); void color_mask(bool red, bool green, bool blue, bool alpha); void compile_shader(GC::Root shader); void copy_tex_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::UnsignedLong internalformat, WebIDL::Long x, WebIDL::Long y, WebIDL::Long width, WebIDL::Long height, WebIDL::Long border); void copy_tex_sub_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::Long x, WebIDL::Long y, WebIDL::Long width, WebIDL::Long height); GC::Root create_buffer(); GC::Root create_framebuffer(); GC::Root create_program(); GC::Root create_renderbuffer(); GC::Root create_shader(WebIDL::UnsignedLong type); GC::Root create_texture(); void cull_face(WebIDL::UnsignedLong mode); void delete_buffer(GC::Root buffer); void delete_framebuffer(GC::Root framebuffer); void delete_program(GC::Root program); void delete_renderbuffer(GC::Root renderbuffer); void delete_shader(GC::Root shader); void delete_texture(GC::Root texture); void depth_func(WebIDL::UnsignedLong func); void depth_mask(bool flag); void depth_range(float z_near, float z_far); void detach_shader(GC::Root program, GC::Root shader); void disable(WebIDL::UnsignedLong cap); void disable_vertex_attrib_array(WebIDL::UnsignedLong index); void draw_arrays(WebIDL::UnsignedLong mode, WebIDL::Long first, WebIDL::Long count); void draw_elements(WebIDL::UnsignedLong mode, WebIDL::Long count, WebIDL::UnsignedLong type, WebIDL::LongLong offset); void enable(WebIDL::UnsignedLong cap); void enable_vertex_attrib_array(WebIDL::UnsignedLong index); void finish(); void flush(); void framebuffer_renderbuffer(WebIDL::UnsignedLong target, WebIDL::UnsignedLong attachment, WebIDL::UnsignedLong renderbuffertarget, GC::Root renderbuffer); void framebuffer_texture2d(WebIDL::UnsignedLong target, WebIDL::UnsignedLong attachment, WebIDL::UnsignedLong textarget, GC::Root texture, WebIDL::Long level); void front_face(WebIDL::UnsignedLong mode); void generate_mipmap(WebIDL::UnsignedLong target); GC::Root get_active_attrib(GC::Root program, WebIDL::UnsignedLong index); GC::Root get_active_uniform(GC::Root program, WebIDL::UnsignedLong index); Optional>> get_attached_shaders(GC::Root program); WebIDL::Long get_attrib_location(GC::Root program, String name); JS::Value get_buffer_parameter(WebIDL::UnsignedLong target, WebIDL::UnsignedLong pname); JS::Value get_parameter(WebIDL::UnsignedLong pname); WebIDL::UnsignedLong get_error(); JS::Value get_program_parameter(GC::Root program, WebIDL::UnsignedLong pname); Optional get_program_info_log(GC::Root program); JS::Value get_shader_parameter(GC::Root shader, WebIDL::UnsignedLong pname); GC::Root get_shader_precision_format(WebIDL::UnsignedLong shadertype, WebIDL::UnsignedLong precisiontype); Optional get_shader_info_log(GC::Root shader); GC::Root get_uniform_location(GC::Root program, String name); void hint(WebIDL::UnsignedLong target, WebIDL::UnsignedLong mode); bool is_buffer(GC::Root buffer); bool is_enabled(WebIDL::UnsignedLong cap); bool is_framebuffer(GC::Root framebuffer); bool is_program(GC::Root program); bool is_renderbuffer(GC::Root renderbuffer); bool is_shader(GC::Root shader); bool is_texture(GC::Root texture); void line_width(float width); void link_program(GC::Root program); void pixel_storei(WebIDL::UnsignedLong pname, WebIDL::Long param); void polygon_offset(float factor, float units); void renderbuffer_storage(WebIDL::UnsignedLong target, WebIDL::UnsignedLong internalformat, WebIDL::Long width, WebIDL::Long height); void sample_coverage(float value, bool invert); void scissor(WebIDL::Long x, WebIDL::Long y, WebIDL::Long width, WebIDL::Long height); void shader_source(GC::Root shader, String source); void stencil_func(WebIDL::UnsignedLong func, WebIDL::Long ref, WebIDL::UnsignedLong mask); void stencil_func_separate(WebIDL::UnsignedLong face, WebIDL::UnsignedLong func, WebIDL::Long ref, WebIDL::UnsignedLong mask); void stencil_mask(WebIDL::UnsignedLong mask); void stencil_mask_separate(WebIDL::UnsignedLong face, WebIDL::UnsignedLong mask); void stencil_op(WebIDL::UnsignedLong fail, WebIDL::UnsignedLong zfail, WebIDL::UnsignedLong zpass); void stencil_op_separate(WebIDL::UnsignedLong face, WebIDL::UnsignedLong fail, WebIDL::UnsignedLong zfail, WebIDL::UnsignedLong zpass); void tex_parameterf(WebIDL::UnsignedLong target, WebIDL::UnsignedLong pname, float param); void tex_parameteri(WebIDL::UnsignedLong target, WebIDL::UnsignedLong pname, WebIDL::Long param); void uniform1f(GC::Root location, float x); void uniform2f(GC::Root location, float x, float y); void uniform3f(GC::Root location, float x, float y, float z); void uniform4f(GC::Root location, float x, float y, float z, float w); void uniform1i(GC::Root location, WebIDL::Long x); void uniform2i(GC::Root location, WebIDL::Long x, WebIDL::Long y); void uniform3i(GC::Root location, WebIDL::Long x, WebIDL::Long y, WebIDL::Long z); void uniform4i(GC::Root location, WebIDL::Long x, WebIDL::Long y, WebIDL::Long z, WebIDL::Long w); void use_program(GC::Root program); void validate_program(GC::Root program); void vertex_attrib1f(WebIDL::UnsignedLong index, float x); void vertex_attrib2f(WebIDL::UnsignedLong index, float x, float y); void vertex_attrib3f(WebIDL::UnsignedLong index, float x, float y, float z); void vertex_attrib4f(WebIDL::UnsignedLong index, float x, float y, float z, float w); void vertex_attrib1fv(WebIDL::UnsignedLong index, Variant, Vector> values); void vertex_attrib2fv(WebIDL::UnsignedLong index, Variant, Vector> values); void vertex_attrib3fv(WebIDL::UnsignedLong index, Variant, Vector> values); void vertex_attrib4fv(WebIDL::UnsignedLong index, Variant, Vector> values); void vertex_attrib_pointer(WebIDL::UnsignedLong index, WebIDL::Long size, WebIDL::UnsignedLong type, bool normalized, WebIDL::Long stride, WebIDL::LongLong offset); void viewport(WebIDL::Long x, WebIDL::Long y, WebIDL::Long width, WebIDL::Long height); protected: virtual void visit_edges(JS::Cell::Visitor&) override; private: GC::Ref m_realm; GC::Ptr m_array_buffer_binding; GC::Ptr m_element_array_buffer_binding; GC::Ptr m_current_program; GC::Ptr m_framebuffer_binding; GC::Ptr m_renderbuffer_binding; GC::Ptr m_texture_binding_2d; GC::Ptr m_texture_binding_cube_map; NonnullOwnPtr m_context; }; }