mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
OpenGL: Tidying
This commit is contained in:
parent
e64f87b26c
commit
b27af5def9
2 changed files with 40 additions and 42 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -1364,7 +1364,7 @@ void OpenGLContext::copyTexture (const Rectangle<int>& targetClipArea,
|
|||
struct OverlayShaderProgram : public ReferenceCountedObject
|
||||
{
|
||||
OverlayShaderProgram (OpenGLContext& context)
|
||||
: program (context), builder (program), params (program)
|
||||
: program (context), params (program)
|
||||
{}
|
||||
|
||||
static const OverlayShaderProgram& select (OpenGLContext& context)
|
||||
|
|
@ -1382,11 +1382,12 @@ void OpenGLContext::copyTexture (const Rectangle<int>& targetClipArea,
|
|||
return *program;
|
||||
}
|
||||
|
||||
struct ProgramBuilder
|
||||
struct BuiltProgram : public OpenGLShaderProgram
|
||||
{
|
||||
ProgramBuilder (OpenGLShaderProgram& prog)
|
||||
explicit BuiltProgram (OpenGLContext& context)
|
||||
: OpenGLShaderProgram (context)
|
||||
{
|
||||
prog.addVertexShader (OpenGLHelpers::translateVertexShaderToV3 (
|
||||
addVertexShader (OpenGLHelpers::translateVertexShaderToV3 (
|
||||
"attribute " JUCE_HIGHP " vec2 position;"
|
||||
"uniform " JUCE_HIGHP " vec2 screenSize;"
|
||||
"uniform " JUCE_HIGHP " float textureBounds[4];"
|
||||
|
|
@ -1400,7 +1401,7 @@ void OpenGLContext::copyTexture (const Rectangle<int>& targetClipArea,
|
|||
"texturePos = vec2 (texturePos.x, vOffsetAndScale.x + vOffsetAndScale.y * texturePos.y);"
|
||||
"}"));
|
||||
|
||||
prog.addFragmentShader (OpenGLHelpers::translateFragmentShaderToV3 (
|
||||
addFragmentShader (OpenGLHelpers::translateFragmentShaderToV3 (
|
||||
"uniform sampler2D imageTexture;"
|
||||
"varying " JUCE_HIGHP " vec2 texturePos;"
|
||||
"void main()"
|
||||
|
|
@ -1408,7 +1409,7 @@ void OpenGLContext::copyTexture (const Rectangle<int>& targetClipArea,
|
|||
"gl_FragColor = texture2D (imageTexture, texturePos);"
|
||||
"}"));
|
||||
|
||||
prog.link();
|
||||
link();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -1437,8 +1438,7 @@ void OpenGLContext::copyTexture (const Rectangle<int>& targetClipArea,
|
|||
OpenGLShaderProgram::Uniform screenSize, imageTexture, textureBounds, vOffsetAndScale;
|
||||
};
|
||||
|
||||
OpenGLShaderProgram program;
|
||||
ProgramBuilder builder;
|
||||
BuiltProgram program;
|
||||
Params params;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue