Class: Mittsu::Texture

Inherits:
HashObject show all
Includes:
EventDispatcher
Defined in:
lib/mittsu/textures/texture.rb

Constant Summary collapse

DEFAULT_IMAGE =
nil
DEFAULT_MAPPING =
UVMapping

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EventDispatcher

#add_event_listener, #dispatch_event, #has_event_listener, #remove_event_listener

Methods inherited from HashObject

#[], #[]=, #delete

Constructor Details

#initialize(image = DEFAULT_IMAGE, mapping = DEFAULT_MAPPING, wrap_s = ClampToEdgeWrapping, wrap_t = ClampToEdgeWrapping, mag_filter = LinearFilter, min_filter = LinearMipMapLinearFilter, format = RGBAFormat, type = UnsignedByteType, anisotropy = 1) ⇒ Texture

Returns a new instance of Texture.



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
# File 'lib/mittsu/textures/texture.rb', line 18

def initialize(image = DEFAULT_IMAGE, mapping = DEFAULT_MAPPING, wrap_s = ClampToEdgeWrapping, wrap_t = ClampToEdgeWrapping, mag_filter = LinearFilter, min_filter = LinearMipMapLinearFilter, format = RGBAFormat, type = UnsignedByteType, anisotropy = 1)
  super()

  @id = (@@id ||= 1).tap { @@id += 1 }
  @uuid = SecureRandom.uuid

  @name = ''
  @source_file = ''

  @image = image
  @mipmaps = []

  @mapping = mapping
  @wrap_s, @wrap_t = wrap_s, wrap_t
  @mag_filter, @min_filter = mag_filter, min_filter
  @anisotropy = anisotropy
  @format, @type = format, type

  @offset = Vector2.new(0.0, 0.0)
  @repeat = Vector2.new(1.0, 1.0)

  @generate_mipmaps = true
  @premultiply_alpha = false
  @filp_y = true
  @unpack_alignment = 4 # valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)

  @_needs_update = false
  @on_update = nil
end

Instance Attribute Details

#anisotropyObject

Returns the value of attribute anisotropy.



16
17
18
# File 'lib/mittsu/textures/texture.rb', line 16

def anisotropy
  @anisotropy
end

#filp_yObject

Returns the value of attribute filp_y.



16
17
18
# File 'lib/mittsu/textures/texture.rb', line 16

def filp_y
  @filp_y
end

#formatObject

Returns the value of attribute format.



16
17
18
# File 'lib/mittsu/textures/texture.rb', line 16

def format
  @format
end

#generate_mipmapsObject

Returns the value of attribute generate_mipmaps.



16
17
18
# File 'lib/mittsu/textures/texture.rb', line 16

def generate_mipmaps
  @generate_mipmaps
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/mittsu/textures/texture.rb', line 14

def id
  @id
end

#imageObject

Returns the value of attribute image.



16
17
18
# File 'lib/mittsu/textures/texture.rb', line 16

def image
  @image
end

#mag_filterObject

Returns the value of attribute mag_filter.



16
17
18
# File 'lib/mittsu/textures/texture.rb', line 16

def mag_filter
  @mag_filter
end

#mappingObject

Returns the value of attribute mapping.



16
17
18
# File 'lib/mittsu/textures/texture.rb', line 16

def mapping
  @mapping
end

#min_filterObject

Returns the value of attribute min_filter.



16
17
18
# File 'lib/mittsu/textures/texture.rb', line 16

def min_filter
  @min_filter
end

#mipmapsObject

Returns the value of attribute mipmaps.



16
17
18
# File 'lib/mittsu/textures/texture.rb', line 16

def mipmaps
  @mipmaps
end

#nameObject

Returns the value of attribute name.



16
17
18
# File 'lib/mittsu/textures/texture.rb', line 16

def name
  @name
end

#offsetObject

Returns the value of attribute offset.



16
17
18
# File 'lib/mittsu/textures/texture.rb', line 16

def offset
  @offset
end

#on_updateObject

Returns the value of attribute on_update.



16
17
18
# File 'lib/mittsu/textures/texture.rb', line 16

def on_update
  @on_update
end

#premultiply_alphaObject

Returns the value of attribute premultiply_alpha.



16
17
18
# File 'lib/mittsu/textures/texture.rb', line 16

def premultiply_alpha
  @premultiply_alpha
end

#repeatObject

Returns the value of attribute repeat.



16
17
18
# File 'lib/mittsu/textures/texture.rb', line 16

def repeat
  @repeat
end

#source_fileObject

Returns the value of attribute source_file.



16
17
18
# File 'lib/mittsu/textures/texture.rb', line 16

def source_file
  @source_file
end

#typeObject

Returns the value of attribute type.



14
15
16
# File 'lib/mittsu/textures/texture.rb', line 14

def type
  @type
end

#unpack_alignmentObject

Returns the value of attribute unpack_alignment.



16
17
18
# File 'lib/mittsu/textures/texture.rb', line 16

def unpack_alignment
  @unpack_alignment
end

#uuidObject (readonly)

Returns the value of attribute uuid.



14
15
16
# File 'lib/mittsu/textures/texture.rb', line 14

def uuid
  @uuid
end

#wrap_sObject

Returns the value of attribute wrap_s.



16
17
18
# File 'lib/mittsu/textures/texture.rb', line 16

def wrap_s
  @wrap_s
end

#wrap_tObject

Returns the value of attribute wrap_t.



16
17
18
# File 'lib/mittsu/textures/texture.rb', line 16

def wrap_t
  @wrap_t
end

Instance Method Details

#clone(texture = Texture.new) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/mittsu/textures/texture.rb', line 57

def clone(texture = Texture.new)
  texture.image = @image
  texture.mipmaps = @mipmaps.dup

  texture.mapping = @mapping

  texture.wrap_s = @wrap_s
  texture.wrap_t = @wrap_t

  texture.mag_filter = @mag_filter
  texture.min_filter = @min_filter

  texture.anisotropy = @anisotropy

  texture.format = @format
  texture.type = @type

  texture.offset.copy(@offset)
  texture.repeat.copy(@repeat)

  texture.generate_mipmaps = @generate_mipmaps
  texture.premultiply_alpha = @premultiply_alpha
  texture.flip_y = @flip_y

  texture
end

#disposeObject



88
89
90
# File 'lib/mittsu/textures/texture.rb', line 88

def dispose
  dispatch_event type: :dispose
end

#needs_update=(value) ⇒ Object



52
53
54
55
# File 'lib/mittsu/textures/texture.rb', line 52

def needs_update=(value)
  update if value
  @_needs_update = value
end

#needs_update?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/mittsu/textures/texture.rb', line 48

def needs_update?
  @_needs_update
end

#updateObject



84
85
86
# File 'lib/mittsu/textures/texture.rb', line 84

def update
  dispatch_event type: :update
end