1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
use std::mem;
use std::rc::Rc;

use glow::{Context as GlowContext, HasContext};

use crate::error::{Result, TetraError};
use crate::graphics::FilterMode;
use crate::math::{Mat2, Mat3, Mat4, Vec2, Vec3, Vec4};

type BufferId = <GlowContext as HasContext>::Buffer;
type ProgramId = <GlowContext as HasContext>::Program;
type TextureId = <GlowContext as HasContext>::Texture;
type FramebufferId = <GlowContext as HasContext>::Framebuffer;
type VertexArrayId = <GlowContext as HasContext>::VertexArray;
type UniformLocation = <GlowContext as HasContext>::UniformLocation;

pub struct GLDevice {
    gl: Rc<GlowContext>,

    current_vertex_buffer: Option<BufferId>,
    current_index_buffer: Option<BufferId>,
    current_program: Option<ProgramId>,
    current_texture: Option<TextureId>,
    current_framebuffer: Option<FramebufferId>,
    current_vertex_array: Option<VertexArrayId>,

    // TODO: I kinda don't like this being here, should probably be on the graphics context.
    default_filter_mode: FilterMode,
}

impl GLDevice {
    pub fn new(gl: GlowContext) -> Result<GLDevice> {
        unsafe {
            gl.enable(glow::CULL_FACE);
            gl.enable(glow::BLEND);

            // This default might want to change if we introduce
            // custom blending modes.
            gl.blend_func_separate(
                glow::SRC_ALPHA,
                glow::ONE_MINUS_SRC_ALPHA,
                glow::ONE,
                glow::ONE_MINUS_SRC_ALPHA,
            );

            // This is only needed for Core GL - if we wanted to be uber compatible, we'd
            // turn it off on older versions.
            let current_vertex_array = gl
                .create_vertex_array()
                .map_err(TetraError::PlatformError)?;

            gl.bind_vertex_array(Some(current_vertex_array));

            // TODO: Find a nice way of exposing this via the platform layer
            // println!("Swap Interval: {:?}", video.gl_get_swap_interval());

            Ok(GLDevice {
                gl: Rc::new(gl),

                current_vertex_buffer: None,
                current_index_buffer: None,
                current_program: None,
                current_texture: None,
                current_framebuffer: None,
                current_vertex_array: Some(current_vertex_array),

                default_filter_mode: FilterMode::Nearest,
            })
        }
    }

    pub fn get_renderer(&self) -> String {
        unsafe { self.gl.get_parameter_string(glow::RENDERER) }
    }

    pub fn get_version(&self) -> String {
        unsafe { self.gl.get_parameter_string(glow::VERSION) }
    }

    pub fn get_vendor(&self) -> String {
        unsafe { self.gl.get_parameter_string(glow::VENDOR) }
    }

    pub fn get_shading_language_version(&self) -> String {
        unsafe { self.gl.get_parameter_string(glow::SHADING_LANGUAGE_VERSION) }
    }

    pub fn clear(&mut self, r: f32, g: f32, b: f32, a: f32) {
        unsafe {
            self.gl.clear_color(r, g, b, a);
            self.gl.clear(glow::COLOR_BUFFER_BIT);
        }
    }

    pub fn front_face(&mut self, front_face: FrontFace) {
        unsafe {
            self.gl.front_face(front_face.into());
        }
    }

    pub fn new_vertex_buffer(
        &mut self,
        count: usize,
        stride: usize,
        usage: BufferUsage,
    ) -> Result<GLVertexBuffer> {
        unsafe {
            let id = self.gl.create_buffer().map_err(TetraError::PlatformError)?;

            let buffer = GLVertexBuffer {
                gl: Rc::clone(&self.gl),
                id,
                count,
                stride,
            };

            self.bind_vertex_buffer(Some(&buffer));

            self.gl.buffer_data_size(
                glow::ARRAY_BUFFER,
                (count * mem::size_of::<f32>()) as i32,
                usage.into(),
            );

            Ok(buffer)
        }
    }

    pub fn set_vertex_buffer_attribute(
        &mut self,
        buffer: &GLVertexBuffer,
        index: u32,
        size: i32,
        offset: usize,
    ) {
        // TODO: This feels a bit unergonomic...

        unsafe {
            self.bind_vertex_buffer(Some(buffer));

            self.gl.vertex_attrib_pointer_f32(
                index,
                size,
                glow::FLOAT,
                false,
                (buffer.stride * mem::size_of::<f32>()) as i32,
                (offset * mem::size_of::<f32>()) as i32,
            );

            self.gl.enable_vertex_attrib_array(index);
        }
    }

    pub fn set_vertex_buffer_data(&mut self, buffer: &GLVertexBuffer, data: &[f32], offset: usize) {
        unsafe {
            self.bind_vertex_buffer(Some(buffer));

            // TODO: What if we want to discard what's already there?
            // TODO: Is this cast safe?

            let byte_len = std::mem::size_of_val(data) / std::mem::size_of::<u8>();
            let byte_slice = std::slice::from_raw_parts(data.as_ptr() as *const u8, byte_len);

            self.gl.buffer_sub_data_u8_slice(
                glow::ARRAY_BUFFER,
                (offset * mem::size_of::<f32>()) as i32,
                byte_slice,
            );
        }
    }

    pub fn new_index_buffer(&mut self, count: usize, usage: BufferUsage) -> Result<GLIndexBuffer> {
        unsafe {
            let id = self.gl.create_buffer().map_err(TetraError::PlatformError)?;

            let buffer = GLIndexBuffer {
                gl: Rc::clone(&self.gl),
                id,
                count,
            };

            self.bind_index_buffer(Some(&buffer));

            self.gl.buffer_data_size(
                glow::ELEMENT_ARRAY_BUFFER,
                (count * mem::size_of::<u32>()) as i32,
                usage.into(),
            );

            Ok(buffer)
        }
    }

    pub fn set_index_buffer_data(&mut self, buffer: &GLIndexBuffer, data: &[u32], offset: usize) {
        unsafe {
            self.bind_index_buffer(Some(buffer));

            // TODO: What if we want to discard what's already there?
            // TODO: Is this cast safe?

            let byte_len = std::mem::size_of_val(data) / std::mem::size_of::<u8>();
            let byte_slice = std::slice::from_raw_parts(data.as_ptr() as *const u8, byte_len);

            self.gl.buffer_sub_data_u8_slice(
                glow::ELEMENT_ARRAY_BUFFER,
                (offset * mem::size_of::<u32>()) as i32,
                byte_slice,
            );
        }
    }

    pub fn new_program(&mut self, vertex_shader: &str, fragment_shader: &str) -> Result<GLProgram> {
        unsafe {
            let program_id = self
                .gl
                .create_program()
                .map_err(TetraError::PlatformError)?;

            // TODO: IDK if this should be applied to *all* shaders...
            self.gl.bind_attrib_location(program_id, 0, "a_position");
            self.gl.bind_attrib_location(program_id, 1, "a_uv");
            self.gl.bind_attrib_location(program_id, 2, "a_color");

            let vertex_id = self
                .gl
                .create_shader(glow::VERTEX_SHADER)
                .map_err(TetraError::PlatformError)?;

            self.gl.shader_source(vertex_id, vertex_shader);
            self.gl.compile_shader(vertex_id);
            self.gl.attach_shader(program_id, vertex_id);

            if !self.gl.get_shader_compile_status(vertex_id) {
                return Err(TetraError::InvalidShader(
                    self.gl.get_shader_info_log(vertex_id),
                ));
            }

            let fragment_id = self
                .gl
                .create_shader(glow::FRAGMENT_SHADER)
                .map_err(TetraError::PlatformError)?;

            self.gl.shader_source(fragment_id, fragment_shader);
            self.gl.compile_shader(fragment_id);
            self.gl.attach_shader(program_id, fragment_id);

            if !self.gl.get_shader_compile_status(fragment_id) {
                return Err(TetraError::InvalidShader(
                    self.gl.get_shader_info_log(fragment_id),
                ));
            }

            self.gl.link_program(program_id);

            if !self.gl.get_program_link_status(program_id) {
                return Err(TetraError::InvalidShader(
                    self.gl.get_program_info_log(program_id),
                ));
            }

            self.gl.delete_shader(vertex_id);
            self.gl.delete_shader(fragment_id);

            let program = GLProgram {
                gl: Rc::clone(&self.gl),
                id: program_id,
            };

            self.set_uniform(&program, "u_texture", 0);

            Ok(program)
        }
    }

    pub fn set_uniform<T>(&mut self, program: &GLProgram, name: &str, value: T)
    where
        T: UniformValue,
    {
        unsafe {
            self.bind_program(Some(program));
            let location = self.gl.get_uniform_location(program.id, name);
            value.set_uniform(program, location);
        }
    }

    pub fn new_texture(&mut self, width: i32, height: i32) -> Result<GLTexture> {
        // TODO: I don't think we need mipmaps?
        unsafe {
            let id = self
                .gl
                .create_texture()
                .map_err(TetraError::PlatformError)?;

            let texture = GLTexture {
                gl: Rc::clone(&self.gl),

                id,
                width,
                height,
                filter_mode: self.default_filter_mode,
            };

            self.bind_texture(Some(&texture));

            self.gl
                .tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_WRAP_S, glow::REPEAT as i32);

            self.gl
                .tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_WRAP_T, glow::REPEAT as i32);

            self.gl.tex_parameter_i32(
                glow::TEXTURE_2D,
                glow::TEXTURE_MIN_FILTER,
                self.default_filter_mode.into(),
            );

            self.gl.tex_parameter_i32(
                glow::TEXTURE_2D,
                glow::TEXTURE_MAG_FILTER,
                self.default_filter_mode.into(),
            );

            self.gl
                .tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_BASE_LEVEL, 0);

            self.gl
                .tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_MAX_LEVEL, 0);

            self.gl.tex_image_2d(
                glow::TEXTURE_2D,
                0,
                glow::RGBA as i32, // love 2 deal with legacy apis
                width,
                height,
                0,
                glow::RGBA,
                glow::UNSIGNED_BYTE,
                None,
            );

            Ok(texture)
        }
    }

    pub fn set_texture_data(
        &mut self,
        texture: &GLTexture,
        data: &[u8],
        x: i32,
        y: i32,
        width: i32,
        height: i32,
    ) {
        unsafe {
            self.bind_texture(Some(texture));

            self.gl.tex_sub_image_2d_u8_slice(
                glow::TEXTURE_2D,
                0,
                x,
                y,
                width,
                height,
                glow::RGBA,
                glow::UNSIGNED_BYTE,
                Some(data),
            )
        }
    }

    pub fn set_texture_filter_mode(&mut self, texture: &mut GLTexture, filter_mode: FilterMode) {
        self.bind_texture(Some(texture));

        unsafe {
            self.gl.tex_parameter_i32(
                glow::TEXTURE_2D,
                glow::TEXTURE_MIN_FILTER,
                filter_mode.into(),
            );

            self.gl.tex_parameter_i32(
                glow::TEXTURE_2D,
                glow::TEXTURE_MAG_FILTER,
                filter_mode.into(),
            );
        }

        texture.filter_mode = filter_mode;
    }

    pub fn new_framebuffer(
        &mut self,
        texture: &GLTexture,
        rebind_previous: bool,
    ) -> Result<GLFramebuffer> {
        unsafe {
            let id = self
                .gl
                .create_framebuffer()
                .map_err(TetraError::PlatformError)?;

            let framebuffer = GLFramebuffer {
                gl: Rc::clone(&self.gl),
                id,
            };

            let previous_id = self.current_framebuffer;

            self.bind_framebuffer(Some(&framebuffer));

            self.gl.framebuffer_texture_2d(
                glow::FRAMEBUFFER,
                glow::COLOR_ATTACHMENT0,
                glow::TEXTURE_2D,
                Some(texture.id),
                0,
            );

            if rebind_previous {
                self.gl.bind_framebuffer(glow::FRAMEBUFFER, previous_id);
                self.current_framebuffer = previous_id;
            }

            Ok(framebuffer)
        }
    }

    pub fn viewport(&mut self, x: i32, y: i32, width: i32, height: i32) {
        unsafe {
            self.gl.viewport(x, y, width, height);
        }
    }

    pub fn draw_elements(
        &mut self,
        vertex_buffer: &GLVertexBuffer,
        index_buffer: &GLIndexBuffer,
        texture: &GLTexture,
        program: &GLProgram,
        count: i32,
    ) {
        unsafe {
            self.bind_vertex_buffer(Some(vertex_buffer));
            self.bind_index_buffer(Some(index_buffer));
            self.bind_texture(Some(texture));
            self.bind_program(Some(program));

            self.gl
                .draw_elements(glow::TRIANGLES, count, glow::UNSIGNED_INT, 0);
        }
    }

    fn bind_vertex_buffer(&mut self, buffer: Option<&GLVertexBuffer>) {
        unsafe {
            let id = buffer.map(|x| x.id);

            if self.current_vertex_buffer != id {
                self.gl.bind_buffer(glow::ARRAY_BUFFER, id);
                self.current_vertex_buffer = id;
            }
        }
    }

    fn bind_index_buffer(&mut self, buffer: Option<&GLIndexBuffer>) {
        unsafe {
            let id = buffer.map(|x| x.id);

            if self.current_index_buffer != id {
                self.gl.bind_buffer(glow::ELEMENT_ARRAY_BUFFER, id);
                self.current_index_buffer = id;
            }
        }
    }

    fn bind_program(&mut self, program: Option<&GLProgram>) {
        unsafe {
            let id = program.map(|x| x.id);

            if self.current_program != id {
                self.gl.use_program(id);
                self.current_program = id;
            }
        }
    }

    fn bind_texture(&mut self, texture: Option<&GLTexture>) {
        unsafe {
            let id = texture.map(|x| x.id);

            if self.current_texture != id {
                self.gl.active_texture(glow::TEXTURE0);
                self.gl.bind_texture(glow::TEXTURE_2D, id);
                self.current_texture = id;
            }
        }
    }

    pub fn bind_framebuffer(&mut self, framebuffer: Option<&GLFramebuffer>) {
        unsafe {
            let id = framebuffer.map(|x| x.id);

            if self.current_framebuffer != id {
                self.gl.bind_framebuffer(glow::FRAMEBUFFER, id);
                self.current_framebuffer = id;
            }
        }
    }

    pub fn get_default_filter_mode(&self) -> FilterMode {
        self.default_filter_mode
    }

    pub fn set_default_filter_mode(&mut self, filter_mode: FilterMode) {
        self.default_filter_mode = filter_mode;
    }
}

impl Drop for GLDevice {
    fn drop(&mut self) {
        unsafe {
            self.gl.bind_vertex_array(None);

            if let Some(va) = self.current_vertex_array {
                self.gl.delete_vertex_array(va);
            }
        }
    }
}

#[derive(Clone, Copy)]
pub enum BufferUsage {
    StaticDraw,
    DynamicDraw,
}

impl From<BufferUsage> for u32 {
    fn from(buffer_usage: BufferUsage) -> u32 {
        match buffer_usage {
            BufferUsage::StaticDraw => glow::STATIC_DRAW,
            BufferUsage::DynamicDraw => glow::DYNAMIC_DRAW,
        }
    }
}
#[derive(Clone, Copy)]
pub enum FrontFace {
    Clockwise,
    CounterClockwise,
}

impl From<FrontFace> for u32 {
    fn from(front_face: FrontFace) -> u32 {
        match front_face {
            FrontFace::Clockwise => glow::CW,
            FrontFace::CounterClockwise => glow::CCW,
        }
    }
}

#[doc(hidden)]
impl From<FilterMode> for i32 {
    fn from(filter_mode: FilterMode) -> i32 {
        match filter_mode {
            FilterMode::Nearest => glow::NEAREST as i32,
            FilterMode::Linear => glow::LINEAR as i32,
        }
    }
}

macro_rules! handle_impls {
    ($name:ty, $delete:ident) => {
        impl PartialEq for $name {
            fn eq(&self, other: &$name) -> bool {
                self.id == other.id
            }
        }

        impl Drop for $name {
            fn drop(&mut self) {
                unsafe {
                    self.gl.$delete(self.id);
                }
            }
        }
    };
}

#[derive(Debug)]
pub struct GLVertexBuffer {
    gl: Rc<GlowContext>,

    id: BufferId,
    count: usize,
    stride: usize,
}

handle_impls!(GLVertexBuffer, delete_buffer);

#[derive(Debug)]
pub struct GLIndexBuffer {
    gl: Rc<GlowContext>,

    id: BufferId,
    count: usize,
}

handle_impls!(GLIndexBuffer, delete_buffer);

#[derive(Debug)]
pub struct GLProgram {
    gl: Rc<GlowContext>,

    id: ProgramId,
}

handle_impls!(GLProgram, delete_program);

#[derive(Debug)]
pub struct GLTexture {
    gl: Rc<GlowContext>,

    id: TextureId,
    width: i32,
    height: i32,
    filter_mode: FilterMode,
}

handle_impls!(GLTexture, delete_texture);

impl GLTexture {
    pub fn width(&self) -> i32 {
        self.width
    }

    pub fn height(&self) -> i32 {
        self.height
    }

    pub fn filter_mode(&self) -> FilterMode {
        self.filter_mode
    }
}

#[derive(Debug)]
pub struct GLFramebuffer {
    gl: Rc<GlowContext>,

    id: FramebufferId,
}

handle_impls!(GLFramebuffer, delete_framebuffer);

mod sealed {
    use super::*;
    pub trait UniformValueTypes {}
    impl UniformValueTypes for i32 {}
    impl UniformValueTypes for f32 {}
    impl UniformValueTypes for Vec2<f32> {}
    impl UniformValueTypes for Vec3<f32> {}
    impl UniformValueTypes for Vec4<f32> {}
    impl UniformValueTypes for Mat2<f32> {}
    impl UniformValueTypes for Mat3<f32> {}
    impl UniformValueTypes for Mat4<f32> {}
    impl<'a, T> UniformValueTypes for &'a T where T: UniformValueTypes {}
}

/// Implemented for types that can be passed as a uniform value to a shader.
///
/// As the implementation of this trait currently interacts directly with the OpenGL layer,
/// it's marked as a [sealed trait](https://rust-lang-nursery.github.io/api-guidelines/future-proofing.html#sealed-traits-protect-against-downstream-implementations-c-sealed),
/// and can't be implemented outside of Tetra. This might change in the future!
pub trait UniformValue: sealed::UniformValueTypes {
    #[doc(hidden)]
    unsafe fn set_uniform(&self, program: &GLProgram, location: Option<UniformLocation>);
}

impl UniformValue for i32 {
    #[doc(hidden)]
    unsafe fn set_uniform(&self, program: &GLProgram, location: Option<UniformLocation>) {
        program.gl.uniform_1_i32(location, *self);
    }
}

impl UniformValue for f32 {
    #[doc(hidden)]
    unsafe fn set_uniform(&self, program: &GLProgram, location: Option<UniformLocation>) {
        program.gl.uniform_1_f32(location, *self);
    }
}

impl UniformValue for Vec2<f32> {
    #[doc(hidden)]
    unsafe fn set_uniform(&self, program: &GLProgram, location: Option<UniformLocation>) {
        program.gl.uniform_2_f32_slice(location, &self.into_array());
    }
}

impl UniformValue for Vec3<f32> {
    #[doc(hidden)]
    unsafe fn set_uniform(&self, program: &GLProgram, location: Option<UniformLocation>) {
        program.gl.uniform_3_f32_slice(location, &self.into_array());
    }
}

impl UniformValue for Vec4<f32> {
    #[doc(hidden)]
    unsafe fn set_uniform(&self, program: &GLProgram, location: Option<UniformLocation>) {
        program.gl.uniform_4_f32_slice(location, &self.into_array());
    }
}

impl UniformValue for Mat2<f32> {
    #[doc(hidden)]
    unsafe fn set_uniform(&self, program: &GLProgram, location: Option<UniformLocation>) {
        program.gl.uniform_matrix_2_f32_slice(
            location,
            self.gl_should_transpose(),
            &self.into_col_array(),
        );
    }
}

impl UniformValue for Mat3<f32> {
    #[doc(hidden)]
    unsafe fn set_uniform(&self, program: &GLProgram, location: Option<UniformLocation>) {
        program.gl.uniform_matrix_3_f32_slice(
            location,
            self.gl_should_transpose(),
            &self.into_col_array(),
        );
    }
}

impl UniformValue for Mat4<f32> {
    #[doc(hidden)]
    unsafe fn set_uniform(&self, program: &GLProgram, location: Option<UniformLocation>) {
        program.gl.uniform_matrix_4_f32_slice(
            location,
            self.gl_should_transpose(),
            &self.into_col_array(),
        );
    }
}

impl<'a, T> UniformValue for &'a T
where
    T: UniformValue,
{
    #[doc(hidden)]
    unsafe fn set_uniform(&self, program: &GLProgram, location: Option<UniformLocation>) {
        (**self).set_uniform(program, location);
    }
}