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
10namespace Mercator {
11
18Surface::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
Template for managing buffers of data for a segment.
Definition: Buffer.h:14
bool isValid() const
Determine if this buffer has valid allocated storage.
Definition: Buffer.h:83
void allocate()
Allocate the storage required by the buffer.
Definition: Buffer.h:76
Class storing heightfield and other data for a single fixed size square area of terrain defined by fo...
Definition: Segment.h:37
Base class for Shader objects which create surface data for use when rendering terrain.
Definition: Shader.h:25
virtual void shade(Surface &) const =0
Populate a Surface with data.
Surface(const Segment &segment, const Shader &shader, bool colors=true, bool alpha=true)
Constructor.
Definition: Surface.cpp:18
void populate()
Populate the data buffer using the correct shader.
Definition: Surface.cpp:27
const Shader & m_shader
The shader that populates this surface.
Definition: Surface.h:26