Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
statetable.cc
Go to the documentation of this file.
1 
18 #include "ion/gfx/statetable.h"
19 
20 #include "ion/base/argcount.h"
21 #include "ion/base/enumhelper.h"
22 #include "ion/base/logging.h"
23 #include "ion/base/static_assert.h"
24 #include "ion/portgfx/glheaders.h"
25 
26 namespace ion {
27 namespace gfx {
28 
30 }
31 
34  data_ = GetDefaultData();
35 
37  const math::Point2i max_point(default_width_, default_height_);
38  data_.scissor_box.SetMaxPoint(max_point);
39  data_.viewport.SetMaxPoint(max_point);
40 }
41 
42 void StateTable::CopyFrom(const StateTable& other) {
43  default_width_ = other.default_width_;
44  default_height_ = other.default_height_;
45  data_ = other.data_;
46 }
47 
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__)
67 
70 #define ION_UPDATE_VALUE(enum_name, ...) \
71  if (state_to_test.IsValueSet(enum_name)) { \
72  data_.values_set.set(enum_name); \
73  ION_UPDATE_VALUE_( \
74  ION_ARGCOUNT_XCONCAT(ION_UPDATE_VALUE, ION_ARGCOUNT(__VA_ARGS__)), \
75  __VA_ARGS__); \
76  }
77 
79  const StateTable& state_to_test) {
80  MergeNonClearValuesFrom(other, state_to_test);
81 
83  if (state_to_test.GetSetValueCount()) {
85  ION_UPDATE_VALUE(kClearDepthValue, clear_depth_value)
86  ION_UPDATE_VALUE(kClearStencilValue, clear_stencil_value)
87  }
88 }
89 
91  const StateTable& state_to_test) {
93  if (state_to_test.GetSetCapabilityCount() &&
94  (!AreCapabilitiesSame(*this, other) ||
95  state_to_test.AreSettingsEnforced())) {
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);
101  }
102  }
103  }
104 
106  if (state_to_test.GetSetValueCount()) {
107  ION_UPDATE_VALUE(kBlendColorValue, blend_color)
108  ION_UPDATE_VALUE(kBlendEquationsValue, rgb_blend_equation,
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])
120  ION_UPDATE_VALUE(kCullFaceModeValue, cull_face_mode)
121  ION_UPDATE_VALUE(kDepthWriteMaskValue, depth_write_mask)
122  ION_UPDATE_VALUE(kFrontFaceModeValue, front_face_mode)
123  ION_UPDATE_VALUE(kDepthFunctionValue, depth_function)
124  ION_UPDATE_VALUE(kDepthRangeValue, depth_range)
125  ION_UPDATE_VALUE(kDrawBufferValue, draw_buffer);
127  if (other.IsValueSet(StateTable::kHintsValue)) {
128  for (int i = 0; i < kNumHints; ++i)
129  data_.hints[i] = other.data_.hints[i];
130  }
131  ION_UPDATE_VALUE(kLineWidthValue, line_width)
133  kPolygonOffsetValue, polygon_offset_factor, polygon_offset_units)
135  kSampleCoverageValue, sample_coverage_value, sample_coverage_inverted)
137  front_stencil_function,
138  back_stencil_function,
139  front_stencil_reference_value,
140  back_stencil_reference_value,
141  front_stencil_mask,
142  back_stencil_mask)
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)
151  ION_UPDATE_VALUE(kScissorBoxValue, scissor_box)
153  front_stencil_write_mask,
154  back_stencil_write_mask)
155  }
156 }
157 
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
166 
168 
172 #define ION_COPY_VAL(var) data_.var = default_data.var
173 
174  const Data& default_data = GetDefaultData();
175 
176  switch (value) {
177  case kBlendColorValue:
178  ION_COPY_VAL(blend_color);
179  break;
181  ION_COPY_VAL(rgb_blend_equation);
182  ION_COPY_VAL(alpha_blend_equation);
183  break;
185  ION_COPY_VAL(rgb_blend_source_factor);
186  ION_COPY_VAL(rgb_blend_destination_factor);
187  ION_COPY_VAL(alpha_blend_source_factor);
188  ION_COPY_VAL(alpha_blend_destination_factor);
189  break;
190  case kClearColorValue:
191  ION_COPY_VAL(clear_color);
192  break;
194  for (int i = 0; i < 4; ++i) {
195  ION_COPY_VAL(color_write_masks[i]);
196  }
197  break;
198  case kCullFaceModeValue:
199  ION_COPY_VAL(cull_face_mode);
200  break;
201  case kFrontFaceModeValue:
202  ION_COPY_VAL(front_face_mode);
203  break;
204  case kClearDepthValue:
205  ION_COPY_VAL(clear_depth_value);
206  break;
207  case kDepthFunctionValue:
208  ION_COPY_VAL(depth_function);
209  break;
210  case kDepthRangeValue:
211  ION_COPY_VAL(depth_range);
212  break;
214  ION_COPY_VAL(depth_write_mask);
215  break;
216  case kDrawBufferValue:
217  ION_COPY_VAL(draw_buffer);
218  break;
219  case kHintsValue:
220  for (int i = 0; i < kNumHints; ++i) {
221  ION_COPY_VAL(hints[i]);
222  }
223  break;
224  case kLineWidthValue:
225  ION_COPY_VAL(line_width);
226  break;
227  case kPolygonOffsetValue:
228  ION_COPY_VAL(polygon_offset_factor);
229  ION_COPY_VAL(polygon_offset_units);
230  break;
232  ION_COPY_VAL(sample_coverage_value);
233  ION_COPY_VAL(sample_coverage_inverted);
234  break;
235  case kScissorBoxValue:
236  data_.scissor_box.SetWithSize(
237  default_data.scissor_box.GetMinPoint(),
238  math::Vector2i(default_width_, default_height_));
239  break;
241  ION_COPY_VAL(front_stencil_function);
242  ION_COPY_VAL(back_stencil_function);
243  ION_COPY_VAL(front_stencil_reference_value);
244  ION_COPY_VAL(back_stencil_reference_value);
245  ION_COPY_VAL(front_stencil_mask);
246  ION_COPY_VAL(back_stencil_mask);
247  break;
249  ION_COPY_VAL(front_stencil_fail_op);
250  ION_COPY_VAL(front_stencil_depth_fail_op);
251  ION_COPY_VAL(front_stencil_pass_op);
252  ION_COPY_VAL(back_stencil_fail_op);
253  ION_COPY_VAL(back_stencil_depth_fail_op);
254  ION_COPY_VAL(back_stencil_pass_op);
255  break;
256  case kClearStencilValue:
257  ION_COPY_VAL(clear_stencil_value);
258  break;
260  ION_COPY_VAL(front_stencil_write_mask);
261  ION_COPY_VAL(back_stencil_write_mask);
262  break;
263  case kViewportValue:
264  data_.viewport.SetWithSize(
265  default_data.viewport.GetMinPoint(),
266  math::Vector2i(default_width_, default_height_));
267  break;
268  default:
269  DCHECK(false) << "Invalid Value type";
270  return;
271  }
272 
274  data_.values_set.reset(value);
275 
276 #undef ION_COPY_VAL
277 }
278 
280 
282 
283 void StateTable::SetBlendColor(const math::Vector4f& color) {
284  data_.blend_color = color;
285  data_.values_set.set(kBlendColorValue);
286 }
287 
289  BlendEquation alpha_eq) {
290  data_.rgb_blend_equation = rgb_eq;
291  data_.alpha_blend_equation = alpha_eq;
292  data_.values_set.set(kBlendEquationsValue);
293 }
294 
296  BlendFunctionFactor rgb_source_factor,
297  BlendFunctionFactor rgb_destination_factor,
298  BlendFunctionFactor alpha_source_factor,
299  BlendFunctionFactor alpha_destination_factor) {
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;
304  data_.values_set.set(kBlendFunctionsValue);
305 }
306 
308 
310 
311 void StateTable::SetClearColor(const math::Vector4f& color) {
312  data_.clear_color = color;
313  data_.values_set.set(kClearColorValue);
314 }
315 
316 void StateTable::SetColorWriteMasks(bool red, bool green,
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;
322  data_.values_set.set(kColorWriteMasksValue);
323 }
324 
326 
328 
330  data_.cull_face_mode = mode;
331  data_.values_set.set(kCullFaceModeValue);
332 }
333 
337  data_.front_face_mode = mode;
338  data_.values_set.set(kFrontFaceModeValue);
339 }
340 
342 
344 
346  data_.clear_depth_value = value;
347  data_.values_set.set(kClearDepthValue);
348 }
349 
351  data_.depth_function = func;
352  data_.values_set.set(kDepthFunctionValue);
353 }
354 
356  data_.depth_range = range;
357  data_.values_set.set(kDepthRangeValue);
358 }
359 
361  data_.depth_write_mask = mask;
362  data_.values_set.set(kDepthWriteMaskValue);
363 }
364 
366 
368 
370  data_.draw_buffer = draw_buffer;
371  data_.values_set.set(kDrawBufferValue);
372 }
373 
375 
377 
379  data_.hints[target] = mode;
380  data_.values_set.set(kHintsValue);
381 }
382 
384 
386 
388  data_.line_width = width;
389  data_.values_set.set(kLineWidthValue);
390 }
391 
393 
395 
396 void StateTable::SetPolygonOffset(float factor, float units) {
397  data_.polygon_offset_factor = factor;
398  data_.polygon_offset_units = units;
399  data_.values_set.set(kPolygonOffsetValue);
400 }
401 
403 
405 
406 void StateTable::SetSampleCoverage(float value, bool is_inverted) {
407  data_.sample_coverage_value = value;
408  data_.sample_coverage_inverted = is_inverted;
409  data_.values_set.set(kSampleCoverageValue);
410 }
411 
413 
415 
417  data_.scissor_box = box;
418  data_.values_set.set(kScissorBoxValue);
419 }
420 
422 
424 
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;
434  data_.values_set.set(kStencilFunctionsValue);
435 }
436 
438  StencilOperation front_depth_fail,
439  StencilOperation front_pass,
440  StencilOperation back_stencil_fail,
441  StencilOperation back_depth_fail,
442  StencilOperation back_pass) {
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;
449  data_.values_set.set(kStencilOperationsValue);
450 }
451 
454  data_.clear_stencil_value = value;
455  data_.values_set.set(kClearStencilValue);
456 }
457 
458 void StateTable::SetStencilWriteMasks(uint32 front_mask, uint32 back_mask) {
459  data_.front_stencil_write_mask = front_mask;
460  data_.back_stencil_write_mask = back_mask;
461  data_.values_set.set(kStencilWriteMasksValue);
462 }
463 
465 
467 
469  data_.viewport = rect;
470  data_.values_set.set(kViewportValue);
471 }
472 
473 void StateTable::SetViewport(int left, int bottom, int width, int height) {
474  SetViewport(math::Range2i::BuildWithSize(math::Point2i(left, bottom),
475  math::Vector2i(width, height)));
476 }
477 
479 
481 
482 #define ION_INSTANTIATE_GETENUMSTRING(type) \
483  template <> ION_API const char* StateTable::GetEnumString(type value) { \
484  return base::EnumHelper::GetString(value); \
485  }
486 
488 ION_INSTANTIATE_GETENUMSTRING(BlendEquation);
489 ION_INSTANTIATE_GETENUMSTRING(BlendFunctionFactor);
490 ION_INSTANTIATE_GETENUMSTRING(CullFaceMode);
491 ION_INSTANTIATE_GETENUMSTRING(DepthFunction);
492 ION_INSTANTIATE_GETENUMSTRING(FrontFaceMode);
494 ION_INSTANTIATE_GETENUMSTRING(StencilFunction);
495 ION_INSTANTIATE_GETENUMSTRING(StencilOperation);
496 
497 #undef ION_INSTANTIATE_GETENUMSTRING
498 
499 } // namespace gfx
500 
502 
504 
505 namespace base {
506 
507 using gfx::StateTable;
508 
509 #define ION_CHECK_ARRAYS(enums, strings) \
510  ION_STATIC_ASSERT(ARRAYSIZE(enums) == ARRAYSIZE(strings), \
511  "Wrong size for " #strings)
512 
515 
517 template <> ION_API const EnumHelper::EnumData<StateTable::Capability>
518 EnumHelper::GetEnumData() {
519  static const GLenum kCapabilities[] = {
520  GL_BLEND,
521  GL_CULL_FACE,
522  GL_DEBUG_OUTPUT_SYNCHRONOUS,
523  GL_DEPTH_TEST,
524  GL_DITHER,
525  GL_MULTISAMPLE,
526  GL_POLYGON_OFFSET_FILL,
527  GL_SAMPLE_ALPHA_TO_COVERAGE,
528  GL_SAMPLE_COVERAGE,
529  GL_SCISSOR_TEST,
530  GL_STENCIL_TEST,
531  };
532  static const char* kCapabilityStrings[] = {
533  "Blend",
534  "CullFace",
535  "DebugOutputSynchronous",
536  "DepthTest",
537  "Dither",
538  "Multisample",
539  "PolygonOffsetFill",
540  "SampleAlphaToCoverage",
541  "SampleCoverage",
542  "ScissorTest",
543  "StencilTest",
544  };
545  ION_CHECK_ARRAYS(kCapabilities, kCapabilityStrings);
546  return EnumData<StateTable::Capability>(
548  kCapabilities, ARRAYSIZE(kCapabilities)),
549  kCapabilityStrings);
550 }
551 
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
557  };
558  static const char* kBlendEquationStrings[] = {
559  "Add", "ReverseSubtract", "Subtract",
560  };
561  ION_CHECK_ARRAYS(kBlendEquations, kBlendEquationStrings);
562  return EnumData<StateTable::BlendEquation>(
564  kBlendEquations, ARRAYSIZE(kBlendEquations)),
565  kBlendEquationStrings);
566 }
567 
569 template <> ION_API
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,
577  GL_ZERO
578  };
579  static const char* kBlendFunctionFactorStrings[] = {
580  "ConstantAlpha", "ConstantColor", "DstAlpha", "DstColor", "One",
581  "OneMinusConstantAlpha", "OneMinusConstantColor", "OneMinusDstAlpha",
582  "OneMinusDstColor", "OneMinusSrcAlpha", "OneMinusSrcColor", "SrcAlpha",
583  "SrcAlphaSaturate", "SrcColor", "Zero"
584  };
585  ION_CHECK_ARRAYS(kBlendFunctionFactors, kBlendFunctionFactorStrings);
586  return EnumData<StateTable::BlendFunctionFactor>(
588  kBlendFunctionFactors, ARRAYSIZE(kBlendFunctionFactors)),
589  kBlendFunctionFactorStrings);
590 }
591 
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
597  };
598  static const char* kCullFaceModeStrings[] = {
599  "CullFront", "CullBack", "CullFrontAndBack",
600  };
601  ION_CHECK_ARRAYS(kCullFaceModes, kCullFaceModeStrings);
602  return EnumData<StateTable::CullFaceMode>(
604  kCullFaceModes, ARRAYSIZE(kCullFaceModes)),
605  kCullFaceModeStrings);
606 }
607 
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
614  };
615  static const char* kDepthFunctionStrings[] = {
616  "DepthAlways", "DepthEqual", "DepthGreater", "DepthGreaterOrEqual",
617  "DepthLess", "DepthLessOrEqual", "DepthNever", "DepthNotEqual"
618  };
619  ION_CHECK_ARRAYS(kDepthFunctions, kDepthFunctionStrings);
620  return EnumData<StateTable::DepthFunction>(
622  kDepthFunctions, ARRAYSIZE(kDepthFunctions)),
623  kDepthFunctionStrings);
624 }
625 
627 template <>
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"};
636  ION_CHECK_ARRAYS(kDrawBuffers, kDrawBufferStrings);
637  return EnumData<StateTable::DrawBuffer>(
639  ARRAYSIZE(kDrawBuffers)),
640  kDrawBufferStrings);
641 }
642 
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"
649  };
650  ION_CHECK_ARRAYS(kFrontFaceModes, kFrontFaceModeStrings);
651  return EnumData<StateTable::FrontFaceMode>(
653  kFrontFaceModes, ARRAYSIZE(kFrontFaceModes)),
654  kFrontFaceModeStrings);
655 }
656 
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"
663  };
664  ION_CHECK_ARRAYS(kHintModes, kHintModeStrings);
665  return EnumData<StateTable::HintMode>(
667  kHintModes, ARRAYSIZE(kHintModes)),
668  kHintModeStrings);
669 }
670 
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
677  };
678  static const char* kStencilFunctionStrings[] = {
679  "StencilAlways", "StencilEqual", "StencilGreater", "StencilGreaterOrEqual",
680  "StencilLess", "StencilLessOrEqual", "StencilNever", "StencilNotEqual"
681  };
682  ION_CHECK_ARRAYS(kStencilFunctions, kStencilFunctionStrings);
683  return EnumData<StateTable::StencilFunction>(
685  kStencilFunctions, ARRAYSIZE(kStencilFunctions)),
686  kStencilFunctionStrings);
687 }
688 
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
695  };
696  static const char* kStencilOperationStrings[] = {
697  "StencilDecrement", "StencilDecrementAndWrap", "StencilIncrement",
698  "StencilIncrementAndWrap", "StencilInvert", "StencilKeep",
699  "StencilReplace", "StencilZero"
700  };
701  ION_CHECK_ARRAYS(kStencilOperations, kStencilOperationStrings);
702  return EnumData<StateTable::StencilOperation>(
704  kStencilOperations, ARRAYSIZE(kStencilOperations)),
705  kStencilOperationStrings);
706 }
707 
708 #undef ION_CHECK_ARRAYS
709 
710 } // namespace base
711 
712 namespace gfx {
713 
715 
717 
718 const StateTable::Data& StateTable::GetDefaultData() {
720  static const StateTable::Data default_data(true);
721  return default_data;
722 }
723 
724 StateTable::Data::Data(bool unused) {
726  capabilities.reset();
727  capabilities.set(kDither);
728 
730  capabilities_set.reset();
731  values_set.reset();
732 
733  is_enforced = false;
734 
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;
749  draw_buffer = kBack;
750  hints[kGenerateMipmapHint] = kHintDontCare;
751  line_width = 1.0f;
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());
766 }
767 
768 } // namespace gfx
769 } // namespace ion
void SetCullFaceMode(CullFaceMode mode)
Face culling state.
Definition: statetable.cc:329
void SetBlendEquations(BlendEquation rgb_eq, BlendEquation alpha_eq)
Sets/returns the RGB and alpha blend equations.
Definition: statetable.cc:288
StencilFunction
OpenGL stencil functions.
Definition: statetable.h:187
FrontFaceMode
OpenGL front face modes.
Definition: statetable.h:169
void SetViewport(const math::Range2i &rect)
Viewport state.
Definition: statetable.cc:468
void ResetValue(Value value)
Generic value item functions.
Definition: statetable.cc:170
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.
Definition: statetable.cc:295
Value
OpenGL state value items.
Definition: statetable.h:72
CullFaceMode
OpenGL cull face modes.
Definition: statetable.h:136
size_t GetSetCapabilityCount() const
Returns the number of capabilities that are set in the instance.
Definition: statetable.h:310
void SetHint(HintTarget target, HintMode mode)
Hint state.
Definition: statetable.cc:378
#define DCHECK(expr)
Definition: logging.h:331
double value
void SetBlendColor(const math::Vector4f &color)
Blending state.
Definition: statetable.cc:283
HintMode
OpenGL hint modes.
Definition: statetable.h:175
void SetClearDepthValue(float value)
Sets/returns the value to clear depth buffers to. The default is 1.
Definition: statetable.cc:345
Range< 2, int32 > Range2i
Definition: range.h:371
void SetClearStencilValue(int value)
Sets/returns the value to clear stencil buffers to. The default is 0.
Definition: statetable.cc:453
void SetStencilFunctions(StencilFunction front_func, int front_reference_value, uint32 front_mask, StencilFunction back_func, int back_reference_value, uint32 back_mask)
Stenciling state.
Definition: statetable.cc:425
DepthFunction
OpenGL depth test functions.
Definition: statetable.h:143
#define ION_CHECK_ARRAYS(enums, strings)
Definition: statetable.cc:509
static bool AreCapabilitiesSame(const StateTable &st0, const StateTable &st1)
Returns true if the capabilities set in two instances are the same.
Definition: statetable.h:315
void SetDepthRange(const math::Range1f &range)
Sets/returns the range to use for mapping depth values.
Definition: statetable.cc:355
This template class can be used to map between two kinds of indices when the following assumptions ap...
Definition: indexmap.h:40
DrawBuffer
OpenGL draw buffers.
Definition: statetable.h:155
#define ION_COPY_VAL(var)
void SetLineWidth(float width)
Line width state.
Definition: statetable.cc:387
BlendFunctionFactor
OpenGL blend function factors.
Definition: statetable.h:110
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.
Definition: statetable.cc:437
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...
Definition: statetable.cc:458
void CopyFrom(const StateTable &other)
Copies all state (including the default width and height) from another instance.
Definition: statetable.cc:42
void Reset()
Resets all items to their default values.
Definition: statetable.cc:32
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...
Definition: statetable.cc:90
void SetDrawBuffer(DrawBuffer draw_buffer)
Draw buffer state.
Definition: statetable.cc:369
int width
BlendEquation
Other enumerated types.
Definition: statetable.h:103
void SetColorWriteMasks(bool red, bool green, bool blue, bool alpha)
Color state.
Definition: statetable.cc:316
HintTarget
OpenGL hint targets.
Definition: statetable.h:182
void SetDepthWriteMask(bool mask)
Sets/returns whether depth values will be written. The default is true.
Definition: statetable.cc:360
bool IsValueSet(Value value) const
Returns a flag indicating whether a value was set since the StateTable was constructed or since the l...
Definition: statetable.h:332
bool AreSettingsEnforced() const
Definition: statetable.h:350
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...
Definition: statetable.cc:78
StencilOperation
OpenGL stencil operations.
Definition: statetable.h:199
size_t GetSetValueCount() const
Returns the number of values that are set in the instance.
Definition: statetable.h:337
~StateTable() override
The destructor is protected because all base::Referent classes must have protected or private destruc...
Definition: statetable.cc:29
A StateTable represents a collection of graphical state items that affect OpenGL rendering.
Definition: statetable.h:48
void SetScissorBox(const math::Range2i &box)
Scissoring state.
Definition: statetable.cc:416
void SetSampleCoverage(float value, bool is_inverted)
Sample coverage state.
Definition: statetable.cc:406
#define ION_UPDATE_VALUE(enum_name,...)
This will call the right macro above by concatenating the macro name with the number of arguments...
Definition: statetable.cc:70
void SetClearColor(const math::Vector4f &color)
Clear state.
Definition: statetable.cc:311
void SetPolygonOffset(float factor, float units)
Polygon offset state.
Definition: statetable.cc:396
Range< 1, float > Range1f
Definition: range.h:365
void SetDepthFunction(DepthFunction func)
Depth buffer state.
Definition: statetable.cc:350
void SetFrontFaceMode(FrontFaceMode mode)
Sets/returns which faces are considered front-facing.
Definition: statetable.cc:336