File: TileShader.cpp

package info (click to toggle)
mercator 0.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,008 kB
  • sloc: sh: 10,433; cpp: 4,482; makefile: 115
file content (58 lines) | stat: -rw-r--r-- 1,493 bytes parent folder | download | duplicates (4)
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
// This file may be redistributed and modified only under the terms of
// the GNU General Public License (See COPYING for details).
// Copyright (C) 2005 Alistair Riddoch

#include <Mercator/TileShader.h>

#include <Mercator/Segment.h>
#include <Mercator/Surface.h>

#include <cassert>

namespace Mercator {

TileShader::TileShader()
{
}

TileShader::~TileShader()
{
    Shaderstore::const_iterator I = m_subShaders.begin();
    Shaderstore::const_iterator Iend = m_subShaders.end();
    for (; I != Iend; ++I) {
        assert(I->second != 0);
        delete I->second;
    }
}

bool TileShader::checkIntersect(const Segment & s) const
{
    return true;
}

void TileShader::shade(Surface & surface) const
{
    ColorT * sdata = surface.getData();
    int sdata_len = surface.getSize() * surface.getSize();

    TileShader::Shaderstore::const_iterator I = m_subShaders.begin();
    TileShader::Shaderstore::const_iterator Iend = m_subShaders.end();
    for (; I != Iend; ++I) {
        if (!I->second->checkIntersect(surface.getSegment())) {
            continue;
        }
        Surface * subs = I->second->newSurface(surface.getSegment());
        subs->populate();
        ColorT * subsdata = subs->getData();
        int channels = subs->getChannels();
        
        for (int i = 0; i < sdata_len; ++i) {
            if (subsdata[i * channels + channels - 1] > 127) {
                sdata[i] = I->first;
            }
        }
        delete subs;
    }
}

} // namespace Mercator