pub struct Device(_);
Expand description
Logical device, representation one or multiple physical devices (hardware or software).
This wraps an existing GL context and acts as the main API interface. It’s the responsibility of the user to keep the context alive.
Implementations
sourceimpl Device
impl Device
sourcepub fn create_buffer(&self, size: u64, memory: MemoryFlags) -> Buffer
pub fn create_buffer(&self, size: u64, memory: MemoryFlags) -> Buffer
Create a new empty buffer.
Parameters
size
: Length in bytes of the associated storage memory.memory
: Properties of the internal memory slice. Indicating the usage and locality of the allocation.
sourcepub fn map_buffer<T>(
&self,
buffer: &Buffer,
range: Range<u64>,
mapping: MappingFlags
) -> &mut [T] ⓘ
pub fn map_buffer<T>(
&self,
buffer: &Buffer,
range: Range<u64>,
mapping: MappingFlags
) -> &mut [T] ⓘ
Persistently map memory to host accessible virtual memory.
Valid usage
range.end
may not be larger than the size of the buffer.range.start
must be smaller thanrange.end
buffer
must be created withCPU_MAP_READ
orCPU_MAP_WRITE
flags.range.end - range.start
must be a multiple of the size ofT
- If the buffer has not been created with
CPU_MAP_READ
the host should not read from the returned slice. - If the buffer has not been created with
CPU_MAP_WRITE
the host should not write to the returned slice. - A buffer can not be mapped multiple times.
Return
Returns a typed slice of the mapped memory range.
sourcepub fn unmap_buffer(&self, buffer: &Buffer) -> bool
pub fn unmap_buffer(&self, buffer: &Buffer) -> bool
sourcepub fn delete_buffer(&self, buffer: Buffer)
pub fn delete_buffer(&self, buffer: Buffer)
Delete a buffer.
sourceimpl Device
impl Device
sourcepub fn bind_vertex_buffers(
&self,
vao: &VertexArray,
first: u32,
views: &[VertexBufferView<'_>]
)
pub fn bind_vertex_buffers(
&self,
vao: &VertexArray,
first: u32,
views: &[VertexBufferView<'_>]
)
Bind vertex buffers to a vertex array.
sourcepub fn bind_index_buffer(&self, vao: &VertexArray, buffer: &Buffer)
pub fn bind_index_buffer(&self, vao: &VertexArray, buffer: &Buffer)
Bind a index buffer to a vertex array.
sourcepub fn bind_pipeline(&self, pipeline: &Pipeline)
pub fn bind_pipeline(&self, pipeline: &Pipeline)
Bind a pipeline for usage.
sourcepub fn set_viewport(&self, first: u32, viewports: &[Viewport])
pub fn set_viewport(&self, first: u32, viewports: &[Viewport])
Set viewport transformation parameters.
The viewport determines the mapping from NDC (normalized device coordinates) into window coordinates.
sourcepub fn set_scissor(&self, first: u32, scissors: &[Region])
pub fn set_scissor(&self, first: u32, scissors: &[Region])
Set scissor rectangles for viewports.
Valid usage
- Every active viewport needs an associated scissor.
sourcepub fn draw(
&self,
primitive: Primitive,
vertices: Range<u32>,
instance: Range<u32>
)
pub fn draw(
&self,
primitive: Primitive,
vertices: Range<u32>,
instance: Range<u32>
)
Submit a (non-indexed) draw call.
Valid usage
- There must be a valid graphics pipeline currently bound.
- There must be a calid vertex array currently bound.
- For each attribute in the bound vertex array there must be a vertex buffer bound at the specified binding slot.
- For each attribute in the bound vertex array there must be a vertex attribute specified in the shader with matching format and location.
- The access vertices must be in bound of the vertex buffers bound.
vertices.end
must be larger thanvertices.start
.vertices.end - vertices.start
must be allow assembling complete primitives.instances.end
must be larger thaninstances.start
.
sourcepub fn draw_indexed(
&self,
primitive: Primitive,
index_ty: IndexTy,
indices: Range<u32>,
instance: Range<u32>,
base_vertex: i32
)
pub fn draw_indexed(
&self,
primitive: Primitive,
index_ty: IndexTy,
indices: Range<u32>,
instance: Range<u32>,
base_vertex: i32
)
Submit an indexed draw call.
Valid usage
- There must be a valid graphics pipeline currently bound.
- There must be a calid vertex array currently bound.
- For each attribute in the bound vertex array there must be a vertex buffer bound at the specified binding slot.
- For each attribute in the bound vertex array there must be a vertex attribute specified in the shader with matching format and location.
- The access vertices must be in bound of the vertex buffers bound.
indices.end
must be larger thanindices.start
.indices.end - indices.start
must be allow assembling complete primitives.instances.end
must be larger thaninstances.start
.
sourceimpl Device
impl Device
sourcepub fn create_framebuffer(&self) -> Framebuffer
pub fn create_framebuffer(&self) -> Framebuffer
sourcepub fn delete_framebuffer(&self, framebuffer: Framebuffer)
pub fn delete_framebuffer(&self, framebuffer: Framebuffer)
sourcepub fn create_renderbuffer(&self) -> Renderbuffer
pub fn create_renderbuffer(&self) -> Renderbuffer
sourcepub fn delete_renderbuffer(&self, renderbuffer: Renderbuffer)
pub fn delete_renderbuffer(&self, renderbuffer: Renderbuffer)
sourcepub fn clear_attachment(&self, fb: &Framebuffer, cv: ClearAttachment)
pub fn clear_attachment(&self, fb: &Framebuffer, cv: ClearAttachment)
Clear framebuffer attachment.
sourcepub fn invalidate_framebuffer(
&self,
_framebuffer: &Framebuffer,
_attachments: &[Attachment],
_region: Region
)
pub fn invalidate_framebuffer(
&self,
_framebuffer: &Framebuffer,
_attachments: &[Attachment],
_region: Region
)
sourceimpl Device
impl Device
pub fn create_image(&self, ty: ImageType, format: Format, levels: u32) -> Image
pub fn copy_host_to_image(
&self,
image: &Image,
level: u32,
layers: Range<u32>,
offset: Offset,
extent: Extent,
data: &[u8],
base_format: BaseFormat,
format_layout: FormatLayout
)
pub fn create_image_view(
&self,
image: &Image,
ty: ImageViewType,
format: Format,
range: SubresourceRange
) -> ImageView
pub fn bind_image_views(&self, first: u32, views: &[&ImageView])
sourceimpl Device
impl Device
sourcepub fn create_sampler(&self, desc: SamplerDesc) -> Sampler
pub fn create_sampler(&self, desc: SamplerDesc) -> Sampler
Create a sampler object.
sourcepub fn bind_samplers(&self, first: u32, samplers: &[&Sampler])
pub fn bind_samplers(&self, first: u32, samplers: &[&Sampler])
Bind samplers to specific texture units.
sourcepub fn delete_sampler(&self, sampler: Sampler)
pub fn delete_sampler(&self, sampler: Sampler)
Delete a sampler.
sourceimpl Device
impl Device
sourcepub fn create_shader(&self, stage: ShaderStage, source: &[u8]) -> Shader
pub fn create_shader(&self, stage: ShaderStage, source: &[u8]) -> Shader
Create a new shader from GLSL.
Valid usage
source
must be a NULL-terminated C-String.- The GLSL shader version must be
450 core
or higher. - The
stage
parameter must be a valid stage of the passed shader source.
sourcepub fn delete_shader(&self, shader: Shader)
pub fn delete_shader(&self, shader: Shader)
Delete a shader.
sourcepub fn create_graphics_pipeline(
&self,
desc: GraphicsPipelineDesc<'_>
) -> Pipeline
pub fn create_graphics_pipeline(
&self,
desc: GraphicsPipelineDesc<'_>
) -> Pipeline
Create a graphics pipeline.
This equals a Program
in GL terminology.
Valid usage
- The vertex shader in
desc
must be valid and created withShaderStage::Vertex
. - The tessellation control shader in
desc
must be valid and created withShaderStage::TessellationControl
if specified. - The tessellation evaluation shader in
desc
must be valid and created withShaderStage::TessellationEvalution
if specified. - The geometry shader in
desc
must be valid and created withShaderStage::Geometry
if specified. - The fragment shader in
desc
must be valid and created withShaderStage::Fragment
if specified.
sourcepub fn create_compute_pipeline(&self, compute_shader: &Shader) -> Pipeline
pub fn create_compute_pipeline(&self, compute_shader: &Shader) -> Pipeline
Create a compute pipeline.
This equals a Program
in GL terminology.
Valid usage
- The compute shader in must be valid and created with
ShaderStage::Compute
.
sourcepub fn create_vertex_array(
&self,
attributes: &[VertexAttributeDesc]
) -> VertexArray
pub fn create_vertex_array(
&self,
attributes: &[VertexAttributeDesc]
) -> VertexArray
Create a new vertex array, storing information for the input assembler.
The vertex array specified the vertex attributes and their binding to vertex buffer objects.
sourcepub fn delete_vertex_array(&self, vao: VertexArray)
pub fn delete_vertex_array(&self, vao: VertexArray)
Delete a vertex array.
sourcepub fn bind_vertex_array(&self, vao: &VertexArray)
pub fn bind_vertex_array(&self, vao: &VertexArray)
Bind a vertex array for usage.