Shader is a resource
This commit is contained in:
parent
775975594b
commit
7631a8d26e
|
@ -73,7 +73,7 @@ int main()
|
|||
glfwSetKeyCallback(on_key);
|
||||
emscripten_set_mousemove_callback(nullptr, nullptr, false, on_em_mousemove);
|
||||
|
||||
exe = Program("textured").build(
|
||||
exe = Program(store, "textured").build(
|
||||
__attrib_count, attribs,
|
||||
__uniform_count, uniforms
|
||||
);
|
||||
|
|
|
@ -9,9 +9,9 @@ const std::string Program::filename(const std::string &name)
|
|||
return "/data/shaders/" + name;
|
||||
}
|
||||
|
||||
Program::Program(const std::string &name):
|
||||
vertex_shader(name + ".vert"),
|
||||
fragment_shader(name + ".frag")
|
||||
Program::Program(Store &store, const std::string &name):
|
||||
vertex_shader(store.load<Shader>(name + ".vert")),
|
||||
fragment_shader(store.load<Shader>(name + ".frag"))
|
||||
{}
|
||||
|
||||
const Executable *Program::build(
|
||||
|
@ -20,8 +20,8 @@ const Executable *Program::build(
|
|||
{
|
||||
Executable *exe = new Executable();
|
||||
|
||||
exe->attach_shader(vertex_shader);
|
||||
exe->attach_shader(fragment_shader);
|
||||
exe->attach_shader(*vertex_shader);
|
||||
exe->attach_shader(*fragment_shader);
|
||||
|
||||
for (GLuint attrib = 0; attrib < attrib_count; ++attrib)
|
||||
exe->bind_attrib_location(attrib, attribs[attrib]);
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
#ifndef _PROGRAM_HPP_
|
||||
#define _PROGRAM_HPP_
|
||||
|
||||
#include "shader.hpp"
|
||||
#include "executable.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
struct Program
|
||||
{
|
||||
Program(const std::string &name);
|
||||
Program(Store &store, const std::string &name);
|
||||
|
||||
const Executable *build(
|
||||
GLuint attrib_count, const GLchar *const attribs[],
|
||||
|
@ -16,8 +17,8 @@ struct Program
|
|||
private:
|
||||
static const std::string filename(const std::string &name);
|
||||
|
||||
const Shader vertex_shader;
|
||||
const Shader fragment_shader;
|
||||
const Shader *vertex_shader;
|
||||
const Shader *fragment_shader;
|
||||
};
|
||||
|
||||
#endif // _PROGRAM_HPP_
|
||||
|
|
|
@ -8,7 +8,7 @@ const std::string Shader::filename(const std::string &name)
|
|||
return "/data/shaders/" + name;
|
||||
}
|
||||
|
||||
Shader::Shader(const std::string &name)
|
||||
Shader::Shader(__attribute__((unused)) Store &store, const std::string &name)
|
||||
{
|
||||
const GLuint type = name.substr(name.size() - 5) == ".vert" ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER;
|
||||
|
||||
|
|
|
@ -2,17 +2,18 @@
|
|||
#define _SHADER_HPP_
|
||||
|
||||
#include "gl.hpp"
|
||||
#include "resource.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
struct Shader
|
||||
struct Shader:
|
||||
Resource
|
||||
{
|
||||
Shader(const std::string &filename);
|
||||
RESOURCE(Shader)
|
||||
|
||||
inline GLuint id() const { return _id; };
|
||||
|
||||
private:
|
||||
static const std::string filename(const std::string &name);
|
||||
|
||||
GLuint _id;
|
||||
};
|
||||
|
||||
|
|
Reference in New Issue