Skip to main content

GpuQueryTrait

Trait GpuQueryTrait 

Source
pub trait GpuQueryTrait: GpuQueryAsAny + Debug {
    // Required methods
    fn begin(&self, kind: QueryKind);
    fn end(&self);
    fn is_started(&self) -> bool;
    fn try_get_result(&self) -> Option<QueryResult>;
}
Expand description

A query object is used to fetch some data from rendering operations asynchronously. Usually it is used to perform occlusion queries.

§Examples

The following examples shows how to create a new GPU query, run it and fetch the result.

use fyrox_graphics::{
    error::FrameworkError,
    query::{QueryKind, QueryResult},
    server::GraphicsServer,
};

fn query(server: &dyn GraphicsServer) -> Result<(), FrameworkError> {
    // Initialization.
    let query = server.create_query()?;

    // Somewhere in the rendering loop.
    if !query.is_started() {
        query.begin(QueryKind::AnySamplesPassed);

        // Draw something.

        query.end();
    } else if let Some(QueryResult::AnySamplesPassed(any_samples_passed)) =
        query.try_get_result()
    {
        println!("{any_samples_passed}");
    }

    Ok(())
}

Keep in mind that you should always re-use the queries instead of creating them on the fly! This is much more efficient, because it removes all redundant memory allocations and calls to the GPU driver.

Required Methods§

Source

fn begin(&self, kind: QueryKind)

Begins a query of the given kind. All drawing commands must be enclosed withing a pair of this method and Self::end calls. See QueryKind for more info.

Source

fn end(&self)

Ends the query. Must be called after and in pair with Self::begin.

Source

fn is_started(&self) -> bool

Returns true if the query is started (Self::begin was called).

Source

fn try_get_result(&self) -> Option<QueryResult>

Tries to fetch the query result without blocking. The query object guarantees that the result will be stored until the next call of Self::begin, so consecutive calls of this method are allowed.

Implementors§