FPLBase
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
detailed_render_state.h
1 // Copyright 2017 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef FPLBASE_DETAILED_RENDER_STATE_H
16 #define FPLBASE_DETAILED_RENDER_STATE_H
17 
18 #include "fplbase/renderer_common.h"
19 
20 namespace fplbase {
21 
22 enum RenderFunction {
23  kRenderAlways, // Corresponds to GL_ALWAYS.
24  kRenderEqual, // Corresponds to GL_EQUAL.
25  kRenderGreater, // Corresponds to GL_GREATER.
26  kRenderGreaterEqual, // Corresponds to GL_GEQUAL.
27  kRenderLess, // Corresponds to GL_LESS.
28  kRenderLessEqual, // Corresponds to GL_LEQUAL.
29  kRenderNever, // Corresponds to GL_NEVER.
30  kRenderNotEqual, // Corresponds to GL_NOTEQUAL.
31  kRenderCount
32 };
33 
35  bool enabled;
36  RenderFunction function;
37  float ref;
38 
39  AlphaTestState() : enabled(false), function(kRenderAlways), ref(0.0f) {}
40 };
41 
42 struct BlendState {
43  enum BlendFactor {
44  kZero, // Corresponds to GL_ZERO.
45  kOne, // Corresponds to GL_ONE.
46  kSrcColor, // Corresponds to GL_SRC_COLOR.
47  kOneMinusSrcColor, // Corresponds to GL_ONE_MINUS_SRC_COLOR.
48  kDstColor, // Corresponds to GL_DST_COLOR.
49  kOneMinusDstColor, // Corresponds to GL_ONE_MINUS_DST_COLOR.
50  kSrcAlpha, // Corresponds to GL_SRC_ALPHA.
51  kOneMinusSrcAlpha, // Corresponds to GL_ONE_MINUS_SRC_ALPHA.
52  kDstAlpha, // Corresponds to GL_DST_ALPHA.
53  kOneMinusDstAlpha, // Corresponds to GL_ONE_MINUS_DST_ALPHA.
54  kConstantColor, // Corresponds to GL_CONSTANT_COLOR.
55  kOneMinusConstantColor, // Corresponds to GL_ONE_MINUS_CONSTANT_COLOR.
56  kConstantAlpha, // Corresponds to GL_CONSTANT_ALPHA.
57  kOneMinusConstantAlpha, // Corresponds to GL_ONE_MINUS_CONSTANT_ALPHA.
58  kSrcAlphaSaturate, // Corresponds to GL_SRC_ALPHA_SATURATE.
59  kCount
60  };
61 
62  bool enabled;
63  BlendFactor src_alpha;
64  BlendFactor src_color;
65  BlendFactor dst_alpha;
66  BlendFactor dst_color;
67 
68  BlendState()
69  : enabled(false),
70  src_alpha(kOne),
71  src_color(kOne),
72  dst_alpha(kZero),
73  dst_color(kZero) {}
74 };
75 
76 struct CullState {
77  enum CullFace { kFront, kBack, kFrontAndBack, kCount };
78  CullFace face;
79  bool enabled;
80 
81  CullState() : face(kBack), enabled(false) {}
82 };
83 
84 struct DepthState {
85  RenderFunction function;
86  bool enabled;
87 
88  DepthState() : function(kRenderAlways), enabled(false) {}
89 };
90 
92  RenderFunction function;
93  int ref;
94  unsigned int mask;
95 
96  StencilFunction() : function(kRenderAlways), ref(0), mask(1) {}
97 };
98 
100  enum StencilOperations {
101  kKeep, // Corresponds to GL_KEEP.
102  kZero, // Corresponds to GL_ZERO.
103  kReplace, // Corresponds to GL_REPLACE.
104  kIncrement, // Corresponds to GL_INCR.
105  kIncrementAndWrap, // Corresponds to GL_INCR_WRAP.
106  kDecrement, // Corresponds to GL_DECR.
107  kDecrementAndWrap, // Corresponds to GL_DECR_WRAP.
108  kInvert, // Corresponds to GL_INVERT.
109  kCount
110  };
111 
112  // Specifies the action to take when the stencil test fails.
113  StencilOperations stencil_fail;
114  // Specifies the stencil action when the stencil test passes, but the depth
115  // test fails.
116  StencilOperations depth_fail;
117  // Specifies the stencil action when both the stencil test and the depth test
118  // pass, or when the stencil test passes and either there is no depth buffer
119  // or depth testing is not enabled.
120  StencilOperations pass;
121 
122  StencilOperation() : stencil_fail(kKeep), depth_fail(kKeep), pass(kKeep) {}
123 };
124 
125 struct StencilState {
126  bool enabled;
127 
128  StencilFunction back_function;
129  StencilOperation back_op;
130  StencilFunction front_function;
131  StencilOperation front_op;
132 
133  StencilState() : enabled(false) {}
134 };
135 
136 struct ScissorState {
137  bool enabled;
138 
139  ScissorState() : enabled(false) {}
140 };
141 
142 struct RenderState {
143  AlphaTestState alpha_test_state;
144  BlendState blend_state;
145  CullState cull_state;
146  DepthState depth_state;
147  ScissorState scissor_state;
148  StencilState stencil_state;
149 
150  Viewport viewport;
151 
152  RenderState() {}
153 };
154 
155 inline bool operator==(const ScissorState &lhs, const ScissorState &rhs) {
156  return (lhs.enabled == rhs.enabled);
157 }
158 
159 inline bool operator!=(const ScissorState &lhs, const ScissorState &rhs) {
160  return !(lhs == rhs);
161 }
162 
163 inline bool operator==(const StencilOperation &lhs,
164  const StencilOperation &rhs) {
165  return (lhs.stencil_fail == rhs.stencil_fail &&
166  lhs.depth_fail == rhs.depth_fail && lhs.pass == rhs.pass);
167 }
168 
169 inline bool operator!=(const StencilOperation &lhs,
170  const StencilOperation &rhs) {
171  return !(lhs == rhs);
172 }
173 
174 inline bool operator==(const StencilFunction &lhs, const StencilFunction &rhs) {
175  return (lhs.function == rhs.function && lhs.ref == rhs.ref &&
176  lhs.mask == rhs.mask);
177 }
178 
179 inline bool operator!=(const StencilFunction &lhs, const StencilFunction &rhs) {
180  return !(lhs == rhs);
181 }
182 
183 inline bool operator==(const StencilState &lhs, const StencilState &rhs) {
184  return lhs.enabled == rhs.enabled && lhs.back_function == rhs.back_function &&
185  lhs.back_op == rhs.back_op &&
186  lhs.front_function == rhs.front_function &&
187  lhs.front_op == rhs.front_op;
188 }
189 
190 inline bool operator!=(const StencilState &lhs, const StencilState &rhs) {
191  return !(lhs == rhs);
192 }
193 
194 inline bool operator==(const DepthState &lhs, const DepthState &rhs) {
195  return lhs.enabled == rhs.enabled && lhs.function == rhs.function;
196 }
197 
198 inline bool operator!=(const DepthState &lhs, const DepthState &rhs) {
199  return !(lhs == rhs);
200 }
201 
202 inline bool operator==(const CullState &lhs, const CullState &rhs) {
203  return lhs.enabled == rhs.enabled && lhs.face == rhs.face;
204 }
205 
206 inline bool operator!=(const CullState &lhs, const CullState &rhs) {
207  return !(lhs == rhs);
208 }
209 
210 } // namespace fplbase
211 
212 #endif // FPLBASE_INTERNAL_RENDER_STATE_H
Definition: detailed_render_state.h:34
Definition: detailed_render_state.h:142
Definition: detailed_render_state.h:99
Definition: detailed_render_state.h:84
Definition: detailed_render_state.h:91
Definition: detailed_render_state.h:76
Definition: detailed_render_state.h:125
Definition: detailed_render_state.h:136
mathfu::recti Viewport
Specifies the region of the surface to be used for rendering.
Definition: renderer_common.h:23
Definition: detailed_render_state.h:42