Class: Mittsu::CubeTexture
- Defined in:
- lib/mittsu/textures/cube_texture.rb,
lib/mittsu/renderers/opengl/textures/cube_texture.rb
Constant Summary
Constants inherited from Texture
Texture::DEFAULT_IMAGE, Texture::DEFAULT_MAPPING
Instance Attribute Summary collapse
-
#images ⇒ Object
Returns the value of attribute images.
Attributes inherited from Texture
#anisotropy, #filp_y, #format, #generate_mipmaps, #id, #image, #mag_filter, #mapping, #min_filter, #mipmaps, #name, #offset, #on_update, #opengl_texture, #premultiply_alpha, #repeat, #source_file, #type, #unpack_alignment, #uuid, #wrap_s, #wrap_t
Instance Method Summary collapse
- #clone(texture = CubeTexture.new) ⇒ Object
-
#initialize(images = nil, mapping = DEFAULT_MAPPING, wrap_s = ClampToEdgeWrapping, wrap_t = ClampToEdgeWrapping, mag_filter = LinearFilter, min_filter = LinearMipMapLinearFilter, format = RGBAFormat, type = UnsignedByteType, anisotropy = 1) ⇒ CubeTexture
constructor
A new instance of CubeTexture.
- #set(slot, renderer) ⇒ Object
Methods inherited from Texture
#dispose, #needs_update=, #needs_update?, #update, #update_opengl
Methods included from EventDispatcher
#add_event_listener, #dispatch_event, #has_event_listener, #remove_event_listener
Constructor Details
#initialize(images = nil, mapping = DEFAULT_MAPPING, wrap_s = ClampToEdgeWrapping, wrap_t = ClampToEdgeWrapping, mag_filter = LinearFilter, min_filter = LinearMipMapLinearFilter, format = RGBAFormat, type = UnsignedByteType, anisotropy = 1) ⇒ CubeTexture
Returns a new instance of CubeTexture.
7 8 9 10 11 |
# File 'lib/mittsu/textures/cube_texture.rb', line 7 def initialize(images = nil, mapping = DEFAULT_MAPPING, wrap_s = ClampToEdgeWrapping, wrap_t = ClampToEdgeWrapping, mag_filter = LinearFilter, min_filter = LinearMipMapLinearFilter, format = RGBAFormat, type = UnsignedByteType, anisotropy = 1) super(images, mapping, wrap_s, wrap_t, mag_filter, min_filter, format, type, anisotropy) @images = images end |
Instance Attribute Details
#images ⇒ Object
Returns the value of attribute images.
5 6 7 |
# File 'lib/mittsu/textures/cube_texture.rb', line 5 def images @images end |
Instance Method Details
#clone(texture = CubeTexture.new) ⇒ Object
13 14 15 16 17 |
# File 'lib/mittsu/textures/cube_texture.rb', line 13 def clone(texture = CubeTexture.new) super(texture) texture.images = @images texture end |
#set(slot, renderer) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/mittsu/renderers/opengl/textures/cube_texture.rb', line 3 def set(slot, renderer) @renderer = renderer if image.length == 6 if needs_update? if !image[:_opengl_texture_cube] add_event_listener(:dispose, @renderer.method(:on_texture_dispose)) image[:_opengl_texture_cube] = glCreateTexture @renderer.info[:memory][:textures] += 1 end glActiveTexture(GL_TEXTURE0 + slot) glBindTexture(GL_TEXTURE_CUBE_MAP, image[:_opengl_texture_cube]) # glPixelStorei(GL_UNPACK_FLIP_Y_WEBGL, texture.flip_y) is_compressed = is_a?(CompressedTexture) is_data_texture = image[0].is_a?(DataTexture) cube_image = []; 6.times do |i| if @auto_scale_cubemaps && !is_compressed && !is_data_texture cube_image[i] = clamp_to_max_size(image[i], @_max_cubemap_size) else cube_image[i] = is_data_texture ? image[i].image : image[i]; end end img = cube_image[0] is_image_power_of_two = Math.power_of_two?(img.width) && Math.power_of_two?(img.height) gl_format = GL_MITTSU_PARAMS[format] gl_type = GL_MITTSU_PARAMS[type] set_parameters(GL_TEXTURE_CUBE_MAP, is_image_power_of_two) 6.times do |i| if !is_compressed if is_data_texture glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, gl_format, cube_image[i].width, cube_image[i].height, 0, gl_format, gl_type, cube_image[i].data) else glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, gl_format, cube_image[i].width, cube_image[i].height, 0, gl_format, gl_type, cube_image[i].data) end else mipmaps = cube_image[i].mipmaps mipmaps.each_with_index do |mipmap, j| if format != RGBAFormat && format != RGBFormat if @renderer.compressed_texture_formats.include?(gl_format) glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, j, gl_format, mipmap.width, mipmap.height, 0, mipmap.data) else puts "WARNING: Mittsu::OpenGLCubeTexture: Attempt to load unsupported compressed texture format in #set" end else glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, j, gl_format, mipmap.width, mipmap.height, 0, gl_format, gl_type, mipmap.data) end end end end if generate_mipmaps && is_image_power_of_two glGenerateMipmap(GL_TEXTURE_CUBE_MAP) end self.needs_update = false on_update.call if on_update else glActiveTexture(GL_TEXTURE0 + slot) glBindTexture(GL_TEXTURE_CUBE_MAP, image[:_opengl_texture_cube]) end end end |