Skip to content
Permalink
Browse files

remove scale factor from opengl view, clients should use frame->getSc…

…aleFactor ()

add stencil buffer size and remove accelerated from pixel format
use custom pixel format to create win32 opengl context
  • Loading branch information...
scheffle committed Dec 9, 2017
1 parent bd1a8c6 commit 6c5974c6f3ed64f3a9b1d2b576b96aecd3289295
@@ -17,23 +17,22 @@ class IPlatformFrame;
//-----------------------------------------------------------------------------
struct PixelFormat
{
// TODO: do we need more ?
// TODO: add more if we need more...

enum {
kDoubleBuffered = 1 << 0,
kAccelerated = 1 << 1,
kMultiSample = 1 << 2,
kModernOpenGL = 1 << 3 // Mac only currently. Indicates to use the NSOpenGLProfileVersion3_2Core. Not tested !
kModernOpenGL = 1 << 3 // Mac only. Indicates to use the NSOpenGLProfileVersion3_2Core.
};

uint32_t depthSize;
uint32_t samples; ///< only used when kMultiSample is set
uint32_t flags;
uint32_t depthBufferSize {32};
uint32_t stencilBufferSize {0};
uint32_t samples {0}; ///< only used when kMultiSample is set
uint32_t flags {kDoubleBuffered};

PixelFormat () : depthSize (32), samples (0), flags (kAccelerated) {}
PixelFormat (const PixelFormat& pf) : depthSize (pf.depthSize), samples (pf.samples), flags (pf.flags) {}

PixelFormat& operator() (const PixelFormat& pf) { depthSize = pf.depthSize; samples = pf.samples; flags = pf.flags; return *this; }
PixelFormat () = default;
PixelFormat (const PixelFormat&) = default;
PixelFormat& operator= (const PixelFormat&) = default;
};

//-----------------------------------------------------------------------------
@@ -60,7 +59,6 @@ class IPlatformOpenGLView : public AtomicReferenceCounted
virtual bool unlockContext () = 0; ///< unlock changes to context

virtual void swapBuffers () = 0; ///< swap buffers and clear active OpenGL context
virtual double getScaleFactor () = 0; ///< get the scale factor on HiDPI screens
};

} // namespace
@@ -70,3 +68,4 @@ class IPlatformOpenGLView : public AtomicReferenceCounted
/// @endcond

#endif // __iplatformopenglview__

@@ -38,7 +38,6 @@ class CocoaOpenGLView : public IPlatformOpenGLView
bool unlockContext () override;

void swapBuffers () override;
double getScaleFactor () override;

void doDraw (const CRect& r);
void reshape ();
@@ -46,12 +46,11 @@ - (id)initWithFrame:(NSRect)frameRect pixelFormat:(NSOpenGLPixelFormat *)format
{
pixelFormat = *_pixelFormat;
formatAttributes.emplace_back (NSOpenGLPFADepthSize);
formatAttributes.emplace_back (pixelFormat.depthSize);
if (pixelFormat.flags & PixelFormat::kAccelerated)
{
formatAttributes.emplace_back (NSOpenGLPFANoRecovery);
formatAttributes.emplace_back (NSOpenGLPFAAccelerated);
}
formatAttributes.emplace_back (pixelFormat.depthBufferSize);
formatAttributes.emplace_back (NSOpenGLPFAStencilSize);
formatAttributes.emplace_back (pixelFormat.stencilBufferSize);
formatAttributes.emplace_back (NSOpenGLPFANoRecovery);
formatAttributes.emplace_back (NSOpenGLPFAAccelerated);
if (pixelFormat.flags & PixelFormat::kDoubleBuffered)
{
formatAttributes.emplace_back (NSOpenGLPFADoubleBuffer);
@@ -71,6 +70,11 @@ - (id)initWithFrame:(NSRect)frameRect pixelFormat:(NSOpenGLPixelFormat *)format
formatAttributes.emplace_back (NSOpenGLPFAOpenGLProfile);
formatAttributes.emplace_back (NSOpenGLProfileVersion3_2Core);
}
else
{
formatAttributes.emplace_back (NSOpenGLPFAOpenGLProfile);
formatAttributes.emplace_back (NSOpenGLProfileVersionLegacy);
}
}
else
{
@@ -187,16 +191,6 @@ - (id)initWithFrame:(NSRect)frameRect pixelFormat:(NSOpenGLPixelFormat *)format
}
}

//-----------------------------------------------------------------------------
double CocoaOpenGLView::getScaleFactor ()
{
if (platformView && platformView.window)
{
return platformView.window.backingScaleFactor;
}
return 1.;
}

//-----------------------------------------------------------------------------
void CocoaOpenGLView::viewSizeChanged (const CRect& visibleSize)
{
@@ -38,7 +38,6 @@ class GLKitOpenGLView : public IPlatformOpenGLView
bool unlockContext () override;

void swapBuffers () override;
double getScaleFactor () override;

void doDraw (const CRect& r);

@@ -167,12 +167,6 @@ - (void)drawRect:(CGRect)rect
{
}

//-----------------------------------------------------------------------------
double GLKitOpenGLView::getScaleFactor ()
{
return 1.;
}

//-----------------------------------------------------------------------------
void GLKitOpenGLView::doDraw (const CRect& r)
{
@@ -102,7 +102,7 @@ LONG_PTR WINAPI Win32OpenGLView::WindowProc (HWND hwnd, UINT message, WPARAM wPa
}

//-----------------------------------------------------------------------------
bool Win32OpenGLView::setupPixelFormt ()
bool Win32OpenGLView::setupPixelFormt (PixelFormat* pixelFormat)
{
// TODO: support for custom PixelFormat
if (deviceContext)
@@ -127,10 +127,18 @@ bool Win32OpenGLView::setupPixelFormt ()
0, // reserved
0, 0, 0 // layer masks ignored
};
int iPixelFormat;

if (pixelFormat)
{
pfd.cDepthBits = pixelFormat->depthBufferSize;
pfd.cStencilBits = pixelFormat->stencilBufferSize;
if (pixelFormat->flags & PixelFormat::kDoubleBuffered)
pfd.dwFlags |= PFD_DOUBLEBUFFER;
else
pfd.dwFlags &= ~PFD_DOUBLEBUFFER;
}

// get the device context's best, available pixel format match
iPixelFormat = ChoosePixelFormat (deviceContext, &pfd);
auto iPixelFormat = ChoosePixelFormat (deviceContext, &pfd);

// make that match the device context's current pixel format
return SetPixelFormat (deviceContext, iPixelFormat, &pfd) ? true : false;
@@ -139,7 +147,7 @@ bool Win32OpenGLView::setupPixelFormt ()
}

//-----------------------------------------------------------------------------
bool Win32OpenGLView::createWindow ()
bool Win32OpenGLView::createWindow (PixelFormat* pixelFormat)
{
if (windowHandle)
return false;
@@ -155,7 +163,7 @@ bool Win32OpenGLView::createWindow ()
EnableWindow (windowHandle, false); // we don't handle mouse and keyboard events
SetWindowLongPtr (windowHandle, GWLP_USERDATA, (__int3264)(LONG_PTR)this);
deviceContext = GetDC (windowHandle);
if (deviceContext && setupPixelFormt ())
if (deviceContext && setupPixelFormt (pixelFormat))
{
openGLContext = wglCreateContext (deviceContext);
return true;
@@ -166,14 +174,12 @@ bool Win32OpenGLView::createWindow ()
}

//-----------------------------------------------------------------------------
bool Win32OpenGLView::init (IOpenGLView* view, PixelFormat* _pixelFormat)
bool Win32OpenGLView::init (IOpenGLView* view, PixelFormat* pixelFormat)
{
if (windowHandle)
return false;
if (_pixelFormat)
pixelFormat = *_pixelFormat;

if (createWindow ())
if (createWindow (pixelFormat))
{
this->view = view;
return true;
@@ -255,12 +261,6 @@ void Win32OpenGLView::swapBuffers ()
}
}

//-----------------------------------------------------------------------------
double Win32OpenGLView::getScaleFactor ()
{
return 1.;
}

} // namespace

#endif // WINDOWS && VSTGUI_OPENGL_SUPPORT
@@ -33,19 +33,17 @@ class Win32OpenGLView : public IPlatformOpenGLView
bool unlockContext () override;

void swapBuffers () override;
double getScaleFactor () override;
protected:
static void initWindowClass ();
static void destroyWindowClass ();
static LONG_PTR WINAPI WindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

bool createWindow ();
bool setupPixelFormt ();
bool createWindow (PixelFormat* pixelFormat);
bool setupPixelFormt (PixelFormat* pixelFormat);

Win32Frame* win32Frame;
IOpenGLView* view;
HWND windowHandle;
PixelFormat pixelFormat;

HDC deviceContext;
HGLRC openGLContext;

0 comments on commit 6c5974c

Please sign in to comment.
You can’t perform that action at this time.