]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/pipelinestate.h
Unify handling of shader resources in PipelineState
[libs/gl.git] / source / core / pipelinestate.h
index 28624ed7ca64a5a0e5bba111cf45b27477bb11e5..e7fdfdc83ff6e17be21b35e0c01b0e8b4c02fcb2 100644 (file)
@@ -32,27 +32,32 @@ class PipelineState: public PipelineStateBackend
        friend PipelineStateBackend;
 
 private:
-       struct BoundTexture
+       enum ResourceType: std::uint8_t
        {
-               unsigned binding = 0;
-               mutable bool changed = false;
-               mutable bool used = false;
-               const Texture *texture = 0;
-               const Sampler *sampler = 0;
-               int level = -1;
-
-               BoundTexture(unsigned b): binding(b) { }
+               NO_RESOURCE,
+               UNIFORM_BLOCK,
+               TEXTURE
        };
 
-       struct BoundUniformBlock
+       struct BoundResource
        {
                int binding = 0;
+               ResourceType type = NO_RESOURCE;
                mutable bool changed = false;
                mutable bool used = false;
-               const UniformBlock *block = 0;
-               const Buffer *buffer = 0;
+               union
+               {
+                       const UniformBlock *block;
+                       const Texture *texture;
+               };
+               union
+               {
+                       const Buffer *buffer;
+                       const Sampler *sampler;
+               };
+               int mip_level = -1;
 
-               BoundUniformBlock(int b): binding(b) { }
+               BoundResource(int b): binding(b), texture(0), sampler(0) { }
        };
 
        enum ChangeMask
@@ -61,8 +66,7 @@ private:
                VIEWPORT = 2,
                SCISSOR = 4,
                SHPROG = 8,
-               UNIFORMS = 16,
-               TEXTURES = 32,
+               RESOURCES = 16,
                VERTEX_SETUP = 64,
                FACE_CULL = 128,
                DEPTH_TEST = 256,
@@ -75,8 +79,7 @@ private:
        Rect viewport = Rect::max();
        Rect scissor = Rect::max();
        const Program *shprog = 0;
-       std::vector<BoundUniformBlock> uniform_blocks;
-       std::vector<BoundTexture> textures;
+       std::vector<BoundResource> resources;
        const VertexSetup *vertex_setup = 0;
        PrimitiveType primitive_type = TRIANGLES;
        FaceWinding front_face = COUNTERCLOCKWISE;