34 data_ = GetDefaultData();
37 const math::Point2i max_point(default_width_, default_height_);
38 data_.scissor_box.SetMaxPoint(max_point);
39 data_.viewport.SetMaxPoint(max_point);
43 default_width_ = other.default_width_;
44 default_height_ = other.default_height_;
49 #define ION_UPDATE_VALUE1(n) data_.n = other.data_.n
50 #define ION_UPDATE_VALUE2(n1, n2) \
51 ION_UPDATE_VALUE1(n1); \
52 data_.n2 = other.data_.n2
53 #define ION_UPDATE_VALUE3(n1, n2, n3) \
54 ION_UPDATE_VALUE2(n1, n2); \
55 data_.n3 = other.data_.n3
56 #define ION_UPDATE_VALUE4(n1, n2, n3, n4) \
57 ION_UPDATE_VALUE3(n1, n2, n3); \
58 data_.n4 = other.data_.n4
59 #define ION_UPDATE_VALUE5(n1, n2, n3, n4, n5) \
60 ION_UPDATE_VALUE4(n1, n2, n3, n4); \
61 data_.n5 = other.data_.n5
62 #define ION_UPDATE_VALUE6(n1, n2, n3, n4, n5, n6) \
63 ION_UPDATE_VALUE5(n1, n2, n3, n4, n5); \
64 data_.n6 = other.data_.n6
65 #define ION_UPDATE_VALUE_(UPDATE_VALUE_MACRO, ...) \
66 UPDATE_VALUE_MACRO(__VA_ARGS__)
70 #define ION_UPDATE_VALUE(enum_name, ...) \
71 if (state_to_test.IsValueSet(enum_name)) { \
72 data_.values_set.set(enum_name); \
74 ION_ARGCOUNT_XCONCAT(ION_UPDATE_VALUE, ION_ARGCOUNT(__VA_ARGS__)), \
96 const size_t num_capabilities = data_.capabilities_set.size();
97 for (
size_t i = 0; i < num_capabilities; ++i) {
98 if (state_to_test.data_.capabilities_set.test(i)) {
99 data_.capabilities.set(i, other.data_.capabilities.test(i));
100 data_.capabilities_set.set(i);
109 alpha_blend_equation)
111 rgb_blend_source_factor,
112 rgb_blend_destination_factor,
113 alpha_blend_source_factor,
114 alpha_blend_destination_factor)
116 color_write_masks[0],
117 color_write_masks[1],
118 color_write_masks[2],
119 color_write_masks[3])
128 for (
int i = 0; i < kNumHints; ++i)
129 data_.hints[i] = other.data_.hints[i];
137 front_stencil_function,
138 back_stencil_function,
139 front_stencil_reference_value,
140 back_stencil_reference_value,
144 front_stencil_fail_op,
145 front_stencil_depth_fail_op,
146 front_stencil_pass_op,
147 back_stencil_fail_op,
148 back_stencil_depth_fail_op,
149 back_stencil_pass_op)
153 front_stencil_write_mask,
154 back_stencil_write_mask)
158 #undef ION_UPDATE_VALUE
159 #undef ION_UPDATE_VALUE_
160 #undef ION_UPDATE_VALUE1
161 #undef ION_UPDATE_VALUE2
162 #undef ION_UPDATE_VALUE3
163 #undef ION_UPDATE_VALUE4
164 #undef ION_UPDATE_VALUE5
165 #undef ION_UPDATE_VALUE6
172 #define ION_COPY_VAL(var) data_.var = default_data.var
174 const Data& default_data = GetDefaultData();
194 for (
int i = 0; i < 4; ++i) {
220 for (
int i = 0; i < kNumHints; ++i) {
236 data_.scissor_box.SetWithSize(
237 default_data.scissor_box.GetMinPoint(),
238 math::Vector2i(default_width_, default_height_));
264 data_.viewport.SetWithSize(
265 default_data.viewport.GetMinPoint(),
266 math::Vector2i(default_width_, default_height_));
269 DCHECK(
false) <<
"Invalid Value type";
274 data_.values_set.reset(value);
284 data_.blend_color = color;
290 data_.rgb_blend_equation = rgb_eq;
291 data_.alpha_blend_equation = alpha_eq;
300 data_.rgb_blend_source_factor = rgb_source_factor;
301 data_.rgb_blend_destination_factor = rgb_destination_factor;
302 data_.alpha_blend_source_factor = alpha_source_factor;
303 data_.alpha_blend_destination_factor = alpha_destination_factor;
312 data_.clear_color = color;
317 bool blue,
bool alpha) {
318 data_.color_write_masks[0] = red;
319 data_.color_write_masks[1] = green;
320 data_.color_write_masks[2] = blue;
321 data_.color_write_masks[3] = alpha;
330 data_.cull_face_mode = mode;
337 data_.front_face_mode = mode;
346 data_.clear_depth_value =
value;
351 data_.depth_function = func;
356 data_.depth_range = range;
361 data_.depth_write_mask = mask;
370 data_.draw_buffer = draw_buffer;
379 data_.hints[target] = mode;
388 data_.line_width =
width;
397 data_.polygon_offset_factor = factor;
398 data_.polygon_offset_units = units;
407 data_.sample_coverage_value =
value;
408 data_.sample_coverage_inverted = is_inverted;
417 data_.scissor_box = box;
426 StencilFunction front_func,
int front_reference_value, uint32 front_mask,
427 StencilFunction back_func,
int back_reference_value, uint32 back_mask) {
428 data_.front_stencil_function = front_func;
429 data_.front_stencil_reference_value = front_reference_value;
430 data_.front_stencil_mask = front_mask;
431 data_.back_stencil_function = back_func;
432 data_.back_stencil_reference_value = back_reference_value;
433 data_.back_stencil_mask = back_mask;
443 data_.front_stencil_fail_op = front_stencil_fail;
444 data_.front_stencil_depth_fail_op = front_depth_fail;
445 data_.front_stencil_pass_op = front_pass;
446 data_.back_stencil_fail_op = back_stencil_fail;
447 data_.back_stencil_depth_fail_op = back_depth_fail;
448 data_.back_stencil_pass_op = back_pass;
454 data_.clear_stencil_value =
value;
459 data_.front_stencil_write_mask = front_mask;
460 data_.back_stencil_write_mask = back_mask;
469 data_.viewport = rect;
474 SetViewport(math::Range2i::BuildWithSize(math::Point2i(left, bottom),
475 math::Vector2i(width, height)));
482 #define ION_INSTANTIATE_GETENUMSTRING(type) \
483 template <> ION_API const char* StateTable::GetEnumString(type value) { \
484 return base::EnumHelper::GetString(value); \
497 #undef ION_INSTANTIATE_GETENUMSTRING
507 using gfx::StateTable;
509 #define ION_CHECK_ARRAYS(enums, strings) \
510 ION_STATIC_ASSERT(ARRAYSIZE(enums) == ARRAYSIZE(strings), \
511 "Wrong size for " #strings)
517 template <> ION_API
const EnumHelper::EnumData<StateTable::Capability>
518 EnumHelper::GetEnumData() {
519 static const GLenum kCapabilities[] = {
522 GL_DEBUG_OUTPUT_SYNCHRONOUS,
526 GL_POLYGON_OFFSET_FILL,
527 GL_SAMPLE_ALPHA_TO_COVERAGE,
532 static const char* kCapabilityStrings[] = {
535 "DebugOutputSynchronous",
540 "SampleAlphaToCoverage",
546 return EnumData<StateTable::Capability>(
548 kCapabilities, ARRAYSIZE(kCapabilities)),
553 template <> ION_API
const EnumHelper::EnumData<StateTable::BlendEquation>
554 EnumHelper::GetEnumData() {
555 static const GLenum kBlendEquations[] = {
556 GL_FUNC_ADD, GL_FUNC_REVERSE_SUBTRACT, GL_FUNC_SUBTRACT
558 static const char* kBlendEquationStrings[] = {
559 "Add",
"ReverseSubtract",
"Subtract",
562 return EnumData<StateTable::BlendEquation>(
564 kBlendEquations, ARRAYSIZE(kBlendEquations)),
565 kBlendEquationStrings);
570 const EnumHelper::EnumData<StateTable::BlendFunctionFactor>
571 EnumHelper::GetEnumData() {
572 static const GLenum kBlendFunctionFactors[] = {
573 GL_CONSTANT_ALPHA, GL_CONSTANT_COLOR, GL_DST_ALPHA, GL_DST_COLOR, GL_ONE,
574 GL_ONE_MINUS_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_COLOR,
575 GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA,
576 GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA, GL_SRC_ALPHA_SATURATE, GL_SRC_COLOR,
579 static const char* kBlendFunctionFactorStrings[] = {
580 "ConstantAlpha",
"ConstantColor",
"DstAlpha",
"DstColor",
"One",
581 "OneMinusConstantAlpha",
"OneMinusConstantColor",
"OneMinusDstAlpha",
582 "OneMinusDstColor",
"OneMinusSrcAlpha",
"OneMinusSrcColor",
"SrcAlpha",
583 "SrcAlphaSaturate",
"SrcColor",
"Zero"
586 return EnumData<StateTable::BlendFunctionFactor>(
588 kBlendFunctionFactors, ARRAYSIZE(kBlendFunctionFactors)),
589 kBlendFunctionFactorStrings);
593 template <> ION_API
const EnumHelper::EnumData<StateTable::CullFaceMode>
594 EnumHelper::GetEnumData() {
595 static const GLenum kCullFaceModes[] = {
596 GL_FRONT, GL_BACK, GL_FRONT_AND_BACK
598 static const char* kCullFaceModeStrings[] = {
599 "CullFront",
"CullBack",
"CullFrontAndBack",
602 return EnumData<StateTable::CullFaceMode>(
604 kCullFaceModes, ARRAYSIZE(kCullFaceModes)),
605 kCullFaceModeStrings);
609 template <> ION_API
const EnumHelper::EnumData<StateTable::DepthFunction>
610 EnumHelper::GetEnumData() {
611 static const GLenum kDepthFunctions[] = {
612 GL_ALWAYS, GL_EQUAL, GL_GREATER, GL_GEQUAL,
613 GL_LESS, GL_LEQUAL, GL_NEVER, GL_NOTEQUAL
615 static const char* kDepthFunctionStrings[] = {
616 "DepthAlways",
"DepthEqual",
"DepthGreater",
"DepthGreaterOrEqual",
617 "DepthLess",
"DepthLessOrEqual",
"DepthNever",
"DepthNotEqual"
620 return EnumData<StateTable::DepthFunction>(
622 kDepthFunctions, ARRAYSIZE(kDepthFunctions)),
623 kDepthFunctionStrings);
628 ION_API
const EnumHelper::EnumData<StateTable::DrawBuffer>
629 EnumHelper::GetEnumData() {
630 static const GLenum kDrawBuffers[] = {
631 GL_BACK, GL_BACK_LEFT, GL_BACK_RIGHT, GL_FRONT, GL_FRONT_AND_BACK,
632 GL_FRONT_LEFT, GL_FRONT_RIGHT, GL_LEFT, GL_NONE, GL_RIGHT};
633 static const char* kDrawBufferStrings[] = {
634 "Back",
"BackLeft",
"BackRight",
"Front",
"FrontAndBack",
635 "FrontLeft",
"FrontRight",
"Left",
"None",
"Right"};
637 return EnumData<StateTable::DrawBuffer>(
639 ARRAYSIZE(kDrawBuffers)),
644 template <> ION_API
const EnumHelper::EnumData<StateTable::FrontFaceMode>
645 EnumHelper::GetEnumData() {
646 static const GLenum kFrontFaceModes[] = { GL_CW, GL_CCW };
647 static const char* kFrontFaceModeStrings[] = {
648 "Clockwise",
"CounterClockwise"
651 return EnumData<StateTable::FrontFaceMode>(
653 kFrontFaceModes, ARRAYSIZE(kFrontFaceModes)),
654 kFrontFaceModeStrings);
658 template <> ION_API
const EnumHelper::EnumData<StateTable::HintMode>
659 EnumHelper::GetEnumData() {
660 static const GLenum kHintModes[] = { GL_FASTEST, GL_NICEST, GL_DONT_CARE };
661 static const char* kHintModeStrings[] = {
662 "HintFastest",
"HintNicest",
"HintDontCare"
665 return EnumData<StateTable::HintMode>(
667 kHintModes, ARRAYSIZE(kHintModes)),
672 template <> ION_API
const EnumHelper::EnumData<StateTable::StencilFunction>
673 EnumHelper::GetEnumData() {
674 static const GLenum kStencilFunctions[] = {
675 GL_ALWAYS, GL_EQUAL, GL_GREATER, GL_GEQUAL,
676 GL_LESS, GL_LEQUAL, GL_NEVER, GL_NOTEQUAL
678 static const char* kStencilFunctionStrings[] = {
679 "StencilAlways",
"StencilEqual",
"StencilGreater",
"StencilGreaterOrEqual",
680 "StencilLess",
"StencilLessOrEqual",
"StencilNever",
"StencilNotEqual"
683 return EnumData<StateTable::StencilFunction>(
685 kStencilFunctions, ARRAYSIZE(kStencilFunctions)),
686 kStencilFunctionStrings);
690 template <> ION_API
const EnumHelper::EnumData<StateTable::StencilOperation>
691 EnumHelper::GetEnumData() {
692 static const GLenum kStencilOperations[] = {
693 GL_DECR, GL_DECR_WRAP, GL_INCR, GL_INCR_WRAP,
694 GL_INVERT, GL_KEEP, GL_REPLACE, GL_ZERO
696 static const char* kStencilOperationStrings[] = {
697 "StencilDecrement",
"StencilDecrementAndWrap",
"StencilIncrement",
698 "StencilIncrementAndWrap",
"StencilInvert",
"StencilKeep",
699 "StencilReplace",
"StencilZero"
702 return EnumData<StateTable::StencilOperation>(
704 kStencilOperations, ARRAYSIZE(kStencilOperations)),
705 kStencilOperationStrings);
708 #undef ION_CHECK_ARRAYS
718 const StateTable::Data& StateTable::GetDefaultData() {
720 static const StateTable::Data default_data(
true);
724 StateTable::Data::Data(
bool unused) {
726 capabilities.reset();
727 capabilities.set(kDither);
730 capabilities_set.reset();
736 blend_color.Set(0.0f, 0.0f, 0.0f, 0.0f);
737 rgb_blend_equation = alpha_blend_equation = kAdd;
738 rgb_blend_source_factor = alpha_blend_source_factor = kOne;
739 rgb_blend_destination_factor = alpha_blend_destination_factor = kZero;
740 clear_color.Set(0.0f, 0.0f, 0.0f, 0.0f);
741 color_write_masks[0] = color_write_masks[1] =
742 color_write_masks[2] = color_write_masks[3] =
true;
743 cull_face_mode = kCullBack;
744 front_face_mode = kCounterClockwise;
745 clear_depth_value = 1.0f;
746 depth_function = kDepthLess;
747 depth_range.Set(0.0f, 1.0f);
748 depth_write_mask =
true;
750 hints[kGenerateMipmapHint] = kHintDontCare;
752 polygon_offset_factor = 0.0f;
753 polygon_offset_units = 0.0f;
754 sample_coverage_value = 1.0f;
755 sample_coverage_inverted =
false;
756 scissor_box.Set(math::Point2i::Zero(), math::Point2i::Zero());
757 front_stencil_function = back_stencil_function = kStencilAlways;
758 front_stencil_reference_value = back_stencil_reference_value = 0;
759 front_stencil_mask = back_stencil_mask = 0xffffffff;
760 front_stencil_fail_op = front_stencil_depth_fail_op =
761 front_stencil_pass_op = back_stencil_fail_op =
762 back_stencil_depth_fail_op = back_stencil_pass_op = kStencilKeep;
763 clear_stencil_value = 0;
764 front_stencil_write_mask = back_stencil_write_mask = 0xffffffff;
765 viewport.Set(math::Point2i::Zero(), math::Point2i::Zero());
void SetCullFaceMode(CullFaceMode mode)
Face culling state.
void SetBlendEquations(BlendEquation rgb_eq, BlendEquation alpha_eq)
Sets/returns the RGB and alpha blend equations.
StencilFunction
OpenGL stencil functions.
FrontFaceMode
OpenGL front face modes.
void SetViewport(const math::Range2i &rect)
Viewport state.
void ResetValue(Value value)
Generic value item functions.
void SetBlendFunctions(BlendFunctionFactor rgb_source_factor, BlendFunctionFactor rgb_destination_factor, BlendFunctionFactor alpha_source_factor, BlendFunctionFactor alpha_destination_factor)
Sets/returns the source and destination factors for the RGB and alpha blend functions.
Value
OpenGL state value items.
CullFaceMode
OpenGL cull face modes.
size_t GetSetCapabilityCount() const
Returns the number of capabilities that are set in the instance.
void SetHint(HintTarget target, HintMode mode)
Hint state.
void SetBlendColor(const math::Vector4f &color)
Blending state.
HintMode
OpenGL hint modes.
void SetClearDepthValue(float value)
Sets/returns the value to clear depth buffers to. The default is 1.
Range< 2, int32 > Range2i
void SetClearStencilValue(int value)
Sets/returns the value to clear stencil buffers to. The default is 0.
void SetStencilFunctions(StencilFunction front_func, int front_reference_value, uint32 front_mask, StencilFunction back_func, int back_reference_value, uint32 back_mask)
Stenciling state.
DepthFunction
OpenGL depth test functions.
#define ION_CHECK_ARRAYS(enums, strings)
static bool AreCapabilitiesSame(const StateTable &st0, const StateTable &st1)
Returns true if the capabilities set in two instances are the same.
void SetDepthRange(const math::Range1f &range)
Sets/returns the range to use for mapping depth values.
This template class can be used to map between two kinds of indices when the following assumptions ap...
DrawBuffer
OpenGL draw buffers.
#define ION_COPY_VAL(var)
void SetLineWidth(float width)
Line width state.
BlendFunctionFactor
OpenGL blend function factors.
void SetStencilOperations(StencilOperation front_stencil_fail, StencilOperation front_depth_fail, StencilOperation front_pass, StencilOperation back_stencil_fail, StencilOperation back_depth_fail, StencilOperation back_pass)
Sets/returns the stencil test actions for front and back faces.
ION_INSTANTIATE_GETENUMSTRING(Capability)
void SetStencilWriteMasks(uint32 front_mask, uint32 back_mask)
Sets/returns a mask indicating which stencil bits will be written for front and back faces...
void CopyFrom(const StateTable &other)
Copies all state (including the default width and height) from another instance.
void Reset()
Resets all items to their default values.
Copyright 2016 Google Inc.
void MergeNonClearValuesFrom(const StateTable &other, const StateTable &state_to_test)
The same as MergeValuesFrom() except that clear-related flags (clear color, depth and stencil values...
void SetDrawBuffer(DrawBuffer draw_buffer)
Draw buffer state.
BlendEquation
Other enumerated types.
void SetColorWriteMasks(bool red, bool green, bool blue, bool alpha)
Color state.
HintTarget
OpenGL hint targets.
void SetDepthWriteMask(bool mask)
Sets/returns whether depth values will be written. The default is true.
bool IsValueSet(Value value) const
Returns a flag indicating whether a value was set since the StateTable was constructed or since the l...
bool AreSettingsEnforced() const
void MergeValuesFrom(const StateTable &other, const StateTable &state_to_test)
Merges all state that has been set in another instance into this one, using the test bits in state_to...
StencilOperation
OpenGL stencil operations.
size_t GetSetValueCount() const
Returns the number of values that are set in the instance.
~StateTable() override
The destructor is protected because all base::Referent classes must have protected or private destruc...
A StateTable represents a collection of graphical state items that affect OpenGL rendering.
void SetScissorBox(const math::Range2i &box)
Scissoring state.
void SetSampleCoverage(float value, bool is_inverted)
Sample coverage state.
#define ION_UPDATE_VALUE(enum_name,...)
This will call the right macro above by concatenating the macro name with the number of arguments...
void SetClearColor(const math::Vector4f &color)
Clear state.
void SetPolygonOffset(float factor, float units)
Polygon offset state.
Range< 1, float > Range1f
void SetDepthFunction(DepthFunction func)
Depth buffer state.
void SetFrontFaceMode(FrontFaceMode mode)
Sets/returns which faces are considered front-facing.