]> git.tdb.fi Git - libs/gl.git/commitdiff
Integrate ProgramCompiler with Program and Resources
authorMikko Rasa <tdb@tdb.fi>
Sat, 12 Nov 2016 00:25:49 +0000 (02:25 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 12 Nov 2016 00:25:49 +0000 (02:25 +0200)
source/program.cpp
source/program.h
source/resources.cpp
source/resources.h

index 82308b3405e0c42cc2086925c7633bd6b6a08770..2d298e82e9d29922a3c18b1d5236dadb25ae402b 100644 (file)
@@ -14,6 +14,7 @@
 #include "error.h"
 #include "misc.h"
 #include "program.h"
+#include "programcompiler.h"
 #include "shader.h"
 
 using namespace std;
@@ -35,6 +36,16 @@ Program::Program(const ProgramBuilder::StandardFeatures &features)
        link();
 }
 
+Program::Program(const std::string &source)
+{
+       init();
+
+       ProgramCompiler compiler;
+       compiler.compile(source);
+       compiler.add_shaders(*this);
+       link();
+}
+
 Program::Program(const string &vert, const string &frag)
 {
        init();
index 53f060d2d99fdf4fd92e55b3fefd4a956c54da2e..a3fe57bfbece6c409cf7e967191e580a5fd5c5ac 100644 (file)
@@ -80,6 +80,9 @@ public:
        /// Constructs a Program with standard features.
        Program(const ProgramBuilder::StandardFeatures &);
 
+       /// Constructs a Program from unified source code using ProgramCompiler.
+       Program(const std::string &);
+
        /// Constructs a Program from vertex and fragment shader source code.
        Program(const std::string &, const std::string &);
 
index 68b8fd5bdded8aa12489d7bda38c42a301e4c0f0..bba69315de900890e5c365a1c7a325e356394e63 100644 (file)
@@ -9,6 +9,7 @@
 #include "object.h"
 #include "pose.h"
 #include "program.h"
+#include "programcompiler.h"
 #include "resourcemanager.h"
 #include "resources.h"
 #include "technique.h"
@@ -35,7 +36,7 @@ Resources::Resources():
        add_type<Mesh>().keyword("mesh").creator(&Resources::create_mesh);
        add_type<Object>().keyword("object");
        add_type<Pose>().keyword("pose");
-       add_type<Program>().keyword("shader");
+       add_type<Program>().keyword("shader").suffix(".glsl").creator(&Resources::create_program);
        add_type<Technique>().suffix(".tech").keyword("technique");
        add_type<Texture1D>().base<Texture>().suffix(".tex1d").keyword("texture1d");
        add_type<Texture2D>().base<Texture>().suffix(".tex2d").suffix(".png").suffix(".jpg").keyword("texture2d").creator(&Resources::create_texture2d);
@@ -107,5 +108,24 @@ Texture2D *Resources::create_texture2d(const string &name)
        return 0;
 }
 
+Program *Resources::create_program(const string &name)
+{
+       string ext = FS::extpart(name);
+       if(ext==".shader")
+               return 0;
+
+       if(RefPtr<IO::Seekable> io = open_from_sources(name))
+       {
+               ProgramCompiler compiler;
+               compiler.compile(*io);
+               RefPtr<Program> program = new Program;
+               compiler.add_shaders(*program);
+               program->link();
+               return program.release();
+       }
+
+       return 0;
+}
+
 } // namespace GL
 } // namespace Msp
index e939f7cef8b9b9238fb3c2c28350c9e391832d04..1f3880aa431c86f69e278a07e951b9423a3273f4 100644 (file)
@@ -8,6 +8,7 @@ namespace Msp {
 namespace GL {
 
 class Mesh;
+class Program;
 class ResourceManager;
 class Texture2D;
 
@@ -38,6 +39,7 @@ public:
 protected:
        Mesh *create_mesh(const std::string &);
        Texture2D *create_texture2d(const std::string &);
+       Program *create_program(const std::string &);
 };
 
 } // namespace GL