pub struct Device { /* private fields */ }
Implementations§
Source§impl Device
impl Device
pub fn new( gl: Rc<GenericGlContext>, crash_annotator: Option<Box<dyn CrashAnnotator>>, resource_override_path: Option<PathBuf>, use_optimized_shaders: bool, upload_method: UploadMethod, cached_programs: Option<Rc<ProgramCache>>, allow_texture_storage_support: bool, allow_texture_swizzling: bool, dump_shader_source: Option<String>, surface_origin_is_top_left: bool, _panic_on_gl_error: bool, ) -> Device
pub fn gl(&self) -> &GenericGlContext
pub fn rc_gl(&self) -> &Rc<GenericGlContext>
Sourcepub fn clamp_max_texture_size(&mut self, size: i32)
pub fn clamp_max_texture_size(&mut self, size: i32)
Ensures that the maximum texture size is less than or equal to the provided value. If the provided value is less than the value supported by the driver, the latter is used.
Sourcepub fn max_texture_size(&self) -> i32
pub fn max_texture_size(&self) -> i32
Returns the limit on texture dimensions (width or height).
pub fn surface_origin_is_top_left(&self) -> bool
pub fn get_capabilities(&self) -> &Capabilities
pub fn preferred_color_formats(&self) -> TextureFormatPair<ImageFormat>
pub fn swizzle_settings(&self) -> Option<SwizzleSettings>
pub fn depth_bits(&self) -> i32
pub fn max_depth_ids(&self) -> i32
pub fn ortho_near_plane(&self) -> f32
pub fn ortho_far_plane(&self) -> f32
pub fn required_pbo_stride(&self) -> StrideAlignment
pub fn upload_method(&self) -> &UploadMethod
pub fn use_batched_texture_uploads(&self) -> bool
pub fn use_draw_calls_for_texture_copy(&self) -> bool
pub fn set_use_batched_texture_uploads(&mut self, enabled: bool)
pub fn set_use_draw_calls_for_texture_copy(&mut self, enabled: bool)
pub fn reset_state(&mut self)
pub fn compile_shader( &self, name: &str, shader_type: GLenum, source: &String, ) -> Result<GLuint, ShaderError>
pub fn begin_frame(&mut self) -> GpuFrameId
pub fn bind_texture<S>(&mut self, slot: S, texture: &Texture, swizzle: Swizzle)where
S: Into<TextureSlot>,
pub fn bind_external_texture<S>(
&mut self,
slot: S,
external_texture: &ExternalTexture,
)where
S: Into<TextureSlot>,
pub fn bind_read_target_impl(&mut self, fbo_id: FBOId, offset: DeviceIntPoint)
pub fn bind_read_target(&mut self, target: ReadTarget)
pub fn reset_read_target(&mut self)
pub fn reset_draw_target(&mut self)
pub fn bind_draw_target(&mut self, target: DrawTarget)
Sourcepub fn create_fbo(&mut self) -> FBOId
pub fn create_fbo(&mut self) -> FBOId
Creates an unbound FBO object. Additional attachment API calls are required to make it complete.
Sourcepub fn create_fbo_for_external_texture(&mut self, texture_id: u32) -> FBOId
pub fn create_fbo_for_external_texture(&mut self, texture_id: u32) -> FBOId
Creates an FBO with the given texture bound as the color attachment.
pub fn delete_fbo(&mut self, fbo: FBOId)
pub fn bind_external_draw_target(&mut self, fbo_id: FBOId)
Sourcepub fn link_program(
&mut self,
program: &mut Program,
descriptor: &VertexDescriptor,
) -> Result<(), ShaderError>
pub fn link_program( &mut self, program: &mut Program, descriptor: &VertexDescriptor, ) -> Result<(), ShaderError>
Link a program, attaching the supplied vertex format.
If create_program()
finds a binary shader on disk, it will kick
off linking immediately, which some drivers (notably ANGLE) run
in parallel on background threads. As such, this function should
ideally be run sometime later, to give the driver time to do that
before blocking due to an API call accessing the shader.
This generally means that the first run of the application will have to do a bunch of blocking work to compile the shader from source, but subsequent runs should load quickly.
pub fn bind_program(&mut self, program: &Program) -> bool
pub fn create_texture( &mut self, target: ImageBufferKind, format: ImageFormat, width: i32, height: i32, filter: TextureFilter, render_target: Option<RenderTargetInfo>, ) -> Texture
Sourcepub fn copy_entire_texture(&mut self, dst: &mut Texture, src: &Texture)
pub fn copy_entire_texture(&mut self, dst: &mut Texture, src: &Texture)
Copies the entire contents of one texture to another. The dest texture must be at least as large as the source texture in each dimension. No scaling is performed, so if the dest texture is larger than the source texture then some of its pixels will not be written to.
Sourcepub fn copy_texture_sub_region(
&mut self,
src_texture: &Texture,
src_x: usize,
src_y: usize,
dest_texture: &Texture,
dest_x: usize,
dest_y: usize,
width: usize,
height: usize,
)
pub fn copy_texture_sub_region( &mut self, src_texture: &Texture, src_x: usize, src_y: usize, dest_texture: &Texture, dest_x: usize, dest_y: usize, width: usize, height: usize, )
Copies the specified subregion from src_texture to dest_texture.
Sourcepub fn invalidate_render_target(&mut self, texture: &Texture)
pub fn invalidate_render_target(&mut self, texture: &Texture)
Notifies the device that the contents of a render target are no longer needed.
Sourcepub fn invalidate_depth_target(&mut self)
pub fn invalidate_depth_target(&mut self)
Notifies the device that the contents of the current framebuffer’s depth attachment is no longer needed. Unlike invalidate_render_target, this can be called even when the contents of the colour attachment is still required. This should be called before unbinding the framebuffer at the end of a pass, to allow tiled GPUs to avoid writing the contents back to memory.
Sourcepub fn reuse_render_target<T: Texel>(
&mut self,
texture: &mut Texture,
rt_info: RenderTargetInfo,
)
pub fn reuse_render_target<T: Texel>( &mut self, texture: &mut Texture, rt_info: RenderTargetInfo, )
Notifies the device that a render target is about to be reused.
This method adds or removes a depth target as necessary.
Sourcepub fn blit_render_target(
&mut self,
src_target: ReadTarget,
src_rect: FramebufferIntRect,
dest_target: DrawTarget,
dest_rect: FramebufferIntRect,
filter: TextureFilter,
)
pub fn blit_render_target( &mut self, src_target: ReadTarget, src_rect: FramebufferIntRect, dest_target: DrawTarget, dest_rect: FramebufferIntRect, filter: TextureFilter, )
Perform a blit between src_target and dest_target. This will overwrite self.bound_read_fbo and self.bound_draw_fbo.
Sourcepub fn blit_render_target_invert_y(
&mut self,
src_target: ReadTarget,
src_rect: FramebufferIntRect,
dest_target: DrawTarget,
dest_rect: FramebufferIntRect,
)
pub fn blit_render_target_invert_y( &mut self, src_target: ReadTarget, src_rect: FramebufferIntRect, dest_target: DrawTarget, dest_rect: FramebufferIntRect, )
Performs a blit while flipping vertically. Useful for blitting textures (which use origin-bottom-left) to the main framebuffer (which uses origin-top-left).
pub fn delete_texture(&mut self, texture: Texture)
pub fn delete_program(&mut self, program: Program)
Sourcepub fn create_program_linked(
&mut self,
base_filename: &'static str,
features: &[&'static str],
descriptor: &VertexDescriptor,
) -> Result<Program, ShaderError>
pub fn create_program_linked( &mut self, base_filename: &'static str, features: &[&'static str], descriptor: &VertexDescriptor, ) -> Result<Program, ShaderError>
Create a shader program and link it immediately.
Sourcepub fn create_program(
&mut self,
base_filename: &'static str,
features: &[&'static str],
) -> Result<Program, ShaderError>
pub fn create_program( &mut self, base_filename: &'static str, features: &[&'static str], ) -> Result<Program, ShaderError>
Create a shader program. This does minimal amount of work to start
loading a binary shader. If a binary shader is found, we invoke
glProgramBinary, which, at least on ANGLE, will load and link the
binary on a background thread. This can speed things up later when
we invoke link_program()
.
pub fn bind_shader_samplers<S>( &mut self, program: &Program, bindings: &[(&'static str, S)], )
pub fn get_uniform_location( &self, program: &Program, name: &str, ) -> UniformLocation
pub fn set_uniforms(&self, program: &Program, transform: &Transform3D<f32>)
pub fn switch_mode(&self, mode: i32)
Sourcepub fn set_shader_texture_size(
&self,
program: &Program,
texture_size: DeviceSize,
)
pub fn set_shader_texture_size( &self, program: &Program, texture_size: DeviceSize, )
Sets the uTextureSize uniform. Most shaders do not require this to be called as they use the textureSize GLSL function instead.
pub fn create_pbo(&mut self) -> PBO
pub fn create_pbo_with_size(&mut self, size: usize) -> PBO
pub fn read_pixels_into_pbo( &mut self, read_target: ReadTarget, rect: DeviceIntRect, format: ImageFormat, pbo: &PBO, )
pub fn map_pbo_for_readback<'a>( &'a mut self, pbo: &'a PBO, ) -> Option<BoundPBO<'a>>
pub fn delete_pbo(&mut self, pbo: PBO)
Sourcepub fn required_upload_size_and_stride(
&self,
size: DeviceIntSize,
format: ImageFormat,
) -> (usize, usize)
pub fn required_upload_size_and_stride( &self, size: DeviceIntSize, format: ImageFormat, ) -> (usize, usize)
Returns the size and stride in bytes required to upload an area of pixels of the specified size, to a texture of the specified format.
Sourcepub fn upload_texture<'a>(
&mut self,
pbo_pool: &'a mut UploadPBOPool,
) -> TextureUploader<'a>
pub fn upload_texture<'a>( &mut self, pbo_pool: &'a mut UploadPBOPool, ) -> TextureUploader<'a>
Returns a TextureUploader
which can be used to upload texture data to texture
.
Once uploads have been performed the uploader must be flushed with TextureUploader::flush()
.
Sourcepub fn upload_texture_immediate<T: Texel>(
&mut self,
texture: &Texture,
pixels: &[T],
)
pub fn upload_texture_immediate<T: Texel>( &mut self, texture: &Texture, pixels: &[T], )
Performs an immediate (non-PBO) texture upload.
pub fn read_pixels(&mut self, img_desc: &ImageDescriptor) -> Vec<u8> ⓘ
Sourcepub fn read_pixels_into(
&mut self,
rect: FramebufferIntRect,
format: ImageFormat,
output: &mut [u8],
)
pub fn read_pixels_into( &mut self, rect: FramebufferIntRect, format: ImageFormat, output: &mut [u8], )
Read rectangle of pixels into the specified output slice.
Sourcepub fn get_tex_image_into(
&mut self,
texture: &Texture,
format: ImageFormat,
output: &mut [u8],
)
pub fn get_tex_image_into( &mut self, texture: &Texture, format: ImageFormat, output: &mut [u8], )
Get texels of a texture into the specified output slice.
pub fn attach_read_texture_external( &mut self, texture_id: GLuint, target: ImageBufferKind, )
pub fn attach_read_texture(&mut self, texture: &Texture)
pub fn bind_vao(&mut self, vao: &VAO)
pub fn bind_custom_vao(&mut self, vao: &CustomVAO)
pub fn create_custom_vao(&mut self, streams: &[Stream<'_>]) -> CustomVAO
pub fn delete_custom_vao(&mut self, vao: CustomVAO)
pub fn create_vbo<T>(&mut self) -> VBO<T>
pub fn delete_vbo<T>(&mut self, vbo: VBO<T>)
pub fn create_vao( &mut self, descriptor: &VertexDescriptor, instance_divisor: u32, ) -> VAO
pub fn delete_vao(&mut self, vao: VAO)
pub fn allocate_vbo<V>( &mut self, vbo: &mut VBO<V>, count: usize, usage_hint: VertexUsageHint, )
pub fn fill_vbo<V>(&mut self, vbo: &VBO<V>, data: &[V], offset: usize)
pub fn create_vao_with_new_instances( &mut self, descriptor: &VertexDescriptor, base_vao: &VAO, ) -> VAO
pub fn update_vao_main_vertices<V>( &mut self, vao: &VAO, vertices: &[V], usage_hint: VertexUsageHint, )
pub fn update_vao_instances<V: Clone>( &mut self, vao: &VAO, instances: &[V], usage_hint: VertexUsageHint, repeat: Option<NonZeroUsize>, )
pub fn update_vao_indices<I>( &mut self, vao: &VAO, indices: &[I], usage_hint: VertexUsageHint, )
pub fn draw_triangles_u16(&mut self, first_vertex: i32, index_count: i32)
pub fn draw_triangles_u32(&mut self, first_vertex: i32, index_count: i32)
pub fn draw_nonindexed_points(&mut self, first_vertex: i32, vertex_count: i32)
pub fn draw_nonindexed_lines(&mut self, first_vertex: i32, vertex_count: i32)
pub fn draw_indexed_triangles(&mut self, index_count: i32)
pub fn draw_indexed_triangles_instanced_u16( &mut self, index_count: i32, instance_count: i32, )
pub fn end_frame(&mut self)
pub fn clear_target( &self, color: Option<[f32; 4]>, depth: Option<f32>, rect: Option<FramebufferIntRect>, )
pub fn enable_depth(&self, depth_func: DepthFunction)
pub fn disable_depth(&self)
pub fn enable_depth_write(&self)
pub fn disable_depth_write(&self)
pub fn disable_stencil(&self)
pub fn set_scissor_rect(&self, rect: FramebufferIntRect)
pub fn enable_scissor(&self)
pub fn disable_scissor(&self)
pub fn enable_color_write(&self)
pub fn disable_color_write(&self)
pub fn set_blend(&mut self, enable: bool)
pub fn set_blend_mode_alpha(&mut self)
pub fn set_blend_mode_premultiplied_alpha(&mut self)
pub fn set_blend_mode_premultiplied_dest_out(&mut self)
pub fn set_blend_mode_multiply(&mut self)
pub fn set_blend_mode_subpixel_pass0(&mut self)
pub fn set_blend_mode_subpixel_pass1(&mut self)
pub fn set_blend_mode_subpixel_with_bg_color_pass0(&mut self)
pub fn set_blend_mode_subpixel_with_bg_color_pass1(&mut self)
pub fn set_blend_mode_subpixel_with_bg_color_pass2(&mut self)
pub fn set_blend_mode_subpixel_constant_text_color(&mut self, color: ColorF)
pub fn set_blend_mode_subpixel_dual_source(&mut self)
pub fn set_blend_mode_multiply_dual_source(&mut self)
pub fn set_blend_mode_screen(&mut self)
pub fn set_blend_mode_exclusion(&mut self)
pub fn set_blend_mode_show_overdraw(&mut self)
pub fn set_blend_mode_max(&mut self)
pub fn set_blend_mode_min(&mut self)
pub fn set_blend_mode_advanced(&mut self, mode: MixBlendMode)
pub fn supports_extension(&self, extension: &str) -> bool
pub fn echo_driver_messages(&self)
pub fn gl_describe_format(&self, format: ImageFormat) -> FormatDesc
Sourcepub fn report_memory(
&self,
size_op_funs: &MallocSizeOfOps,
swgl: *mut c_void,
) -> MemoryReport
pub fn report_memory( &self, size_op_funs: &MallocSizeOfOps, swgl: *mut c_void, ) -> MemoryReport
Generates a memory report for the resources managed by the device layer.
pub fn depth_targets_memory(&self) -> usize
Auto Trait Implementations§
impl Freeze for Device
impl !RefUnwindSafe for Device
impl !Send for Device
impl !Sync for Device
impl Unpin for Device
impl !UnwindSafe for Device
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more