From 1393d7db0309a905fe37ac73745f7aeda959b980 Mon Sep 17 00:00:00 2001 From: drug007 Date: Wed, 25 Apr 2018 20:10:00 +0300 Subject: [PATCH] Additional image flags. These flags allow better control of texture outputting for nice visual effects. --- nanovega.d | 21 +++++++++++++++++++-- simpledisplay.d | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/nanovega.d b/nanovega.d index 921cf55..5a51e70 100644 --- a/nanovega.d +++ b/nanovega.d @@ -1281,6 +1281,8 @@ public enum NVGImageFlag : uint { RepeatY = 1<<2, /// Repeat image in Y direction. FlipY = 1<<3, /// Flips (inverses) image in Y direction when rendered. Premultiplied = 1<<4, /// Image data has premultiplied alpha. + ClampToBorderX = 1<<5, /// Clamp image to border (instead of clamping to edge by default) + ClampToBorderY = 1<<6, /// Clamp image to border (instead of clamping to edge by default) NoFiltering = 1<<8, /// use GL_NEAREST instead of GL_LINEAR Nearest = NoFiltering, /// compatibility with original NanoVG NoDelete = 1<<16,/// Do not delete GL texture handle. @@ -13405,8 +13407,23 @@ int glnvg__renderCreateTexture (void* uptr, NVGtexture type, int w, int h, int i glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, tfmin); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (imageFlags&NVGImageFlag.NoFiltering ? GL_NEAREST : GL_LINEAR)); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (imageFlags&NVGImageFlag.RepeatX ? GL_REPEAT : GL_CLAMP_TO_EDGE)); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (imageFlags&NVGImageFlag.RepeatY ? GL_REPEAT : GL_CLAMP_TO_EDGE)); + int flag; + if (imageFlags&NVGImageFlag.RepeatX) + flag = GL_REPEAT; + else if (imageFlags&NVGImageFlag.ClampToBorderX) + flag = GL_CLAMP_TO_BORDER; + else + flag = GL_CLAMP_TO_EDGE; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, flag); + + + if (imageFlags&NVGImageFlag.RepeatY) + flag = GL_REPEAT; + else if (imageFlags&NVGImageFlag.ClampToBorderY) + flag = GL_CLAMP_TO_BORDER; + else + flag = GL_CLAMP_TO_EDGE; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, flag); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); diff --git a/simpledisplay.d b/simpledisplay.d index 2fb6662..793f0c8 100644 --- a/simpledisplay.d +++ b/simpledisplay.d @@ -12507,6 +12507,7 @@ extern(System) nothrow @nogc { enum uint GL_REPEAT = 0x2901; enum uint GL_CLAMP = 0x2900; enum uint GL_CLAMP_TO_EDGE = 0x812F; + enum uint GL_CLAMP_TO_BORDER = 0x812D; enum uint GL_DECAL = 0x2101; enum uint GL_MODULATE = 0x2100; enum uint GL_TEXTURE_ENV = 0x2300;