Struct Factory

Source
pub struct Factory { /* private fields */ }
Expand description

GL resource factory.

Implementations§

Source§

impl Factory

Source

pub fn new(share: Rc<Share>) -> Factory

Create a new Factory.

Source

pub fn create_command_buffer(&mut self) -> CommandBuffer

Examples found in repository?
examples/window.rs (line 35)
25pub fn main() {
26    let sdl_context = sdl2::init().unwrap();
27    let video = sdl_context.video().unwrap();
28    // Request opengl core 3.2 for example:
29    video.gl_attr().set_context_profile(sdl2::video::GLProfile::Core);
30    video.gl_attr().set_context_version(3, 2);
31    let builder = video.window("SDL Window", 1024, 768);
32    let (window, _gl_context, mut device, mut factory, main_color, _main_depth) =
33        gfx_window_sdl::init::<Rgba8, DepthStencil>(&video, builder).unwrap();
34
35    let mut encoder: gfx::Encoder<_, _> = factory.create_command_buffer().into();
36
37    let mut events = sdl_context.event_pump().unwrap();
38
39    let mut running = true;
40    while running {
41        // handle events
42        for event in events.poll_iter() {
43            match event {
44                Event::Quit { .. } |
45                Event::KeyUp { keycode: Some(Keycode::Escape), .. } => {
46                    running = false;
47                }
48                _ => {}
49            }
50        }
51
52        // draw a frame
53        encoder.clear(&main_color, CLEAR_COLOR);
54        // <- draw actual stuff here
55        encoder.flush(&mut device);
56        window.gl_swap_window();
57        device.cleanup();
58    }
59}

Trait Implementations§

Source§

impl Clone for Factory

Source§

fn clone(&self) -> Factory

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Factory<Resources> for Factory

Source§

fn get_capabilities(&self) -> &Capabilities

Returns the capabilities of this Factory. This usually depends on the graphics API being used.
Source§

fn create_buffer_raw( &mut self, info: Info, ) -> Result<RawBuffer<Resources>, CreationError>

Source§

fn create_buffer_immutable_raw( &mut self, data: &[u8], stride: usize, role: Role, bind: Bind, ) -> Result<RawBuffer<Resources>, CreationError>

Source§

fn create_shader( &mut self, stage: Stage, code: &[u8], ) -> Result<Shader<Resources>, CreateShaderError>

Compiles a shader source into a Shader object that can be used to create a shader Program.
Source§

fn create_program( &mut self, shader_set: &ShaderSet<Resources>, ) -> Result<Program<Resources>, CreateProgramError>

Creates a new shader Program for the supplied ShaderSet.
Source§

fn create_pipeline_state_raw( &mut self, program: &Program<Resources>, desc: &Descriptor, ) -> Result<RawPipelineState<Resources>, CreationError>

Creates a new RawPipelineState. To create a safely typed PipelineState, see the FactoryExt trait and pso module, both in the gfx crate.
Source§

fn create_texture_raw( &mut self, desc: Info, hint: Option<ChannelType>, data_opt: Option<(&[&[u8]], Mipmap)>, ) -> Result<RawTexture<Resources>, CreationError>

Create a new empty raw texture with no data. The channel type parameter is a hint, required to assist backends that have no concept of typeless formats (OpenGL). The initial data, if given, has to be provided for all mip levels and slices: Slice0.Mip0, Slice0.Mip1, …, Slice1.Mip0, …
Source§

fn view_buffer_as_shader_resource_raw( &mut self, hbuf: &RawBuffer<Resources>, format: Format, ) -> Result<RawShaderResourceView<Resources>, ResourceViewError>

Source§

fn view_buffer_as_unordered_access_raw( &mut self, _hbuf: &RawBuffer<Resources>, ) -> Result<RawUnorderedAccessView<Resources>, ResourceViewError>

Source§

fn view_texture_as_shader_resource_raw( &mut self, htex: &RawTexture<Resources>, desc: ResourceDesc, ) -> Result<RawShaderResourceView<Resources>, ResourceViewError>

Source§

fn view_texture_as_unordered_access_raw( &mut self, _htex: &RawTexture<Resources>, ) -> Result<RawUnorderedAccessView<Resources>, ResourceViewError>

Source§

fn view_texture_as_render_target_raw( &mut self, htex: &RawTexture<Resources>, desc: RenderDesc, ) -> Result<RawRenderTargetView<Resources>, TargetViewError>

Source§

fn view_texture_as_depth_stencil_raw( &mut self, htex: &RawTexture<Resources>, desc: DepthStencilDesc, ) -> Result<RawDepthStencilView<Resources>, TargetViewError>

Source§

fn create_sampler(&mut self, info: SamplerInfo) -> Sampler<Resources>

Source§

fn read_mapping<'a, 'b, T>( &'a mut self, buf: &'b Buffer<Resources, T>, ) -> Result<Reader<'b, Resources, T>, Error>
where T: Copy,

Acquire a mapping Reader Read more
Source§

fn write_mapping<'a, 'b, T>( &'a mut self, buf: &'b Buffer<Resources, T>, ) -> Result<Writer<'b, Resources, T>, Error>
where T: Copy,

Acquire a mapping Writer Read more
Source§

fn create_buffer_immutable<T>( &mut self, data: &[T], role: Role, bind: Bind, ) -> Result<Buffer<R, T>, CreationError>
where T: Pod,

Source§

fn create_buffer<T>( &mut self, num: usize, role: Role, usage: Usage, bind: Bind, ) -> Result<Buffer<R, T>, CreationError>

Source§

fn create_shader_vertex( &mut self, code: &[u8], ) -> Result<VertexShader<R>, CreateShaderError>

Compiles a VertexShader from source.
Source§

fn create_shader_hull( &mut self, code: &[u8], ) -> Result<HullShader<R>, CreateShaderError>

Compiles a HullShader from source.
Source§

fn create_shader_domain( &mut self, code: &[u8], ) -> Result<DomainShader<R>, CreateShaderError>

Compiles a VertexShader from source.
Source§

fn create_shader_geometry( &mut self, code: &[u8], ) -> Result<GeometryShader<R>, CreateShaderError>

Compiles a GeometryShader from source.
Source§

fn create_shader_pixel( &mut self, code: &[u8], ) -> Result<PixelShader<R>, CreateShaderError>

Compiles a PixelShader from source. This is the same as what some APIs call a fragment shader.
Source§

fn create_texture<S>( &mut self, kind: Kind, levels: u8, bind: Bind, usage: Usage, channel_hint: Option<ChannelType>, ) -> Result<Texture<R, S>, CreationError>
where S: SurfaceTyped,

Source§

fn view_buffer_as_shader_resource<T>( &mut self, buf: &Buffer<R, T>, ) -> Result<ShaderResourceView<R, T>, ResourceViewError>
where T: Formatted,

Source§

fn view_buffer_as_unordered_access<T>( &mut self, buf: &Buffer<R, T>, ) -> Result<UnorderedAccessView<R, T>, ResourceViewError>

Source§

fn view_texture_as_shader_resource<T>( &mut self, tex: &Texture<R, <T as Formatted>::Surface>, levels: (u8, u8), swizzle: Swizzle, ) -> Result<ShaderResourceView<R, <T as Formatted>::View>, ResourceViewError>
where T: TextureFormat,

Source§

fn view_texture_as_unordered_access<T>( &mut self, tex: &Texture<R, <T as Formatted>::Surface>, ) -> Result<UnorderedAccessView<R, <T as Formatted>::View>, ResourceViewError>
where T: TextureFormat,

Source§

fn view_texture_as_render_target<T>( &mut self, tex: &Texture<R, <T as Formatted>::Surface>, level: u8, layer: Option<u16>, ) -> Result<RenderTargetView<R, T>, TargetViewError>
where T: RenderFormat,

Source§

fn view_texture_as_depth_stencil<T>( &mut self, tex: &Texture<R, <T as Formatted>::Surface>, level: u8, layer: Option<u16>, flags: DepthStencilFlags, ) -> Result<DepthStencilView<R, T>, TargetViewError>
where T: DepthFormat,

Source§

fn view_texture_as_depth_stencil_trivial<T>( &mut self, tex: &Texture<R, <T as Formatted>::Surface>, ) -> Result<DepthStencilView<R, T>, TargetViewError>
where T: DepthFormat,

Source§

fn create_texture_immutable_u8<T>( &mut self, kind: Kind, mipmap: Mipmap, data: &[&[u8]], ) -> Result<(Texture<R, <T as Formatted>::Surface>, ShaderResourceView<R, <T as Formatted>::View>), CombinedError>
where T: TextureFormat,

Source§

fn create_texture_immutable<T>( &mut self, kind: Kind, mipmap: Mipmap, data: &[&[<<T as Formatted>::Surface as SurfaceTyped>::DataType]], ) -> Result<(Texture<R, <T as Formatted>::Surface>, ShaderResourceView<R, <T as Formatted>::View>), CombinedError>
where T: TextureFormat,

Source§

fn create_render_target<T>( &mut self, width: u16, height: u16, ) -> Result<(Texture<R, <T as Formatted>::Surface>, ShaderResourceView<R, <T as Formatted>::View>, RenderTargetView<R, T>), CombinedError>

Source§

fn create_depth_stencil<T>( &mut self, width: u16, height: u16, ) -> Result<(Texture<R, <T as Formatted>::Surface>, ShaderResourceView<R, <T as Formatted>::View>, DepthStencilView<R, T>), CombinedError>

Source§

fn create_depth_stencil_view_only<T>( &mut self, width: u16, height: u16, ) -> Result<DepthStencilView<R, T>, CombinedError>

Auto Trait Implementations§

§

impl Freeze for Factory

§

impl !RefUnwindSafe for Factory

§

impl !Send for Factory

§

impl !Sync for Factory

§

impl Unpin for Factory

§

impl !UnwindSafe for Factory

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.