]> git.tdb.fi Git - libs/gl.git/blobdiff - source/programdata.cpp
Add 3x3 and 2x2 uniform matrices
[libs/gl.git] / source / programdata.cpp
index b8a272c0fc0bde8a3699a81e347115327c41938f..1ecd3a1dc42eaef6a62785f3fa4f07e1809a6405 100644 (file)
@@ -1,7 +1,7 @@
+#include "arb_shader_objects.h"
 #include "buffer.h"
 #include "color.h"
 #include "error.h"
-#include "extension.h"
 #include "matrix.h"
 #include "program.h"
 #include "programdata.h"
@@ -19,7 +19,7 @@ ProgramData::ProgramData():
        buffer(0),
        changes(NO_CHANGES)
 {
-       static RequireExtension _ext("GL_ARB_shader_objects");
+       static Require _req(ARB_shader_objects);
 }
 
 // Blocks are intentionally left uncopied
@@ -39,6 +39,7 @@ ProgramData::~ProgramData()
                delete i->second;
        for(BlockMap::iterator i=blocks.begin(); i!=blocks.end(); ++i)
                delete i->second.block;
+       delete buffer;
 }
 
 void ProgramData::uniform(const string &name, Uniform *uni)
@@ -46,6 +47,9 @@ void ProgramData::uniform(const string &name, Uniform *uni)
        UniformMap::iterator i = uniforms.find(name);
        if(i!=uniforms.end())
        {
+               /* UniformBlock does not copy the uniforms, so existing blocks will be
+               left with stale pointers.  This is not a problem as long as no one stores
+               pointers to the blocks and expects them to stay valid. */
                delete i->second;
                i->second = uni;
                changes = VALUES_CHANGED;
@@ -115,6 +119,16 @@ void ProgramData::uniform4(const string &name, const float *v)
        uniform(name, new Uniform4f(v));
 }
 
+void ProgramData::uniform_matrix2(const string &name, const float *v)
+{
+       uniform(name, new UniformMatrix2x2f(v));
+}
+
+void ProgramData::uniform_matrix3(const string &name, const float *v)
+{
+       uniform(name, new UniformMatrix3x3f(v));
+}
+
 void ProgramData::uniform_matrix4(const string &name, const float *v)
 {
        uniform(name, new UniformMatrix4x4f(v));
@@ -168,7 +182,10 @@ UniformBlock *ProgramData::create_block(const Program::UniformBlockInfo &info) c
 {
        UniformBlock *block = new UniformBlock(info.data_size);
        if(!buffer)
+       {
                buffer = new Buffer(UNIFORM_BUFFER);
+               buffer->set_usage(STREAM_DRAW);
+       }
        block->use_buffer(buffer, last_block);
        last_block = block;
        return block;