From 156ce94f3726377b6e7a43cbba4ea48122f98178 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Mon, 11 Apr 2016 11:58:50 +0300 Subject: [PATCH] Scene3d Texture colors fixed --- src/dlangui/graphics/drawbuf.d | 14 +++++++++++++- src/dlangui/graphics/gldrawbuf.d | 6 +++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/dlangui/graphics/drawbuf.d b/src/dlangui/graphics/drawbuf.d index 2f4d7e2f..06a6eb9e 100644 --- a/src/dlangui/graphics/drawbuf.d +++ b/src/dlangui/graphics/drawbuf.d @@ -970,17 +970,29 @@ class ColorDrawBuf : ColorDrawBufBase { fill(0xFFFFFFFF); drawRescaled(Rect(0, 0, dx, dy), v, Rect(0, 0, v.width, v.height)); } + void invertAlpha() { foreach(ref pixel; _buf) pixel ^= 0xFF000000; } + void invertByteOrder() { - foreach(pixel; _buf) { + foreach(ref pixel; _buf) { pixel = (pixel & 0xFF00FF00) | ((pixel & 0xFF0000) >> 16) | ((pixel & 0xFF) << 16); } } + + // for passing of image to OpenGL texture + void invertAlphaAndByteOrder() { + foreach(ref pixel; _buf) { + pixel = ((pixel & 0xFF00FF00) | + ((pixel & 0xFF0000) >> 16) | + ((pixel & 0xFF) << 16)); + pixel ^= 0xFF000000; + } + } override uint * scanLine(int y) { if (y >= 0 && y < _dy) return _buf.ptr + _dx * y; diff --git a/src/dlangui/graphics/gldrawbuf.d b/src/dlangui/graphics/gldrawbuf.d index 69fc7c9d..2eb772b5 100644 --- a/src/dlangui/graphics/gldrawbuf.d +++ b/src/dlangui/graphics/gldrawbuf.d @@ -852,14 +852,14 @@ static class GLTexture : RefCountedObject { return; } uint * pixels = buf.scanLine(0); - buf.invertAlpha(); + buf.invertAlphaAndByteOrder(); if (!glSupport.setTextureImage(_texture, buf.width, buf.height, cast(ubyte*)pixels, mipmapLevels)) { destroy(_texture); _texture = null; - buf.invertAlpha(); + buf.invertAlphaAndByteOrder(); return; } - buf.invertAlpha(); + buf.invertAlphaAndByteOrder(); } }