Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Commit 697807a

Browse files
author
Mike Blumenkrantz
committed
add gl error checking after every single gl function call
1 parent ff65707 commit 697807a

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

src/platform/linux/surface.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,13 @@ impl PixmapNativeSurface {
277277
];
278278

279279
let glx_display = mem::transmute(native_context.display);
280-
280+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
281281
let glx_pixmap = glx::CreatePixmap(glx_display,
282282
native_context.framebuffer_configuration.expect(
283283
"GLX 1.3 should have a framebuffer_configuration"),
284284
self.pixmap,
285285
pixmap_attributes.as_ptr());
286-
286+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
287287
let glXBindTexImageEXT: extern "C" fn(*mut Display, glx::types::GLXDrawable, c_int, *mut c_int) =
288288
mem::transmute(glx::GetProcAddress(mem::transmute(&"glXBindTexImageEXT\x00".as_bytes()[0])));
289289
assert!(glXBindTexImageEXT as *mut c_void != ptr::null_mut());
@@ -292,10 +292,11 @@ impl PixmapNativeSurface {
292292
mem::transmute(glx_pixmap),
293293
glx::FRONT_EXT as i32,
294294
ptr::null_mut());
295-
assert_eq!(gl::GetError(), gl::NO_ERROR);
295+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
296296

297297
// FIXME(pcwalton): Recycle these for speed?
298298
glx::DestroyPixmap(glx_display, glx_pixmap);
299+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
299300
}
300301
}
301302

src/platform/surface.rs

+1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ impl MemoryBufferNativeSurface {
216216
gl::BGRA,
217217
gl::UNSIGNED_BYTE,
218218
Some(&self.bytes));
219+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
219220
}
220221

221222
#[cfg(target_os="android")]

src/rendergl.rs

+52
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,15 @@ struct ShaderProgram {
102102

103103
impl ShaderProgram {
104104
pub fn new(vertex_shader_source: &str, fragment_shader_source: &str) -> ShaderProgram {
105+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
105106
let id = gl::create_program();
107+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
106108
gl::attach_shader(id, ShaderProgram::compile_shader(fragment_shader_source, gl::FRAGMENT_SHADER));
109+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
107110
gl::attach_shader(id, ShaderProgram::compile_shader(vertex_shader_source, gl::VERTEX_SHADER));
111+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
108112
gl::link_program(id);
113+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
109114
if gl::get_program_iv(id, gl::LINK_STATUS) == (0 as GLint) {
110115
panic!("Failed to compile shader program: {}", gl::get_program_info_log(id));
111116
}
@@ -117,8 +122,11 @@ impl ShaderProgram {
117122

118123
pub fn compile_shader(source_string: &str, shader_type: GLenum) -> GLuint {
119124
let id = gl::create_shader(shader_type);
125+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
120126
gl::shader_source(id, &[ source_string.as_bytes() ]);
127+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
121128
gl::compile_shader(id);
129+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
122130
if gl::get_shader_iv(id, gl::COMPILE_STATUS) == (0 as GLint) {
123131
panic!("Failed to compile shader: {}", gl::get_shader_info_log(id));
124132
}
@@ -173,8 +181,11 @@ impl TextureProgram {
173181
unit_rect: Rect<f32>,
174182
opacity: f32) {
175183
gl::uniform_1i(self.sampler_uniform, 0);
184+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
176185
gl::uniform_matrix_4fv(self.modelview_uniform, false, &transform.to_array());
186+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
177187
gl::uniform_matrix_4fv(self.projection_uniform, false, &projection_matrix.to_array());
188+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
178189

179190
let new_coords: [f32; 8] = [
180191
unit_rect.min_x(), unit_rect.min_y(),
@@ -183,22 +194,29 @@ impl TextureProgram {
183194
unit_rect.max_x(), unit_rect.max_y(),
184195
];
185196
gl::bind_buffer(gl::ARRAY_BUFFER, buffers.textured_quad_vertex_buffer);
197+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
186198
gl::buffer_data(gl::ARRAY_BUFFER, &new_coords, gl::STATIC_DRAW);
199+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
187200
gl::vertex_attrib_pointer_f32(self.vertex_position_attr as GLuint, 2, false, 0, 0);
201+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
188202

189203
gl::uniform_matrix_4fv(self.texture_space_transform_uniform,
190204
false,
191205
&texture_space_transform.to_array());
206+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
192207

193208
gl::uniform_1f(self.opacity_uniform, opacity);
209+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
194210
}
195211

196212
fn enable_attribute_arrays(&self) {
197213
gl::enable_vertex_attrib_array(self.vertex_position_attr as GLuint);
214+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
198215
}
199216

200217
fn disable_attribute_arrays(&self) {
201218
gl::disable_vertex_attrib_array(self.vertex_position_attr as GLuint);
219+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
202220
}
203221

204222
fn create_2d_program() -> TextureProgram {
@@ -208,6 +226,7 @@ impl TextureProgram {
208226
#[cfg(target_os="macos")]
209227
fn create_rectangle_program_if_necessary() -> Option<TextureProgram> {
210228
gl::enable(gl::TEXTURE_RECTANGLE_ARB);
229+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
211230
Some(TextureProgram::new("texture2DRect", "sampler2DRect"))
212231
}
213232

@@ -245,17 +264,21 @@ impl SolidColorProgram {
245264
projection_matrix: &Matrix4<f32>,
246265
color: Color) {
247266
gl::uniform_matrix_4fv(self.modelview_uniform, false, &transform.to_array());
267+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
248268
gl::uniform_matrix_4fv(self.projection_uniform, false, &projection_matrix.to_array());
269+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
249270
gl::uniform_4f(self.color_uniform,
250271
color.r as GLfloat,
251272
color.g as GLfloat,
252273
color.b as GLfloat,
253274
color.a as GLfloat);
275+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
254276

255277
let texture_transform: Matrix4<f32> = identity();
256278
gl::uniform_matrix_4fv(self.texture_space_transform_uniform,
257279
false,
258280
&texture_transform.to_array());
281+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
259282
}
260283

261284
fn bind_uniforms_and_attributes_for_lines(&self,
@@ -265,7 +288,9 @@ impl SolidColorProgram {
265288
color: Color) {
266289
self.bind_uniforms_and_attributes_common(transform, projection_matrix, color);
267290
gl::bind_buffer(gl::ARRAY_BUFFER, buffers.line_quad_vertex_buffer);
291+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
268292
gl::vertex_attrib_pointer_f32(self.vertex_position_attr as GLuint, 2, false, 0, 0);
293+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
269294
}
270295

271296
fn bind_uniforms_and_attributes_for_quad(&self,
@@ -283,16 +308,21 @@ impl SolidColorProgram {
283308
unit_rect.origin.x + unit_rect.size.width, unit_rect.origin.y + unit_rect.size.height,
284309
];
285310
gl::bind_buffer(gl::ARRAY_BUFFER, buffers.textured_quad_vertex_buffer);
311+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
286312
gl::buffer_data(gl::ARRAY_BUFFER, &new_coords, gl::STATIC_DRAW);
313+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
287314
gl::vertex_attrib_pointer_f32(self.vertex_position_attr as GLuint, 2, false, 0, 0);
315+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
288316
}
289317

290318
fn enable_attribute_arrays(&self) {
291319
gl::enable_vertex_attrib_array(self.vertex_position_attr as GLuint);
320+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
292321
}
293322

294323
fn disable_attribute_arrays(&self) {
295324
gl::disable_vertex_attrib_array(self.vertex_position_attr as GLuint);
325+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
296326
}
297327
}
298328

@@ -313,11 +343,15 @@ pub struct RenderContext {
313343
impl RenderContext {
314344
pub fn new(compositing_context: NativeCompositingGraphicsContext,
315345
show_debug_borders: bool) -> RenderContext {
346+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
316347
gl::enable(gl::TEXTURE_2D);
348+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
317349

318350
// Each layer uses premultiplied alpha!
319351
gl::enable(gl::BLEND);
352+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
320353
gl::blend_func(gl::ONE, gl::ONE_MINUS_SRC_ALPHA);
354+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
321355

322356
let texture_2d_program = TextureProgram::create_2d_program();
323357
let solid_color_program = SolidColorProgram::new();
@@ -335,12 +369,18 @@ impl RenderContext {
335369

336370
fn init_buffers() -> Buffers {
337371
let textured_quad_vertex_buffer = gl::gen_buffers(1)[0];
372+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
338373
gl::bind_buffer(gl::ARRAY_BUFFER, textured_quad_vertex_buffer);
374+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
339375
gl::buffer_data(gl::ARRAY_BUFFER, &TEXTURED_QUAD_VERTICES, gl::STATIC_DRAW);
376+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
340377

341378
let line_quad_vertex_buffer = gl::gen_buffers(1)[0];
379+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
342380
gl::bind_buffer(gl::ARRAY_BUFFER, line_quad_vertex_buffer);
381+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
343382
gl::buffer_data(gl::ARRAY_BUFFER, &LINE_QUAD_VERTICES, gl::STATIC_DRAW);
383+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
344384

345385
Buffers {
346386
textured_quad_vertex_buffer: textured_quad_vertex_buffer,
@@ -369,7 +409,9 @@ pub fn bind_and_render_quad(render_context: RenderContext,
369409
program.enable_attribute_arrays();
370410

371411
gl::use_program(program.program.id);
412+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
372413
gl::active_texture(gl::TEXTURE0);
414+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
373415

374416
// FIXME: This should technically check that the transform
375417
// matrix only contains scale in these components.
@@ -412,7 +454,9 @@ pub fn bind_and_render_quad(render_context: RenderContext,
412454

413455
// Draw!
414456
gl::draw_arrays(gl::TRIANGLE_STRIP, 0, 4);
457+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
415458
gl::bind_texture(gl::TEXTURE_2D, 0);
459+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
416460

417461
program.disable_attribute_arrays()
418462
}
@@ -425,13 +469,16 @@ pub fn bind_and_render_quad_lines(render_context: RenderContext,
425469
let solid_color_program = render_context.solid_color_program;
426470
solid_color_program.enable_attribute_arrays();
427471
gl::use_program(solid_color_program.program.id);
472+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
428473
let projection_matrix = ortho(0.0, scene_size.width, scene_size.height, 0.0, -10.0, 10.0);
429474
solid_color_program.bind_uniforms_and_attributes_for_lines(transform,
430475
&projection_matrix,
431476
&render_context.buffers,
432477
color);
433478
gl::line_width(line_thickness as GLfloat);
479+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
434480
gl::draw_arrays(gl::LINE_STRIP, 0, 5);
481+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
435482
solid_color_program.disable_attribute_arrays();
436483
}
437484

@@ -443,13 +490,15 @@ pub fn bind_and_render_solid_quad(render_context: RenderContext,
443490
let solid_color_program = render_context.solid_color_program;
444491
solid_color_program.enable_attribute_arrays();
445492
gl::use_program(solid_color_program.program.id);
493+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
446494
let projection_matrix = ortho(0.0, scene_size.width, scene_size.height, 0.0, -10.0, 10.0);
447495
solid_color_program.bind_uniforms_and_attributes_for_quad(transform,
448496
&projection_matrix,
449497
&render_context.buffers,
450498
color,
451499
unit_rect);
452500
gl::draw_arrays(gl::TRIANGLE_STRIP, 0, 4);
501+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
453502
solid_color_program.disable_attribute_arrays();
454503
}
455504

@@ -605,9 +654,12 @@ pub fn render_scene<T>(root_layer: Rc<Layer<T>>,
605654
let v = scene.viewport.to_untyped();
606655
gl::viewport(v.origin.x as GLint, v.origin.y as GLint,
607656
v.size.width as GLsizei, v.size.height as GLsizei);
657+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
608658

609659
gl::clear_color(1.0, 1.0, 1.0, 1.0);
660+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
610661
gl::clear(gl::COLOR_BUFFER_BIT);
662+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
611663

612664
// Set up the initial modelview matrix.
613665
let transform = identity().scale(scene.scale.get(), scene.scale.get(), 1.0);

src/texturegl.rs

+9
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ pub struct BoundTexture {
108108
impl Drop for BoundTexture {
109109
fn drop(&mut self) {
110110
gl::bind_texture(self.target.as_gl_target(), 0);
111+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
111112
}
112113
}
113114

@@ -121,6 +122,7 @@ impl Texture {
121122
flip: Flip::NoFlip,
122123
size: size,
123124
};
125+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
124126
this.set_default_params();
125127
this
126128
}
@@ -169,9 +171,13 @@ impl Texture {
169171
fn set_default_params(&self) {
170172
let _bound_texture = self.bind();
171173
gl::tex_parameter_i(self.target.as_gl_target(), gl::TEXTURE_MAG_FILTER, gl::LINEAR as GLint);
174+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
172175
gl::tex_parameter_i(self.target.as_gl_target(), gl::TEXTURE_MIN_FILTER, gl::LINEAR as GLint);
176+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
173177
gl::tex_parameter_i(self.target.as_gl_target(), gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE as GLint);
178+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
174179
gl::tex_parameter_i(self.target.as_gl_target(), gl::TEXTURE_WRAP_T, gl::CLAMP_TO_EDGE as GLint);
180+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
175181
}
176182

177183
/// Sets the filter mode for this texture.
@@ -182,12 +188,15 @@ impl Texture {
182188
FilterMode::Linear => gl::LINEAR,
183189
} as GLint;
184190
gl::tex_parameter_i(self.target.as_gl_target(), gl::TEXTURE_MAG_FILTER, gl_mode);
191+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
185192
gl::tex_parameter_i(self.target.as_gl_target(), gl::TEXTURE_MIN_FILTER, gl_mode);
193+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
186194
}
187195

188196
/// Binds the texture to the current context.
189197
pub fn bind(&self) -> BoundTexture {
190198
gl::bind_texture(self.target.as_gl_target(), self.id);
199+
unsafe { assert_eq!(gl::GetError(), gl::NO_ERROR); }
191200

192201
BoundTexture {
193202
target: self.target,

0 commit comments

Comments
 (0)