pub struct Device {Show 41 fields
gl: Rc<dyn Gl>,
base_gl: Option<Rc<dyn Gl>>,
bound_textures: [GLuint; 16],
bound_program: GLuint,
bound_program_name: Rc<CString>,
bound_vao: GLuint,
bound_read_fbo: (FBOId, DeviceIntPoint),
bound_draw_fbo: FBOId,
default_read_fbo: FBOId,
default_draw_fbo: FBOId,
depth_available: bool,
upload_method: UploadMethod,
use_batched_texture_uploads: bool,
use_draw_calls_for_texture_copy: bool,
batched_upload_threshold: i32,
capabilities: Capabilities,
color_formats: TextureFormatPair<ImageFormat>,
bgra_formats: TextureFormatPair<GLuint>,
bgra_pixel_type: GLuint,
swizzle_settings: SwizzleSettings,
depth_format: GLuint,
depth_targets: FastHashMap<DeviceIntSize, SharedDepthTarget>,
inside_frame: bool,
crash_annotator: Option<Box<dyn CrashAnnotator>>,
annotate_draw_call_crashes: bool,
resource_override_path: Option<PathBuf>,
use_optimized_shaders: bool,
max_texture_size: i32,
cached_programs: Option<Rc<ProgramCache>>,
frame_id: GpuFrameId,
texture_storage_usage: TexStorageUsage,
required_pbo_stride: StrideAlignment,
requires_null_terminated_shader_source: bool,
requires_texture_external_unbind: bool,
is_software_webrender: bool,
extensions: Vec<String>,
dump_shader_source: Option<String>,
surface_origin_is_top_left: bool,
shader_is_ready: bool,
pub textures_created: u32,
pub textures_deleted: u32,
}
Fields§
§gl: Rc<dyn Gl>
§base_gl: Option<Rc<dyn Gl>>
If non-None, |gl| points to a profiling wrapper, and this points to the underling Gl instance.
bound_textures: [GLuint; 16]
§bound_program: GLuint
§bound_program_name: Rc<CString>
§bound_vao: GLuint
§bound_read_fbo: (FBOId, DeviceIntPoint)
§bound_draw_fbo: FBOId
§default_read_fbo: FBOId
§default_draw_fbo: FBOId
§depth_available: bool
Track depth state for assertions. Note that the default FBO has depth, so this defaults to true.
upload_method: UploadMethod
§use_batched_texture_uploads: bool
§use_draw_calls_for_texture_copy: bool
Whether to use draw calls instead of regular blitting commands.
Note: this currently only applies to the batched texture uploads path.
batched_upload_threshold: i32
Number of pixels below which we prefer batched uploads.
capabilities: Capabilities
§color_formats: TextureFormatPair<ImageFormat>
§bgra_formats: TextureFormatPair<GLuint>
§bgra_pixel_type: GLuint
§swizzle_settings: SwizzleSettings
§depth_format: GLuint
§depth_targets: FastHashMap<DeviceIntSize, SharedDepthTarget>
Map from texture dimensions to shared depth buffers for render targets.
Render targets often have the same width/height, so we can save memory by sharing these across targets.
inside_frame: bool
§crash_annotator: Option<Box<dyn CrashAnnotator>>
§annotate_draw_call_crashes: bool
§resource_override_path: Option<PathBuf>
§use_optimized_shaders: bool
Whether to use shaders that have been optimized at build time.
max_texture_size: i32
§cached_programs: Option<Rc<ProgramCache>>
§frame_id: GpuFrameId
§texture_storage_usage: TexStorageUsage
When to use glTexStorage*. We prefer this over glTexImage* because it guarantees that mipmaps won’t be generated (which they otherwise are on some drivers, particularly ANGLE). However, it is not always supported at all, or for BGRA8 format. If it’s not supported for the required format, we fall back to glTexImage*.
required_pbo_stride: StrideAlignment
Required stride alignment for pixel transfers. This may be required for correctness reasons due to driver bugs, or for performance reasons to ensure we remain on the fast-path for transfers.
requires_null_terminated_shader_source: bool
Whether we must ensure the source strings passed to glShaderSource() are null-terminated, to work around driver bugs.
requires_texture_external_unbind: bool
Whether we must unbind any texture from GL_TEXTURE_EXTERNAL_OES before binding to GL_TEXTURE_2D, to work around an android emulator bug.
is_software_webrender: bool
§extensions: Vec<String>
§dump_shader_source: Option<String>
Dumps the source of the shader with the given name
surface_origin_is_top_left: bool
§shader_is_ready: bool
A debug boolean for tracking if the shader program has been set after a blend mode change.
This is needed for compatibility with next-gen GPU APIs that switch states using “pipeline object” that bundles together the blending state with the shader.
Having the constraint of always binding the shader last would allow us to have the “pipeline object” bound at that time. Without this constraint, we’d either have to eagerly bind the “pipeline object” on changing either the shader or the blend more, or lazily bind it at draw call time, neither of which is desirable.
textures_created: u32
§textures_deleted: u32
Implementations§
source§impl Device
impl Device
pub fn new( gl: Rc<dyn Gl>, crash_annotator: Option<Box<dyn CrashAnnotator>>, resource_override_path: Option<PathBuf>, use_optimized_shaders: bool, upload_method: UploadMethod, batched_upload_threshold: i32, 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) -> &dyn Gl
pub fn rc_gl(&self) -> &Rc<dyn Gl>
pub fn set_parameter(&mut self, param: &Parameter)
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 batched_upload_threshold(&self) -> i32
pub fn reset_state(&mut self)
fn print_shader_errors(source: &str, log: &str)
pub fn compile_shader( &self, name: &str, shader_type: GLenum, source: &String, ) -> Result<GLuint, ShaderError>
pub fn begin_frame(&mut self) -> GpuFrameId
fn bind_texture_impl( &mut self, slot: TextureSlot, id: GLuint, target: GLenum, set_swizzle: Option<Swizzle>, image_rendering: Option<ImageRendering>, )
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)
fn bind_draw_target_impl(&mut self, fbo_id: FBOId)
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
fn set_texture_parameters(&mut self, target: GLuint, filter: TextureFilter)
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.
fn init_fbos(&mut self, texture: &mut Texture, with_depth: bool)
fn acquire_depth_target(&mut self, dimensions: DeviceIntSize) -> RBOId
fn release_depth_target(&mut self, dimensions: DeviceIntSize)
sourcefn blit_render_target_impl(
&mut self,
src_rect: FramebufferIntRect,
dest_rect: FramebufferIntRect,
filter: TextureFilter,
)
fn blit_render_target_impl( &mut self, src_rect: FramebufferIntRect, dest_rect: FramebufferIntRect, filter: TextureFilter, )
Perform a blit between self.bound_read_fbo and self.bound_draw_fbo.
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()
.
fn build_shader_string<F: FnMut(&str)>( &self, features: &[&'static str], kind: ShaderKind, base_filename: &str, output: F, )
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>)
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.
sourcefn attach_read_texture_raw(&mut self, texture_id: GLuint, target: GLuint)
fn attach_read_texture_raw(&mut self, texture_id: GLuint, target: GLuint)
Attaches the provided texture to the current Read FBO binding.
pub fn attach_read_texture_external( &mut self, texture_id: GLuint, target: ImageBufferKind, )
pub fn attach_read_texture(&mut self, texture: &Texture)
fn bind_vao_impl(&mut self, id: GLuint)
pub fn bind_vao(&mut self, vao: &VAO)
pub fn bind_custom_vao(&mut self, vao: &CustomVAO)
fn create_vao_with_vbos( &mut self, descriptor: &VertexDescriptor, main_vbo_id: VBOId, instance_vbo_id: VBOId, instance_divisor: u32, ibo_id: IBOId, owns_vertices_and_indices: bool, ) -> VAO
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)
fn update_vbo_data<V>( &mut self, vbo: VBOId, vertices: &[V], usage_hint: VertexUsageHint, )
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)
fn set_blend_factors( &mut self, color: (GLenum, GLenum), alpha: (GLenum, GLenum), )
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_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_plus_lighter(&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)
fn log_driver_messages(gl: &dyn Gl)
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