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

program_params.hpp « shaders - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fe7c02ba807c881c0d03db57d4830b3ae3a6bf28 (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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#pragma once

#include "shaders/programs.hpp"

#include "drape/drape_global.hpp"
#include "drape/glsl_types.hpp"
#include "drape/graphics_context.hpp"
#include "drape/gpu_program.hpp"
#include "drape/pointers.hpp"

#include "base/assert.hpp"

#include "std/target_os.hpp"

#include <map>
#include <vector>

namespace gpu
{
class ProgramParams
{
public:
  static void Init();
  static void Destroy();
  static std::string GetBoundParamsName(ref_ptr<dp::GpuProgram> program);

private:
  static std::map<std::string, std::string> m_boundParams;
};

#define BIND_PROGRAMS(ParamsType, ...) \
  static std::vector<gpu::Program> const & GetBoundPrograms() \
  { \
    static std::vector<gpu::Program> programs = {__VA_ARGS__}; \
    return programs; \
  } \
  static std::string GetName() { return std::string(#ParamsType); } \
  static void BindPrograms(std::map<std::string, std::string> & params) \
  { \
    for (auto const p : GetBoundPrograms()) \
    { \
      auto const programName = DebugPrint(p); \
      CHECK(params.find(programName) == params.cend(), \
        ("Program has already bound", programName)); \
      params[programName] = GetName(); \
    } \
  }

#define ALIGNMENT __attribute__ ((aligned(16)))

struct MapProgramParams
{
  glsl::mat4 m_modelView;
  glsl::mat4 m_projection;
  glsl::mat4 m_pivotTransform;
  float m_opacity = 1.0f;
  float m_zScale = 1.0f;
  float m_interpolation = 1.0f;
  float m_isOutlinePass = 1.0f;
  glsl::vec2 m_contrastGamma;

  BIND_PROGRAMS(MapProgramParams,
    Program::Area,
    Program::Area3d,
    Program::Area3dOutline,
    Program::AreaOutline,
    Program::Bookmark,
    Program::BookmarkAnim,
    Program::BookmarkAnimBillboard,
    Program::BookmarkBillboard,
    Program::CapJoin,
    Program::CirclePoint,
    Program::ColoredSymbol,
    Program::ColoredSymbolBillboard,
    Program::DashedLine,
    Program::HatchingArea,
    Program::Line,
    Program::MaskedTexturing,
    Program::MaskedTexturingBillboard,
    Program::PathSymbol,
    Program::Text,
    Program::TextBillboard,
    Program::TextFixed,
    Program::TextFixedBillboard,
    Program::TextOutlined,
    Program::TextOutlinedBillboard,
    Program::Texturing,
    Program::TexturingBillboard,
    Program::BookmarkAboveText,
    Program::BookmarkAnimAboveText,
    Program::BookmarkAnimAboveTextBillboard,
    Program::BookmarkAboveTextBillboard)
} ALIGNMENT;

struct RouteProgramParams
{
  glsl::mat4 m_modelView;
  glsl::mat4 m_projection;
  glsl::mat4 m_pivotTransform;
  glsl::vec4 m_routeParams;
  glsl::vec4 m_color;
  glsl::vec4 m_maskColor;
  glsl::vec4 m_outlineColor;
  glsl::vec2 m_pattern;
  glsl::vec2 m_angleCosSin;
  float m_arrowHalfWidth = 0.0f;
  float m_opacity = 1.0f;
  glsl::vec2 m_fakeBorders;
  glsl::vec4 m_fakeColor;
  glsl::vec4 m_fakeOutlineColor;

  BIND_PROGRAMS(RouteProgramParams,
    Program::Route,
    Program::RouteDash,
    Program::RouteArrow,
    Program::RouteMarker)
} ALIGNMENT;

struct TrafficProgramParams
{
  glsl::mat4 m_modelView;
  glsl::mat4 m_projection;
  glsl::mat4 m_pivotTransform;
  glsl::vec4 m_trafficParams;
  glsl::vec3 m_outlineColor;
  float m_outline = 0.0f;
  glsl::vec3 m_lightArrowColor;
  float m_opacity = 1.0f;
  glsl::vec3 m_darkArrowColor;

  BIND_PROGRAMS(TrafficProgramParams,
    Program::Traffic,
    Program::TrafficLine,
    Program::TrafficCircle)
} ALIGNMENT;

struct TransitProgramParams
{
  glsl::mat4 m_modelView;
  glsl::mat4 m_projection;
  glsl::mat4 m_pivotTransform;
  glsl::vec3 m_params;
  float m_lineHalfWidth = 0.0f;
  float m_maxRadius = 0.0f;

  BIND_PROGRAMS(TransitProgramParams,
    Program::Transit,
    Program::TransitCircle,
    Program::TransitMarker)
} ALIGNMENT;

struct GuiProgramParams
{
  glsl::mat4 m_modelView;
  glsl::mat4 m_projection;
  glsl::vec2 m_contrastGamma;
  glsl::vec2 m_position;
  float m_isOutlinePass = 1.0f;
  float m_opacity = 1.0f;
  float m_length = 0.0f;

  BIND_PROGRAMS(GuiProgramParams,
    Program::TextStaticOutlinedGui,
    Program::TextOutlinedGui,
    Program::TexturingGui,
    Program::Ruler)
} ALIGNMENT;

struct ShapesProgramParams
{
  glsl::mat4 m_modelView;
  glsl::mat4 m_projection;
  glsl::mat4 m_pivotTransform;
  glsl::vec3 m_position;
  float m_accuracy = 0.0;
  glsl::vec2 m_lineParams;
  float m_zScale = 1.0f;
  float m_opacity = 1.0f;
  float m_azimut = 0.0;

  BIND_PROGRAMS(ShapesProgramParams,
    Program::Accuracy,
    Program::MyPosition,
    Program::SelectionLine)
} ALIGNMENT;

struct Arrow3dProgramParams
{
  glsl::mat4 m_transform;
  glsl::vec4 m_color;

  BIND_PROGRAMS(Arrow3dProgramParams,
    Program::Arrow3d,
    Program::Arrow3dShadow,
    Program::Arrow3dOutline)
} ALIGNMENT;

struct DebugRectProgramParams
{
  glsl::vec4 m_color;

  BIND_PROGRAMS(DebugRectProgramParams, Program::DebugRect)
} ALIGNMENT;

struct ScreenQuadProgramParams
{
  float m_opacity = 1.0f;
  float m_invertV = 1.0f;

  BIND_PROGRAMS(ScreenQuadProgramParams, Program::ScreenQuad)
} ALIGNMENT;

struct SMAAProgramParams
{
  glsl::vec4 m_framebufferMetrics;

  BIND_PROGRAMS(SMAAProgramParams,
    Program::SmaaEdges,
    Program::SmaaBlendingWeight,
    Program::SmaaFinal)
} ALIGNMENT;

#undef ALIGNMENT

class ProgramParamsSetter
{
public:
  virtual ~ProgramParamsSetter() = default;
  virtual void Apply(ref_ptr<dp::GraphicsContext> context,
                     ref_ptr<dp::GpuProgram> program, MapProgramParams const & params) = 0;
  virtual void Apply(ref_ptr<dp::GraphicsContext> context,
                     ref_ptr<dp::GpuProgram> program, RouteProgramParams const & params) = 0;
  virtual void Apply(ref_ptr<dp::GraphicsContext> context,
                     ref_ptr<dp::GpuProgram> program, TrafficProgramParams const & params) = 0;
  virtual void Apply(ref_ptr<dp::GraphicsContext> context,
                     ref_ptr<dp::GpuProgram> program, TransitProgramParams const & params) = 0;
  virtual void Apply(ref_ptr<dp::GraphicsContext> context,
                     ref_ptr<dp::GpuProgram> program, GuiProgramParams const & params) = 0;
  virtual void Apply(ref_ptr<dp::GraphicsContext> context,
                     ref_ptr<dp::GpuProgram> program, ShapesProgramParams const & params) = 0;
  virtual void Apply(ref_ptr<dp::GraphicsContext> context,
                     ref_ptr<dp::GpuProgram> program, Arrow3dProgramParams const & params) = 0;
  virtual void Apply(ref_ptr<dp::GraphicsContext> context,
                     ref_ptr<dp::GpuProgram> program, DebugRectProgramParams const & params) = 0;
  virtual void Apply(ref_ptr<dp::GraphicsContext> context,
                     ref_ptr<dp::GpuProgram> program, ScreenQuadProgramParams const & params) = 0;
  virtual void Apply(ref_ptr<dp::GraphicsContext> context,
                     ref_ptr<dp::GpuProgram> program, SMAAProgramParams const & params) = 0;
};
}  // namespace gpu