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§
Sourcefn end(&self)
fn end(&self)
Ends the query. Must be called after and in pair with Self::begin.
Sourcefn is_started(&self) -> bool
fn is_started(&self) -> bool
Returns true if the query is started (Self::begin was called).
Sourcefn try_get_result(&self) -> Option<QueryResult>
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.