note
	description: "A hardware accelerated picture in memory"
	author: "Louis Marchand"
	date: "Fri, 27 Mar 2015 21:44:07 +0000"
	revision: "2.0"

class 
	GAME_TEXTURE

create 
	make,
	make_target,
	make_from_surface,
	make_from_image,
	share_from_other

feature {NONE} -- Initialization

	default_create
			-- Process instances of classes with no creation clause.
			-- (Default: do nothing.)
			-- (from ANY)
		do
		end

	make (a_renderer: GAME_RENDERER; a_pixel_format: GAME_PIXEL_FORMAT_READABLE; a_width, a_height: INTEGER_32)
			-- Initialization for Current of dimension (a_width , `a_height)
			-- for use on a_renderer, having a_pixel_format. Current
			-- can not be locked to be modified (best performance)
		do
			make_with_flags (a_renderer, a_pixel_format, {GAME_SDL_EXTERNAL}.sdl_textureaccess_static, a_width, a_height)
		ensure
			error_or_exist: not has_error implies exists
			is_not_shared: not shared
		end

	make_from_image (a_renderer: GAME_RENDERER; a_image: GAME_IMAGE)
			-- Initialization of Current for use on a_renderer and using
			-- the data of a_image
		require
			image_is_open: a_image.is_open
		local
			l_item: POINTER
		do
			clear_error
			l_item := {GAME_SDL_EXTERNAL}.sdl_createtexturefromsurface (a_renderer.item, a_image.item)
			manage_error_pointer (l_item, "Cannot create texture.")
			make_by_pointer (l_item)
			shared := False
			is_locked := False
		ensure
			error_or_exist: not has_error implies exists
			is_not_shared: not shared
		end

	make_from_surface (a_renderer: GAME_RENDERER; a_surface: GAME_SURFACE)
			-- Initialization of Current for use on a_renderer and using
			-- the data of a_surface (pixel format, picture, etc.)
		do
			make_from_image (a_renderer, a_surface.image)
			is_locked := False
		ensure
			error_or_exist: not has_error implies exists
			is_not_shared: not shared
		end

	make_target (a_renderer: GAME_RENDERER; a_pixel_format: GAME_PIXEL_FORMAT_READABLE; a_width, a_height: INTEGER_32)
		obsolete "Use the class {GAME_TEXTURE_TARGET} instead."
			-- Initialization for Current of dimension (a_width , `a_height)
			-- for use on a_renderer, having a_pixel_format. Current
			-- can be used as rendering target (see: GAME_RENDERER.render_target)
		do
			make_with_flags (a_renderer, a_pixel_format, {GAME_SDL_EXTERNAL}.sdl_textureaccess_target, a_width, a_height)
		ensure
			error_or_exist: not has_error implies exists
			is_not_shared: not shared
		end

	make_with_flags (a_renderer: GAME_RENDERER; a_pixel_format: GAME_PIXEL_FORMAT_READABLE; a_access_flags, a_width, a_height: INTEGER_32)
			-- Initialization for Current of dimension (a_width , `a_height)
			-- for use on a_renderer, having a_pixel_format and
			-- respecting a_access_flags.
		local
			l_item: POINTER
		do
			clear_error
			l_item := {GAME_SDL_EXTERNAL}.sdl_createtexture (a_renderer.item, a_pixel_format.internal_index, a_access_flags, a_width, a_height)
			manage_error_pointer (l_item, "Cannot create texture.")
			make_by_pointer (l_item)
			shared := False
			is_locked := False
		ensure
			error_or_exist: not has_error implies exists
			is_not_shared: not shared
		end

	share_from_other (a_other: GAME_TEXTURE)
			-- Initialization of Current sharing the internal data of Current
			-- Note that each modification of Current will affect a_other and
			-- vice versa
		require
			other_exists: a_other.exists
		local
			l_root: like other
		do
			from
				l_root := a_other
			until
				not (attached l_root and then l_root.shared)
			loop
				l_root := l_root.other
			end
			check
					attached l_root
			then
				make_by_pointer (l_root.item)
				other := l_root
				shared := True
			end
		ensure
			is_created: exists
			is_shared: shared
			other_assign: attached other as la_other and then not la_other.shared
		end
	
feature -- Initialization

	make_structure
			-- Initialize current with given structure_size.
			-- (from MEMORY_STRUCTURE)
		local
			null: POINTER
		do
			internal_item := null
			create managed_pointer.make (structure_size)
			internal_item_exists := False
		ensure -- from MEMORY_STRUCTURE
			not_shared: not internal_item_exists
		end

	make_by_pointer (a_ptr: POINTER)
			-- Initialize current with a_ptr.
			-- (from MEMORY_STRUCTURE)
		require -- from MEMORY_STRUCTURE
			a_ptr_not_null: a_ptr /= default_pointer
		do
			internal_item := a_ptr
			managed_pointer := Void
			internal_item_exists := True
		ensure -- from MEMORY_STRUCTURE
			shared: internal_item_exists
		end
	
feature -- Access

	additionnal_alpha: NATURAL_8 assign set_additionnal_alpha
			-- Additionnal alpha blend to apply on Current when drawing
		require
			texture_exist: exists
		local
			l_error: INTEGER_32
		do
			clear_error
			l_error := {GAME_SDL_EXTERNAL}.sdl_gettexturealphamod (item, $Result.to_pointer)
			manage_error_code (l_error, "Cannot retreive the texture additionnal alpha value.")
		end

	additionnal_color: GAME_COLOR_READABLE assign set_additionnal_color
			-- Additionnal color to multiply to Current when drawing
		require
			texture_exist: exists
		local
			l_error: INTEGER_32
			l_red, l_green, l_blue: NATURAL_8
		do
			clear_error
			l_error := {GAME_SDL_EXTERNAL}.sdl_gettexturecolormod (item, $l_red.to_pointer, $l_green.to_pointer, $l_blue.to_pointer)
			manage_error_code (l_error, "Cannot retreive the texture additionnal color value.")
			create Result.make_rgb (l_red, l_green, l_blue)
		end

	disable_blending
			-- Disable every blending mode to use for drawing operations.
			-- No blending mode:	dstRGBA = srcRGBA
			-- (from GAME_BLENDABLE)
		require -- from GAME_BLENDABLE
			blendable_is_valid: exists
		do
			set_blend_mode ({GAME_SDL_EXTERNAL}.sdl_blendmode_none)
		end

	enable_additive_blending
			-- Set the additive blending mode to use for drawing operations.
			-- Additive blending:	dstRGB = (srcRGB * srcA) + dstRGB
			--						dstA = dstA
			-- (from GAME_BLENDABLE)
		require -- from GAME_BLENDABLE
			blendable_is_valid: exists
		do
			set_blend_mode ({GAME_SDL_EXTERNAL}.sdl_blendmode_add)
		end

	enable_alpha_blending
			-- Set the alpha blending mode to use for drawing operations.
			-- Alpha blending:	dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
			--					dstA = srcA + (dstA * (1-srcA))
			-- (from GAME_BLENDABLE)
		require -- from GAME_BLENDABLE
			blendable_is_valid: exists
		do
			set_blend_mode ({GAME_SDL_EXTERNAL}.sdl_blendmode_blend)
		end

	enable_modulate_blending
			-- Set the color modulate blending mode to use for drawing operations.
			-- Color modulate:	dstRGB = srcRGB * dstRGB
			--					dstA = dstA
			-- (from GAME_BLENDABLE)
		require -- from GAME_BLENDABLE
			blendable_is_valid: exists
		do
			set_blend_mode ({GAME_SDL_EXTERNAL}.sdl_blendmode_mod)
		end

	generating_type: TYPE [detachable GAME_TEXTURE]
			-- Type of current object
			-- (type of which it is a direct instance)
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			generating_type_not_void: Result /= Void
		end

	generator: STRING_8
			-- Name of current object's generating class
			-- (base class of the type of which it is a direct instance)
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			generator_not_void: Result /= Void
			generator_not_empty: not Result.is_empty
		end

	has_error: BOOLEAN
			-- Is the library has generate an error
			-- (from GAME_ERROR_MANAGER)

	height: INTEGER_32
			-- The vertical length of Current
		require
			texture_exist: exists
		do
			Result := informations.height
		end

	is_additive_blending_enabled: BOOLEAN
			-- True if the blending mode for drawing operation is additive blending.
			-- Additive blending:	dstRGB = (srcRGB * srcA) + dstRGB
			--						dstA = dstA
			-- (from GAME_BLENDABLE)
		require -- from GAME_BLENDABLE
			blendable_is_valid: exists
		local
			l_blending_mode: INTEGER_32
		do
			l_blending_mode := blend_mode
			if not has_error then
				Result := l_blending_mode = {GAME_SDL_EXTERNAL}.sdl_blendmode_add
			else
				Result := False
			end
		end

	is_alpha_blending_enabled: BOOLEAN
			-- True if the blending mode for drawing operation is alpha blending.
			-- Alpha blending:	dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
			--					dstA = srcA + (dstA * (1-srcA))
			-- (from GAME_BLENDABLE)
		require -- from GAME_BLENDABLE
			blendable_is_valid: exists
		local
			l_blending_mode: INTEGER_32
		do
			l_blending_mode := blend_mode
			if not has_error then
				Result := l_blending_mode = {GAME_SDL_EXTERNAL}.sdl_blendmode_blend
			else
				Result := False
			end
		end

	is_blending_disabled: BOOLEAN
			-- True if no blending mode is used for drawing operations.
			-- No blending mode:	dstRGBA = srcRGBA
			-- (from GAME_BLENDABLE)
		require -- from GAME_BLENDABLE
			blendable_is_valid: exists
		local
			l_blending_mode: INTEGER_32
		do
			l_blending_mode := blend_mode
			if not has_error then
				Result := l_blending_mode = {GAME_SDL_EXTERNAL}.sdl_blendmode_none
			else
				Result := False
			end
		end

	is_locked: BOOLEAN
			-- Current is locked to access pixels. Current cannot be used until unlock is called.

	is_modulate_blending_enabled: BOOLEAN
			-- True if the blending mode for drawing operation is color modulate blending.
			-- Color modulate:	dstRGB = srcRGB * dstRGB
			--					dstA = dstA
			-- (from GAME_BLENDABLE)
		require -- from GAME_BLENDABLE
			blendable_is_valid: exists
		local
			l_blending_mode: INTEGER_32
		do
			l_blending_mode := blend_mode
			if not has_error then
				Result := l_blending_mode = {GAME_SDL_EXTERNAL}.sdl_blendmode_mod
			else
				Result := False
			end
		end

	is_streamable: BOOLEAN
			-- Can Current be modified by locking
		require
			texture_exist: exists
		do
			Result := informations.access = {GAME_SDL_EXTERNAL}.sdl_textureaccess_streaming
		end

	is_targetable: BOOLEAN
			-- Can Current be use as render target
		require
			texture_exist: exists
		do
			Result := informations.access = {GAME_SDL_EXTERNAL}.sdl_textureaccess_target
		end

	item: POINTER
			-- Access to memory area.
			-- (from MEMORY_STRUCTURE)
		require -- from  GAME_BLENDABLE
			True
		local
			m: like managed_pointer
		do
			if internal_item_exists then
				Result := internal_item
			else
				m := managed_pointer
				if m /= Void then
					Result := m.item
				end
			end
		end

	last_error: READABLE_STRING_GENERAL
			-- The last error generate by the library
			-- (from GAME_SDL_ANY)
		local
			l_string: C_STRING
		do
			if is_manual_error then
				Result := Precursor {GAME_ERROR_MANAGER}
			else
				create l_string.make_by_pointer ({GAME_SDL_EXTERNAL}.sdl_geterror)
				Result := l_string.string
			end
		end

	pixel_format: GAME_PIXEL_FORMAT_READABLE
			-- Informations about the internal representation of pixels in Current
		require
			texture_exist: exists
		do
			create Result.make_from_flags (informations.format)
		end

	set_additionnal_alpha (a_additionnal_alpha: NATURAL_8)
			-- Assign additionnal_alpha with the value of a_additionnal_alpha
		require
			texture_exist: exists
		local
			l_error: INTEGER_32
		do
			clear_error
			l_error := {GAME_SDL_EXTERNAL}.sdl_settexturealphamod (item, a_additionnal_alpha)
			manage_error_code (l_error, "Cannot set the texture additionnal alpha value")
		ensure
			is_set: additionnal_alpha = a_additionnal_alpha
		end

	set_additionnal_color (a_additionnal_color: GAME_COLOR_READABLE)
			-- Assign additionnal_color with the value of a_additionnal_color
		require
			texture_exist: exists
		local
			l_error: INTEGER_32
		do
			clear_error
			l_error := {GAME_SDL_EXTERNAL}.sdl_settexturecolormod (item, a_additionnal_color.red, a_additionnal_color.green, a_additionnal_color.blue)
			manage_error_code (l_error, "Cannot set the texture additionnal color value")
		ensure
			is_set: additionnal_color.is_equal_ignore_alpha (a_additionnal_color)
		end

	internal_item_exists: BOOLEAN
			-- Is current memory area shared with others?
			-- (from MEMORY_STRUCTURE)

	shared: BOOLEAN
			-- Is current memory area shared with others?

	update_pixels (a_pixels: GAME_PIXEL_BUFFER)
			-- Modify the pixels colors in the section of Current starting at a_x,a_y using data in a_pixels
		require
			is_format_valid: a_pixels.pixel_format ~ pixel_format
			is_dimension_valid: width ~ a_pixels.width and height ~ a_pixels.height
		local
			l_error: INTEGER_32
		do
			clear_error
			l_error := {GAME_SDL_EXTERNAL}.sdl_updatetexture (item, create {POINTER}, a_pixels.item, a_pixels.pitch)
			manage_error_code (l_error, "Cannot update texture pixels.")
		end

	update_pixels_with_rect (a_x, a_y: INTEGER_32; a_pixels: GAME_PIXEL_BUFFER)
			-- Modify the pixels colors in the section of Current starting at a_x,a_y using data in a_pixels
		require
			is_format_valid: a_pixels.pixel_format ~ pixel_format
			is_dimension_valid: width >= a_x + a_pixels.width and height >= a_y + a_pixels.height
		local
			l_rectangle: POINTER
			l_error: INTEGER_32
		do
			l_rectangle := l_rectangle.memory_calloc (1, {GAME_SDL_EXTERNAL}.c_sizeof_sdl_rect)
			{GAME_SDL_EXTERNAL}.set_rect_struct_x (l_rectangle, a_x)
			{GAME_SDL_EXTERNAL}.set_rect_struct_y (l_rectangle, a_y)
			{GAME_SDL_EXTERNAL}.set_rect_struct_w (l_rectangle, a_pixels.width)
			{GAME_SDL_EXTERNAL}.set_rect_struct_h (l_rectangle, a_pixels.height)
			clear_error
			l_error := {GAME_SDL_EXTERNAL}.sdl_updatetexture (item, l_rectangle, a_pixels.item, a_pixels.pitch)
			manage_error_code (l_error, "Cannot update texture pixels.");
			l_rectangle.memory_free
		end

	width: INTEGER_32
			-- The horizontal length of Current
		require
			texture_exist: exists
		do
			Result := informations.width
		end
	
feature -- Measurement

	structure_size: INTEGER_32
			-- Size to allocate (in bytes).
		do
			Result := 0
		ensure -- from MEMORY_STRUCTURE
			is_class: class
			positive_result: Result > 0
		end
	
feature -- Comparison

	frozen deep_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void
			-- or attached to isomorphic object structures?
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.is_deep_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			shallow_implies_deep: standard_equal (a, b) implies Result
			both_or_none_void: (a = Void) implies (Result = (b = Void))
			same_type: (Result and (a /= Void)) implies (b /= Void and then a.same_type (b))
			symmetric: Result implies deep_equal (b, a)
		end

	frozen equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached
			-- to objects considered equal?
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.is_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.is_equal (b))
		end

	frozen is_deep_equal alias "≡≡≡" (other: GAME_TEXTURE): BOOLEAN
			-- Are Current and other attached to isomorphic object structures?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			shallow_implies_deep: standard_is_equal (other) implies Result
			same_type: Result implies same_type (other)
			symmetric: Result implies other.is_deep_equal (Current)
		end

	is_equal (other: GAME_TEXTURE): BOOLEAN
			-- Is other attached to an object considered
			-- equal to current object?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			symmetric: Result implies other ~ Current
			consistent: standard_is_equal (other) implies Result
		end

	frozen standard_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached to
			-- field-by-field identical objects of the same type?
			-- Always uses default object comparison criterion.
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.standard_is_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.standard_is_equal (b))
		end

	frozen standard_is_equal alias "≜" (other: GAME_TEXTURE): BOOLEAN
			-- Is other attached to an object of the same type
			-- as current object, and field-by-field identical to it?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			same_type: Result implies same_type (other)
			symmetric: Result implies other.standard_is_equal (Current)
		end
	
feature -- Status report

	conforms_to (other: ANY): BOOLEAN
			-- Does type of current object conform to type
			-- of other (as per Eiffel: The Language, chapter 13)?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		end

	exists: BOOLEAN
			-- Is allocated memory still allocated?
			-- (from MEMORY_STRUCTURE)
		require -- from  GAME_BLENDABLE
			True
		do
			Result := item /= default_pointer
		end

	same_type (other: ANY): BOOLEAN
			-- Is type of current object identical to type of other?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			definition: Result = (conforms_to (other) and other.conforms_to (Current))
		end
	
feature {NONE} -- Status report

	is_in_final_collect: BOOLEAN
			-- Is GC currently performing final collection
			-- after execution of current program?
			-- Safe to use in dispose.
			-- (from DISPOSABLE)
		external
			"C inline use %"eif_memory.h%""
		alias
			"return eif_is_in_final_collect;"
		end
	
feature -- Duplication

	frozen clone (other: detachable ANY): like other
		obsolete "Use `twin' instead. [2017-05-31]"
			-- Void if other is void; otherwise new object
			-- equal to other
			--
			-- For non-void other, clone calls copy;
			-- to change copying/cloning semantics, redefine copy.
			-- (from ANY)
		do
			if other /= Void then
				Result := other.twin
			end
		ensure -- from ANY
			instance_free: class
			equal: Result ~ other
		end

	copy (other: GAME_TEXTURE)
			-- Update current object using fields of object attached
			-- to other, so as to yield equal objects.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		external
			"built_in"
		ensure -- from ANY
			is_equal: Current ~ other
		end

	frozen deep_clone (other: detachable ANY): like other
		obsolete "Use `deep_twin' instead. [2017-05-31]"
			-- Void if other is void: otherwise, new object structure
			-- recursively duplicated from the one attached to other
			-- (from ANY)
		do
			if other /= Void then
				Result := other.deep_twin
			end
		ensure -- from ANY
			instance_free: class
			deep_equal: deep_equal (other, Result)
		end

	frozen deep_copy (other: GAME_TEXTURE)
			-- Effect equivalent to that of:
			--		copy (other . deep_twin)
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		do
			copy (other.deep_twin)
		ensure -- from ANY
			deep_equal: deep_equal (Current, other)
		end

	frozen deep_twin: GAME_TEXTURE
			-- New object structure recursively duplicated from Current.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			deep_twin_not_void: Result /= Void
			deep_equal: deep_equal (Current, Result)
		end

	frozen standard_clone (other: detachable ANY): like other
		obsolete "Use `standard_twin' instead. [2017-05-31]"
			-- Void if other is void; otherwise new object
			-- field-by-field identical to other.
			-- Always uses default copying semantics.
			-- (from ANY)
		do
			if other /= Void then
				Result := other.standard_twin
			end
		ensure -- from ANY
			instance_free: class
			equal: standard_equal (Result, other)
		end

	frozen standard_copy (other: GAME_TEXTURE)
			-- Copy every field of other onto corresponding field
			-- of current object.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		external
			"built_in"
		ensure -- from ANY
			is_standard_equal: standard_is_equal (other)
		end

	frozen standard_twin: GAME_TEXTURE
			-- New object field-by-field identical to other.
			-- Always uses default copying semantics.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			standard_twin_not_void: Result /= Void
			equal: standard_equal (Result, Current)
		end

	frozen twin: GAME_TEXTURE
			-- New object equal to Current
			-- twin calls copy; to change copying/twinning semantics, redefine copy.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			twin_not_void: Result /= Void
			is_equal: Result ~ Current
		end
	
feature -- Basic operations

	frozen as_attached: attached GAME_TEXTURE
		obsolete "Remove calls to this feature. [2017-05-31]"
			-- Attached version of Current.
			-- (Can be used during transitional period to convert
			-- non-void-safe classes to void-safe ones.)
			-- (from ANY)
		do
			Result := Current
		end

	frozen default: detachable GAME_TEXTURE
			-- Default value of object's type
			-- (from ANY)
		do
		end

	frozen default_pointer: POINTER
			-- Default value of type POINTER
			-- (Avoid the need to write p.default for
			-- some p of type POINTER.)
			-- (from ANY)
		do
		ensure -- from ANY
			instance_free: class
		end

	default_rescue
			-- Process exception for routines with no Rescue clause.
			-- (Default: do nothing.)
			-- (from ANY)
		do
		end

	frozen do_nothing
			-- Execute a null action.
			-- (from ANY)
		do
		ensure -- from ANY
			instance_free: class
		end
	
feature {NONE} -- Implementation

	blend_mode: INTEGER_32 assign set_blend_mode
			-- The alpha blending mode of Current
			-- (from GAME_BLENDABLE)
		local
			l_error, l_blending_mode: INTEGER_32
		do
			clear_error
			l_error := c_get_blend_mode (item, $l_blending_mode.to_pointer)
			if l_error < 0 then
				manage_error_code (l_error, "An error occured while retrieving the blending mode.")
				Result := 0
			end
			Result := l_blending_mode
		end

	clear_error
			-- Remove error pending in Current
			-- (from GAME_SDL_ANY)
		require -- from  GAME_ERROR_MANAGER
			True
		do
			{GAME_SDL_EXTERNAL}.sdl_clearerror
			Precursor {GAME_ERROR_MANAGER}
			is_manual_error := False
		ensure -- from GAME_ERROR_MANAGER
			no_error: not has_error
		ensure then -- from GAME_SDL_ANY
			no_error: not is_manual_error
		end

	disable_print_on_error
			-- Desactive the print_on_error functionnality.
			-- (from GAME_ERROR_MANAGER)
		do
			Print_on_error_internal.put (False)
		end

	enable_print_on_error
			-- Active the print_on_error functionnality.
			-- (from GAME_ERROR_MANAGER)
		do
			Print_on_error_internal.put (True)
		end

	informations: TUPLE [format: NATURAL_32; access: INTEGER_32; width: INTEGER_32; height: INTEGER_32]
			-- Retreive the pixel format, the access flag, the width and the height of Current
		require
			texture_exists: exists
		local
			l_format: NATURAL_32
			l_error, l_access, l_width, l_height: INTEGER_32
		do
			l_error := {GAME_SDL_EXTERNAL}.sdl_querytexture (item, $l_format.to_pointer, $l_access.to_pointer, $l_width.to_pointer, $l_height.to_pointer)
			manage_error_code (l_error, "Cannot retreive texture informations.")
			Result := [l_format, l_access, l_width, l_height]
		end

	internal_item: POINTER
			-- Pointer holding value when shared.
			-- (from MEMORY_STRUCTURE)

	is_manual_error: BOOLEAN
			-- Is the current pending error is a manual error (using manual_error as message)
			-- (from GAME_SDL_ANY)

	manage_error_boolean (a_boolean: BOOLEAN; a_message: READABLE_STRING_GENERAL)
			-- Create an error if a_boolean is false.
			-- If there is an error, append a_message to the error message
			-- on the SDL2 library
			-- (from GAME_SDL_ANY)
		do
			if not a_boolean then
				if Print_on_error_internal.item then
					Io.Error.put_string (a_message.to_string_8 + "%N");
					Io.Error.put_string (last_error.to_string_8 + "%N")
				end
				has_error := True
			end
		ensure -- from GAME_SDL_ANY
				not a_boolean implies has_error
		end

	manage_error_code (a_error_code: INTEGER_32; a_message: READABLE_STRING_GENERAL)
			-- If needed create an error depending of the error code a_code.
			-- If there is an error, append a_message to the error message
			-- on the SDL2 library
			-- (from GAME_SDL_ANY)
		do
			if a_error_code < 0 then
				if Print_on_error_internal.item then
					Io.Error.put_string (a_message.to_string_8 + "%N");
					Io.Error.put_string (last_error.to_string_8 + "%N")
				end
				has_error := True
			end
		end

	manage_error_pointer (a_pointer: POINTER; a_message: READABLE_STRING_GENERAL)
			-- Create an error if a_pointer is not valid.
			-- If there is an error, append a_message to the error message
			-- on the SDL2 library
			-- (from GAME_SDL_ANY)
		do
			if a_pointer.is_default_pointer then
				if Print_on_error_internal.item then
					Io.Error.put_string (a_message.to_string_8 + "%N");
					Io.Error.put_string (last_error.to_string_8 + "%N")
				end
				has_error := True
			end
		ensure -- from GAME_SDL_ANY
				a_pointer.is_default_pointer implies has_error
		end

	managed_pointer: detachable MANAGED_POINTER
			-- Hold memory area in a managed way.
			-- (from MEMORY_STRUCTURE)

	manual_error: detachable READABLE_STRING_GENERAL
			-- The specific message for the last error
			-- (from GAME_ERROR_MANAGER)

	print_on_error: BOOLEAN
			-- When an error occured, the library will print
			-- informations about the error on the error console
			-- output (default is True).
			-- (from GAME_ERROR_MANAGER)
		do
			Result := Print_on_error_internal.item
		end

	Print_on_error_internal: CELL [BOOLEAN]
			-- True when an error occured,
			-- The library will print it right away.
			-- (from GAME_ERROR_MANAGER)
		once ("PROCESS")
			create Result.put (True)
		end

	put_manual_error (a_general_message, a_specific_error: READABLE_STRING_GENERAL)
			-- Create an error using a_general_error for the debug information
			-- and a_specific_error for the lasting information
			-- (from GAME_SDL_ANY)
		do
			is_manual_error := True
			Precursor {GAME_ERROR_MANAGER} (a_general_message, a_specific_error)
		ensure -- from GAME_ERROR_MANAGER
				has_error
		end

	set_blend_mode (a_blend_mode: INTEGER_32)
			-- The alpha blending mode of Current
			-- (from GAME_BLENDABLE)
		local
			l_error: INTEGER_32
		do
			clear_error
			l_error := c_set_blend_mode (item, a_blend_mode)
			manage_error_code (l_error, "An error occured while enabling color modulate blending on the renderer.")
		end

	set_print_on_error (a_value: BOOLEAN)
			-- Assign to print_on_error the value of a_value
			-- (from GAME_ERROR_MANAGER)
		do
			if a_value then
				enable_print_on_error
			else
				disable_print_on_error
			end
		ensure -- from GAME_ERROR_MANAGER
			is_assign: print_on_error ~ a_value
		end
	
feature -- Implementation

	dispose
			-- Action to be executed just before garbage collection
			-- reclaims an object.
			-- Effect it in descendants to perform specific dispose
			-- actions. Those actions should only take care of freeing
			-- external resources; they should not perform remote calls
			-- on other objects since these may also be dead and reclaimed.
		do
			if exists and not shared then
				{GAME_SDL_EXTERNAL}.sdl_destroytexture (item)
				create internal_item
			end
		end
	
feature {GAME_TEXTURE} -- Implementation

	other: detachable GAME_TEXTURE
			-- If Current has been created with share_from_other,
			-- Keep the origin GAME_TEXTURE to prevent the Garbage
			-- Collector from collect it and free the internal
			-- memory pointed by item
	
feature {NONE} -- External

	c_get_blend_mode (a_item, a_blend_mode: POINTER): INTEGER_32
			-- Internal getter for blend mode
		do
			Result := {GAME_SDL_EXTERNAL}.sdl_gettextureblendmode (a_item, a_blend_mode)
		end

	c_set_blend_mode (a_item: POINTER; a_blend_mode: INTEGER_32): INTEGER_32
			-- Internal setter for blend mode
		do
			Result := {GAME_SDL_EXTERNAL}.sdl_settextureblendmode (a_item, a_blend_mode)
		end
	
feature -- Output

	Io: STD_FILES
			-- Handle to standard file setup
			-- (from ANY)
		once
			create Result;
			Result.set_output_default
		ensure -- from ANY
			instance_free: class
			io_not_void: Result /= Void
		end

	out: STRING_8
			-- New string containing terse printable representation
			-- of current object
			-- (from ANY)
		do
			Result := tagged_out
		ensure -- from ANY
			out_not_void: Result /= Void
		end

	print (o: detachable ANY)
			-- Write terse external representation of o
			-- on standard output.
			-- (from ANY)
		local
			s: READABLE_STRING_8
		do
			if attached o then
				s := o.out
				if attached {READABLE_STRING_32} s as s32 then
					Io.put_string_32 (s32)
				elseif attached {READABLE_STRING_8} s as s8 then
					Io.put_string (s8)
				else
					Io.put_string_32 (s.as_string_32)
				end
			end
		ensure -- from ANY
			instance_free: class
		end

	frozen tagged_out: STRING_8
			-- New string containing terse printable representation
			-- of current object
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			tagged_out_not_void: Result /= Void
		end
	
feature -- Platform

	Operating_environment: OPERATING_ENVIRONMENT
			-- Objects available from the operating system
			-- (from ANY)
		once
			create Result
		ensure -- from ANY
			instance_free: class
			operating_environment_not_void: Result /= Void
		end
	
feature {NONE} -- Retrieval

	frozen internal_correct_mismatch
			-- Called from runtime to perform a proper dynamic dispatch on correct_mismatch
			-- from MISMATCH_CORRECTOR.
			-- (from ANY)
		local
			l_msg: STRING_32
			l_exc: EXCEPTIONS
		do
			if attached {MISMATCH_CORRECTOR} Current as l_corrector then
				l_corrector.correct_mismatch
			else
				create l_msg.make_from_string ("Mismatch: ".as_string_32)
				create l_exc;
				l_msg.append (generating_type.name_32);
				l_exc.raise_retrieval_exception (l_msg)
			end
		end
	
invariant
		-- from ANY
	reflexive_equality: standard_is_equal (Current)
	reflexive_conformance: conforms_to (Current)

		-- from MEMORY_STRUCTURE
	managed_pointer_valid: not internal_item_exists implies managed_pointer /= Void
	internal_item_valid: internal_item_exists implies internal_item /= default_pointer

end -- class GAME_TEXTURE

Generated by ISE EiffelStudio