]> git.tdb.fi Git - libs/gl.git/commitdiff
Support setting a sampler directly in Renderer
authorMikko Rasa <tdb@tdb.fi>
Thu, 11 Feb 2021 22:19:53 +0000 (00:19 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 11 Feb 2021 22:19:53 +0000 (00:19 +0200)
source/renderer.cpp
source/renderer.h

index d4cbbfe3454e39ef91a881bcf72cb8e06e00628a..416a0fc89ced4827147982f234ca009fb94576c0 100644 (file)
@@ -9,6 +9,7 @@
 #include "programdata.h"
 #include "renderable.h"
 #include "renderer.h"
+#include "sampler.h"
 #include "texture.h"
 #include "texturing.h"
 #include "texunit.h"
@@ -73,9 +74,10 @@ void Renderer::transform(const Matrix &matrix)
        changed |= MATRIX;
 }
 
-void Renderer::set_texture(const Texture *t)
+void Renderer::set_texture(const Texture *t, const Sampler *s)
 {
        state->texture = t;
+       state->sampler = s;
        state->texturing = 0;
 }
 
@@ -83,6 +85,7 @@ void Renderer::set_texturing(const Texturing *t)
 {
        state->texturing = t;
        state->texture = 0;
+       state->sampler = 0;
 }
 
 unsigned Renderer::allocate_effect_texunit()
@@ -283,7 +286,13 @@ void Renderer::apply_state()
        {
                Texturing::unbind();
                if(state->texture)
+               {
+                       if(state->sampler)
+                               state->sampler->bind_to(0);
+                       else
+                               Sampler::unbind_from(0);
                        state->texture->bind_to(0);
+               }
                else
                        Texture::unbind_from(0);
        }
index a1217c77833216266e51a014c4984e0f4a056a59..2854bc8ff181f3ead7f0f19ec9b0ec56d79b0470 100644 (file)
@@ -19,6 +19,7 @@ class Mesh;
 class Lighting;
 class Program;
 class Renderable;
+class Sampler;
 class Texture;
 class Texturing;
 class VertexSetup;
@@ -68,6 +69,7 @@ private:
                const Camera *camera;
                Matrix modelview_matrix;
                const Texture *texture;
+               const Sampler *sampler;
                const Texturing *texturing;
                unsigned lowest_effect_texunit;
                const Material *material;
@@ -124,7 +126,7 @@ public:
        /** Returns the current modelview matrix. */
        const Matrix &get_matrix() const { return state->modelview_matrix; }
 
-       void set_texture(const Texture *);
+       void set_texture(const Texture *, const Sampler * = 0);
        void set_texturing(const Texturing *);
        unsigned allocate_effect_texunit();
        void set_material(const Material *);