Class: Mittsu::DataTexture

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

Constant Summary

Constants inherited from Texture

Texture::DEFAULT_IMAGE, Texture::DEFAULT_MAPPING

Instance Attribute Summary

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

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(data = 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) ⇒ DataTexture

Returns a new instance of DataTexture.



5
6
7
8
9
# File 'lib/mittsu/textures/data_texture.rb', line 5

def initialize(data = 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 = { data: data, width: width, height: height }
end

Instance Method Details

#cloneObject



11
12
13
14
15
# File 'lib/mittsu/textures/data_texture.rb', line 11

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

#update_specificObject



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

def update_specific
  gl_format = GL_MITTSU_PARAMS[format]
  gl_type = GL_MITTSU_PARAMS[type]
  is_image_power_of_two = Math.power_of_two?(image.width) && Math.power_of_two?(image.height)

  # use manually created mipmaps if available
  # if there are no manual mipmaps
  # set 0 level mipmap and then use GL to generate other mipmap levels

  if !mipmaps.empty? && is_image_power_of_two
    mipmaps.each_with_index do |mipmap, i|
      glTexImage2D(GL_TEXTURE_2D, i, gl_format, mipmap.width, mipmap.height, 0, gl_format, gl_type, mipmap.data)
    end
  else
    glTexImage2D(GL_TEXTURE_2D, 0, gl_format, image.width, image.height, 0, gl_format, gl_type, image.data)
  end
end