18 #ifndef ION_GFX_STATETABLE_H_
19 #define ION_GFX_STATETABLE_H_
23 #include "base/integral_types.h"
223 : default_width_(default_width),
224 default_height_(default_height) {
237 data_.capabilities_set.reset();
238 data_.values_set.reset();
245 data_.capabilities_set.set();
246 data_.values_set.set();
269 void MergeNonClearValuesFrom(
const StateTable& other,
279 data_.capabilities.set(capability, is_enabled);
280 data_.capabilities_set.set(capability);
285 return data_.capabilities.test(capability);
290 return data_.capabilities.count();
295 if (capability == kDither)
296 data_.capabilities.set(capability);
298 data_.capabilities.reset(capability);
299 data_.capabilities_set.reset(capability);
306 return data_.capabilities_set.test(capability);
311 return data_.capabilities_set.count();
317 return st0.data_.capabilities == st1.data_.capabilities;
333 return data_.values_set.test(value);
338 return data_.values_set.count();
357 void SetBlendColor(
const math::Vector4f& color);
362 void SetBlendEquations(BlendEquation rgb_eq, BlendEquation alpha_eq);
365 return data_.alpha_blend_equation;
370 void SetBlendFunctions(BlendFunctionFactor rgb_source_factor,
371 BlendFunctionFactor rgb_destination_factor,
372 BlendFunctionFactor alpha_source_factor,
373 BlendFunctionFactor alpha_destination_factor);
375 return data_.rgb_blend_source_factor;
378 return data_.rgb_blend_destination_factor;
381 return data_.alpha_blend_source_factor;
384 return data_.alpha_blend_destination_factor;
392 void SetClearColor(
const math::Vector4f& color);
396 void SetClearDepthValue(
float value);
400 void SetClearStencilValue(
int value);
409 void SetColorWriteMasks(
bool red,
bool green,
bool blue,
bool alpha);
421 void SetCullFaceMode(CullFaceMode mode);
426 void SetFrontFaceMode(FrontFaceMode mode);
435 void SetDepthFunction(DepthFunction func);
444 void SetDepthWriteMask(
bool mask);
452 void SetDrawBuffer(DrawBuffer draw_buffer);
461 void SetHint(HintTarget target, HintMode mode);
469 void SetLineWidth(
float width);
478 void SetPolygonOffset(
float factor,
float units);
488 void SetSampleCoverage(
float value,
bool is_inverted);
491 return data_.sample_coverage_inverted;
509 void SetStencilFunctions(
510 StencilFunction front_func,
int front_reference_value, uint32 front_mask,
511 StencilFunction back_func,
int back_reference_value, uint32 back_mask);
513 return data_.front_stencil_function;
516 return data_.back_stencil_function;
519 return data_.front_stencil_reference_value;
522 return data_.back_stencil_reference_value;
529 void SetStencilOperations(StencilOperation front_stencil_fail,
530 StencilOperation front_depth_fail,
531 StencilOperation front_pass,
532 StencilOperation back_stencil_fail,
533 StencilOperation back_depth_fail,
534 StencilOperation back_pass);
536 return data_.front_stencil_fail_op;
539 return data_.front_stencil_depth_fail_op;
542 return data_.front_stencil_pass_op;
545 return data_.back_stencil_fail_op;
548 return data_.back_stencil_depth_fail_op;
551 return data_.back_stencil_pass_op;
556 void SetStencilWriteMasks(uint32 front_mask, uint32 back_mask);
558 return data_.front_stencil_write_mask;
561 return data_.back_stencil_write_mask;
570 void SetViewport(
int left,
int bottom,
int width,
int height);
578 template <
typename EnumType>
static const char* GetEnumString(EnumType
value);
587 static const int kNumStateValues = kViewportValue + 1;
590 static const int kNumClearMaskBits = kClearStencilBufferBit + 1;
593 static const int kNumHints = kGenerateMipmapHint + 1;
607 explicit Data(
bool unused);
610 std::bitset<kNumCapabilities> capabilities_set;
613 std::bitset<kNumStateValues> values_set;
616 std::bitset<kNumCapabilities> capabilities;
625 math::Vector4f blend_color;
626 BlendEquation rgb_blend_equation;
627 BlendEquation alpha_blend_equation;
628 BlendFunctionFactor rgb_blend_source_factor;
629 BlendFunctionFactor rgb_blend_destination_factor;
630 BlendFunctionFactor alpha_blend_source_factor;
631 BlendFunctionFactor alpha_blend_destination_factor;
634 math::Vector4f clear_color;
635 float clear_depth_value;
636 int clear_stencil_value;
639 bool color_write_masks[4];
642 CullFaceMode cull_face_mode;
643 FrontFaceMode front_face_mode;
646 DepthFunction depth_function;
648 bool depth_write_mask;
651 DrawBuffer draw_buffer;
654 HintMode hints[kNumHints];
660 float polygon_offset_factor;
661 float polygon_offset_units;
664 float sample_coverage_value;
665 bool sample_coverage_inverted;
671 StencilFunction front_stencil_function;
672 StencilFunction back_stencil_function;
673 int front_stencil_reference_value;
674 int back_stencil_reference_value;
675 uint32 front_stencil_mask;
676 uint32 back_stencil_mask;
677 StencilOperation front_stencil_fail_op;
678 StencilOperation front_stencil_depth_fail_op;
679 StencilOperation front_stencil_pass_op;
680 StencilOperation back_stencil_fail_op;
681 StencilOperation back_stencil_depth_fail_op;
682 StencilOperation back_stencil_pass_op;
683 uint32 front_stencil_write_mask;
684 uint32 back_stencil_write_mask;
694 static const Data& GetDefaultData();
710 #endif // ION_GFX_STATETABLE_H_
const math::Range2i & GetViewport() const
Returns the viewport rectangle.
bool GetDepthWriteMask() const
int GetClearStencilValue() const
StencilFunction
OpenGL stencil functions.
FrontFaceMode
OpenGL front face modes.
BlendFunctionFactor GetAlphaBlendFunctionSourceFactor() const
bool GetRedColorWriteMask() const
uint32 GetFrontStencilMask() const
uint32 GetFrontStencilWriteMask() const
StencilOperation GetBackStencilFailOperation() const
bool GetAlphaColorWriteMask() const
uint32 GetBackStencilWriteMask() const
Value
OpenGL state value items.
float GetPolygonOffsetFactor() const
const math::Range1f & GetDepthRange() const
const math::Vector4f & GetClearColor() const
CullFaceMode
OpenGL cull face modes.
StencilOperation GetBackStencilPassOperation() const
size_t GetSetCapabilityCount() const
Returns the number of capabilities that are set in the instance.
bool IsEnabled(Capability capability) const
Returns a flag indicating whether a capability is enabled.
DrawBuffer GetDrawBuffer() const
Returns the target draw buffer.
HintMode GetHint(HintTarget target) const
StencilOperation GetBackStencilDepthFailOperation() const
void ResetCapability(Capability capability)
Resets a capability flag to its default state.
BlendEquation GetAlphaBlendEquation() const
HintMode
OpenGL hint modes.
Capability
Enumerated types for StateTable items.
Range< 2, int32 > Range2i
void MarkAllSet()
Sets the "set" state to true for all capabilities and values of the StateTable; future calls to IsVal...
bool GetBlueColorWriteMask() const
base::ReferentPtr< StateTable >::Type StateTablePtr
Convenience typedef for shared pointer to a StateTable.
Thread-safe abstract base class.
DepthFunction
OpenGL depth test functions.
static bool AreCapabilitiesSame(const StateTable &st0, const StateTable &st1)
Returns true if the capabilities set in two instances are the same.
static int GetValueCount()
Returns the number of Values.
StateTable()
The constructor initializes the instance to contain all default values.
StencilOperation GetFrontStencilPassOperation() const
float GetSampleCoverageValue() const
bool IsCapabilitySet(Capability capability) const
Returns a flag indicating whether a capability was set since the StateTable was constructed or since ...
BlendEquation GetRgbBlendEquation() const
static int GetCapabilityCount()
Returns the number of Capabilities.
CullFaceMode GetCullFaceMode() const
FrontFaceMode GetFrontFaceMode() const
DrawBuffer
OpenGL draw buffers.
const math::Vector4f & GetBlendColor() const
BlendFunctionFactor GetRgbBlendFunctionDestinationFactor() const
StencilOperation GetFrontStencilDepthFailOperation() const
BlendFunctionFactor GetRgbBlendFunctionSourceFactor() const
void ResetSetState()
Resets the "set" state of the StateTable; future calls to IsValueSet() or IsCapabilitySet() will retu...
StencilFunction GetFrontStencilFunction() const
void Enable(Capability capability, bool is_enabled)
Capability item functions.
float GetClearDepthValue() const
bool GetGreenColorWriteMask() const
BlendFunctionFactor
OpenGL blend function factors.
DepthFunction GetDepthFunction() const
void SetEnforceSettings(bool enforced)
Sets/returns whether enforcement is enabled.
BlendEquation
Other enumerated types.
BlendFunctionFactor GetAlphaBlendFunctionDestinationFactor() const
HintTarget
OpenGL hint targets.
size_t GetEnabledCount() const
Returns the number of capabilities that are enabled in the instance.
int GetFrontStencilReferenceValue() const
StencilFunction GetBackStencilFunction() const
int GetBackStencilReferenceValue() const
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
StateTable(int default_width, int default_height)
float GetPolygonOffsetUnits() const
StencilOperation
OpenGL stencil operations.
size_t GetSetValueCount() const
Returns the number of values that are set in the instance.
StencilOperation GetFrontStencilFailOperation() const
A StateTable represents a collection of graphical state items that affect OpenGL rendering.
uint32 GetBackStencilMask() const
A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting...
const math::Range2i & GetScissorBox() const
float GetLineWidth() const
bool IsSampleCoverageInverted() const
ClearMaskBit
OpenGL clear mask bits.
Range< 1, float > Range1f