|
|
|
@@ -44,13 +44,13 @@ public: |
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
|
|
|
initialisePixelFormatDescriptor (pfd, pixelFormat);
|
|
|
|
|
|
|
|
auto pixFormat = ChoosePixelFormat (dc, &pfd);
|
|
|
|
auto pixFormat = ChoosePixelFormat (dc.get(), &pfd);
|
|
|
|
|
|
|
|
if (pixFormat != 0)
|
|
|
|
SetPixelFormat (dc, pixFormat, &pfd);
|
|
|
|
SetPixelFormat (dc.get(), pixFormat, &pfd);
|
|
|
|
|
|
|
|
initialiseWGLExtensions (dc);
|
|
|
|
renderContext = createRenderContext (version, dc);
|
|
|
|
initialiseWGLExtensions (dc.get());
|
|
|
|
renderContext.reset (createRenderContext (version, dc.get()));
|
|
|
|
|
|
|
|
if (renderContext != nullptr)
|
|
|
|
{
|
|
|
|
@@ -62,20 +62,20 @@ public: |
|
|
|
if (wglFormat != pixFormat && wglFormat != 0)
|
|
|
|
{
|
|
|
|
// can't change the pixel format of a window, so need to delete the
|
|
|
|
// old one and create a new one..
|
|
|
|
releaseDC();
|
|
|
|
// old one and create a new one.
|
|
|
|
dc.reset();
|
|
|
|
nativeWindow = nullptr;
|
|
|
|
createNativeWindow (component);
|
|
|
|
|
|
|
|
if (SetPixelFormat (dc, wglFormat, &pfd))
|
|
|
|
if (SetPixelFormat (dc.get(), wglFormat, &pfd))
|
|
|
|
{
|
|
|
|
deleteRenderContext();
|
|
|
|
renderContext = createRenderContext (version, dc);
|
|
|
|
renderContext.reset();
|
|
|
|
renderContext.reset (createRenderContext (version, dc.get()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contextToShareWithIn != nullptr)
|
|
|
|
wglShareLists ((HGLRC) contextToShareWithIn, renderContext);
|
|
|
|
wglShareLists ((HGLRC) contextToShareWithIn, renderContext.get());
|
|
|
|
|
|
|
|
component.getTopLevelComponent()->repaint();
|
|
|
|
component.repaint();
|
|
|
|
@@ -84,8 +84,8 @@ public: |
|
|
|
|
|
|
|
~NativeContext() override
|
|
|
|
{
|
|
|
|
deleteRenderContext();
|
|
|
|
releaseDC();
|
|
|
|
renderContext.reset();
|
|
|
|
dc.reset();
|
|
|
|
|
|
|
|
if (safeComponent != nullptr)
|
|
|
|
if (auto* peer = safeComponent->getTopLevelComponent()->getPeer())
|
|
|
|
@@ -107,9 +107,9 @@ public: |
|
|
|
}
|
|
|
|
|
|
|
|
static void deactivateCurrentContext() { wglMakeCurrent (nullptr, nullptr); }
|
|
|
|
bool makeActive() const noexcept { return isActive() || wglMakeCurrent (dc, renderContext) != FALSE; }
|
|
|
|
bool isActive() const noexcept { return wglGetCurrentContext() == renderContext; }
|
|
|
|
void swapBuffers() const noexcept { SwapBuffers (dc); }
|
|
|
|
bool makeActive() const noexcept { return isActive() || wglMakeCurrent (dc.get(), renderContext.get()) != FALSE; }
|
|
|
|
bool isActive() const noexcept { return wglGetCurrentContext() == renderContext.get(); }
|
|
|
|
void swapBuffers() const noexcept { SwapBuffers (dc.get()); }
|
|
|
|
|
|
|
|
bool setSwapInterval (int numFramesPerSwap)
|
|
|
|
{
|
|
|
|
@@ -137,7 +137,7 @@ public: |
|
|
|
}
|
|
|
|
|
|
|
|
bool createdOk() const noexcept { return getRawContext() != nullptr; }
|
|
|
|
void* getRawContext() const noexcept { return renderContext; }
|
|
|
|
void* getRawContext() const noexcept { return renderContext.get(); }
|
|
|
|
unsigned int getFrameBufferID() const noexcept { return 0; }
|
|
|
|
|
|
|
|
void triggerRepaint()
|
|
|
|
@@ -292,21 +292,8 @@ private: |
|
|
|
}
|
|
|
|
|
|
|
|
nativeWindow->setVisible (true);
|
|
|
|
dc = GetDC ((HWND) nativeWindow->getNativeHandle());
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteRenderContext()
|
|
|
|
{
|
|
|
|
if (renderContext != nullptr)
|
|
|
|
{
|
|
|
|
wglDeleteContext (renderContext);
|
|
|
|
renderContext = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void releaseDC()
|
|
|
|
{
|
|
|
|
ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
|
|
|
|
dc = std::unique_ptr<std::remove_pointer_t<HDC>, DeviceContextDeleter> { GetDC ((HWND) nativeWindow->getNativeHandle()),
|
|
|
|
DeviceContextDeleter { (HWND) nativeWindow->getNativeHandle() } };
|
|
|
|
}
|
|
|
|
|
|
|
|
int wglChoosePixelFormatExtension (const OpenGLPixelFormat& pixelFormat) const
|
|
|
|
@@ -351,7 +338,7 @@ private: |
|
|
|
jassert (n <= numElementsInArray (atts));
|
|
|
|
|
|
|
|
UINT formatsCount = 0;
|
|
|
|
wglChoosePixelFormatARB (dc, atts, nullptr, 1, &format, &formatsCount);
|
|
|
|
wglChoosePixelFormatARB (dc.get(), atts, nullptr, 1, &format, &formatsCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
return format;
|
|
|
|
@@ -368,12 +355,23 @@ private: |
|
|
|
#undef JUCE_DECLARE_WGL_EXTENSION_FUNCTION
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
struct RenderContextDeleter
|
|
|
|
{
|
|
|
|
void operator() (HGLRC ptr) const { wglDeleteContext (ptr); }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DeviceContextDeleter
|
|
|
|
{
|
|
|
|
void operator() (HDC ptr) const { ReleaseDC (hwnd, ptr); }
|
|
|
|
HWND hwnd;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unique_ptr<DummyComponent> dummyComponent;
|
|
|
|
std::unique_ptr<ComponentPeer> nativeWindow;
|
|
|
|
std::unique_ptr<ScopedThreadDPIAwarenessSetter> threadAwarenessSetter;
|
|
|
|
Component::SafePointer<Component> safeComponent;
|
|
|
|
HGLRC renderContext;
|
|
|
|
HDC dc;
|
|
|
|
std::unique_ptr<std::remove_pointer_t<HGLRC>, RenderContextDeleter> renderContext;
|
|
|
|
std::unique_ptr<std::remove_pointer_t<HDC>, DeviceContextDeleter> dc;
|
|
|
|
OpenGLContext* context = nullptr;
|
|
|
|
double nativeScaleFactor = 1.0;
|
|
|
|
|
|
|
|
|