@@ -48,305 +48,6 @@ WebGLRenderingContextImpl::WebGLRenderingContextImpl(JS::Realm& realm, NonnullOw
4848{
4949}
5050
51- void WebGLRenderingContextImpl::buffer_data (WebIDL::UnsignedLong target, WebIDL::LongLong size, WebIDL::UnsignedLong usage)
52- {
53- m_context->make_current ();
54-
55- glBufferData (target, size, 0 , usage);
56- }
57-
58- void WebGLRenderingContextImpl::buffer_data (WebIDL::UnsignedLong target, GC::Root<WebIDL::BufferSource> data, WebIDL::UnsignedLong usage)
59- {
60- m_context->make_current ();
61-
62- auto span = MUST (get_offset_span<u8 const >(*data, /* src_offset= */ 0 ));
63- glBufferData (target, span.size (), span.data (), usage);
64- }
65-
66- void WebGLRenderingContextImpl::buffer_sub_data (WebIDL::UnsignedLong target, WebIDL::LongLong offset, GC::Root<WebIDL::BufferSource> data)
67- {
68- m_context->make_current ();
69-
70- auto span = MUST (get_offset_span<u8 const >(*data, /* src_offset= */ 0 ));
71- glBufferSubData (target, offset, span.size (), span.data ());
72- }
73-
74- void WebGLRenderingContextImpl::compressed_tex_image2d (WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::UnsignedLong internalformat, WebIDL::Long width, WebIDL::Long height, WebIDL::Long border, GC::Root<WebIDL::ArrayBufferView> data)
75- {
76- m_context->make_current ();
77-
78- auto span = MUST (get_offset_span<u8 const >(*data, /* src_offset= */ 0 ));
79- glCompressedTexImage2DRobustANGLE (target, level, internalformat, width, height, border, span.size (), span.size (), span.data ());
80- }
81-
82- void WebGLRenderingContextImpl::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<WebIDL::ArrayBufferView> data)
83- {
84- m_context->make_current ();
85-
86- auto span = MUST (get_offset_span<u8 const >(*data, /* src_offset= */ 0 ));
87- glCompressedTexSubImage2DRobustANGLE (target, level, xoffset, yoffset, width, height, format, span.size (), span.size (), span.data ());
88- }
89-
90- void WebGLRenderingContextImpl::read_pixels (WebIDL::Long x, WebIDL::Long y, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, GC::Root<WebIDL::ArrayBufferView> pixels)
91- {
92- m_context->make_current ();
93-
94- if (!pixels) {
95- return ;
96- }
97-
98- auto span = MUST (get_offset_span<u8 >(*pixels, /* src_offset= */ 0 ));
99- glReadPixelsRobustANGLE (x, y, width, height, format, type, span.size (), nullptr , nullptr , nullptr , span.data ());
100- }
101-
102- void WebGLRenderingContextImpl::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<WebIDL::ArrayBufferView> pixels)
103- {
104- m_context->make_current ();
105-
106- if (pixels) {
107- auto span = MUST (get_offset_span<u8 >(*pixels, /* src_offset= */ 0 ));
108- glTexImage2DRobustANGLE (target, level, internalformat, width, height, border, format, type, span.size (), span.data ());
109- return ;
110- }
111-
112- Checked<size_t > bytes = 0 ;
113- if (type == GL_UNSIGNED_SHORT_5_6_5 && format != GL_RGB) {
114- set_error (GL_INVALID_OPERATION);
115- return ;
116- }
117-
118- if ((type == GL_UNSIGNED_SHORT_4_4_4_4 || type == GL_UNSIGNED_SHORT_5_5_5_1) && format != GL_RGBA) {
119- set_error (GL_INVALID_OPERATION);
120- return ;
121- }
122-
123- switch (format) {
124- case GL_ALPHA:
125- case GL_LUMINANCE:
126- case GL_LUMINANCE_ALPHA: {
127- if (type != GL_UNSIGNED_BYTE) {
128- set_error (GL_INVALID_ENUM);
129- return ;
130- }
131-
132- bytes = format == GL_LUMINANCE_ALPHA ? 2 : 1 ;
133- break ;
134- }
135- case GL_RGB:
136- case GL_RGBA: {
137- switch (type) {
138- case GL_UNSIGNED_BYTE:
139- bytes = format == GL_RGB ? 3 : 4 ;
140- break ;
141- case GL_UNSIGNED_SHORT_4_4_4_4:
142- case GL_UNSIGNED_SHORT_5_5_5_1:
143- case GL_UNSIGNED_SHORT_5_6_5:
144- bytes = 2 ;
145- break ;
146- default :
147- set_error (GL_INVALID_ENUM);
148- return ;
149- }
150-
151- break ;
152- }
153- default :
154- set_error (GL_INVALID_ENUM);
155- return ;
156- }
157-
158- bytes *= width;
159- bytes *= height;
160-
161- if (bytes.has_overflow ()) {
162- set_error (GL_INVALID_OPERATION);
163- return ;
164- }
165-
166- auto byte_buffer = MUST (ByteBuffer::create_zeroed (bytes.value_unchecked ()));
167- glTexImage2DRobustANGLE (target, level, internalformat, width, height, border, format, type, byte_buffer.size (), byte_buffer.data ());
168- }
169-
170- void WebGLRenderingContextImpl::tex_image2d (WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long internalformat, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, TexImageSource source)
171- {
172- m_context->make_current ();
173-
174- auto maybe_converted_texture = read_and_pixel_convert_texture_image_source (source, format, type);
175- if (!maybe_converted_texture.has_value ())
176- return ;
177- auto converted_texture = maybe_converted_texture.release_value ();
178- glTexImage2DRobustANGLE (target, level, internalformat, converted_texture.width , converted_texture.height , 0 , format, type, converted_texture.buffer .size (), converted_texture.buffer .data ());
179- }
180-
181- void WebGLRenderingContextImpl::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<WebIDL::ArrayBufferView> pixels)
182- {
183- m_context->make_current ();
184-
185- auto span = MUST (get_offset_span<u8 >(*pixels, /* src_offset= */ 0 ));
186- glTexSubImage2DRobustANGLE (target, level, xoffset, yoffset, width, height, format, type, span.size (), span.data ());
187- }
188-
189- void WebGLRenderingContextImpl::tex_sub_image2d (WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, TexImageSource source)
190- {
191- m_context->make_current ();
192-
193- auto maybe_converted_texture = read_and_pixel_convert_texture_image_source (source, format, type);
194-
195- if (!maybe_converted_texture.has_value ())
196- return ;
197- auto converted_texture = maybe_converted_texture.release_value ();
198- glTexSubImage2DRobustANGLE (target, level, xoffset, yoffset, converted_texture.width , converted_texture.height , format, type, converted_texture.buffer .size (), converted_texture.buffer .data ());
199- }
200-
201- void WebGLRenderingContextImpl::uniform1fv (GC::Root<WebGLUniformLocation> location, Float32List v)
202- {
203- m_context->make_current ();
204-
205- if (!location)
206- return ;
207- auto span = MUST (span_from_float32_list (v, /* src_offset= */ 0 ));
208- glUniform1fv (location->handle (), span.size (), span.data ());
209- }
210-
211- void WebGLRenderingContextImpl::uniform2fv (GC::Root<WebGLUniformLocation> location, Float32List v)
212- {
213- m_context->make_current ();
214-
215- if (!location)
216- return ;
217- auto span = MUST (span_from_float32_list (v, /* src_offset= */ 0 ));
218- if (span.size () % 2 != 0 ) [[unlikely]] {
219- set_error (GL_INVALID_VALUE);
220- return ;
221- }
222- glUniform2fv (location->handle (), span.size () / 2 , span.data ());
223- }
224-
225- void WebGLRenderingContextImpl::uniform3fv (GC::Root<WebGLUniformLocation> location, Float32List v)
226- {
227- m_context->make_current ();
228-
229- if (!location)
230- return ;
231- auto span = MUST (span_from_float32_list (v, /* src_offset= */ 0 ));
232- if (span.size () % 3 != 0 ) [[unlikely]] {
233- set_error (GL_INVALID_VALUE);
234- return ;
235- }
236- glUniform3fv (location->handle (), span.size () / 3 , span.data ());
237- }
238-
239- void WebGLRenderingContextImpl::uniform4fv (GC::Root<WebGLUniformLocation> location, Float32List v)
240- {
241- m_context->make_current ();
242-
243- if (!location)
244- return ;
245- auto span = MUST (span_from_float32_list (v, /* src_offset= */ 0 ));
246- if (span.size () % 4 != 0 ) [[unlikely]] {
247- set_error (GL_INVALID_VALUE);
248- return ;
249- }
250- glUniform4fv (location->handle (), span.size () / 4 , span.data ());
251- }
252-
253- void WebGLRenderingContextImpl::uniform1iv (GC::Root<WebGLUniformLocation> location, Int32List v)
254- {
255- m_context->make_current ();
256-
257- if (!location)
258- return ;
259- auto span = MUST (span_from_int32_list (v, /* src_offset= */ 0 ));
260- glUniform1iv (location->handle (), span.size (), span.data ());
261- }
262-
263- void WebGLRenderingContextImpl::uniform2iv (GC::Root<WebGLUniformLocation> location, Int32List v)
264- {
265- m_context->make_current ();
266-
267- if (!location)
268- return ;
269- auto span = MUST (span_from_int32_list (v, /* src_offset= */ 0 ));
270- if (span.size () % 2 != 0 ) [[unlikely]] {
271- set_error (GL_INVALID_VALUE);
272- return ;
273- }
274- glUniform2iv (location->handle (), span.size () / 2 , span.data ());
275- }
276-
277- void WebGLRenderingContextImpl::uniform3iv (GC::Root<WebGLUniformLocation> location, Int32List v)
278- {
279- m_context->make_current ();
280-
281- if (!location)
282- return ;
283- auto span = MUST (span_from_int32_list (v, /* src_offset= */ 0 ));
284- if (span.size () % 3 != 0 ) [[unlikely]] {
285- set_error (GL_INVALID_VALUE);
286- return ;
287- }
288- glUniform3iv (location->handle (), span.size () / 3 , span.data ());
289- }
290-
291- void WebGLRenderingContextImpl::uniform4iv (GC::Root<WebGLUniformLocation> location, Int32List v)
292- {
293- m_context->make_current ();
294-
295- if (!location)
296- return ;
297- auto span = MUST (span_from_int32_list (v, /* src_offset= */ 0 ));
298- if (span.size () % 4 != 0 ) [[unlikely]] {
299- set_error (GL_INVALID_VALUE);
300- return ;
301- }
302- glUniform4iv (location->handle (), span.size () / 4 , span.data ());
303- }
304-
305- void WebGLRenderingContextImpl::uniform_matrix2fv (GC::Root<WebGLUniformLocation> location, bool transpose, Float32List value)
306- {
307- m_context->make_current ();
308-
309- if (!location)
310- return ;
311- constexpr auto matrix_size = 2 * 2 ;
312- auto span = MUST (span_from_float32_list (value, /* src_offset= */ 0 ));
313- if (span.size () % matrix_size != 0 ) [[unlikely]] {
314- set_error (GL_INVALID_VALUE);
315- return ;
316- }
317- glUniformMatrix2fv (location->handle (), span.size () / matrix_size, transpose, span.data ());
318- }
319-
320- void WebGLRenderingContextImpl::uniform_matrix3fv (GC::Root<WebGLUniformLocation> location, bool transpose, Float32List value)
321- {
322- m_context->make_current ();
323-
324- if (!location)
325- return ;
326- constexpr auto matrix_size = 3 * 3 ;
327- auto span = MUST (span_from_float32_list (value, /* src_offset= */ 0 ));
328- if (span.size () % matrix_size != 0 ) [[unlikely]] {
329- set_error (GL_INVALID_VALUE);
330- return ;
331- }
332- glUniformMatrix3fv (location->handle (), span.size () / matrix_size, transpose, span.data ());
333- }
334-
335- void WebGLRenderingContextImpl::uniform_matrix4fv (GC::Root<WebGLUniformLocation> location, bool transpose, Float32List value)
336- {
337- m_context->make_current ();
338-
339- if (!location)
340- return ;
341- constexpr auto matrix_size = 4 * 4 ;
342- auto span = MUST (span_from_float32_list (value, /* src_offset= */ 0 ));
343- if (span.size () % matrix_size != 0 ) [[unlikely]] {
344- set_error (GL_INVALID_VALUE);
345- return ;
346- }
347- glUniformMatrix4fv (location->handle (), span.size () / matrix_size, transpose, span.data ());
348- }
349-
35051void WebGLRenderingContextImpl::active_texture (WebIDL::UnsignedLong texture)
35152{
35253 m_context->make_current ();
0 commit comments