Sha256: 370964ac592f6c68c03cc7d986e4f4ae4306178ccec4948edfa75d9ab9a33a4b

Contents?: true

Size: 1.44 KB

Versions: 23

Compression:

Stored size: 1.44 KB

Contents

require_relative 'helper'


class TestShader < Test::Unit::TestCase

  def color(*args)
    Rays::Color.new(*args)
  end

  def shader(vs = vshader, fs = fshader)
    Processing::Shader.new vs, fs
  end

  def vshader()
    "void main() {gl_Position = vec4(0.0, 0.0, 0.0, 1.0);}"
  end

  def fshader()
    "void main() {gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);}"
  end

  def test_initialize()
    assert shader vshader, fshader
    assert shader nil,     fshader

    assert_raise(ArgumentError) {shader "", fshader}
    assert_raise(ArgumentError) {shader vshader, ""}
    assert_raise(ArgumentError) {shader vshader, nil}
  end

  def test_uniform()
    sh = shader(nil, <<~END).tap {|s| s.set :val, 1.0}
      uniform float val;
      void main() {gl_FragColor = vec4(val, 0.0, 0.0, 1.0);}
    END

    graphics do |g, image|
      g.shader sh
      g.rect 0, 0, 10, 10
      assert_equal color(1, 0, 0, 1), image[0, 0]
    end
  end

  def test_shadertoy_shader()
    assert_equal <<~EXPECTED, shader(nil, <<~ACTUAL).instance_variable_get(:@shader).fragment_shader_source
      void mainImage(out vec4 fragColor, in vec2 fragCoord) {
      }
      varying vec4 vertTexCoord;
      void main() {
        mainImage(gl_FragColor, vertTexCoord.xy);
      }
    EXPECTED
      void mainImage(out vec4 fragColor, in vec2 fragCoord) {
      }
    ACTUAL
  end

  def test_inspect()
    assert_match %r|#<Processing::Shader:0x\w{16}>|, shader.inspect
  end

end# TestShader

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
processing-1.1 test/test_shader.rb
processing-1.0.3 test/test_shader.rb
processing-1.0.2 test/test_shader.rb
processing-1.0.1 test/test_shader.rb
processing-0.5.34 test/test_shader.rb
processing-0.5.33 test/test_shader.rb
processing-0.5.32 test/test_shader.rb
processing-0.5.31 test/test_shader.rb
processing-0.5.30 test/test_shader.rb
processing-0.5.29 test/test_shader.rb
processing-0.5.28 test/test_shader.rb
processing-0.5.27 test/test_shader.rb
processing-0.5.26 test/test_shader.rb
processing-0.5.25 test/test_shader.rb
processing-0.5.24 test/test_shader.rb
processing-0.5.23 test/test_shader.rb
processing-0.5.22 test/test_shader.rb
processing-0.5.21 test/test_shader.rb
processing-0.5.20 test/test_shader.rb
processing-0.5.19 test/test_shader.rb