1 | /** |
2 | * Copyright (c) 2006-2023 LOVE Development Team |
3 | * |
4 | * This software is provided 'as-is', without any express or implied |
5 | * warranty. In no event will the authors be held liable for any damages |
6 | * arising from the use of this software. |
7 | * |
8 | * Permission is granted to anyone to use this software for any purpose, |
9 | * including commercial applications, and to alter it and redistribute it |
10 | * freely, subject to the following restrictions: |
11 | * |
12 | * 1. The origin of this software must not be misrepresented; you must not |
13 | * claim that you wrote the original software. If you use this software |
14 | * in a product, an acknowledgment in the product documentation would be |
15 | * appreciated but is not required. |
16 | * 2. Altered source versions must be plainly marked as such, and must not be |
17 | * misrepresented as being the original software. |
18 | * 3. This notice may not be removed or altered from any source distribution. |
19 | **/ |
20 | |
21 | #include "depthstencil.h" |
22 | #include "common/StringMap.h" |
23 | |
24 | namespace love |
25 | { |
26 | namespace graphics |
27 | { |
28 | |
29 | CompareMode getReversedCompareMode(CompareMode mode) |
30 | { |
31 | switch (mode) |
32 | { |
33 | case COMPARE_LESS: |
34 | return COMPARE_GREATER; |
35 | case COMPARE_LEQUAL: |
36 | return COMPARE_GEQUAL; |
37 | case COMPARE_GEQUAL: |
38 | return COMPARE_LEQUAL; |
39 | case COMPARE_GREATER: |
40 | return COMPARE_LESS; |
41 | default: |
42 | return mode; |
43 | } |
44 | } |
45 | |
46 | static StringMap<StencilAction, STENCIL_MAX_ENUM>::Entry stencilActionEntries[] = |
47 | { |
48 | { "replace" , STENCIL_REPLACE }, |
49 | { "increment" , STENCIL_INCREMENT }, |
50 | { "decrement" , STENCIL_DECREMENT }, |
51 | { "incrementwrap" , STENCIL_INCREMENT_WRAP }, |
52 | { "decrementwrap" , STENCIL_DECREMENT_WRAP }, |
53 | { "invert" , STENCIL_INVERT }, |
54 | }; |
55 | |
56 | static StringMap<StencilAction, STENCIL_MAX_ENUM> stencilActions(stencilActionEntries, sizeof(stencilActionEntries)); |
57 | |
58 | static StringMap<CompareMode, COMPARE_MAX_ENUM>::Entry compareModeEntries[] = |
59 | { |
60 | { "less" , COMPARE_LESS }, |
61 | { "lequal" , COMPARE_LEQUAL }, |
62 | { "equal" , COMPARE_EQUAL }, |
63 | { "gequal" , COMPARE_GEQUAL }, |
64 | { "greater" , COMPARE_GREATER }, |
65 | { "notequal" , COMPARE_NOTEQUAL }, |
66 | { "always" , COMPARE_ALWAYS }, |
67 | { "never" , COMPARE_NEVER }, |
68 | }; |
69 | |
70 | static StringMap<CompareMode, COMPARE_MAX_ENUM> compareModes(compareModeEntries, sizeof(compareModeEntries)); |
71 | |
72 | bool getConstant(const char *in, StencilAction &out) |
73 | { |
74 | return stencilActions.find(in, out); |
75 | } |
76 | |
77 | bool getConstant(StencilAction in, const char *&out) |
78 | { |
79 | return stencilActions.find(in, out); |
80 | } |
81 | |
82 | std::vector<std::string> getConstants(StencilAction) |
83 | { |
84 | return stencilActions.getNames(); |
85 | } |
86 | |
87 | bool getConstant(const char *in, CompareMode &out) |
88 | { |
89 | return compareModes.find(in, out); |
90 | } |
91 | |
92 | bool getConstant(CompareMode in, const char *&out) |
93 | { |
94 | return compareModes.find(in, out); |
95 | } |
96 | |
97 | std::vector<std::string> getConstants(CompareMode) |
98 | { |
99 | return compareModes.getNames(); |
100 | } |
101 | |
102 | } // graphics |
103 | } // love |
104 | |