@@ -143,10 +143,15 @@ struct ShaderProgram {
143
143
144
144
impl ShaderProgram {
145
145
pub fn new ( vertex_shader_source : & str , fragment_shader_source : & str ) -> ShaderProgram {
146
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
146
147
let id = gl:: create_program ( ) ;
148
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
147
149
gl:: attach_shader ( id, ShaderProgram :: compile_shader ( fragment_shader_source, gl:: FRAGMENT_SHADER ) ) ;
150
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
148
151
gl:: attach_shader ( id, ShaderProgram :: compile_shader ( vertex_shader_source, gl:: VERTEX_SHADER ) ) ;
152
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
149
153
gl:: link_program ( id) ;
154
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
150
155
if gl:: get_program_iv ( id, gl:: LINK_STATUS ) == ( 0 as GLint ) {
151
156
panic ! ( "Failed to compile shader program: {}" , gl:: get_program_info_log( id) ) ;
152
157
}
@@ -158,8 +163,11 @@ impl ShaderProgram {
158
163
159
164
pub fn compile_shader ( source_string : & str , shader_type : GLenum ) -> GLuint {
160
165
let id = gl:: create_shader ( shader_type) ;
166
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
161
167
gl:: shader_source ( id, & [ source_string. as_bytes ( ) ] ) ;
168
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
162
169
gl:: compile_shader ( id) ;
170
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
163
171
if gl:: get_shader_iv ( id, gl:: COMPILE_STATUS ) == ( 0 as GLint ) {
164
172
panic ! ( "Failed to compile shader: {}" , gl:: get_shader_info_log( id) ) ;
165
173
}
@@ -216,31 +224,43 @@ impl TextureProgram {
216
224
buffers : & Buffers ,
217
225
opacity : f32 ) {
218
226
gl:: uniform_1i ( self . sampler_uniform , 0 ) ;
227
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
219
228
gl:: uniform_matrix_4fv ( self . modelview_uniform , false , & transform. to_array ( ) ) ;
229
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
220
230
gl:: uniform_matrix_4fv ( self . projection_uniform , false , & projection_matrix. to_array ( ) ) ;
231
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
221
232
222
233
let vertex_size = mem:: size_of :: < TextureVertex > ( ) ;
223
234
224
235
gl:: bind_buffer ( gl:: ARRAY_BUFFER , buffers. quad_vertex_buffer ) ;
236
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
225
237
gl:: buffer_data ( gl:: ARRAY_BUFFER , vertices, gl:: DYNAMIC_DRAW ) ;
238
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
226
239
gl:: vertex_attrib_pointer_f32 ( self . vertex_position_attr as GLuint , 2 , false , vertex_size as i32 , 0 ) ;
240
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
227
241
gl:: vertex_attrib_pointer_f32 ( self . vertex_uv_attr as GLuint , 2 , false , vertex_size as i32 , 8 ) ;
242
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
228
243
229
244
gl:: uniform_matrix_4fv ( self . texture_space_transform_uniform ,
230
245
false ,
231
246
& texture_space_transform. to_array ( ) ) ;
247
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
232
248
233
249
gl:: uniform_1f ( self . opacity_uniform , opacity) ;
250
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
234
251
}
235
252
236
253
fn enable_attribute_arrays ( & self ) {
237
254
gl:: enable_vertex_attrib_array ( self . vertex_position_attr as GLuint ) ;
255
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
238
256
gl:: enable_vertex_attrib_array ( self . vertex_uv_attr as GLuint ) ;
257
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
239
258
}
240
259
241
260
fn disable_attribute_arrays ( & self ) {
242
261
gl:: disable_vertex_attrib_array ( self . vertex_uv_attr as GLuint ) ;
243
262
gl:: disable_vertex_attrib_array ( self . vertex_position_attr as GLuint ) ;
263
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
244
264
}
245
265
246
266
fn create_2d_program ( ) -> TextureProgram {
@@ -250,6 +270,7 @@ impl TextureProgram {
250
270
#[ cfg( target_os="macos" ) ]
251
271
fn create_rectangle_program_if_necessary ( ) -> Option < TextureProgram > {
252
272
gl:: enable ( gl:: TEXTURE_RECTANGLE_ARB ) ;
273
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
253
274
Some ( TextureProgram :: new ( "texture2DRect" , "sampler2DRect" ) )
254
275
}
255
276
@@ -286,12 +307,15 @@ impl SolidColorProgram {
286
307
projection_matrix : & Matrix4 ,
287
308
color : & Color ) {
288
309
gl:: uniform_matrix_4fv ( self . modelview_uniform , false , & transform. to_array ( ) ) ;
310
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
289
311
gl:: uniform_matrix_4fv ( self . projection_uniform , false , & projection_matrix. to_array ( ) ) ;
312
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
290
313
gl:: uniform_4f ( self . color_uniform ,
291
314
color. r as GLfloat ,
292
315
color. g as GLfloat ,
293
316
color. b as GLfloat ,
294
317
color. a as GLfloat ) ;
318
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
295
319
}
296
320
297
321
fn bind_uniforms_and_attributes_for_lines ( & self ,
@@ -303,8 +327,11 @@ impl SolidColorProgram {
303
327
self . bind_uniforms_and_attributes_common ( transform, projection_matrix, color) ;
304
328
305
329
gl:: bind_buffer ( gl:: ARRAY_BUFFER , buffers. line_quad_vertex_buffer ) ;
330
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
306
331
gl:: buffer_data ( gl:: ARRAY_BUFFER , vertices, gl:: DYNAMIC_DRAW ) ;
332
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
307
333
gl:: vertex_attrib_pointer_f32 ( self . vertex_position_attr as GLuint , 2 , false , 0 , 0 ) ;
334
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
308
335
}
309
336
310
337
fn bind_uniforms_and_attributes_for_quad ( & self ,
@@ -316,16 +343,21 @@ impl SolidColorProgram {
316
343
self . bind_uniforms_and_attributes_common ( transform, projection_matrix, color) ;
317
344
318
345
gl:: bind_buffer ( gl:: ARRAY_BUFFER , buffers. quad_vertex_buffer ) ;
346
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
319
347
gl:: buffer_data ( gl:: ARRAY_BUFFER , vertices, gl:: DYNAMIC_DRAW ) ;
348
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
320
349
gl:: vertex_attrib_pointer_f32 ( self . vertex_position_attr as GLuint , 2 , false , 0 , 0 ) ;
350
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
321
351
}
322
352
323
353
fn enable_attribute_arrays ( & self ) {
324
354
gl:: enable_vertex_attrib_array ( self . vertex_position_attr as GLuint ) ;
355
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
325
356
}
326
357
327
358
fn disable_attribute_arrays ( & self ) {
328
359
gl:: disable_vertex_attrib_array ( self . vertex_position_attr as GLuint ) ;
360
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
329
361
}
330
362
}
331
363
@@ -483,11 +515,15 @@ impl RenderContext {
483
515
pub fn new ( compositing_display : NativeDisplay ,
484
516
show_debug_borders : bool ,
485
517
force_near_texture_filter : bool ) -> RenderContext {
518
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
486
519
gl:: enable ( gl:: TEXTURE_2D ) ;
520
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
487
521
488
522
// Each layer uses premultiplied alpha!
489
523
gl:: enable ( gl:: BLEND ) ;
524
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
490
525
gl:: blend_func ( gl:: ONE , gl:: ONE_MINUS_SRC_ALPHA ) ;
526
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
491
527
492
528
let texture_2d_program = TextureProgram :: create_2d_program ( ) ;
493
529
let solid_color_program = SolidColorProgram :: new ( ) ;
@@ -506,10 +542,14 @@ impl RenderContext {
506
542
507
543
fn init_buffers ( ) -> Buffers {
508
544
let quad_vertex_buffer = gl:: gen_buffers ( 1 ) [ 0 ] ;
545
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
509
546
gl:: bind_buffer ( gl:: ARRAY_BUFFER , quad_vertex_buffer) ;
547
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
510
548
511
549
let line_quad_vertex_buffer = gl:: gen_buffers ( 1 ) [ 0 ] ;
550
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
512
551
gl:: bind_buffer ( gl:: ARRAY_BUFFER , line_quad_vertex_buffer) ;
552
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
513
553
514
554
Buffers {
515
555
quad_vertex_buffer : quad_vertex_buffer,
@@ -524,12 +564,14 @@ impl RenderContext {
524
564
color : & Color ) {
525
565
self . solid_color_program . enable_attribute_arrays ( ) ;
526
566
gl:: use_program ( self . solid_color_program . program . id ) ;
567
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
527
568
self . solid_color_program . bind_uniforms_and_attributes_for_quad ( vertices,
528
569
transform,
529
570
projection,
530
571
& self . buffers ,
531
572
color) ;
532
573
gl:: draw_arrays ( gl:: TRIANGLE_STRIP , 0 , 4 ) ;
574
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
533
575
self . solid_color_program . disable_attribute_arrays ( ) ;
534
576
}
535
577
@@ -553,16 +595,21 @@ impl RenderContext {
553
595
program. enable_attribute_arrays ( ) ;
554
596
555
597
gl:: use_program ( program. program . id ) ;
598
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
556
599
gl:: active_texture ( gl:: TEXTURE0 ) ;
600
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
557
601
gl:: bind_texture ( texture. target . as_gl_target ( ) , texture. native_texture ( ) ) ;
602
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
558
603
559
604
let filter_mode = if self . force_near_texture_filter {
560
605
gl:: NEAREST
561
606
} else {
562
607
gl:: LINEAR
563
608
} as GLint ;
564
609
gl:: tex_parameter_i ( texture. target . as_gl_target ( ) , gl:: TEXTURE_MAG_FILTER , filter_mode) ;
610
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
565
611
gl:: tex_parameter_i ( texture. target . as_gl_target ( ) , gl:: TEXTURE_MIN_FILTER , filter_mode) ;
612
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
566
613
567
614
// We calculate a transformation matrix for the texture coordinates
568
615
// which is useful for flipping the texture vertically or scaling the
@@ -589,9 +636,12 @@ impl RenderContext {
589
636
590
637
// Draw!
591
638
gl:: draw_arrays ( gl:: TRIANGLE_STRIP , 0 , 4 ) ;
639
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
592
640
gl:: bind_texture ( gl:: TEXTURE_2D , 0 ) ;
641
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
593
642
594
643
gl:: bind_texture ( texture. target . as_gl_target ( ) , 0 ) ;
644
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
595
645
program. disable_attribute_arrays ( )
596
646
}
597
647
@@ -609,7 +659,9 @@ impl RenderContext {
609
659
& self . buffers ,
610
660
color) ;
611
661
gl:: line_width ( line_thickness as GLfloat ) ;
662
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
612
663
gl:: draw_arrays ( gl:: LINE_STRIP , 0 , 5 ) ;
664
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
613
665
self . solid_color_program . disable_attribute_arrays ( ) ;
614
666
}
615
667
@@ -819,14 +871,19 @@ pub fn render_scene<T>(root_layer: Rc<Layer<T>>,
819
871
let v = scene. viewport . to_untyped ( ) ;
820
872
gl:: viewport ( v. origin . x as GLint , v. origin . y as GLint ,
821
873
v. size . width as GLsizei , v. size . height as GLsizei ) ;
874
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
822
875
823
876
// Enable depth testing for 3d transforms. Set z-mode to LESS-EQUAL
824
877
// so that layers with equal Z are able to paint correctly in
825
878
// the order they are specified.
826
879
gl:: enable ( gl:: DEPTH_TEST ) ;
880
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
827
881
gl:: clear_color ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
882
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
828
883
gl:: clear ( gl:: COLOR_BUFFER_BIT | gl:: DEPTH_BUFFER_BIT ) ;
884
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
829
885
gl:: depth_func ( gl:: LEQUAL ) ;
886
+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
830
887
831
888
// Set up the initial modelview matrix.
832
889
let transform = Matrix4 :: identity ( ) . scale ( scene. scale . get ( ) , scene. scale . get ( ) , 1.0 ) ;
0 commit comments