Skip to content

Commit

Permalink
Merge pull request gfx-rs#503 from csherratt/master
Browse files Browse the repository at this point in the history
Fix build with latest rustc
  • Loading branch information
brendanzab committed Jan 24, 2015
2 parents f308feb + 01c40f2 commit b21a766
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 53 deletions.
14 changes: 9 additions & 5 deletions examples/cube/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ glsl_150: b"
//----------------------------------------

fn main() {
let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS)
.ok().expect("Failed to initialize glfs-rs");

glfw.window_hint(glfw::WindowHint::ContextVersion(3, 2));
glfw.window_hint(glfw::WindowHint::OpenglForwardCompat(true));
Expand Down Expand Up @@ -192,21 +193,24 @@ fn main() {
format: gfx::tex::RGBA8,
};
let image_info = texture_info.to_image_info();
let texture = device.create_texture(texture_info).unwrap();
let texture = device.create_texture(texture_info)
.ok().expect("Failed to create texture");
device.update_texture(&texture, &image_info,
&[0x20u8, 0xA0u8, 0xC0u8, 0x00u8])
.unwrap();
.ok().expect("Failed to update texture");

let sampler = device.create_sampler(
gfx::tex::SamplerInfo::new(gfx::tex::FilterMethod::Bilinear,
gfx::tex::WrapMode::Clamp)
);

let program = device.link_program(VERTEX_SRC.clone(), FRAGMENT_SRC.clone())
.unwrap();
.ok().expect("Failed to link program.");

let state = gfx::DrawState::new().depth(gfx::state::Comparison::LessEqual, true);

let batch: CubeBatch = context.make_batch(&program, &mesh, slice, &state).unwrap();
let batch: CubeBatch = context.make_batch(&program, &mesh, slice, &state)
.ok().expect("Failed to make batch.");;

let view: AffineMatrix3<f32> = Transform::look_at(
&Point3::new(1.5f32, -5.0, 3.0),
Expand Down
42 changes: 28 additions & 14 deletions examples/deferred/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,14 @@ fn create_g_buffer(width: u16, height: u16, device: &mut gfx::GlDevice) -> (gfx:
kind: gfx::tex::TextureKind::Texture2D,
format: gfx::tex::Format::DEPTH24STENCIL8,
};
let texture_pos = device.create_texture(texture_info_float).unwrap();
let texture_normal = device.create_texture(texture_info_float).unwrap();
let texture_diffuse = device.create_texture(texture_info_float).unwrap();
let texture_depth = device.create_texture(texture_info_depth).unwrap();
let texture_pos = device.create_texture(texture_info_float)
.ok().expect("failed to create texture.");
let texture_normal = device.create_texture(texture_info_float)
.ok().expect("failed to create texture.");
let texture_diffuse = device.create_texture(texture_info_float)
.ok().expect("failed to create texture.");
let texture_depth = device.create_texture(texture_info_depth)
.ok().expect("failed to create texture.");

frame.colors.push(Plane::Texture(texture_pos, 0, None));
frame.colors.push(Plane::Texture(texture_normal, 0, None));
Expand All @@ -511,7 +515,9 @@ fn create_res_buffer(width: u16, height: u16, device: &mut gfx::GlDevice, textur
format: gfx::tex::Format::Float(gfx::tex::Components::RGBA, gfx::attrib::FloatSize::F32),
};

let texture_frame = device.create_texture(texture_info_float).unwrap();
let texture_frame = device.create_texture(texture_info_float)
.ok().expect("failed to create texture.");
;

frame.colors.push(Plane::Texture(texture_frame, 0, None));
frame.depth = Some(Plane::Texture(texture_depth, 0, None));
Expand All @@ -520,7 +526,8 @@ fn create_res_buffer(width: u16, height: u16, device: &mut gfx::GlDevice, textur
}

fn main() {
let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS)
.ok().expect("Failed to initialize glfw.");

glfw.window_hint(glfw::WindowHint::ContextVersion(3, 2));
glfw.window_hint(glfw::WindowHint::OpenglForwardCompat(true));
Expand Down Expand Up @@ -576,10 +583,11 @@ fn main() {
.to_slice(gfx::PrimitiveType::TriangleList);

let program = device.link_program(TERRAIN_VERTEX_SRC.clone(), TERRAIN_FRAGMENT_SRC.clone())
.unwrap();
.ok().expect("Failed to link program");
let state = gfx::DrawState::new().depth(gfx::state::Comparison::LessEqual, true);

context.make_batch(&program, &mesh, slice, &state).unwrap()
context.make_batch(&program, &mesh, slice, &state)
.ok().expect("Failed to match back")
};

let blit_batch: BlitBatch = {
Expand All @@ -594,10 +602,12 @@ fn main() {
let mesh = device.create_mesh(&vertex_data);
let slice = mesh.to_slice(gfx::PrimitiveType::TriangleList);

let program = device.link_program(BLIT_VERTEX_SRC.clone(), BLIT_FRAGMENT_SRC.clone()).unwrap();
let program = device.link_program(BLIT_VERTEX_SRC.clone(), BLIT_FRAGMENT_SRC.clone())
.ok().expect("Failed to link program");
let state = gfx::DrawState::new();

context.make_batch(&program, &mesh, slice, &state).unwrap()
context.make_batch(&program, &mesh, slice, &state)
.ok().expect("Failed to create batch")
};

let (light_batch, emitter_batch) = {
Expand Down Expand Up @@ -653,15 +663,19 @@ fn main() {
.blend(gfx::BlendPreset::Additive);

let light_batch: LightBatch = {
let program = device.link_program(LIGHT_VERTEX_SRC.clone(), LIGHT_FRAGMENT_SRC.clone()).unwrap();
let program = device.link_program(LIGHT_VERTEX_SRC.clone(), LIGHT_FRAGMENT_SRC.clone())
.ok().expect("Failed to link program.");

context.make_batch(&program, &mesh, slice, &state).unwrap()
context.make_batch(&program, &mesh, slice, &state)
.ok().expect("Failed to create batch")
};

let emitter_batch: EmitterBatch = {
let program = device.link_program(EMITTER_VERTEX_SRC.clone(), EMITTER_FRAGMENT_SRC.clone()).unwrap();
let program = device.link_program(EMITTER_VERTEX_SRC.clone(), EMITTER_FRAGMENT_SRC.clone())
.ok().expect("Failed to link program.");

context.make_batch(&program, &mesh, slice, &state).unwrap()
context.make_batch(&program, &mesh, slice, &state)
.ok().expect("Failed to create batch")
};

(light_batch, emitter_batch)
Expand Down
13 changes: 8 additions & 5 deletions examples/performance/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,14 @@ fn gfx_main(mut glfw: glfw::Glfw,
format: gfx::tex::RGBA8,
};
let image_info = texture_info.to_image_info();
let texture = device.create_texture(texture_info).unwrap();
let texture = device.create_texture(texture_info)
.ok().expect("Failed to create texture");
device.update_texture(&texture, &image_info,
&[0x20u8, 0xA0u8, 0xC0u8, 0x00u8])
.unwrap();
.ok().expect("Failed to update texture");

let program = device.link_program(VERTEX_SRC.clone(), FRAGMENT_SRC.clone())
.unwrap();
.ok().expect("Failed to link shaders");
let view: AffineMatrix3<f32> = Transform::look_at(
&Point3::new(0f32, -5.0, 0.0),
&Point3::new(0f32, 0.0, 0.0),
Expand All @@ -136,7 +137,8 @@ fn gfx_main(mut glfw: glfw::Glfw,
};

let mut graphics = gfx::Graphics::new(device);
let batch: TriangleBatch = graphics.make_batch(&program, &mesh, slice, &state).unwrap();
let batch: TriangleBatch = graphics.make_batch(&program, &mesh, slice, &state)
.ok().expect("Failed to make batch");

while !window.should_close() {
glfw.poll_events();
Expand Down Expand Up @@ -380,7 +382,8 @@ fn main() {

let count = ((count as f64).sqrt() / 2.) as i16;

let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS)
.ok().expect("Failed to initialize glfs-rs");

glfw.window_hint(glfw::WindowHint::ContextVersion(3, 2));
glfw.window_hint(glfw::WindowHint::OpenglForwardCompat(true));
Expand Down
8 changes: 5 additions & 3 deletions examples/terrain/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ fn calculate_color(height: f32) -> [f32; 3] {
fn main() {
use std::num::Float;

let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS)
.ok().expect("Failed to initialize glfs-rs");

glfw.window_hint(glfw::WindowHint::ContextVersion(3, 2));
glfw.window_hint(glfw::WindowHint::OpenglForwardCompat(true));
Expand Down Expand Up @@ -192,11 +193,12 @@ fn main() {

let mesh = device.create_mesh(vertex_data.as_slice());
let program = device.link_program(VERTEX_SRC.clone(), FRAGMENT_SRC.clone())
.unwrap();
.ok().expect("Failed to link shaders.");
let state = gfx::DrawState::new().depth(gfx::state::Comparison::LessEqual, true);

let mut graphics = gfx::Graphics::new(device);
let batch: Terrain = graphics.make_batch(&program, &mesh, slice, &state).unwrap();
let batch: Terrain = graphics.make_batch(&program, &mesh, slice, &state)
.ok().expect("Failed to make batch.");

let aspect = w as f32 / h as f32;
let mut data = Params {
Expand Down
7 changes: 4 additions & 3 deletions examples/triangle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ glsl_150: b"
};

fn main() {
let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS)
.ok().expect("failed to init glfw");

glfw.window_hint(glfw::WindowHint::ContextVersion(3, 2));
glfw.window_hint(glfw::WindowHint::OpenglForwardCompat(true));
Expand Down Expand Up @@ -111,11 +112,11 @@ fn main() {
let slice = mesh.to_slice(gfx::PrimitiveType::TriangleList);

let program = device.link_program(VERTEX_SRC.clone(), FRAGMENT_SRC.clone())
.unwrap();
.ok().expect("Failed to link program");

let mut graphics = gfx::Graphics::new(device);
let batch: gfx::batch::RefBatch<(), ()> = graphics.make_batch(
&program, &mesh, slice, &gfx::DrawState::new()).unwrap();
&program, &mesh, slice, &gfx::DrawState::new()).ok().expect("Failed to make batch");

let clear_data = gfx::ClearData {
color: [0.3, 0.3, 0.3, 1.0],
Expand Down
17 changes: 8 additions & 9 deletions src/gfx_macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,20 @@ fn extern_crate_hack<F>(context: &mut ext::base::ExtCtxt,
extern_crate_hack,
vec![],
vec![
ast::ViewItem {
P(ast::Item {
span: span,
vis: ast::Inherited,
attrs: vec![],
node: ast::ViewItemExternCrate(
context.ident_of("gfx_"),
node: ast::ItemExternCrate(
Some((
token::InternedString::new("gfx"),
ast::CookedStr
)),
ast::DUMMY_NODE_ID
)
},
context.view_use_simple_(
),
id: ast::DUMMY_NODE_ID,
ident: token::str_to_ident("gfx_")
}),
context.item_use_simple_(
span,
ast::Public,
context.ident_of("gfx"),
Expand All @@ -111,8 +111,7 @@ fn extern_crate_hack<F>(context: &mut ext::base::ExtCtxt,
context.ident_of("gfx_")
])
)
],
vec![]
]
);
push(item);
extern_crate_hack
Expand Down
28 changes: 14 additions & 14 deletions src/gfx_macros/shader_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,19 @@ fn method_fill(cx: &mut ext::base::ExtCtxt, span: codemap::Span,
match *substr.fields {
generic::Struct(ref fields) => {
let out = &substr.nonself_args[1];
let max_num = cx.expr_uint(span, fields.len());
let max_num = cx.expr_usize(span, fields.len());
let mut calls = vec![
cx.stmt_item(span, cx.item_use_simple(
span,
ast::Inherited,
cx.path(span, vec![
cx.ident_of("self"),
path_root,
cx.ident_of("gfx"),
cx.ident_of("shade"),
cx.ident_of("ToUniform"),
])
)),
quote_stmt!(cx, $out.uniforms.reserve($max_num);),
quote_stmt!(cx, $out.blocks.reserve($max_num);),
quote_stmt!(cx, $out.textures.reserve($max_num);),
Expand Down Expand Up @@ -188,22 +199,11 @@ fn method_fill(cx: &mut ext::base::ExtCtxt, span: codemap::Span,
f.name.unwrap().as_str(),
)[]
);
cx.stmt_expr(cx.expr_uint(span, 0))
cx.stmt_expr(cx.expr_usize(span, 0))
},
}
}));
let view = cx.view_use_simple(
span,
ast::Inherited,
cx.path(span, vec![
cx.ident_of("self"),
path_root,
cx.ident_of("gfx"),
cx.ident_of("shade"),
cx.ident_of("ToUniform"),
])
);
cx.expr_block(cx.block_all(span, vec![view], calls, None))
cx.expr_block(cx.block_all(span, calls, None))
},
_ => {
cx.span_err(span, "Unable to implement `ShaderParam::bind()` on a non-structure");
Expand Down

0 comments on commit b21a766

Please sign in to comment.