diff --git a/dgl/OpenGL.hpp b/dgl/OpenGL.hpp index 91da7e3c..4d2e9ceb 100644 --- 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 index b7426370..6bd3063e 100644 --- a/dgl/src/OpenGL.cpp +++ b/dgl/src/OpenGL.cpp @@ -445,17 +445,17 @@ static void drawOpenGLImage(const OpenGLImage& image, const Point& 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& 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& 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& 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& 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 index 0f2d9ec9..001d757d 100644 --- 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);