commit 7bd8b4c5638b3a3b214b56f8bd129e613a252150
parent 9864c371e917bde9cf7d20c8cbcb5fc8f9657970
Author: falkTX <falktx@gmail.com>
Date: Sat, 2 May 2015 21:07:09 +0200
Add NanoVG::createImageFromTextureHandle
Diffstat:
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/dgl/NanoVG.hpp b/dgl/NanoVG.hpp
@@ -196,8 +196,7 @@ public:
IMAGE_REPEAT_X = 1 << 1, // Repeat image in X direction.
IMAGE_REPEAT_Y = 1 << 2, // Repeat image in Y direction.
IMAGE_FLIP_Y = 1 << 3, // Flips (inverses) image in Y direction when rendered.
- IMAGE_PREMULTIPLIED = 1 << 4, // Image data has premultiplied alpha.
- IMAGE_NODELETE = 1 << 16,// Do not delete GL texture handle.
+ IMAGE_PREMULTIPLIED = 1 << 4 // Image data has premultiplied alpha.
};
enum Align {
@@ -538,6 +537,13 @@ public:
// TODO overloaded?
+ /**
+ Creates image from an OpenGL texture handle.
+ */
+ NanoImage* createImageFromTextureHandle(GLuint textureId, uint w, uint h, int imageFlags, bool deleteTexture = false);
+
+ // TODO overloaded?
+
/* --------------------------------------------------------------------
* Paints */
diff --git a/dgl/src/NanoVG.cpp b/dgl/src/NanoVG.cpp
@@ -522,6 +522,20 @@ NanoImage* NanoVG::createImageRGBA(uint w, uint h, const uchar* data, int imageF
return nullptr;
}
+NanoImage* NanoVG::createImageFromTextureHandle(GLuint textureId, uint w, uint h, int imageFlags, bool deleteTexture)
+{
+ if (fContext == nullptr) return nullptr;
+ DISTRHO_SAFE_ASSERT_RETURN(textureId != 0, nullptr);
+
+ if (! deleteTexture)
+ imageFlags |= NVG_IMAGE_NODELETE;
+
+ if (const int imageId = nvglCreateImageFromHandle(fContext, textureId, static_cast<int>(w), static_cast<int>(h), imageFlags))
+ return new NanoImage(fContext, imageId);
+
+ return nullptr;
+}
+
// -----------------------------------------------------------------------
// Paints