Class: Glslkit::WebGL::Texture

Inherits:
Object
  • Object
show all
Defined in:
lib/glslkit/webgl/texture.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#unitObject (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

#bindObject



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