pub trait GraphicsServer: GraphicsServerAsAny {
Show 27 methods
// Required methods
fn create_buffer(
&self,
desc: GpuBufferDescriptor<'_>,
) -> Result<GpuBuffer, FrameworkError>;
fn create_texture(
&self,
desc: GpuTextureDescriptor<'_>,
) -> Result<GpuTexture, FrameworkError>;
fn create_sampler(
&self,
desc: GpuSamplerDescriptor,
) -> Result<GpuSampler, FrameworkError>;
fn create_frame_buffer(
&self,
depth_attachment: Option<Attachment>,
color_attachments: Vec<Attachment>,
) -> Result<GpuFrameBuffer, FrameworkError>;
fn back_buffer(&self) -> GpuFrameBuffer;
fn create_query(&self) -> Result<GpuQuery, FrameworkError>;
fn create_shader(
&self,
name: String,
kind: ShaderKind,
source: String,
resources: &[ShaderResourceDefinition],
line_offset: isize,
) -> Result<GpuShader, FrameworkError>;
fn create_program(
&self,
name: &str,
vertex_source: String,
vertex_source_line_offset: isize,
fragment_source: String,
fragment_source_line_offset: isize,
resources: &[ShaderResourceDefinition],
) -> Result<GpuProgram, FrameworkError>;
fn create_program_from_shaders(
&self,
name: &str,
vertex_shader: &GpuShader,
fragment_shader: &GpuShader,
resources: &[ShaderResourceDefinition],
) -> Result<GpuProgram, FrameworkError>;
fn create_async_read_buffer(
&self,
name: &str,
pixel_size: usize,
pixel_count: usize,
) -> Result<GpuAsyncReadBuffer, FrameworkError>;
fn create_geometry_buffer(
&self,
desc: GpuGeometryBufferDescriptor<'_>,
) -> Result<GpuGeometryBuffer, FrameworkError>;
fn weak(&self) -> Weak<dyn GraphicsServer>;
fn flush(&self);
fn finish(&self);
fn invalidate_resource_bindings_cache(&self);
fn pipeline_statistics(&self) -> PipelineStatistics;
fn swap_buffers(&self) -> Result<(), FrameworkError>;
fn set_frame_size(&self, new_size: (u32, u32));
fn capabilities(&self) -> ServerCapabilities;
fn set_polygon_fill_mode(
&self,
polygon_face: PolygonFace,
polygon_fill_mode: PolygonFillMode,
);
fn generate_mipmap(&self, texture: &GpuTexture);
fn memory_usage(&self) -> ServerMemoryUsage;
fn push_debug_group(&self, name: &str);
fn pop_debug_group(&self);
// Provided methods
fn begin_scope(&self, name: &str) -> RenderingScope { ... }
fn create_2d_render_target(
&self,
name: &str,
pixel_kind: PixelKind,
width: usize,
height: usize,
) -> Result<GpuTexture, FrameworkError> { ... }
fn create_cube_render_target(
&self,
name: &str,
pixel_kind: PixelKind,
size: usize,
) -> Result<GpuTexture, FrameworkError> { ... }
}Expand description
Graphics server is an abstraction layer over various graphics APIs used on different platforms supported by the engine. Such abstraction layer tries to provide more or less high-level and unified interface, that can be used to build graphics pipelines quickly and more or less efficiently.
Low-level GAPI-specific optimizations could be performed using direct access to the underlying API, by downcasting to a specific type.
Required Methods§
Sourcefn create_buffer(
&self,
desc: GpuBufferDescriptor<'_>,
) -> Result<GpuBuffer, FrameworkError>
fn create_buffer( &self, desc: GpuBufferDescriptor<'_>, ) -> Result<GpuBuffer, FrameworkError>
Creates a GPU buffer with the given size and kind. Usage is a hint to the video driver that allows to perform some potential performance optimizations.
Sourcefn create_texture(
&self,
desc: GpuTextureDescriptor<'_>,
) -> Result<GpuTexture, FrameworkError>
fn create_texture( &self, desc: GpuTextureDescriptor<'_>, ) -> Result<GpuTexture, FrameworkError>
Creates a new GPU texture using the given descriptor.
Sourcefn create_sampler(
&self,
desc: GpuSamplerDescriptor,
) -> Result<GpuSampler, FrameworkError>
fn create_sampler( &self, desc: GpuSamplerDescriptor, ) -> Result<GpuSampler, FrameworkError>
Creates a new GPU sampler that can be used to sample texels from a texture.
Sourcefn create_frame_buffer(
&self,
depth_attachment: Option<Attachment>,
color_attachments: Vec<Attachment>,
) -> Result<GpuFrameBuffer, FrameworkError>
fn create_frame_buffer( &self, depth_attachment: Option<Attachment>, color_attachments: Vec<Attachment>, ) -> Result<GpuFrameBuffer, FrameworkError>
Creates a new frame buffer using the given depth and color attachments. Depth attachment not exist, but there must be at least one color attachment of a format that supports rendering.
Sourcefn back_buffer(&self) -> GpuFrameBuffer
fn back_buffer(&self) -> GpuFrameBuffer
Creates a frame buffer that “connected” to the final image that will be displayed to the screen.
Sourcefn create_query(&self) -> Result<GpuQuery, FrameworkError>
fn create_query(&self) -> Result<GpuQuery, FrameworkError>
Creates a new GPU query, that can perform asynchronous data fetching from GPU. Usually it is used to create occlusion queries.
Sourcefn create_shader(
&self,
name: String,
kind: ShaderKind,
source: String,
resources: &[ShaderResourceDefinition],
line_offset: isize,
) -> Result<GpuShader, FrameworkError>
fn create_shader( &self, name: String, kind: ShaderKind, source: String, resources: &[ShaderResourceDefinition], line_offset: isize, ) -> Result<GpuShader, FrameworkError>
Creates a new named GPU shader. The name could be used for debugging purposes. The implementation of graphics server will generate proper resource bindings in the shader code for you.
Sourcefn create_program(
&self,
name: &str,
vertex_source: String,
vertex_source_line_offset: isize,
fragment_source: String,
fragment_source_line_offset: isize,
resources: &[ShaderResourceDefinition],
) -> Result<GpuProgram, FrameworkError>
fn create_program( &self, name: &str, vertex_source: String, vertex_source_line_offset: isize, fragment_source: String, fragment_source_line_offset: isize, resources: &[ShaderResourceDefinition], ) -> Result<GpuProgram, FrameworkError>
Creates a new named GPU program using source code of both vertex and fragment shaders. The name could be used for debugging purposes. The implementation of graphics server will generate proper resource bindings in the shader code for you.
Sourcefn create_program_from_shaders(
&self,
name: &str,
vertex_shader: &GpuShader,
fragment_shader: &GpuShader,
resources: &[ShaderResourceDefinition],
) -> Result<GpuProgram, FrameworkError>
fn create_program_from_shaders( &self, name: &str, vertex_shader: &GpuShader, fragment_shader: &GpuShader, resources: &[ShaderResourceDefinition], ) -> Result<GpuProgram, FrameworkError>
Creates a new named GPU program using a pair of vertex and fragment shaders. The name could be used for debugging purposes. The implementation of graphics server will generate proper resource bindings in the shader code for you.
Sourcefn create_async_read_buffer(
&self,
name: &str,
pixel_size: usize,
pixel_count: usize,
) -> Result<GpuAsyncReadBuffer, FrameworkError>
fn create_async_read_buffer( &self, name: &str, pixel_size: usize, pixel_count: usize, ) -> Result<GpuAsyncReadBuffer, FrameworkError>
Creates a new read-back buffer, that can be used to obtain texture data from GPU. It can be used to read rendering result from GPU to CPU memory and save the result to disk.
Sourcefn create_geometry_buffer(
&self,
desc: GpuGeometryBufferDescriptor<'_>,
) -> Result<GpuGeometryBuffer, FrameworkError>
fn create_geometry_buffer( &self, desc: GpuGeometryBufferDescriptor<'_>, ) -> Result<GpuGeometryBuffer, FrameworkError>
Creates a new geometry buffer, which consists of one or more vertex buffers and only one element buffer. Geometry buffer could be considered as a complex mesh storage allocated on GPU.
Sourcefn weak(&self) -> Weak<dyn GraphicsServer>
fn weak(&self) -> Weak<dyn GraphicsServer>
Creates a weak reference to the shared graphics server.
Sourcefn flush(&self)
fn flush(&self)
Sends all scheduled GPU command buffers for execution on GPU without waiting for a certain threshold.
Sourcefn finish(&self)
fn finish(&self)
Waits until all the scheduled GPU commands are fully executed. This is blocking operation, and it blocks the current thread until all the commands are fully executed.
Sourcefn invalidate_resource_bindings_cache(&self)
fn invalidate_resource_bindings_cache(&self)
Unbinds the all bound resources from the graphics pipeline.
Sourcefn pipeline_statistics(&self) -> PipelineStatistics
fn pipeline_statistics(&self) -> PipelineStatistics
Returns GPU pipeline statistics. See PipelineStatistics for more info.
Sourcefn swap_buffers(&self) -> Result<(), FrameworkError>
fn swap_buffers(&self) -> Result<(), FrameworkError>
Swaps the front and back buffers and thus presenting the final image on screen. There could be more than two buffers, and it is up to the graphics server implementation to choose the right amount, but it can’t be less than two.
Sourcefn set_frame_size(&self, new_size: (u32, u32))
fn set_frame_size(&self, new_size: (u32, u32))
Notifies the graphics server that the size of the back buffer has changed. It has very limited use and there are very few platforms (Linux with Wayland mostly) that needs this function to be called.
Sourcefn capabilities(&self) -> ServerCapabilities
fn capabilities(&self) -> ServerCapabilities
Returns current capabilities of the graphics server. See ServerCapabilities for more info.
Sourcefn set_polygon_fill_mode(
&self,
polygon_face: PolygonFace,
polygon_fill_mode: PolygonFillMode,
)
fn set_polygon_fill_mode( &self, polygon_face: PolygonFace, polygon_fill_mode: PolygonFillMode, )
Sets current polygon fill mode for front faces, back faces, or both.
The mode of front faces is controlled separately from the mode of back faces,
and polygon_face determines which mode is set by this method.
See PolygonFace and PolygonFillMode docs for more info.
Sourcefn generate_mipmap(&self, texture: &GpuTexture)
fn generate_mipmap(&self, texture: &GpuTexture)
Generates mipmaps for the given texture. Graphics server implementation can pick any desired way of mipmaps generation, depending on the underlying GAPI capabilities.
Sourcefn memory_usage(&self) -> ServerMemoryUsage
fn memory_usage(&self) -> ServerMemoryUsage
Fetches the total amount of memory used by the graphics server.
Sourcefn push_debug_group(&self, name: &str)
fn push_debug_group(&self, name: &str)
Begins a new named debug group. It is recommended to use Self::begin_scope instead,
so that the compiler will manage the scope lifetime for your correctly. Otherwise, a forgotten
call to Self::pop_debug_group may cause stack overflow or underflow errors.
Sourcefn pop_debug_group(&self)
fn pop_debug_group(&self)
Ends the current debug group.
Provided Methods§
Sourcefn begin_scope(&self, name: &str) -> RenderingScope
fn begin_scope(&self, name: &str) -> RenderingScope
Begins a new debug scope by creating a temporary object that automatically exits the
scope on drop. The scope could be created like so: let _debug_scope = server.begin_scope("ScopeName");
Note the let _debug_scope = ... part - it is important to keep the produced object alive
until the end of the current semantic scope. Do not call this method like so:
server.begin_scope("VisibilityTest"); because it will enter and leave the scope instantly.
Sourcefn create_2d_render_target(
&self,
name: &str,
pixel_kind: PixelKind,
width: usize,
height: usize,
) -> Result<GpuTexture, FrameworkError>
fn create_2d_render_target( &self, name: &str, pixel_kind: PixelKind, width: usize, height: usize, ) -> Result<GpuTexture, FrameworkError>
A shortcut for Self::create_texture, that creates a rectangular texture with the given
size and pixel kind.
Sourcefn create_cube_render_target(
&self,
name: &str,
pixel_kind: PixelKind,
size: usize,
) -> Result<GpuTexture, FrameworkError>
fn create_cube_render_target( &self, name: &str, pixel_kind: PixelKind, size: usize, ) -> Result<GpuTexture, FrameworkError>
A shortcut for Self::create_texture, that creates a cube texture with the given
size and pixel kind.