From 917db342def84f9ce925df3cb27043b92ef2bfda Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 12 Feb 2021 00:19:53 +0200 Subject: [PATCH] Support setting a sampler directly in Renderer --- source/renderer.cpp | 11 ++++++++++- source/renderer.h | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/source/renderer.cpp b/source/renderer.cpp index d4cbbfe3..416a0fc8 100644 --- a/source/renderer.cpp +++ b/source/renderer.cpp @@ -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); } diff --git a/source/renderer.h b/source/renderer.h index a1217c77..2854bc8f 100644 --- a/source/renderer.h +++ b/source/renderer.h @@ -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 *); -- 2.45.2