pub struct GLContext {
pub reference: u32,
pub is_webgl2: bool,
}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: u32openGL internal reference
is_webgl2: boolwhether this context is a WebGL 2.0 context
Implementations§
Source§impl 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