mercator  0.4.0
A terrain generation library for the Worldforge system.
TileShader.cpp
1 // This file may be redistributed and modified only under the terms of
2 // the GNU General Public License (See COPYING for details).
3 // Copyright (C) 2005 Alistair Riddoch
4 
5 #include "TileShader.h"
6 
7 #include "Segment.h"
8 #include "Surface.h"
9 
10 #include <cassert>
11 
12 namespace Mercator {
13 
14 TileShader::TileShader() = default;
15 
16 TileShader::~TileShader() = default;
17 
18 bool TileShader::checkIntersect(const Segment & s) const
19 {
20  return true;
21 }
22 
23 void TileShader::shade(Surface & surface) const
24 {
25  ColorT * sdata = surface.getData();
26  auto sdata_len = surface.getSize() * surface.getSize();
27 
28  auto I = m_subShaders.begin();
29  auto Iend = m_subShaders.end();
30  for (; I != Iend; ++I) {
31  if (!I->second->checkIntersect(surface.getSegment())) {
32  continue;
33  }
34  auto subs = I->second->newSurface(surface.getSegment());
35  assert(subs);
36  subs->populate();
37  ColorT * subsdata = subs->getData();
38  auto channels = subs->getChannels();
39 
40  for (unsigned int i = 0; i < sdata_len; ++i) {
41  if (subsdata[i * channels + channels - 1] > 127) {
42  sdata[i] = I->first;
43  }
44  }
45  }
46 }
47 
48 } // namespace Mercator
void shade(Surface &) const override
Populate a Surface with data.
Definition: TileShader.cpp:23
DataType * getData()
Accessor for a pointer to buffer containing data values.
Definition: Buffer.h:63
Data store for terrain surface data.
Definition: Surface.h:23
Class storing heightfield and other data for a single fixed size square area of terrain defined by fo...
Definition: Segment.h:37
bool checkIntersect(const Segment &) const override
Check whether this Shader has any effect on the given Segment.
Definition: TileShader.cpp:18
unsigned int getSize() const
Accessor for the size of segment, m_res + 1.
Definition: Buffer.h:53
const Segment & getSegment() const
Accessor for the terrain height segment this surface is associated with.
Definition: Surface.h:37