Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pipeline_manager.hpp « graphics - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2f50bb3763a1a267d223b76f3b2370ce73a3f8a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#pragma once

#include "../std/shared_ptr.hpp"
#include "../std/function.hpp"
#include "../std/vector.hpp"
#include "../std/queue.hpp"

#include "../geometry/rect2d.hpp"

#include "opengl/vertex.hpp"

#include "display_list_renderer.hpp"
#include "resource.hpp"
#include "geometry_pipeline.hpp"

namespace graphics
{
  template <typename pair_t>
  struct first_less
  {
    bool operator()(pair_t const & first, pair_t const & second)
    {
      return first.first < second.first;
    }
  };

  class PipelinesManager : public DisplayListRenderer
  {
  public:

    typedef DisplayListRenderer base_t;

    typedef function<void()> clearPageFn;
    typedef function<void()> overflowFn;

  private:

    vector<GeometryPipeline> m_pipelines;

    typedef pair<uint8_t, uint32_t> id_pair_t;

    typedef priority_queue<pair<size_t, clearPageFn>,
                           vector<pair<size_t, clearPageFn> >,
                           first_less<pair<size_t, clearPageFn> >
                           > clearPageFns;

    vector<clearPageFns> m_clearPageFns;

    typedef priority_queue<pair<size_t, overflowFn>,
                           vector<pair<size_t, overflowFn> >,
                           first_less<pair<size_t, overflowFn> >
                           > overflowFns;

    vector<overflowFns> m_overflowFns;
    void callOverflowFns(uint8_t pipelineID);

    void clearPageHandles(int pipelineID);

  public:

    PipelinesManager(base_t::Params const & params);
    ~PipelinesManager();

    id_pair_t unpackID(uint32_t id) const;
    uint32_t packID(uint8_t, uint32_t) const;

    /// obtain Resource from id
    Resource const * fromID(uint32_t id);

    void addClearPageFn(int pipelineID, clearPageFn fn, int priority);
    void callClearPageFns(int pipelineID);

    /// reserve static pipelines
    unsigned reservePipelines(vector<shared_ptr<ResourceCache> > const & caches,
                              EStorageType storageType,
                              VertexDecl const * decl);

    /// reserve dynamic pipelines
    unsigned reservePipelines(unsigned count,
                              ETextureType textureType,
                              EStorageType storageType,
                              VertexDecl const * decl);

    void freePipeline(int pipelineID);
    void freeTexture(int pipelineID);

    bool flushPipeline(int pipelineID);
    void unlockPipeline(int pipelineID);
    void discardPipeline(int pipelineID);
    void resetPipeline(int pipelineID);
    void clearPipeline(int pipelineID);

    GeometryPipeline const & pipeline(int i) const;
    GeometryPipeline & pipeline(int i);
    unsigned pipelinesCount() const;

    uint32_t invalidHandle() const;
    uint32_t invalidPageHandle() const;

    void clearHandles();

    void memoryWarning();
    void enterBackground();
    void enterForeground();

    void beginFrame();
    void endFrame();
  };
}