Class: Mittsu::OpenGLTexture
- Inherits:
-
Object
- Object
- Mittsu::OpenGLTexture
- Defined in:
- lib/mittsu/renderers/opengl/textures/opengl_texture.rb
Direct Known Subclasses
OpenGLCompressedTexture, OpenGLCubeTexture, OpenGLDataTexture, OpenGLRenderTarget
Instance Attribute Summary collapse
-
#opengl_texture ⇒ Object
readonly
Returns the value of attribute opengl_texture.
Instance Method Summary collapse
-
#initialize(texture, renderer) ⇒ OpenGLTexture
constructor
A new instance of OpenGLTexture.
- #set(slot) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(texture, renderer) ⇒ OpenGLTexture
Returns a new instance of OpenGLTexture.
5 6 7 8 9 |
# File 'lib/mittsu/renderers/opengl/textures/opengl_texture.rb', line 5 def initialize(texture, renderer) @texture = texture @renderer = renderer @initted = false end |
Instance Attribute Details
#opengl_texture ⇒ Object (readonly)
Returns the value of attribute opengl_texture.
3 4 5 |
# File 'lib/mittsu/renderers/opengl/textures/opengl_texture.rb', line 3 def opengl_texture @opengl_texture end |
Instance Method Details
#set(slot) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/mittsu/renderers/opengl/textures/opengl_texture.rb', line 11 def set(slot) glActiveTexture(GL_TEXTURE0 + slot) if @texture.needs_update? update else glBindTexture(GL_TEXTURE_2D, @opengl_texture) end end |
#update ⇒ Object
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 |
# File 'lib/mittsu/renderers/opengl/textures/opengl_texture.rb', line 21 def update if !@initted @initted = true @texture.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, texture.flip_y) ??? # glPixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiply_alpha) ??? glPixelStorei(GL_UNPACK_ALIGNMENT, @texture.unpack_alignment) image = @texture.image = @renderer.clamp_to_max_size(@texture.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 @texture.generate_mipmaps && is_image_power_of_two glGenerateMipmap(GL_TEXTURE_2D) end @texture.needs_update = false @texture.on_update.call if @texture.on_update end |