@@ -143,10 +143,15 @@ struct ShaderProgram {
143143
144144impl ShaderProgram {
145145 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 ) ; } }
146147 let id = gl:: create_program ( ) ;
148+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
147149 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 ) ; } }
148151 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 ) ; } }
149153 gl:: link_program ( id) ;
154+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
150155 if gl:: get_program_iv ( id, gl:: LINK_STATUS ) == ( 0 as GLint ) {
151156 panic ! ( "Failed to compile shader program: {}" , gl:: get_program_info_log( id) ) ;
152157 }
@@ -158,8 +163,11 @@ impl ShaderProgram {
158163
159164 pub fn compile_shader ( source_string : & str , shader_type : GLenum ) -> GLuint {
160165 let id = gl:: create_shader ( shader_type) ;
166+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
161167 gl:: shader_source ( id, & [ source_string. as_bytes ( ) ] ) ;
168+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
162169 gl:: compile_shader ( id) ;
170+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
163171 if gl:: get_shader_iv ( id, gl:: COMPILE_STATUS ) == ( 0 as GLint ) {
164172 panic ! ( "Failed to compile shader: {}" , gl:: get_shader_info_log( id) ) ;
165173 }
@@ -216,31 +224,43 @@ impl TextureProgram {
216224 buffers : & Buffers ,
217225 opacity : f32 ) {
218226 gl:: uniform_1i ( self . sampler_uniform , 0 ) ;
227+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
219228 gl:: uniform_matrix_4fv ( self . modelview_uniform , false , & transform. to_array ( ) ) ;
229+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
220230 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 ) ; } }
221232
222233 let vertex_size = mem:: size_of :: < TextureVertex > ( ) ;
223234
224235 gl:: bind_buffer ( gl:: ARRAY_BUFFER , buffers. quad_vertex_buffer ) ;
236+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
225237 gl:: buffer_data ( gl:: ARRAY_BUFFER , vertices, gl:: DYNAMIC_DRAW ) ;
238+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
226239 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 ) ; } }
227241 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 ) ; } }
228243
229244 gl:: uniform_matrix_4fv ( self . texture_space_transform_uniform ,
230245 false ,
231246 & texture_space_transform. to_array ( ) ) ;
247+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
232248
233249 gl:: uniform_1f ( self . opacity_uniform , opacity) ;
250+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
234251 }
235252
236253 fn enable_attribute_arrays ( & self ) {
237254 gl:: enable_vertex_attrib_array ( self . vertex_position_attr as GLuint ) ;
255+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
238256 gl:: enable_vertex_attrib_array ( self . vertex_uv_attr as GLuint ) ;
257+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
239258 }
240259
241260 fn disable_attribute_arrays ( & self ) {
242261 gl:: disable_vertex_attrib_array ( self . vertex_uv_attr as GLuint ) ;
243262 gl:: disable_vertex_attrib_array ( self . vertex_position_attr as GLuint ) ;
263+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
244264 }
245265
246266 fn create_2d_program ( ) -> TextureProgram {
@@ -250,6 +270,7 @@ impl TextureProgram {
250270 #[ cfg( target_os="macos" ) ]
251271 fn create_rectangle_program_if_necessary ( ) -> Option < TextureProgram > {
252272 gl:: enable ( gl:: TEXTURE_RECTANGLE_ARB ) ;
273+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
253274 Some ( TextureProgram :: new ( "texture2DRect" , "sampler2DRect" ) )
254275 }
255276
@@ -286,12 +307,15 @@ impl SolidColorProgram {
286307 projection_matrix : & Matrix4 ,
287308 color : & Color ) {
288309 gl:: uniform_matrix_4fv ( self . modelview_uniform , false , & transform. to_array ( ) ) ;
310+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
289311 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 ) ; } }
290313 gl:: uniform_4f ( self . color_uniform ,
291314 color. r as GLfloat ,
292315 color. g as GLfloat ,
293316 color. b as GLfloat ,
294317 color. a as GLfloat ) ;
318+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
295319 }
296320
297321 fn bind_uniforms_and_attributes_for_lines ( & self ,
@@ -303,8 +327,11 @@ impl SolidColorProgram {
303327 self . bind_uniforms_and_attributes_common ( transform, projection_matrix, color) ;
304328
305329 gl:: bind_buffer ( gl:: ARRAY_BUFFER , buffers. line_quad_vertex_buffer ) ;
330+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
306331 gl:: buffer_data ( gl:: ARRAY_BUFFER , vertices, gl:: DYNAMIC_DRAW ) ;
332+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
307333 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 ) ; } }
308335 }
309336
310337 fn bind_uniforms_and_attributes_for_quad ( & self ,
@@ -316,16 +343,21 @@ impl SolidColorProgram {
316343 self . bind_uniforms_and_attributes_common ( transform, projection_matrix, color) ;
317344
318345 gl:: bind_buffer ( gl:: ARRAY_BUFFER , buffers. quad_vertex_buffer ) ;
346+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
319347 gl:: buffer_data ( gl:: ARRAY_BUFFER , vertices, gl:: DYNAMIC_DRAW ) ;
348+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
320349 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 ) ; } }
321351 }
322352
323353 fn enable_attribute_arrays ( & self ) {
324354 gl:: enable_vertex_attrib_array ( self . vertex_position_attr as GLuint ) ;
355+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
325356 }
326357
327358 fn disable_attribute_arrays ( & self ) {
328359 gl:: disable_vertex_attrib_array ( self . vertex_position_attr as GLuint ) ;
360+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
329361 }
330362}
331363
@@ -483,11 +515,15 @@ impl RenderContext {
483515 pub fn new ( compositing_display : NativeDisplay ,
484516 show_debug_borders : bool ,
485517 force_near_texture_filter : bool ) -> RenderContext {
518+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
486519 gl:: enable ( gl:: TEXTURE_2D ) ;
520+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
487521
488522 // Each layer uses premultiplied alpha!
489523 gl:: enable ( gl:: BLEND ) ;
524+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
490525 gl:: blend_func ( gl:: ONE , gl:: ONE_MINUS_SRC_ALPHA ) ;
526+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
491527
492528 let texture_2d_program = TextureProgram :: create_2d_program ( ) ;
493529 let solid_color_program = SolidColorProgram :: new ( ) ;
@@ -506,10 +542,14 @@ impl RenderContext {
506542
507543 fn init_buffers ( ) -> Buffers {
508544 let quad_vertex_buffer = gl:: gen_buffers ( 1 ) [ 0 ] ;
545+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
509546 gl:: bind_buffer ( gl:: ARRAY_BUFFER , quad_vertex_buffer) ;
547+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
510548
511549 let line_quad_vertex_buffer = gl:: gen_buffers ( 1 ) [ 0 ] ;
550+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
512551 gl:: bind_buffer ( gl:: ARRAY_BUFFER , line_quad_vertex_buffer) ;
552+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
513553
514554 Buffers {
515555 quad_vertex_buffer : quad_vertex_buffer,
@@ -524,12 +564,14 @@ impl RenderContext {
524564 color : & Color ) {
525565 self . solid_color_program . enable_attribute_arrays ( ) ;
526566 gl:: use_program ( self . solid_color_program . program . id ) ;
567+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
527568 self . solid_color_program . bind_uniforms_and_attributes_for_quad ( vertices,
528569 transform,
529570 projection,
530571 & self . buffers ,
531572 color) ;
532573 gl:: draw_arrays ( gl:: TRIANGLE_STRIP , 0 , 4 ) ;
574+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
533575 self . solid_color_program . disable_attribute_arrays ( ) ;
534576 }
535577
@@ -553,16 +595,21 @@ impl RenderContext {
553595 program. enable_attribute_arrays ( ) ;
554596
555597 gl:: use_program ( program. program . id ) ;
598+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
556599 gl:: active_texture ( gl:: TEXTURE0 ) ;
600+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
557601 gl:: bind_texture ( texture. target . as_gl_target ( ) , texture. native_texture ( ) ) ;
602+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
558603
559604 let filter_mode = if self . force_near_texture_filter {
560605 gl:: NEAREST
561606 } else {
562607 gl:: LINEAR
563608 } as GLint ;
564609 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 ) ; } }
565611 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 ) ; } }
566613
567614 // We calculate a transformation matrix for the texture coordinates
568615 // which is useful for flipping the texture vertically or scaling the
@@ -589,9 +636,12 @@ impl RenderContext {
589636
590637 // Draw!
591638 gl:: draw_arrays ( gl:: TRIANGLE_STRIP , 0 , 4 ) ;
639+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
592640 gl:: bind_texture ( gl:: TEXTURE_2D , 0 ) ;
641+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
593642
594643 gl:: bind_texture ( texture. target . as_gl_target ( ) , 0 ) ;
644+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
595645 program. disable_attribute_arrays ( )
596646 }
597647
@@ -609,7 +659,9 @@ impl RenderContext {
609659 & self . buffers ,
610660 color) ;
611661 gl:: line_width ( line_thickness as GLfloat ) ;
662+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
612663 gl:: draw_arrays ( gl:: LINE_STRIP , 0 , 5 ) ;
664+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
613665 self . solid_color_program . disable_attribute_arrays ( ) ;
614666 }
615667
@@ -819,14 +871,19 @@ pub fn render_scene<T>(root_layer: Rc<Layer<T>>,
819871 let v = scene. viewport . to_untyped ( ) ;
820872 gl:: viewport ( v. origin . x as GLint , v. origin . y as GLint ,
821873 v. size . width as GLsizei , v. size . height as GLsizei ) ;
874+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
822875
823876 // Enable depth testing for 3d transforms. Set z-mode to LESS-EQUAL
824877 // so that layers with equal Z are able to paint correctly in
825878 // the order they are specified.
826879 gl:: enable ( gl:: DEPTH_TEST ) ;
880+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
827881 gl:: clear_color ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
882+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
828883 gl:: clear ( gl:: COLOR_BUFFER_BIT | gl:: DEPTH_BUFFER_BIT ) ;
884+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
829885 gl:: depth_func ( gl:: LEQUAL ) ;
886+ unsafe { if cfg ! ( feature = "gldebug" ) { assert_eq ! ( gl:: GetError ( ) , gl:: NO_ERROR ) ; } }
830887
831888 // Set up the initial modelview matrix.
832889 let transform = Matrix4 :: identity ( ) . scale ( scene. scale . get ( ) , scene. scale . get ( ) , 1.0 ) ;
0 commit comments