indexing description: "An Eiffel class that wraps all the OpenGL functions concerning textures" "Some remarks: " " * This class is ment to wrapp ALL opengl functions conserning textures" " * _internal funcitons are faster than normal functions because they do not" " bind the texture each time, but you have to bind the texture on your own!!!!" " * to use more texture functions extend this class or inherit from it." " * when creating a object of this class you have to call default_create!" documentation: "Documentation of class" date: "$Date$" revision: "$Revision$" deferred class EMGL_TEXTURE[F -> EMGL_FORMAT create default_create end] inherit EMGL_FUNCTIONS export {NONE} all {ANY} gl_get_error_external redefine default_create end EM_CONSTANTS export {NONE} all; {ANY} em_gl_invalid_operation redefine default_create end DISPOSABLE redefine default_create end EMGL_BASIC_TEXTURE redefine default_create end feature {NONE} -- Initialization and destruction default_create is -- Create a new EMGL_TEXTURE object. do gl_gen_textures_external(1, $texture_id) end dispose is -- free the texture do gl_delete_textures_external( 1, $texture_id ) end feature {EMGL_TEXTURE} --Access frozen format_desc: F -- Description of internal format of this texture frozen internal_format: INTEGER is -- Shortcut for `format_desc.internal_format' do Result := format_desc.internal_format end target: INTEGER is -- The target on which thresulte texture is bound deferred ensure target_is_valid: result=em_gl_texture_1d or result=em_gl_texture_2d or result=em_gl_texture_3d end binding_target: INTEGER is -- The target on which the texture is bound deferred ensure target_is_valid: binding_target=binding_target or else result=em_gl_texture_binding_1d or result=em_gl_texture_binding_2d or result=em_gl_texture_binding_3d end next_power_of_two( i:INTEGER ):INTEGER is -- return the text power of two do from result:=1 until result>=i loop result:=result*2 end end feature {EMGL_TEXTURE} --internal function wrapper are_textures_resident_internal ( n:INTEGER; textures:POINTER; residences:POINTER ): INTEGER is --Wrap the OpenGL function `gl_are_textures_resident`, for internal use only texture might not be bound! do result:=gl_are_textures_resident_external( n, textures, residences ) end bind_texture_internal ( texture:INTEGER ) is --Wrap the OpenGL function `gl_bind_texture`, for internal use only texture might not be bound! do gl_bind_texture_external( target, texture ) end copy_tex_image1d_internal ( level:INTEGER; x:INTEGER; y:INTEGER; width:INTEGER; border:INTEGER ) is --Wrap the OpenGL function `gl_copy_tex_image1d`, for internal use only texture might not be bound! do gl_copy_tex_image1d_external( target, level, internal_format, x, y, width, border ) end copy_tex_image2d_internal ( level:INTEGER; x:INTEGER; y:INTEGER; width:INTEGER; height:INTEGER; border:INTEGER ) is --Wrap the OpenGL function `gl_copy_tex_image2d`, for internal use only texture might not be bound! do gl_copy_tex_image2d_external( target, level, internal_format, x, y, width, height, border ) end copy_tex_sub_image1d_internal ( level:INTEGER; xoffset:INTEGER; x:INTEGER; y:INTEGER; width:INTEGER ) is --Wrap the OpenGL function `gl_copy_tex_sub_image1d`, for internal use only texture might not be bound! do gl_copy_tex_sub_image1d_external( target, level, xoffset, x, y, width ) end copy_tex_sub_image2d_internal ( level:INTEGER; xoffset:INTEGER; yoffset:INTEGER; x:INTEGER; y:INTEGER; width:INTEGER; height:INTEGER ) is --Wrap the OpenGL function `gl_copy_tex_sub_image2d`, for internal use only texture might not be bound! do gl_copy_tex_sub_image2d_external( target, level, xoffset, yoffset, x, y, width, height ) end delete_textures_internal ( n:INTEGER; textures:POINTER ) is --Wrap the OpenGL function `gl_delete_textures`, for internal use only texture might not be bound! do gl_delete_textures_external( n, textures ) end gen_textures_internal ( n:INTEGER; textures:POINTER ) is --Wrap the OpenGL function `gl_gen_textures`, for internal use only texture might not be bound! do gl_gen_textures_external( n, textures ) end get_tex_image_internal ( level:INTEGER; format:INTEGER; type:INTEGER; pixels:POINTER ) is --Wrap the OpenGL function `gl_get_tex_image`, for internal use only texture might not be bound! do gl_get_tex_image_external( target, level, format, type, pixels ) end get_tex_level_parameterfv_internal ( level:INTEGER; pname:INTEGER; params:POINTER ) is --Wrap the OpenGL function `gl_get_tex_level_parameterfv`, for internal use only texture might not be bound! do gl_get_tex_level_parameterfv_external( target, level, pname, params ) end get_tex_level_parameteriv_internal ( level:INTEGER; pname:INTEGER; params:POINTER ) is --Wrap the OpenGL function `gl_get_tex_level_parameteriv`, for internal use only texture might not be bound! do gl_get_tex_level_parameteriv_external( target, level, pname, params ) end get_tex_parameterfv_internal ( pname:INTEGER; params:POINTER ) is --Wrap the OpenGL function `gl_get_tex_parameterfv`, for internal use only texture might not be bound! do gl_get_tex_parameterfv_external( target, pname, params ) end get_tex_parameteriv_internal ( pname:INTEGER; params:POINTER ) is --Wrap the OpenGL function `gl_get_tex_parameteriv`, for internal use only texture might not be bound! do gl_get_tex_parameteriv_external( target, pname, params ) end is_texture_internal ( texture:INTEGER ): INTEGER is --Wrap the OpenGL function `gl_is_texture`, for internal use only texture might not be bound! do result:=gl_is_texture_external( texture ) end prioritize_textures_internal ( n:INTEGER; textures:POINTER; priorities:POINTER ) is --Wrap the OpenGL function `gl_prioritize_textures`, for internal use only texture might not be bound! do gl_prioritize_textures_external( n, textures, priorities ) end tex_image1d_internal ( level:INTEGER; width:INTEGER; border:INTEGER; format:INTEGER; type:INTEGER; pixels:POINTER ) is --Wrap the OpenGL function `gl_tex_image1d`, for internal use only texture might not be bound! do gl_tex_image1d_external( target, level, internal_format, width, border, format, type, pixels ) end tex_image2d_internal ( level:INTEGER; width:INTEGER; height:INTEGER; border:INTEGER; format:INTEGER; type:INTEGER; pixels:POINTER ) is --Wrap the OpenGL function `gl_tex_image2d`, for internal use only texture might not be bound! do gl_tex_image2d_external( target, level, internal_format, width, height, border, format, type, pixels ) end tex_parameterf_internal ( pname:INTEGER; param:REAL ) is --Wrap the OpenGL function `gl_tex_parameterf`, for internal use only texture might not be bound! do gl_tex_parameterf_external( target, pname, param ) end tex_parameterfv_internal ( pname:INTEGER; params:POINTER ) is --Wrap the OpenGL function `gl_tex_parameterfv`, for internal use only texture might not be bound! do gl_tex_parameterfv_external( target, pname, params ) end tex_parameteri_internal ( pname:INTEGER; param:INTEGER ) is --Wrap the OpenGL function `gl_tex_parameteri`, for internal use only texture might not be bound! do gl_tex_parameteri_external( target, pname, param ) end tex_parameteriv_internal ( pname:INTEGER; params:POINTER ) is --Wrap the OpenGL function `gl_tex_parameteriv`, for internal use only texture might not be bound! do gl_tex_parameteriv_external( target, pname, params ) end tex_sub_image1d_internal ( level:INTEGER; xoffset:INTEGER; width:INTEGER; format:INTEGER; type:INTEGER; pixels:POINTER ) is --Wrap the OpenGL function `gl_tex_sub_image1d`, for internal use only texture might not be bound! do gl_tex_sub_image1d_external( target, level, xoffset, width, format, type, pixels ) end tex_sub_image2d_internal ( level:INTEGER; xoffset:INTEGER; yoffset:INTEGER; width:INTEGER; height:INTEGER; format:INTEGER; type:INTEGER; pixels:POINTER ) is --Wrap the OpenGL function `gl_tex_sub_image2d`, for internal use only texture might not be bound! do gl_tex_sub_image2d_external( target, level, xoffset, yoffset, width, height, format, type, pixels ) end feature --general function wrapper are_textures_resident ( n:INTEGER; textures:POINTER; residences:POINTER ): INTEGER is --Wrap the OpenGL function `gl_are_textures_resident`, autobind and unbind the texture do bind_and_save_old result:=gl_are_textures_resident_external( n, textures, residences ) bind_old_id end bind_texture ( texture:INTEGER ) is --Wrap the OpenGL function `gl_bind_texture`, autobind and unbind the texture do bind_and_save_old gl_bind_texture_external( target, texture ) bind_old_id end copy_tex_image1d ( level:INTEGER; x:INTEGER; y:INTEGER; width:INTEGER; border:INTEGER ) is --Wrap the OpenGL function `gl_copy_tex_image1d`, autobind and unbind the texture do bind_and_save_old gl_copy_tex_image1d_external( target, level, internal_format, x, y, width, border ) bind_old_id end copy_tex_image2d ( level:INTEGER; x:INTEGER; y:INTEGER; width:INTEGER; height:INTEGER; border:INTEGER ) is --Wrap the OpenGL function `gl_copy_tex_image2d`, autobind and unbind the texture do bind_and_save_old gl_copy_tex_image2d_external( target, level, internal_format, x, y, width, height, border ) bind_old_id end copy_tex_sub_image1d ( level:INTEGER; xoffset:INTEGER; x:INTEGER; y:INTEGER; width:INTEGER ) is --Wrap the OpenGL function `gl_copy_tex_sub_image1d`, autobind and unbind the texture do bind_and_save_old gl_copy_tex_sub_image1d_external( target, level, xoffset, x, y, width ) bind_old_id end copy_tex_sub_image2d ( level:INTEGER; xoffset:INTEGER; yoffset:INTEGER; x:INTEGER; y:INTEGER; width:INTEGER; height:INTEGER ) is --Wrap the OpenGL function `gl_copy_tex_sub_image2d`, autobind and unbind the texture do bind_and_save_old gl_copy_tex_sub_image2d_external( target, level, xoffset, yoffset, x, y, width, height ) bind_old_id end delete_textures ( n:INTEGER; textures:POINTER ) is --Wrap the OpenGL function `gl_delete_textures`, autobind and unbind the texture do bind_and_save_old gl_delete_textures_external( n, textures ) bind_old_id end gen_textures ( n:INTEGER; textures:POINTER ) is --Wrap the OpenGL function `gl_gen_textures`, autobind and unbind the texture do bind_and_save_old gl_gen_textures_external( n, textures ) bind_old_id end get_tex_image ( level:INTEGER; format:INTEGER; type:INTEGER; pixels:POINTER ) is --Wrap the OpenGL function `gl_get_tex_image`, autobind and unbind the texture do bind_and_save_old gl_get_tex_image_external( target, level, format, type, pixels ) bind_old_id end get_tex_level_parameterfv ( level:INTEGER; pname:INTEGER; params:POINTER ) is --Wrap the OpenGL function `gl_get_tex_level_parameterfv`, autobind and unbind the texture do bind_and_save_old gl_get_tex_level_parameterfv_external( target, level, pname, params ) bind_old_id end get_tex_level_parameteriv ( level:INTEGER; pname:INTEGER; params:POINTER ) is --Wrap the OpenGL function `gl_get_tex_level_parameteriv`, autobind and unbind the texture do bind_and_save_old gl_get_tex_level_parameteriv_external( target, level, pname, params ) bind_old_id end get_tex_parameterfv ( pname:INTEGER; params:POINTER ) is --Wrap the OpenGL function `gl_get_tex_parameterfv`, autobind and unbind the texture do bind_and_save_old gl_get_tex_parameterfv_external( target, pname, params ) bind_old_id end get_tex_parameteriv ( pname:INTEGER; params:POINTER ) is --Wrap the OpenGL function `gl_get_tex_parameteriv`, autobind and unbind the texture do bind_and_save_old gl_get_tex_parameteriv_external( target, pname, params ) bind_old_id end is_texture ( texture:INTEGER ): INTEGER is --Wrap the OpenGL function `gl_is_texture`, autobind and unbind the texture do bind_and_save_old result:=gl_is_texture_external( texture ) bind_old_id end prioritize_textures ( n:INTEGER; textures:POINTER; priorities:POINTER ) is --Wrap the OpenGL function `gl_prioritize_textures`, autobind and unbind the texture do bind_and_save_old gl_prioritize_textures_external( n, textures, priorities ) bind_old_id end tex_image1d ( level:INTEGER; internalformat:INTEGER; width:INTEGER; border:INTEGER; format:INTEGER; type:INTEGER; pixels:POINTER ) is --Wrap the OpenGL function `gl_tex_image1d`, autobind and unbind the texture do bind_and_save_old gl_tex_image1d_external( target, level, internalformat, width, border, format, type, pixels ) bind_old_id end tex_image2d ( level:INTEGER; width:INTEGER; height:INTEGER; border:INTEGER; format:INTEGER; type:INTEGER; pixels:POINTER ) is --Wrap the OpenGL function `gl_tex_image2d`, autobind and unbind the texture do bind_and_save_old gl_tex_image2d_external( target, level, internal_format, width, height, border, format, type, pixels ) bind_old_id end tex_parameterf ( pname:INTEGER; param:REAL ) is --Wrap the OpenGL function `gl_tex_parameterf`, autobind and unbind the texture do bind_and_save_old gl_tex_parameterf_external( target, pname, param ) bind_old_id end tex_parameterfv ( pname:INTEGER; params:POINTER ) is --Wrap the OpenGL function `gl_tex_parameterfv`, autobind and unbind the texture do bind_and_save_old gl_tex_parameterfv_external( target, pname, params ) bind_old_id end tex_parameteri ( pname:INTEGER; param:INTEGER ) is --Wrap the OpenGL function `gl_tex_parameteri`, autobind and unbind the texture do bind_and_save_old gl_tex_parameteri_external( target, pname, param ) bind_old_id end tex_parameteriv ( pname:INTEGER; params:POINTER ) is --Wrap the OpenGL function `gl_tex_parameteriv`, autobind and unbind the texture do bind_and_save_old gl_tex_parameteriv_external( target, pname, params ) bind_old_id end tex_sub_image1d ( level:INTEGER; xoffset:INTEGER; width:INTEGER; format:INTEGER; type:INTEGER; pixels:POINTER ) is --Wrap the OpenGL function `gl_tex_sub_image1d`, autobind and unbind the texture do bind_and_save_old gl_tex_sub_image1d_external( target, level, xoffset, width, format, type, pixels ) bind_old_id end tex_sub_image2d ( level:INTEGER; xoffset:INTEGER; yoffset:INTEGER; width:INTEGER; height:INTEGER; format:INTEGER; type:INTEGER; pixels:POINTER ) is --Wrap the OpenGL function `gl_tex_sub_image2d`, autobind and unbind the texture do bind_and_save_old gl_tex_sub_image2d_external( target, level, xoffset, yoffset, width, height, format, type, pixels ) bind_old_id end feature {EMGL_TEXTURE} --internal function wrapper get_tex_envi_internal ( pname:INTEGER ): INTEGER is --Wrap the OpenGL function `gl_get_tex_enviv`, for internal use only texture might not be bound! do gl_get_tex_enviv_external( target, pname, $result ) end get_tex_level_parameteri_internal ( level:INTEGER; pname:INTEGER ): INTEGER is --Wrap the OpenGL function `gl_get_tex_level_parameteriv`, for internal use only texture might not be bound! do gl_get_tex_level_parameteriv_external( target, level, pname, $result ) end get_tex_parameteri_internal ( pname:INTEGER ): INTEGER is --Wrap the OpenGL function `gl_get_tex_parameteriv`, for internal use only texture might not be bound! do gl_get_tex_parameteriv_external( target, pname, $result ) end feature --general function wrapper get_tex_envi ( pname:INTEGER ): INTEGER is --Wrap the OpenGL function `gl_get_tex_enviv`, autobind and unbind the texture do bind_and_save_old gl_get_tex_enviv_external( target, pname, $result ) bind_old_id end get_tex_level_parameteri ( level:INTEGER; pname:INTEGER ): INTEGER is --Wrap the OpenGL function `gl_get_tex_level_parameteriv`, autobind and unbind the texture do bind_and_save_old gl_get_tex_level_parameteriv_external( target, level, pname, $result ) bind_old_id end get_tex_parameteri ( pname:INTEGER ): INTEGER is --Wrap the OpenGL function `gl_get_tex_parameteriv`, autobind and unbind the texture do bind_and_save_old gl_get_tex_parameteriv_external( target, pname, $result ) bind_old_id end feature {EMGL_TEXTURE} --internal function wrapper get_tex_envf_internal ( pname:INTEGER ): REAL is --Wrap the OpenGL function `gl_get_tex_envfv`, for internal use only texture might not be bound! do gl_get_tex_envfv_external( target, pname, $result ) end get_tex_level_parameterf_internal ( level:INTEGER; pname:INTEGER ): REAL is --Wrap the OpenGL function `gl_get_tex_level_parameterfv`, for internal use only texture might not be bound! do gl_get_tex_level_parameterfv_external( target, level, pname, $result ) end get_tex_parameterf_internal ( pname:INTEGER ): REAL is --Wrap the OpenGL function `gl_get_tex_parameterfv`, for internal use only texture might not be bound! do gl_get_tex_parameterfv_external( target, pname, $result ) end feature --general function wrapper get_tex_envf ( pname:INTEGER ): REAL is --Wrap the OpenGL function `gl_get_tex_envfv`, autobind and unbind the texture do bind_and_save_old gl_get_tex_envfv_external( target, pname, $result ) bind_old_id end get_tex_level_parameterf ( level:INTEGER; pname:INTEGER ): REAL is --Wrap the OpenGL function `gl_get_tex_level_parameterfv`, autobind and unbind the texture do bind_and_save_old gl_get_tex_level_parameterfv_external( target, level, pname, $result ) bind_old_id end get_tex_parameterf ( pname:INTEGER ): REAL is --Wrap the OpenGL function `gl_get_tex_parameterfv`, autobind and unbind the texture do bind_and_save_old gl_get_tex_parameterfv_external( target, pname, $result ) bind_old_id end feature{EMGL_TEXTURE} -- Internal Commands old_texture_id: INTEGER bind_and_save_old is -- bind this texture and save the old binding -- DO NEVER, NEVER USE THIS FEATURE RECURSIVELY OR -- CALL ANY FEATURES THAT MIGHT DO SO!!!!! do old_texture_id := current_texture_binding bind end bind_old_id is -- bind old_texture_id require valid_old_texture_id: old_texture_id>=0 do gl_bind_texture_external(target, old_texture_id) end update_texture is -- Called before bind do -- Nothing end feature -- Commands frozen bind is require gl_get_error_external /= em_gl_invalid_operation do update_texture gl_bind_texture_external(target, texture_id) ensure -- Possible error: Called between gl_begin and gl_end target_bound: is_texture( texture_id ) > 0 end frozen unbind is -- Unbind a texture to target do gl_bind_texture_external(target, 0) ensure -- Possible error: Called between gl_begin and gl_end -- This postcon is violated, I don't know why -- target_unbound: current_texture_binding = 0 end frozen current_texture_binding: INTEGER is -- Return the texture id bound to target do result := emgl_get_integer( binding_target ) ensure valid_id: result>=0 end feature -- Tex Level Parameter texture_width: INTEGER is -- Returns the texture widht do result := get_tex_level_parameteri( 0, em_gl_texture_width ) end texture_height: INTEGER is -- Returns the texture heiht do result := get_tex_level_parameteri( 0, em_gl_texture_height ) end texture_depth: INTEGER is -- Returns the texture depth do result := get_tex_level_parameteri( 0, em_gl_texture_depth ) end texture_depth_ext: INTEGER is -- Returns the texture depth_ext do result := get_tex_level_parameteri( 0, em_gl_texture_depth_ext ) end texture_border: INTEGER is -- Returns the texture birder size do result := get_tex_level_parameteri( 0, em_gl_texture_border ) end texture_alpha_size: INTEGER is -- Returns the texture alpha size do result := get_tex_level_parameteri( 0, em_gl_texture_alpha_size ) end texture_blue_size: INTEGER is -- Returns the texture blue size do result := get_tex_level_parameteri( 0, em_gl_texture_blue_size ) end texture_red_size: INTEGER is -- Returns the texture red size do result := get_tex_level_parameteri( 0, em_gl_texture_red_size ) end texture_green_size: INTEGER is -- Returns the texture green size do result := get_tex_level_parameteri( 0, em_gl_texture_green_size ) end texture_intensity_size: INTEGER is -- Returns the 'The internal storage resolution of an individual component' do result := get_tex_level_parameteri( 0, em_gl_texture_intensity_size ) end texture_internal_format: INTEGER is -- self explaining do result := get_tex_level_parameteri( 0, em_gl_texture_internal_format ) end texture_luminance_size: INTEGER is -- Returns the 'The internal storage resolution of an individual luminance component' do result := get_tex_level_parameteri( 0, em_gl_texture_luminance_size ) end feature{EMGL_TEXTURE} -- Tex Parameter, Internal only texture_min_filter_internal: INTEGER is -- Returns the value of GL_TEXTURE_MIN_FILTER do result := get_tex_parameteri_internal( em_gl_texture_min_filter ) end set_texture_min_filter_internal( value: INTEGER ) is -- Specify GL_TEXTURE_MIN_FILTER do tex_parameteri_internal( em_gl_texture_min_filter, value ) end texture_mag_filter_internal: INTEGER is -- Returns the value of GL_TEXTURE_MAG_FILTER do result := get_tex_parameteri_internal( em_gl_texture_mag_filter ) end set_texture_mag_filter_internal( value: INTEGER ) is -- Specify GL_TEXTURE_MAG_FILTER do tex_parameteri_internal( em_gl_texture_mag_filter, value ) end texture_wrap_s_internal: INTEGER is -- Returns the value of GL_TEXTURE_WRAP_S do result := get_tex_parameteri_internal( em_gl_texture_wrap_s ) end set_texture_wrap_s_internal( value: INTEGER ) is -- Specify GL_TEXTURE_WRAP_S do tex_parameteri_internal( em_gl_texture_wrap_s, value ) end texture_wrap_t_internal: INTEGER is -- Returns the value of GL_TEXTURE_WRAP_T do result := get_tex_parameteri_internal( em_gl_texture_wrap_t ) end set_texture_wrap_t_internal( value: INTEGER ) is -- Specify GL_TEXTURE_WRAP_T do tex_parameteri_internal( em_gl_texture_wrap_t, value ) end texture_priority_internal_internal: INTEGER is -- Returns the value of GL_TEXTURE_PRIORITY do result := get_tex_parameteri_internal( em_gl_texture_priority ) end set_texture_priority_internal( value: INTEGER ) is -- Specify GL_TEXTURE_PRIORITY do tex_parameteri_internal( em_gl_texture_priority, value ) end feature -- Tex Parameter texture_min_filter: INTEGER is -- Returns the value of GL_TEXTURE_MIN_FILTER do result := get_tex_parameteri( em_gl_texture_min_filter ) end set_texture_min_filter( value: INTEGER ) is -- Specify GL_TEXTURE_MIN_FILTER do tex_parameteri( em_gl_texture_min_filter, value ) end texture_mag_filter: INTEGER is -- Returns the value of GL_TEXTURE_MAG_FILTER do result := get_tex_parameteri( em_gl_texture_mag_filter ) end set_texture_mag_filter( value: INTEGER ) is -- Specify GL_TEXTURE_MAG_FILTER do tex_parameteri( em_gl_texture_mag_filter, value ) end texture_wrap_s : INTEGER is -- Returns the value of GL_TEXTURE_WRAP_S do result := get_tex_parameteri( em_gl_texture_wrap_s ) end set_texture_wrap_s( value: INTEGER ) is -- Specify GL_TEXTURE_WRAP_S do tex_parameteri( em_gl_texture_wrap_s, value ) end texture_wrap_t: INTEGER is -- Returns the value of GL_TEXTURE_WRAP_T do result := get_tex_parameteri( em_gl_texture_wrap_t ) end set_texture_wrap_t( value: INTEGER ) is -- Specify GL_TEXTURE_WRAP_T do tex_parameteri( em_gl_texture_wrap_t, value ) end texture_priority: INTEGER is -- Returns the value of GL_TEXTURE_PRIORITY do result := get_tex_parameteri( em_gl_texture_priority ) end set_texture_priority( value: INTEGER ) is -- Specify GL_TEXTURE_PRIORITY do tex_parameteri( em_gl_texture_priority, value ) end invariant -- Did you call default_craete? texture_is_valid: texture_id>0 end -- class EMGL_TEXTURE