X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fprogram.cpp;h=8bec2f6f488295474804d641516b825de8ef309a;hb=b877c737bc5f759e6da25f886ad965e4a274cf2a;hp=473d8a0b0d2c79e8a147e4b278e02ffbf303cb73;hpb=3a1b9cbe2441ae670a97541dc8ccb0a2860c8302;p=libs%2Fgl.git diff --git a/source/core/program.cpp b/source/core/program.cpp index 473d8a0b..8bec2f6f 100644 --- a/source/core/program.cpp +++ b/source/core/program.cpp @@ -19,10 +19,8 @@ #include #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; @@ -35,30 +33,6 @@ Program::Program() 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 &spec_values) { init(); @@ -187,16 +161,18 @@ void Program::add_glsl_stages(const GlslModule &mod, const map &spe 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(module)->get_source_map().translate_errors(info_log); - if(!compiled) + if(!status) throw compile_error(info_log); #ifdef DEBUG if(!info_log.empty()) @@ -255,61 +231,6 @@ void Program::add_spirv_stages(const SpirVModule &mod, const map &s 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 &Program::get_attached_shaders() const -{ - static vector 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()) @@ -320,9 +241,12 @@ void Program::link() 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); @@ -384,7 +308,8 @@ void Program::link() void Program::query_uniforms() { - unsigned count = get_program_i(id, GL_ACTIVE_UNIFORMS); + unsigned count = 0; + glGetProgramiv(id, GL_ACTIVE_UNIFORMS, reinterpret_cast(&count)); uniforms.reserve(count); vector uniform_names(count); for(unsigned i=0; i &uniforms_by_index) { - unsigned count = get_program_i(id, GL_ACTIVE_UNIFORM_BLOCKS); + unsigned count = 0; + glGetProgramiv(id, GL_ACTIVE_UNIFORM_BLOCKS, reinterpret_cast(&count)); // Reserve an extra index for the default block uniform_blocks.reserve(count+1); for(unsigned i=0; i &uniforms_by_inde void Program::query_attributes() { - unsigned count = get_program_i(id, GL_ACTIVE_ATTRIBUTES); + unsigned count = 0; + glGetProgramiv(id, GL_ACTIVE_ATTRIBUTES, reinterpret_cast(&count)); attributes.reserve(count); for(unsigned i=0; ilocationlocation; } -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); @@ -806,12 +724,6 @@ Program::Loader::Loader(Program &p, Collection &c): DataFile::CollectionObjectLoader(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() @@ -827,29 +739,6 @@ void Program::Loader::module(const string &n) obj.add_stages(get_collection().get(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;