-
Notifications
You must be signed in to change notification settings - Fork 543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Moved gl_device out #598
Moved gl_device out #598
Changes from all commits
cb217de
5d7d09f
7ee12e5
88b28da
21119de
89c722a
cb7a62c
7dbe7bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
|
||
extern crate cgmath; | ||
extern crate gfx; | ||
extern crate gfx_device_gl; | ||
extern crate glfw; | ||
extern crate time; | ||
extern crate rand; | ||
|
@@ -45,6 +46,7 @@ use cgmath::{Transform, AffineMatrix3}; | |
use gfx::{Device, DeviceExt, Plane, ToSlice, RawBufferHandle}; | ||
use gfx::batch::RefBatch; | ||
use glfw::Context; | ||
use gfx_device_gl::GlResources as R; | ||
use genmesh::{Vertices, Triangulate}; | ||
use genmesh::generators::{SharedVertex, IndexedPolygon}; | ||
use time::precise_time_s; | ||
|
@@ -84,7 +86,7 @@ struct CubeVertex { | |
pos: [i8; 3], | ||
} | ||
|
||
#[shader_param] | ||
#[shader_param(R)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is ok for now, but it would be nice to have a better way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, I just wasn't able to come up with anything better than that... The problem comes from the fact that this structure has to implement |
||
struct TerrainParams { | ||
#[name = "u_Model"] | ||
model: [[f32; 4]; 4], | ||
|
@@ -96,40 +98,40 @@ struct TerrainParams { | |
cam_pos: [f32; 3], | ||
} | ||
|
||
#[shader_param] | ||
#[shader_param(R)] | ||
struct LightParams { | ||
#[name = "u_Transform"] | ||
transform: [[f32; 4]; 4], | ||
#[name = "u_LightPosBlock"] | ||
light_pos_buf: gfx::RawBufferHandle<gfx::GlResources>, | ||
light_pos_buf: gfx::RawBufferHandle<R>, | ||
#[name = "u_Radius"] | ||
radius: f32, | ||
#[name = "u_CameraPos"] | ||
cam_pos: [f32; 3], | ||
#[name = "u_FrameRes"] | ||
frame_res: [f32; 2], | ||
#[name = "u_TexPos"] | ||
tex_pos: gfx::shade::TextureParam<gfx::GlResources>, | ||
tex_pos: gfx::shade::TextureParam<R>, | ||
#[name = "u_TexNormal"] | ||
tex_normal: gfx::shade::TextureParam<gfx::GlResources>, | ||
tex_normal: gfx::shade::TextureParam<R>, | ||
#[name = "u_TexDiffuse"] | ||
tex_diffuse: gfx::shade::TextureParam<gfx::GlResources>, | ||
tex_diffuse: gfx::shade::TextureParam<R>, | ||
} | ||
|
||
#[shader_param] | ||
#[shader_param(R)] | ||
struct EmitterParams { | ||
#[name = "u_Transform"] | ||
transform: [[f32; 4]; 4], | ||
#[name = "u_LightPosBlock"] | ||
light_pos_buf: gfx::RawBufferHandle<gfx::GlResources>, | ||
light_pos_buf: gfx::RawBufferHandle<R>, | ||
#[name = "u_Radius"] | ||
radius: f32, | ||
} | ||
|
||
#[shader_param] | ||
#[shader_param(R)] | ||
struct BlitParams { | ||
#[name = "u_Tex"] | ||
tex: gfx::shade::TextureParam<gfx::GlResources>, | ||
tex: gfx::shade::TextureParam<R>, | ||
} | ||
|
||
static TERRAIN_VERTEX_SRC: &'static [u8] = b" | ||
|
@@ -307,11 +309,10 @@ fn calculate_color(height: f32) -> [f32; 3] { | |
} | ||
} | ||
|
||
type Frame = gfx::Frame<gfx::GlResources>; | ||
type Texture = gfx::TextureHandle<gfx::GlResources>; | ||
type Texture = gfx::TextureHandle<R>; | ||
|
||
fn create_g_buffer(width: u16, height: u16, device: &mut gfx::GlDevice) | ||
-> (Frame, Texture, Texture, Texture, Texture) { | ||
fn create_g_buffer(width: u16, height: u16, device: &mut gfx_device_gl::GlDevice) | ||
-> (gfx::Frame<R>, Texture, Texture, Texture, Texture) { | ||
let mut frame = gfx::Frame::new(width, height); | ||
|
||
let texture_info_float = gfx::tex::TextureInfo { | ||
|
@@ -347,8 +348,8 @@ fn create_g_buffer(width: u16, height: u16, device: &mut gfx::GlDevice) | |
(frame, texture_pos, texture_normal, texture_diffuse, texture_depth) | ||
} | ||
|
||
fn create_res_buffer(width: u16, height: u16, device: &mut gfx::GlDevice, texture_depth: Texture) | ||
-> (Frame, Texture, Texture) { | ||
fn create_res_buffer(width: u16, height: u16, device: &mut gfx_device_gl::GlDevice, texture_depth: Texture) | ||
-> (gfx::Frame<R>, Texture, Texture) { | ||
let mut frame = gfx::Frame::new(width, height); | ||
|
||
let texture_info_float = gfx::tex::TextureInfo { | ||
|
@@ -372,7 +373,7 @@ fn create_res_buffer(width: u16, height: u16, device: &mut gfx::GlDevice, textur | |
|
||
fn main() { | ||
let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS) | ||
.ok().expect("Failed to initialize glfw."); | ||
.unwrap(); | ||
|
||
glfw.window_hint(glfw::WindowHint::ContextVersion(3, 2)); | ||
glfw.window_hint(glfw::WindowHint::OpenglForwardCompat(true)); | ||
|
@@ -389,7 +390,7 @@ fn main() { | |
let (w, h) = window.get_framebuffer_size(); | ||
let frame = gfx::Frame::new(w as u16, h as u16); | ||
|
||
let mut device = gfx::GlDevice::new(|s| window.get_proc_address(s)); | ||
let mut device = gfx_device_gl::GlDevice::new(|s| window.get_proc_address(s)); | ||
let mut renderer = device.create_renderer(); | ||
let mut context = gfx::batch::Context::new(); | ||
|
||
|
@@ -428,11 +429,11 @@ fn main() { | |
.to_slice(gfx::PrimitiveType::TriangleList); | ||
|
||
let program = device.link_program(TERRAIN_VERTEX_SRC, TERRAIN_FRAGMENT_SRC) | ||
.ok().expect("Failed to link program"); | ||
.unwrap(); | ||
let state = gfx::DrawState::new().depth(gfx::state::Comparison::LessEqual, true); | ||
|
||
context.make_batch(&program, &mesh, slice, &state) | ||
.ok().expect("Failed to match back") | ||
.unwrap() | ||
}; | ||
|
||
let blit_batch: RefBatch<BlitParams> = { | ||
|
@@ -448,11 +449,11 @@ fn main() { | |
let slice = mesh.to_slice(gfx::PrimitiveType::TriangleList); | ||
|
||
let program = device.link_program(BLIT_VERTEX_SRC, BLIT_FRAGMENT_SRC) | ||
.ok().expect("Failed to link program"); | ||
.unwrap(); | ||
let state = gfx::DrawState::new(); | ||
|
||
context.make_batch(&program, &mesh, slice, &state) | ||
.ok().expect("Failed to create batch") | ||
.unwrap() | ||
}; | ||
|
||
let (light_batch, emitter_batch) = { | ||
|
@@ -509,18 +510,18 @@ fn main() { | |
|
||
let light_batch: RefBatch<LightParams> = { | ||
let program = device.link_program(LIGHT_VERTEX_SRC, LIGHT_FRAGMENT_SRC) | ||
.ok().expect("Failed to link program."); | ||
.unwrap(); | ||
|
||
context.make_batch(&program, &mesh, slice, &state) | ||
.ok().expect("Failed to create batch") | ||
.unwrap() | ||
}; | ||
|
||
let emitter_batch: RefBatch<EmitterParams> = { | ||
let program = device.link_program(EMITTER_VERTEX_SRC, EMITTER_FRAGMENT_SRC) | ||
.ok().expect("Failed to link program."); | ||
.unwrap(); | ||
|
||
context.make_batch(&program, &mesh, slice, &state) | ||
.ok().expect("Failed to create batch") | ||
.unwrap() | ||
}; | ||
|
||
(light_batch, emitter_batch) | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yay~