1
0
Fork 0

Shader is a resource

This commit is contained in:
Meoweg 2015-11-13 14:52:35 +00:00
parent 775975594b
commit 7631a8d26e
5 changed files with 16 additions and 14 deletions

View File

@ -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
);

View File

@ -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]);

View File

@ -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_

View File

@ -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;

View File

@ -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;
};