gamnit :: GamnitDisplay :: aspect_ratio
Aspect ratio of the screen,width / height
			gamnit :: GamnitDisplay :: aspect_ratio=
gamnit :: GamnitDisplay :: blue_bits
Number of bits used for the blue value in the color buffergamnit :: GamnitDisplay :: check_egl_context
Check if the current configuration ofnative_window is still valid
			gamnit :: GamnitDisplay :: defaultinit
gamnit :: GamnitDisplay :: egl_config=
The selected EGL configurationgamnit :: GamnitDisplay :: egl_context=
The EGL contextgamnit :: GamnitDisplay :: egl_display=
The EGL displaygamnit :: GamnitDisplay :: feed_events
Loop on available events and feed them back to the appgamnit :: GamnitDisplay :: gl_extensions
Extensions to OpenGL ES 2.0 supported by the current configurationgamnit :: GamnitDisplay :: gl_extensions=
Extensions to OpenGL ES 2.0 supported by the current configurationgamnit :: GamnitDisplay :: glk_view
Underlying GLKit game controller and viewgamnit :: GamnitDisplay :: glk_view=
Underlying GLKit game controller and viewgamnit :: GamnitDisplay :: green_bits
Number of bits used for the green value in the color buffergamnit :: GamnitDisplay :: height=
Actual height or desired height of the window, can be set before callingsetup
			gamnit :: GamnitDisplay :: height=
gamnit :: GamnitDisplay :: height=
gamnit :: GamnitDisplay :: lock_cursor
Is the cursor locked et the center of the screen?gamnit :: GamnitDisplay :: lock_cursor=
Is the cursor locked et the center of the screen?gamnit :: GamnitDisplay :: mix_init_flags
SDL2 mixer initialization flagsgamnit :: GamnitDisplay :: mix_init_flags=
SDL2 mixer initialization flagsgamnit :: GamnitDisplay :: native_window_is_invalid
Return value fromcheck_egl_context, the current native window is invalid
			gamnit :: GamnitDisplay :: native_window_is_invalid=
Return value fromcheck_egl_context, the current native window is invalid
			gamnit :: GamnitDisplay :: red_bits
Number of bits used for the red value in the color buffergamnit :: GamnitDisplay :: sdl_window
The SDL display managing the window and eventsgamnit :: GamnitDisplay :: sdl_window=
The SDL display managing the window and eventsgamnit :: GamnitDisplay :: sdl_window_flags
SDL2 window initialization flagsgamnit :: GamnitDisplay :: sdl_window_flags=
SDL2 window initialization flagsgamnit :: GamnitDisplay :: select_egl_config
Select an EGL configgamnit :: GamnitDisplay :: setup_egl_context
Setup the EGL context for the givennative_window
			gamnit :: GamnitDisplay :: setup_egl_display
Setup the EGL display for the givennative_display
			gamnit :: GamnitDisplay :: width=
gamnit :: GamnitDisplay :: width=
Actual width or desired width of the window, can be set before callingsetup
			gamnit :: GamnitDisplay :: width=
gamnit :: GamnitDisplay :: window_surface
The EGL surface for the windowgamnit :: GamnitDisplay :: window_surface=
The EGL surface for the windowgamnit :: GamnitDisplay :: window_title
Title of the window, must be set before creating the window (or redef)gamnit :: GamnitDisplay :: window_title=
Title of the window, must be set before creating the window (or redef)gamnit $ GamnitDisplay :: SELF
Type of this instance, automatically specialized in every classgamnit :: stereoscopic_view $ GamnitDisplay :: aspect_ratio
With stereoscopic view, the aspect ratio (in each eye) is half of the screengamnit :: gamnit_linux $ GamnitDisplay :: aspect_ratio
Aspect ratio of the screen,width / height
			gamnit :: display_linux $ GamnitDisplay :: close
Close EGL and SDL in reverse order ofsetup (nothing to do for X11)
			gamnit :: display_android $ GamnitDisplay :: close
Close this display and free underlying resourcesgamnit :: display_ios $ GamnitDisplay :: height
Height of the display, in pixelsgamnit :: gamnit_android $ GamnitDisplay :: height
Height of the display, in pixelsgamnit :: display_linux $ GamnitDisplay :: lock_cursor
Is the cursor locked et the center of the screen?gamnit :: display_linux $ GamnitDisplay :: lock_cursor=
Is the cursor locked et the center of the screen?gamnit :: display_linux $ GamnitDisplay :: show_cursor
Is the cursor visible?gamnit :: display_linux $ GamnitDisplay :: show_cursor=
Is the cursor visible?gamnit :: gamnit_android $ GamnitDisplay :: width
Width of the display, in pixelsgamnit :: GamnitDisplay :: aspect_ratio
Aspect ratio of the screen,width / height
			gamnit :: GamnitDisplay :: aspect_ratio=
gamnit :: GamnitDisplay :: blue_bits
Number of bits used for the blue value in the color buffergamnit :: GamnitDisplay :: check_egl_context
Check if the current configuration ofnative_window is still valid
			core :: Object :: class_factory
Implementation used byget_class to create the specific class.
			core :: Object :: defaultinit
gamnit :: GamnitDisplay :: defaultinit
gamnit :: GamnitDisplay :: egl_config=
The selected EGL configurationgamnit :: GamnitDisplay :: egl_context=
The EGL contextgamnit :: GamnitDisplay :: egl_display=
The EGL displaygamnit :: GamnitDisplay :: feed_events
Loop on available events and feed them back to the appgamnit :: GamnitDisplay :: gl_extensions
Extensions to OpenGL ES 2.0 supported by the current configurationgamnit :: GamnitDisplay :: gl_extensions=
Extensions to OpenGL ES 2.0 supported by the current configurationgamnit :: GamnitDisplay :: glk_view
Underlying GLKit game controller and viewgamnit :: GamnitDisplay :: glk_view=
Underlying GLKit game controller and viewgamnit :: GamnitDisplay :: green_bits
Number of bits used for the green value in the color buffergamnit :: GamnitDisplay :: height=
gamnit :: GamnitDisplay :: height=
Actual height or desired height of the window, can be set before callingsetup
			gamnit :: GamnitDisplay :: height=
core :: Object :: is_same_instance
Return true ifself and other are the same instance (i.e. same identity).
			core :: Object :: is_same_serialized
Isself the same as other in a serialization context?
			core :: Object :: is_same_type
Return true ifself and other have the same dynamic type.
			gamnit :: GamnitDisplay :: lock_cursor
Is the cursor locked et the center of the screen?gamnit :: GamnitDisplay :: lock_cursor=
Is the cursor locked et the center of the screen?gamnit :: GamnitDisplay :: mix_init_flags
SDL2 mixer initialization flagsgamnit :: GamnitDisplay :: mix_init_flags=
SDL2 mixer initialization flagsgamnit :: GamnitDisplay :: native_window_is_invalid
Return value fromcheck_egl_context, the current native window is invalid
			gamnit :: GamnitDisplay :: native_window_is_invalid=
Return value fromcheck_egl_context, the current native window is invalid
			core :: Object :: output_class_name
Display class name on stdout (debug only).gamnit :: GamnitDisplay :: red_bits
Number of bits used for the red value in the color buffergamnit :: GamnitDisplay :: sdl_window
The SDL display managing the window and eventsgamnit :: GamnitDisplay :: sdl_window=
The SDL display managing the window and eventsgamnit :: GamnitDisplay :: sdl_window_flags
SDL2 window initialization flagsgamnit :: GamnitDisplay :: sdl_window_flags=
SDL2 window initialization flagsgamnit :: GamnitDisplay :: select_egl_config
Select an EGL configgamnit :: GamnitDisplay :: setup_egl_context
Setup the EGL context for the givennative_window
			gamnit :: GamnitDisplay :: setup_egl_display
Setup the EGL display for the givennative_display
			gamnit :: GamnitDisplay :: width=
gamnit :: GamnitDisplay :: width=
gamnit :: GamnitDisplay :: width=
Actual width or desired width of the window, can be set before callingsetup
			gamnit :: GamnitDisplay :: window_surface
The EGL surface for the windowgamnit :: GamnitDisplay :: window_surface=
The EGL surface for the windowgamnit :: GamnitDisplay :: window_title
Title of the window, must be set before creating the window (or redef)gamnit :: GamnitDisplay :: window_title=
Title of the window, must be set before creating the window (or redef)
# General display class, is sized and drawable
class GamnitDisplay
	# Width of the display, in pixels
	fun width: Int is abstract
	# Height of the display, in pixels
	fun height: Int is abstract
	# Aspect ratio of the screen, `width / height`
	fun aspect_ratio: Float do return width.to_f / height.to_f
	# Is the cursor locked et the center of the screen?
	var lock_cursor = false is writable
	# Is the cursor visible?
	#
	# Only affects the desktop implementations.
	var show_cursor: Bool = true is writable
	# Number of bits used for the red value in the color buffer
	fun red_bits: Int do return 8
	# Number of bits used for the green value in the color buffer
	fun green_bits: Int do return 8
	# Number of bits used for the blue value in the color buffer
	fun blue_bits: Int do return 8
	# Prepare this display
	#
	# The implementation varies per platform.
	fun setup is abstract
	# Close this display and free underlying resources
	#
	# The implementation varies per platform.
	fun close do end
	# Flip the display buffers
	#
	# The implementation varies per platform.
	fun flip do end
	# Loop on available events and feed them back to the app
	#
	# The implementation varies per platform.
	fun feed_events do end
	# Extensions to OpenGL ES 2.0 supported by the current configuration
	var gl_extensions: Array[String] is lazy do return glGetString(gl_EXTENSIONS).split(' ')
end
					lib/gamnit/display.nit:28,1--79,3
				
redef class GamnitDisplay
	# The EGL display
	var egl_display: EGLDisplay is noautoinit
	# The EGL context
	var egl_context: EGLContext is noautoinit
	# The EGL surface for the window
	var window_surface: EGLSurface is noautoinit
	# The selected EGL configuration
	var egl_config: EGLConfig is noautoinit
	# Setup the EGL display for the given `native_display`
	protected fun setup_egl_display(native_display: Pointer)
	do
		var egl_display = new EGLDisplay(native_display)
		assert egl_display.is_valid else print "new EGL display is not valid"
		egl_display.initialize
		assert egl_display.is_valid else print "EGL initialize error: {egl_display.error}"
		self.egl_display = egl_display
	end
	# Select an EGL config
	protected fun select_egl_config(red, green, blue, alpha, depth, stencil: Int)
	do
		var config_chooser = new EGLConfigChooser
		config_chooser.renderable_type_egl
		config_chooser.surface_type_egl
		config_chooser.red_size = red
		config_chooser.green_size = green
		config_chooser.blue_size = blue
		if alpha > 0 then config_chooser.alpha_size = alpha
		if depth > 0 then config_chooser.depth_size = depth
		if stencil > 0 then config_chooser.stencil_size = stencil
		config_chooser.sample_buffers = 1
		config_chooser.samples = 4
		config_chooser.close
		var configs = config_chooser.choose(egl_display)
		assert configs != null else print "Choosing EGL config failed: {egl_display.error}"
		assert not configs.is_empty else print "Found no EGL config"
		if debug_gamnit then
			print "EGL available configurations:"
			for config in configs do
				var attribs = config.attribs(egl_display)
				print "* Conformant to: {attribs.conformant}"
				print "  Caveats: {attribs.caveat}"
				print "  Size of RGBA: {attribs.red_size} {attribs.green_size} {attribs.blue_size} {attribs.alpha_size}"
				print "  Buffer, depth, stencil: {attribs.buffer_size} {attribs.depth_size} {attribs.stencil_size}"
				print "  Sample buffers, samples: {attribs.sample_buffers} {attribs.samples}"
			end
		end
		# We use the first one, it is recommended
		self.egl_config = configs.first
	end
	# Setup the EGL context for the given `native_window`
	protected fun setup_egl_context(native_window: Pointer)
	do
		var window_surface = egl_display.create_window_surface(egl_config, native_window, [0])
		assert window_surface.is_ok else print "Creating EGL window surface failed: {egl_display.error}"
		self.window_surface = window_surface
		egl_context = egl_display.create_context(egl_config)
		assert egl_context.is_ok else print "Creating EGL context failed: {egl_display.error}"
		var make_current_res = egl_display.make_current(window_surface, window_surface, egl_context)
		assert make_current_res else print "Creating EGL make current failed: {egl_display.error}"
		# TODO make the API selection configurable per platform
		assert egl_bind_opengl_es_api else print "EGL bind API failed: {egl_display.error}"
	end
	# Check if the current configuration of `native_window` is still valid
	#
	# There is two return values:
	# * Returns `true` if the Gamnit services should be recreated.
	# * Sets `native_window_is_invalid` if the system provided window handle is invalid.
	#   We should wait until we are provided a valid window handle.
	fun check_egl_context(native_window: Pointer): Bool
	do
		native_window_is_invalid = false
		if not egl_context.is_ok then
			# Needs recreating
			egl_context = egl_display.create_context(egl_config)
			assert egl_context.is_ok else print "Creating EGL context failed: {egl_display.error}"
		end
		var success = egl_display.make_current(window_surface, window_surface, egl_context)
		if not success then
			var error = egl_display.error
			print "check_egl_context make_current: {error}"
			if error.is_bad_native_window then
				# native_window is invalid
				native_window_is_invalid = true
				return true
			else if not error.is_success then
				# The context is now invalid, rebuild it
				setup_egl_context native_window
				return true
			end
		end
		return false
	end
	# Return value from `check_egl_context`, the current native window is invalid
	#
	# We should wait until we are provided a valid window handle.
	var native_window_is_invalid = false
	redef fun width do return window_surface.attribs(egl_display).width
	redef fun height do return window_surface.attribs(egl_display).height
	# Close the EGL context
	fun close_egl
	do
		egl_display.make_current(new EGLSurface.none, new EGLSurface.none, new EGLContext.none)
		egl_display.destroy_context(egl_context)
		egl_display.destroy_surface(window_surface)
	end
	redef fun flip
	do
		assert glGetError == gl_NO_ERROR
		assert egl_display.is_valid
		egl_display.swap_buffers(window_surface)
	end
end
					lib/gamnit/egl.nit:22,1--164,3
				
redef class GamnitDisplay
	redef var width = 200
	redef var height = 300
	# Underlying GLKit game controller and view
	var glk_view: NitGLKView is noautoinit
	redef fun setup
	do
		var view = new GamnitGLKView
		view.multiple_touch_enabled = true
		self.glk_view = view
		self.width = view.drawable_width
		self.height = view.drawable_height
	end
end
					lib/gamnit/display_ios.nit:28,1--44,3
				
redef class GamnitDisplay
	# Actual width or desired width of the window, can be set before calling `setup`
	fun width=(value: Int) do requested_width = value
	private var requested_width = 1920
	# Actual height or desired height of the window, can be set before calling `setup`
	fun height=(value: Int) do requested_height = value
	private var requested_height = 1080
	redef fun show_cursor do return sdl.show_cursor
	redef fun show_cursor=(val) do sdl.show_cursor = val
	redef fun lock_cursor=(val) do sdl.relative_mouse_mode = val
	redef fun lock_cursor do return sdl.relative_mouse_mode
	# Setup SDL, wm, EGL in order
	redef fun setup
	do
		if debug_gamnit then print "Setting up SDL"
		self.sdl_window = setup_sdl(requested_width, requested_height)
		if debug_gamnit then print "Setting up window manager"
		setup_egl_display sdl_window.wm_info.display_handle
		if debug_gamnit then print "Setting up EGL context"
		select_egl_config(red_bits, green_bits, blue_bits, 8, 8, 0)
		setup_egl_context sdl_window.wm_info.window_handle
	end
	# Close EGL and SDL in reverse order of `setup` (nothing to do for X11)
	redef fun close
	do
		close_egl
		close_sdl
	end
	# ---
	# SDL
	# The SDL display managing the window and events
	var sdl_window: SDLWindow is noautoinit
	# Title of the window, must be set before creating the window (or redef)
	var window_title = "gamnit game" is lazy, writable
	# Setup the SDL display and lib
	fun setup_sdl(window_width, window_height: Int): SDLWindow
	do
		assert sdl.initialize((new SDLInitFlags).video.audio) else
			print_error "Failed to initialize SDL2: {sdl.error}"
		end
		var img_flags = (new SDLImgInitFlags).png.jpg
		assert sdl.img.initialize(img_flags) == img_flags else
			print_error "Failed to initialize SDL2 IMG: {sdl.error}"
		end
		var sdl_window = new SDLWindow(window_title.to_cstring, window_width, window_height, sdl_window_flags)
		assert not sdl_window.address_is_null else
			print_error "Failed to create SDL2 window: {sdl.error}"
		end
		# Audio support
		var inited = mix.initialize(mix_init_flags)
		if inited != mix_init_flags then
			print_error "Failed to load SDL2 mixer format supports: {mix.error}"
		end
		var open = mix.open_audio(44100, mix.default_format, 2, 1024)
		if not open then
			print_error "Failed to initialize SDL2 mixer: {mix.error}"
		end
		return sdl_window
	end
	# SDL2 window initialization flags
	#
	# The default value supports OpenGL and window resizing.
	var sdl_window_flags: SDLWindowFlags = (new SDLWindowFlags).opengl.resizable is lazy, writable
	# SDL2 mixer initialization flags
	#
	# Defaults to FLAC, MP3 and OGG.
	var mix_init_flags: MixInitFlags = mix.flac | mix.mp3 | mix.ogg is lazy, writable
	# Close the SDL display
	fun close_sdl
	do
		sdl_window.destroy
		mix.close_audio
		mix.quit
		sdl.finalize
	end
end
					lib/gamnit/display_linux.nit:25,1--122,3
				
redef class GamnitDisplay
	redef fun setup
	do
		var native_display = egl_default_display
		var native_window = app.native_app_glue.window
		setup_egl_display native_display
		# We need 8 bits per color for selection by color
		select_egl_config(red_bits, green_bits, blue_bits, 0, 8, 0)
		var format = egl_config.attribs(egl_display).native_visual_id
		assert not native_window.address_is_null
		native_window.set_buffers_geometry(0, 0, format)
		setup_egl_context native_window
	end
	redef fun close do close_egl
end
					lib/gamnit/display_android.nit:32,1--52,3
				
redef class GamnitDisplay
	# With stereoscopic view, the aspect ratio (in each eye) is half of the screen
	redef fun aspect_ratio do return super / 2.0
end
					lib/gamnit/depth/stereoscopic_view.nit:57,1--61,3
				
redef class GamnitDisplay
	redef var aspect_ratio = super is lazy
end
					lib/gamnit/gamnit_linux.nit:59,1--61,3
				
redef class GamnitDisplay
	redef var width = 1080
	redef var height = 720
	# Update `width` and `height`
	private fun update_size
	do
		var context = app.native_activity
		self.width = context.window_width
		self.height = context.window_height
	end
end
					lib/gamnit/gamnit_android.nit:278,1--290,3