ClientContext
#include
<oglplus/client_context.hpp>
The ClientContext
class keeps local copies of most of
the GL context state variable values and allows to query and manipulate
them more efficiently. During construction an instance of ClientContext
queries the values of all GL state variables, which are managed by it.
When successfully constructed the members of this instance can be used
to obtain the cached value without actually querying GL. Furthermore the
values can also be modified and pushed and subsequently popped from a stack.
The modification operations compare the new value with the current and
call to the functions from the GL API which change the GL state are made
only if they are different. The stack functionality allows to temporarily
change the value of a GL context setting and restore the previous value
later.
Note | |
---|---|
In order to function properly, the use of |
class ClientContext : public client::CapabilityState , public client::ViewportState , public client::ClipControlState , public client::BufferMaskingState , public client::BufferClearingOps , public client::BufferClearingState , public client::RasterizationState , public client::RasterizationOps , public client::DrawingState , public client::DrawingOps , public client::ComputingOps , public client::DepthTestState , public client::StencilTestState , public client::ScissorTestState , public client::LogicOpState , public client::PixelState , public client::PixelOps , public client::BlendingOps , public client::BlendingState , public client::Synchronization , public client::HintState , public client::LimitQueries , public client::NumericQueries , public client::StringQueries , public client::CurrentObjects { };
ClientContext gl; gl.ClearColor.Set(0.3f, 0.3f, 0.3f, 0.0f); gl.ClearDepth.Set(1.0f); gl.Caps.DepthTest.Disable(); gl.Caps.Blend.Enable(); gl.BlendFunc.Set(BlendFunction::SrcAlpha, BlendFunction::OneMinusSrcAlpha); gl.LineWidth.Set(1.5f); gl.Viewport.Set(800, 600); gl.Clear().ColorBuffer().DepthBuffer().StencilBuffer(); Program prog; VertexArray vao; /* ... */ gl.Program.Bind(prog); gl.VertexArray.Bind(vao); { auto no_blend = gl.Caps.Blend.Push(false); auto no_depth = gl.Caps.DepthTest.Push(false); gl.DrawArrays(PrimitiveType::TriangleStrip, 0, n); assert(no_depth); no_depth.Pop(); assert(!no_depth); gl.DrawArrays(PrimitiveType::TriangleStrip, 0, n); } gl.DrawElements(PrimitiveType::TriangleStrip, m, DataType::UnsignedInt);
Stateful (caching) wrapper for a GL context. During the construction of this instance the values of current GL context variables are queried and stored internally. |
|
When using ClientContext,
then |
|
Likewise, other objects bound to their binding points, must be bound
through the client context wrapper, not by |
|
Push a new value |
|
The setting holders returned by |
|
Explicitly pop the pushed setting of |
|
After the value in the holder has been popped conversion to |
|
When the |
#include
<oglplus/client/setting.hpp>
Instances of SettingHolder
are created by various
instantiations of SettingStack
when a new value is pushed on top of the stack. The purpose of a setting
holder is to keep that value on top of the stack. While an instance of
SettingHolder
is alive, then the associated value
is kept on the stack. Once the holder is destroyed, the associated value
is popped from the stack an the previous GL context setting is restored
(to the next value on the stack). The values can also be popped (once)
explicitly by calling the Pop
member function.
OGLplus library client applications should never need to instantiate
SettingHolder
directly. Either use the auto
keyword or the typedefs in SettingStack
.
namespace client { template <typename T, ...> class SettingHolder { public: SettingHolder(const SettingHolder&) = delete; SettingHolder(SettingHolder&&) noexcept; ~SettingHolder(void) noexcept; void Pop(void) noexcept; explicit operator bool (void) const noexcept; }; } // namespace client
Implicitly pops the value which this holder keeps from the setting
stack which created |
|
Explicitly pops the value which this holder keeps from the setting
stack which created |
|
Returns |
Instances of SettingStack
are used to maintain and
manage the the values of a single particular GL context setting. In the
constructor they query the initial value of the managed setting and push
it on top of the stack. The user can then repeatedly query the values
(without actually querying GL state) by the Set
member
functions, change the value of the setting (both locally and in the GL
context if necessary) by calling the Set
member functions,
Push
new values on top of the stack while keeping
the previous ones (and changing the GL context if necessary) and finally
to Pop
the values from the stack either implicitly
or explicitly (and updating the GL context accordingly).
OGLplus library client applications should never need to instantiate
SettingStack
directly. The (direct or indirect) members
of ClientContext
should be used.
namespace client { template <typename T, ...> class SettingStack { public: SettingStack(const SettingStack&) = delete; SettingStack(void); typedef SettingHolder<T, ...> Holder; SettingStack& operator [] (Index index); SettingStack& Indexed(Index index); Holder Push(T value); template <typename ... A> Holder Push(A&& ... a); T Get(void) const noexcept; void Set(T value); template <typename ... A> void Set(A&& ... a); }; } // namespace client
Queries the current value of the setting that this stack manages and pushes it on itself as the first element. |
|
Returns a reference to itself if |
|
Pushes a new value on top of the setting stack. When the returned
instance of |
|
This overload of |
|
Returns the value of the setting on the top of this setting stack. |
|
Changes the current setting value without pushing on the stack. |
|
This overload of |
Instances of SettingStackIndexed
are used to manage
the values of indexed GL context settings. They maintain a sequence of
SettingStack
instances, each for a single setting at a particular index.
The individual setting stacks are accessed via the Indexed
member function or the operator[]
. The settings on
the zero-th index can be also manipulated directly be calling the Push
,
Get
and Set
member functions which
have the same semantics as in SettingStack.
OGLplus library client applications should never need to instantiate
SettingStack
directly. The (direct or indirect) members
of ClientContext
should be used.
namespace client { template <typename Derived, typename T, typename Index = GLuint> class SettingStackIndexed { public: SettingStackIndexed(const SettingStackIndexed&) = delete; SettingStackIndexed(void); Derived& operator [] (Index index); Derived& Indexed(Index index); typedef SettingHolder<T, GLuint> Holder; Holder Push(T value); template <typename ... A> Holder Push(A&& ... a); T Get(void) const noexcept; void Set(T value); template <typename ... A> void Set(A&& ... a); }; } // namespace client
Initialized the SettingStack on index zero. |
|
Returns a reference to the setting stack at the specified index. The value of index should not exceed the maximum value for the managed indexed setting. |
|
Pushes a new value on the stack at index zero. |
|
Gets the value from the stack at index zero. |
|
Sets a new value on the stack at index zero. |
#include
<oglplus/client/blending.hpp>
namespace client { using oglplus::context::BlendingOps; } // namespace client
namespace client { class BlendingState { public: SettingStackIndexed< SettingStack<context::BlendEquationSeparate, ...>, context::BlendEquationSeparate, DrawBufferIndex > BlendEquation; SettingStackIndexed< SettingStack<context::BlendFunctionSeparate, ...>, context::BlendFunctionSeparate, DrawBufferIndex > BlendEquation; SettingStack<context::RGBAValue, ...> BlendColor; }; } // namespace client
#include
<oglplus/client/buffer_clearing.hpp>
namespace client { using oglplus::context::BufferClearingOps; } // namespace client
namespace client { class BufferClearingState { public: SettingStack<context::RGBAValue, ...> ClearColor; SettingStack<GLfloat, ...> ClearDepth; SettingStack<GLint, ...> ClearStencil; }; } // namespace client
#include
<oglplus/client/buffer_masking.hpp>
namespace client { class BufferMaskingState { public: SettingStackIndexed< SettingStack<context::RGBAMask, ...>, context::RGBAMask, DrawBufferIndex > ColorMask; SettingStack<Boolean, ...> DepthMask; private: template <SingleFace Value> class StencilMaskStack : SettingStack<Boolean, ...> { }; public: enums::EnumToClass< Nothing, SingleFace, StencilMaskStack > StencilMask; }; } // namespace client
#include
<oglplus/client/capabilities.hpp>
namespace client { class CapabilityState { private: template <Capability Value> class CurrentCapabilityIndexed : SettingStack<Boolean, ...> { public: Boolean IsEnabled(void) const noexcept; explicit operator Boolean (void) const noexcept; void Enable(Boolean status = true); void Disable(void); }; template <Capability Value> class CurrentCapability : SettingStackIndexed<CurrentCapabilityIndexed<Value>, Boolean> { public: Boolean IsEnabled(void) const noexcept; explicit operator Boolean (void) const noexcept; void Enable(Boolean status = true); void Disable(void); }; public: enums::EnumToClass< Nothing, Capability, CurrentCapability > Caps; }; } // namespace client
This class template is here for documentation purposes only and is not part of the public interface. |
|
Checks if the capability is currently enabled ( |
|
Checks if the capability is currently enabled ( |
|
Enables (by default) or sets the capability to the specified |
|
Disables the capability. |
|
This class template is here for documentation purposes only and is not part of the public interface. |
|
Stacks managing the state (enabled or disabled) individually for each capability in the Capability enumeration. |
#include
<oglplus/client/clip_control.hpp>
namespace client { class ClipControlState { public: SettingStack<context::ClipControlParams, ...> ClipControl; }; } // namespace client
#include
<oglplus/client/computing.hpp>
namespace client { using oglplus::context::ComputingOps; } // namespace client
#include
<oglplus/client/depth_test.hpp>
namespace client { class DepthTestState { public: SettingStack<CompareFunction, ...> DepthFunc; }; } // namespace client
#include
<oglplus/client/stencil_test.hpp>
namespace client { class StencilTestState { private: template <SingleFace Value> class StencilFuncStack : SettingStack<context::StencilFuncArgs, ...> { }; public: enums::EnumToClass< Nothing, SingleFace, StencilFuncStack > StencilFunc; private: template <SingleFace Value> class StencilOpStack : SettingStack<context::StencilOperations, ...> { }; public: enums::EnumToClass< Nothing, SingleFace, StencilOpStack > StencilOp; }; } // namespace client
This class template is here for documentation purposes only and is not part of the public interface. |
|
Stack managing the setting of stencil function arguments. |
|
This class template is here for documentation purposes only and is not part of the public interface. |
|
Stack managing the setting of stencil operations. |
#include
<oglplus/client/scissor_test.hpp>
namespace client { class ScissorTestState { SettingStackIndexed< SettingStack<context::ScissorRectangle, ...>, context::ScissorRectangle, ViewportIndex > Scissor; }; } // namespace client
#include
<oglplus/client/viewport.hpp>
namespace client { class ViewportState { SettingStackIndexed< SettingStack<context::ViewportExtents, ...>, context::ViewportExtents, ViewportIndex > Viewport; SettingStackIndexed< SettingStack<context::ViewportDepthRange, ...>, context::ViewportDepthRange, ViewportIndex > DepthRange; }; } // namespace client
#include
<oglplus/client/drawing.hpp>
namespace client { using oglplus::context::DrawingOps; } // namespace client
namespace client { class DrawingState { public: SettingStack<GLint, ...> PrimitiveRestartIndex; }; } // namespace client
#include
<oglplus/client/hint.hpp>
namespace client { class HintState { private: template <HintTarget Value> class Hint : SettingStack<HintOption, ...> { }; public: enums::EnumToClass< Nothing, HintTarget, Hint > Hints; }; } // namespace client
This class template is here for documentation purposes only and is not part of the public interface. |
|
Set of stacks managing the setting of HintOption settings individually for each value in the HintTarget enumeration. |
#include
<oglplus/client/limit_queries.hpp>
namespace client { class LimitQueries { private: template <LimitQuery Limit> class LimitGetter { public: typedef <Unspecified> value_type; static value_type Get(void); static value_type Get(GLuint index); operator value_type(void) const; }; public: enums::EnumToClass< Nothing, LimitQuery, LimitGetter > Limits; }; } // namespace client
This class template is here for documentation purposes only and is not part of the public interface. |
|
The type of the value associated with the |
|
Returns the value of the |
|
Returns the value of the |
|
Returns the value of the |
|
Set of classes with static member functions which allow to get the values of various limits. |
#include
<oglplus/client/numeric_queries.hpp>
namespace client { using oglplus::context::NumericQueries; } // namespace client
#include
<oglplus/client/string_queries.hpp>
namespace client { using oglplus::context::StringQueries; } // namespace client
#include
<oglplus/client/logic_ops.hpp>
namespace client { class LogicOpState { public: SettingStack<ColorLogicOperation, ...> LogicOp; }; } // namespace client
#include
<oglplus/client/pixel_ops.hpp>
namespace client { using oglplus::context::PixelOps; } // namespace client
namespace client { class PixelState { private: template <PixelParameter Parameter> class PixelParams : SettingStack<<Unspecified>, ...> { }; public: enums::EnumToClass< Nothing, PixelParameter, PixelParams > PixelStore; }; } // namespace client
This class template is here for documentation purposes only and is not part of the public interface. |
|
Stack of numeric values (booleans, integers, floats) appropriate
for the pixel |
|
Set of stacks managing the setting of numeric pixel parameters individually for each value in the PixelParameter enumeration. |
#include
<oglplus/client/synchronization.hpp>
namespace client { using oglplus::context::Synchronization; } // namespace client
#include
<oglplus/client/rasterization.hpp>
namespace client { using oglplus::context::RasterizationOps; } // namespace client
namespace client { class RasterizationState { public: SettingStack<FaceOrientation, ...> FrontFace; SettingStack<Face, ...> CullFace; SettingStack<PolygonMode, ...> PolygonMode; SettingStack<context::PolygonOffsPara, ...> PolygonOffset; #if GL_VERSION_3_2 || GL_ARB_provoking_vertex SettingStack<ProvokeMode, ...> ProvokingVertex; #endif SettingStack<GLfloat, ...> LineWidth; SettingStack<GLfloat, ...> PointSize; SettingStack<GLfloat, ...> PointFadeThresholdSize; #if GL_VERSION_4_0 SettingStack<GLfloat, ...> MinSampleShading; #endif #if GL_NV_fragment_coverage_to_color SettingStack<FragDataSlot, ...> FragmentCoverageColor; #endif }; } // namespace client
Stack managing the setting of the front face orientation. |
|
Stack managing the setting of cull face. |
|
Stack managing the setting of polygon rasterization mode. |
|
Stack managing the setting of polygon offset parameters. |
|
Stack managing the setting of provoking vertex mode. |
|
Stack managing the setting of line width value. |
|
Stack managing the setting of point size value. |
|
Stack managing the setting of point fade threshold size value. |
|
Stack managing the setting of the minimal sample shading value. |
|
Stack managing the setting of the draw buffer used for fragment coverage to color. |
#include
<oglplus/client/object_binding.hpp>
namespace client { class CurrentObjects { private: template <typename ObjTag> struct CurrentObject { template <typename ObjBindingOps<ObjTag>::Target ObjTarget> class WithTarget : public SettingStack<GLuint, ...> , public BoundObjOps<ObjTag> { public: WithTarget(void); ObjectName<ObjTag> Get(void) const noexcept; operator ObjectName<ObjTag> (void) const noexcept; typedef SettingHolder<GLuint, ...> Holder; Holder Push(ObjectName<ObjTag> obj); void Bind(ObjectName<ObjTag> obj); }; }; template <typename ObjTag> class CurrentObjectsWithTarget : public enums::EnumToClass< Nothing, typename ObjBindingOps<ObjTag>::Target, CurrentObject<ObjTag>::template WithTarget > { }; public: CurrentObjectsWithTarget<tag::Framebuffer> Framebuffer; CurrentObjectsWithTarget<tag::Renderbuffer> Renderbuffer; CurrentObjectsWithTarget<tag::TransformFeedback> TransformFeedback; CurrentObjectsWithTarget<tag::Buffer> Buffer;
These private classes are here for documentation purposes only. Their public interface can be used in library client code, but the class names (as documented here) are not part of the public interface. |
|
Stack of unwrapped object names. |
|
This class has the same interface as |
|
Returns the current object binding. |
|
Unwraps the object name, binds it to |
|
Unwraps the object name, binds it to |
|
Set of stacks of objects names the top of which is currently bound to a named binding point. |
private: class BufferNameAndRange { public: BufferName Buffer(void) const; bool BoundRange(void) const; BufferSize Offset(void) const; BufferSize Size(void) const; }; template <BufferIndexedTarget BufTarget> class CurrentIndexBuffers : public SettingStack<BufferNameAndRange, ...> { public: CurrentIndexBuffers(GLuint index); BufferNameAndRange Get(void) const; noexcept; operator BufferNameAndRange (void) const noexcept; typedef SettingHolder<BufferNameAndRange, ...> Holder; Holder Push(BufferName obj); Holder Push(BufferName obj, BufferSize offset, BufferSize size); void BindBase(BufferName obj); void BindRange(BufferName obj, BufferSize offset, BufferSize size); }; template <BufferIndexedTarget BufTarget> class CurrentIndexedTargetBuffers { public: CurrentIndexBuffers<BufTarget>& Index(GLuint index); CurrentIndexBuffers<BufTarget>& operator [] (GLuint index); }; public: typedef enums::EnumToClass< Nothing, BufferIndexedTarget, CurrentIndexedTargetBuffers > BufferIndexed;
These private classes are here for documentation purposes only. Their public interface can be used in library client code, but the class names (as documented here) are not part of the public interface. |
|
Indicates whether just a subrange of the buffer ( |
|
These functions return meaningful values only if |
|
Stack of buffer names the top of which is currently bound to the specified BufferIndexedTarget with a particular index. |
|
Returns the current indexed buffer binding. |
|
Unwraps the buffer name, binds it to indexed |
|
Unwraps the buffer name, binds the specified range to indexed |
|
Unwraps the buffer name, binds it to indexed |
|
Unwraps the buffer name, binds the specified range to indexed |
|
Set of stacks managing the buffers bound to the indvidual indices of the specified BufferIndexedTarget. |
|
Returns the stack managing objects bound to the specified |
private: template <typename ObjTag> class CurrentObjectWithoutTarget : public SettingStack<GLuint, ...> { public: CurrentObjectWithoutTarget(void); ObjectName<ObjTag> Get(void) const noexcept; operator ObjectName<ObjTag> (void) const noexcept; typedef SettingHolder<GLuint, ...> Holder; Holder Push(ObjectName<ObjTag> obj); void Bind(ObjectName<ObjTag> obj); }; public: CurrentObjectWithoutTarget<tag::Program> Program; CurrentObjectWithoutTarget<tag::ProgramPipeline> ProgramPipeline; CurrentObjectWithoutTarget<tag::VertexArray> VertexArray;
These private classes are here for documentation purposes only. Their public interface can be used in library client code, but the class names (as documented here) are not part of the public interface. |
|
Stack of objects the top of which is currently bound to an implicit binding point. |
|
Unwraps the object name, binds it to the implicit binding point and pushes it onto the stack. |
|
Unwraps the object name, binds it to the implicit binding point and calls SettingStack::Set. |
private: template <TextureTarget TexTarget> class CurrentUnitTexture : public SettingStack<GLuint, ...> { CurrentUnitTexture(TextureUnitSelector tex_unit); TextureName Get(void) const noexcept; operator TextureName (void) const noexcept; typedef SettingHolder<GLuint, ...> Holder; Holder Push(TextureName tex); void Bind(TextureName tex); }; class CurrentTextures { private: typedef enums::EnumToClass< TextureUnitSelector, TextureTarget, CurrentUnitTexture > CurrentUnitTextures; public: CurrentUnitTextures& Unit(TextureUnitSelector index); CurrentUnitTextures& operator [] (TextureUnitSelector index); }; public: CurrentTextures Texture;
These private classes are here for documentation purposes only. Their public interface can be used in library client code, but the class names (as documented here) are not part of the public interface. |
|
Stack of texture names the top of which is currently bound to the
specified |
|
Unwraps the texture name, binds it to |
|
Unwraps the texture name, binds it to |
|
Set of stacks (each for a particular texture unit) managing the binding of textures to binding points. |
|
Returns a reference to the stack of texture bindings on the texture
unit at the specified |