GLProgram: load and store uniform locations
This commit is contained in:
1 parent
cad9bc056f
commit
914f08952b
4 files changed
+86
-28
No files matched your search
@@ -1,9 +1,14 @@
|
||||
class GLProgram
|
||||
# @overload initialize(*shaders, options = {})
|
||||
#
|
||||
# @param shaders [Array<GLShader>] Shaders to attach to the program.
|
||||
# @param options [Hash] Optional parameters.
|
||||
# @param shaders [Array<GLShader>]
|
||||
# Shaders to attach to the program.
|
||||
# @param options [Hash]
|
||||
# Optional parameters.
|
||||
# @option options [Array<String>] :uniforms
|
||||
# Names of uniforms to load locations of for this program.
|
||||
def initialize(*args)
|
||||
options = args.last.is_a?(Hash) ? args.pop : {}
|
||||
args.each do |arg|
|
||||
if arg.is_a?(GLShader)
|
||||
attach_shader(arg)
|
||||
@@ -11,6 +16,16 @@ class GLProgram
|
||||
raise NotImplementedError.new("Other arguments not yet implemented")
|
||||
end
|
||||
end
|
||||
options.each do |option, value|
|
||||
case option
|
||||
when :uniforms
|
||||
value.each do |uniform|
|
||||
load_uniform_location(uniform)
|
||||
end
|
||||
else
|
||||
raise "Unknown option #{option.inspect}"
|
||||
end
|
||||
end
|
||||
link
|
||||
end
|
||||
end
|
||||
+14
-3
@@ -36,11 +36,22 @@ class Window
|
||||
}
|
||||
|
||||
program_sources.each do |program, (v_src_fname, f_src_fname)|
|
||||
v_shader = GLShader.new(:vertex, Runtime.read(:shader, v_src_fname))
|
||||
v_src = Runtime.read(:shader, v_src_fname)
|
||||
v_shader = GLShader.new(:vertex, v_src)
|
||||
v_shader or raise "Could not find shader #{v_src_fname}"
|
||||
f_shader = GLShader.new(:fragment, Runtime.read(:shader, f_src_fname))
|
||||
|
||||
f_src = Runtime.read(:shader, f_src_fname)
|
||||
f_shader = GLShader.new(:fragment, f_src)
|
||||
f_shader or raise "Could not find shader #{f_src_fname}"
|
||||
@programs[program] = GLProgram.new(v_shader, f_shader)
|
||||
|
||||
uniforms = (v_src + f_src).lines.map do |line|
|
||||
if line =~ /\buniform\s.*\s(\S+);/
|
||||
$1
|
||||
end
|
||||
end.compact
|
||||
|
||||
@programs[program] = GLProgram.new(v_shader, f_shader,
|
||||
uniforms: uniforms)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user