Skip to content

Commit 2066c4b

Browse files
committed
Merge pull request #341 from bjz/gl_device
Move OpenGL device implementation into separate directory
2 parents fb51688 + 47d0702 commit 2066c4b

File tree

11 files changed

+64
-22
lines changed

11 files changed

+64
-22
lines changed

src/device/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ authors = [
99
name = "device"
1010
path = "lib.rs"
1111

12-
[dependencies.gl_generator]
13-
git = "https://github.com/bjz/gl-rs.git"
12+
[dependencies.gl]
13+
path = "../gl_device/gl/"

src/device/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@
2626
#[phase(plugin, link)] extern crate log;
2727
extern crate libc;
2828

29-
// when cargo is ready, re-enable the cfgs
30-
/* #[cfg(gl)] */ pub use self::gl as back;
31-
/* #[cfg(gl)] */ pub use gl::GlDevice;
32-
/* #[cfg(gl)] */ pub use gl::draw::GlCommandBuffer;
33-
// #[cfg(d3d11)] ... // TODO
29+
// TODO: Remove these exports once `gl_device` becomes a separate crate.
30+
pub use self::gl_device as back;
3431

3532
use std::mem;
3633

@@ -43,7 +40,10 @@ pub mod shade;
4340
pub mod state;
4441
pub mod target;
4542
pub mod tex;
46-
/* #[cfg(gl)] */ mod gl;
43+
44+
// TODO: This will become a separate crate once associated items are implemented
45+
// in rustc and subsequently used in the `Device` trait.
46+
/* #[cfg(gl)] */ #[path = "../gl_device/lib.rs"] pub mod gl_device;
4747

4848
/// Draw vertex count.
4949
pub type VertexCount = u32;

src/gfx/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ pub use render::state::{DrawState, BlendAdditive, BlendAlpha};
4040
pub use render::shade;
4141
pub use render::target::{Frame, Plane, PlaneEmpty, PlaneSurface, PlaneTexture};
4242
pub use device::Device;
43-
// when cargo is ready, re-enable the cfgs
44-
/* #[cfg(gl)] */ pub use device::{GlDevice, GlCommandBuffer};
4543
pub use device::{attrib, state, tex};
4644
pub use device::{BufferHandle, BufferInfo, RawBufferHandle, ShaderHandle,
4745
ProgramHandle, SurfaceHandle, TextureHandle};
@@ -56,3 +54,6 @@ pub use device::shade::{UniformValue,
5654
ValueF32Matrix2, ValueF32Matrix3, ValueF32Matrix4};
5755
pub use device::shade::{ShaderSource, StaticBytes, OwnedBytes, ProgramInfo};
5856
pub use device::target::{Color, ClearData, Layer, Level};
57+
58+
// TODO: Remove this re-export once `gl_device` becomes a separate crate.
59+
pub use device::gl_device::{GlDevice, GlCommandBuffer};
File renamed without changes.

src/gl_device/gl/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
3+
name = "gl"
4+
version = "0.1.0"
5+
authors = [
6+
]
7+
8+
[lib]
9+
name = "gl"
10+
path = "lib.rs"
11+
12+
[dependencies.gl_generator]
13+
git = "https://github.com/bjz/gl-rs.git"

src/gl_device/gl/lib.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2014 The Gfx-rs Developers.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#![crate_name = "gl"]
16+
#![comment = "An OpenGL loader tailored to gfx-rs's needs."]
17+
#![license = "ASL2"]
18+
#![crate_type = "lib"]
19+
20+
#![feature(phase)]
21+
22+
//! An OpenGL loader generated by [gl-rs](https://github.com/bjz/gl-rs).
23+
//!
24+
//! This is useful for directly accessing the underlying OpenGL API via the
25+
//! `GlDevice::with_gl` method. It is also used internally by the `GlDevice`
26+
//! implementation.
27+
28+
#[phase(plugin)] extern crate gl_generator;
29+
30+
generate_gl_bindings!("gl", "core", "4.5", "struct", [ "GL_EXT_texture_filter_anisotropic" ])
File renamed without changes.

src/device/gl/mod.rs renamed to src/gl_device/lib.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
//! OpenGL implementation of a device, striving to support OpenGL 2.0 with at least VAOs, but using
16-
//! newer extensions when available.
15+
//! OpenGL implementation of a device, striving to support OpenGL 2.0 with at
16+
//! least VAOs, but using newer extensions when available.
1717
1818
#![allow(missing_doc)]
1919
#![experimental]
2020

21-
#[phase(plugin)] extern crate gl_generator;
2221
extern crate libc;
22+
extern crate gl;
2323

2424
use log;
2525

@@ -28,18 +28,15 @@ use attrib;
2828
use Device;
2929
use blob::{Blob, RefBlobCast};
3030

31+
pub use self::draw::GlCommandBuffer;
3132
pub use self::info::{Info, PlatformName, Version};
3233

33-
pub mod draw;
34+
mod draw;
3435
mod shade;
3536
mod state;
3637
mod tex;
3738
mod info;
3839

39-
mod gl {
40-
generate_gl_bindings!("gl", "core", "4.5", "struct", [ "GL_EXT_texture_filter_anisotropic" ])
41-
}
42-
4340
pub type Buffer = gl::types::GLuint;
4441
pub type ArrayBuffer = gl::types::GLuint;
4542
pub type Shader = gl::types::GLuint;
@@ -132,8 +129,9 @@ impl GlDevice {
132129
}
133130
}
134131

135-
/// Access the GL directly using a closure
136-
pub fn with_gl(&mut self, fun: |&gl::Gl|) {
132+
/// Access the OpenGL directly via a closure. OpenGL types and enumerations
133+
/// can be found in the `gl` crate.
134+
pub unsafe fn with_gl(&mut self, fun: |&gl::Gl|) {
137135
self.reset_state();
138136
fun(&self.gl);
139137
}
@@ -423,7 +421,7 @@ impl GlDevice {
423421
}
424422
}
425423

426-
impl Device<draw::GlCommandBuffer> for GlDevice {
424+
impl Device<GlCommandBuffer> for GlDevice {
427425
fn get_capabilities<'a>(&'a self) -> &'a ::Capabilities {
428426
&self.caps
429427
}
@@ -434,7 +432,7 @@ impl Device<draw::GlCommandBuffer> for GlDevice {
434432
}
435433
}
436434

437-
fn submit(&mut self, cb: &draw::GlCommandBuffer) {
435+
fn submit(&mut self, cb: &GlCommandBuffer) {
438436
self.reset_state();
439437
for com in cb.iter() {
440438
self.process(com);
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)