/
cmp-tex.h
64 lines (46 loc) · 1.31 KB
/
cmp-tex.h
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
// cmp-tex.h -- Texture comparison
//
// Copyright (C) 2008, 2011 Miles Bader <miles@gnu.org>
//
// This source code is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 3, or (at
// your option) any later version. See the file COPYING for more details.
//
// Written by Miles Bader <miles@gnu.org>
//
#ifndef SNOGRAY_CMP_TEX_H
#define SNOGRAY_CMP_TEX_H
#include "tex.h"
namespace snogray {
// A texture which compares two input values, and returns one of two source
// values depending on the result.
//
template<typename T>
class CmpTex : public Tex<T>
{
public:
enum Op { EQ, NE, LT, LE, GT, GE };
CmpTex (Op _op,
const TexVal<float> &_cval1, const TexVal<float> &_cval2,
const TexVal<T> &_rval1, const TexVal<T> &_rval2)
: op (_op), cval1 (_cval1), cval2 (_cval2), rval1 (_rval1), rval2 (_rval2)
{ }
// Evaluate this texture at COORDS.
//
virtual T eval (const TexCoords &coords) const;
// The operation.
//
Op op;
// Values to compare.
//
TexVal<float> cval1, cval2;
// Values to return based on comparison result.
//
TexVal<T> rval1, rval2;
};
} // namespace snogray
// Include method definitions
//
#include "cmp-tex.tcc"
#endif // SNOGRAY_CMP_TEX_H