Class: Mittsu::CompressedTexture

Inherits:
Texture
  • Object
show all
Defined in:
lib/mittsu/textures/compressed_texture.rb,
lib/mittsu/renderers/opengl/textures/compressed_texture.rb

Constant Summary

Constants inherited from Texture

Texture::DEFAULT_IMAGE, Texture::DEFAULT_MAPPING

Instance Attribute Summary collapse

Attributes inherited from Texture

#anisotropy, #filp_y, #format, #generate_mipmaps, #id, #image, #mag_filter, #mapping, #min_filter, #name, #offset, #on_update, #opengl_texture, #premultiply_alpha, #repeat, #source_file, #type, #unpack_alignment, #uuid, #wrap_s, #wrap_t

Instance Method Summary collapse

Methods inherited from Texture

#dispose, #needs_update=, #needs_update?, #set, #update, #update_opengl

Methods included from EventDispatcher

#add_event_listener, #dispatch_event, #has_event_listener, #remove_event_listener

Constructor Details

#initialize(mipmaps = nil, width = nil, height = nil, format = RGBAFormat, type = UnsignedByteType, mapping = DEFAULT_MAPPING, wrap_s = ClampToEdgeWrapping, wrap_t = ClampToEdgeWrapping, mag_filter = LinearFilter, min_filter = LinearMipMapLinearFilter, anisotropy = 1) ⇒ CompressedTexture

Returns a new instance of CompressedTexture.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mittsu/textures/compressed_texture.rb', line 7

def initialize(mipmaps = nil, width = nil, height = nil, format = RGBAFormat, type = UnsignedByteType, mapping = DEFAULT_MAPPING, wrap_s = ClampToEdgeWrapping, wrap_t = ClampToEdgeWrapping, mag_filter = LinearFilter, min_filter = LinearMipMapLinearFilter, anisotropy = 1)
  super(null, mapping, wrap_s, wrap_t, mag_filter, min_filter, format, type, anisotropy)

  @image = { width: width, height: height }
  @mipmaps = mipmaps

  # no flipping for cube textures
  # (also flipping doesn't work for compressed textures )

  @flip_y = false

  # can't generate mipmaps for compressed textures
  # mips must be embedded in DDS files

  @generate_mipmaps = false
end

Instance Attribute Details

#mipmapsObject

Returns the value of attribute mipmaps.



5
6
7
# File 'lib/mittsu/textures/compressed_texture.rb', line 5

def mipmaps
  @mipmaps
end

Instance Method Details

#cloneObject



24
25
26
27
28
# File 'lib/mittsu/textures/compressed_texture.rb', line 24

def clone
  texture = CompressedTexture.new
  super(texture)
  texture
end

#update_specificObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/mittsu/renderers/opengl/textures/compressed_texture.rb', line 3

def update_specific
  gl_format = GL_MITTSU_PARAMS[format]
  gl_type = GL_MITTSU_PARAMS[type]

  mipmaps.each_with_index do |mipmap, i|
    if format != RGBAFormat && format != RGBFormat
      if @renderer.compressed_texture_formats.include?(gl_format)
        glCompressedTexImage2D(GL_TEXTURE_2D, i, gl_format, mipmap.width, mipmap.height, 0, mipmap.data)
      else
        puts 'WARNING: Mittsu::Texture: Attempt to load unsupported compressed texture format in #update_texture'
      end
    else
      glTexImage2D(GL_TEXTURE_2D, i, gl_format, mipmap.width, mipmap.height, 0, gl_format, gl_type, mipmap.data)
    end
  end
end