@@ -102,10 +102,15 @@ struct ShaderProgram {
102
102
103
103
impl ShaderProgram {
104
104
pub fn new ( vertex_shader_source : & str , fragment_shader_source : & str ) -> ShaderProgram {
105
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
105
106
let id = gl:: create_program ( ) ;
107
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
106
108
gl:: attach_shader ( id, ShaderProgram :: compile_shader ( fragment_shader_source, gl:: FRAGMENT_SHADER ) ) ;
109
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
107
110
gl:: attach_shader ( id, ShaderProgram :: compile_shader ( vertex_shader_source, gl:: VERTEX_SHADER ) ) ;
111
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
108
112
gl:: link_program ( id) ;
113
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
109
114
if gl:: get_program_iv ( id, gl:: LINK_STATUS ) == ( 0 as GLint ) {
110
115
panic ! ( "Failed to compile shader program: {}" , gl:: get_program_info_log( id) ) ;
111
116
}
@@ -117,8 +122,11 @@ impl ShaderProgram {
117
122
118
123
pub fn compile_shader ( source_string : & str , shader_type : GLenum ) -> GLuint {
119
124
let id = gl:: create_shader ( shader_type) ;
125
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
120
126
gl:: shader_source ( id, & [ source_string. as_bytes ( ) ] ) ;
127
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
121
128
gl:: compile_shader ( id) ;
129
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
122
130
if gl:: get_shader_iv ( id, gl:: COMPILE_STATUS ) == ( 0 as GLint ) {
123
131
panic ! ( "Failed to compile shader: {}" , gl:: get_shader_info_log( id) ) ;
124
132
}
@@ -173,8 +181,11 @@ impl TextureProgram {
173
181
unit_rect : Rect < f32 > ,
174
182
opacity : f32 ) {
175
183
gl:: uniform_1i ( self . sampler_uniform , 0 ) ;
184
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
176
185
gl:: uniform_matrix_4fv ( self . modelview_uniform , false , & transform. to_array ( ) ) ;
186
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
177
187
gl:: uniform_matrix_4fv ( self . projection_uniform , false , & projection_matrix. to_array ( ) ) ;
188
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
178
189
179
190
let new_coords: [ f32 ; 8 ] = [
180
191
unit_rect. min_x ( ) , unit_rect. min_y ( ) ,
@@ -183,22 +194,29 @@ impl TextureProgram {
183
194
unit_rect. max_x ( ) , unit_rect. max_y ( ) ,
184
195
] ;
185
196
gl:: bind_buffer ( gl:: ARRAY_BUFFER , buffers. textured_quad_vertex_buffer ) ;
197
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
186
198
gl:: buffer_data ( gl:: ARRAY_BUFFER , & new_coords, gl:: STATIC_DRAW ) ;
199
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
187
200
gl:: vertex_attrib_pointer_f32 ( self . vertex_position_attr as GLuint , 2 , false , 0 , 0 ) ;
201
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
188
202
189
203
gl:: uniform_matrix_4fv ( self . texture_space_transform_uniform ,
190
204
false ,
191
205
& texture_space_transform. to_array ( ) ) ;
206
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
192
207
193
208
gl:: uniform_1f ( self . opacity_uniform , opacity) ;
209
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
194
210
}
195
211
196
212
fn enable_attribute_arrays ( & self ) {
197
213
gl:: enable_vertex_attrib_array ( self . vertex_position_attr as GLuint ) ;
214
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
198
215
}
199
216
200
217
fn disable_attribute_arrays ( & self ) {
201
218
gl:: disable_vertex_attrib_array ( self . vertex_position_attr as GLuint ) ;
219
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
202
220
}
203
221
204
222
fn create_2d_program ( ) -> TextureProgram {
@@ -208,6 +226,7 @@ impl TextureProgram {
208
226
#[ cfg( target_os="macos" ) ]
209
227
fn create_rectangle_program_if_necessary ( ) -> Option < TextureProgram > {
210
228
gl:: enable ( gl:: TEXTURE_RECTANGLE_ARB ) ;
229
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
211
230
Some ( TextureProgram :: new ( "texture2DRect" , "sampler2DRect" ) )
212
231
}
213
232
@@ -245,17 +264,21 @@ impl SolidColorProgram {
245
264
projection_matrix : & Matrix4 < f32 > ,
246
265
color : Color ) {
247
266
gl:: uniform_matrix_4fv ( self . modelview_uniform , false , & transform. to_array ( ) ) ;
267
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
248
268
gl:: uniform_matrix_4fv ( self . projection_uniform , false , & projection_matrix. to_array ( ) ) ;
269
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
249
270
gl:: uniform_4f ( self . color_uniform ,
250
271
color. r as GLfloat ,
251
272
color. g as GLfloat ,
252
273
color. b as GLfloat ,
253
274
color. a as GLfloat ) ;
275
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
254
276
255
277
let texture_transform: Matrix4 < f32 > = identity ( ) ;
256
278
gl:: uniform_matrix_4fv ( self . texture_space_transform_uniform ,
257
279
false ,
258
280
& texture_transform. to_array ( ) ) ;
281
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
259
282
}
260
283
261
284
fn bind_uniforms_and_attributes_for_lines ( & self ,
@@ -265,7 +288,9 @@ impl SolidColorProgram {
265
288
color : Color ) {
266
289
self . bind_uniforms_and_attributes_common ( transform, projection_matrix, color) ;
267
290
gl:: bind_buffer ( gl:: ARRAY_BUFFER , buffers. line_quad_vertex_buffer ) ;
291
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
268
292
gl:: vertex_attrib_pointer_f32 ( self . vertex_position_attr as GLuint , 2 , false , 0 , 0 ) ;
293
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
269
294
}
270
295
271
296
fn bind_uniforms_and_attributes_for_quad ( & self ,
@@ -283,16 +308,21 @@ impl SolidColorProgram {
283
308
unit_rect. origin . x + unit_rect. size . width , unit_rect. origin . y + unit_rect. size . height ,
284
309
] ;
285
310
gl:: bind_buffer ( gl:: ARRAY_BUFFER , buffers. textured_quad_vertex_buffer ) ;
311
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
286
312
gl:: buffer_data ( gl:: ARRAY_BUFFER , & new_coords, gl:: STATIC_DRAW ) ;
313
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
287
314
gl:: vertex_attrib_pointer_f32 ( self . vertex_position_attr as GLuint , 2 , false , 0 , 0 ) ;
315
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
288
316
}
289
317
290
318
fn enable_attribute_arrays ( & self ) {
291
319
gl:: enable_vertex_attrib_array ( self . vertex_position_attr as GLuint ) ;
320
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
292
321
}
293
322
294
323
fn disable_attribute_arrays ( & self ) {
295
324
gl:: disable_vertex_attrib_array ( self . vertex_position_attr as GLuint ) ;
325
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
296
326
}
297
327
}
298
328
@@ -313,11 +343,15 @@ pub struct RenderContext {
313
343
impl RenderContext {
314
344
pub fn new ( compositing_context : NativeCompositingGraphicsContext ,
315
345
show_debug_borders : bool ) -> RenderContext {
346
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
316
347
gl:: enable ( gl:: TEXTURE_2D ) ;
348
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
317
349
318
350
// Each layer uses premultiplied alpha!
319
351
gl:: enable ( gl:: BLEND ) ;
352
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
320
353
gl:: blend_func ( gl:: ONE , gl:: ONE_MINUS_SRC_ALPHA ) ;
354
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
321
355
322
356
let texture_2d_program = TextureProgram :: create_2d_program ( ) ;
323
357
let solid_color_program = SolidColorProgram :: new ( ) ;
@@ -335,12 +369,18 @@ impl RenderContext {
335
369
336
370
fn init_buffers ( ) -> Buffers {
337
371
let textured_quad_vertex_buffer = gl:: gen_buffers ( 1 ) [ 0 ] ;
372
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
338
373
gl:: bind_buffer ( gl:: ARRAY_BUFFER , textured_quad_vertex_buffer) ;
374
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
339
375
gl:: buffer_data ( gl:: ARRAY_BUFFER , & TEXTURED_QUAD_VERTICES , gl:: STATIC_DRAW ) ;
376
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
340
377
341
378
let line_quad_vertex_buffer = gl:: gen_buffers ( 1 ) [ 0 ] ;
379
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
342
380
gl:: bind_buffer ( gl:: ARRAY_BUFFER , line_quad_vertex_buffer) ;
381
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
343
382
gl:: buffer_data ( gl:: ARRAY_BUFFER , & LINE_QUAD_VERTICES , gl:: STATIC_DRAW ) ;
383
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
344
384
345
385
Buffers {
346
386
textured_quad_vertex_buffer : textured_quad_vertex_buffer,
@@ -369,7 +409,9 @@ pub fn bind_and_render_quad(render_context: RenderContext,
369
409
program. enable_attribute_arrays ( ) ;
370
410
371
411
gl:: use_program ( program. program . id ) ;
412
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
372
413
gl:: active_texture ( gl:: TEXTURE0 ) ;
414
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
373
415
374
416
// FIXME: This should technically check that the transform
375
417
// matrix only contains scale in these components.
@@ -412,7 +454,9 @@ pub fn bind_and_render_quad(render_context: RenderContext,
412
454
413
455
// Draw!
414
456
gl:: draw_arrays ( gl:: TRIANGLE_STRIP , 0 , 4 ) ;
457
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
415
458
gl:: bind_texture ( gl:: TEXTURE_2D , 0 ) ;
459
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
416
460
417
461
program. disable_attribute_arrays ( )
418
462
}
@@ -425,13 +469,16 @@ pub fn bind_and_render_quad_lines(render_context: RenderContext,
425
469
let solid_color_program = render_context. solid_color_program ;
426
470
solid_color_program. enable_attribute_arrays ( ) ;
427
471
gl:: use_program ( solid_color_program. program . id ) ;
472
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
428
473
let projection_matrix = ortho ( 0.0 , scene_size. width , scene_size. height , 0.0 , -10.0 , 10.0 ) ;
429
474
solid_color_program. bind_uniforms_and_attributes_for_lines ( transform,
430
475
& projection_matrix,
431
476
& render_context. buffers ,
432
477
color) ;
433
478
gl:: line_width ( line_thickness as GLfloat ) ;
479
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
434
480
gl:: draw_arrays ( gl:: LINE_STRIP , 0 , 5 ) ;
481
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
435
482
solid_color_program. disable_attribute_arrays ( ) ;
436
483
}
437
484
@@ -443,13 +490,15 @@ pub fn bind_and_render_solid_quad(render_context: RenderContext,
443
490
let solid_color_program = render_context. solid_color_program ;
444
491
solid_color_program. enable_attribute_arrays ( ) ;
445
492
gl:: use_program ( solid_color_program. program . id ) ;
493
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
446
494
let projection_matrix = ortho ( 0.0 , scene_size. width , scene_size. height , 0.0 , -10.0 , 10.0 ) ;
447
495
solid_color_program. bind_uniforms_and_attributes_for_quad ( transform,
448
496
& projection_matrix,
449
497
& render_context. buffers ,
450
498
color,
451
499
unit_rect) ;
452
500
gl:: draw_arrays ( gl:: TRIANGLE_STRIP , 0 , 4 ) ;
501
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
453
502
solid_color_program. disable_attribute_arrays ( ) ;
454
503
}
455
504
@@ -605,9 +654,12 @@ pub fn render_scene<T>(root_layer: Rc<Layer<T>>,
605
654
let v = scene. viewport . to_untyped ( ) ;
606
655
gl:: viewport ( v. origin . x as GLint , v. origin . y as GLint ,
607
656
v. size . width as GLsizei , v. size . height as GLsizei ) ;
657
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
608
658
609
659
gl:: clear_color ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
660
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
610
661
gl:: clear ( gl:: COLOR_BUFFER_BIT ) ;
662
+ unsafe { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; }
611
663
612
664
// Set up the initial modelview matrix.
613
665
let transform = identity ( ) . scale ( scene. scale . get ( ) , scene. scale . get ( ) , 1.0 ) ;
0 commit comments