mercator  0.4.0
A terrain generation library for the Worldforge system.
Surface.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) 2003 Alistair Riddoch
4 
5 #include "Surface.h"
6 
7 #include "Shader.h"
8 #include <cassert>
9 
10 namespace Mercator {
11 
18 Surface::Surface(const Segment & seg, const Shader & sh, bool color, bool alpha)
19  : Buffer<ColorT>(seg.getSize(), (color ? 3 : 0) + (alpha ? 1 : 0)), m_shader(sh), m_segment(seg)
20 {
21 }
22 
23 
28 {
29  if (!isValid()) {
30  allocate();
31  }
32 
33  m_shader.shade(*this);
34 }
35 
36 } // namespace Mercator
Mercator::Surface::Surface
Surface(const Segment &segment, const Shader &shader, bool colors=true, bool alpha=true)
Constructor.
Definition: Surface.cpp:18
Mercator::Surface::populate
void populate()
Populate the data buffer using the correct shader.
Definition: Surface.cpp:27
Mercator::Segment
Class storing heightfield and other data for a single fixed size square area of terrain defined by fo...
Definition: Segment.h:37
Mercator::Buffer< ColorT >::allocate
void allocate()
Allocate the storage required by the buffer.
Definition: Buffer.h:76
Mercator::Surface::m_shader
const Shader & m_shader
The shader that populates this surface.
Definition: Surface.h:26
Mercator::Shader::shade
virtual void shade(Surface &) const =0
Populate a Surface with data.
Mercator::Buffer< ColorT >::isValid
bool isValid() const
Determine if this buffer has valid allocated storage.
Definition: Buffer.h:83
Mercator::Buffer
Template for managing buffers of data for a segment.
Definition: Buffer.h:14
Mercator::Shader
Base class for Shader objects which create surface data for use when rendering terrain.
Definition: Shader.h:25