Skip to content

Commit f99f255

Browse files
committed
Run rustfmt
1 parent 80700fc commit f99f255

File tree

15 files changed

+807
-537
lines changed

15 files changed

+807
-537
lines changed

gl/examples/triangle.rs

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,16 @@ use std::str;
2222
use std::ffi::CString;
2323

2424
// Vertex data
25-
static VERTEX_DATA: [GLfloat; 6] = [
26-
0.0, 0.5,
27-
0.5, -0.5,
28-
-0.5, -0.5
29-
];
25+
static VERTEX_DATA: [GLfloat; 6] = [0.0, 0.5, 0.5, -0.5, -0.5, -0.5];
3026

3127
// Shader sources
32-
static VS_SRC: &'static str =
33-
"#version 150\n\
28+
static VS_SRC: &'static str = "#version 150\n\
3429
in vec2 position;\n\
3530
void main() {\n\
3631
gl_Position = vec4(position, 0.0, 1.0);\n\
3732
}";
3833

39-
static FS_SRC: &'static str =
40-
"#version 150\n\
34+
static FS_SRC: &'static str = "#version 150\n\
4135
out vec4 out_color;\n\
4236
void main() {\n\
4337
out_color = vec4(1.0, 1.0, 1.0, 1.0);\n\
@@ -62,33 +56,47 @@ fn compile_shader(src: &str, ty: GLenum) -> GLuint {
6256
gl::GetShaderiv(shader, gl::INFO_LOG_LENGTH, &mut len);
6357
let mut buf = Vec::with_capacity(len as usize);
6458
buf.set_len((len as usize) - 1); // subtract 1 to skip the trailing null character
65-
gl::GetShaderInfoLog(shader, len, ptr::null_mut(), buf.as_mut_ptr() as *mut GLchar);
66-
panic!("{}", str::from_utf8(&buf).ok().expect("ShaderInfoLog not valid utf8"));
59+
gl::GetShaderInfoLog(shader,
60+
len,
61+
ptr::null_mut(),
62+
buf.as_mut_ptr() as *mut GLchar);
63+
panic!("{}",
64+
str::from_utf8(&buf)
65+
.ok()
66+
.expect("ShaderInfoLog not valid utf8"));
6767
}
6868
}
6969
shader
7070
}
7171

72-
fn link_program(vs: GLuint, fs: GLuint) -> GLuint { unsafe {
73-
let program = gl::CreateProgram();
74-
gl::AttachShader(program, vs);
75-
gl::AttachShader(program, fs);
76-
gl::LinkProgram(program);
77-
// Get the link status
78-
let mut status = gl::FALSE as GLint;
79-
gl::GetProgramiv(program, gl::LINK_STATUS, &mut status);
80-
81-
// Fail on error
82-
if status != (gl::TRUE as GLint) {
83-
let mut len: GLint = 0;
84-
gl::GetProgramiv(program, gl::INFO_LOG_LENGTH, &mut len);
85-
let mut buf = Vec::with_capacity(len as usize);
86-
buf.set_len((len as usize) - 1); // subtract 1 to skip the trailing null character
87-
gl::GetProgramInfoLog(program, len, ptr::null_mut(), buf.as_mut_ptr() as *mut GLchar);
88-
panic!("{}", str::from_utf8(&buf).ok().expect("ProgramInfoLog not valid utf8"));
72+
fn link_program(vs: GLuint, fs: GLuint) -> GLuint {
73+
unsafe {
74+
let program = gl::CreateProgram();
75+
gl::AttachShader(program, vs);
76+
gl::AttachShader(program, fs);
77+
gl::LinkProgram(program);
78+
// Get the link status
79+
let mut status = gl::FALSE as GLint;
80+
gl::GetProgramiv(program, gl::LINK_STATUS, &mut status);
81+
82+
// Fail on error
83+
if status != (gl::TRUE as GLint) {
84+
let mut len: GLint = 0;
85+
gl::GetProgramiv(program, gl::INFO_LOG_LENGTH, &mut len);
86+
let mut buf = Vec::with_capacity(len as usize);
87+
buf.set_len((len as usize) - 1); // subtract 1 to skip the trailing null character
88+
gl::GetProgramInfoLog(program,
89+
len,
90+
ptr::null_mut(),
91+
buf.as_mut_ptr() as *mut GLchar);
92+
panic!("{}",
93+
str::from_utf8(&buf)
94+
.ok()
95+
.expect("ProgramInfoLog not valid utf8"));
96+
}
97+
program
8998
}
90-
program
91-
} }
99+
}
92100

93101
fn main() {
94102
let window = glutin::Window::new().unwrap();
@@ -123,15 +131,17 @@ fn main() {
123131

124132
// Use shader program
125133
gl::UseProgram(program);
126-
gl::BindFragDataLocation(program, 0,
127-
CString::new("out_color").unwrap().as_ptr());
134+
gl::BindFragDataLocation(program, 0, CString::new("out_color").unwrap().as_ptr());
128135

129136
// Specify the layout of the vertex data
130-
let pos_attr = gl::GetAttribLocation(program,
131-
CString::new("position").unwrap().as_ptr());
137+
let pos_attr = gl::GetAttribLocation(program, CString::new("position").unwrap().as_ptr());
132138
gl::EnableVertexAttribArray(pos_attr as GLuint);
133-
gl::VertexAttribPointer(pos_attr as GLuint, 2, gl::FLOAT,
134-
gl::FALSE as GLboolean, 0, ptr::null());
139+
gl::VertexAttribPointer(pos_attr as GLuint,
140+
2,
141+
gl::FLOAT,
142+
gl::FALSE as GLboolean,
143+
0,
144+
ptr::null());
135145
}
136146

137147
for event in window.wait_events() {

gl_generator/generators/debug_struct_gen.rs

Lines changed: 73 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ use std::io;
1919
pub struct DebugStructGenerator;
2020

2121
impl super::Generator for DebugStructGenerator {
22-
fn write<W>(&self, registry: &Registry, dest: &mut W) -> io::Result<()> where W: io::Write {
22+
fn write<W>(&self, registry: &Registry, dest: &mut W) -> io::Result<()>
23+
where W: io::Write
24+
{
2325
try!(write_header(dest));
2426
try!(write_type_aliases(registry, dest));
2527
try!(write_enums(registry, dest));
@@ -33,8 +35,11 @@ impl super::Generator for DebugStructGenerator {
3335

3436
/// Creates a `__gl_imports` module which contains all the external symbols that we need for the
3537
/// bindings.
36-
fn write_header<W>(dest: &mut W) -> io::Result<()> where W: io::Write {
37-
writeln!(dest, r#"
38+
fn write_header<W>(dest: &mut W) -> io::Result<()>
39+
where W: io::Write
40+
{
41+
writeln!(dest,
42+
r#"
3843
mod __gl_imports {{
3944
pub use std::mem;
4045
pub use std::marker::Send;
@@ -46,8 +51,11 @@ fn write_header<W>(dest: &mut W) -> io::Result<()> where W: io::Write {
4651
/// Creates a `types` module which contains all the type aliases.
4752
///
4853
/// See also `generators::gen_types`.
49-
fn write_type_aliases<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W: io::Write {
50-
try!(writeln!(dest, r#"
54+
fn write_type_aliases<W>(registry: &Registry, dest: &mut W) -> io::Result<()>
55+
where W: io::Write
56+
{
57+
try!(writeln!(dest,
58+
r#"
5159
pub mod types {{
5260
#![allow(non_camel_case_types, non_snake_case, dead_code, missing_copy_implementations)]
5361
"#));
@@ -58,7 +66,9 @@ fn write_type_aliases<W>(registry: &Registry, dest: &mut W) -> io::Result<()> wh
5866
}
5967

6068
/// Creates all the `<enum>` elements at the root of the bindings.
61-
fn write_enums<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W: io::Write {
69+
fn write_enums<W>(registry: &Registry, dest: &mut W) -> io::Result<()>
70+
where W: io::Write
71+
{
6272
for enm in &registry.enums {
6373
try!(super::gen_enum_item(enm, "types::", dest));
6474
}
@@ -67,8 +77,11 @@ fn write_enums<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W:
6777
}
6878

6979
/// Creates a `FnPtr` structure which contains the store for a single binding.
70-
fn write_fnptr_struct_def<W>(dest: &mut W) -> io::Result<()> where W: io::Write {
71-
writeln!(dest, "
80+
fn write_fnptr_struct_def<W>(dest: &mut W) -> io::Result<()>
81+
where W: io::Write
82+
{
83+
writeln!(dest,
84+
"
7285
#[allow(dead_code, missing_copy_implementations)]
7386
#[derive(Clone)]
7487
pub struct FnPtr {{
@@ -106,26 +119,29 @@ fn write_fnptr_struct_def<W>(dest: &mut W) -> io::Result<()> where W: io::Write
106119
/// Creates a `panicking` module which contains one function per GL command.
107120
///
108121
/// These functions are the mocks that are called if the real function could not be loaded.
109-
fn write_panicking_fns<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W: io::Write {
122+
fn write_panicking_fns<W>(registry: &Registry, dest: &mut W) -> io::Result<()>
123+
where W: io::Write
124+
{
110125
writeln!(dest,
111-
"#[inline(never)]
126+
"#[inline(never)]
112127
fn missing_fn_panic() -> ! {{
113128
panic!(\"{api} function was not loaded\")
114129
}}",
115-
api = registry.api
116-
)
130+
api = registry.api)
117131
}
118132

119133
/// Creates a structure which stores all the `FnPtr` of the bindings.
120134
///
121135
/// The name of the struct corresponds to the namespace.
122-
fn write_struct<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W: io::Write {
123-
try!(writeln!(dest, "
136+
fn write_struct<W>(registry: &Registry, dest: &mut W) -> io::Result<()>
137+
where W: io::Write
138+
{
139+
try!(writeln!(dest,
140+
"
124141
#[allow(non_camel_case_types, non_snake_case, dead_code)]
125142
#[derive(Clone)]
126143
pub struct {api} {{",
127-
api = super::gen_struct_name(registry.api)
128-
));
144+
api = super::gen_struct_name(registry.api)));
129145

130146
for cmd in &registry.cmds {
131147
if let Some(v) = registry.aliases.get(&cmd.proto.ident) {
@@ -138,9 +154,11 @@ fn write_struct<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W:
138154
}
139155

140156
/// Creates the `impl` of the structure created by `write_struct`.
141-
fn write_impl<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W: io::Write {
157+
fn write_impl<W>(registry: &Registry, dest: &mut W) -> io::Result<()>
158+
where W: io::Write
159+
{
142160
try!(writeln!(dest,
143-
"impl {api} {{
161+
"impl {api} {{
144162
/// Load each OpenGL symbol using a custom load function. This allows for the
145163
/// use of functions like `glfwGetProcAddress` or `SDL_GL_GetProcAddress`.
146164
///
@@ -167,8 +185,7 @@ fn write_impl<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W: i
167185
do_metaloadfn(&mut loadfn, symbol, symbols)
168186
}};
169187
{api} {{",
170-
api = super::gen_struct_name(registry.api)
171-
));
188+
api = super::gen_struct_name(registry.api)));
172189

173190
for cmd in &registry.cmds {
174191
try!(writeln!(dest,
@@ -187,53 +204,60 @@ fn write_impl<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W: i
187204
}
188205

189206
try!(writeln!(dest,
190-
"}}
191-
}}"
192-
));
207+
"}}
208+
}}"));
193209

194210
for cmd in &registry.cmds {
195211
let idents = super::gen_parameters(cmd, true, false);
196212
let typed_params = super::gen_parameters(cmd, false, true);
197213
let println = format!("println!(\"[OpenGL] {}({})\" {});",
198-
cmd.proto.ident,
199-
(0 .. idents.len()).map(|_| "{:?}".to_string()).collect::<Vec<_>>().join(", "),
200-
idents.iter().zip(typed_params.iter())
201-
.map(|(name, ty)| {
202-
if ty.contains("GLDEBUGPROC") {
203-
format!(", \"<callback>\"")
204-
} else {
205-
format!(", {}", name)
206-
}
207-
}).collect::<Vec<_>>().concat());
214+
cmd.proto.ident,
215+
(0..idents.len())
216+
.map(|_| "{:?}".to_string())
217+
.collect::<Vec<_>>()
218+
.join(", "),
219+
idents
220+
.iter()
221+
.zip(typed_params.iter())
222+
.map(|(name, ty)| if ty.contains("GLDEBUGPROC") {
223+
format!(", \"<callback>\"")
224+
} else {
225+
format!(", {}", name)
226+
})
227+
.collect::<Vec<_>>()
228+
.concat());
208229

209230
try!(writeln!(dest,
210-
"#[allow(non_snake_case, unused_variables, dead_code)]
231+
"#[allow(non_snake_case, unused_variables, dead_code)]
211232
#[inline] pub unsafe fn {name}(&self, {params}) -> {return_suffix} {{ \
212233
{println}
213234
let r = __gl_imports::mem::transmute::<_, extern \"system\" fn({typed_params}) -> {return_suffix}>\
214235
(self.{name}.f)({idents});
215236
{print_err}
216237
r
217238
}}",
218-
name = cmd.proto.ident,
219-
params = super::gen_parameters(cmd, true, true).join(", "),
220-
typed_params = typed_params.join(", "),
221-
return_suffix = cmd.proto.ty,
222-
idents = idents.join(", "),
223-
println = println,
224-
print_err = if cmd.proto.ident != "GetError" && registry.cmds.iter().find(|cmd| cmd.proto.ident == "GetError").is_some() {
225-
format!(r#"match __gl_imports::mem::transmute::<_, extern "system" fn() -> u32>
239+
name = cmd.proto.ident,
240+
params = super::gen_parameters(cmd, true, true).join(", "),
241+
typed_params = typed_params.join(", "),
242+
return_suffix = cmd.proto.ty,
243+
idents = idents.join(", "),
244+
println = println,
245+
print_err = if cmd.proto.ident != "GetError" &&
246+
registry
247+
.cmds
248+
.iter()
249+
.find(|cmd| cmd.proto.ident == "GetError")
250+
.is_some() {
251+
format!(r#"match __gl_imports::mem::transmute::<_, extern "system" fn() -> u32>
226252
(self.GetError.f)() {{ 0 => (), r => println!("[OpenGL] ^ GL error triggered: {{}}", r) }}"#)
227-
} else {
228-
format!("")
229-
}
230-
))
253+
} else {
254+
format!("")
255+
}))
231256
}
232257

233258
writeln!(dest,
234-
"}}
259+
"}}
235260
236261
unsafe impl __gl_imports::Send for {api} {{}}",
237-
api = super::gen_struct_name(registry.api)
238-
)
262+
api = super::gen_struct_name(registry.api))
239263
}

0 commit comments

Comments
 (0)