Sha256: dcf626487a850b117fd59475d1e6f8c0c489cd125b2496a90995989ad89aac1e

Contents?: true

Size: 1.42 KB

Versions: 17

Compression:

Stored size: 1.42 KB

Contents

require 'mittsu/renderers/shaders/uniforms_utils'
require 'mittsu/renderers/shaders/uniforms_lib'
require 'mittsu/renderers/shaders/shader_chunk'
require 'mittsu/renderers/shaders/rbsl_loader'

module Mittsu
  class ShaderLib_Instance
    attr_accessor :uniforms, :vertex_shader, :fragment_shader
    def initialize(options = {})
      @uniforms = options.fetch(:uniforms)
      @vertex_shader = options.fetch(:vertex_shader)
      @fragment_shader = options.fetch(:fragment_shader)
    end

    def self.load_from_file(name)
      ShaderLib_Instance.new(
        uniforms: RBSLLoader.load_uniforms(File.read(File.join(__dir__, 'shader_lib', name, "#{name}_uniforms.rbslu")), UniformsLib),
        vertex_shader: RBSLLoader.load_shader(File.read(File.join(__dir__, 'shader_lib', name, "#{name}_vertex.rbsl")), ShaderChunk),
        fragment_shader: RBSLLoader.load_shader(File.read(File.join(__dir__, 'shader_lib', name, "#{name}_fragment.rbsl")), ShaderChunk)
      )
    end
  end
  private_constant :ShaderLib_Instance

  SHADER_LIB_HASH = Hash.new { |h, k|
    h[k] = ShaderLib_Instance.load_from_file(k.to_s)
  }

  class ShaderLib
    def self.create_shader(id, options={})
      shader = self[id]
      {
        uniforms: UniformsUtils.clone(shader.uniforms),
        vertex_shader: shader.vertex_shader,
        fragment_shader: shader.fragment_shader
      }.merge(options)
    end

    def self.[](id)
      SHADER_LIB_HASH[id]
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
mittsu-0.4.1 lib/mittsu/renderers/shaders/shader_lib.rb
mittsu-0.4.0 lib/mittsu/renderers/shaders/shader_lib.rb
mittsu-0.3.3 lib/mittsu/renderers/shaders/shader_lib.rb
mittsu-0.3.2 lib/mittsu/renderers/shaders/shader_lib.rb
mittsu-0.3.1 lib/mittsu/renderers/shaders/shader_lib.rb
mittsu-0.3.0 lib/mittsu/renderers/shaders/shader_lib.rb
mittsu-0.2.4 lib/mittsu/renderers/shaders/shader_lib.rb
mittsu-0.2.3 lib/mittsu/renderers/shaders/shader_lib.rb
mittsu-0.2.2 lib/mittsu/renderers/shaders/shader_lib.rb
mittsu-0.2.1 lib/mittsu/renderers/shaders/shader_lib.rb
mittsu-0.2.0 lib/mittsu/renderers/shaders/shader_lib.rb
mittsu-0.1.7 lib/mittsu/renderers/shaders/shader_lib.rb
mittsu-0.1.6 lib/mittsu/renderers/shaders/shader_lib.rb
mittsu-0.1.5 lib/mittsu/renderers/shaders/shader_lib.rb
mittsu-0.1.4 lib/mittsu/renderers/shaders/shader_lib.rb
mittsu-0.1.3 lib/mittsu/renderers/shaders/shader_lib.rb
mittsu-0.1.2 lib/mittsu/renderers/shaders/shader_lib.rb