Register loaders and add engine.loadScene that chooses the appropriate loader.
This commit is contained in:
parent
cea7df6947
commit
c3581a6054
5 changed files with 67 additions and 22 deletions
|
@ -33,8 +33,11 @@
|
||||||
{.warning[UseBase]: off.} # can't seem to satisy this...
|
{.warning[UseBase]: off.} # can't seem to satisy this...
|
||||||
{.warning[UnusedImport]: off.} # for ./loader_base
|
{.warning[UnusedImport]: off.} # for ./loader_base
|
||||||
|
|
||||||
|
const myouUseBlendLoader {.booldefine.} = true
|
||||||
|
|
||||||
import ../types
|
import ../types
|
||||||
import ./loader_base
|
import ./loader_base
|
||||||
|
export loader_base
|
||||||
import std/tables
|
import std/tables
|
||||||
import std/strutils
|
import std/strutils
|
||||||
import std/strformat
|
import std/strformat
|
||||||
|
@ -66,8 +69,9 @@ import float16
|
||||||
when defined(nimdoc):
|
when defined(nimdoc):
|
||||||
type TYPES* = BlendLoader
|
type TYPES* = BlendLoader
|
||||||
|
|
||||||
proc newBlendLoader*(engine: MyouEngine, use_indices:bool = true,
|
proc newBlendLoader*(engine: MyouEngine,
|
||||||
shader_library: string = "", shader_textures = initTable[string, Texture]()): BlendLoader =
|
shader_library: string = "",
|
||||||
|
shader_textures = initTable[string, Texture]()): BlendLoader =
|
||||||
result = new BlendLoader
|
result = new BlendLoader
|
||||||
result.engine = engine
|
result.engine = engine
|
||||||
if shader_library != "":
|
if shader_library != "":
|
||||||
|
@ -76,8 +80,13 @@ proc newBlendLoader*(engine: MyouEngine, use_indices:bool = true,
|
||||||
else:
|
else:
|
||||||
result.shader_library = get_builtin_shader_library()
|
result.shader_library = get_builtin_shader_library()
|
||||||
result.shader_textures = get_builtin_shader_textures()
|
result.shader_textures = get_builtin_shader_textures()
|
||||||
result.file_extensions = @["blend"]
|
result.use_indices = true
|
||||||
result.use_indices = use_indices
|
|
||||||
|
proc registerBlendLoader*(engine: MyouEngine) =
|
||||||
|
when myouUseBlendLoader:
|
||||||
|
engine.registerLoader(@["blend"], proc(e: MyouEngine): Loader =
|
||||||
|
e.newBlendLoader()
|
||||||
|
)
|
||||||
|
|
||||||
var used_resources: seq[LoadableResource]
|
var used_resources: seq[LoadableResource]
|
||||||
|
|
||||||
|
@ -584,3 +593,4 @@ method loadScene*(self: BlendLoader, name: string="", scene: Scene=nil, callback
|
||||||
|
|
||||||
proc debug_dump*(self: BlendLoader) =
|
proc debug_dump*(self: BlendLoader) =
|
||||||
self.blend_file.debug_dump
|
self.blend_file.debug_dump
|
||||||
|
|
||||||
|
|
|
@ -31,13 +31,22 @@
|
||||||
# version of this file under either the CPAL or the [AGPL-3] License.
|
# version of this file under either the CPAL or the [AGPL-3] License.
|
||||||
|
|
||||||
import ../types
|
import ../types
|
||||||
|
import std/tables
|
||||||
|
|
||||||
when defined(nimdoc):
|
when defined(nimdoc):
|
||||||
type TYPES* = Loader
|
type TYPES* = Loader
|
||||||
|
|
||||||
method openAssetFile*(self: Loader, path: string) {.base, locks: "unknown".} =
|
method openAssetFile*(self: Loader, path: string) {.base.} =
|
||||||
discard
|
discard
|
||||||
method loadScene*(self: Loader, name: string="", scene: Scene=nil): Scene {.base, locks: "unknown".} =
|
method loadScene*(self: Loader, name: string="", scene: Scene=nil,
|
||||||
|
callback: proc(scene: Scene)) {.base.} =
|
||||||
discard
|
discard
|
||||||
method loadImageImpl*(self: Loader) {.base, locks: "unknown".} =
|
method loadImageImpl*(self: Loader) {.base.} =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
proc registerLoader*(engine: MyouEngine,
|
||||||
|
extensions: seq[string],
|
||||||
|
constructor: proc(e: MyouEngine): Loader) =
|
||||||
|
|
||||||
|
for ext in extensions:
|
||||||
|
engine.loaders_by_ext.mgetOrPut(ext, @[]).add constructor
|
||||||
|
|
|
@ -74,6 +74,7 @@ import std/monotimes
|
||||||
import ./graphics/render
|
import ./graphics/render
|
||||||
import ./screen
|
import ./screen
|
||||||
import ./platform/platform
|
import ./platform/platform
|
||||||
|
import ./loaders/blend
|
||||||
import ./util
|
import ./util
|
||||||
import arr_ref
|
import arr_ref
|
||||||
|
|
||||||
|
@ -130,6 +131,8 @@ proc newMyouEngine*(
|
||||||
init_graphics(result, width, height, title, opengl_version, opengl_es)
|
init_graphics(result, width, height, title, opengl_version, opengl_es)
|
||||||
discard result.newScreen(width, height, title)
|
discard result.newScreen(width, height, title)
|
||||||
|
|
||||||
|
registerBlendLoader(result)
|
||||||
|
|
||||||
proc get_builtin_shader_library*(use_cubemap_prefiltering = true): string =
|
proc get_builtin_shader_library*(use_cubemap_prefiltering = true): string =
|
||||||
## Returns a string with the code of the default shader library of the
|
## Returns a string with the code of the default shader library of the
|
||||||
## engine. If you use this, you may want to also add the textures given by
|
## engine. If you use this, you may want to also add the textures given by
|
||||||
|
@ -179,3 +182,18 @@ proc run*(self: MyouEngine) =
|
||||||
last_time = getmonotime().ticks.float/1000000000
|
last_time = getmonotime().ticks.float/1000000000
|
||||||
when not defined(nimdoc):
|
when not defined(nimdoc):
|
||||||
start_platform_main_loop(self, myou_main_loop)
|
start_platform_main_loop(self, myou_main_loop)
|
||||||
|
|
||||||
|
proc loadScene*(self: MyouEngine, uri: string, callback: proc(scene: Scene), name = "", ext = "") =
|
||||||
|
let ext = if ext == "":
|
||||||
|
uri.rsplit('.', 1)[1]
|
||||||
|
else:
|
||||||
|
ext
|
||||||
|
|
||||||
|
if ext notin self.loaders_by_ext:
|
||||||
|
raise ValueError.newException "File extension not supported: " & ext
|
||||||
|
|
||||||
|
# TODO: use the next loader if the first one fails
|
||||||
|
let loaders = self.loaders_by_ext[ext]
|
||||||
|
let loader = loaders[0](self)
|
||||||
|
loader.openAssetFile(uri)
|
||||||
|
loader.loadScene(name, nil, callback)
|
||||||
|
|
|
@ -38,6 +38,16 @@ when defined(nimdoc):
|
||||||
type TYPES* = ProbeInfluenceType | ProbeParallaxType | CubemapProbe | CubemapProbeUniform | SH9Uniform
|
type TYPES* = ProbeInfluenceType | ProbeParallaxType | CubemapProbe | CubemapProbeUniform | SH9Uniform
|
||||||
|
|
||||||
# Forward declarations and ob type methods
|
# Forward declarations and ob type methods
|
||||||
|
proc newCubemapProbe*(engine: MyouEngine, name: string="camera", scene: Scene = nil,
|
||||||
|
influence_type: ProbeInfluenceType = SphereInfluence,
|
||||||
|
influence_distance: float32 = 2.5,
|
||||||
|
falloff: float32 = 0.2,
|
||||||
|
intensity: float32 = 1,
|
||||||
|
clipping_start: float32 = 0.8,
|
||||||
|
clipping_end: float32 = 40,
|
||||||
|
parallax_type: ProbeParallaxType = NoParallax,
|
||||||
|
parallax_distance: float32 = 0.0, # 0 means auto
|
||||||
|
): CubemapProbe
|
||||||
func getCubemapSideMatrix*(side: int, position = vec3()): Mat4
|
func getCubemapSideMatrix*(side: int, position = vec3()): Mat4
|
||||||
proc render_cubemap*(self: CubemapProbe, use_roughness_prefiltering = false, mipmap_shader: Material = nil)
|
proc render_cubemap*(self: CubemapProbe, use_roughness_prefiltering = false, mipmap_shader: Material = nil)
|
||||||
proc render_background_cubemap*(scene: Scene, use_roughness_prefiltering = false, mipmap_shader: Material = nil, world_to_cube_matrix: Mat4 = mat4(), upload_UBO = true)
|
proc render_background_cubemap*(scene: Scene, use_roughness_prefiltering = false, mipmap_shader: Material = nil, world_to_cube_matrix: Mat4 = mat4(), upload_UBO = true)
|
||||||
|
|
|
@ -81,6 +81,7 @@ type
|
||||||
renderer*: RenderManager
|
renderer*: RenderManager
|
||||||
tone_mapping_library*: string
|
tone_mapping_library*: string
|
||||||
tone_mapping_function*: string
|
tone_mapping_function*: string
|
||||||
|
loaders_by_ext*: Table[string, seq[proc(e: MyouEngine): Loader]]
|
||||||
# TODO: remove this and query it when screen is created
|
# TODO: remove this and query it when screen is created
|
||||||
width*, height*: int
|
width*, height*: int
|
||||||
glsl_version*: string
|
glsl_version*: string
|
||||||
|
@ -738,6 +739,16 @@ type
|
||||||
influence_distance*: float32
|
influence_distance*: float32
|
||||||
falloff*: float32
|
falloff*: float32
|
||||||
|
|
||||||
|
# loader_base.nim
|
||||||
|
|
||||||
|
Loader* = ref object of RootObj
|
||||||
|
engine*: MyouEngine
|
||||||
|
shader_library*: string
|
||||||
|
shader_textures*: Table[string, Texture]
|
||||||
|
# on_destroy*: OnDestroy
|
||||||
|
path_handler*: proc(path: string): string
|
||||||
|
override_textures_sampler_type*: Table[string, string]
|
||||||
|
|
||||||
# INCOMPLETE
|
# INCOMPLETE
|
||||||
|
|
||||||
Armature* = ref object of GameObject
|
Armature* = ref object of GameObject
|
||||||
|
@ -806,15 +817,6 @@ const HARDCODED_MAXUBOS* = 80
|
||||||
|
|
||||||
# LOADERS
|
# LOADERS
|
||||||
|
|
||||||
type Loader* = ref object of RootObj
|
|
||||||
engine*: MyouEngine
|
|
||||||
file_extensions*: seq[string]
|
|
||||||
shader_library*: string
|
|
||||||
shader_textures*: Table[string, Texture]
|
|
||||||
# on_destroy*: OnDestroy
|
|
||||||
path_handler*: proc(path: string): string
|
|
||||||
override_textures_sampler_type*: Table[string, string]
|
|
||||||
|
|
||||||
type BlendLoader* = ref object of Loader
|
type BlendLoader* = ref object of Loader
|
||||||
blend_file_path*: string ## private
|
blend_file_path*: string ## private
|
||||||
blend_file*: BlendFile ## private
|
blend_file*: BlendFile ## private
|
||||||
|
@ -823,10 +825,6 @@ type BlendLoader* = ref object of Loader
|
||||||
(string, seq[Varying], OrderedTable[string, string], OrderedTable[string, TexturePixels])] ## private
|
(string, seq[Varying], OrderedTable[string, string], OrderedTable[string, TexturePixels])] ## private
|
||||||
resource*: LoadableResource
|
resource*: LoadableResource
|
||||||
|
|
||||||
template AllLoaders*: untyped = @[
|
|
||||||
newBlendLoader,
|
|
||||||
]
|
|
||||||
|
|
||||||
template enqueue*(self: RenderManager, fun: proc()) =
|
template enqueue*(self: RenderManager, fun: proc()) =
|
||||||
if self.initialized:
|
if self.initialized:
|
||||||
fun()
|
fun()
|
||||||
|
|
Loading…
Reference in a new issue