GLContext

Struct GLContext 

Source
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: u32

openGL internal reference

§is_webgl2: bool

whether this context is a WebGL 2.0 context

Implementations§

Source§

impl GLContext

Source

pub fn new() -> GLContext

Source

pub fn print<T: Into<String>>(msg: T)

Source

pub fn create_buffer(&self) -> WebGLBuffer

create a new OpenGL buffer

Source

pub fn delete_buffer(&self, buffer: &WebGLBuffer)

delete an existing buffer

Source

pub fn bind_buffer(&self, kind: BufferKind, buffer: &WebGLBuffer)

bind a buffer to current state.

Source

pub fn buffer_data(&self, kind: BufferKind, data: &[u8], draw: DrawMode)

fills a buffer with data.

kind : see GLContext::bind_buffer.

Source

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

Source

pub fn unbind_buffer(&self, kind: BufferKind)

this buffer is not bound to the current state anymore.

Source

pub fn create_shader(&self, kind: ShaderKind) -> WebGLShader

create a new shader.

Source

pub fn shader_source(&self, shader: &WebGLShader, source: &str)

set or replace the source code in a shader

Source

pub fn compile_shader(&self, shader: &WebGLShader)

compile a shader

Source

pub fn create_program(&self) -> WebGLProgram

create a program

link a program

Source

pub fn use_program(&self, program: &WebGLProgram)

bind a program to the current state.

Source

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.

Source

pub fn bind_attrib_location(&self, program: &WebGLProgram, name: &str, loc: u32)

associate a generic vertex attribute index with a named attribute

Source

pub fn get_attrib_location( &self, program: &WebGLProgram, name: &str, ) -> Option<u32>

return the location of an attribute variable

Source

pub fn get_uniform_location( &self, program: &WebGLProgram, name: &str, ) -> Option<WebGLUniformLocation>

return the location of a uniform variable

Source

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

Source

pub fn enable_vertex_attrib_array(&self, location: u32)

enable a generic vertex attribute array

Source

pub fn clear_color(&self, r: f32, g: f32, b: f32, a: f32)

specify clear values for the color buffers

Source

pub fn enable(&self, flag: i32)

enable GL capabilities.

flag should be one of Flag

Source

pub fn disable(&self, flag: i32)

disable GL capabilities.

flag should be one of Flag

Source

pub fn cull_face(&self, flag: Culling)

specify whether front- or back-facing polygons can be culled

Source

pub fn depth_mask(&self, b: bool)

enable or disable writing into the depth buffer

Source

pub fn depth_func(&self, d: DepthTest)

specify the value used for depth buffer comparisons

Source

pub fn clear_depth(&self, value: f32)

specify the clear value for the depth buffer

Source

pub fn clear(&self, bit: BufferBit)

clear buffers to preset values

Source

pub fn viewport(&self, x: i32, y: i32, width: u32, height: u32)

set the viewport

Source

pub fn draw_elements( &self, mode: Primitives, count: usize, kind: DataType, offset: u32, )

render primitives from indexed array data

Source

pub fn draw_arrays(&self, mode: Primitives, count: usize)

render primitives from array data

Source

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

Source

pub fn pixel_storei(&self, storage: PixelStorageMode, value: i32)

set pixel storage modes

Source

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

Source

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

Source

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

Source

pub fn get_program_parameter( &self, program: &WebGLProgram, pname: ShaderParameter, ) -> i32

return informations about current program

Source

pub fn create_texture(&self) -> WebGLTexture

create a new texture object

Source

pub fn delete_texture(&self, texture: &WebGLTexture)

destroy a texture object

Source

pub fn generate_mipmap(&self)

generate mipmaps for current 2D texture

Source

pub fn generate_mipmap_cube(&self)

generate mipmaps for current cube map texture

Source

pub fn active_texture(&self, active: u32)

select active texture unit

Source

pub fn bind_texture(&self, texture: &WebGLTexture)

bind a named 2D texture to a texturing target

Source

pub fn unbind_texture(&self)

current 2D texture is not bound to current state anymore

Source

pub fn bind_texture_cube(&self, texture: &WebGLTexture)

bind a named cube map texture to a texturing target

Source

pub fn unbind_texture_cube(&self)

current cube map texture is not bound to current state anymore

Source

pub fn blend_equation(&self, eq: BlendEquation)

set the RGB alpha blend equation

Source

pub fn blend_func(&self, b1: BlendMode, b2: BlendMode)

specify pixel arithmetic for RGB and alpha components separately

Source

pub fn blend_color(&self, r: f32, g: f32, b: f32, a: f32)

set the blend color

Source

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

Source

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

Source

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

Source

pub fn uniform_1i(&self, location: &WebGLUniformLocation, value: i32)

specify the value of an int uniform variable for the current program object

Source

pub fn uniform_1f(&self, location: &WebGLUniformLocation, value: f32)

specify the value of a float uniform variable for the current program object

Source

pub fn uniform_2f(&self, location: &WebGLUniformLocation, value: (f32, f32))

specify the value of a vec2 uniform variable for the current program object

Source

pub fn uniform_3f( &self, location: &WebGLUniformLocation, value: (f32, f32, f32), )

specify the value of a vec3 uniform variable for the current program object

Source

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

Source

pub fn tex_parameteri( &self, kind: TextureKind, pname: TextureParameter, param: i32, )

set texture integer parameters

Source

pub fn tex_parameterfv( &self, kind: TextureKind, pname: TextureParameter, param: f32, )

set texture float parameters

Source

pub fn create_vertex_array(&self) -> WebGLVertexArray

create a vertex array object

Source

pub fn delete_vertex_array(&self, vao: &WebGLVertexArray)

destroy a vertex array object

Source

pub fn bind_vertex_array(&self, vao: &WebGLVertexArray)

bind a vertex array object to current state

Source

pub fn unbind_vertex_array(&self, _vao: &WebGLVertexArray)

current vertex array object is not bound to the current state anymore

Source

pub fn draw_buffer(&self, buffers: &[ColorBuffer])

specify which color buffers are to be drawn into

Source

pub fn create_framebuffer(&self) -> WebGLFrameBuffer

create a new framebuffer

Source

pub fn delete_framebuffer(&self, fb: &WebGLFrameBuffer)

destroy a framebuffer

Source

pub fn bind_framebuffer(&self, buffer: Buffers, fb: &WebGLFrameBuffer)

bind a framebuffer to the current state

Source

pub fn framebuffer_texture2d( &self, target: Buffers, attachment: Buffers, textarget: TextureBindPoint, texture: &WebGLTexture, level: i32, )

attach a texture to a framebuffer

Source

pub fn unbind_framebuffer(&self, buffer: Buffers)

unbind a framebuffer

Trait Implementations§

Source§

impl Clone for GLContext

Source§

fn clone(&self) -> GLContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GLContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for GLContext

Source§

fn eq(&self, other: &GLContext) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for GLContext

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.