Expand description
uni-gl internal OpenGL context.
You shouldn’t use this struct directly. Instead, call the methods on WebGLRenderingContext
as it automatically dereferences into a GLContext
.
This doc is not intended to cover all OpenGL API in depth. Check https://www.khronos.org/opengl/ for more information.
Fields
reference: u32
openGL internal reference
is_webgl2: bool
whether this context is a WebGL 2.0 context
Implementations
sourceimpl GLContext
impl GLContext
pub fn new() -> GLContext
pub fn print<T: Into<String>>(msg: T)
sourcepub fn create_buffer(&self) -> WebGLBuffer
pub fn create_buffer(&self) -> WebGLBuffer
create a new OpenGL buffer
sourcepub fn delete_buffer(&self, buffer: &WebGLBuffer)
pub fn delete_buffer(&self, buffer: &WebGLBuffer)
delete an existing buffer
sourcepub fn bind_buffer(&self, kind: BufferKind, buffer: &WebGLBuffer)
pub fn bind_buffer(&self, kind: BufferKind, buffer: &WebGLBuffer)
bind a buffer to current state.
sourcepub fn buffer_data(&self, kind: BufferKind, data: &[u8], draw: DrawMode)
pub fn buffer_data(&self, kind: BufferKind, data: &[u8], draw: DrawMode)
fills a buffer with data.
kind : see GLContext::bind_buffer
.
sourcepub fn buffer_sub_data(&self, kind: BufferKind, offset: u32, data: &[u8])
pub fn buffer_sub_data(&self, kind: BufferKind, offset: u32, data: &[u8])
update a subset of a buffer
kind : see GLContext::bind_buffer
.
offset : offset in the buffer where data replacement will begin
sourcepub fn unbind_buffer(&self, kind: BufferKind)
pub fn unbind_buffer(&self, kind: BufferKind)
this buffer is not bound to the current state anymore.
sourcepub fn create_shader(&self, kind: ShaderKind) -> WebGLShader
pub fn create_shader(&self, kind: ShaderKind) -> WebGLShader
create a new shader.
sourcepub fn shader_source(&self, shader: &WebGLShader, source: &str)
pub fn shader_source(&self, shader: &WebGLShader, source: &str)
set or replace the source code in a shader
sourcepub fn compile_shader(&self, shader: &WebGLShader)
pub fn compile_shader(&self, shader: &WebGLShader)
compile a shader
sourcepub fn create_program(&self) -> WebGLProgram
pub fn create_program(&self) -> WebGLProgram
create a program
sourcepub fn link_program(&self, program: &WebGLProgram)
pub fn link_program(&self, program: &WebGLProgram)
link a program
sourcepub fn use_program(&self, program: &WebGLProgram)
pub fn use_program(&self, program: &WebGLProgram)
bind a program to the current state.
sourcepub fn attach_shader(&self, program: &WebGLProgram, shader: &WebGLShader)
pub fn attach_shader(&self, program: &WebGLProgram, shader: &WebGLShader)
attach a shader to a program. A program must have two shaders : vertex and fragment shader.
sourcepub fn bind_attrib_location(&self, program: &WebGLProgram, name: &str, loc: u32)
pub fn bind_attrib_location(&self, program: &WebGLProgram, name: &str, loc: u32)
associate a generic vertex attribute index with a named attribute
sourcepub fn get_attrib_location(
&self,
program: &WebGLProgram,
name: &str
) -> Option<u32>
pub fn get_attrib_location(
&self,
program: &WebGLProgram,
name: &str
) -> Option<u32>
return the location of an attribute variable
sourcepub fn get_uniform_location(
&self,
program: &WebGLProgram,
name: &str
) -> Option<WebGLUniformLocation>
pub fn get_uniform_location(
&self,
program: &WebGLProgram,
name: &str
) -> Option<WebGLUniformLocation>
return the location of a uniform variable
sourcepub fn vertex_attrib_pointer(
&self,
location: u32,
size: AttributeSize,
kind: DataType,
normalized: bool,
stride: u32,
offset: u32
)
pub fn vertex_attrib_pointer(
&self,
location: u32,
size: AttributeSize,
kind: DataType,
normalized: bool,
stride: u32,
offset: u32
)
define an array of generic vertex attribute data
sourcepub fn enable_vertex_attrib_array(&self, location: u32)
pub fn enable_vertex_attrib_array(&self, location: u32)
enable a generic vertex attribute array
sourcepub fn clear_color(&self, r: f32, g: f32, b: f32, a: f32)
pub fn clear_color(&self, r: f32, g: f32, b: f32, a: f32)
specify clear values for the color buffers
sourcepub fn cull_face(&self, flag: Culling)
pub fn cull_face(&self, flag: Culling)
specify whether front- or back-facing polygons can be culled
sourcepub fn depth_mask(&self, b: bool)
pub fn depth_mask(&self, b: bool)
enable or disable writing into the depth buffer
sourcepub fn depth_func(&self, d: DepthTest)
pub fn depth_func(&self, d: DepthTest)
specify the value used for depth buffer comparisons
sourcepub fn clear_depth(&self, value: f32)
pub fn clear_depth(&self, value: f32)
specify the clear value for the depth buffer
sourcepub fn draw_elements(
&self,
mode: Primitives,
count: usize,
kind: DataType,
offset: u32
)
pub fn draw_elements(
&self,
mode: Primitives,
count: usize,
kind: DataType,
offset: u32
)
render primitives from indexed array data
sourcepub fn draw_arrays(&self, mode: Primitives, count: usize)
pub fn draw_arrays(&self, mode: Primitives, count: usize)
render primitives from array data
sourcepub fn read_pixels(
&self,
x: u32,
y: u32,
width: u32,
height: u32,
format: PixelFormat,
kind: PixelType,
data: &mut [u8]
)
pub fn read_pixels(
&self,
x: u32,
y: u32,
width: u32,
height: u32,
format: PixelFormat,
kind: PixelType,
data: &mut [u8]
)
read a block of pixels from the frame buffer
sourcepub fn pixel_storei(&self, storage: PixelStorageMode, value: i32)
pub fn pixel_storei(&self, storage: PixelStorageMode, value: i32)
set pixel storage modes
sourcepub fn tex_image2d(
&self,
target: TextureBindPoint,
level: u8,
width: u16,
height: u16,
format: PixelFormat,
kind: PixelType,
pixels: &[u8]
)
pub fn tex_image2d(
&self,
target: TextureBindPoint,
level: u8,
width: u16,
height: u16,
format: PixelFormat,
kind: PixelType,
pixels: &[u8]
)
specify a two-dimensional texture image
sourcepub fn tex_sub_image2d(
&self,
target: TextureBindPoint,
level: u8,
xoffset: u16,
yoffset: u16,
width: u16,
height: u16,
format: PixelFormat,
kind: PixelType,
pixels: &[u8]
)
pub fn tex_sub_image2d(
&self,
target: TextureBindPoint,
level: u8,
xoffset: u16,
yoffset: u16,
width: u16,
height: u16,
format: PixelFormat,
kind: PixelType,
pixels: &[u8]
)
update a part of a two-dimensional texture subimage
sourcepub fn compressed_tex_image2d(
&self,
target: TextureBindPoint,
level: u8,
compression: TextureCompression,
width: u16,
height: u16,
data: &[u8]
)
pub fn compressed_tex_image2d(
&self,
target: TextureBindPoint,
level: u8,
compression: TextureCompression,
width: u16,
height: u16,
data: &[u8]
)
specify a two-dimensional texture image in a compressed format
sourcepub fn get_program_parameter(
&self,
program: &WebGLProgram,
pname: ShaderParameter
) -> i32
pub fn get_program_parameter(
&self,
program: &WebGLProgram,
pname: ShaderParameter
) -> i32
return informations about current program
sourcepub fn create_texture(&self) -> WebGLTexture
pub fn create_texture(&self) -> WebGLTexture
create a new texture object
sourcepub fn delete_texture(&self, texture: &WebGLTexture)
pub fn delete_texture(&self, texture: &WebGLTexture)
destroy a texture object
sourcepub fn generate_mipmap(&self)
pub fn generate_mipmap(&self)
generate mipmaps for current 2D texture
sourcepub fn generate_mipmap_cube(&self)
pub fn generate_mipmap_cube(&self)
generate mipmaps for current cube map texture
sourcepub fn active_texture(&self, active: u32)
pub fn active_texture(&self, active: u32)
select active texture unit
sourcepub fn bind_texture(&self, texture: &WebGLTexture)
pub fn bind_texture(&self, texture: &WebGLTexture)
bind a named 2D texture to a texturing target
sourcepub fn unbind_texture(&self)
pub fn unbind_texture(&self)
current 2D texture is not bound to current state anymore
sourcepub fn bind_texture_cube(&self, texture: &WebGLTexture)
pub fn bind_texture_cube(&self, texture: &WebGLTexture)
bind a named cube map texture to a texturing target
sourcepub fn unbind_texture_cube(&self)
pub fn unbind_texture_cube(&self)
current cube map texture is not bound to current state anymore
sourcepub fn blend_equation(&self, eq: BlendEquation)
pub fn blend_equation(&self, eq: BlendEquation)
set the RGB alpha blend equation
sourcepub fn blend_func(&self, b1: BlendMode, b2: BlendMode)
pub fn blend_func(&self, b1: BlendMode, b2: BlendMode)
specify pixel arithmetic for RGB and alpha components separately
sourcepub fn uniform_matrix_4fv(
&self,
location: &WebGLUniformLocation,
value: &[[f32; 4]; 4]
)
pub fn uniform_matrix_4fv(
&self,
location: &WebGLUniformLocation,
value: &[[f32; 4]; 4]
)
specify the value of a mat4 uniform variable for the current program object
sourcepub fn uniform_matrix_3fv(
&self,
location: &WebGLUniformLocation,
value: &[[f32; 3]; 3]
)
pub fn uniform_matrix_3fv(
&self,
location: &WebGLUniformLocation,
value: &[[f32; 3]; 3]
)
specify the value of a mat3 uniform variable for the current program object
sourcepub fn uniform_matrix_2fv(
&self,
location: &WebGLUniformLocation,
value: &[[f32; 2]; 2]
)
pub fn uniform_matrix_2fv(
&self,
location: &WebGLUniformLocation,
value: &[[f32; 2]; 2]
)
specify the value of a mat2 uniform variable for the current program object
sourcepub fn uniform_1i(&self, location: &WebGLUniformLocation, value: i32)
pub fn uniform_1i(&self, location: &WebGLUniformLocation, value: i32)
specify the value of an int uniform variable for the current program object
sourcepub fn uniform_1f(&self, location: &WebGLUniformLocation, value: f32)
pub fn uniform_1f(&self, location: &WebGLUniformLocation, value: f32)
specify the value of a float uniform variable for the current program object
sourcepub fn uniform_2f(&self, location: &WebGLUniformLocation, value: (f32, f32))
pub fn uniform_2f(&self, location: &WebGLUniformLocation, value: (f32, f32))
specify the value of a vec2 uniform variable for the current program object
sourcepub fn uniform_3f(&self, location: &WebGLUniformLocation, value: (f32, f32, f32))
pub fn uniform_3f(&self, location: &WebGLUniformLocation, value: (f32, f32, f32))
specify the value of a vec3 uniform variable for the current program object
sourcepub fn uniform_4f(
&self,
location: &WebGLUniformLocation,
value: (f32, f32, f32, f32)
)
pub fn uniform_4f(
&self,
location: &WebGLUniformLocation,
value: (f32, f32, f32, f32)
)
specify the value of a vec4 uniform variable for the current program object
sourcepub fn tex_parameteri(
&self,
kind: TextureKind,
pname: TextureParameter,
param: i32
)
pub fn tex_parameteri(
&self,
kind: TextureKind,
pname: TextureParameter,
param: i32
)
set texture integer parameters
sourcepub fn tex_parameterfv(
&self,
kind: TextureKind,
pname: TextureParameter,
param: f32
)
pub fn tex_parameterfv(
&self,
kind: TextureKind,
pname: TextureParameter,
param: f32
)
set texture float parameters
sourcepub fn create_vertex_array(&self) -> WebGLVertexArray
pub fn create_vertex_array(&self) -> WebGLVertexArray
create a vertex array object
sourcepub fn delete_vertex_array(&self, vao: &WebGLVertexArray)
pub fn delete_vertex_array(&self, vao: &WebGLVertexArray)
destroy a vertex array object
sourcepub fn bind_vertex_array(&self, vao: &WebGLVertexArray)
pub fn bind_vertex_array(&self, vao: &WebGLVertexArray)
bind a vertex array object to current state
sourcepub fn unbind_vertex_array(&self, _vao: &WebGLVertexArray)
pub fn unbind_vertex_array(&self, _vao: &WebGLVertexArray)
current vertex array object is not bound to the current state anymore
sourcepub fn draw_buffer(&self, buffers: &[ColorBuffer])
pub fn draw_buffer(&self, buffers: &[ColorBuffer])
specify which color buffers are to be drawn into
sourcepub fn create_framebuffer(&self) -> WebGLFrameBuffer
pub fn create_framebuffer(&self) -> WebGLFrameBuffer
create a new framebuffer
sourcepub fn delete_framebuffer(&self, fb: &WebGLFrameBuffer)
pub fn delete_framebuffer(&self, fb: &WebGLFrameBuffer)
destroy a framebuffer
sourcepub fn bind_framebuffer(&self, buffer: Buffers, fb: &WebGLFrameBuffer)
pub fn bind_framebuffer(&self, buffer: Buffers, fb: &WebGLFrameBuffer)
bind a framebuffer to the current state
sourcepub fn framebuffer_texture2d(
&self,
target: Buffers,
attachment: Buffers,
textarget: TextureBindPoint,
texture: &WebGLTexture,
level: i32
)
pub fn framebuffer_texture2d(
&self,
target: Buffers,
attachment: Buffers,
textarget: TextureBindPoint,
texture: &WebGLTexture,
level: i32
)
attach a texture to a framebuffer
sourcepub fn unbind_framebuffer(&self, buffer: Buffers)
pub fn unbind_framebuffer(&self, buffer: Buffers)
unbind a framebuffer