Class: Glslkit::WebGL::Texture
- Inherits:
-
Object
- Object
- Glslkit::WebGL::Texture
- Defined in:
- lib/glslkit/webgl/texture.rb
Instance Attribute Summary collapse
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
Instance Method Summary collapse
- #bind ⇒ Object
-
#initialize(gl, width:, height:, data:, unit: 0) ⇒ Texture
constructor
A new instance of Texture.
Constructor Details
#initialize(gl, width:, height:, data:, unit: 0) ⇒ Texture
Returns a new instance of Texture.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/glslkit/webgl/texture.rb', line 8 def initialize(gl, width:, height:, data:, unit: 0) @gl = gl @unit = unit @handle = gl.call(:createTexture) pixels = JS.global[:Uint8Array].call(:from, data.to_js) bind gl.call(:texImage2D, gl[:TEXTURE_2D], 0, gl[:RGBA], width, height, 0, gl[:RGBA], gl[:UNSIGNED_BYTE], pixels) gl.call(:texParameteri, gl[:TEXTURE_2D], gl[:TEXTURE_MIN_FILTER], gl[:NEAREST]) gl.call(:texParameteri, gl[:TEXTURE_2D], gl[:TEXTURE_MAG_FILTER], gl[:NEAREST]) end |
Instance Attribute Details
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
6 7 8 |
# File 'lib/glslkit/webgl/texture.rb', line 6 def unit @unit end |
Instance Method Details
#bind ⇒ Object
20 21 22 23 24 |
# File 'lib/glslkit/webgl/texture.rb', line 20 def bind @gl.call(:activeTexture, @gl[:TEXTURE0].to_i + @unit) @gl.call(:bindTexture, @gl[:TEXTURE_2D], @handle) self end |