1use glenum::{BufferKind, DataHint, PixelCopyFormat, PixelReadFormat, PixelType, TextureBindPoint};
2use rendering_context::WebGL2RenderingContext;
3use wasm_bindgen::JsValue;
4
5pub trait Buffer {
6 fn buffer_data(&self, context: &WebGL2RenderingContext, target: BufferKind, usage: DataHint);
7 fn buffer_sub_data(&self, context: &WebGL2RenderingContext, target: BufferKind, offset: i64);
8 fn get_buffer_sub_data(
9 &mut self,
10 context: &WebGL2RenderingContext,
11 target: BufferKind,
12 src_offset: i64,
13 dst_offset: u32,
14 length: u32,
15 ) -> Result<(), JsValue>;
16}
17
18pub trait Image {
19 fn tex_image_2d(
20 &self,
21 context: &WebGL2RenderingContext,
22 target: TextureBindPoint,
23 level: u32,
24 internalformat: PixelCopyFormat,
25 width: u32,
26 height: u32,
27 format: PixelCopyFormat,
28 pixel_type: PixelType,
29 ) -> Result<(), JsValue>;
30 fn tex_sub_image_2d(
42 &self,
43 context: &WebGL2RenderingContext,
44 target: TextureBindPoint,
45 level: u32,
46 xoffset: u32,
47 yoffset: u32,
48 width: u32,
49 height: u32,
50 format: PixelCopyFormat,
51 pixel_type: PixelType,
52 ) -> Result<(), JsValue>;
53
54 fn read_pixels(
55 &mut self,
56 context: &WebGL2RenderingContext,
57 x: u32,
58 y: u32,
59 width: u32,
60 height: u32,
61 format: PixelReadFormat,
62 pixel_type: PixelType,
63 ) -> Result<(), JsValue>;
64}
65
66impl Buffer for Vec<u8> {
67 fn buffer_data(&self, context: &WebGL2RenderingContext, target: BufferKind, usage: DataHint) {
68 context._buffer_data_u8(target, self, usage);
69 }
70 fn buffer_sub_data(&self, context: &WebGL2RenderingContext, target: BufferKind, offset: i64) {
71 context._buffer_sub_data_u8(target, offset, self);
72 }
73 fn get_buffer_sub_data(
74 &mut self,
75 context: &WebGL2RenderingContext,
76 target: BufferKind,
77 src_offset: i64,
78 dst_offset: u32,
79 length: u32,
80 ) -> Result<(), JsValue> {
81 context._get_buffer_sub_data_u8(target, src_offset, self, dst_offset, length)
82 }
83}
84
85impl Image for Vec<u8> {
86 fn tex_image_2d(
87 &self,
88 context: &WebGL2RenderingContext,
89 target: TextureBindPoint,
90 level: u32,
91 internalformat: PixelCopyFormat,
92 width: u32,
93 height: u32,
94 format: PixelCopyFormat,
95 pixel_type: PixelType,
96 ) -> Result<(), JsValue> {
97 context._tex_image_2d_u8(
98 target,
99 level,
100 internalformat,
101 width,
102 height,
103 0,
104 format,
105 pixel_type,
106 self,
107 )
108 }
109 fn tex_sub_image_2d(
110 &self,
111 context: &WebGL2RenderingContext,
112 target: TextureBindPoint,
113 level: u32,
114 xoffset: u32,
115 yoffset: u32,
116 width: u32,
117 height: u32,
118 format: PixelCopyFormat,
119 pixel_type: PixelType,
120 ) -> Result<(), JsValue> {
121 context._tex_sub_image_2d_u8(
122 target, level, xoffset, yoffset, width, height, format, pixel_type, self,
123 )
124 }
125 fn read_pixels(
126 &mut self,
127 context: &WebGL2RenderingContext,
128 x: u32,
129 y: u32,
130 width: u32,
131 height: u32,
132 format: PixelReadFormat,
133 pixel_type: PixelType,
134 ) -> Result<(), JsValue> {
135 context._read_pixels_u8(x, y, width, height, format, pixel_type, self)
136 }
137}
138
139impl Buffer for Vec<i8> {
140 fn buffer_data(&self, context: &WebGL2RenderingContext, target: BufferKind, usage: DataHint) {
141 context._buffer_data_i8(target, self, usage);
142 }
143 fn buffer_sub_data(&self, context: &WebGL2RenderingContext, target: BufferKind, offset: i64) {
144 context._buffer_sub_data_i8(target, offset, self);
145 }
146 fn get_buffer_sub_data(
147 &mut self,
148 context: &WebGL2RenderingContext,
149 target: BufferKind,
150 src_offset: i64,
151 dst_offset: u32,
152 length: u32,
153 ) -> Result<(), JsValue> {
154 context._get_buffer_sub_data_i8(target, src_offset, self, dst_offset, length)
155 }
156}
157
158impl Image for Vec<i8> {
159 fn tex_image_2d(
160 &self,
161 context: &WebGL2RenderingContext,
162 target: TextureBindPoint,
163 level: u32,
164 internalformat: PixelCopyFormat,
165 width: u32,
166 height: u32,
167 format: PixelCopyFormat,
168 pixel_type: PixelType,
169 ) -> Result<(), JsValue> {
170 context._tex_image_2d_i8(
171 target,
172 level,
173 internalformat,
174 width,
175 height,
176 0,
177 format,
178 pixel_type,
179 self,
180 )
181 }
182 fn tex_sub_image_2d(
183 &self,
184 context: &WebGL2RenderingContext,
185 target: TextureBindPoint,
186 level: u32,
187 xoffset: u32,
188 yoffset: u32,
189 width: u32,
190 height: u32,
191 format: PixelCopyFormat,
192 pixel_type: PixelType,
193 ) -> Result<(), JsValue> {
194 context._tex_sub_image_2d_i8(
195 target, level, xoffset, yoffset, width, height, format, pixel_type, self,
196 )
197 }
198 fn read_pixels(
199 &mut self,
200 context: &WebGL2RenderingContext,
201 x: u32,
202 y: u32,
203 width: u32,
204 height: u32,
205 format: PixelReadFormat,
206 pixel_type: PixelType,
207 ) -> Result<(), JsValue> {
208 context._read_pixels_i8(x, y, width, height, format, pixel_type, self)
209 }
210}
211
212impl Buffer for Vec<u16> {
213 fn buffer_data(&self, context: &WebGL2RenderingContext, target: BufferKind, usage: DataHint) {
214 context._buffer_data_u16(target, self, usage);
215 }
216 fn buffer_sub_data(&self, context: &WebGL2RenderingContext, target: BufferKind, offset: i64) {
217 context._buffer_sub_data_u16(target, offset, self);
218 }
219 fn get_buffer_sub_data(
220 &mut self,
221 context: &WebGL2RenderingContext,
222 target: BufferKind,
223 src_offset: i64,
224 dst_offset: u32,
225 length: u32,
226 ) -> Result<(), JsValue> {
227 context._get_buffer_sub_data_u16(target, src_offset, self, dst_offset, length)
228 }
229}
230
231impl Image for Vec<u16> {
232 fn tex_image_2d(
233 &self,
234 context: &WebGL2RenderingContext,
235 target: TextureBindPoint,
236 level: u32,
237 internalformat: PixelCopyFormat,
238 width: u32,
239 height: u32,
240 format: PixelCopyFormat,
241 pixel_type: PixelType,
242 ) -> Result<(), JsValue> {
243 context._tex_image_2d_u16(
244 target,
245 level,
246 internalformat,
247 width,
248 height,
249 0,
250 format,
251 pixel_type,
252 self,
253 )
254 }
255 fn tex_sub_image_2d(
256 &self,
257 context: &WebGL2RenderingContext,
258 target: TextureBindPoint,
259 level: u32,
260 xoffset: u32,
261 yoffset: u32,
262 width: u32,
263 height: u32,
264 format: PixelCopyFormat,
265 pixel_type: PixelType,
266 ) -> Result<(), JsValue> {
267 context._tex_sub_image_2d_u16(
268 target, level, xoffset, yoffset, width, height, format, pixel_type, self,
269 )
270 }
271 fn read_pixels(
272 &mut self,
273 context: &WebGL2RenderingContext,
274 x: u32,
275 y: u32,
276 width: u32,
277 height: u32,
278 format: PixelReadFormat,
279 pixel_type: PixelType,
280 ) -> Result<(), JsValue> {
281 context._read_pixels_u16(x, y, width, height, format, pixel_type, self)
282 }
283}
284
285impl Buffer for Vec<i16> {
286 fn buffer_data(&self, context: &WebGL2RenderingContext, target: BufferKind, usage: DataHint) {
287 context._buffer_data_i16(target, self, usage);
288 }
289 fn buffer_sub_data(&self, context: &WebGL2RenderingContext, target: BufferKind, offset: i64) {
290 context._buffer_sub_data_i16(target, offset, self);
291 }
292 fn get_buffer_sub_data(
293 &mut self,
294 context: &WebGL2RenderingContext,
295 target: BufferKind,
296 src_offset: i64,
297 dst_offset: u32,
298 length: u32,
299 ) -> Result<(), JsValue> {
300 context._get_buffer_sub_data_i16(target, src_offset, self, dst_offset, length)
301 }
302}
303
304impl Image for Vec<i16> {
305 fn tex_image_2d(
306 &self,
307 context: &WebGL2RenderingContext,
308 target: TextureBindPoint,
309 level: u32,
310 internalformat: PixelCopyFormat,
311 width: u32,
312 height: u32,
313 format: PixelCopyFormat,
314 pixel_type: PixelType,
315 ) -> Result<(), JsValue> {
316 context._tex_image_2d_i16(
317 target,
318 level,
319 internalformat,
320 width,
321 height,
322 0,
323 format,
324 pixel_type,
325 self,
326 )
327 }
328 fn tex_sub_image_2d(
329 &self,
330 context: &WebGL2RenderingContext,
331 target: TextureBindPoint,
332 level: u32,
333 xoffset: u32,
334 yoffset: u32,
335 width: u32,
336 height: u32,
337 format: PixelCopyFormat,
338 pixel_type: PixelType,
339 ) -> Result<(), JsValue> {
340 context._tex_sub_image_2d_i16(
341 target, level, xoffset, yoffset, width, height, format, pixel_type, self,
342 )
343 }
344 fn read_pixels(
345 &mut self,
346 context: &WebGL2RenderingContext,
347 x: u32,
348 y: u32,
349 width: u32,
350 height: u32,
351 format: PixelReadFormat,
352 pixel_type: PixelType,
353 ) -> Result<(), JsValue> {
354 context._read_pixels_i16(x, y, width, height, format, pixel_type, self)
355 }
356}
357
358impl Buffer for Vec<u32> {
359 fn buffer_data(&self, context: &WebGL2RenderingContext, target: BufferKind, usage: DataHint) {
360 context._buffer_data_u32(target, self, usage);
361 }
362 fn buffer_sub_data(&self, context: &WebGL2RenderingContext, target: BufferKind, offset: i64) {
363 context._buffer_sub_data_u32(target, offset, self);
364 }
365 fn get_buffer_sub_data(
366 &mut self,
367 context: &WebGL2RenderingContext,
368 target: BufferKind,
369 src_offset: i64,
370 dst_offset: u32,
371 length: u32,
372 ) -> Result<(), JsValue> {
373 context._get_buffer_sub_data_u32(target, src_offset, self, dst_offset, length)
374 }
375}
376
377impl Image for Vec<u32> {
378 fn tex_image_2d(
379 &self,
380 context: &WebGL2RenderingContext,
381 target: TextureBindPoint,
382 level: u32,
383 internalformat: PixelCopyFormat,
384 width: u32,
385 height: u32,
386 format: PixelCopyFormat,
387 pixel_type: PixelType,
388 ) -> Result<(), JsValue> {
389 context._tex_image_2d_u32(
390 target,
391 level,
392 internalformat,
393 width,
394 height,
395 0,
396 format,
397 pixel_type,
398 self,
399 )
400 }
401 fn tex_sub_image_2d(
402 &self,
403 context: &WebGL2RenderingContext,
404 target: TextureBindPoint,
405 level: u32,
406 xoffset: u32,
407 yoffset: u32,
408 width: u32,
409 height: u32,
410 format: PixelCopyFormat,
411 pixel_type: PixelType,
412 ) -> Result<(), JsValue> {
413 context._tex_sub_image_2d_u32(
414 target, level, xoffset, yoffset, width, height, format, pixel_type, self,
415 )
416 }
417 fn read_pixels(
418 &mut self,
419 context: &WebGL2RenderingContext,
420 x: u32,
421 y: u32,
422 width: u32,
423 height: u32,
424 format: PixelReadFormat,
425 pixel_type: PixelType,
426 ) -> Result<(), JsValue> {
427 context._read_pixels_u32(x, y, width, height, format, pixel_type, self)
428 }
429}
430
431impl Buffer for Vec<i32> {
432 fn buffer_data(&self, context: &WebGL2RenderingContext, target: BufferKind, usage: DataHint) {
433 context._buffer_data_i32(target, self, usage);
434 }
435 fn buffer_sub_data(&self, context: &WebGL2RenderingContext, target: BufferKind, offset: i64) {
436 context._buffer_sub_data_i32(target, offset, self);
437 }
438 fn get_buffer_sub_data(
439 &mut self,
440 context: &WebGL2RenderingContext,
441 target: BufferKind,
442 src_offset: i64,
443 dst_offset: u32,
444 length: u32,
445 ) -> Result<(), JsValue> {
446 context._get_buffer_sub_data_i32(target, src_offset, self, dst_offset, length)
447 }
448}
449
450impl Image for Vec<i32> {
451 fn tex_image_2d(
452 &self,
453 context: &WebGL2RenderingContext,
454 target: TextureBindPoint,
455 level: u32,
456 internalformat: PixelCopyFormat,
457 width: u32,
458 height: u32,
459 format: PixelCopyFormat,
460 pixel_type: PixelType,
461 ) -> Result<(), JsValue> {
462 context._tex_image_2d_i32(
463 target,
464 level,
465 internalformat,
466 width,
467 height,
468 0,
469 format,
470 pixel_type,
471 self,
472 )
473 }
474 fn tex_sub_image_2d(
475 &self,
476 context: &WebGL2RenderingContext,
477 target: TextureBindPoint,
478 level: u32,
479 xoffset: u32,
480 yoffset: u32,
481 width: u32,
482 height: u32,
483 format: PixelCopyFormat,
484 pixel_type: PixelType,
485 ) -> Result<(), JsValue> {
486 context._tex_sub_image_2d_i32(
487 target, level, xoffset, yoffset, width, height, format, pixel_type, self,
488 )
489 }
490 fn read_pixels(
491 &mut self,
492 context: &WebGL2RenderingContext,
493 x: u32,
494 y: u32,
495 width: u32,
496 height: u32,
497 format: PixelReadFormat,
498 pixel_type: PixelType,
499 ) -> Result<(), JsValue> {
500 context._read_pixels_i32(x, y, width, height, format, pixel_type, self)
501 }
502}
503
504impl Buffer for Vec<f32> {
505 fn buffer_data(&self, context: &WebGL2RenderingContext, target: BufferKind, usage: DataHint) {
506 context._buffer_data_f32(target, self, usage);
507 }
508 fn buffer_sub_data(&self, context: &WebGL2RenderingContext, target: BufferKind, offset: i64) {
509 context._buffer_sub_data_f32(target, offset, self);
510 }
511 fn get_buffer_sub_data(
512 &mut self,
513 context: &WebGL2RenderingContext,
514 target: BufferKind,
515 src_offset: i64,
516 dst_offset: u32,
517 length: u32,
518 ) -> Result<(), JsValue> {
519 context._get_buffer_sub_data_f32(target, src_offset, self, dst_offset, length)
520 }
521}
522
523impl Image for Vec<f32> {
524 fn tex_image_2d(
525 &self,
526 context: &WebGL2RenderingContext,
527 target: TextureBindPoint,
528 level: u32,
529 internalformat: PixelCopyFormat,
530 width: u32,
531 height: u32,
532 format: PixelCopyFormat,
533 pixel_type: PixelType,
534 ) -> Result<(), JsValue> {
535 context._tex_image_2d_f32(
536 target,
537 level,
538 internalformat,
539 width,
540 height,
541 0,
542 format,
543 pixel_type,
544 self,
545 )
546 }
547 fn tex_sub_image_2d(
548 &self,
549 context: &WebGL2RenderingContext,
550 target: TextureBindPoint,
551 level: u32,
552 xoffset: u32,
553 yoffset: u32,
554 width: u32,
555 height: u32,
556 format: PixelCopyFormat,
557 pixel_type: PixelType,
558 ) -> Result<(), JsValue> {
559 context._tex_sub_image_2d_f32(
560 target, level, xoffset, yoffset, width, height, format, pixel_type, self,
561 )
562 }
563 fn read_pixels(
564 &mut self,
565 context: &WebGL2RenderingContext,
566 x: u32,
567 y: u32,
568 width: u32,
569 height: u32,
570 format: PixelReadFormat,
571 pixel_type: PixelType,
572 ) -> Result<(), JsValue> {
573 context._read_pixels_f32(x, y, width, height, format, pixel_type, self)
574 }
575}
576
577impl Buffer for Vec<f64> {
578 fn buffer_data(&self, context: &WebGL2RenderingContext, target: BufferKind, usage: DataHint) {
579 context._buffer_data_f64(target, self, usage);
580 }
581 fn buffer_sub_data(&self, context: &WebGL2RenderingContext, target: BufferKind, offset: i64) {
582 context._buffer_sub_data_f64(target, offset, self);
583 }
584 fn get_buffer_sub_data(
585 &mut self,
586 context: &WebGL2RenderingContext,
587 target: BufferKind,
588 src_offset: i64,
589 dst_offset: u32,
590 length: u32,
591 ) -> Result<(), JsValue> {
592 context._get_buffer_sub_data_f64(target, src_offset, self, dst_offset, length)
593 }
594}