aboutsummaryrefslogtreecommitdiff
path: root/dep/g3dlite/include/G3D/WrapMode.h
blob: e71d6dfa6214e7d57a4a2c2c414580fb6b8d3238 (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/** 
  \file G3D/WrapMode.h
 
  \maintainer Morgan McGuire, http://graphics.cs.williams.edu
 
  \created 2007-04-17
  \edited  2010-04-17

  Copyright 2000-2012, Morgan McGuire.
  All rights reserved.
 */

#ifndef G3D_WrapMode_h
#define G3D_WrapMode_h

#include "G3D/platform.h"
#include "G3D/enumclass.h"

#ifdef IGNORE
#   undef IGNORE
#endif
#ifdef ZERO
#   undef ZERO
#endif
#ifdef ERROR
#   undef ERROR
#endif

namespace G3D {

/** 
  Describes the behavior of G3D::Texture, G3D::Map2D, G3D::Image3,
  etc. when accessing an out-of-bounds pixel.  Not all classes support
  all modes.

  Refer to these as scoped enums, e.g., <code>WrapMode m = WrapMode::CLAMP;</code>.

  WrapMode::IGNORE silently discards attempts to write to out 
     of bounds locations and returns an undefined value for reading
     from out of bounds locations.

  WrapMode::ERROR generates an error when the 
     pixel indices are out of bounds

  WrapMode::CLAMP makes out of bounds pixels equal to the last in-range pixel along that dimension.

  WrapMode::TILE computes out of bounds pixels modulo the dimension

  WrapMode::ZERO treats out of bounds values as the zero value, which varies in definition
  according to the class used.  For example, with a G3D::Texture, ZERO = Color4(0,0,0,0).

  Uses the "Intelligent Enum" design pattern 
  http://www.codeguru.com/cpp/cpp/cpp_mfc/article.php/c4001/
 */ 
class WrapMode {
public:
    /** Don't use this enum; use WrapMode instances instead. */
    enum Value {
        CLAMP, 
        TILE, 
        ZERO,
        IGNORE, 
        ERROR
    } value;
    
    static const char* toString(int i, Value& v) {
        static const char* str[] = {"CLAMP", "TILE", "ZERO", "IGNORE", "ERROR", NULL}; 
        static const Value val[] = {CLAMP, TILE, ZERO, IGNORE, ERROR};
        const char* s = str[i];
        if (s) {
            v = val[i];
        }
        return s;
    }


    G3D_DECLARE_ENUM_CLASS_METHODS(WrapMode);
};


} // namespace G3D

G3D_DECLARE_ENUM_CLASS_HASHCODE(G3D::WrapMode);

#endif