Merge OpenGL API changes and better modern OpenGL support

Closes https://github.com/wxWidgets/wxWidgets/pull/227
This commit is contained in:
Vadim Zeitlin
2016-02-24 20:15:35 +01:00
44 changed files with 9382 additions and 1157 deletions

View File

@@ -49,13 +49,120 @@ enum
WX_GL_MIN_ACCUM_ALPHA, // use alpha buffer with most bits (> MIN_ACCUM_ALPHA bits)
WX_GL_SAMPLE_BUFFERS, // 1 for multisampling support (antialiasing)
WX_GL_SAMPLES, // 4 for 2x2 antialiasing supersampling on most graphics cards
WX_GL_FRAMEBUFFER_SRGB,// capability for sRGB framebuffer
// Context attributes
WX_GL_CORE_PROFILE, // use an OpenGL core profile
WX_GL_MAJOR_VERSION, // major OpenGL version of the core profile
WX_GL_MINOR_VERSION // minor OpenGL version of the core profile
WX_GL_MINOR_VERSION, // minor OpenGL version of the core profile
wx_GL_COMPAT_PROFILE, // use compatible profile (use all versions features)
WX_GL_FORWARD_COMPAT, // forward compatible context. OpenGL >= 3.0
WX_GL_ES2, // ES or ES2 context.
WX_GL_DEBUG, // create a debug context
WX_GL_ROBUST_ACCESS, // robustness.
WX_GL_NO_RESET_NOTIFY, // never deliver notification of reset events
WX_GL_LOSE_ON_RESET, // if graphics reset, all context state is lost
WX_GL_RESET_ISOLATION, // protect other apps or share contexts from reset side-effects
WX_GL_RELEASE_FLUSH, // on context release, flush pending commands
WX_GL_RELEASE_NONE // on context release, pending commands are not flushed
};
#define wxGLCanvasName wxT("GLCanvas")
// ----------------------------------------------------------------------------
// wxGLAttribsBase: OpenGL rendering attributes
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_GL wxGLAttribsBase
{
public:
wxGLAttribsBase() { Reset(); }
// Setters
void AddAttribute(int attribute) { m_GLValues.push_back(attribute); }
// Search for searchVal and combine the next value with combineVal
void AddAttribBits(int searchVal, int combineVal);
// ARB functions necessity
void SetNeedsARB(bool needsARB = true) { m_needsARB = needsARB; }
// Delete contents
void Reset()
{
m_GLValues.clear();
m_needsARB = false;
}
// Accessors
const int* GetGLAttrs() const
{
return (m_GLValues.empty() || !m_GLValues[0]) ? NULL : &*m_GLValues.begin();
}
int GetSize() const { return (int)(m_GLValues.size()); }
// ARB function (e.g. wglCreateContextAttribsARB) is needed
bool NeedsARB() const { return m_needsARB; }
private:
wxVector<int> m_GLValues;
bool m_needsARB;
};
// ----------------------------------------------------------------------------
// wxGLContextAttrs: OpenGL rendering context attributes
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_GL wxGLContextAttrs : public wxGLAttribsBase
{
public:
// Setters, allowing chained calls
wxGLContextAttrs& CoreProfile();
wxGLContextAttrs& MajorVersion(int val);
wxGLContextAttrs& MinorVersion(int val);
wxGLContextAttrs& OGLVersion(int vmayor, int vminor)
{ return MajorVersion(vmayor).MinorVersion(vminor); }
wxGLContextAttrs& CompatibilityProfile();
wxGLContextAttrs& ForwardCompatible();
wxGLContextAttrs& ES2();
wxGLContextAttrs& DebugCtx();
wxGLContextAttrs& Robust();
wxGLContextAttrs& NoResetNotify();
wxGLContextAttrs& LoseOnReset();
wxGLContextAttrs& ResetIsolation();
wxGLContextAttrs& ReleaseFlush(int val = 1); //'int' allows future values
wxGLContextAttrs& PlatformDefaults();
void EndList(); // No more values can be chained
// Currently only used for X11 context creation
bool x11Direct; // X11 direct render
bool renderTypeRGBA;
};
// ----------------------------------------------------------------------------
// wxGLAttributes: canvas configuration
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_GL wxGLAttributes : public wxGLAttribsBase
{
public:
// Setters, allowing chained calls
wxGLAttributes& RGBA();
wxGLAttributes& BufferSize(int val);
wxGLAttributes& Level(int val);
wxGLAttributes& DoubleBuffer();
wxGLAttributes& Stereo();
wxGLAttributes& AuxBuffers(int val);
wxGLAttributes& MinRGBA(int mRed, int mGreen, int mBlue, int mAlpha);
wxGLAttributes& Depth(int val);
wxGLAttributes& Stencil(int val);
wxGLAttributes& MinAcumRGBA(int mRed, int mGreen, int mBlue, int mAlpha);
wxGLAttributes& PlatformDefaults();
wxGLAttributes& Defaults();
wxGLAttributes& SampleBuffers(int val);
wxGLAttributes& Samplers(int val);
wxGLAttributes& FrameBuffersRGB();
void EndList(); // No more values can be chained
};
// ----------------------------------------------------------------------------
// wxGLContextBase: OpenGL rendering context
// ----------------------------------------------------------------------------
@@ -63,14 +170,20 @@ enum
class WXDLLIMPEXP_GL wxGLContextBase : public wxObject
{
public:
/*
The derived class should provide a ctor with this signature:
wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
*/
// The derived class should provide a ctor with this signature:
//
// wxGLContext(wxGLCanvas *win,
// const wxGLContext *other = NULL,
// const wxGLContextAttrs *ctxAttrs = NULL);
// set this context as the current one
virtual bool SetCurrent(const wxGLCanvas& win) const = 0;
bool IsOK() { return m_isOk; }
protected:
bool m_isOk;
};
// ----------------------------------------------------------------------------
@@ -90,8 +203,8 @@ public:
The derived class should provide a ctor with this signature:
wxGLCanvas(wxWindow *parent,
const wxGLAttributes& dispAttrs,
wxWindowID id = wxID_ANY,
int* attribList = 0,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
@@ -113,6 +226,7 @@ public:
// ---------
// check if the given attributes are supported without creating a canvas
static bool IsDisplaySupported(const wxGLAttributes& dispAttrs);
static bool IsDisplaySupported(const int *attribList);
#if wxUSE_PALETTE
@@ -134,6 +248,11 @@ public:
// compilation
static bool IsExtensionSupported(const char *extension);
// Get the wxGLContextAttrs object filled with the context-related values
// of the list of attributes passed at ctor when no wxGLAttributes is used
// as a parameter
wxGLContextAttrs& GetGLCTXAttrs() { return m_GLCTXAttrs; }
// deprecated methods using the implicit wxGLContext
#if WXWIN_COMPATIBILITY_2_8
wxDEPRECATED( wxGLContext* GetContext() const );
@@ -158,6 +277,15 @@ protected:
// by glXQueryExtensionsString() or glGetString(GL_EXTENSIONS)
static bool IsExtensionInList(const char *list, const char *extension);
// For the case of "int* attribList" at ctor is != 0
wxGLContextAttrs m_GLCTXAttrs;
// Extract pixel format and context attributes.
// Return false if an unknown attribute is found.
static bool ParseAttribList(const int* attribList,
wxGLAttributes& dispAttrs,
wxGLContextAttrs* ctxAttrs = NULL);
#if wxUSE_PALETTE
// create default palette if we're not using RGBA mode
// (not supported in most ports)

View File

@@ -20,6 +20,16 @@
class WXDLLIMPEXP_GL wxGLCanvas : public wxGLCanvasX11
{
public:
wxGLCanvas(wxWindow *parent,
const wxGLAttributes& dispAttrs,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxGLCanvasName,
const wxPalette& palette = wxNullPalette);
wxEXPLICIT // avoid implicitly converting a wxWindow* to wxGLCanvas
wxGLCanvas(wxWindow *parent,
wxWindowID id = wxID_ANY,
const int *attribList = NULL,
@@ -29,6 +39,15 @@ public:
const wxString& name = wxGLCanvasName,
const wxPalette& palette = wxNullPalette);
bool Create(wxWindow *parent,
const wxGLAttributes& dispAttrs,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxGLCanvasName,
const wxPalette& palette = wxNullPalette);
bool Create(wxWindow *parent,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,

View File

@@ -20,6 +20,16 @@
class WXDLLIMPEXP_GL wxGLCanvas : public wxGLCanvasX11
{
public:
wxGLCanvas(wxWindow *parent,
const wxGLAttributes& dispAttrs,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxGLCanvasName,
const wxPalette& palette = wxNullPalette);
wxEXPLICIT // avoid implicitly converting a wxWindow* to wxGLCanvas
wxGLCanvas(wxWindow *parent,
wxWindowID id = wxID_ANY,
const int *attribList = NULL,
@@ -29,6 +39,15 @@ public:
const wxString& name = wxGLCanvasName,
const wxPalette& palette = wxNullPalette);
bool Create(wxWindow *parent,
const wxGLAttributes& dispAttrs,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxGLCanvasName,
const wxPalette& palette = wxNullPalette);
bool Create(wxWindow *parent,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,

View File

@@ -24,7 +24,9 @@
class WXDLLIMPEXP_GL wxGLContext : public wxGLContextBase
{
public:
wxGLContext(wxGLCanvas *win, const wxGLContext* other = NULL);
wxGLContext(wxGLCanvas *win,
const wxGLContext *other = NULL,
const wxGLContextAttrs *ctxAttrs = NULL);
virtual ~wxGLContext();
virtual bool SetCurrent(const wxGLCanvas& win) const;
@@ -46,6 +48,16 @@ class WXDLLIMPEXP_GL wxGLCanvas : public wxGLCanvasBase
{
public:
wxEXPLICIT // avoid implicitly converting a wxWindow* to wxGLCanvas
wxGLCanvas(wxWindow *parent,
const wxGLAttributes& dispAttrs,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxGLCanvasName,
const wxPalette& palette = wxNullPalette);
wxEXPLICIT
wxGLCanvas(wxWindow *parent,
wxWindowID id = wxID_ANY,
const int *attribList = NULL,
@@ -55,6 +67,15 @@ public:
const wxString& name = wxGLCanvasName,
const wxPalette& palette = wxNullPalette);
bool Create(wxWindow *parent,
const wxGLAttributes& dispAttrs,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxGLCanvasName,
const wxPalette& palette = wxNullPalette);
bool Create(wxWindow *parent,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
@@ -76,9 +97,12 @@ public:
// get the HDC used for OpenGL rendering
HDC GetHDC() const { return m_hDC; }
// try to find pixel format matching the given attributes list for the
// specified HDC, return 0 on error, otherwise pfd is filled in with the
// information from attribList if non-NULL
// Try to find pixel format matching the given attributes list for the
// specified HDC, return 0 on error, otherwise ppfd is filled in with the
// information from dispAttrs
static int FindMatchingPixelFormat(const wxGLAttributes& dispAttrs,
PIXELFORMATDESCRIPTOR* ppfd = NULL);
// Same as FindMatchingPixelFormat
static int ChooseMatchingPixelFormat(HDC hdc, const int *attribList,
PIXELFORMATDESCRIPTOR *pfd = NULL);

View File

@@ -29,13 +29,18 @@ WXDLLIMPEXP_GL void WXGLDestroyContext( WXGLContext context );
WXDLLIMPEXP_GL WXGLContext WXGLGetCurrentContext();
WXDLLIMPEXP_GL bool WXGLSetCurrentContext(WXGLContext context);
WXDLLIMPEXP_GL WXGLPixelFormat WXGLChoosePixelFormat(const int *attribList);
WXDLLIMPEXP_GL WXGLPixelFormat WXGLChoosePixelFormat(const int *GLAttrs = NULL,
int n1 = 0,
const int *ctxAttrs = NULL,
int n2 = 0);
WXDLLIMPEXP_GL void WXGLDestroyPixelFormat( WXGLPixelFormat pixelFormat );
class WXDLLIMPEXP_GL wxGLContext : public wxGLContextBase
{
public:
wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
wxGLContext(wxGLCanvas *win,
const wxGLContext *other = NULL,
const wxGLContextAttrs *ctxAttrs = NULL);
virtual ~wxGLContext();
virtual bool SetCurrent(const wxGLCanvas& win) const;
@@ -52,6 +57,15 @@ private:
class WXDLLIMPEXP_GL wxGLCanvas : public wxGLCanvasBase
{
public:
wxGLCanvas(wxWindow *parent,
const wxGLAttributes& dispAttrs,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxGLCanvasName,
const wxPalette& palette = wxNullPalette);
wxGLCanvas(wxWindow *parent,
wxWindowID id = wxID_ANY,
const int *attribList = NULL,
@@ -61,6 +75,15 @@ public:
const wxString& name = wxGLCanvasName,
const wxPalette& palette = wxNullPalette);
bool Create(wxWindow *parent,
const wxGLAttributes& dispAttrs,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxGLCanvasName,
const wxPalette& palette = wxNullPalette);
bool Create(wxWindow *parent,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
@@ -85,6 +108,9 @@ public:
// return the pixel format used by this window
WXGLPixelFormat GetWXGLPixelFormat() const { return m_glFormat; }
// Return the copy of attributes passed at ctor
wxGLAttributes& GetGLDispAttrs() { return m_GLAttrs; }
// update the view port of the current context to match this window
void SetViewport();
@@ -133,6 +159,7 @@ public:
protected:
WXGLPixelFormat m_glFormat;
wxGLAttributes m_GLAttrs;
#if wxOSX_USE_CARBON
bool m_macCanvasIsShown,

View File

@@ -12,6 +12,9 @@
#include <GL/glx.h>
class wxGLContextAttrs;
class wxGLAttributes;
// ----------------------------------------------------------------------------
// wxGLContext
// ----------------------------------------------------------------------------
@@ -19,7 +22,9 @@
class WXDLLIMPEXP_GL wxGLContext : public wxGLContextBase
{
public:
wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
wxGLContext(wxGLCanvas *win,
const wxGLContext *other = NULL,
const wxGLContextAttrs *ctxAttrs = NULL);
virtual ~wxGLContext();
virtual bool SetCurrent(const wxGLCanvas& win) const wxOVERRIDE;
@@ -46,8 +51,8 @@ public:
// default ctor doesn't do anything, InitVisual() must be called
wxGLCanvasX11();
// initializes the XVisualInfo corresponding to the given attributes
bool InitVisual(const int *attribList);
// initializes GLXFBConfig and XVisualInfo corresponding to the given attributes
bool InitVisual(const wxGLAttributes& dispAttrs);
// frees XVisualInfo info
virtual ~wxGLCanvasX11();
@@ -75,10 +80,6 @@ public:
// GLX-specific methods
// --------------------
// return attribs for glXCreateContextAttribsARB
const int *GetGLXContextAttribs() const { return m_glxContextAttribs; }
// override some wxWindow methods
// ------------------------------
@@ -108,22 +109,10 @@ public:
//
// returns false if XVisualInfo couldn't be initialized, otherwise caller
// is responsible for freeing the pointers
static bool InitXVisualInfo(const int *attribList,
static bool InitXVisualInfo(const wxGLAttributes& dispAttrs,
GLXFBConfig **pFBC, XVisualInfo **pXVisual);
private:
// initializes glxContextAttribs as defined by wxattrs which must be
// 0-terminated
static void InitGLXContextAttribs(const int *wxattrs, int *glxctxattribs);
// fills in glattrs with attributes defined by wxattrs which must be
// 0-terminated if it is non-NULL
// will ignore any gl context attribs
//
// n is the max size of glattrs, false is returned if we overflow it, it
// should be at least 16 to accommodate the default attributes
static bool ConvertWXAttrsToGL(const int *wxattrs, int *glattrs, size_t n);
// this is only used if it's supported i.e. if GL >= 1.3
GLXFBConfig *m_fbc;
@@ -134,10 +123,6 @@ private:
// the global/default versions of the above
static GLXFBConfig *ms_glFBCInfo;
static XVisualInfo *ms_glVisualInfo;
// max 8 attributes plus terminator
// if first is 0, create legacy context
int m_glxContextAttribs[9];
};
// ----------------------------------------------------------------------------

View File

@@ -17,6 +17,16 @@
class WXDLLIMPEXP_GL wxGLCanvas : public wxGLCanvasX11
{
public:
wxGLCanvas(wxWindow *parent,
const wxGLAttributes& dispAttrs,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxGLCanvasName,
const wxPalette& palette = wxNullPalette);
wxEXPLICIT // avoid implicitly converting a wxWindow* to wxGLCanvas
wxGLCanvas(wxWindow *parent,
wxWindowID id = wxID_ANY,
const int *attribList = NULL,
@@ -26,6 +36,15 @@ public:
const wxString& name = wxGLCanvasName,
const wxPalette& palette = wxNullPalette);
bool Create(wxWindow *parent,
const wxGLAttributes& dispAttrs,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxGLCanvasName,
const wxPalette& palette = wxNullPalette);
bool Create(wxWindow *parent,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,