]> git.sesse.net Git - movit/blobdiff - effect_chain.h
Use UBOs instead of glUniform. Work in progress; no clear wins seen yet.
[movit] / effect_chain.h
index 2e89c3bcc38717473c10f8b05cfffe80a68b9689..de50512f204b7f15fd67f9620307026c44fad528 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <epoxy/gl.h>
 #include <stdio.h>
+#include <list>
 #include <map>
 #include <set>
 #include <string>
@@ -147,6 +148,11 @@ struct Phase {
        Node *output_node;
 
        GLuint glsl_program_num;  // Owned by the resource_pool.
+
+       // Position and texcoord attribute indexes, although it doesn't matter
+       // which is which, because they contain the same data.
+       std::set<GLint> attribute_indexes;
+
        bool input_needs_mipmaps;
 
        // Inputs are only inputs from other phases (ie., those that come from RTT);
@@ -173,8 +179,13 @@ struct Phase {
        std::vector<Uniform<float> > uniforms_vec4;
        std::vector<Uniform<Eigen::Matrix3d> > uniforms_mat3;
 
+       GLuint ubo;  // GL_INVALID_INDEX if not using UBOs.
+       GLuint uniform_block_index;
+       std::vector<char> ubo_data;
+
        // For measurement of GPU time used.
-       GLuint timer_query_object;
+       std::list<GLuint> timer_query_objects_running;
+       std::list<GLuint> timer_query_objects_free;
        uint64_t time_elapsed_ns;
        uint64_t num_measured_iterations;
 };
@@ -187,7 +198,7 @@ public:
        // will create its own that is not shared with anything else. Does not take
        // ownership of the passed-in ResourcePool, but will naturally take ownership
        // of its own internal one if created.
-       EffectChain(float aspect_nom, float aspect_denom, ResourcePool *resource_pool = NULL);
+       EffectChain(float aspect_nom, float aspect_denom, ResourcePool *resource_pool = NULL, GLenum intermediate_format = GL_RGBA16F);
        ~EffectChain();
 
        // User API:
@@ -220,14 +231,36 @@ public:
                inputs.push_back(input3);
                return add_effect(effect, inputs);
        }
+       Effect *add_effect(Effect *effect, Effect *input1, Effect *input2, Effect *input3, Effect *input4) {
+               std::vector<Effect *> inputs;
+               inputs.push_back(input1);
+               inputs.push_back(input2);
+               inputs.push_back(input3);
+               inputs.push_back(input4);
+               return add_effect(effect, inputs);
+       }
+       Effect *add_effect(Effect *effect, Effect *input1, Effect *input2, Effect *input3, Effect *input4, Effect *input5) {
+               std::vector<Effect *> inputs;
+               inputs.push_back(input1);
+               inputs.push_back(input2);
+               inputs.push_back(input3);
+               inputs.push_back(input4);
+               inputs.push_back(input5);
+               return add_effect(effect, inputs);
+       }
        Effect *add_effect(Effect *effect, const std::vector<Effect *> &inputs);
 
-       // Adds an RGB output. Note that you can only have one output.
+       // Adds an RGBA output. Note that you can have at most one RGBA output and one
+       // Y'CbCr output (see below for details).
        void add_output(const ImageFormat &format, OutputAlphaFormat alpha_format);
 
        // Adds an YCbCr output. Note that you can only have one output.
        // Currently, only chunked packed output is supported, and only 4:4:4
        // (so chroma_subsampling_x and chroma_subsampling_y must both be 1).
+       //
+       // If you have both RGBA and Y'CbCr output, the RGBA output will come
+       // in the last draw buffer. Also, <format> and <alpha_format> must be
+       // identical between the two.
        void add_ycbcr_output(const ImageFormat &format, OutputAlphaFormat alpha_format,
                              const YCbCrFormat &ycbcr_format,
                              YCbCrOutputSplitting output_splitting = YCBCR_OUTPUT_INTERLEAVED);
@@ -298,6 +331,13 @@ public:
        // single-sampler input, or from an RTT texture.
        GLenum get_input_sampler(Node *node, unsigned input_num) const;
 
+       // Whether input <input_num> of <node> corresponds to a single sampler
+       // (see get_input_sampler()). Normally, you should not need to call this;
+       // however, if the input Effect has set override_texture_bounce(),
+       // this will return false, and you could be flexible and check it first
+       // if you want.
+       GLenum has_input_sampler(Node *node, unsigned input_num) const;
+
        // Get the current resource pool assigned to this EffectChain.
        // Primarily to let effects allocate textures as needed.
        // Any resources you get from the pool must be returned to the pool
@@ -331,7 +371,10 @@ private:
        Phase *construct_phase(Node *output, std::map<Node *, Phase *> *completed_effects);
 
        // Execute one phase, ie. set up all inputs, effects and outputs, and render the quad.
-       void execute_phase(Phase *phase, bool last_phase, std::map<Phase *, GLuint> *output_textures, std::set<Phase *> *generated_mipmaps);
+       void execute_phase(Phase *phase, bool last_phase,
+                          std::set<GLint> *bound__attribute_indices,
+                          std::map<Phase *, GLuint> *output_textures,
+                          std::set<Phase *> *generated_mipmaps);
 
        // Set up uniforms for one phase. The program must already be bound.
        void setup_uniforms(Phase *phase);
@@ -388,10 +431,9 @@ private:
        ImageFormat output_format;
        OutputAlphaFormat output_alpha_format;
 
-       enum OutputColorType { OUTPUT_COLOR_RGB, OUTPUT_COLOR_YCBCR };
-       OutputColorType output_color_type;
-       YCbCrFormat output_ycbcr_format;              // If output_color_type == OUTPUT_COLOR_YCBCR.
-       YCbCrOutputSplitting output_ycbcr_splitting;  // If output_color_type == OUTPUT_COLOR_YCBCR.
+       bool output_color_rgba, output_color_ycbcr;
+       YCbCrFormat output_ycbcr_format;              // If output_color_ycbcr is true.
+       YCbCrOutputSplitting output_ycbcr_splitting;  // If output_color_ycbcr is true.
 
        std::vector<Node *> nodes;
        std::map<Effect *, Node *> node_map;
@@ -400,9 +442,11 @@ private:
        std::vector<Input *> inputs;  // Also contained in nodes.
        std::vector<Phase *> phases;
 
+       GLenum intermediate_format;
        unsigned num_dither_bits;
        OutputOrigin output_origin;
        bool finalized;
+       GLuint vbo;  // Contains vertex and texture coordinate data.
 
        ResourcePool *resource_pool;
        bool owns_resource_pool;