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

geometry_batcher.hpp « graphics - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d181c192b9cc04a44a5d7eeda24b3db9c01d282a (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#pragma once

#include "opengl/vertex.hpp"
#include "opengl/buffer_object.hpp"
#include "opengl/renderbuffer.hpp"
#include "opengl/framebuffer.hpp"
#include "opengl/storage.hpp"

#include "pipeline_manager.hpp"
#include "resource_cache.hpp"
#include "resource_manager.hpp"

#include "../std/vector.hpp"
#include "../std/string.hpp"
#include "../std/list.hpp"
#include "../std/function.hpp"

#include "../geometry/angles.hpp"

#include "../base/matrix.hpp"

namespace graphics
{
  class GeometryBatcher : public PipelinesManager
  {
  private:

    typedef PipelinesManager base_t;

    bool m_isAntiAliased;

    int m_aaShift;

  public:

    /// INTERNAL API! USE WITH CAUTION
    /// @{
    void flush(int pipelineID);
    /// @}

    bool hasRoom(size_t verticesCount, size_t indicesCount, int pipelineID) const;
    int verticesLeft(int pipelineID) const;
    int  indicesLeft(int pipelineID) const;

    struct Params : public base_t::Params
    {
      EStorageType m_storageType;
      ETextureType m_textureType;
      Params();
    };

    uint8_t m_startStaticPage;
    uint8_t m_staticPagesCount;

    uint8_t m_startDynamicPage;
    uint8_t m_dynamicPage;
    uint8_t m_dynamicPagesCount;

    GeometryBatcher(Params const & params);

    void beginFrame();
    void endFrame();

    bool isDynamicPage(int i) const;
    void flushDynamicPage();
    int  nextDynamicPage() const;
    void changeDynamicPage();

    void onDynamicOverflow(int pipelineID);

    /// copy vertices from source VertexStream
    unsigned copyVertices(VertexStream * srcVS,
                          unsigned vCount,
                          unsigned iCount,
                          int pipelineID);

  public:

    /// This functions hide the base_t functions with the same name and signature
    /// to flush(-1) upon calling them
    /// @{
    void enableClipRect(bool flag);
    void setClipRect(m2::RectI const & rect);

    void clear(Color const & c, bool clearRT = true, float depth = 1.0, bool clearDepth = true);
    /// @}

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

    unsigned reservePipelines(unsigned count,
                              ETextureType textureType,
                              EStorageType storageType,
                              VertexDecl const * decl);

    void addTriangleStrip(VertexStream * srcVS,
                          unsigned count,
                          int pipelineID);

    void addTriangleList(VertexStream * srcVS,
                         unsigned count,
                         int pipelineID);

    void addTriangleFan(VertexStream * srcVS,
                        unsigned count,
                        int pipelineID);

    void addTexturedFan(m2::PointF const * coords,
                        m2::PointF const * normals,
                        m2::PointF const * texCoords,
                        unsigned size,
                        double depth,
                        int pipelineID);

    void addTexturedFanStrided(m2::PointF const * coords,
                               size_t coordsStride,
                               m2::PointF const * normals,
                               size_t normalsStride,
                               m2::PointF const * texCoords,
                               size_t texCoordsStride,
                               unsigned size,
                               double depth,
                               int pipelineID);

    void addTexturedStrip(m2::PointF const * coords,
                          m2::PointF const * normals,
                          m2::PointF const * texCoords,
                          unsigned size,
                          double depth,
                          int pipelineID);

    void addTexturedStripStrided(m2::PointF const * coords,
                                 size_t coordsStride,
                                 m2::PointF const * normals,
                                 size_t normalsStride,
                                 m2::PointF const * texCoords,
                                 size_t texCoordsStride,
                                 unsigned size,
                                 double depth,
                                 int pipelineID);

    void addTexturedStripStrided(m2::PointD const * coords,
                                 size_t coordsStride,
                                 m2::PointF const * normals,
                                 size_t normalsStride,
                                 m2::PointF const * texCoords,
                                 size_t texCoordsStride,
                                 unsigned size,
                                 double depth,
                                 int pipelineID);

    void addTexturedList(m2::PointF const * coords,
                         m2::PointF const * texCoords,
                         m2::PointF const * normalCoords,
                         unsigned size,
                         double depth,
                         int pipelineID);

    void addTexturedListStrided(m2::PointF const * coords,
                                size_t coordsStride,
                                m2::PointF const * normals,
                                size_t normalsStride,
                                m2::PointF const * texCoords,
                                size_t texCoordsStride,
                                unsigned size,
                                double depth,
                                int pipelineID);

    void addTexturedListStrided(m2::PointD const * coords,
                                size_t coordsStride,
                                m2::PointF const * normals,
                                size_t normalsStride,
                                m2::PointF const * texCoords,
                                size_t texCoordsStride,
                                unsigned size,
                                double depth,
                                int pipelineID);

    int aaShift() const;

    void drawStraightTexturedPolygon(
        m2::PointD const & ptPivot,
        float tx0, float ty0, float tx1, float ty1,
        float x0, float y0, float x1, float y1,
        double depth,
        int pipelineID);

    /// drawing textured polygon with antialiasing
    /// we assume that the (tx0, ty0, tx1, ty1) area on texture is surrounded by (0, 0, 0, 0) pixels,
    /// and the 1px interior area is also (0, 0, 0, 0).
    void drawTexturedPolygon(
        m2::PointD const & ptWhere,
        ang::AngleD const & angle,
        float tx0, float ty0, float tx1, float ty1,
        float x0, float y0, float x1, float y1,
        double depth,
        int pipelineID);

    void setDisplayList(DisplayList * dl);
    void drawDisplayList(DisplayList * dl, math::Matrix<double, 3, 3> const & m);

    void uploadResources(shared_ptr<Resource> const * resources,
                         size_t count,
                         shared_ptr<gl::BaseTexture> const & texture);

    void applyStates();
    void applyBlitStates();
    void applySharpStates();

    /// map Resource::Info on skin
    /// if found - return id.
    /// if not - pack and return id.
    uint32_t mapInfo(Resource::Info const & info);
    /// map array of Resource::Info's on skin
    bool mapInfo(Resource::Info const * const * infos,
             uint32_t * ids,
             size_t count);

    uint32_t findInfo(Resource::Info const & info);


    uint8_t dynamicPage() const;

    /// change pipeline for its "backbuffer" counterpart.
    /// pipelines works in pairs to employ "double-buffering" technique
    /// to enhance CPU-GPU parallelism.
    /// this function is called after any rendering command
    /// issued to avoid the "GPU is waiting on texture used in
    /// rendering call" issue.
    /// @warning does nothing for pipelines with EStaticTexture type.
    /// (pipelines loaded at screen creation time)
    void changePipeline(int i);
    int nextPipeline(int i) const;
  };
}