]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/pipelinestate.cpp
Support binding individual mipmap levels of textures
[libs/gl.git] / source / core / pipelinestate.cpp
index 076eb333d29b127a0d08ef38ec158223fb957179..210a0703868035dc69572fc56cc50eaf67b9ff08 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdexcept>
 #include <msp/core/algorithm.h>
+#include "error.h"
 #include "pipelinestate.h"
 
 using namespace std;
@@ -52,18 +53,26 @@ void PipelineState::set_uniform_block(int binding, const UniformBlock *block)
 }
 
 void PipelineState::set_texture(unsigned binding, const Texture *tex, const Sampler *samp)
+{
+       set_texture(binding, tex, -1, samp);
+}
+
+void PipelineState::set_texture(unsigned binding, const Texture *tex, int level, const Sampler *samp)
 {
        if((tex!=0)!=(samp!=0))
                throw invalid_argument("PipelineState::set_texture");
+       if(level>=0 && !can_bind_tex_level(level))
+               throw invalid_operation("PipelineState::set_texture");
 
        auto i = lower_bound_member(textures, binding, &BoundTexture::binding);
        if(i==textures.end() || i->binding!=binding)
                i = textures.insert(i, BoundTexture(binding));
        i->used = (tex && samp);
-       if(tex!=i->texture || samp!=i->sampler)
+       if(tex!=i->texture || level!=i->level || samp!=i->sampler)
        {
                i->texture = tex;
                i->sampler = samp;
+               i->level = level;
                i->changed = true;
                changes |= TEXTURES;
        }