#include <msp/strings/format.h>
#include "buffer.h"
#include "error.h"
-#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();
void Program::compile_glsl_stage(unsigned stage_id)
{
glCompileShader(stage_id);
- bool compiled = get_shader_i(stage_id, GL_COMPILE_STATUS);
+ int status = 0;
+ glGetShaderiv(stage_id, GL_COMPILE_STATUS, &status);
- GLsizei info_log_len = get_shader_i(stage_id, GL_INFO_LOG_LENGTH);
+ int info_log_len = 0;
+ glGetShaderiv(stage_id, GL_INFO_LOG_LENGTH, &info_log_len);
string info_log(info_log_len+1, 0);
glGetShaderInfoLog(stage_id, info_log_len+1, &info_log_len, &info_log[0]);
info_log.erase(info_log_len);
if(module && module->get_format()==Module::GLSL)
info_log = static_cast<const GlslModule *>(module)->get_source_map().translate_errors(info_log);
- if(!compiled)
+ if(!status)
throw compile_error(info_log);
#ifdef DEBUG
if(!info_log.empty())
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())
attributes.clear();
glLinkProgram(id);
- linked = get_program_i(id, GL_LINK_STATUS);
+ int status = 0;
+ glGetProgramiv(id, GL_LINK_STATUS, &status);
+ linked = status;
- GLsizei info_log_len = get_program_i(id, GL_INFO_LOG_LENGTH);
+ int info_log_len = 0;
+ glGetProgramiv(id, GL_INFO_LOG_LENGTH, &info_log_len);
string info_log(info_log_len+1, 0);
glGetProgramInfoLog(id, info_log_len+1, &info_log_len, &info_log[0]);
info_log.erase(info_log_len);
void Program::query_uniforms()
{
- unsigned count = get_program_i(id, GL_ACTIVE_UNIFORMS);
+ unsigned count = 0;
+ glGetProgramiv(id, GL_ACTIVE_UNIFORMS, reinterpret_cast<int *>(&count));
uniforms.reserve(count);
vector<string> uniform_names(count);
for(unsigned i=0; i<count; ++i)
void Program::query_uniform_blocks(const vector<UniformInfo *> &uniforms_by_index)
{
- unsigned count = get_program_i(id, GL_ACTIVE_UNIFORM_BLOCKS);
+ unsigned count = 0;
+ glGetProgramiv(id, GL_ACTIVE_UNIFORM_BLOCKS, reinterpret_cast<int *>(&count));
// Reserve an extra index for the default block
uniform_blocks.reserve(count+1);
for(unsigned i=0; i<count; ++i)
void Program::query_attributes()
{
- unsigned count = get_program_i(id, GL_ACTIVE_ATTRIBUTES);
+ unsigned count = 0;
+ glGetProgramiv(id, GL_ACTIVE_ATTRIBUTES, reinterpret_cast<int *>(&count));
attributes.reserve(count);
for(unsigned i=0; i<count; ++i)
{
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;