};
private:
- struct BoundTexture
+ struct SampledTexture
{
- Tag tag;
- mutable int binding = -1;
const Texture *texture = 0;
const Sampler *sampler = 0;
int level = -1;
+
+ SampledTexture() = default;
+ SampledTexture(const Texture *t, const Sampler *s, int l): texture(t), sampler(s), level(l) { }
+
+ bool operator==(const SampledTexture &o) const { return texture==o.texture && sampler==o.sampler && level==o.level; }
+ };
+
+ template<typename T>
+ struct BoundResource
+ {
+ Tag tag;
+ mutable int binding = -1;
int replaced = -1;
+ T resource;
};
struct BoundProgramData
State *current_state = 0;
ProgramData standard_shdata;
std::vector<BoundProgramData> shdata_stack;
- std::vector<BoundTexture> texture_stack;
+ std::vector<BoundResource<SampledTexture>> texture_stack;
const Texture &placeholder_texture;
const Sampler &default_sampler;
PipelineState *last_pipeline = 0;
void set_texture(Tag, const Texture *, int, const Sampler * = 0);
private:
+ template<typename T>
+ static void set_resource(std::vector<BoundResource<T>> &, unsigned &, Tag, const T &);
+
void flush_shader_data();
- void flush_textures();
+
+ template<typename T>
+ static void flush_resources(std::vector<BoundResource<T>> &, unsigned &);
public:
void set_vertex_setup(const VertexSetup *);