Public Member Functions
-
~Context ()
-
const std::shared_ptr< PlatformData >getPlatformData () const
Returns the platform-specific OpenGL Context . CGLContextObj on Mac OS X, EAGLContext on iOS.
-
void
-
std::vector< mat4 > &getModelMatrixStack ()
Returns a reference to the stack of Model matrices.
-
const std::vector< mat4 > &getModelMatrixStack () const
Returns a const reference to the stack of Model matrices.
-
std::vector< mat4 > &getViewMatrixStack ()
Returns a reference to the stack of View matrices.
-
const std::vector< mat4 > &getViewMatrixStack () const
Returns a const reference to the stack of Model matrices.
-
std::vector< mat4 > &getProjectionMatrixStack ()
Returns a reference to the stack of Projection matrices.
-
const std::vector< mat4 > &getProjectionMatrixStack () const
Returns a const reference to the stack of Projection matrices.
-
voidbindVao (Vao *vao)
Binds a VAO. Consider using a ScopedVao instead.
-
voidbindVao (VaoRef &vao)
Binds a VAO. Consider using a ScopedVao instead.
-
voidpushVao (Vao *vao)
Pushes and binds the VAO vao .
-
voidpushVao (const VaoRef &vao)
Pushes and binds the VAO vao .
-
voidpushVao ()
Duplicates and pushes the current VAO binding.
-
voidpopVao ()
Pops the current VAO binding.
-
Vao *getVao ()
Returns the currently bound VAO.
-
voidrestoreInvalidatedVao ()
Restores the VAO binding when code that is not caching aware has invalidated it. Not typically necessary.
-
voidvaoCreated (const Vao *vao)
Used by object tracking.
-
voidvaoDeleted (const Vao *vao)
Used by object tracking.
-
voidviewport (const std::pair< ivec2, ivec2 > &viewport)
Analogous to glViewport(). Sets the viewport based on a pair<ivec2,ivec2> representing the position of the lower-left corner and the size, respectively.
-
voidpushViewport (const std::pair< ivec2, ivec2 > &viewport)
Pushes the viewport based on a pair<ivec2,ivec2> representing the position of the lower-left corner and the size, respectively.
-
voidpushViewport ()
Duplicates and pushes the top of the Viewport stack.
-
voidpopViewport (bool forceRestore=false)
Pops the viewport. If forceRestore then redundancy checks are skipped and the hardware state is always set.
-
std::pair< ivec2, ivec2 >getViewport ()
Returns a pair<ivec2,ivec2> representing the position of the lower-left corner and the size, respectively of the viewport.
-
voidsetScissor (const std::pair< ivec2, ivec2 > &scissor)
Sets the scissor box based on a pair<ivec2,ivec2> representing the position of the lower-left corner and the size, respectively.
-
voidpushScissor (const std::pair< ivec2, ivec2 > &scissor)
Pushes the scissor box based on a pair<ivec2,ivec2> representing the position of the lower-left corner and the size, respectively.
-
voidpushScissor ()
Duplicates and pushes the top of the Scissor box stack.
-
voidpopScissor (bool forceRestore=false)
Pushes the scissor box based on a pair<ivec2,ivec2> representing the position of the lower-left corner and the size, respectively. If forceRestore then redundancy checks are skipped and the hardware state is always set.
-
std::pair< ivec2, ivec2 >getScissor ()
Returns a pair<ivec2,ivec2> representing the position of the lower-left corner and the size, respectively of the scissor box.
-
voidcullFace (GLenum face)
Analogous to glCullFace( face ). Valid arguments are
GL_FRONT
andGL_BACK
. -
voidpushCullFace (GLenum face)
Pushes the cull face face . Valid arguments are
GL_FRONT
andGL_BACK
. -
voidpushCullFace ()
Duplicates and pushes the top of the Cull Face stack.
-
voidpopCullFace (bool forceRestore=false)
Pops the top of the Cull Face stack. If forceRestore then redundancy checks are skipped and the hardware state is always set.
-
GLenumgetCullFace ()
Returns a GLenum representing the current cull face. Either
GL_FRONT
orGL_BACK
. -
voidfrontFace (GLenum mode)
Set the winding order defining front-facing polygons. Valid arguments are
GL_CW
andGL_CCW
. Default isGL_CCW
. -
voidpushFrontFace (GLenum mode)
Push the winding order defining front-facing polygons. Valid arguments are
GL_CW
andGL_CCW
. Default isGL_CCW
. -
voidpushFrontFace ()
Push the winding order defining front-facing polygons.
-
voidpopFrontFace (bool forceRestore=false)
Pops the winding order defining front-facing polygons. If forceRestore then redundancy checks are skipped and the hardware state is always set.
-
GLenumgetFrontFace ()
Returns the winding order defining front-facing polygons, either
GL_CW
orGL_CCW
(the default). -
voidlogicOp (GLenum mode)
Analogous to glLogicOp( mode ). Valid arguments are
GL_CLEAR
,GL_SET
,GL_COPY
,GL_COPY_INVERTED
,GL_NOOP
,GL_INVERT
,GL_AND
,GL_NAND
,GL_OR
,GL_NOR
,GL_XOR
,GL_EQUIV
,GL_AND_REVERSE
,GL_AND_INVERTED
,GL_OR_REVERSE
, orGL_OR_INVERTED
. -
voidpushLogicOp (GLenum mode)
Pushes the logical operation mode . Valid arguments are
GL_CLEAR
,GL_SET
,GL_COPY
,GL_COPY_INVERTED
,GL_NOOP
,GL_INVERT
,GL_AND
,GL_NAND
,GL_OR
,GL_NOR
,GL_XOR
,GL_EQUIV
,GL_AND_REVERSE
,GL_AND_INVERTED
,GL_OR_REVERSE
, orGL_OR_INVERTED
. -
voidpopLogicOp (bool forceRestore=false)
Pops the top of the Logic Op stack. If forceRestore then redundancy checks are skipped and the hardware state is always set.
-
GLenumgetLogicOp ()
Returns a GLenum representing the current logical operation.
-
voidbindBuffer (GLenum target, GLuint id)
Analogous to glBindBuffer( target , id )
-
voidpushBufferBinding (GLenum target, GLuint id)
Pushes and binds buffer object id for the target target .
-
voidpushBufferBinding (GLenum target)
Duplicates and pushes the buffer binding for the target target .
-
voidpopBufferBinding (GLenum target)
Pops the buffer binding for the target target .
-
GLuintgetBufferBinding (GLenum target)
Returns the current object binding for target . If not cached, queries the GL for the current value (and caches it).
-
voidreflectBufferBinding (GLenum target, GLuint id)
Updates the binding stack without rebinding. Not generally necessary to call directly.
-
voidbufferCreated (const BufferObj *buffer)
Used by object tracking.
-
voidbufferDeleted (const BufferObj *buffer)
No-op if BufferObj wasn't bound, otherwise reflects the binding as 0 (in accordance with what GL has done automatically). Also used by object tracking.
-
voidinvalidateBufferBindingCache (GLenum target)
Marks the cache of target's buffer binding as invalid. Typically called when a VAO is unbound, against GL_ELEMENT_ARRAY_BUFFER.
-
voidrestoreInvalidatedBufferBinding (GLenum target)
Restores a buffer binding when code that is not caching aware has invalidated it. Not typically necessary.
-
voidbindRenderbuffer (GLenum target, GLuint id)
Analogous to glBindRenderbuffer( target , id )
-
voidpushRenderbufferBinding (GLenum target, GLuint id)
Pushes and binds renderbuffer object id for the target target .
-
voidpushRenderbufferBinding (GLenum target)
Duplicates and pushes the renderbuffer binding for the target target .
-
voidpopRenderbufferBinding (GLenum target)
Pops the renderbuffer binding for the target target .
-
GLuintgetRenderbufferBinding (GLenum target)
Returns the current renderbuffer binding for target . If not cached, queries the GL for the current value (and caches it).
-
voidrenderbufferDeleted (const Renderbuffer *buffer)
No-op if Renderbuffer wasn't bound, otherwise reflects the binding as 0 (in accordance with what GL has done automatically).
-
voidbindGlslProg (const GlslProg *prog)
Binds GLSL program prog . Analogous to glUseProgram()
-
voidbindGlslProg (GlslProgRef &prog)
-
voidpushGlslProg (const GlslProg *prog)
Pushes and binds GLSL program prog .
-
voidpushGlslProg (GlslProgRef &prog)
-
voidpushGlslProg ()
Duplicates and pushes the top of the GlslProg stack.
-
voidpopGlslProg (bool forceRestore=false)
Pops the GlslProg stack. If forceRestore then redundancy checks are skipped and the hardware state is always set.
-
const GlslProg *getGlslProg ()
Returns the currently bound GlslProg .
-
voidglslProgCreated (const GlslProg *glslProg)
Used by object tracking.
-
voidglslProgDeleted (const GlslProg *glslProg)
Used by object tracking.
-
voidbindBufferBase (GLenum target, GLuint index, const BufferObjRef &buffer)
Binds ref to the specific index within target . Analogous to glBindBufferBase()
-
voidbindBufferBase (GLenum target, GLuint index, GLuint id)
Binds ref to the specific index within target . Analogous to glBindBufferBase()
-
voidbindBufferRange (GLenum target, GLuint index, const BufferObjRef &buffer, GLintptr offset, GLsizeiptr size)
Analogous to glBindBufferRange()
-
voidbindTexture (GLenum target, GLuint textureId)
Analogous to glBindTexture( target , textureId ) for the active texture unit.
-
voidbindTexture (GLenum target, GLuint textureId, uint8_t textureUnit)
Analogous to glBindTexture( target , textureId ) for texture unit textureUnit .
-
voidpushTextureBinding (GLenum target, uint8_t textureUnit)
Duplicates and pushes the binding for the target target for texture unit textureUnit .
-
voidpushTextureBinding (GLenum target, GLuint textureId, uint8_t textureUnit)
Pushes and binds textureId for the target target for texture unit textureUnit .
-
voidpopTextureBinding (GLenum target, uint8_t textureUnit, bool forceRestore=false)
Pops the texture binding for the target target for texture unit textureUnit . If forceRestore then redundancy checks are skipped and the hardware state is always set.
-
GLuintgetTextureBinding (GLenum target)
Returns the current texture binding for target for the active texture unit. If not cached, queries the GL for the current value (and caches it).
-
GLuintgetTextureBinding (GLenum target, uint8_t textureUnit)
Returns the current texture binding for target for texture unit textureUnit . If not cached, queries the GL for the current value (and caches it).
-
voidtextureCreated (const TextureBase *texture)
Used by object tracking.
-
voidtextureDeleted (const TextureBase *texture)
No-op if texture wasn't bound, otherwise reflects the texture unit's binding as 0 (in accordance with what GL has done automatically). Also used by object tracking.
-
voidsetActiveTexture (uint8_t textureUnit)
Sets the active texture unit; expects values relative to
0
, not GL_TEXTURE0. -
voidpushActiveTexture (uint8_t textureUnit)
Pushes and sets the active texture unit; expects values relative to
0
, not GL_TEXTURE0. -
voidpushActiveTexture ()
Duplicates and pushes the active texture unit.
-
voidpopActiveTexture (bool forceRestore=false)
Sets the active texture unit; expects values relative to
0
, not GL_TEXTURE0. If forceRestore then redundancy checks are skipped and the hardware state is always set.Sets the active texture unit; expects values relative to
0
, not GL_TEXTURE0. -
uint8_tgetActiveTexture ()
Returns the active texture unit with values relative to
0
, not GL_TEXTURE0. -
voidbindFramebuffer (const FboRef &fbo, GLenum target=GL_FRAMEBUFFER)
Analogous to glBindFramebuffer()
-
voidbindFramebuffer (GLenum target, GLuint framebuffer)
Analogous to glBindFramebuffer(). Prefer the FboRef variant when possible. This does not allow gl::Fbo to mark itself as needing multisample resolution.
-
voidpushFramebuffer (const FboRef &fbo, GLenum target=GL_FRAMEBUFFER)
Pushes and sets the active framebuffer.
-
voidpushFramebuffer (GLenum target, GLuint framebuffer=GL_FRAMEBUFFER)
Pushes and sets the active framebuffer. Prefer the FboRef variant when possible. This does not allow gl::Fbo to mark itself as needing multisample resolution.
-
voidpushFramebuffer (GLenum target=GL_FRAMEBUFFER)
Duplicates and pushes the active framebuffer.
-
voidpopFramebuffer (GLuint framebuffer=GL_FRAMEBUFFER)
Pops the active framebuffer.
-
voidunbindFramebuffer ()
Unbinds the current FBO (binding the default (screen) framebuffer)
-
GLuintgetFramebuffer (GLenum target=GL_FRAMEBUFFER)
Returns the ID of the framebuffer currently bound to target .
-
voidframebufferCreated (const Fbo *fbo)
Used by object tracking.
-
voidframebufferDeleted (const Fbo *fbo)
Used by object tracking.
-
voidsetBoolState (GLenum cap, GLboolean value)
Analogous to glEnable() or glDisable(). Enables or disables OpenGL capability cap .
-
voidpushBoolState (GLenum cap, GLboolean value)
Pushes and sets the state stack for OpenGL capability cap to value .
-
voidpushBoolState (GLenum cap)
Duplicates and pushes the state stack for OpenGL capability cap .
-
voidpopBoolState (GLenum cap, bool forceRestore=false)
Pops the state stack for OpenGL capability cap . If forceRestore then redundancy checks are skipped and the hardware state is always set.
-
voidenable (GLenum cap, GLboolean value=true)
Synonym for setBoolState() . Enables or disables OpenGL capability cap .
-
GLbooleangetBoolState (GLenum cap)
Analogous to glIsEnabled(). Returns whether a given OpenGL capability is enabled or not.
-
voidsetBoolState (GLenum cap, GLboolean value, const std::function< void(GLboolean)> &setter)
Enables or disables OpenGL capability cap . Calls setter rather than glEnable or glDisable. Not generally necessary to call directly.
-
voidblendFunc (GLenum sfactor, GLenum dfactor)
Analogous glBlendFunc(). Consider using a ScopedBlend instead.
-
voidblendFuncSeparate (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
Analogous to glBlendFuncSeparate(). Consider using a ScopedBlend instead.
-
voidpushBlendFuncSeparate (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
Analogous to glBlendFuncSeparate, but pushes values rather than replaces them.
-
voidpushBlendFuncSeparate ()
Duplicates and pushes the glBlendFunc state stack.
-
voidpopBlendFuncSeparate (bool forceRestore=false)
Pops the current blend functions. If forceRestore then redundancy checks are skipped and the hardware state is always set.
-
voidgetBlendFuncSeparate (GLenum *resultSrcRGB, GLenum *resultDstRGB, GLenum *resultSrcAlpha, GLenum *resultDstAlpha)
Returns the current values for glBendFuncs.
-
voidlineWidth (float lineWidth)
Sets the current line width.
-
voidpushLineWidth (float lineWidth)
Pushes and sets the current line width.
-
voidpushLineWidth ()
Duplicates and pushes the current line width.
-
voidpopLineWidth (bool forceRestore=false)
Sets the current line width. If forceRestore then redundancy checks are skipped and the hardware state is always set.
-
floatgetLineWidth ()
Returns the current line width.
-
voiddepthMask (GLboolean enable)
Analogous to glDepthMask(). Enables or disables writing into the depth buffer.
-
voidpushDepthMask (GLboolean enable)
Push the depth buffer writing flag.
-
voidpushDepthMask ()
Push the depth buffer writing flag.
-
voidpopDepthMask (bool forceRestore=false)
Pops the depth buffer writing flag. If forceRestore then redundancy checks are skipped and the hardware state is always set.
-
GLbooleangetDepthMask ()
Returns the depth buffer writing flag.
-
voiddepthFunc (GLenum func)
Set the depth buffer comparison function. Analogous to glDepthFunc(). Valid arguments are
GL_NEVER
,GL_LESS
,GL_EQUAL
,GL_LEQUAL
,GL_GREATER
,GL_NOTEQUAL
,GL_GEQUAL
andGL_ALWAYS
. Default isGL_LESS
. -
voidpushDepthFunc (GLenum func)
Push the depth buffer comparison function. Valid arguments are
GL_NEVER
,GL_LESS
,GL_EQUAL
,GL_LEQUAL
,GL_GREATER
,GL_NOTEQUAL
,GL_GEQUAL
andGL_ALWAYS
. Default isGL_LESS
. -
voidpushDepthFunc ()
Push the depth buffer comparison function.
-
voidpopDepthFunc (bool forceRestore=false)
Pops the depth buffer comparison function. If forceRestore then redundancy checks are skipped and the hardware state is always set.
-
GLenumgetDepthFunc ()
Returns the depth buffer comparison function, either
GL_NEVER
,GL_LESS
,GL_EQUAL
,GL_LEQUAL
,GL_GREATER
,GL_NOTEQUAL
,GL_GEQUAL
orGL_ALWAYS
. -
voidpolygonMode (GLenum face, GLenum mode)
Sets the current polygon rasterization mode. face must be
GL_FRONT_AND_BACK
.GL_POINT
,GL_LINE
&GL_FILL
are legal values for mode . -
voidpushPolygonMode (GLenum face, GLenum mode)
Pushes the current polygon rasterization mode. face must be
GL_FRONT_AND_BACK
.GL_POINT
,GL_LINE
&GL_FILL
are legal values for mode . -
voidpushPolygonMode (GLenum face)
Pushes the current polygon rasterization mode. face must be
GL_FRONT_AND_BACK
. -
voidpopPolygonMode (GLenum face, bool forceRestore=false)
Pops the current polygon rasterization mode. face must be
GL_FRONT_AND_BACK
. If forceRestore then redundancy checks are skipped and the hardware state is always set. -
GLenumgetPolygonMode (GLenum face)
Returns the current polygon rasterization mode. face must be
GL_FRONT_AND_BACK
. -
voidsanityCheck ()
-
voidprintState (std::ostream &os) const
-
const std::set< const TextureBase * > &getLiveTextures () const
Returns the container of live Textures. Requires object tracking to be enabled.
-
const std::set< const BufferObj * > &getLiveBuffers () const
Returns the container of live BufferObjs. Requires object tracking to be enabled.
-
const std::set< const GlslProg * > &getLiveGlslProgs () const
Returns the container of live GlslProgs. Requires object tracking to be enabled.
-
const std::set< const Vao * > &getLiveVaos () const
Returns the container of live Vaos. Requires object tracking to be enabled.
-
const std::set< const Fbo * > &getLiveFbos () const
Returns the container of live Fbos. Requires object tracking to be enabled.
-
voidenableVertexAttribArray (GLuint index)
Analogous to glEnableVertexAttribArray()
-
voiddisableVertexAttribArray (GLuint index)
Analogous to glDisableVertexAttribArray()
-
voidvertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer)
Analogous to glVertexAttribPointer()
-
voidvertexAttribIPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
Analogous to glVertexAttribIPointer()
-
voidvertexAttribDivisor (GLuint index, GLuint divisor)
Analogous to glVertexAttribDivisor()
-
voidvertexAttrib1f (GLuint index, float v0)
Analogous to glVertexAttrib1f()
-
voidvertexAttrib2f (GLuint index, float v0, float v1)
Analogous to glVertexAttrib2f()
-
voidvertexAttrib3f (GLuint index, float v0, float v1, float v2)
Analogous to glVertexAttrib3f()
-
voidvertexAttrib4f (GLuint index, float v0, float v1, float v2, float v3)
Analogous to glVertexAttrib4f()
-
voiddrawArrays (GLenum mode, GLint first, GLsizei count)
Analogous to glDrawArrays()
-
voiddrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
Analogous to glDrawElements()
-
const ColorAf &getCurrentColor () const
Returns the current active color, used in immediate-mode emulation and as UNIFORM_COLOR.
-
voidsetCurrentColor (const ColorAf &color)
-
getStockShader (const ShaderDef &shaderDef)
-
voidsetDefaultShaderVars ()
-
getDefaultArrayVbo (size_t requiredSize=0)
Returns default VBO for vertex array data, ensuring it is at least requiredSize bytes. Designed for use with convenience functions.
-
getDefaultElementVbo (size_t requiredSize=0)
Returns default VBO for element array data, ensuring it is at least requiredSize bytes. Designed for use with convenience functions.
-
Vao *getDefaultVao ()
Returns default VAO, designed for use with convenience functions.
-
getDrawTextureVbo ()
Returns a VBO for drawing textured rectangles; used by gl::draw(TextureRef)
-
Vao *getDrawTextureVao ()
Returns a VBO for drawing textured rectangles; used by gl::draw(TextureRef)
-
immediate ()
Returns a reference to the immediate mode emulation structure. Generally use gl::begin() and friends instead.
Static Public Member Functions
-
create (const Context *sharedContext)
Creates a new OpenGL context, sharing resources and pixel format with sharedContext. This (essentially) must be done from the primary thread on MSW. ANGLE doesn't support multithreaded use. Destroys the platform Context on destruction.
-
createFromExisting (const std::shared_ptr< PlatformData > &platformData)
Creates based on an existing platform-specific GL context. platformContext is CGLContextObj on Mac OS X, EAGLContext on iOS, HGLRC on MSW. platformContext is an HDC on MSW and ignored elsewhere. Does not assume ownership of the platform's context.
-
Context *getCurrent ()
Returns the thread's currently active OpenGL Context .
-
voidreflectCurrent (Context *context)
Set thread's local storage to reflect context as the active Context .
Protected Member Functions
-
boolpushStackState (std::vector< T > &stack, T value)
Returns
true
if value is different from the previous top of the stack. -
boolpopStackState (std::vector< T > &stack)
Returns
true
if the new top of stack is different from the previous top, or the stack is empty. -
boolsetStackState (std::vector< T > &stack, T value)
Returns
true
if value is different from the previous top of the stack. -
boolgetStackState (std::vector< T > &stack, T *result)
Returns
true
if result is valid; will returnfalse
when stack was empty. -
voidallocateDefaultVboAndVao ()
Protected Attributes
-
std::map< ShaderDef, GlslProgRef >mStockShaders
-
std::map< GLenum, std::vector< int > >mBufferBindingStack
-
std::map< GLenum, std::vector< int > >mRenderbufferBindingStack
-
std::vector< const GlslProg * >mGlslProgStack
-
std::vector< Vao * >mVaoStack
-
std::vector< GLint >mBlendSrcRgbStack
-
std::vector< GLint >mBlendDstRgbStack
-
std::vector< GLint >mBlendSrcAlphaStack
-
std::vector< GLint >mBlendDstAlphaStack
-
std::vector< GLint >mFramebufferStack
-
std::vector< GLenum >mCullFaceStack
-
std::vector< GLenum >mFrontFaceStack
-
std::vector< GLenum >mLogicOpStack
-
std::vector< GLenum >mPolygonModeStack
-
std::vector< GLboolean >mDepthMaskStack
-
std::vector< GLenum >mDepthFuncStack
-
std::map< GLenum, std::vector< GLboolean > >mBoolStateStack
-
std::map< uint8_t, std::map< GLenum, std::vector< GLint > > >mTextureBindingStack
-
std::vector< uint8_t >mActiveTextureStack
-
mDefaultVao
-
mDefaultArrayVbo [4]
-
mDefaultElementVbo
-
uint8_tmDefaultArrayVboIdx
-
mImmediateMode
-
mDrawTextureVao
-
mDrawTextureVbo