Class: Mittsu::Texture
- Inherits:
-
Object
- Object
- Mittsu::Texture
- Includes:
- EventDispatcher
- Defined in:
- lib/mittsu/textures/texture.rb,
lib/mittsu/renderers/opengl/textures/texture.rb
Direct Known Subclasses
CompressedTexture, CubeTexture, DataTexture, OpenGLRenderTarget, VideoTexture
Constant Summary collapse
- DEFAULT_IMAGE =
nil
- DEFAULT_MAPPING =
UVMapping
Instance Attribute Summary collapse
-
#anisotropy ⇒ Object
Returns the value of attribute anisotropy.
-
#filp_y ⇒ Object
Returns the value of attribute filp_y.
-
#format ⇒ Object
Returns the value of attribute format.
-
#generate_mipmaps ⇒ Object
Returns the value of attribute generate_mipmaps.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#image ⇒ Object
Returns the value of attribute image.
-
#mag_filter ⇒ Object
Returns the value of attribute mag_filter.
-
#mapping ⇒ Object
Returns the value of attribute mapping.
-
#min_filter ⇒ Object
Returns the value of attribute min_filter.
-
#mipmaps ⇒ Object
Returns the value of attribute mipmaps.
-
#name ⇒ Object
Returns the value of attribute name.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#on_update ⇒ Object
Returns the value of attribute on_update.
-
#opengl_texture ⇒ Object
readonly
Returns the value of attribute opengl_texture.
-
#premultiply_alpha ⇒ Object
Returns the value of attribute premultiply_alpha.
-
#repeat ⇒ Object
Returns the value of attribute repeat.
-
#source_file ⇒ Object
Returns the value of attribute source_file.
-
#type ⇒ Object
Returns the value of attribute type.
-
#unpack_alignment ⇒ Object
Returns the value of attribute unpack_alignment.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
-
#wrap_s ⇒ Object
Returns the value of attribute wrap_s.
-
#wrap_t ⇒ Object
Returns the value of attribute wrap_t.
Instance Method Summary collapse
- #clone(texture = Texture.new) ⇒ Object
- #dispose ⇒ Object
-
#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
constructor
A new instance of Texture.
- #needs_update=(value) ⇒ Object
- #needs_update? ⇒ Boolean
- #set(slot, renderer) ⇒ Object
- #update ⇒ Object
- #update_opengl(renderer) ⇒ Object
Methods included from EventDispatcher
#add_event_listener, #dispatch_event, #has_event_listener, #remove_event_listener
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.
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 |
# File 'lib/mittsu/textures/texture.rb', line 17 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
#anisotropy ⇒ Object
Returns the value of attribute anisotropy.
15 16 17 |
# File 'lib/mittsu/textures/texture.rb', line 15 def anisotropy @anisotropy end |
#filp_y ⇒ Object
Returns the value of attribute filp_y.
15 16 17 |
# File 'lib/mittsu/textures/texture.rb', line 15 def filp_y @filp_y end |
#format ⇒ Object
Returns the value of attribute format.
15 16 17 |
# File 'lib/mittsu/textures/texture.rb', line 15 def format @format end |
#generate_mipmaps ⇒ Object
Returns the value of attribute generate_mipmaps.
15 16 17 |
# File 'lib/mittsu/textures/texture.rb', line 15 def generate_mipmaps @generate_mipmaps end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
13 14 15 |
# File 'lib/mittsu/textures/texture.rb', line 13 def id @id end |
#image ⇒ Object
Returns the value of attribute image.
15 16 17 |
# File 'lib/mittsu/textures/texture.rb', line 15 def image @image end |
#mag_filter ⇒ Object
Returns the value of attribute mag_filter.
15 16 17 |
# File 'lib/mittsu/textures/texture.rb', line 15 def mag_filter @mag_filter end |
#mapping ⇒ Object
Returns the value of attribute mapping.
15 16 17 |
# File 'lib/mittsu/textures/texture.rb', line 15 def mapping @mapping end |
#min_filter ⇒ Object
Returns the value of attribute min_filter.
15 16 17 |
# File 'lib/mittsu/textures/texture.rb', line 15 def min_filter @min_filter end |
#mipmaps ⇒ Object
Returns the value of attribute mipmaps.
15 16 17 |
# File 'lib/mittsu/textures/texture.rb', line 15 def mipmaps @mipmaps end |
#name ⇒ Object
Returns the value of attribute name.
15 16 17 |
# File 'lib/mittsu/textures/texture.rb', line 15 def name @name end |
#offset ⇒ Object
Returns the value of attribute offset.
15 16 17 |
# File 'lib/mittsu/textures/texture.rb', line 15 def offset @offset end |
#on_update ⇒ Object
Returns the value of attribute on_update.
15 16 17 |
# File 'lib/mittsu/textures/texture.rb', line 15 def on_update @on_update end |
#opengl_texture ⇒ Object (readonly)
Returns the value of attribute opengl_texture.
3 4 5 |
# File 'lib/mittsu/renderers/opengl/textures/texture.rb', line 3 def opengl_texture @opengl_texture end |
#premultiply_alpha ⇒ Object
Returns the value of attribute premultiply_alpha.
15 16 17 |
# File 'lib/mittsu/textures/texture.rb', line 15 def premultiply_alpha @premultiply_alpha end |
#repeat ⇒ Object
Returns the value of attribute repeat.
15 16 17 |
# File 'lib/mittsu/textures/texture.rb', line 15 def repeat @repeat end |
#source_file ⇒ Object
Returns the value of attribute source_file.
15 16 17 |
# File 'lib/mittsu/textures/texture.rb', line 15 def source_file @source_file end |
#type ⇒ Object
Returns the value of attribute type.
13 14 15 |
# File 'lib/mittsu/textures/texture.rb', line 13 def type @type end |
#unpack_alignment ⇒ Object
Returns the value of attribute unpack_alignment.
15 16 17 |
# File 'lib/mittsu/textures/texture.rb', line 15 def unpack_alignment @unpack_alignment end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
13 14 15 |
# File 'lib/mittsu/textures/texture.rb', line 13 def uuid @uuid end |
#wrap_s ⇒ Object
Returns the value of attribute wrap_s.
15 16 17 |
# File 'lib/mittsu/textures/texture.rb', line 15 def wrap_s @wrap_s end |
#wrap_t ⇒ Object
Returns the value of attribute wrap_t.
15 16 17 |
# File 'lib/mittsu/textures/texture.rb', line 15 def wrap_t @wrap_t end |
Instance Method Details
#clone(texture = Texture.new) ⇒ Object
56 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 |
# File 'lib/mittsu/textures/texture.rb', line 56 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 |
#dispose ⇒ Object
87 88 89 |
# File 'lib/mittsu/textures/texture.rb', line 87 def dispose dispatch_event type: :dispose end |
#needs_update=(value) ⇒ Object
51 52 53 54 |
# File 'lib/mittsu/textures/texture.rb', line 51 def needs_update=(value) update if value @_needs_update = value end |
#needs_update? ⇒ Boolean
47 48 49 |
# File 'lib/mittsu/textures/texture.rb', line 47 def needs_update? @_needs_update end |
#set(slot, renderer) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/mittsu/renderers/opengl/textures/texture.rb', line 5 def set(slot, renderer) @renderer = renderer glActiveTexture(GL_TEXTURE0 + slot) if needs_update? update_opengl(@renderer) else glBindTexture(GL_TEXTURE_2D, @opengl_texture) end end |
#update ⇒ Object
83 84 85 |
# File 'lib/mittsu/textures/texture.rb', line 83 def update dispatch_event type: :update end |
#update_opengl(renderer) ⇒ Object
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 |
# File 'lib/mittsu/renderers/opengl/textures/texture.rb', line 17 def update_opengl(renderer) @renderer = renderer if !@initted @initted = true add_event_listener(:dispose, @renderer.method(:on_texture_dispose)) @opengl_texture = glCreateTexture @renderer.info[:memory][:textures] += 1 end glBindTexture(GL_TEXTURE_2D, @opengl_texture) # glPixelStorei(GL_UNPACK_FLIP_Y_WEBGL, flip_y) ??? # glPixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL, premultiply_alpha) ??? glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_alignment) self.image = @renderer.clamp_to_max_size(image) is_image_power_of_two = Math.power_of_two?(image.width) && Math.power_of_two?(image.height) set_parameters(GL_TEXTURE_2D, is_image_power_of_two) update_specific if generate_mipmaps && is_image_power_of_two glGenerateMipmap(GL_TEXTURE_2D) end self.needs_update = false on_update.call if on_update end |