#include "misc.h"
#include "program.h"
#include "resources.h"
-#include "shader.h"
#include "glsl/compiler.h"
using namespace std;
init();
}
-Program::Program(const string &source)
-{
- init();
-
- GlslModule mod;
- mod.set_source(source);
- add_stages(mod);
-
- link();
- module = 0;
-}
-
-Program::Program(const string &vert, const string &frag)
-{
- init();
-
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
- attach_shader_owned(new VertexShader(vert));
- attach_shader_owned(new FragmentShader(frag));
-#pragma GCC diagnostic pop
- link();
-}
-
Program::Program(const Module &mod, const map<string, int> &spec_values)
{
init();
used_stage_ids[n_stages++] = stage_id;
}
- const vector<UInt32> &code = mod.get_code();
+ const vector<uint32_t> &code = mod.get_code();
glShaderBinary(n_stages, used_stage_ids, GL_SHADER_BINARY_FORMAT_SPIR_V, &code[0], code.size()*4);
if(!spec_values.empty() && !transient)
glSpecializeShader(stage_ids[i], j->name.c_str(), spec_id_array.size(), &spec_id_array[0], &spec_value_array[0]);
}
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-void Program::attach_shader(Shader &shader)
-{
- unsigned shader_id = shader.steal_id();
- if(!shader_id)
- throw invalid_argument("Program::attach_shader");
-
- int type;
- glGetShaderiv(shader_id, GL_SHADER_TYPE, &type);
- switch(type)
- {
- case GL_VERTEX_SHADER: stage_ids[VERTEX] = shader_id; break;
- case GL_GEOMETRY_SHADER: stage_ids[GEOMETRY] = shader_id; break;
- case GL_FRAGMENT_SHADER: stage_ids[FRAGMENT] = shader_id; break;
- }
-
- glAttachShader(id, shader_id);
- compile_glsl_stage(shader_id);
-}
-
-void Program::attach_shader_owned(Shader *shader)
-{
- attach_shader(*shader);
- delete shader;
-}
-
-void Program::detach_shader(Shader &)
-{
-}
-
-const vector<Shader *> &Program::get_attached_shaders() const
-{
- static vector<Shader *> dummy;
- return dummy;
-}
-
-void Program::bind_attribute(unsigned index, const string &name)
-{
- static Require _req(ARB_vertex_shader);
- glBindAttribLocation(id, index, name.c_str());
-}
-
-void Program::bind_attribute(VertexAttribute attr, const string &name)
-{
- bind_attribute(get_attribute_semantic(attr), name);
-}
-
-void Program::bind_fragment_data(unsigned index, const string &name)
-{
- static Require _req(EXT_gpu_shader4);
- glBindFragDataLocation(id, index, name.c_str());
-}
-#pragma GCC diagnostic pop
-
void Program::link()
{
if(!has_stages())
return uni1->location<uni2->location;
}
-string Program::get_info_log() const
-{
- GLsizei len = get_program_i(id, GL_INFO_LOG_LENGTH);
- string log(len+1, 0);
- glGetProgramInfoLog(id, len+1, &len, &log[0]);
- log.erase(len);
- return log;
-}
-
const Program::UniformBlockInfo &Program::get_uniform_block_info(const string &name) const
{
auto i = find_member(uniform_blocks, name, &UniformBlockInfo::name);
DataFile::CollectionObjectLoader<Program>(p, &c)
{
add("module", &Loader::module);
-
- // Deprecated
- add("attribute", &Loader::attribute);
- add("fragment_shader", &Loader::fragment_shader);
- add("geometry_shader", &Loader::geometry_shader);
- add("vertex_shader", &Loader::vertex_shader);
}
void Program::Loader::finish()
obj.add_stages(get_collection().get<Module>(n), spec_values);
}
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-void Program::Loader::attribute(unsigned i, const string &n)
-{
- obj.bind_attribute(i, n);
-}
-
-void Program::Loader::fragment_shader(const string &src)
-{
- obj.attach_shader_owned(new FragmentShader(src));
-}
-
-void Program::Loader::geometry_shader(const string &src)
-{
- obj.attach_shader_owned(new GeometryShader(src));
-}
-
-void Program::Loader::vertex_shader(const string &src)
-{
- obj.attach_shader_owned(new VertexShader(src));
-}
-#pragma GCC diagnostic pop
-
DataFile::Loader::ActionMap Program::SpecializationLoader::shared_actions;