Skip to content
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

Merged
merged 8 commits into from
Feb 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

[package]
name = "gfx"
version = "0.1.7"
version = "0.2.0"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay~

description = "A high-performance, bindless graphics API"
homepage = "https://github.com/gfx/gfx-rs"
repository = "https://github.com/gfx/gfx-rs"
homepage = "https://github.com/gfx-rs/gfx-rs"
repository = "https://github.com/gfx-rs/gfx-rs"
keywords = ["graphics", "gamedev"]
license = "Apache-2.0"
authors = ["The Gfx-rs Developers"]
Expand All @@ -27,22 +27,23 @@ name = "gfx"
path = "src/gfx/lib.rs"

[dependencies]
bitflags = "*"
log = "*"

[dependencies.gfx_macros]
[dev_dependencies.gfx_macros]
path = "src/gfx_macros"
plugin = true
version = "0.1.6"

[dependencies.gfx_device_gl]
path = "src/device"
version = "0.1.3"
[dev_dependencies.gfx_device_gl]
git = "https://github.com/gfx-rs/gfx_device_gl"
version = "0.2.0"

[dev_dependencies]
glfw = "*"
gfx_gl = "*"
cgmath = "*"
genmesh = "*"
gfx_gl = "*"
noise = "*"
time = "*"
rand = "*"
Expand Down
10 changes: 6 additions & 4 deletions examples/cube/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
#![plugin(gfx_macros)]

extern crate cgmath;
extern crate gfx;
extern crate glfw;
extern crate gfx;
extern crate gfx_device_gl;

use cgmath::FixedArray;
use cgmath::{Matrix, Point3, Vector3};
use cgmath::{Transform, AffineMatrix3};
use gfx::{Device, DeviceExt, ToSlice};
use gfx::batch::RefBatch;
use glfw::Context;
use gfx_device_gl::GlResources as R;

#[vertex_format]
#[derive(Copy)]
Expand All @@ -40,13 +42,13 @@ struct Vertex {

// The shader_param attribute makes sure the following struct can be used to
// pass parameters to a shader.
#[shader_param]
#[shader_param(R)]
struct Params {
#[name = "u_Transform"]
transform: [[f32; 4]; 4],

#[name = "t_Color"]
color: gfx::shade::TextureParam<gfx::GlResources>,
color: gfx::shade::TextureParam<R>,
}

static VERTEX_SRC: &'static [u8] = b"
Expand Down Expand Up @@ -97,7 +99,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();

Expand Down
53 changes: 27 additions & 26 deletions examples/deferred/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

extern crate cgmath;
extern crate gfx;
extern crate gfx_device_gl;
extern crate glfw;
extern crate time;
extern crate rand;
Expand All @@ -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;
Expand Down Expand Up @@ -84,7 +86,7 @@ struct CubeVertex {
pos: [i8; 3],
}

#[shader_param]
#[shader_param(R)]
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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 ShaderParam for every device. We need to somehow make it device-independent.

struct TerrainParams {
#[name = "u_Model"]
model: [[f32; 4]; 4],
Expand All @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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));
Expand All @@ -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();

Expand Down Expand Up @@ -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> = {
Expand All @@ -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) = {
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion examples/glutin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//! Demonstrates how to initialize gfx-rs using the gl-init-rs library.

extern crate gfx;
extern crate gfx_device_gl;
extern crate glutin;

use gfx::{Device, DeviceExt};
Expand All @@ -28,7 +29,7 @@ fn main() {
unsafe { window.make_current() };
let (w, h) = window.get_inner_size().unwrap();

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();

renderer.clear(
Expand Down
6 changes: 4 additions & 2 deletions examples/performance/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

extern crate cgmath;
extern crate gfx;
extern crate gfx_device_gl;
extern crate glfw;
extern crate time;
extern crate "gfx_gl" as gl;
Expand All @@ -28,6 +29,7 @@ use cgmath::{Transform, AffineMatrix3, Vector4, Array1};
use gfx::{Device, DeviceExt, ToSlice};
use gfx::batch::RefBatch;
use glfw::Context;
use gfx_device_gl::GlResources as R;
use gl::Gl;
use gl::types::*;
use std::mem;
Expand All @@ -50,7 +52,7 @@ struct Vertex {

// The shader_param attribute makes sure the following struct can be used to
// pass parameters to a shader.
#[shader_param]
#[shader_param(R)]
struct Params {
#[name = "u_Transform"]
transform: [[f32; 4]; 4],
Expand Down Expand Up @@ -84,7 +86,7 @@ fn gfx_main(mut glfw: glfw::Glfw,
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 state = gfx::DrawState::new().depth(gfx::state::Comparison::LessEqual, true);

Expand Down
6 changes: 4 additions & 2 deletions examples/terrain/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

extern crate cgmath;
extern crate gfx;
extern crate gfx_device_gl;
extern crate glfw;
extern crate time;
extern crate rand;
Expand All @@ -31,6 +32,7 @@ use cgmath::{Transform, AffineMatrix3};
use gfx::{Device, DeviceExt, ToSlice};
use gfx::batch::RefBatch;
use glfw::Context;
use gfx_device_gl::GlResources as R;
use genmesh::{Vertices, Triangulate};
use genmesh::generators::{Plane, SharedVertex, IndexedPolygon};
use time::precise_time_s;
Expand Down Expand Up @@ -61,7 +63,7 @@ impl fmt::Debug for Vertex {

// The shader_param attribute makes sure the following struct can be used to
// pass parameters to a shader.
#[shader_param]
#[shader_param(R)]
struct Params {
#[name = "u_Model"]
model: [[f32; 4]; 4],
Expand Down Expand Up @@ -132,7 +134,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 rand_seed = rand::thread_rng().gen();
let seed = Seed::new(rand_seed);
Expand Down
3 changes: 2 additions & 1 deletion examples/triangle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#![plugin(gfx_macros)]

extern crate gfx;
extern crate gfx_device_gl;
extern crate glfw;

use gfx::{Device, DeviceExt, ToSlice};
Expand Down Expand Up @@ -69,7 +70,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 vertex_data = [
Vertex { pos: [ -0.5, -0.5 ], color: [1.0, 0.0, 0.0] },
Expand Down
34 changes: 0 additions & 34 deletions src/device/Cargo.toml

This file was deleted.

Loading