Ion
|
Opaque class that sets up an offscreen OpenGL context/surface/visual in a platform-specific way to allow OpenGL calls to succeed on the current thread. More...
#include "visual.h"
Public Member Functions | |
virtual | ~Visual () |
OpenGL calls should not be made after the Visual is destroyed. More... | |
bool | IsCurrent () const |
Return true if this is the current Visual on this thread. More... | |
virtual bool | IsValid () const |
Returns true if the OpenGL initialization was successful. More... | |
size_t | GetId () const |
Returns the ID associated with this Visual. More... | |
int | GetGlVersion () const |
Returns the major and minor OpenGL version without a decimal point, e.g. More... | |
Static Public Member Functions | |
static void | RefreshCurrentVisual () |
Refreshes the current visual's internal state. More... | |
static const Visual * | GetCurrent () |
Returns the Visual that is current for the calling thread. More... | |
static std::unique_ptr< Visual > | CreateVisual () |
Creates a new Visual that is not in a share group. More... | |
static std::unique_ptr< Visual > | CreateVisualInCurrentShareGroup () |
Creates a new Visual in the same share group as the current Visual. More... | |
static bool | MakeCurrent (const Visual *new_current) |
Makes the passed Visual the current one for this thread. More... | |
static void | DestroyWrappingVisual (const Visual *visual) |
If the passed Visual wraps a GL context not created by Ion, the Visual is destroyed; the passed pointer should then not be used after calling this function. More... | |
static size_t | GetCurrentId () |
Returns a unique ID for the currently bound Visual. More... | |
Protected Member Functions | |
Visual () | |
Constructor for subclasses that make their own contexts. More... | |
virtual Visual * | CreateVisualInShareGroup () const |
Return a newly-instantiated Visual in the same share group as this Visual. More... | |
virtual bool | MakeCurrent () const |
Makes this Visual current for this thread and returns whether its associated GL context was successfully made current. More... | |
virtual void | TeardownContextNew () |
Destroy Visuals of type kNew. More... | |
virtual void | TeardownContextShared () |
Destroy Visuals of type kShare. More... | |
virtual void | UpdateId () |
Updates this' ID in a platform dependent way. More... | |
void | SetId (size_t id) |
Sets the ID of this. More... | |
Static Protected Member Functions | |
static void | TeardownVisual (Visual *visual) |
Responsible for cleaning up |visual's| resources. More... | |
static void | RegisterVisual (Visual *visual) |
Registers the passed Visual in the global list. More... | |
Friends | |
class | MockVisual |
Opaque class that sets up an offscreen OpenGL context/surface/visual in a platform-specific way to allow OpenGL calls to succeed on the current thread.
To create a Visual that is part of a context share group, bind a valid GL context and construct a Visual(true). The original context can be the main context used for rendering (which Ion does not manage), or another Visual.
|
virtual |
OpenGL calls should not be made after the Visual is destroyed.
Definition at line 953 of file visual.cc.
References TeardownVisual().
|
protected |
Constructor for subclasses that make their own contexts.
Definition at line 948 of file visual.cc.
Referenced by CreateVisual(), CreateVisualInShareGroup(), and GetCurrent().
|
static |
Creates a new Visual that is not in a share group.
Returns NULL if there is no current Visual.
Definition at line 353 of file visual.cc.
References RegisterVisual(), UpdateId(), and Visual().
|
static |
Creates a new Visual in the same share group as the current Visual.
Returns NULL if there is no current Visual.
Definition at line 360 of file visual.cc.
References CreateVisualInShareGroup(), GetCurrent(), IsValid(), LOG, RegisterVisual(), UpdateId(), and ion::port::WARNING.
|
protectedvirtual |
Return a newly-instantiated Visual in the same share group as this Visual.
If this Visual is not current, then return NULL without creating a clone.
Definition at line 381 of file visual.cc.
References DCHECK_EQ, GetCurrent(), and Visual().
Referenced by CreateVisualInCurrentShareGroup().
|
static |
If the passed Visual wraps a GL context not created by Ion, the Visual is destroyed; the passed pointer should then not be used after calling this function.
Passing Visuals created with CreateVisual() or CreateVisualInCurrentShareGroup() has no effect.
|
static |
Returns the Visual that is current for the calling thread.
This has the following semantics:
Definition at line 213 of file visual.cc.
References DCHECK, DCHECK_EQ, GetCurrent(), GetId(), id, MakeCurrent(), and Visual().
Referenced by CreateVisualInCurrentShareGroup(), CreateVisualInShareGroup(), GetCurrent(), GetCurrentId(), ion::portgfx::IsExtensionSupported(), MakeCurrent(), RefreshCurrentVisual(), and TeardownVisual().
|
static |
Returns a unique ID for the currently bound Visual.
The visual's context pointer is used as the id, which may be recycled, i.e. the pointer may get reused when a context is destroyed and another is created.
Definition at line 313 of file visual.cc.
References GetCurrent(), and GetId().
Referenced by ion::gfx::Renderer::DestroyCurrentStateCache().
int ion::portgfx::Visual::GetGlVersion | ( | ) | const |
Returns the major and minor OpenGL version without a decimal point, e.g.
version 2.0 returns 20, version 4.3 returns 43.
Definition at line 964 of file visual.cc.
References LOG, ion::base::StartsWith(), and ion::port::WARNING.
|
inline |
Returns the ID associated with this Visual.
Definition at line 54 of file visual.h.
Referenced by ion::gfx::Renderer::DestroyStateCache(), DestroyWrappingVisual(), GetCurrent(), GetCurrentId(), RegisterVisual(), and TeardownVisual().
|
inline |
|
virtual |
Returns true if the OpenGL initialization was successful.
Callers should not attempt to make calls to OpenGL if Ion is managing the GL context, and this returns false.
Definition at line 949 of file visual.cc.
Referenced by CreateVisualInCurrentShareGroup(), MakeCurrent(), and RegisterVisual().
Makes the passed Visual the current one for this thread.
The Visual's GL context is also made current. Returns whether the Visual was successfully made current.
Definition at line 266 of file visual.cc.
References GetCurrent(), IsValid(), LOG, MakeCurrent(), and ion::port::WARNING.
Referenced by MakeCurrent().
|
protectedvirtual |
Makes this Visual current for this thread and returns whether its associated GL context was successfully made current.
Future GL calls on this thread should succeed after a return value of true.
Definition at line 950 of file visual.cc.
Referenced by GetCurrent().
|
static |
Refreshes the current visual's internal state.
Implemented solely for EGL to reacquire the current surface on platforms like Android that replace the active surface during resize/resume operations.
Definition at line 992 of file visual.cc.
References GetCurrent().
|
staticprotected |
Registers the passed Visual in the global list.
Subclasses must call this to ensure that they are returned from GetCurrent().
Definition at line 373 of file visual.cc.
References GetId(), and IsValid().
Referenced by CreateVisual(), and CreateVisualInCurrentShareGroup().
|
inlineprotected |
Sets the ID of this.
Definition at line 127 of file visual.h.
References id.
Referenced by UpdateId().
|
protectedvirtual |
Destroy Visuals of type kNew.
Definition at line 951 of file visual.cc.
Referenced by TeardownVisual().
|
protectedvirtual |
Destroy Visuals of type kShare.
Should not attempt to destroy parts of the current OpenGL context, surface, display, etc.
Definition at line 952 of file visual.cc.
Referenced by TeardownVisual().
|
staticprotected |
Responsible for cleaning up |visual's| resources.
Calls SetCurrent(NULL) if visual->IsCurrent(), and dispatches into DestroyContextNew() or DestroyContextShared() for kNew and kShared visuals, respectively.
Definition at line 325 of file visual.cc.
References DCHECK, GetCurrent(), GetId(), TeardownContextNew(), and TeardownContextShared().
Referenced by ~Visual().
|
protectedvirtual |
Updates this' ID in a platform dependent way.
Definition at line 959 of file visual.cc.
References SetId().
Referenced by CreateVisual(), and CreateVisualInCurrentShareGroup().