commit 4336226e13cea171ebfdc30fac2e78565c7594ef
parent 45d2cab48a9d312d00e9811f2f6dc2a724916503
Author: falkTX <falktx@falktx.com>
Date: Mon, 31 Oct 2022 00:31:40 +0000
Avoid creating GL textures for empty images
Signed-off-by: falkTX <falktx@falktx.com>
Diffstat:
3 files changed, 35 insertions(+), 17 deletions(-)
diff --git a/dgl/OpenGL.hpp b/dgl/OpenGL.hpp
@@ -202,8 +202,9 @@ public:
GLenum getType() const noexcept { return GL_UNSIGNED_BYTE; }
private:
- GLuint textureId;
bool setupCalled;
+ bool textureInit;
+ GLuint textureId;
};
// -----------------------------------------------------------------------
diff --git a/dgl/src/OpenGL.cpp b/dgl/src/OpenGL.cpp
@@ -445,17 +445,17 @@ static void drawOpenGLImage(const OpenGLImage& image, const Point<int>& pos, con
OpenGLImage::OpenGLImage()
: ImageBase(),
- textureId(0),
- setupCalled(false)
+ setupCalled(false),
+ textureInit(false),
+ textureId(0)
{
- glGenTextures(1, &textureId);
- DISTRHO_SAFE_ASSERT(textureId != 0);
}
OpenGLImage::OpenGLImage(const char* const rdata, const uint w, const uint h, const ImageFormat fmt)
: ImageBase(rdata, w, h, fmt),
- textureId(0),
- setupCalled(false)
+ setupCalled(false),
+ textureInit(true),
+ textureId(0)
{
glGenTextures(1, &textureId);
DISTRHO_SAFE_ASSERT(textureId != 0);
@@ -463,8 +463,9 @@ OpenGLImage::OpenGLImage(const char* const rdata, const uint w, const uint h, co
OpenGLImage::OpenGLImage(const char* const rdata, const Size<uint>& s, const ImageFormat fmt)
: ImageBase(rdata, s, fmt),
- textureId(0),
- setupCalled(false)
+ setupCalled(false),
+ textureInit(true),
+ textureId(0)
{
glGenTextures(1, &textureId);
DISTRHO_SAFE_ASSERT(textureId != 0);
@@ -472,8 +473,9 @@ OpenGLImage::OpenGLImage(const char* const rdata, const Size<uint>& s, const Ima
OpenGLImage::OpenGLImage(const OpenGLImage& image)
: ImageBase(image),
- textureId(0),
- setupCalled(false)
+ setupCalled(false),
+ textureInit(true),
+ textureId(0)
{
glGenTextures(1, &textureId);
DISTRHO_SAFE_ASSERT(textureId != 0);
@@ -487,6 +489,12 @@ OpenGLImage::~OpenGLImage()
void OpenGLImage::loadFromMemory(const char* const rdata, const Size<uint>& s, const ImageFormat fmt) noexcept
{
+ if (!textureInit)
+ {
+ textureInit = true;
+ glGenTextures(1, &textureId);
+ DISTRHO_SAFE_ASSERT(textureId != 0);
+ }
setupCalled = false;
ImageBase::loadFromMemory(rdata, s, fmt);
}
@@ -502,14 +510,23 @@ OpenGLImage& OpenGLImage::operator=(const OpenGLImage& image) noexcept
size = image.size;
format = image.format;
setupCalled = false;
+
+ if (image.isValid() && !textureInit)
+ {
+ textureInit = true;
+ glGenTextures(1, &textureId);
+ DISTRHO_SAFE_ASSERT(textureId != 0);
+ }
+
return *this;
}
// deprecated calls
OpenGLImage::OpenGLImage(const char* const rdata, const uint w, const uint h, const GLenum fmt)
: ImageBase(rdata, w, h, asDISTRHOImageFormat(fmt)),
- textureId(0),
- setupCalled(false)
+ setupCalled(false),
+ textureInit(true),
+ textureId(0)
{
glGenTextures(1, &textureId);
DISTRHO_SAFE_ASSERT(textureId != 0);
@@ -517,8 +534,9 @@ OpenGLImage::OpenGLImage(const char* const rdata, const uint w, const uint h, co
OpenGLImage::OpenGLImage(const char* const rdata, const Size<uint>& s, const GLenum fmt)
: ImageBase(rdata, s, asDISTRHOImageFormat(fmt)),
- textureId(0),
- setupCalled(false)
+ setupCalled(false),
+ textureInit(true),
+ textureId(0)
{
glGenTextures(1, &textureId);
DISTRHO_SAFE_ASSERT(textureId != 0);
diff --git a/dgl/src/pugl.cpp b/dgl/src/pugl.cpp
@@ -564,8 +564,7 @@ void puglWin32ShowCentered(PuglView* const view)
mInfo.cbSize = sizeof(mInfo);
if (GetMonitorInfo(MonitorFromWindow(impl->hwnd, MONITOR_DEFAULTTOPRIMARY), &mInfo))
- SetWindowPos(impl->hwnd,
- HWND_TOP,
+ SetWindowPos(impl->hwnd, HWND_TOP,
mInfo.rcWork.left + (mInfo.rcWork.right - mInfo.rcWork.left - view->frame.width) / 2,
mInfo.rcWork.top + (mInfo.rcWork.bottom - mInfo.rcWork.top - view->frame.height) / 2,
0, 0, SWP_SHOWWINDOW|SWP_NOSIZE);