1 // Copyright 2014 The Servo Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9 
10 use std::mem;
11 use std::mem::size_of;
12 use std::os::raw::{c_char, c_int, c_void};
13 use std::ptr;
14 use std::rc::Rc;
15 use std::str;
16 use std::iter::repeat;
17 use std::ffi::{CString, CStr};
18 use ffi;
19 
20 pub use ffi::types::*;
21 pub use ffi::*;
22 
23 pub use ffi_gl::Gl as GlFfi;
24 pub use ffi_gles::Gles2 as GlesFfi;
25 
26 #[derive(Debug, Eq, PartialEq)]
27 pub enum GlType {
28     Gl,
29     Gles,
30 }
31 
32 impl Default for GlType {
33     #[cfg(any(target_os="android", target_os="ios"))]
default() -> GlType34     fn default() -> GlType {
35         GlType::Gles
36     }
37     #[cfg(not(any(target_os="android", target_os="ios")))]
default() -> GlType38     fn default() -> GlType {
39         GlType::Gl
40     }
41 }
42 
calculate_length(width: GLsizei, height: GLsizei, format: GLenum, pixel_type: GLenum) -> usize43 fn calculate_length(width: GLsizei, height: GLsizei, format: GLenum, pixel_type: GLenum) -> usize {
44     let colors = match format {
45         ffi::RED => 1,
46         ffi::RGB => 3,
47         ffi::BGR => 3,
48 
49         ffi::RGBA => 4,
50         ffi::BGRA => 4,
51 
52         ffi::ALPHA => 1,
53         ffi::LUMINANCE => 1,
54         ffi::DEPTH_COMPONENT => 1,
55         _ => panic!("unsupported format for read_pixels: {:?}", format),
56     };
57     let depth = match pixel_type {
58         ffi::UNSIGNED_BYTE => 1,
59         ffi::FLOAT=> 4,
60         _ => panic!("unsupported pixel_type for read_pixels: {:?}", pixel_type),
61     };
62 
63     return (width * height * colors * depth) as usize;
64 }
65 
66 pub trait Gl {
get_type(&self) -> GlType67     fn get_type(&self) -> GlType;
buffer_data_untyped(&self, target: GLenum, size: GLsizeiptr, data: *const GLvoid, usage: GLenum)68     fn buffer_data_untyped(&self,
69                            target: GLenum,
70                            size: GLsizeiptr,
71                            data: *const GLvoid,
72                            usage: GLenum);
buffer_sub_data_untyped(&self, target: GLenum, offset: isize, size: GLsizeiptr, data: *const GLvoid)73     fn buffer_sub_data_untyped(&self,
74                                target: GLenum,
75                                offset: isize,
76                                size: GLsizeiptr,
77                                data: *const GLvoid);
tex_buffer(&self, target: GLenum, internal_format: GLenum, buffer: GLuint)78     fn tex_buffer(&self, target: GLenum, internal_format: GLenum, buffer: GLuint);
shader_source(&self, shader: GLuint, strings: &[&[u8]])79     fn shader_source(&self, shader: GLuint, strings: &[&[u8]]);
read_buffer(&self, mode: GLenum)80     fn read_buffer(&self, mode: GLenum);
read_pixels_into_buffer(&self, x: GLint, y: GLint, width: GLsizei, height: GLsizei, format: GLenum, pixel_type: GLenum, dst_buffer: &mut [u8])81     fn read_pixels_into_buffer(&self,
82                                x: GLint,
83                                y: GLint,
84                                width: GLsizei,
85                                height: GLsizei,
86                                format: GLenum,
87                                pixel_type: GLenum,
88                                dst_buffer: &mut [u8]);
read_pixels(&self, x: GLint, y: GLint, width: GLsizei, height: GLsizei, format: GLenum, pixel_type: GLenum) -> Vec<u8>89     fn read_pixels(&self,
90                    x: GLint,
91                    y: GLint,
92                    width: GLsizei,
93                    height: GLsizei,
94                    format: GLenum,
95                    pixel_type: GLenum)
96                    -> Vec<u8>;
sample_coverage(&self, value: GLclampf, invert: bool)97     fn sample_coverage(&self, value: GLclampf, invert: bool);
polygon_offset(&self, factor: GLfloat, units: GLfloat)98     fn polygon_offset(&self, factor: GLfloat, units: GLfloat);
pixel_store_i(&self, name: GLenum, param: GLint)99     fn pixel_store_i(&self, name: GLenum, param: GLint);
gen_buffers(&self, n: GLsizei) -> Vec<GLuint>100     fn gen_buffers(&self, n: GLsizei) -> Vec<GLuint>;
gen_renderbuffers(&self, n: GLsizei) -> Vec<GLuint>101     fn gen_renderbuffers(&self, n: GLsizei) -> Vec<GLuint>;
gen_framebuffers(&self, n: GLsizei) -> Vec<GLuint>102     fn gen_framebuffers(&self, n: GLsizei) -> Vec<GLuint>;
gen_textures(&self, n: GLsizei) -> Vec<GLuint>103     fn gen_textures(&self, n: GLsizei) -> Vec<GLuint>;
gen_vertex_arrays(&self, n: GLsizei) -> Vec<GLuint>104     fn gen_vertex_arrays(&self, n: GLsizei) -> Vec<GLuint>;
gen_queries(&self, n: GLsizei) -> Vec<GLuint>105     fn gen_queries(&self, n: GLsizei) -> Vec<GLuint>;
begin_query(&self, target: GLenum, id: GLuint)106     fn begin_query(&self, target: GLenum, id: GLuint);
end_query(&self, target: GLenum)107     fn end_query(&self, target: GLenum);
query_counter(&self, id: GLuint, target: GLenum)108     fn query_counter(&self, id: GLuint, target: GLenum);
get_query_object_iv(&self, id: GLuint, pname: GLenum) -> i32109     fn get_query_object_iv(&self, id: GLuint, pname: GLenum) -> i32;
get_query_object_uiv(&self, id: GLuint, pname: GLenum) -> u32110     fn get_query_object_uiv(&self, id: GLuint, pname: GLenum) -> u32;
get_query_object_i64v(&self, id: GLuint, pname: GLenum) -> i64111     fn get_query_object_i64v(&self, id: GLuint, pname: GLenum) -> i64;
get_query_object_ui64v(&self, id: GLuint, pname: GLenum) -> u64112     fn get_query_object_ui64v(&self, id: GLuint, pname: GLenum) -> u64;
delete_queries(&self, queries: &[GLuint])113     fn delete_queries(&self, queries: &[GLuint]);
delete_vertex_arrays(&self, vertex_arrays: &[GLuint])114     fn delete_vertex_arrays(&self, vertex_arrays: &[GLuint]);
delete_buffers(&self, buffers: &[GLuint])115     fn delete_buffers(&self, buffers: &[GLuint]);
delete_renderbuffers(&self, renderbuffers: &[GLuint])116     fn delete_renderbuffers(&self, renderbuffers: &[GLuint]);
delete_framebuffers(&self, framebuffers: &[GLuint])117     fn delete_framebuffers(&self, framebuffers: &[GLuint]);
delete_textures(&self, textures: &[GLuint])118     fn delete_textures(&self, textures: &[GLuint]);
framebuffer_renderbuffer(&self, target: GLenum, attachment: GLenum, renderbuffertarget: GLenum, renderbuffer: GLuint)119     fn framebuffer_renderbuffer(&self,
120                                 target: GLenum,
121                                 attachment: GLenum,
122                                 renderbuffertarget: GLenum,
123                                 renderbuffer: GLuint);
renderbuffer_storage(&self, target: GLenum, internalformat: GLenum, width: GLsizei, height: GLsizei)124     fn renderbuffer_storage(&self,
125                             target: GLenum,
126                             internalformat: GLenum,
127                             width: GLsizei,
128                             height: GLsizei);
depth_func(&self, func: GLenum)129     fn depth_func(&self, func: GLenum);
active_texture(&self, texture: GLenum)130     fn active_texture(&self, texture: GLenum);
attach_shader(&self, program: GLuint, shader: GLuint)131     fn attach_shader(&self, program: GLuint, shader: GLuint);
bind_attrib_location(&self, program: GLuint, index: GLuint, name: &str)132     fn bind_attrib_location(&self, program: GLuint, index: GLuint, name: &str);
get_uniform_block_index(&self, program: GLuint, name: &str) -> GLuint133     fn get_uniform_block_index(&self, program: GLuint, name: &str) -> GLuint;
get_uniform_indices(&self, program: GLuint, names: &[&str]) -> Vec<GLuint>134     fn get_uniform_indices(&self,  program: GLuint, names: &[&str]) -> Vec<GLuint>;
bind_buffer_base(&self, target: GLenum, index: GLuint, buffer: GLuint)135     fn bind_buffer_base(&self, target: GLenum, index: GLuint, buffer: GLuint);
bind_buffer_range(&self, target: GLenum, index: GLuint, buffer: GLuint, offset: GLintptr, size: GLsizeiptr)136     fn bind_buffer_range(&self, target: GLenum, index: GLuint, buffer: GLuint, offset: GLintptr, size: GLsizeiptr);
uniform_block_binding(&self, program: GLuint, uniform_block_index: GLuint, uniform_block_binding: GLuint)137     fn uniform_block_binding(&self,
138                              program: GLuint,
139                              uniform_block_index: GLuint,
140                              uniform_block_binding: GLuint);
bind_buffer(&self, target: GLenum, buffer: GLuint)141     fn bind_buffer(&self, target: GLenum, buffer: GLuint);
bind_vertex_array(&self, vao: GLuint)142     fn bind_vertex_array(&self, vao: GLuint);
bind_renderbuffer(&self, target: GLenum, renderbuffer: GLuint)143     fn bind_renderbuffer(&self, target: GLenum, renderbuffer: GLuint);
bind_framebuffer(&self, target: GLenum, framebuffer: GLuint)144     fn bind_framebuffer(&self, target: GLenum, framebuffer: GLuint);
bind_texture(&self, target: GLenum, texture: GLuint)145     fn bind_texture(&self, target: GLenum, texture: GLuint);
tex_image_2d(&self, target: GLenum, level: GLint, internal_format: GLint, width: GLsizei, height: GLsizei, border: GLint, format: GLenum, ty: GLenum, opt_data: Option<&[u8]>)146     fn tex_image_2d(&self,
147                     target: GLenum,
148                     level: GLint,
149                     internal_format: GLint,
150                     width: GLsizei,
151                     height: GLsizei,
152                     border: GLint,
153                     format: GLenum,
154                     ty: GLenum,
155                     opt_data: Option<&[u8]>);
compressed_tex_image_2d(&self, target: GLenum, level: GLint, internal_format: GLenum, width: GLsizei, height: GLsizei, border: GLint, data: &[u8])156     fn compressed_tex_image_2d(&self,
157                                target: GLenum,
158                                level: GLint,
159                                internal_format: GLenum,
160                                width: GLsizei,
161                                height: GLsizei,
162                                border: GLint,
163                                data: &[u8]);
compressed_tex_sub_image_2d(&self, target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, width: GLsizei, height: GLsizei, format: GLenum, data: &[u8])164     fn compressed_tex_sub_image_2d(&self,
165                                    target: GLenum,
166                                    level: GLint,
167                                    xoffset: GLint,
168                                    yoffset: GLint,
169                                    width: GLsizei,
170                                    height: GLsizei,
171                                    format: GLenum,
172                                    data: &[u8]);
tex_image_3d(&self, target: GLenum, level: GLint, internal_format: GLint, width: GLsizei, height: GLsizei, depth: GLsizei, border: GLint, format: GLenum, ty: GLenum, opt_data: Option<&[u8]>)173     fn tex_image_3d(&self,
174                     target: GLenum,
175                     level: GLint,
176                     internal_format: GLint,
177                     width: GLsizei,
178                     height: GLsizei,
179                     depth: GLsizei,
180                     border: GLint,
181                     format: GLenum,
182                     ty: GLenum,
183                     opt_data: Option<&[u8]>);
copy_tex_image_2d(&self, target: GLenum, level: GLint, internal_format: GLenum, x: GLint, y: GLint, width: GLsizei, height: GLsizei, border: GLint)184     fn copy_tex_image_2d(&self,
185                          target: GLenum,
186                          level: GLint,
187                          internal_format: GLenum,
188                          x: GLint,
189                          y: GLint,
190                          width: GLsizei,
191                          height: GLsizei,
192                          border: GLint);
copy_tex_sub_image_2d(&self, target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, x: GLint, y: GLint, width: GLsizei, height: GLsizei)193     fn copy_tex_sub_image_2d(&self,
194                              target: GLenum,
195                              level: GLint,
196                              xoffset: GLint,
197                              yoffset: GLint,
198                              x: GLint,
199                              y: GLint,
200                              width: GLsizei,
201                              height: GLsizei);
copy_tex_sub_image_3d(&self, target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, zoffset: GLint, x: GLint, y: GLint, width: GLsizei, height: GLsizei)202     fn copy_tex_sub_image_3d(&self,
203                              target: GLenum,
204                              level: GLint,
205                              xoffset: GLint,
206                              yoffset: GLint,
207                              zoffset: GLint,
208                              x: GLint,
209                              y: GLint,
210                              width: GLsizei,
211                              height: GLsizei);
tex_sub_image_2d(&self, target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, width: GLsizei, height: GLsizei, format: GLenum, ty: GLenum, data: &[u8])212     fn tex_sub_image_2d(&self,
213                         target: GLenum,
214                         level: GLint,
215                         xoffset: GLint,
216                         yoffset: GLint,
217                         width: GLsizei,
218                         height: GLsizei,
219                         format: GLenum,
220                         ty: GLenum,
221                         data: &[u8]);
tex_sub_image_2d_pbo(&self, target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, width: GLsizei, height: GLsizei, format: GLenum, ty: GLenum, offset: usize)222     fn tex_sub_image_2d_pbo(&self,
223                             target: GLenum,
224                             level: GLint,
225                             xoffset: GLint,
226                             yoffset: GLint,
227                             width: GLsizei,
228                             height: GLsizei,
229                             format: GLenum,
230                             ty: GLenum,
231                             offset: usize);
tex_sub_image_3d(&self, target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, zoffset: GLint, width: GLsizei, height: GLsizei, depth: GLsizei, format: GLenum, ty: GLenum, data: &[u8])232     fn tex_sub_image_3d(&self,
233                         target: GLenum,
234                         level: GLint,
235                         xoffset: GLint,
236                         yoffset: GLint,
237                         zoffset: GLint,
238                         width: GLsizei,
239                         height: GLsizei,
240                         depth: GLsizei,
241                         format: GLenum,
242                         ty: GLenum,
243                         data: &[u8]);
tex_sub_image_3d_pbo(&self, target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, zoffset: GLint, width: GLsizei, height: GLsizei, depth: GLsizei, format: GLenum, ty: GLenum, offset: usize)244     fn tex_sub_image_3d_pbo(&self,
245                             target: GLenum,
246                             level: GLint,
247                             xoffset: GLint,
248                             yoffset: GLint,
249                             zoffset: GLint,
250                             width: GLsizei,
251                             height: GLsizei,
252                             depth: GLsizei,
253                             format: GLenum,
254                             ty: GLenum,
255                             offset: usize);
get_tex_image_into_buffer(&self, target: GLenum, level: GLint, format: GLenum, ty: GLenum, output: &mut [u8])256     fn get_tex_image_into_buffer(&self,
257                                  target: GLenum,
258                                  level: GLint,
259                                  format: GLenum,
260                                  ty: GLenum,
261                                  output: &mut [u8]);
get_integer_v(&self, name: GLenum) -> GLint262     fn get_integer_v(&self, name: GLenum) -> GLint;
get_integer_64v(&self, name: GLenum) -> GLint64263     fn get_integer_64v(&self, name: GLenum) -> GLint64;
get_integer_iv(&self, name: GLenum, index: GLuint) -> GLint264     fn get_integer_iv(&self, name: GLenum, index: GLuint) -> GLint;
get_integer_64iv(&self, name: GLenum, index: GLuint) -> GLint64265     fn get_integer_64iv(&self, name: GLenum, index: GLuint) -> GLint64;
get_boolean_v(&self, name: GLenum) -> GLboolean266     fn get_boolean_v(&self, name: GLenum) -> GLboolean;
get_float_v(&self, name: GLenum) -> GLfloat267     fn get_float_v(&self, name: GLenum) -> GLfloat;
tex_parameter_i(&self, target: GLenum, pname: GLenum, param: GLint)268     fn tex_parameter_i(&self, target: GLenum, pname: GLenum, param: GLint);
tex_parameter_f(&self, target: GLenum, pname: GLenum, param: GLfloat)269     fn tex_parameter_f(&self, target: GLenum, pname: GLenum, param: GLfloat);
framebuffer_texture_2d(&self, target: GLenum, attachment: GLenum, textarget: GLenum, texture: GLuint, level: GLint)270     fn framebuffer_texture_2d(&self,
271                               target: GLenum,
272                               attachment: GLenum,
273                               textarget: GLenum,
274                               texture: GLuint,
275                               level: GLint);
framebuffer_texture_layer(&self, target: GLenum, attachment: GLenum, texture: GLuint, level: GLint, layer: GLint)276     fn framebuffer_texture_layer(&self,
277                                  target: GLenum,
278                                  attachment: GLenum,
279                                  texture: GLuint,
280                                  level: GLint,
281                                  layer: GLint);
blit_framebuffer(&self, src_x0: GLint, src_y0: GLint, src_x1: GLint, src_y1: GLint, dst_x0: GLint, dst_y0: GLint, dst_x1: GLint, dst_y1: GLint, mask: GLbitfield, filter: GLenum)282     fn blit_framebuffer(&self,
283                         src_x0: GLint,
284                         src_y0: GLint,
285                         src_x1: GLint,
286                         src_y1: GLint,
287                         dst_x0: GLint,
288                         dst_y0: GLint,
289                         dst_x1: GLint,
290                         dst_y1: GLint,
291                         mask: GLbitfield,
292                         filter: GLenum);
vertex_attrib_4f(&self, index: GLuint, x: GLfloat, y: GLfloat, z: GLfloat, w: GLfloat)293     fn vertex_attrib_4f(&self, index: GLuint, x: GLfloat, y: GLfloat, z: GLfloat, w: GLfloat);
vertex_attrib_pointer_f32(&self, index: GLuint, size: GLint, normalized: bool, stride: GLsizei, offset: GLuint)294     fn vertex_attrib_pointer_f32(&self,
295                                  index: GLuint,
296                                  size: GLint,
297                                  normalized: bool,
298                                  stride: GLsizei,
299                                  offset: GLuint);
vertex_attrib_pointer(&self, index: GLuint, size: GLint, type_: GLenum, normalized: bool, stride: GLsizei, offset: GLuint)300     fn vertex_attrib_pointer(&self,
301                              index: GLuint,
302                              size: GLint,
303                              type_: GLenum,
304                              normalized: bool,
305                              stride: GLsizei,
306                              offset: GLuint);
vertex_attrib_i_pointer(&self, index: GLuint, size: GLint, type_: GLenum, stride: GLsizei, offset: GLuint)307     fn vertex_attrib_i_pointer(&self,
308                                index: GLuint,
309                                size: GLint,
310                                type_: GLenum,
311                                stride: GLsizei,
312                                offset: GLuint);
vertex_attrib_divisor(&self, index: GLuint, divisor: GLuint)313     fn vertex_attrib_divisor(&self, index: GLuint, divisor: GLuint);
viewport(&self, x: GLint, y: GLint, width: GLsizei, height: GLsizei)314     fn viewport(&self, x: GLint, y: GLint, width: GLsizei, height: GLsizei);
scissor(&self, x: GLint, y: GLint, width: GLsizei, height: GLsizei)315     fn scissor(&self, x: GLint, y: GLint, width: GLsizei, height: GLsizei);
line_width(&self, width: GLfloat)316     fn line_width(&self, width: GLfloat);
use_program(&self, program: GLuint)317     fn use_program(&self, program: GLuint);
validate_program(&self, program: GLuint)318     fn validate_program(&self, program: GLuint);
draw_arrays(&self, mode: GLenum, first: GLint, count: GLsizei)319     fn draw_arrays(&self, mode: GLenum, first: GLint, count: GLsizei);
draw_arrays_instanced(&self, mode: GLenum, first: GLint, count: GLsizei, primcount: GLsizei)320     fn draw_arrays_instanced(&self,
321                              mode: GLenum,
322                              first: GLint,
323                              count: GLsizei,
324                              primcount: GLsizei);
draw_elements(&self, mode: GLenum, count: GLsizei, element_type: GLenum, indices_offset: GLuint)325     fn draw_elements(&self,
326                      mode: GLenum,
327                      count: GLsizei,
328                      element_type: GLenum,
329                      indices_offset: GLuint);
draw_elements_instanced(&self, mode: GLenum, count: GLsizei, element_type: GLenum, indices_offset: GLuint, primcount: GLsizei)330     fn draw_elements_instanced(&self,
331                                mode: GLenum,
332                                count: GLsizei,
333                                element_type: GLenum,
334                                indices_offset: GLuint,
335                                primcount: GLsizei);
blend_color(&self, r: f32, g: f32, b: f32, a: f32)336     fn blend_color(&self, r: f32, g: f32, b: f32, a: f32);
blend_func(&self, sfactor: GLenum, dfactor: GLenum)337     fn blend_func(&self, sfactor: GLenum, dfactor: GLenum);
blend_func_separate(&self, src_rgb: GLenum, dest_rgb: GLenum, src_alpha: GLenum, dest_alpha: GLenum)338     fn blend_func_separate(&self,
339                            src_rgb: GLenum,
340                            dest_rgb: GLenum,
341                            src_alpha: GLenum,
342                            dest_alpha: GLenum);
blend_equation(&self, mode: GLenum)343     fn blend_equation(&self, mode: GLenum);
blend_equation_separate(&self, mode_rgb: GLenum, mode_alpha: GLenum)344     fn blend_equation_separate(&self, mode_rgb: GLenum, mode_alpha: GLenum);
color_mask(&self, r: bool, g: bool, b: bool, a: bool)345     fn color_mask(&self, r: bool, g: bool, b: bool, a: bool);
cull_face(&self, mode: GLenum)346     fn cull_face(&self, mode: GLenum);
front_face(&self, mode: GLenum)347     fn front_face(&self, mode: GLenum);
enable(&self, cap: GLenum)348     fn enable(&self, cap: GLenum);
disable(&self, cap: GLenum)349     fn disable(&self, cap: GLenum);
hint(&self, param_name: GLenum, param_val: GLenum)350     fn hint(&self, param_name: GLenum, param_val: GLenum);
is_enabled(&self, cap: GLenum) -> GLboolean351     fn is_enabled(&self, cap: GLenum) -> GLboolean;
is_shader(&self, shader: GLuint) -> GLboolean352     fn is_shader(&self, shader: GLuint) -> GLboolean;
is_texture(&self, texture: GLenum) -> GLboolean353     fn is_texture(&self, texture: GLenum) -> GLboolean;
is_framebuffer(&self, framebuffer: GLenum) -> GLboolean354     fn is_framebuffer(&self, framebuffer: GLenum) -> GLboolean;
is_renderbuffer(&self, renderbuffer: GLenum) -> GLboolean355     fn is_renderbuffer(&self, renderbuffer: GLenum) -> GLboolean;
check_frame_buffer_status(&self, target: GLenum) -> GLenum356     fn check_frame_buffer_status(&self, target: GLenum) -> GLenum;
enable_vertex_attrib_array(&self, index: GLuint)357     fn enable_vertex_attrib_array(&self, index: GLuint);
disable_vertex_attrib_array(&self, index: GLuint)358     fn disable_vertex_attrib_array(&self, index: GLuint);
uniform_1f(&self, location: GLint, v0: GLfloat)359     fn uniform_1f(&self, location: GLint, v0: GLfloat);
uniform_1fv(&self, location: GLint, values: &[f32])360     fn uniform_1fv(&self, location: GLint, values: &[f32]);
uniform_1i(&self, location: GLint, v0: GLint)361     fn uniform_1i(&self, location: GLint, v0: GLint);
uniform_1iv(&self, location: GLint, values: &[i32])362     fn uniform_1iv(&self, location: GLint, values: &[i32]);
uniform_1ui(&self, location: GLint, v0: GLuint)363     fn uniform_1ui(&self, location: GLint, v0: GLuint);
uniform_2f(&self, location: GLint, v0: GLfloat, v1: GLfloat)364     fn uniform_2f(&self, location: GLint, v0: GLfloat, v1: GLfloat);
uniform_2fv(&self, location: GLint, values: &[f32])365     fn uniform_2fv(&self, location: GLint, values: &[f32]);
uniform_2i(&self, location: GLint, v0: GLint, v1: GLint)366     fn uniform_2i(&self, location: GLint, v0: GLint, v1: GLint);
uniform_2iv(&self, location: GLint, values: &[i32])367     fn uniform_2iv(&self, location: GLint, values: &[i32]);
uniform_2ui(&self, location: GLint, v0: GLuint, v1: GLuint)368     fn uniform_2ui(&self, location: GLint, v0: GLuint, v1: GLuint);
uniform_3f(&self, location: GLint, v0: GLfloat, v1: GLfloat, v2: GLfloat)369     fn uniform_3f(&self, location: GLint, v0: GLfloat, v1: GLfloat, v2: GLfloat);
uniform_3fv(&self, location: GLint, values: &[f32])370     fn uniform_3fv(&self, location: GLint, values: &[f32]);
uniform_3i(&self, location: GLint, v0: GLint, v1: GLint, v2: GLint)371     fn uniform_3i(&self, location: GLint, v0: GLint, v1: GLint, v2: GLint);
uniform_3iv(&self, location: GLint, values: &[i32])372     fn uniform_3iv(&self, location: GLint, values: &[i32]);
uniform_3ui(&self, location: GLint, v0: GLuint, v1: GLuint, v2: GLuint)373     fn uniform_3ui(&self, location: GLint, v0: GLuint, v1: GLuint, v2: GLuint);
uniform_4f(&self, location: GLint, x: GLfloat, y: GLfloat, z: GLfloat, w: GLfloat)374     fn uniform_4f(&self, location: GLint, x: GLfloat, y: GLfloat, z: GLfloat, w: GLfloat);
uniform_4i(&self, location: GLint, x: GLint, y: GLint, z: GLint, w: GLint)375     fn uniform_4i(&self, location: GLint, x: GLint, y: GLint, z: GLint, w: GLint);
uniform_4iv(&self, location: GLint, values: &[i32])376     fn uniform_4iv(&self, location: GLint, values: &[i32]);
uniform_4ui(&self, location: GLint, x: GLuint, y: GLuint, z: GLuint, w: GLuint)377     fn uniform_4ui(&self, location: GLint, x: GLuint, y: GLuint, z: GLuint, w: GLuint);
uniform_4fv(&self, location: GLint, values: &[f32])378     fn uniform_4fv(&self, location: GLint, values: &[f32]);
uniform_matrix_2fv(&self, location: GLint, transpose: bool, value: &[f32])379     fn uniform_matrix_2fv(&self, location: GLint, transpose: bool, value: &[f32]);
uniform_matrix_3fv(&self, location: GLint, transpose: bool, value: &[f32])380     fn uniform_matrix_3fv(&self, location: GLint, transpose: bool, value: &[f32]);
uniform_matrix_4fv(&self, location: GLint, transpose: bool, value: &[f32])381     fn uniform_matrix_4fv(&self, location: GLint, transpose: bool, value: &[f32]);
depth_mask(&self, flag: bool)382     fn depth_mask(&self, flag: bool);
depth_range(&self, near: f64, far: f64)383     fn depth_range(&self, near: f64, far: f64);
get_active_attrib(&self, program: GLuint, index: GLuint) -> (i32, u32, String)384     fn get_active_attrib(&self, program: GLuint, index: GLuint) -> (i32, u32, String);
get_active_uniform(&self, program: GLuint, index: GLuint) -> (i32, u32, String)385     fn get_active_uniform(&self, program: GLuint, index: GLuint) -> (i32, u32, String);
get_active_uniforms_iv(&self, program: GLuint, indices: Vec<GLuint>, pname: GLenum) -> Vec<GLint>386     fn get_active_uniforms_iv(&self, program: GLuint, indices: Vec<GLuint>, pname: GLenum) -> Vec<GLint>;
get_active_uniform_block_i(&self, program: GLuint, index: GLuint, pname: GLenum) -> GLint387     fn get_active_uniform_block_i(&self, program: GLuint, index: GLuint, pname: GLenum) -> GLint;
get_active_uniform_block_iv(&self, program: GLuint, index: GLuint, pname: GLenum) -> Vec<GLint>388     fn get_active_uniform_block_iv(&self, program: GLuint, index: GLuint, pname: GLenum) -> Vec<GLint>;
get_active_uniform_block_name(&self, program: GLuint, index: GLuint) -> String389     fn get_active_uniform_block_name(&self, program: GLuint, index: GLuint) -> String;
get_attrib_location(&self, program: GLuint, name: &str) -> c_int390     fn get_attrib_location(&self, program: GLuint, name: &str) -> c_int;
get_frag_data_location(&self, program: GLuint, name: &str) -> c_int391     fn get_frag_data_location(&self, program: GLuint, name: &str) -> c_int;
get_uniform_location(&self, program: GLuint, name: &str) -> c_int392     fn get_uniform_location(&self, program: GLuint, name: &str) -> c_int;
get_program_info_log(&self, program: GLuint) -> String393     fn get_program_info_log(&self, program: GLuint) -> String;
get_program_iv(&self, program: GLuint, pname: GLenum) -> GLint394     fn get_program_iv(&self, program: GLuint, pname: GLenum) -> GLint;
get_program_binary(&self, program: GLuint) -> (Vec<u8>, GLenum)395     fn get_program_binary(&self, program: GLuint) -> (Vec<u8>, GLenum);
program_binary(&self, program: GLuint, format: GLenum, binary: &[u8])396     fn program_binary(&self, program: GLuint, format: GLenum, binary: &[u8]);
program_parameter_i(&self, program: GLuint, pname: GLenum, value: GLint)397     fn program_parameter_i(&self, program: GLuint, pname: GLenum, value: GLint);
get_vertex_attrib_iv(&self, index: GLuint, pname: GLenum) -> GLint398     fn get_vertex_attrib_iv(&self, index: GLuint, pname: GLenum) -> GLint;
get_vertex_attrib_fv(&self, index: GLuint, pname: GLenum) -> Vec<GLfloat>399     fn get_vertex_attrib_fv(&self, index: GLuint, pname: GLenum) -> Vec<GLfloat>;
get_vertex_attrib_pointer_v(&self, index: GLuint, pname: GLenum) -> GLsizeiptr400     fn get_vertex_attrib_pointer_v(&self, index: GLuint, pname: GLenum) -> GLsizeiptr;
get_buffer_parameter_iv(&self, target: GLuint, pname: GLenum) -> GLint401     fn get_buffer_parameter_iv(&self, target: GLuint, pname: GLenum) -> GLint;
get_shader_info_log(&self, shader: GLuint) -> String402     fn get_shader_info_log(&self, shader: GLuint) -> String;
get_string(&self, which: GLenum) -> String403     fn get_string(&self, which: GLenum) -> String;
get_string_i(&self, which: GLenum, index: GLuint) -> String404     fn get_string_i(&self, which: GLenum, index: GLuint) -> String;
get_shader_iv(&self, shader: GLuint, pname: GLenum) -> GLint405     fn get_shader_iv(&self, shader: GLuint, pname: GLenum) -> GLint;
get_shader_precision_format(&self, shader_type: GLuint, precision_type: GLuint) -> (GLint, GLint, GLint)406     fn get_shader_precision_format(&self,
407                                    shader_type: GLuint,
408                                    precision_type: GLuint)
409                                    -> (GLint, GLint, GLint);
compile_shader(&self, shader: GLuint)410     fn compile_shader(&self, shader: GLuint);
create_program(&self) -> GLuint411     fn create_program(&self) -> GLuint;
delete_program(&self, program: GLuint)412     fn delete_program(&self, program: GLuint);
create_shader(&self, shader_type: GLenum) -> GLuint413     fn create_shader(&self, shader_type: GLenum) -> GLuint;
delete_shader(&self, shader: GLuint)414     fn delete_shader(&self, shader: GLuint);
detach_shader(&self, program: GLuint, shader: GLuint)415     fn detach_shader(&self, program: GLuint, shader: GLuint);
link_program(&self, program: GLuint)416     fn link_program(&self, program: GLuint);
clear_color(&self, r: f32, g: f32, b: f32, a: f32)417     fn clear_color(&self, r: f32, g: f32, b: f32, a: f32);
clear(&self, buffer_mask: GLbitfield)418     fn clear(&self, buffer_mask: GLbitfield);
clear_depth(&self, depth: f64)419     fn clear_depth(&self, depth: f64);
clear_stencil(&self, s: GLint)420     fn clear_stencil(&self, s: GLint);
flush(&self)421     fn flush(&self);
finish(&self)422     fn finish(&self);
get_error(&self) -> GLenum423     fn get_error(&self) -> GLenum;
stencil_mask(&self, mask: GLuint)424     fn stencil_mask(&self, mask: GLuint);
stencil_mask_separate(&self, face: GLenum, mask: GLuint)425     fn stencil_mask_separate(&self, face: GLenum, mask: GLuint);
stencil_func(&self, func: GLenum, ref_: GLint, mask: GLuint)426     fn stencil_func(&self, func: GLenum, ref_: GLint, mask: GLuint);
stencil_func_separate(&self, face: GLenum, func: GLenum, ref_: GLint, mask: GLuint)427     fn stencil_func_separate(&self, face: GLenum, func: GLenum, ref_: GLint, mask: GLuint);
stencil_op(&self, sfail: GLenum, dpfail: GLenum, dppass: GLenum)428     fn stencil_op(&self, sfail: GLenum, dpfail: GLenum, dppass: GLenum);
stencil_op_separate(&self, face: GLenum, sfail: GLenum, dpfail: GLenum, dppass: GLenum)429     fn stencil_op_separate(&self, face: GLenum, sfail: GLenum, dpfail: GLenum, dppass: GLenum);
egl_image_target_texture2d_oes(&self, target: GLenum, image: GLeglImageOES)430     fn egl_image_target_texture2d_oes(&self, target: GLenum, image: GLeglImageOES);
generate_mipmap(&self, target: GLenum)431     fn generate_mipmap(&self, target: GLenum);
insert_event_marker_ext(&self, message: &str)432     fn insert_event_marker_ext(&self, message: &str);
push_group_marker_ext(&self, message: &str)433     fn push_group_marker_ext(&self, message: &str);
pop_group_marker_ext(&self)434     fn pop_group_marker_ext(&self);
fence_sync(&self, condition: GLenum, flags: GLbitfield) -> GLsync435     fn fence_sync(&self, condition: GLenum, flags: GLbitfield) -> GLsync;
client_wait_sync(&self, sync: GLsync, flags: GLbitfield, timeout: GLuint64)436     fn client_wait_sync(&self, sync: GLsync, flags: GLbitfield, timeout: GLuint64);
wait_sync(&self, sync: GLsync, flags: GLbitfield, timeout: GLuint64)437     fn wait_sync(&self, sync: GLsync, flags: GLbitfield, timeout: GLuint64);
delete_sync(&self, sync: GLsync)438     fn delete_sync(&self, sync: GLsync);
texture_range_apple(&self, target: GLenum, data: &[u8])439     fn texture_range_apple(&self, target: GLenum, data: &[u8]);
gen_fences_apple(&self, n: GLsizei) -> Vec<GLuint>440     fn gen_fences_apple(&self, n: GLsizei) -> Vec<GLuint>;
delete_fences_apple(&self, fences: &[GLuint])441     fn delete_fences_apple(&self, fences: &[GLuint]);
set_fence_apple(&self, fence: GLuint)442     fn set_fence_apple(&self, fence: GLuint);
finish_fence_apple(&self, fence: GLuint)443     fn finish_fence_apple(&self, fence: GLuint);
test_fence_apple(&self, fence: GLuint)444     fn test_fence_apple(&self, fence: GLuint);
445 
446     // GL_ARB_blend_func_extended
bind_frag_data_location_indexed( &self, program: GLuint, color_number: GLuint, index: GLuint, name: &str, )447     fn bind_frag_data_location_indexed(
448         &self,
449         program: GLuint,
450         color_number: GLuint,
451         index: GLuint,
452         name: &str,
453     );
get_frag_data_index( &self, program: GLuint, name: &str, ) -> GLint454     fn get_frag_data_index(
455         &self,
456         program: GLuint,
457         name: &str,
458     ) -> GLint;
459 }
460 
461 #[inline]
buffer_data<T>(gl_: &Gl, target: GLenum, data: &[T], usage: GLenum)462 pub fn buffer_data<T>(gl_: &Gl, target: GLenum, data: &[T], usage: GLenum) {
463     gl_.buffer_data_untyped(target,
464                             (data.len() * size_of::<T>()) as GLsizeiptr,
465                             data.as_ptr() as *const GLvoid,
466                             usage)
467 }
468 
469 #[inline]
buffer_data_raw<T>(gl_: &Gl, target: GLenum, data: &T, usage: GLenum)470 pub fn buffer_data_raw<T>(gl_: &Gl, target: GLenum, data: &T, usage: GLenum) {
471     gl_.buffer_data_untyped(target,
472                             size_of::<T>() as GLsizeiptr,
473                             data as *const T as *const GLvoid,
474                             usage)
475 }
476 
477 #[inline]
buffer_sub_data<T>(gl_: &Gl, target: GLenum, offset: isize, data: &[T])478 pub fn buffer_sub_data<T>(gl_: &Gl, target: GLenum, offset: isize, data: &[T]) {
479     gl_.buffer_sub_data_untyped(target,
480                                 offset,
481                                 (data.len() * size_of::<T>()) as GLsizeiptr,
482                                 data.as_ptr() as *const GLvoid);
483 }
484 
485 include!("gl_fns.rs");
486 include!("gles_fns.rs");
487