forked from projectM-visualizer/projectm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PipelineMerger.cpp
125 lines (103 loc) · 3.39 KB
/
PipelineMerger.cpp
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
#include "PipelineMerger.hpp"
#include "RenderItemMatcher.hpp"
#include "RenderItemMergeFunction.hpp"
const double PipelineMerger::e(2.71828182845904523536);
const double PipelineMerger::s(0.5);
void PipelineMerger::mergePipelines(const Pipeline & a, const Pipeline & b, Pipeline & out, RenderItemMatcher::MatchResults & results, RenderItemMergeFunction & mergeFunction, float ratio)
{
const double invratio = 1.0 - ratio;
out.textureWrap = ( ratio < 0.5 ) ? a.textureWrap : b.textureWrap;
out.screenDecay = lerp ( b.screenDecay, a.screenDecay, ratio );
out.drawables.clear();
out.compositeDrawables.clear();
for ( std::vector<RenderItem*>::const_iterator pos = a.drawables.begin();
pos != a.drawables.end(); ++pos )
{
( *pos )->masterAlpha = invratio;
out.drawables.push_back ( *pos );
}
for ( std::vector<RenderItem*>::const_iterator pos = b.drawables.begin();
pos != b.drawables.end();++pos )
{
( *pos )->masterAlpha = ratio;
out.drawables.push_back ( *pos );
}
if(ratio < 0.5)
{
const double local_ratio = (invratio - 0.5) * 2;
for (std::vector<RenderItem*>::const_iterator pos = a.compositeDrawables.begin();
pos != a.compositeDrawables.end(); ++pos)
{
(*pos)->masterAlpha = local_ratio;
out.compositeDrawables.push_back(*pos);
}
}
else
{
const double local_ratio = (ratio - 0.5) * 2;
for (std::vector<RenderItem*>::const_iterator pos = b.compositeDrawables.begin();
pos != b.compositeDrawables.end();++pos)
{
(*pos)->masterAlpha = local_ratio;
out.compositeDrawables.push_back(*pos);
}
}
/*
for (RenderItemMatchList::iterator pos = results.matches.begin(); pos != results.matches.end(); ++pos) {
RenderItem * itemA = pos->first;
RenderItem * itemB = pos->second;
RenderItem * itemC = mergeFunction(itemA, itemB, ratio);
if (itemC == 0) {
itemA->masterAlpha = ratio;
out.drawables.push_back(itemA);
itemB->masterAlpha = invratio;
out.drawables.push_back(itemB);
} else
out.drawables.push_back(itemC);
}
for (std::vector<RenderItem*>::const_iterator pos = results.unmatchedLeft.begin();
pos != results.unmatchedLeft.end(); ++pos)
{
(*pos)->masterAlpha = invratio;
out.drawables.push_back(*pos);
}
for (std::vector<RenderItem*>::const_iterator pos = results.unmatchedRight.begin();
pos != results.unmatchedRight.end(); ++pos)
{
(*pos)->masterAlpha = ratio;
out.drawables.push_back(*pos);
}
*/
if (a.staticPerPixel && b.staticPerPixel)
{
out.staticPerPixel = true;
for (int x=0;x<a.gx;x++)
{
for(int y=0;y<a.gy;y++)
{
out.x_mesh[x][y] = a.x_mesh[x][y]* invratio + b.x_mesh[x][y]*ratio;
}
}
for (int x=0;x<a.gx;x++)
{
for(int y=0;y<a.gy;y++)
{
out.y_mesh[x][y] = a.y_mesh[x][y]* invratio + b.y_mesh[x][y]*ratio;
}
}
}
if(ratio < 0.5)
{
out.compositeShader = a.compositeShader;
out.warpShader = a.warpShader;
out.warpShaderFilename = a.warpShaderFilename;
out.compositeShaderFilename = a.compositeShaderFilename;
}
else
{
out.compositeShader = b.compositeShader;
out.warpShader = b.warpShader;
out.warpShaderFilename = b.warpShaderFilename;
out.compositeShaderFilename = b.compositeShaderFilename;
}
}