]> git.tdb.fi Git - libs/gl.git/commitdiff
Store materials and scenes using actual types
authorMikko Rasa <tdb@tdb.fi>
Tue, 5 Oct 2021 22:19:53 +0000 (01:19 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 6 Oct 2021 08:27:23 +0000 (11:27 +0300)
source/resources/resources.cpp

index 63a72404339435329206acc68f5b9df515fb7dc0..32f59d93d6e5a85f0bea998fd6bc446deb3fe88f 100644 (file)
@@ -2,28 +2,33 @@
 #include <msp/fs/utils.h>
 #include "animation.h"
 #include "armature.h"
 #include <msp/fs/utils.h>
 #include "animation.h"
 #include "armature.h"
+#include "basicmaterial.h"
 #include "camera.h"
 #include "error.h"
 #include "font.h"
 #include "keyframe.h"
 #include "light.h"
 #include "lighting.h"
 #include "camera.h"
 #include "error.h"
 #include "font.h"
 #include "keyframe.h"
 #include "light.h"
 #include "lighting.h"
-#include "material.h"
 #include "mesh.h"
 #include "module.h"
 #include "object.h"
 #include "mesh.h"
 #include "module.h"
 #include "object.h"
+#include "occludedscene.h"
+#include "orderedscene.h"
+#include "pbrmaterial.h"
 #include "sequencetemplate.h"
 #include "pose.h"
 #include "program.h"
 #include "resourcemanager.h"
 #include "resources.h"
 #include "sampler.h"
 #include "sequencetemplate.h"
 #include "pose.h"
 #include "program.h"
 #include "resourcemanager.h"
 #include "resources.h"
 #include "sampler.h"
-#include "scene.h"
+#include "simplescene.h"
 #include "technique.h"
 #include "texture1d.h"
 #include "texture2d.h"
 #include "texture2darray.h"
 #include "texturecube.h"
 #include "technique.h"
 #include "texture1d.h"
 #include "texture2d.h"
 #include "texture2darray.h"
 #include "texturecube.h"
+#include "unlitmaterial.h"
+#include "zsortedscene.h"
 #include "glsl/compiler.h"
 
 using namespace std;
 #include "glsl/compiler.h"
 
 using namespace std;
@@ -42,6 +47,9 @@ Resources::Resources(bool set_as_global):
 {
        add_type<Animation>().suffix(".anim").keyword("animation");
        add_type<Armature>().suffix(".arma").keyword("armature");
 {
        add_type<Animation>().suffix(".anim").keyword("animation");
        add_type<Armature>().suffix(".arma").keyword("armature");
+       add_type<BasicMaterial>().base<Material>().suffix(".mat")
+               .creator([this](const string &n) -> BasicMaterial * { create_generic<Material>(n); return 0; })
+               .notify(&set_debug_name<Material>);
        add_type<Camera>().keyword("camera")
                .notify(&set_debug_name<Camera>);
        add_type<Font>().keyword("font");
        add_type<Camera>().keyword("camera")
                .notify(&set_debug_name<Camera>);
        add_type<Font>().keyword("font");
@@ -49,15 +57,19 @@ Resources::Resources(bool set_as_global):
        add_type<Light>().keyword("light");
        add_type<Lighting>().suffix(".lightn").keyword("lighting")
                .notify(&set_debug_name<Lighting>);
        add_type<Light>().keyword("light");
        add_type<Lighting>().suffix(".lightn").keyword("lighting")
                .notify(&set_debug_name<Lighting>);
-       add_type<Material>().suffix(".mat")
-               .creator([this](const string &n){ return create_generic<Material>(n); })
-               .notify(&set_debug_name<Material>);
        add_type<Mesh>().keyword("mesh")
                .creator([this](const string &n){ return create_mesh(n); })
                .notify(&set_debug_name<Mesh>);
        add_type<Module>().suffix(".glsl").suffix(".spv")
                .creator([this](const string &n){ return create_module(n); });
        add_type<Object>().keyword("object");
        add_type<Mesh>().keyword("mesh")
                .creator([this](const string &n){ return create_mesh(n); })
                .notify(&set_debug_name<Mesh>);
        add_type<Module>().suffix(".glsl").suffix(".spv")
                .creator([this](const string &n){ return create_module(n); });
        add_type<Object>().keyword("object");
+       add_type<OccludedScene>().base<Scene>().suffix(".scene")
+               .creator([this](const string &n) -> OccludedScene * { create_generic<Scene>(n); return 0; });
+       add_type<OrderedScene>().base<Scene>().suffix(".scene")
+               .creator([this](const string &n) -> OrderedScene * { create_generic<Scene>(n); return 0; });
+       add_type<PbrMaterial>().base<Material>().suffix(".mat")
+               .creator([this](const string &n) -> PbrMaterial * { create_generic<Material>(n); return 0; })
+               .notify(&set_debug_name<Material>);
        add_type<SequenceTemplate>().suffix(".seq").keyword("sequence");
        add_type<Pose>().keyword("pose");
        add_type<Program>().keyword("shader")
        add_type<SequenceTemplate>().suffix(".seq").keyword("sequence");
        add_type<Pose>().keyword("pose");
        add_type<Program>().keyword("shader")
@@ -65,8 +77,8 @@ Resources::Resources(bool set_as_global):
                .notify(&set_debug_name<Program>);
        add_type<Sampler>().suffix(".samp").keyword("sampler")
                .notify(&set_debug_name<Sampler>);
                .notify(&set_debug_name<Program>);
        add_type<Sampler>().suffix(".samp").keyword("sampler")
                .notify(&set_debug_name<Sampler>);
-       add_type<Scene>().suffix(".scene")
-               .creator([this](const string &n){ return create_generic<Scene>(n); });
+       add_type<SimpleScene>().base<Scene>().suffix(".scene")
+               .creator([this](const string &n) -> SimpleScene * { create_generic<Scene>(n); return 0; });
        add_type<Technique>().suffix(".tech").keyword("technique")
                .notify(&set_debug_name<Technique>);
        add_type<Texture1D>().base<Texture>().suffix(".tex1d").keyword("texture1d")
        add_type<Technique>().suffix(".tech").keyword("technique")
                .notify(&set_debug_name<Technique>);
        add_type<Texture1D>().base<Texture>().suffix(".tex1d").keyword("texture1d")
@@ -80,6 +92,11 @@ Resources::Resources(bool set_as_global):
                .notify(&set_debug_name<TextureCube>);
        add_type<Texture2DArray>().base<Texture>().suffix(".tex2da").keyword("texture2d_array")
                .notify(&set_debug_name<Texture2DArray>);
                .notify(&set_debug_name<TextureCube>);
        add_type<Texture2DArray>().base<Texture>().suffix(".tex2da").keyword("texture2d_array")
                .notify(&set_debug_name<Texture2DArray>);
+       add_type<UnlitMaterial>().base<Material>().suffix(".mat")
+               .creator([this](const string &n) -> UnlitMaterial * { create_generic<Material>(n); return 0; })
+               .notify(&set_debug_name<Material>);
+       add_type<ZSortedScene>().base<Scene>().suffix(".scene")
+               .creator([this](const string &n) -> ZSortedScene * { create_generic<Scene>(n); return 0; });
 
        add_source(get_builtins());
 
 
        add_source(get_builtins());
 
@@ -133,7 +150,7 @@ T *Resources::create_generic(const string &name)
                DataFile::Parser parser(*io, name);
                typename T::GenericLoader ldr(*this);
                ldr.load(parser);
                DataFile::Parser parser(*io, name);
                typename T::GenericLoader ldr(*this);
                ldr.load(parser);
-               return ldr.get_object();
+               ldr.store_object(*this, name);
        }
 
        return 0;
        }
 
        return 0;