From 6d31105cb879614b2cf87193ea90215efd13bcce Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jarkko=20P=C3=B6yry?= Date: Thu, 5 Mar 2015 15:21:30 -0800 Subject: [PATCH] Expose tcuTexture getChannelReadMap publicly. - Add TextureSwizzle struct that can be used in future to implement swizzling in tcu::Sampler. - Expose getChannelReadMap and WriteMap and rename them to getChannelReadSwizzle and WriteSwizzle. - Use exposed channel maps in tcuTextureUtil instead of duplicating. Change-Id: Ie4953f4d9814d7e493dbea761dc5734f7a50c57f --- framework/common/tcuTexture.cpp | 269 ++++++++++++++++++++---------------- framework/common/tcuTexture.hpp | 28 ++++ framework/common/tcuTextureUtil.cpp | 100 ++++---------- 3 files changed, 203 insertions(+), 194 deletions(-) diff --git a/framework/common/tcuTexture.cpp b/framework/common/tcuTexture.cpp index 028d75e..ed11674 100644 --- a/framework/common/tcuTexture.cpp +++ b/framework/common/tcuTexture.cpp @@ -84,18 +84,6 @@ inline void writeRGB888Float (deUint8* ptr, const Vec4& val) ptr[2] = floatToU8(val[2]); } -enum Channel -{ - // \note CHANNEL_N must equal int N - CHANNEL_0 = 0, - CHANNEL_1, - CHANNEL_2, - CHANNEL_3, - - CHANNEL_ZERO, - CHANNEL_ONE -}; - // \todo [2011-09-21 pyry] Move to tcutil? template inline T convertSatRte (float f) @@ -125,89 +113,6 @@ inline T convertSatRte (float f) return (T)intVal; } -const Channel* getChannelReadMap (TextureFormat::ChannelOrder order) -{ - static const Channel INV[] = { CHANNEL_ZERO, CHANNEL_ZERO, CHANNEL_ZERO, CHANNEL_ONE }; - static const Channel R[] = { CHANNEL_0, CHANNEL_ZERO, CHANNEL_ZERO, CHANNEL_ONE }; - static const Channel A[] = { CHANNEL_ZERO, CHANNEL_ZERO, CHANNEL_ZERO, CHANNEL_0 }; - static const Channel I[] = { CHANNEL_0, CHANNEL_0, CHANNEL_0, CHANNEL_0 }; - static const Channel L[] = { CHANNEL_0, CHANNEL_0, CHANNEL_0, CHANNEL_ONE }; - static const Channel LA[] = { CHANNEL_0, CHANNEL_0, CHANNEL_0, CHANNEL_1 }; - static const Channel RG[] = { CHANNEL_0, CHANNEL_1, CHANNEL_ZERO, CHANNEL_ONE }; - static const Channel RA[] = { CHANNEL_0, CHANNEL_ZERO, CHANNEL_ZERO, CHANNEL_1 }; - static const Channel RGB[] = { CHANNEL_0, CHANNEL_1, CHANNEL_2, CHANNEL_ONE }; - static const Channel RGBA[] = { CHANNEL_0, CHANNEL_1, CHANNEL_2, CHANNEL_3 }; - static const Channel BGRA[] = { CHANNEL_2, CHANNEL_1, CHANNEL_0, CHANNEL_3 }; - static const Channel ARGB[] = { CHANNEL_1, CHANNEL_2, CHANNEL_3, CHANNEL_0 }; - static const Channel D[] = { CHANNEL_0, CHANNEL_ZERO, CHANNEL_ZERO, CHANNEL_ONE }; - static const Channel S[] = { CHANNEL_ZERO, CHANNEL_ZERO, CHANNEL_ZERO, CHANNEL_0 }; - static const Channel DS[] = { CHANNEL_0, CHANNEL_ZERO, CHANNEL_ZERO, CHANNEL_1 }; - - switch (order) - { - case TextureFormat::R: return R; - case TextureFormat::A: return A; - case TextureFormat::I: return I; - case TextureFormat::L: return L; - case TextureFormat::LA: return LA; - case TextureFormat::RG: return RG; - case TextureFormat::RA: return RA; - case TextureFormat::RGB: return RGB; - case TextureFormat::RGBA: return RGBA; - case TextureFormat::ARGB: return ARGB; - case TextureFormat::BGRA: return BGRA; - case TextureFormat::sRGB: return RGB; - case TextureFormat::sRGBA: return RGBA; - case TextureFormat::D: return D; - case TextureFormat::S: return S; - case TextureFormat::DS: return DS; - default: - DE_ASSERT(DE_FALSE); - return INV; - } -} - -const int* getChannelWriteMap (TextureFormat::ChannelOrder order) -{ - static const int R[] = { 0 }; - static const int A[] = { 3 }; - static const int I[] = { 0 }; - static const int L[] = { 0 }; - static const int LA[] = { 0, 3 }; - static const int RG[] = { 0, 1 }; - static const int RA[] = { 0, 3 }; - static const int RGB[] = { 0, 1, 2 }; - static const int RGBA[] = { 0, 1, 2, 3 }; - static const int BGRA[] = { 2, 1, 0, 3 }; - static const int ARGB[] = { 3, 0, 1, 2 }; - static const int D[] = { 0 }; - static const int S[] = { 3 }; - static const int DS[] = { 0, 3 }; - - switch (order) - { - case TextureFormat::R: return R; - case TextureFormat::A: return A; - case TextureFormat::I: return I; - case TextureFormat::L: return L; - case TextureFormat::LA: return LA; - case TextureFormat::RG: return RG; - case TextureFormat::RA: return RA; - case TextureFormat::RGB: return RGB; - case TextureFormat::RGBA: return RGBA; - case TextureFormat::ARGB: return ARGB; - case TextureFormat::BGRA: return BGRA; - case TextureFormat::sRGB: return RGB; - case TextureFormat::sRGBA: return RGBA; - case TextureFormat::D: return D; - case TextureFormat::S: return S; - case TextureFormat::DS: return DS; - default: - DE_ASSERT(DE_FALSE); - return DE_NULL; - } -} - int getChannelSize (TextureFormat::ChannelType type) { switch (type) @@ -403,6 +308,96 @@ tcu::Vec4 unpackRGB999E5 (deUint32 color) } // anonymous +const TextureSwizzle& getChannelReadSwizzle (TextureFormat::ChannelOrder order) +{ + // make sure to update these tables when channel orders are updated + DE_STATIC_ASSERT(TextureFormat::CHANNELORDER_LAST == 16); + + static const TextureSwizzle INV = {{ TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ONE }}; + static const TextureSwizzle R = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ONE }}; + static const TextureSwizzle A = {{ TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_0 }}; + static const TextureSwizzle I = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_0 }}; + static const TextureSwizzle L = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_ONE }}; + static const TextureSwizzle LA = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_1 }}; + static const TextureSwizzle RG = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_1, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ONE }}; + static const TextureSwizzle RA = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_1 }}; + static const TextureSwizzle RGB = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_1, TextureSwizzle::CHANNEL_2, TextureSwizzle::CHANNEL_ONE }}; + static const TextureSwizzle RGBA = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_1, TextureSwizzle::CHANNEL_2, TextureSwizzle::CHANNEL_3 }}; + static const TextureSwizzle BGRA = {{ TextureSwizzle::CHANNEL_2, TextureSwizzle::CHANNEL_1, TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3 }}; + static const TextureSwizzle ARGB = {{ TextureSwizzle::CHANNEL_1, TextureSwizzle::CHANNEL_2, TextureSwizzle::CHANNEL_3, TextureSwizzle::CHANNEL_0 }}; + static const TextureSwizzle D = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ONE }}; + static const TextureSwizzle S = {{ TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_0 }}; + static const TextureSwizzle DS = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_1 }}; + + switch (order) + { + case TextureFormat::R: return R; + case TextureFormat::A: return A; + case TextureFormat::I: return I; + case TextureFormat::L: return L; + case TextureFormat::LA: return LA; + case TextureFormat::RG: return RG; + case TextureFormat::RA: return RA; + case TextureFormat::RGB: return RGB; + case TextureFormat::RGBA: return RGBA; + case TextureFormat::ARGB: return ARGB; + case TextureFormat::BGRA: return BGRA; + case TextureFormat::sRGB: return RGB; + case TextureFormat::sRGBA: return RGBA; + case TextureFormat::D: return D; + case TextureFormat::S: return S; + case TextureFormat::DS: return DS; + default: + DE_ASSERT(DE_FALSE); + return INV; + } +} + +const TextureSwizzle& getChannelWriteSwizzle (TextureFormat::ChannelOrder order) +{ + // make sure to update these tables when channel orders are updated + DE_STATIC_ASSERT(TextureFormat::CHANNELORDER_LAST == 16); + + static const TextureSwizzle INV = {{ TextureSwizzle::CHANNEL_LAST, TextureSwizzle::CHANNEL_LAST, TextureSwizzle::CHANNEL_LAST, TextureSwizzle::CHANNEL_LAST }}; + static const TextureSwizzle R = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_LAST, TextureSwizzle::CHANNEL_LAST, TextureSwizzle::CHANNEL_LAST }}; + static const TextureSwizzle A = {{ TextureSwizzle::CHANNEL_3, TextureSwizzle::CHANNEL_LAST, TextureSwizzle::CHANNEL_LAST, TextureSwizzle::CHANNEL_LAST }}; + static const TextureSwizzle I = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_LAST, TextureSwizzle::CHANNEL_LAST, TextureSwizzle::CHANNEL_LAST }}; + static const TextureSwizzle L = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_LAST, TextureSwizzle::CHANNEL_LAST, TextureSwizzle::CHANNEL_LAST }}; + static const TextureSwizzle LA = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3, TextureSwizzle::CHANNEL_LAST, TextureSwizzle::CHANNEL_LAST }}; + static const TextureSwizzle RG = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_1, TextureSwizzle::CHANNEL_LAST, TextureSwizzle::CHANNEL_LAST }}; + static const TextureSwizzle RA = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3, TextureSwizzle::CHANNEL_LAST, TextureSwizzle::CHANNEL_LAST }}; + static const TextureSwizzle RGB = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_1, TextureSwizzle::CHANNEL_2, TextureSwizzle::CHANNEL_LAST }}; + static const TextureSwizzle RGBA = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_1, TextureSwizzle::CHANNEL_2, TextureSwizzle::CHANNEL_3 }}; + static const TextureSwizzle BGRA = {{ TextureSwizzle::CHANNEL_2, TextureSwizzle::CHANNEL_1, TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3 }}; + static const TextureSwizzle ARGB = {{ TextureSwizzle::CHANNEL_3, TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_1, TextureSwizzle::CHANNEL_2 }}; + static const TextureSwizzle D = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_LAST, TextureSwizzle::CHANNEL_LAST, TextureSwizzle::CHANNEL_LAST }}; + static const TextureSwizzle S = {{ TextureSwizzle::CHANNEL_3, TextureSwizzle::CHANNEL_LAST, TextureSwizzle::CHANNEL_LAST, TextureSwizzle::CHANNEL_LAST }}; + static const TextureSwizzle DS = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3, TextureSwizzle::CHANNEL_LAST, TextureSwizzle::CHANNEL_LAST }}; + + switch (order) + { + case TextureFormat::R: return R; + case TextureFormat::A: return A; + case TextureFormat::I: return I; + case TextureFormat::L: return L; + case TextureFormat::LA: return LA; + case TextureFormat::RG: return RG; + case TextureFormat::RA: return RA; + case TextureFormat::RGB: return RGB; + case TextureFormat::RGBA: return RGBA; + case TextureFormat::ARGB: return ARGB; + case TextureFormat::BGRA: return BGRA; + case TextureFormat::sRGB: return RGB; + case TextureFormat::sRGBA: return RGBA; + case TextureFormat::D: return D; + case TextureFormat::S: return S; + case TextureFormat::DS: return DS; + default: + DE_ASSERT(DE_FALSE); + return INV; + } +} + IVec3 calculatePackedPitch (const TextureFormat& format, const IVec3& size) { const int pixelSize = format.getPixelSize(); @@ -645,19 +640,32 @@ Vec4 ConstPixelBufferAccess::getPixel (int x, int y, int z) const #undef UB32 // Generic path. - Vec4 result; - const Channel* channelMap = getChannelReadMap(m_format.order); - int channelSize = getChannelSize(m_format.type); + Vec4 result; + const TextureSwizzle::Channel* channelMap = getChannelReadSwizzle(m_format.order).components; + int channelSize = getChannelSize(m_format.type); for (int c = 0; c < 4; c++) { - Channel map = channelMap[c]; - if (map == CHANNEL_ZERO) - result[c] = 0.0f; - else if (map == CHANNEL_ONE) - result[c] = 1.0f; - else - result[c] = channelToFloat(pixelPtr + channelSize*((int)map), m_format.type); + switch (channelMap[c]) + { + case TextureSwizzle::CHANNEL_0: + case TextureSwizzle::CHANNEL_1: + case TextureSwizzle::CHANNEL_2: + case TextureSwizzle::CHANNEL_3: + result[c] = channelToFloat(pixelPtr + channelSize*((int)channelMap[c]), m_format.type); + break; + + case TextureSwizzle::CHANNEL_ZERO: + result[c] = 0.0f; + break; + + case TextureSwizzle::CHANNEL_ONE: + result[c] = 1.0f; + break; + + default: + DE_ASSERT(false); + } } return result; @@ -719,18 +727,31 @@ IVec4 ConstPixelBufferAccess::getPixelInt (int x, int y, int z) const #undef U32 // Generic path. - const Channel* channelMap = getChannelReadMap(m_format.order); - int channelSize = getChannelSize(m_format.type); + const TextureSwizzle::Channel* channelMap = getChannelReadSwizzle(m_format.order).components; + int channelSize = getChannelSize(m_format.type); for (int c = 0; c < 4; c++) { - Channel map = channelMap[c]; - if (map == CHANNEL_ZERO) - result[c] = 0; - else if (map == CHANNEL_ONE) - result[c] = 1; - else - result[c] = channelToInt(pixelPtr + channelSize*((int)map), m_format.type); + switch (channelMap[c]) + { + case TextureSwizzle::CHANNEL_0: + case TextureSwizzle::CHANNEL_1: + case TextureSwizzle::CHANNEL_2: + case TextureSwizzle::CHANNEL_3: + result[c] = channelToInt(pixelPtr + channelSize*((int)channelMap[c]), m_format.type); + break; + + case TextureSwizzle::CHANNEL_ZERO: + result[c] = 0; + break; + + case TextureSwizzle::CHANNEL_ONE: + result[c] = 1; + break; + + default: + DE_ASSERT(false); + } } return result; @@ -910,13 +931,15 @@ void PixelBufferAccess::setPixel (const Vec4& color, int x, int y, int z) const default: { // Generic path. - int numChannels = getNumUsedChannels(m_format.order); - const int* map = getChannelWriteMap(m_format.order); - int channelSize = getChannelSize(m_format.type); + int numChannels = getNumUsedChannels(m_format.order); + const TextureSwizzle::Channel* map = getChannelWriteSwizzle(m_format.order).components; + int channelSize = getChannelSize(m_format.type); for (int c = 0; c < numChannels; c++) + { + DE_ASSERT(deInRange32(map[c], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3)); floatToChannel(pixelPtr + channelSize*c, color[map[c]], m_format.type); - + } break; } } @@ -972,13 +995,15 @@ void PixelBufferAccess::setPixel (const IVec4& color, int x, int y, int z) const default: { // Generic path. - int numChannels = getNumUsedChannels(m_format.order); - const int* map = getChannelWriteMap(m_format.order); - int channelSize = getChannelSize(m_format.type); + int numChannels = getNumUsedChannels(m_format.order); + const TextureSwizzle::Channel* map = getChannelWriteSwizzle(m_format.order).components; + int channelSize = getChannelSize(m_format.type); for (int c = 0; c < numChannels; c++) + { + DE_ASSERT(deInRange32(map[c], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3)); intToChannel(pixelPtr + channelSize*c, color[map[c]], m_format.type); - + } break; } } diff --git a/framework/common/tcuTexture.hpp b/framework/common/tcuTexture.hpp index b0e0435..a0e2bb7 100644 --- a/framework/common/tcuTexture.hpp +++ b/framework/common/tcuTexture.hpp @@ -119,6 +119,34 @@ public: } DE_WARN_UNUSED_TYPE; /*--------------------------------------------------------------------*//*! + * \brief Texture swizzle + *//*--------------------------------------------------------------------*/ +struct TextureSwizzle +{ + enum Channel + { + // \note CHANNEL_N must equal int N + CHANNEL_0 = 0, + CHANNEL_1, + CHANNEL_2, + CHANNEL_3, + + CHANNEL_ZERO, + CHANNEL_ONE, + + CHANNEL_LAST + }; + + Channel components[4]; +}; + +//! get the swizzle used to expand texture data with a given channel order to RGBA form +const TextureSwizzle& getChannelReadSwizzle (TextureFormat::ChannelOrder order); + +//! get the swizzle used to narrow RGBA form data to native texture data with a given channel order +const TextureSwizzle& getChannelWriteSwizzle (TextureFormat::ChannelOrder order); + +/*--------------------------------------------------------------------*//*! * \brief Sampling parameters *//*--------------------------------------------------------------------*/ class Sampler diff --git a/framework/common/tcuTextureUtil.cpp b/framework/common/tcuTextureUtil.cpp index 2f15696..abc4deb 100644 --- a/framework/common/tcuTextureUtil.cpp +++ b/framework/common/tcuTextureUtil.cpp @@ -278,28 +278,14 @@ TextureFormatInfo getTextureFormatInfo (const TextureFormat& format) Vec4(1.0f, 1.0f, 1.0f, 1.0f), Vec4(0.0f, 0.0f, 0.0f, 0.0f)); - Vec2 cRange = getChannelValueRange(format.type); - BVec4 chnMask = BVec4(false); - - switch (format.order) - { - case TextureFormat::R: chnMask = BVec4(true, false, false, false); break; - case TextureFormat::A: chnMask = BVec4(false, false, false, true); break; - case TextureFormat::L: chnMask = BVec4(true, true, true, false); break; - case TextureFormat::LA: chnMask = BVec4(true, true, true, true); break; - case TextureFormat::RG: chnMask = BVec4(true, true, false, false); break; - case TextureFormat::RGB: chnMask = BVec4(true, true, true, false); break; - case TextureFormat::RGBA: chnMask = BVec4(true, true, true, true); break; - case TextureFormat::sRGB: chnMask = BVec4(true, true, true, false); break; - case TextureFormat::sRGBA: chnMask = BVec4(true, true, true, true); break; - case TextureFormat::D: chnMask = BVec4(true, true, true, false); break; - case TextureFormat::DS: chnMask = BVec4(true, true, true, true); break; - default: - DE_ASSERT(false); - } - - float scale = 1.0f / (cRange[1] - cRange[0]); - float bias = -cRange[0] * scale; + const Vec2 cRange = getChannelValueRange(format.type); + const TextureSwizzle::Channel* map = getChannelReadSwizzle(format.order).components; + const BVec4 chnMask = BVec4(deInRange32(map[0], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, + deInRange32(map[1], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, + deInRange32(map[2], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, + deInRange32(map[3], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE); + const float scale = 1.0f / (cRange[1] - cRange[0]); + const float bias = -cRange[0] * scale; return TextureFormatInfo(select(cRange[0], 0.0f, chnMask), select(cRange[1], 0.0f, chnMask), @@ -344,31 +330,16 @@ static IVec4 getChannelBitDepth (TextureFormat::ChannelType channelType) IVec4 getTextureFormatBitDepth (const TextureFormat& format) { - IVec4 chnBits = getChannelBitDepth(format.type); - BVec4 chnMask = BVec4(false); - IVec4 chnSwz (0,1,2,3); - - switch (format.order) - { - case TextureFormat::R: chnMask = BVec4(true, false, false, false); break; - case TextureFormat::A: chnMask = BVec4(false, false, false, true); break; - case TextureFormat::RA: chnMask = BVec4(true, false, false, true); break; - case TextureFormat::L: chnMask = BVec4(true, true, true, false); break; - case TextureFormat::I: chnMask = BVec4(true, true, true, true); break; - case TextureFormat::LA: chnMask = BVec4(true, true, true, true); break; - case TextureFormat::RG: chnMask = BVec4(true, true, false, false); break; - case TextureFormat::RGB: chnMask = BVec4(true, true, true, false); break; - case TextureFormat::RGBA: chnMask = BVec4(true, true, true, true); break; - case TextureFormat::BGRA: chnMask = BVec4(true, true, true, true); chnSwz = IVec4(2, 1, 0, 3); break; - case TextureFormat::ARGB: chnMask = BVec4(true, true, true, true); chnSwz = IVec4(1, 2, 3, 0); break; - case TextureFormat::sRGB: chnMask = BVec4(true, true, true, false); break; - case TextureFormat::sRGBA: chnMask = BVec4(true, true, true, true); break; - case TextureFormat::D: chnMask = BVec4(true, false, false, false); break; - case TextureFormat::DS: chnMask = BVec4(true, false, false, true); break; - case TextureFormat::S: chnMask = BVec4(false, false, false, true); break; - default: - DE_ASSERT(false); - } + const IVec4 chnBits = getChannelBitDepth(format.type); + const TextureSwizzle::Channel* map = getChannelReadSwizzle(format.order).components; + const BVec4 chnMask = BVec4(deInRange32(map[0], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, + deInRange32(map[1], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, + deInRange32(map[2], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, + deInRange32(map[3], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE); + const IVec4 chnSwz = IVec4((chnMask[0]) ? ((int)map[0]) : (0), + (chnMask[1]) ? ((int)map[1]) : (0), + (chnMask[2]) ? ((int)map[2]) : (0), + (chnMask[3]) ? ((int)map[3]) : (0)); return select(chnBits.swizzle(chnSwz.x(), chnSwz.y(), chnSwz.z(), chnSwz.w()), IVec4(0), chnMask); } @@ -412,31 +383,16 @@ static IVec4 getChannelMantissaBitDepth (TextureFormat::ChannelType channelType) IVec4 getTextureFormatMantissaBitDepth (const TextureFormat& format) { - IVec4 chnBits = getChannelMantissaBitDepth(format.type); - BVec4 chnMask = BVec4(false); - IVec4 chnSwz (0,1,2,3); - - switch (format.order) - { - case TextureFormat::R: chnMask = BVec4(true, false, false, false); break; - case TextureFormat::A: chnMask = BVec4(false, false, false, true); break; - case TextureFormat::RA: chnMask = BVec4(true, false, false, true); break; - case TextureFormat::L: chnMask = BVec4(true, true, true, false); break; - case TextureFormat::I: chnMask = BVec4(true, true, true, true); break; - case TextureFormat::LA: chnMask = BVec4(true, true, true, true); break; - case TextureFormat::RG: chnMask = BVec4(true, true, false, false); break; - case TextureFormat::RGB: chnMask = BVec4(true, true, true, false); break; - case TextureFormat::RGBA: chnMask = BVec4(true, true, true, true); break; - case TextureFormat::BGRA: chnMask = BVec4(true, true, true, true); chnSwz = IVec4(2, 1, 0, 3); break; - case TextureFormat::ARGB: chnMask = BVec4(true, true, true, true); chnSwz = IVec4(1, 2, 3, 0); break; - case TextureFormat::sRGB: chnMask = BVec4(true, true, true, false); break; - case TextureFormat::sRGBA: chnMask = BVec4(true, true, true, true); break; - case TextureFormat::D: chnMask = BVec4(true, false, false, false); break; - case TextureFormat::DS: chnMask = BVec4(true, false, false, true); break; - case TextureFormat::S: chnMask = BVec4(false, false, false, true); break; - default: - DE_ASSERT(false); - } + const IVec4 chnBits = getChannelMantissaBitDepth(format.type); + const TextureSwizzle::Channel* map = getChannelReadSwizzle(format.order).components; + const BVec4 chnMask = BVec4(deInRange32(map[0], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, + deInRange32(map[1], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, + deInRange32(map[2], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, + deInRange32(map[3], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE); + const IVec4 chnSwz = IVec4((chnMask[0]) ? ((int)map[0]) : (0), + (chnMask[1]) ? ((int)map[1]) : (0), + (chnMask[2]) ? ((int)map[2]) : (0), + (chnMask[3]) ? ((int)map[3]) : (0)); return select(chnBits.swizzle(chnSwz.x(), chnSwz.y(), chnSwz.z(), chnSwz.w()), IVec4(0), chnMask); } -- 2.7.4