Browse Source

Avoid creating GL textures for empty images

Signed-off-by: falkTX <falktx@falktx.com>
pull/409/head
falkTX 3 years ago
parent
commit
4336226e13
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
3 changed files with 35 additions and 17 deletions
  1. +2
    -1
      dgl/OpenGL.hpp
  2. +32
    -14
      dgl/src/OpenGL.cpp
  3. +1
    -2
      dgl/src/pugl.cpp

+ 2
- 1
dgl/OpenGL.hpp View File

@@ -202,8 +202,9 @@ public:
GLenum getType() const noexcept { return GL_UNSIGNED_BYTE; }

private:
GLuint textureId;
bool setupCalled;
bool textureInit;
GLuint textureId;
};

// -----------------------------------------------------------------------


+ 32
- 14
dgl/src/OpenGL.cpp View File

@@ -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);


+ 1
- 2
dgl/src/pugl.cpp View File

@@ -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);


Loading…
Cancel
Save