Fixed reloading shader which failed to compile at start up but succeeded at runtime caused crash due to Model expecting access to attribute location of shader inputs

This commit is contained in:
2020-03-24 10:32:32 -05:00
parent 578c00673d
commit d839811cfd
3 changed files with 20 additions and 12 deletions

View File

@@ -53,11 +53,9 @@ class IMICFPS
end
end
if Shader.available?("default")
allocate_gl_objects
populate_vertex_buffer
configure_vao
end
allocate_gl_objects
populate_vertex_buffer
configure_vao
@objects.each {|o| @vertex_count+=o.vertices.size}
@objects.each_with_index do |o, i|
@@ -172,30 +170,33 @@ class IMICFPS
def configure_vao
glBindVertexArray(@vertex_array_id)
program = Shader.get("default").program
# index, size, type, normalized, stride, pointer
# vertices (positions)
glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id)
glVertexAttribPointer(glGetAttribLocation(program, "inPosition"), 3, GL_FLOAT, GL_FALSE, 0, nil)
# inPosition
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nil)
gl_error?
# colors
glBindBuffer(GL_ARRAY_BUFFER, @colors_buffer_id)
glVertexAttribPointer(glGetAttribLocation(program, "inColor"), 3, GL_FLOAT, GL_FALSE, 0, nil)
# inColor
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, nil)
gl_error?
# normals
glBindBuffer(GL_ARRAY_BUFFER, @normals_buffer_id)
glVertexAttribPointer(glGetAttribLocation(program, "inNormal"), 4, GL_FLOAT, GL_FALSE, 0, nil)
# inNormal
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, nil)
gl_error?
if has_texture?
# uvs
glBindBuffer(GL_ARRAY_BUFFER, @uvs_buffer_id)
glVertexAttribPointer(glGetAttribLocation(program, "inUV"), 3, GL_FLOAT, GL_FALSE, 0, nil)
# inUV
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, nil)
gl_error?
# texture ids
glBindBuffer(GL_ARRAY_BUFFER, @textures_buffer_id)
glVertexAttribPointer(glGetAttribLocation(program, "inTextureID"), 1, GL_FLOAT, GL_FALSE, 0, nil)
# inTextureID
glVertexAttribPointer(4, 1, GL_FLOAT, GL_FALSE, 0, nil)
gl_error?
end

View File

@@ -24,6 +24,8 @@ class IMICFPS
shader.uniform_vec3("lights[#{i}].diffuse", light.diffuse)
shader.uniform_vec3("lights[#{i}].specular", light.specular)
end
gl_error?
shader.uniform_integer("totalLights", lights.size)

View File

@@ -25,6 +25,8 @@ class IMICFPS
return
when 1
name = arguments.first
Shader.delete(name)
shader = Shader.new(
name: name,
includes_dir: "shaders/include",
@@ -34,6 +36,8 @@ class IMICFPS
when 2
vertex = arguments.first
fragment = arguments.last
Shader.remove(vertex)
shader = Shader.new(
name: vertex,
includes_dir: "shaders/include",
@@ -52,6 +56,7 @@ class IMICFPS
end
ensure
$stdout = stdout
puts string if string
end
def usage