text
stringlengths
12
786k
let _ = field surface_struct " map " ( ptr void )
let _ = field surface_struct " refcount " int
let ( ) = seal surface_struct
type surface = surface_struct ptr
let surface : surface typ = ptr surface_struct
let surface_opt : surface option typ = ptr_opt surface_struct
let unsafe_surface_of_ptr addr : surface = from_voidp surface_struct ( ptr_of_raw_address addr )
let unsafe_ptr_of_surface surface = raw_address_of_ptr ( to_voidp surface )
let blit_scaled = foreign " SDL_UpperBlitScaled " ( surface @-> ptr rect @-> surface @-> ptr rect @-> returning zero_to_ok )
let blit_scaled ~ src sr ~ dst dr = blit_scaled src ( Rect . opt_addr sr ) dst ( Rect . opt_addr dr )
let blit_surface = foreign " SDL_UpperBlit " ( surface @-> ptr rect @-> surface @-> ptr rect @-> returning zero_to_ok )
let blit_surface ~ src sr ~ dst dr = blit_surface src ( Rect . opt_addr sr ) dst ( Rect . opt_addr dr )
let convert_pixels = foreign " SDL_ConvertPixels " ( int @-> int @-> uint32_t @-> ptr void @-> int @-> uint32_t @-> ptr void @-> int @-> returning zero_to_ok )
let convert_pixels ~ w ~ h ~ src sp spitch ~ dst dp dpitch = let spitch = ba_kind_byte_size ( Bigarray . Array1 . kind sp ) * spitch in let dpitch = ba_kind_byte_size ( Bigarray . Array1 . kind dp ) * dpitch in let sp = to_voidp ( bigarray_start array1 sp ) in let dp = to_voidp ( bigarray_start array1 dp ) in convert_pixels w h src sp spitch dst dp dpitch
let convert_surface = foreign " SDL_ConvertSurface " ( surface @-> pixel_format @-> uint32_t @-> returning ( some_to_ok surface_opt ) )
let convert_surface s pf = convert_surface s pf Unsigned . UInt32 . zero
let convert_surface_format = foreign " SDL_ConvertSurfaceFormat " ( surface @-> uint32_t @-> uint32_t @-> returning ( some_to_ok surface_opt ) )
let convert_surface_format s pf = convert_surface_format s pf Unsigned . UInt32 . zero
let create_rgb_surface = foreign " SDL_CreateRGBSurface " ( uint32_t @-> int @-> int @-> int @-> int32_as_uint32_t @-> int32_as_uint32_t @-> int32_as_uint32_t @-> int32_as_uint32_t @-> returning ( some_to_ok surface_opt ) )
let create_rgb_surface ~ w ~ h ~ depth rmask gmask bmask amask = create_rgb_surface Unsigned . UInt32 . zero w h depth rmask gmask bmask amask
let create_rgb_surface_from = foreign " SDL_CreateRGBSurfaceFrom " ( ptr void @-> int @-> int @-> int @-> int @-> int32_as_uint32_t @-> int32_as_uint32_t @-> int32_as_uint32_t @-> int32_as_uint32_t @-> returning ( some_to_ok surface_opt ) )
let create_rgb_surface_from p ~ w ~ h ~ depth ~ pitch rmask gmask bmask amask = let pitch = ba_kind_byte_size ( Bigarray . Array1 . kind p ) * pitch in let p = to_voidp ( bigarray_start array1 p ) in create_rgb_surface_from p w h depth pitch rmask gmask bmask amask
let create_rgb_surface_with_format = foreign " SDL_CreateRGBSurfaceWithFormat " ( uint32_t @-> int @-> int @-> int @-> uint32_t @-> returning ( some_to_ok surface_opt ) )
let create_rgb_surface_with_format ~ w ~ h ~ depth format = create_rgb_surface_with_format Unsigned . UInt32 . zero w h depth format
let create_rgb_surface_with_format_from = foreign " SDL_CreateRGBSurfaceWithFormatFrom " ( ptr void @-> int @-> int @-> int @-> int @-> uint32_t @-> returning ( some_to_ok surface_opt ) )
let create_rgb_surface_with_format_from p ~ w ~ h ~ depth ~ pitch format = let pitch = ba_kind_byte_size ( Bigarray . Array1 . kind p ) * pitch in let p = to_voidp ( bigarray_start array1 p ) in create_rgb_surface_with_format_from p w h depth pitch format
let duplicate_surface = foreign " SDL_DuplicateSurface " ( surface @-> returning surface )
let fill_rect = foreign " SDL_FillRect " ( surface @-> ptr rect @-> int32_as_uint32_t @-> returning zero_to_ok )
let fill_rect s r c = fill_rect s ( Rect . opt_addr r ) c
let fill_rects = foreign " SDL_FillRects " ( surface @-> ptr void @-> int @-> int32_as_uint32_t @-> returning zero_to_ok )
let fill_rects_ba s rs col = let len = Bigarray . Array1 . dim rs in if len mod 4 <> 0 then invalid_arg ( err_length_mul len 4 ) else let count = len / 4 in let rs = to_voidp ( bigarray_start array1 rs ) in fill_rects s rs count col
let fill_rects s rs col = let count = List . length rs in let a = CArray . of_list rect rs in fill_rects s ( to_voidp ( CArray . start a ) ) count col
let free_surface = foreign " SDL_FreeSurface " ( surface @-> returning void )
let get_clip_rect = foreign " SDL_GetClipRect " ( surface @-> ptr rect @-> returning void )
let get_clip_rect s = let r = make rect in ( get_clip_rect s ( addr r ) ; r )
let get_color_key = foreign " SDL_GetColorKey " ( surface @-> ptr uint32_t @-> returning zero_to_ok )
let get_color_key s = let key = allocate uint32_t Unsigned . UInt32 . zero in match get_color_key s key with | Ok ( ) -> Ok ( Unsigned . UInt32 . to_int32 ( !@ key ) ) | Error _ as e -> e
let get_surface_alpha_mod = foreign " SDL_GetSurfaceAlphaMod " ( surface @-> ptr uint8_t @-> returning zero_to_ok )
let get_surface_alpha_mod s = let alpha = allocate uint8_t Unsigned . UInt8 . zero in match get_surface_alpha_mod s alpha with | Ok ( ) -> Ok ( Unsigned . UInt8 . to_int ( !@ alpha ) ) | Error _ as e -> e
let get_surface_blend_mode = foreign " SDL_GetSurfaceBlendMode " ( surface @-> ptr int @-> returning zero_to_ok )
let get_surface_blend_mode s = let mode = allocate int 0 in match get_surface_blend_mode s mode with Ok ( ) -> Ok ( !@ mode ) | Error _ as e -> e
let get_surface_color_mod = foreign " SDL_GetSurfaceColorMod " ( surface @-> ptr uint8_t @-> ptr uint8_t @-> ptr uint8_t @-> returning zero_to_ok )
let get_surface_color_mod s = let alloc ( ) = allocate uint8_t Unsigned . UInt8 . zero in let get v = Unsigned . UInt8 . to_int ( !@ v ) in let r , g , b = alloc ( ) , alloc ( ) , alloc ( ) in match get_surface_color_mod s r g b with | Ok ( ) -> Ok ( get r , get g , get b ) | Error _ as e -> e
let get_surface_format_enum s = get_pixel_format_format ( getf ( !@ s ) surface_format )
let get_surface_pitch s = getf ( !@ s ) surface_pitch
let get_surface_pixels s kind = let pitch = get_surface_pitch s in let kind_size = ba_kind_byte_size kind in if pitch mod kind_size <> 0 then invalid_arg ( err_bigarray_pitch pitch kind_size ) else let h = getf ( !@ s ) surface_h in let ba_size = ( pitch * h ) / kind_size in let pixels = getf ( !@ s ) surface_pixels in let pixels = coerce ( ptr void ) ( access_ptr_typ_of_ba_kind kind ) pixels in bigarray_of_ptr array1 ba_size kind pixels
let get_surface_size s = getf ( !@ s ) surface_w , getf ( !@ s ) surface_h
let load_bmp_rw = foreign " SDL_LoadBMP_RW " ( rw_ops @-> bool @-> returning ( some_to_ok surface_opt ) )
let load_bmp_rw rw ~ close = load_bmp_rw rw close
let load_bmp file = match rw_from_file file " rb " with | Error _ as e -> e | Ok rw -> load_bmp_rw rw ~ close : true
let lock_surface = foreign " SDL_LockSurface " ( surface @-> returning zero_to_ok )
let lower_blit = foreign " SDL_LowerBlit " ( surface @-> ptr rect @-> surface @-> ptr rect @-> returning zero_to_ok )
let lower_blit ~ src sr ~ dst dr = lower_blit src ( addr sr ) dst ( addr dr )
let lower_blit_scaled = foreign " SDL_LowerBlitScaled " ( surface @-> ptr rect @-> surface @-> ptr rect @-> returning zero_to_ok )
let lower_blit_scaled ~ src sr ~ dst dr = lower_blit_scaled src ( addr sr ) dst ( addr dr )
let save_bmp_rw = foreign " SDL_SaveBMP_RW " ( surface @-> rw_ops @-> bool @-> returning zero_to_ok )
let save_bmp_rw s rw ~ close = save_bmp_rw s rw close
let save_bmp s file = match rw_from_file file " wb " with | Error _ as e -> e | Ok rw -> save_bmp_rw s rw ~ close : true
let set_clip_rect = foreign " SDL_SetClipRect " ( surface @-> ptr rect @-> returning bool )
let set_clip_rect s r = set_clip_rect s ( addr r )
let set_color_key = foreign " SDL_SetColorKey " ( surface @-> bool @-> int32_as_uint32_t @-> returning zero_to_ok )
let set_surface_alpha_mod = foreign " SDL_SetSurfaceAlphaMod " ( surface @-> int_as_uint8_t @-> returning zero_to_ok )
let set_surface_blend_mode = foreign " SDL_SetSurfaceBlendMode " ( surface @-> int @-> returning zero_to_ok )
let set_surface_color_mod = foreign " SDL_SetSurfaceColorMod " ( surface @-> int_as_uint8_t @-> int_as_uint8_t @-> int_as_uint8_t @-> returning zero_to_ok )
let set_surface_palette = foreign " SDL_SetSurfacePalette " ( surface @-> palette @-> returning zero_to_ok )
let set_surface_rle = foreign " SDL_SetSurfaceRLE " ( surface @-> bool @-> returning zero_to_ok )
let unlock_surface = foreign " SDL_UnlockSurface " ( surface @-> returning void )
module Flip = struct let ( + ) = ( lor ) let none = sdl_flip_none let horizontal = sdl_flip_horizontal let vertical = sdl_flip_vertical end
type texture = unit ptr
let texture : texture typ = ptr void
let texture_opt : texture option typ = ptr_opt void
let unsafe_texture_of_ptr addr : texture = ptr_of_raw_address addr
let unsafe_ptr_of_texture texture = raw_address_of_ptr ( to_voidp texture )
type renderer = unit ptr
let renderer : renderer typ = ptr void
let renderer_opt : renderer option typ = ptr_opt void
let unsafe_renderer_of_ptr addr : renderer = ptr_of_raw_address addr
let unsafe_ptr_of_renderer renderer = raw_address_of_ptr ( to_voidp renderer )
module Renderer = struct type flags = Unsigned . uint32 let i = Unsigned . UInt32 . of_int let ( + ) = Unsigned . UInt32 . logor let test f m = Unsigned . UInt32 . ( compare ( logand f m ) zero <> 0 ) let eq f f ' = Unsigned . UInt32 . ( compare f f ' = 0 ) let none = Unsigned . UInt32 . zero let software = i sdl_renderer_software let accelerated = i sdl_renderer_accelerated let presentvsync = i sdl_renderer_presentvsync let targettexture = i sdl_renderer_targettexture end
type renderer_info = { ri_name : string ; ri_flags : Renderer . flags ; ri_texture_formats : Pixel . format_enum list ; ri_max_texture_width : int ; ri_max_texture_height : int ; }
let renderer_info = structure " SDL_RendererInfo "
let ri_name = field renderer_info " name " string
let ri_flags = field renderer_info " flags " uint32_t
let ri_num_tf = field renderer_info " num_texture_formats " uint32_t
let ri_tfs = field renderer_info " texture_formats " ( array 16 uint32_t )
let ri_max_texture_width = field renderer_info " max_texture_width " int
let ri_max_texture_height = field renderer_info " max_texture_height " int
let ( ) = seal renderer_info
let renderer_info_of_c c = let ri_name = getf c ri_name in let ri_flags = getf c ri_flags in let num_tf = Unsigned . UInt32 . to_int ( getf c ri_num_tf ) in let tfs = getf c ri_tfs in let ri_texture_formats = let acc = ref [ ] in for i = 0 to num_tf - 1 do acc := ( CArray . get tfs i ) :: ! acc done ; List . rev ! acc in let ri_max_texture_width = getf c ri_max_texture_width in let ri_max_texture_height = getf c ri_max_texture_height in { ri_name ; ri_flags ; ri_texture_formats ; ri_max_texture_width ; ri_max_texture_height }
let create_renderer = foreign " SDL_CreateRenderer " ( window @-> int @-> uint32_t @-> returning ( some_to_ok renderer_opt ) )
let create_renderer ( ? index = - 1 ) ( ? flags = Unsigned . UInt32 . zero ) w = create_renderer w index flags
let create_software_renderer = foreign " SDL_CreateSoftwareRenderer " ( surface @-> returning ( some_to_ok renderer_opt ) )
let destroy_renderer = foreign " SDL_DestroyRenderer " ( renderer @-> returning void )
let get_num_render_drivers = foreign " SDL_GetNumRenderDrivers " ( void @-> returning nat_to_ok )
let get_render_draw_blend_mode = foreign " SDL_GetRenderDrawBlendMode " ( renderer @-> ptr int @-> returning zero_to_ok )
let get_render_draw_blend_mode r = let m = allocate int 0 in match get_render_draw_blend_mode r m with | Ok ( ) -> Ok !@ m | Error _ as e -> e
let get_render_draw_color = foreign " SDL_GetRenderDrawColor " ( renderer @-> ptr uint8_t @-> ptr uint8_t @-> ptr uint8_t @-> ptr uint8_t @-> returning zero_to_ok )
let get_render_draw_color rend = let alloc ( ) = allocate uint8_t Unsigned . UInt8 . zero in let get v = Unsigned . UInt8 . to_int ( !@ v ) in let r , g , b , a = alloc ( ) , alloc ( ) , alloc ( ) , alloc ( ) in match get_render_draw_color rend r g b a with | Ok ( ) -> Ok ( get r , get g , get b , get a ) | Error _ as e -> e
let get_render_driver_info = foreign " SDL_GetRenderDriverInfo " ( int @-> ptr renderer_info @-> returning zero_to_ok )
let get_render_driver_info i = let info = make renderer_info in match get_render_driver_info i ( addr info ) with | Ok ( ) -> Ok ( renderer_info_of_c info ) | Error _ as e -> e