Skip to content

Commit

Permalink
Merge pull request gfx-rs#29 from kvark/output
Browse files Browse the repository at this point in the history
Frame abstraction
  • Loading branch information
bvssvni committed Apr 11, 2015
2 parents 6a24eb0 + 61b2159 commit dd5a4ed
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
39 changes: 35 additions & 4 deletions src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ use std::rc::Rc;
use std::slice;

use {gl, tex};
use gfx;
use gfx::device as d;
use gfx::device::handle;
use gfx::device::handle::Producer;
use gfx::device::mapping::Builder;
use gfx::tex::Size;

use Buffer;
use Resources as R;
Expand All @@ -43,6 +45,27 @@ pub fn update_sub_buffer(gl: &gl::Gl, buffer: Buffer, address: *const u8,
}
}

/// A placeholder for a real `Output` implemented by your window.
pub struct Output {
width: Size,
height: Size,
handle: handle::FrameBuffer<R>,
}

impl gfx::Output<R> for Output {
fn get_handle(&self) -> Option<&handle::FrameBuffer<R>> {
Some(&self.handle)
}

fn get_size(&self) -> (Size, Size) {
(self.width, self.height)
}

fn get_mask(&self) -> gfx::Mask {
gfx::COLOR | gfx::DEPTH | gfx::STENCIL
}
}

/// GL resource factory.
pub struct Factory {
caps: d::Capabilities,
Expand Down Expand Up @@ -94,6 +117,18 @@ impl Factory {
);
}
}

pub fn get_main_frame_buffer(&self) -> handle::FrameBuffer<R> {
self.main_fbo.clone()
}

pub fn make_fake_output(&self, w: Size, h: Size) -> Output {
Output {
width: w,
height: h,
handle: self.main_fbo.clone(),
}
}
}


Expand Down Expand Up @@ -236,10 +271,6 @@ impl d::Factory<R> for Factory {
self.handles.make_sampler(sam, info)
}

fn get_main_frame_buffer(&self) -> handle::FrameBuffer<R> {
self.main_fbo.clone()
}

fn update_buffer_raw(&mut self, buffer: &handle::RawBuffer<R>,
data: &[u8], offset_bytes: usize) {
debug_assert!(offset_bytes + data.len() <= buffer.get_info().size);
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use gfx::device::handle;
use gfx::device::state::{CullFace, RasterMethod, FrontFace};

pub use self::draw::{Command, CommandBuffer};
pub use self::factory::Factory;
pub use self::factory::{Factory, Output};
pub use self::info::{Info, PlatformName, Version};

mod draw;
Expand Down

0 comments on commit dd5a4ed

Please sign in to comment.