]> git.tdb.fi Git - libs/gl.git/blobdiff - source/backends/opengl/program_backend.cpp
Use emplace_back when a new object is being constructed
[libs/gl.git] / source / backends / opengl / program_backend.cpp
index 1fc8c4420556257c19a5611ce66b9d212b86da86..a9328488cedc9bc12b5399bf55d2b032771dd52a 100644 (file)
@@ -12,6 +12,7 @@
 #include <msp/gl/extensions/khr_debug.h>
 #include <msp/gl/extensions/nv_non_square_matrices.h>
 #include <msp/io/print.h>
+#include "device.h"
 #include "error.h"
 #include "program.h"
 #include "program_backend.h"
@@ -45,6 +46,17 @@ OpenGLProgram::OpenGLProgram()
        id = glCreateProgram();
 }
 
+OpenGLProgram::OpenGLProgram(OpenGLProgram &&other):
+       id(other.id),
+       linked(other.linked),
+       uniform_calls(move(other.uniform_calls)),
+       debug_name(move(other.debug_name))
+{
+       move(other.stage_ids, other.stage_ids+MAX_STAGES, stage_ids);
+       other.id = 0;
+       fill(other.stage_ids, other.stage_ids+MAX_STAGES, 0);
+}
+
 OpenGLProgram::~OpenGLProgram()
 {
        for(unsigned i=0; i<MAX_STAGES; ++i)
@@ -89,7 +101,7 @@ unsigned OpenGLProgram::add_stage(Stage type)
 
 void OpenGLProgram::add_glsl_stages(const GlslModule &mod, const map<string, int> &spec_values, TransientData &transient)
 {
-       SL::Compiler compiler;
+       SL::Compiler compiler(Device::get_current().get_info().glsl_features);
        compiler.set_source(mod.get_prepared_source(), "<module>");
        compiler.specialize(spec_values);
        compiler.compile(SL::Compiler::PROGRAM);
@@ -262,7 +274,7 @@ void OpenGLProgram::query_uniforms()
                        if(len>3 && !strcmp(name+len-3, "[0]"))
                                name[len-3] = 0;
 
-                       rd.uniforms.push_back(ReflectData::UniformInfo());
+                       rd.uniforms.emplace_back();
                        ReflectData::UniformInfo &info = rd.uniforms.back();
                        info.name = name;
                        info.tag = name;
@@ -284,7 +296,7 @@ void OpenGLProgram::query_uniforms()
                query_uniform_blocks(uniforms_by_index);
        }
 
-       rd.uniform_blocks.push_back(ReflectData::UniformBlockInfo());
+       rd.uniform_blocks.emplace_back();
        ReflectData::UniformBlockInfo &default_block = rd.uniform_blocks.back();
 
        for(ReflectData::UniformInfo &u: rd.uniforms)
@@ -319,7 +331,7 @@ void OpenGLProgram::query_uniform_blocks(const vector<ReflectData::UniformInfo *
                char name[128];
                int len;
                glGetActiveUniformBlockName(id, i, sizeof(name), &len, name);
-               rd.uniform_blocks.push_back(ReflectData::UniformBlockInfo());
+               rd.uniform_blocks.emplace_back();
                ReflectData::UniformBlockInfo &info = rd.uniform_blocks.back();
                info.name = name;
 
@@ -396,7 +408,7 @@ void OpenGLProgram::query_attributes()
                        if(len>3 && !strcmp(name+len-3, "[0]"))
                                name[len-3] = 0;
 
-                       rd.attributes.push_back(ReflectData::AttributeInfo());
+                       rd.attributes.emplace_back();
                        ReflectData::AttributeInfo &info = rd.attributes.back();
                        info.name = name;
                        info.location = glGetAttribLocation(id, name);