Material: Make scene optional, fix typo, other minor changes.
This commit is contained in:
parent
fb50b3a018
commit
0b5cd6f8d2
1 changed files with 12 additions and 12 deletions
|
@ -40,7 +40,7 @@ when defined(nimdoc):
|
||||||
|
|
||||||
# Forward declarations
|
# Forward declarations
|
||||||
func add_line_numbers(s: string, first: int=1):string
|
func add_line_numbers(s: string, first: int=1):string
|
||||||
proc newMaterial*(engine: MyouEngine, name: string, scene: Scene,
|
proc newMaterial*(engine: MyouEngine, name: string, scene: Scene = nil,
|
||||||
vertex = "",
|
vertex = "",
|
||||||
fragment = "",
|
fragment = "",
|
||||||
textures = initOrderedTable[string, Texture](),
|
textures = initOrderedTable[string, Texture](),
|
||||||
|
@ -122,7 +122,7 @@ func add_line_numbers(s: string, first: int=1):string =
|
||||||
lines[i] = $(i+first) & " " & line
|
lines[i] = $(i+first) & " " & line
|
||||||
return lines.join("\n")
|
return lines.join("\n")
|
||||||
|
|
||||||
proc newMaterial*(engine: MyouEngine, name: string, scene: Scene,
|
proc newMaterial*(engine: MyouEngine, name: string, scene: Scene = nil,
|
||||||
vertex = "",
|
vertex = "",
|
||||||
fragment = "",
|
fragment = "",
|
||||||
textures = initOrderedTable[string, Texture](),
|
textures = initOrderedTable[string, Texture](),
|
||||||
|
@ -166,7 +166,7 @@ proc newSolidMaterial*(engine: MyouEngine, name: string, color: Vec4): Material
|
||||||
}}""",
|
}}""",
|
||||||
)
|
)
|
||||||
|
|
||||||
proc newVertexColordMaterial*(engine: MyouEngine, name: string): Material =
|
proc newVertexColorMaterial*(engine: MyouEngine, name = "vertex color"): Material =
|
||||||
newMaterial(engine, name, nil,
|
newMaterial(engine, name, nil,
|
||||||
fragment = dedent """
|
fragment = dedent """
|
||||||
in vec4 vcol;
|
in vec4 vcol;
|
||||||
|
@ -190,7 +190,7 @@ proc get_shader*(self: Material, mesh: Mesh): Shader =
|
||||||
shader = new Shader
|
shader = new Shader
|
||||||
self.shaders[mesh.layout] = shader
|
self.shaders[mesh.layout] = shader
|
||||||
self.last_shader = shader
|
self.last_shader = shader
|
||||||
shader.initShader(self.engine, self, mesh.data.layout & mesh.data.tf_layout,
|
shader.initShader(self.engine, self, mesh.data.layout & mesh.data.tf_layout,
|
||||||
mesh.vertex_modifiers, mesh.material_defines)
|
mesh.vertex_modifiers, mesh.material_defines)
|
||||||
return shader
|
return shader
|
||||||
|
|
||||||
|
@ -404,7 +404,7 @@ proc initShader*(self: Shader, engine: MyouEngine, material: Material,
|
||||||
@[]) & varyings_assign & modifiers_post_bodies &
|
@[]) & varyings_assign & modifiers_post_bodies &
|
||||||
"gl_Position = proj_co;\n}"
|
"gl_Position = proj_co;\n}"
|
||||||
).join("\n ")
|
).join("\n ")
|
||||||
vs = (version_line & extension_lines & vs_head & varyings_uniform_decl &
|
vs = (version_line & extension_lines & vs_head & varyings_uniform_decl &
|
||||||
attribute_lines & vertex_shader_library & modifiers_uniforms & varyings_decl & vs_body).join("\n")
|
attribute_lines & vertex_shader_library & modifiers_uniforms & varyings_decl & vs_body).join("\n")
|
||||||
when defined(myouStoreGLSL):
|
when defined(myouStoreGLSL):
|
||||||
self.vs_code = vs
|
self.vs_code = vs
|
||||||
|
@ -502,6 +502,8 @@ proc initShader*(self: Shader, engine: MyouEngine, material: Material,
|
||||||
|
|
||||||
# TODO: use KHR_parallel_shader_compile
|
# TODO: use KHR_parallel_shader_compile
|
||||||
|
|
||||||
|
# TODO: identify unused uniforms (at least unused textures)
|
||||||
|
|
||||||
var ubo_names = newSeqOfCap[string](material.ubos.len)
|
var ubo_names = newSeqOfCap[string](material.ubos.len)
|
||||||
self.ubos.setLen 0
|
self.ubos.setLen 0
|
||||||
for ubo in material.ubos & modifier_ubos:
|
for ubo in material.ubos & modifier_ubos:
|
||||||
|
@ -515,31 +517,31 @@ proc initShader*(self: Shader, engine: MyouEngine, material: Material,
|
||||||
assert ubo.name notin ubo_names, "There's more than one UBO with name " & ubo.name & " in {material.name}"
|
assert ubo.name notin ubo_names, "There's more than one UBO with name " & ubo.name & " in {material.name}"
|
||||||
ubo_names.add ubo.name
|
ubo_names.add ubo.name
|
||||||
ubo_names.setLen 0
|
ubo_names.setLen 0
|
||||||
|
|
||||||
self.texture_locations.setLen 0
|
self.texture_locations.setLen 0
|
||||||
var extra_location_count = 0
|
var extra_location_count = 0
|
||||||
for name in material.textures.keys:
|
for name in material.textures.keys:
|
||||||
self.texture_locations.add glGetUniformLocation(prog, name.cstring)
|
self.texture_locations.add glGetUniformLocation(prog, name.cstring)
|
||||||
if defined(myouEnsureTextureLocations) and not defined(release):
|
if defined(myouEnsureTextureLocations) and not defined(release):
|
||||||
assert self.texture_locations[^1] != -1, "invalid texture location for " & name
|
assert self.texture_locations[^1] != -1, "invalid texture location for " & name
|
||||||
|
|
||||||
self.cubemap_locations.setLen 0
|
self.cubemap_locations.setLen 0
|
||||||
self.shadowmap_location = -1
|
self.shadowmap_location = -1
|
||||||
if material.scene != nil:
|
if material.scene != nil:
|
||||||
self.shadowmap_location = glGetUniformLocation(prog, "shadow_maps".cstring)
|
self.shadowmap_location = glGetUniformLocation(prog, "shadow_maps".cstring)
|
||||||
if self.shadowmap_location != -1:
|
if self.shadowmap_location != -1:
|
||||||
extra_location_count.inc
|
extra_location_count.inc
|
||||||
|
|
||||||
for i in 0 ..< material.scene.max_cubemaps:
|
for i in 0 ..< material.scene.max_cubemaps:
|
||||||
# TODO: test with a single glUniform1iv instead of changing
|
# TODO: test with a single glUniform1iv instead of changing
|
||||||
# the individual array elements
|
# the individual array elements
|
||||||
self.cubemap_locations.add glGetUniformLocation(prog,
|
self.cubemap_locations.add glGetUniformLocation(prog,
|
||||||
(&"cube_maps[{i}]").cstring)
|
(&"cube_maps[{i}]").cstring)
|
||||||
# when not defined(release):
|
# when not defined(release):
|
||||||
# assert self.shadowmap_locations[^1] != -1
|
# assert self.shadowmap_locations[^1] != -1
|
||||||
# dump material.name
|
# dump material.name
|
||||||
# dump self.cubemap_locations
|
# dump self.cubemap_locations
|
||||||
|
|
||||||
assert self.texture_locations.len + self.cubemap_locations.len +
|
assert self.texture_locations.len + self.cubemap_locations.len +
|
||||||
extra_location_count <= self.engine.renderer.max_textures
|
extra_location_count <= self.engine.renderer.max_textures
|
||||||
|
|
||||||
|
@ -551,5 +553,3 @@ proc use*(self: Shader): GLuint {.inline,discardable.} =
|
||||||
|
|
||||||
proc destroy*(self: Shader) =
|
proc destroy*(self: Shader) =
|
||||||
self.program = 0.GPUProgram
|
self.program = 0.GPUProgram
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue