|
|
@@ -589,31 +589,31 @@ namespace bs
|
|
|
0, 0, 0, 0, 0, 0, 0, 0
|
|
|
},
|
|
|
//-----------------------------------------------------------------------
|
|
|
- {"PF_FLOAT16_RGB",
|
|
|
- /* Bytes per element */
|
|
|
- 6,
|
|
|
- /* Flags */
|
|
|
- PFF_FLOAT,
|
|
|
- /* Component type and count */
|
|
|
- PCT_FLOAT16, 3,
|
|
|
- /* rbits, gbits, bbits, abits */
|
|
|
- 16, 16, 16, 0,
|
|
|
- /* Masks and shifts */
|
|
|
- 0, 0, 0, 0, 0, 0, 0, 0
|
|
|
- },
|
|
|
+ { "PF_FLOAT16_RGB",
|
|
|
+ /* Bytes per element */
|
|
|
+ 6,
|
|
|
+ /* Flags */
|
|
|
+ PFF_FLOAT,
|
|
|
+ /* Component type and count */
|
|
|
+ PCT_FLOAT16, 3,
|
|
|
+ /* rbits, gbits, bbits, abits */
|
|
|
+ 16, 16, 16, 0,
|
|
|
+ /* Masks and shifts */
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 0
|
|
|
+ },
|
|
|
//-----------------------------------------------------------------------
|
|
|
- {"PF_FLOAT16_RGBA",
|
|
|
- /* Bytes per element */
|
|
|
- 8,
|
|
|
- /* Flags */
|
|
|
- PFF_FLOAT | PFF_HASALPHA,
|
|
|
- /* Component type and count */
|
|
|
- PCT_FLOAT16, 4,
|
|
|
- /* rbits, gbits, bbits, abits */
|
|
|
- 16, 16, 16, 16,
|
|
|
- /* Masks and shifts */
|
|
|
- 0, 0, 0, 0, 0, 0, 0, 0
|
|
|
- },
|
|
|
+ { "PF_FLOAT16_RGBA",
|
|
|
+ /* Bytes per element */
|
|
|
+ 8,
|
|
|
+ /* Flags */
|
|
|
+ PFF_FLOAT | PFF_HASALPHA,
|
|
|
+ /* Component type and count */
|
|
|
+ PCT_FLOAT16, 4,
|
|
|
+ /* rbits, gbits, bbits, abits */
|
|
|
+ 16, 16, 16, 16,
|
|
|
+ /* Masks and shifts */
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 0
|
|
|
+ },
|
|
|
//-----------------------------------------------------------------------
|
|
|
{"PF_FLOAT32_R",
|
|
|
/* Bytes per element */
|
|
|
@@ -641,31 +641,31 @@ namespace bs
|
|
|
0, 0, 0, 0, 0, 0, 0, 0
|
|
|
},
|
|
|
//-----------------------------------------------------------------------
|
|
|
- {"PF_FLOAT32_RGB",
|
|
|
- /* Bytes per element */
|
|
|
- 12,
|
|
|
- /* Flags */
|
|
|
- PFF_FLOAT,
|
|
|
- /* Component type and count */
|
|
|
- PCT_FLOAT32, 3,
|
|
|
- /* rbits, gbits, bbits, abits */
|
|
|
- 32, 32, 32, 0,
|
|
|
- /* Masks and shifts */
|
|
|
- 0, 0, 0, 0, 0, 0, 0, 0
|
|
|
- },
|
|
|
+ { "PF_FLOAT32_RGB",
|
|
|
+ /* Bytes per element */
|
|
|
+ 12,
|
|
|
+ /* Flags */
|
|
|
+ PFF_FLOAT,
|
|
|
+ /* Component type and count */
|
|
|
+ PCT_FLOAT32, 3,
|
|
|
+ /* rbits, gbits, bbits, abits */
|
|
|
+ 32, 32, 32, 0,
|
|
|
+ /* Masks and shifts */
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 0
|
|
|
+ },
|
|
|
//-----------------------------------------------------------------------
|
|
|
- {"PF_FLOAT32_RGBA",
|
|
|
- /* Bytes per element */
|
|
|
- 16,
|
|
|
- /* Flags */
|
|
|
- PFF_FLOAT | PFF_HASALPHA,
|
|
|
- /* Component type and count */
|
|
|
- PCT_FLOAT32, 4,
|
|
|
- /* rbits, gbits, bbits, abits */
|
|
|
- 32, 32, 32, 32,
|
|
|
- /* Masks and shifts */
|
|
|
- 0, 0, 0, 0, 0, 0, 0, 0
|
|
|
- },
|
|
|
+ { "PF_FLOAT32_RGBA",
|
|
|
+ /* Bytes per element */
|
|
|
+ 16,
|
|
|
+ /* Flags */
|
|
|
+ PFF_FLOAT | PFF_HASALPHA,
|
|
|
+ /* Component type and count */
|
|
|
+ PCT_FLOAT32, 4,
|
|
|
+ /* rbits, gbits, bbits, abits */
|
|
|
+ 32, 32, 32, 32,
|
|
|
+ /* Masks and shifts */
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 0
|
|
|
+ },
|
|
|
//-----------------------------------------------------------------------
|
|
|
{"PF_D32_S8X24",
|
|
|
/* Bytes per element */
|
|
|
@@ -746,15 +746,15 @@ namespace bs
|
|
|
0x000003FF, 0x000FFC00, 0x3FF00000, 0xC0000000,
|
|
|
0, 10, 20, 30
|
|
|
},
|
|
|
- };
|
|
|
+ };
|
|
|
|
|
|
- static inline const PixelFormatDescription &getDescriptionFor(const PixelFormat fmt)
|
|
|
- {
|
|
|
- const int ord = (int)fmt;
|
|
|
- assert(ord>=0 && ord<PF_COUNT);
|
|
|
+ static inline const PixelFormatDescription &getDescriptionFor(const PixelFormat fmt)
|
|
|
+ {
|
|
|
+ const int ord = (int)fmt;
|
|
|
+ assert(ord >= 0 && ord < PF_COUNT);
|
|
|
|
|
|
- return _pixelFormats[ord];
|
|
|
- }
|
|
|
+ return _pixelFormats[ord];
|
|
|
+ }
|
|
|
|
|
|
/** Handles compression output from NVTT library for a single image. */
|
|
|
struct NVTTCompressOutputHandler : public nvtt::OutputHandler
|
|
|
@@ -895,10 +895,10 @@ namespace bs
|
|
|
return nvtt::WrapMode_Mirror;
|
|
|
}
|
|
|
|
|
|
- UINT32 PixelUtil::getNumElemBytes(PixelFormat format)
|
|
|
- {
|
|
|
- return getDescriptionFor(format).elemBytes;
|
|
|
- }
|
|
|
+ UINT32 PixelUtil::getNumElemBytes(PixelFormat format)
|
|
|
+ {
|
|
|
+ return getDescriptionFor(format).elemBytes;
|
|
|
+ }
|
|
|
|
|
|
UINT32 PixelUtil::getMemorySize(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format)
|
|
|
{
|
|
|
@@ -974,40 +974,40 @@ namespace bs
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- UINT32 PixelUtil::getNumElemBits(PixelFormat format)
|
|
|
- {
|
|
|
- return getDescriptionFor(format).elemBytes * 8;
|
|
|
- }
|
|
|
-
|
|
|
- UINT32 PixelUtil::getFlags(PixelFormat format)
|
|
|
- {
|
|
|
- return getDescriptionFor(format).flags;
|
|
|
- }
|
|
|
-
|
|
|
- bool PixelUtil::hasAlpha(PixelFormat format)
|
|
|
- {
|
|
|
- return (PixelUtil::getFlags(format) & PFF_HASALPHA) > 0;
|
|
|
- }
|
|
|
-
|
|
|
- bool PixelUtil::isFloatingPoint(PixelFormat format)
|
|
|
- {
|
|
|
- return (PixelUtil::getFlags(format) & PFF_FLOAT) > 0;
|
|
|
- }
|
|
|
-
|
|
|
- bool PixelUtil::isCompressed(PixelFormat format)
|
|
|
- {
|
|
|
- return (PixelUtil::getFlags(format) & PFF_COMPRESSED) > 0;
|
|
|
- }
|
|
|
-
|
|
|
- bool PixelUtil::isDepth(PixelFormat format)
|
|
|
- {
|
|
|
- return (PixelUtil::getFlags(format) & PFF_DEPTH) > 0;
|
|
|
- }
|
|
|
-
|
|
|
- bool PixelUtil::isNativeEndian(PixelFormat format)
|
|
|
- {
|
|
|
- return (PixelUtil::getFlags(format) & PFF_NATIVEENDIAN) > 0;
|
|
|
- }
|
|
|
+ UINT32 PixelUtil::getNumElemBits(PixelFormat format)
|
|
|
+ {
|
|
|
+ return getDescriptionFor(format).elemBytes * 8;
|
|
|
+ }
|
|
|
+
|
|
|
+ UINT32 PixelUtil::getFlags(PixelFormat format)
|
|
|
+ {
|
|
|
+ return getDescriptionFor(format).flags;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool PixelUtil::hasAlpha(PixelFormat format)
|
|
|
+ {
|
|
|
+ return (PixelUtil::getFlags(format) & PFF_HASALPHA) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool PixelUtil::isFloatingPoint(PixelFormat format)
|
|
|
+ {
|
|
|
+ return (PixelUtil::getFlags(format) & PFF_FLOAT) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool PixelUtil::isCompressed(PixelFormat format)
|
|
|
+ {
|
|
|
+ return (PixelUtil::getFlags(format) & PFF_COMPRESSED) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool PixelUtil::isDepth(PixelFormat format)
|
|
|
+ {
|
|
|
+ return (PixelUtil::getFlags(format) & PFF_DEPTH) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool PixelUtil::isNativeEndian(PixelFormat format)
|
|
|
+ {
|
|
|
+ return (PixelUtil::getFlags(format) & PFF_NATIVEENDIAN) > 0;
|
|
|
+ }
|
|
|
|
|
|
bool PixelUtil::checkFormat(PixelFormat& format, TextureType texType, int usage)
|
|
|
{
|
|
|
@@ -1101,25 +1101,25 @@ namespace bs
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void PixelUtil::getBitDepths(PixelFormat format, int (&rgba)[4])
|
|
|
- {
|
|
|
- const PixelFormatDescription& des = getDescriptionFor(format);
|
|
|
- rgba[0] = des.rbits;
|
|
|
- rgba[1] = des.gbits;
|
|
|
- rgba[2] = des.bbits;
|
|
|
- rgba[3] = des.abits;
|
|
|
- }
|
|
|
-
|
|
|
- void PixelUtil::getBitMasks(PixelFormat format, UINT32 (&rgba)[4])
|
|
|
- {
|
|
|
- const PixelFormatDescription& des = getDescriptionFor(format);
|
|
|
- rgba[0] = des.rmask;
|
|
|
- rgba[1] = des.gmask;
|
|
|
- rgba[2] = des.bmask;
|
|
|
- rgba[3] = des.amask;
|
|
|
- }
|
|
|
-
|
|
|
- void PixelUtil::getBitShifts(PixelFormat format, UINT8 (&rgba)[4])
|
|
|
+ void PixelUtil::getBitDepths(PixelFormat format, int(&rgba)[4])
|
|
|
+ {
|
|
|
+ const PixelFormatDescription& des = getDescriptionFor(format);
|
|
|
+ rgba[0] = des.rbits;
|
|
|
+ rgba[1] = des.gbits;
|
|
|
+ rgba[2] = des.bbits;
|
|
|
+ rgba[3] = des.abits;
|
|
|
+ }
|
|
|
+
|
|
|
+ void PixelUtil::getBitMasks(PixelFormat format, UINT32(&rgba)[4])
|
|
|
+ {
|
|
|
+ const PixelFormatDescription& des = getDescriptionFor(format);
|
|
|
+ rgba[0] = des.rmask;
|
|
|
+ rgba[1] = des.gmask;
|
|
|
+ rgba[2] = des.bmask;
|
|
|
+ rgba[3] = des.amask;
|
|
|
+ }
|
|
|
+
|
|
|
+ void PixelUtil::getBitShifts(PixelFormat format, UINT8(&rgba)[4])
|
|
|
{
|
|
|
const PixelFormatDescription& des = getDescriptionFor(format);
|
|
|
rgba[0] = des.rshift;
|
|
|
@@ -1128,262 +1128,262 @@ namespace bs
|
|
|
rgba[3] = des.ashift;
|
|
|
}
|
|
|
|
|
|
- String PixelUtil::getFormatName(PixelFormat srcformat)
|
|
|
- {
|
|
|
- return getDescriptionFor(srcformat).name;
|
|
|
- }
|
|
|
+ String PixelUtil::getFormatName(PixelFormat srcformat)
|
|
|
+ {
|
|
|
+ return getDescriptionFor(srcformat).name;
|
|
|
+ }
|
|
|
|
|
|
- bool PixelUtil::isAccessible(PixelFormat srcformat)
|
|
|
- {
|
|
|
- if (srcformat == PF_UNKNOWN)
|
|
|
- return false;
|
|
|
+ bool PixelUtil::isAccessible(PixelFormat srcformat)
|
|
|
+ {
|
|
|
+ if (srcformat == PF_UNKNOWN)
|
|
|
+ return false;
|
|
|
|
|
|
- UINT32 flags = getFlags(srcformat);
|
|
|
- return !((flags & PFF_COMPRESSED) || (flags & PFF_DEPTH));
|
|
|
- }
|
|
|
+ UINT32 flags = getFlags(srcformat);
|
|
|
+ return !((flags & PFF_COMPRESSED) || (flags & PFF_DEPTH));
|
|
|
+ }
|
|
|
|
|
|
- PixelComponentType PixelUtil::getElementType(PixelFormat format)
|
|
|
- {
|
|
|
+ PixelComponentType PixelUtil::getElementType(PixelFormat format)
|
|
|
+ {
|
|
|
const PixelFormatDescription& des = getDescriptionFor(format);
|
|
|
- return des.componentType;
|
|
|
- }
|
|
|
+ return des.componentType;
|
|
|
+ }
|
|
|
|
|
|
UINT32 PixelUtil::getNumElements(PixelFormat format)
|
|
|
- {
|
|
|
+ {
|
|
|
const PixelFormatDescription& des = getDescriptionFor(format);
|
|
|
- return des.componentCount;
|
|
|
- }
|
|
|
+ return des.componentCount;
|
|
|
+ }
|
|
|
|
|
|
UINT32 PixelUtil::getMaxMipmaps(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format)
|
|
|
{
|
|
|
UINT32 count = 0;
|
|
|
- if((width > 0) && (height > 0))
|
|
|
- {
|
|
|
+ if ((width > 0) && (height > 0))
|
|
|
+ {
|
|
|
while (!(width == 1 && height == 1 && depth == 1))
|
|
|
- {
|
|
|
- if(width>1) width = width/2;
|
|
|
- if(height>1) height = height/2;
|
|
|
- if(depth>1) depth = depth/2;
|
|
|
-
|
|
|
- count ++;
|
|
|
- }
|
|
|
- }
|
|
|
+ {
|
|
|
+ if (width > 1) width = width / 2;
|
|
|
+ if (height > 1) height = height / 2;
|
|
|
+ if (depth > 1) depth = depth / 2;
|
|
|
+
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
- void PixelUtil::packColor(const Color& color, PixelFormat format, void* dest)
|
|
|
- {
|
|
|
- packColor(color.r, color.g, color.b, color.a, format, dest);
|
|
|
- }
|
|
|
+ void PixelUtil::packColor(const Color& color, PixelFormat format, void* dest)
|
|
|
+ {
|
|
|
+ packColor(color.r, color.g, color.b, color.a, format, dest);
|
|
|
+ }
|
|
|
|
|
|
- void PixelUtil::packColor(UINT8 r, UINT8 g, UINT8 b, UINT8 a, PixelFormat format, void* dest)
|
|
|
- {
|
|
|
- const PixelFormatDescription &des = getDescriptionFor(format);
|
|
|
+ void PixelUtil::packColor(UINT8 r, UINT8 g, UINT8 b, UINT8 a, PixelFormat format, void* dest)
|
|
|
+ {
|
|
|
+ const PixelFormatDescription &des = getDescriptionFor(format);
|
|
|
|
|
|
- if(des.flags & PFF_NATIVEENDIAN)
|
|
|
+ if (des.flags & PFF_NATIVEENDIAN)
|
|
|
{
|
|
|
- // Shortcut for integer formats packing
|
|
|
- UINT32 value = ((Bitwise::fixedToFixed(r, 8, des.rbits)<<des.rshift) & des.rmask) |
|
|
|
- ((Bitwise::fixedToFixed(g, 8, des.gbits)<<des.gshift) & des.gmask) |
|
|
|
- ((Bitwise::fixedToFixed(b, 8, des.bbits)<<des.bshift) & des.bmask) |
|
|
|
- ((Bitwise::fixedToFixed(a, 8, des.abits)<<des.ashift) & des.amask);
|
|
|
-
|
|
|
- // And write to memory
|
|
|
- Bitwise::intWrite(dest, des.elemBytes, value);
|
|
|
- }
|
|
|
- else
|
|
|
+ // Shortcut for integer formats packing
|
|
|
+ UINT32 value = ((Bitwise::fixedToFixed(r, 8, des.rbits) << des.rshift) & des.rmask) |
|
|
|
+ ((Bitwise::fixedToFixed(g, 8, des.gbits) << des.gshift) & des.gmask) |
|
|
|
+ ((Bitwise::fixedToFixed(b, 8, des.bbits) << des.bshift) & des.bmask) |
|
|
|
+ ((Bitwise::fixedToFixed(a, 8, des.abits) << des.ashift) & des.amask);
|
|
|
+
|
|
|
+ // And write to memory
|
|
|
+ Bitwise::intWrite(dest, des.elemBytes, value);
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- // Convert to float
|
|
|
- packColor((float)r/255.0f,(float)g/255.0f,(float)b/255.0f,(float)a/255.0f, format, dest);
|
|
|
- }
|
|
|
- }
|
|
|
+ // Convert to float
|
|
|
+ packColor((float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, (float)a / 255.0f, format, dest);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- void PixelUtil::packColor(float r, float g, float b, float a, const PixelFormat format, void* dest)
|
|
|
- {
|
|
|
- const PixelFormatDescription& des = getDescriptionFor(format);
|
|
|
+ void PixelUtil::packColor(float r, float g, float b, float a, const PixelFormat format, void* dest)
|
|
|
+ {
|
|
|
+ const PixelFormatDescription& des = getDescriptionFor(format);
|
|
|
|
|
|
- if(des.flags & PFF_NATIVEENDIAN)
|
|
|
+ if (des.flags & PFF_NATIVEENDIAN)
|
|
|
{
|
|
|
- // Do the packing
|
|
|
- const unsigned int value = ((Bitwise::floatToFixed(r, des.rbits)<<des.rshift) & des.rmask) |
|
|
|
- ((Bitwise::floatToFixed(g, des.gbits)<<des.gshift) & des.gmask) |
|
|
|
- ((Bitwise::floatToFixed(b, des.bbits)<<des.bshift) & des.bmask) |
|
|
|
- ((Bitwise::floatToFixed(a, des.abits)<<des.ashift) & des.amask);
|
|
|
-
|
|
|
- // And write to memory
|
|
|
- Bitwise::intWrite(dest, des.elemBytes, value);
|
|
|
- }
|
|
|
- else
|
|
|
+ // Do the packing
|
|
|
+ const unsigned int value = ((Bitwise::floatToFixed(r, des.rbits) << des.rshift) & des.rmask) |
|
|
|
+ ((Bitwise::floatToFixed(g, des.gbits) << des.gshift) & des.gmask) |
|
|
|
+ ((Bitwise::floatToFixed(b, des.bbits) << des.bshift) & des.bmask) |
|
|
|
+ ((Bitwise::floatToFixed(a, des.abits) << des.ashift) & des.amask);
|
|
|
+
|
|
|
+ // And write to memory
|
|
|
+ Bitwise::intWrite(dest, des.elemBytes, value);
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- switch(format)
|
|
|
- {
|
|
|
- case PF_FLOAT32_R:
|
|
|
- ((float*)dest)[0] = r;
|
|
|
- break;
|
|
|
+ switch (format)
|
|
|
+ {
|
|
|
+ case PF_FLOAT32_R:
|
|
|
+ ((float*)dest)[0] = r;
|
|
|
+ break;
|
|
|
case PF_FLOAT32_RG:
|
|
|
((float*)dest)[0] = r;
|
|
|
((float*)dest)[1] = g;
|
|
|
break;
|
|
|
- case PF_FLOAT32_RGB:
|
|
|
- ((float*)dest)[0] = r;
|
|
|
- ((float*)dest)[1] = g;
|
|
|
- ((float*)dest)[2] = b;
|
|
|
- break;
|
|
|
- case PF_FLOAT32_RGBA:
|
|
|
- ((float*)dest)[0] = r;
|
|
|
- ((float*)dest)[1] = g;
|
|
|
- ((float*)dest)[2] = b;
|
|
|
- ((float*)dest)[3] = a;
|
|
|
- break;
|
|
|
- case PF_FLOAT16_R:
|
|
|
- ((UINT16*)dest)[0] = Bitwise::floatToHalf(r);
|
|
|
- break;
|
|
|
+ case PF_FLOAT32_RGB:
|
|
|
+ ((float*)dest)[0] = r;
|
|
|
+ ((float*)dest)[1] = g;
|
|
|
+ ((float*)dest)[2] = b;
|
|
|
+ break;
|
|
|
+ case PF_FLOAT32_RGBA:
|
|
|
+ ((float*)dest)[0] = r;
|
|
|
+ ((float*)dest)[1] = g;
|
|
|
+ ((float*)dest)[2] = b;
|
|
|
+ ((float*)dest)[3] = a;
|
|
|
+ break;
|
|
|
+ case PF_FLOAT16_R:
|
|
|
+ ((UINT16*)dest)[0] = Bitwise::floatToHalf(r);
|
|
|
+ break;
|
|
|
case PF_FLOAT16_RG:
|
|
|
((UINT16*)dest)[0] = Bitwise::floatToHalf(r);
|
|
|
((UINT16*)dest)[1] = Bitwise::floatToHalf(g);
|
|
|
break;
|
|
|
- case PF_FLOAT16_RGB:
|
|
|
- ((UINT16*)dest)[0] = Bitwise::floatToHalf(r);
|
|
|
- ((UINT16*)dest)[1] = Bitwise::floatToHalf(g);
|
|
|
- ((UINT16*)dest)[2] = Bitwise::floatToHalf(b);
|
|
|
- break;
|
|
|
- case PF_FLOAT16_RGBA:
|
|
|
- ((UINT16*)dest)[0] = Bitwise::floatToHalf(r);
|
|
|
- ((UINT16*)dest)[1] = Bitwise::floatToHalf(g);
|
|
|
- ((UINT16*)dest)[2] = Bitwise::floatToHalf(b);
|
|
|
- ((UINT16*)dest)[3] = Bitwise::floatToHalf(a);
|
|
|
- break;
|
|
|
+ case PF_FLOAT16_RGB:
|
|
|
+ ((UINT16*)dest)[0] = Bitwise::floatToHalf(r);
|
|
|
+ ((UINT16*)dest)[1] = Bitwise::floatToHalf(g);
|
|
|
+ ((UINT16*)dest)[2] = Bitwise::floatToHalf(b);
|
|
|
+ break;
|
|
|
+ case PF_FLOAT16_RGBA:
|
|
|
+ ((UINT16*)dest)[0] = Bitwise::floatToHalf(r);
|
|
|
+ ((UINT16*)dest)[1] = Bitwise::floatToHalf(g);
|
|
|
+ ((UINT16*)dest)[2] = Bitwise::floatToHalf(b);
|
|
|
+ ((UINT16*)dest)[3] = Bitwise::floatToHalf(a);
|
|
|
+ break;
|
|
|
case PF_R8G8:
|
|
|
((UINT8*)dest)[0] = (UINT8)Bitwise::floatToFixed(r, 8);
|
|
|
- ((UINT8*)dest)[1] = (UINT8)Bitwise::floatToFixed(g, 8);
|
|
|
+ ((UINT8*)dest)[1] = (UINT8)Bitwise::floatToFixed(g, 8);
|
|
|
break;
|
|
|
case PF_R8:
|
|
|
((UINT8*)dest)[0] = (UINT8)Bitwise::floatToFixed(r, 8);
|
|
|
break;
|
|
|
case PF_FLOAT_R11G11B10:
|
|
|
- {
|
|
|
- UINT32 value;
|
|
|
- value = Bitwise::floatToFloat11(r);
|
|
|
- value |= Bitwise::floatToFloat11(g) << 11;
|
|
|
- value |= Bitwise::floatToFloat10(b) << 22;
|
|
|
+ {
|
|
|
+ UINT32 value;
|
|
|
+ value = Bitwise::floatToFloat11(r);
|
|
|
+ value |= Bitwise::floatToFloat11(g) << 11;
|
|
|
+ value |= Bitwise::floatToFloat10(b) << 22;
|
|
|
|
|
|
- ((UINT32*)dest)[0] = value;
|
|
|
- }
|
|
|
+ ((UINT32*)dest)[0] = value;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ LOGERR("Pack to " + getFormatName(format) + " not implemented");
|
|
|
break;
|
|
|
- default:
|
|
|
- LOGERR("Pack to " + getFormatName(format) + " not implemented");
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- void PixelUtil::unpackColor(Color* color, PixelFormat format, const void* src)
|
|
|
- {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ void PixelUtil::unpackColor(Color* color, PixelFormat format, const void* src)
|
|
|
+ {
|
|
|
unpackColor(&color->r, &color->g, &color->b, &color->a, format, src);
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- void PixelUtil::unpackColor(UINT8* r, UINT8* g, UINT8* b, UINT8* a, PixelFormat format, const void* src)
|
|
|
- {
|
|
|
- const PixelFormatDescription &des = getDescriptionFor(format);
|
|
|
+ void PixelUtil::unpackColor(UINT8* r, UINT8* g, UINT8* b, UINT8* a, PixelFormat format, const void* src)
|
|
|
+ {
|
|
|
+ const PixelFormatDescription &des = getDescriptionFor(format);
|
|
|
|
|
|
- if(des.flags & PFF_NATIVEENDIAN)
|
|
|
+ if (des.flags & PFF_NATIVEENDIAN)
|
|
|
{
|
|
|
- // Shortcut for integer formats unpacking
|
|
|
- const UINT32 value = Bitwise::intRead(src, des.elemBytes);
|
|
|
-
|
|
|
- *r = (UINT8)Bitwise::fixedToFixed((value & des.rmask)>>des.rshift, des.rbits, 8);
|
|
|
- *g = (UINT8)Bitwise::fixedToFixed((value & des.gmask)>>des.gshift, des.gbits, 8);
|
|
|
- *b = (UINT8)Bitwise::fixedToFixed((value & des.bmask)>>des.bshift, des.bbits, 8);
|
|
|
-
|
|
|
- if(des.flags & PFF_HASALPHA)
|
|
|
- {
|
|
|
- *a = (UINT8)Bitwise::fixedToFixed((value & des.amask)>>des.ashift, des.abits, 8);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- *a = 255; // No alpha, default a component to full
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
+ // Shortcut for integer formats unpacking
|
|
|
+ const UINT32 value = Bitwise::intRead(src, des.elemBytes);
|
|
|
+
|
|
|
+ *r = (UINT8)Bitwise::fixedToFixed((value & des.rmask) >> des.rshift, des.rbits, 8);
|
|
|
+ *g = (UINT8)Bitwise::fixedToFixed((value & des.gmask) >> des.gshift, des.gbits, 8);
|
|
|
+ *b = (UINT8)Bitwise::fixedToFixed((value & des.bmask) >> des.bshift, des.bbits, 8);
|
|
|
+
|
|
|
+ if (des.flags & PFF_HASALPHA)
|
|
|
+ {
|
|
|
+ *a = (UINT8)Bitwise::fixedToFixed((value & des.amask) >> des.ashift, des.abits, 8);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ *a = 255; // No alpha, default a component to full
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- // Do the operation with the more generic floating point
|
|
|
- float rr, gg, bb, aa;
|
|
|
- unpackColor(&rr,&gg,&bb,&aa, format, src);
|
|
|
-
|
|
|
- *r = (UINT8)Bitwise::floatToFixed(rr, 8);
|
|
|
- *g = (UINT8)Bitwise::floatToFixed(gg, 8);
|
|
|
- *b = (UINT8)Bitwise::floatToFixed(bb, 8);
|
|
|
- *a = (UINT8)Bitwise::floatToFixed(aa, 8);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- void PixelUtil::unpackColor(float* r, float* g, float* b, float* a, PixelFormat format, const void* src)
|
|
|
- {
|
|
|
- const PixelFormatDescription &des = getDescriptionFor(format);
|
|
|
- if(des.flags & PFF_NATIVEENDIAN)
|
|
|
+ // Do the operation with the more generic floating point
|
|
|
+ float rr, gg, bb, aa;
|
|
|
+ unpackColor(&rr, &gg, &bb, &aa, format, src);
|
|
|
+
|
|
|
+ *r = (UINT8)Bitwise::floatToFixed(rr, 8);
|
|
|
+ *g = (UINT8)Bitwise::floatToFixed(gg, 8);
|
|
|
+ *b = (UINT8)Bitwise::floatToFixed(bb, 8);
|
|
|
+ *a = (UINT8)Bitwise::floatToFixed(aa, 8);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void PixelUtil::unpackColor(float* r, float* g, float* b, float* a, PixelFormat format, const void* src)
|
|
|
+ {
|
|
|
+ const PixelFormatDescription &des = getDescriptionFor(format);
|
|
|
+ if (des.flags & PFF_NATIVEENDIAN)
|
|
|
{
|
|
|
- // Shortcut for integer formats unpacking
|
|
|
- const unsigned int value = Bitwise::intRead(src, des.elemBytes);
|
|
|
-
|
|
|
- *r = Bitwise::fixedToFloat((value & des.rmask)>>des.rshift, des.rbits);
|
|
|
- *g = Bitwise::fixedToFloat((value & des.gmask)>>des.gshift, des.gbits);
|
|
|
- *b = Bitwise::fixedToFloat((value & des.bmask)>>des.bshift, des.bbits);
|
|
|
-
|
|
|
- if(des.flags & PFF_HASALPHA)
|
|
|
- {
|
|
|
- *a = Bitwise::fixedToFloat((value & des.amask)>>des.ashift, des.abits);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- *a = 1.0f; // No alpha, default a component to full
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
+ // Shortcut for integer formats unpacking
|
|
|
+ const unsigned int value = Bitwise::intRead(src, des.elemBytes);
|
|
|
+
|
|
|
+ *r = Bitwise::fixedToFloat((value & des.rmask) >> des.rshift, des.rbits);
|
|
|
+ *g = Bitwise::fixedToFloat((value & des.gmask) >> des.gshift, des.gbits);
|
|
|
+ *b = Bitwise::fixedToFloat((value & des.bmask) >> des.bshift, des.bbits);
|
|
|
+
|
|
|
+ if (des.flags & PFF_HASALPHA)
|
|
|
+ {
|
|
|
+ *a = Bitwise::fixedToFloat((value & des.amask) >> des.ashift, des.abits);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ *a = 1.0f; // No alpha, default a component to full
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- switch(format)
|
|
|
- {
|
|
|
- case PF_FLOAT32_R:
|
|
|
- *r = *g = *b = ((float*)src)[0];
|
|
|
- *a = 1.0f;
|
|
|
- break;
|
|
|
+ switch (format)
|
|
|
+ {
|
|
|
+ case PF_FLOAT32_R:
|
|
|
+ *r = *g = *b = ((float*)src)[0];
|
|
|
+ *a = 1.0f;
|
|
|
+ break;
|
|
|
case PF_FLOAT32_RG:
|
|
|
*r = ((float*)src)[0];
|
|
|
*g = *b = ((float*)src)[1];
|
|
|
*a = 1.0f;
|
|
|
break;
|
|
|
- case PF_FLOAT32_RGB:
|
|
|
- *r = ((float*)src)[0];
|
|
|
- *g = ((float*)src)[1];
|
|
|
- *b = ((float*)src)[2];
|
|
|
- *a = 1.0f;
|
|
|
- break;
|
|
|
- case PF_FLOAT32_RGBA:
|
|
|
- *r = ((float*)src)[0];
|
|
|
- *g = ((float*)src)[1];
|
|
|
- *b = ((float*)src)[2];
|
|
|
- *a = ((float*)src)[3];
|
|
|
- break;
|
|
|
- case PF_FLOAT16_R:
|
|
|
- *r = *g = *b = Bitwise::halfToFloat(((UINT16*)src)[0]);
|
|
|
- *a = 1.0f;
|
|
|
- break;
|
|
|
+ case PF_FLOAT32_RGB:
|
|
|
+ *r = ((float*)src)[0];
|
|
|
+ *g = ((float*)src)[1];
|
|
|
+ *b = ((float*)src)[2];
|
|
|
+ *a = 1.0f;
|
|
|
+ break;
|
|
|
+ case PF_FLOAT32_RGBA:
|
|
|
+ *r = ((float*)src)[0];
|
|
|
+ *g = ((float*)src)[1];
|
|
|
+ *b = ((float*)src)[2];
|
|
|
+ *a = ((float*)src)[3];
|
|
|
+ break;
|
|
|
+ case PF_FLOAT16_R:
|
|
|
+ *r = *g = *b = Bitwise::halfToFloat(((UINT16*)src)[0]);
|
|
|
+ *a = 1.0f;
|
|
|
+ break;
|
|
|
case PF_FLOAT16_RG:
|
|
|
*r = Bitwise::halfToFloat(((UINT16*)src)[0]);
|
|
|
*g = *b = Bitwise::halfToFloat(((UINT16*)src)[1]);
|
|
|
*a = 1.0f;
|
|
|
break;
|
|
|
- case PF_FLOAT16_RGB:
|
|
|
- *r = Bitwise::halfToFloat(((UINT16*)src)[0]);
|
|
|
- *g = Bitwise::halfToFloat(((UINT16*)src)[1]);
|
|
|
- *b = Bitwise::halfToFloat(((UINT16*)src)[2]);
|
|
|
- *a = 1.0f;
|
|
|
- break;
|
|
|
- case PF_FLOAT16_RGBA:
|
|
|
- *r = Bitwise::halfToFloat(((UINT16*)src)[0]);
|
|
|
- *g = Bitwise::halfToFloat(((UINT16*)src)[1]);
|
|
|
- *b = Bitwise::halfToFloat(((UINT16*)src)[2]);
|
|
|
- *a = Bitwise::halfToFloat(((UINT16*)src)[3]);
|
|
|
- break;
|
|
|
+ case PF_FLOAT16_RGB:
|
|
|
+ *r = Bitwise::halfToFloat(((UINT16*)src)[0]);
|
|
|
+ *g = Bitwise::halfToFloat(((UINT16*)src)[1]);
|
|
|
+ *b = Bitwise::halfToFloat(((UINT16*)src)[2]);
|
|
|
+ *a = 1.0f;
|
|
|
+ break;
|
|
|
+ case PF_FLOAT16_RGBA:
|
|
|
+ *r = Bitwise::halfToFloat(((UINT16*)src)[0]);
|
|
|
+ *g = Bitwise::halfToFloat(((UINT16*)src)[1]);
|
|
|
+ *b = Bitwise::halfToFloat(((UINT16*)src)[2]);
|
|
|
+ *a = Bitwise::halfToFloat(((UINT16*)src)[3]);
|
|
|
+ break;
|
|
|
case PF_R8G8:
|
|
|
*r = Bitwise::fixedToFloat(((UINT8*)src)[0], 8);
|
|
|
*g = Bitwise::fixedToFloat(((UINT8*)src)[1], 8);
|
|
|
@@ -1404,12 +1404,12 @@ namespace bs
|
|
|
*b = Bitwise::float10ToFloat(value >> 22);
|
|
|
}
|
|
|
break;
|
|
|
- default:
|
|
|
- LOGERR("Unpack from " + getFormatName(format) + " not implemented");
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ default:
|
|
|
+ LOGERR("Unpack from " + getFormatName(format) + " not implemented");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
void PixelUtil::packDepth(float depth, const PixelFormat format, void* dest)
|
|
|
{
|
|
|
@@ -1455,16 +1455,16 @@ namespace bs
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void PixelUtil::bulkPixelConversion(const PixelData &src, PixelData &dst)
|
|
|
- {
|
|
|
- assert(src.getWidth() == dst.getWidth() &&
|
|
|
- src.getHeight() == dst.getHeight() &&
|
|
|
- src.getDepth() == dst.getDepth());
|
|
|
+ void PixelUtil::bulkPixelConversion(const PixelData &src, PixelData &dst)
|
|
|
+ {
|
|
|
+ assert(src.getWidth() == dst.getWidth() &&
|
|
|
+ src.getHeight() == dst.getHeight() &&
|
|
|
+ src.getDepth() == dst.getDepth());
|
|
|
|
|
|
// Check for compressed formats, we don't support decompression
|
|
|
- if(PixelUtil::isCompressed(src.getFormat()))
|
|
|
+ if (PixelUtil::isCompressed(src.getFormat()))
|
|
|
{
|
|
|
- if(src.getFormat() == dst.getFormat())
|
|
|
+ if (src.getFormat() == dst.getFormat())
|
|
|
{
|
|
|
memcpy(dst.getData(), src.getData(), src.getConsecutiveSize());
|
|
|
return;
|
|
|
@@ -1494,85 +1494,85 @@ namespace bs
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // The easy case
|
|
|
- if(src.getFormat() == dst.getFormat())
|
|
|
+ // The easy case
|
|
|
+ if (src.getFormat() == dst.getFormat())
|
|
|
{
|
|
|
- // Everything consecutive?
|
|
|
- if(src.isConsecutive() && dst.isConsecutive())
|
|
|
- {
|
|
|
+ // Everything consecutive?
|
|
|
+ if (src.isConsecutive() && dst.isConsecutive())
|
|
|
+ {
|
|
|
memcpy(dst.getData(), src.getData(), src.getConsecutiveSize());
|
|
|
- return;
|
|
|
- }
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
const UINT32 srcPixelSize = PixelUtil::getNumElemBytes(src.getFormat());
|
|
|
const UINT32 dstPixelSize = PixelUtil::getNumElemBytes(dst.getFormat());
|
|
|
- UINT8 *srcptr = static_cast<UINT8*>(src.getData())
|
|
|
- + (src.getLeft() + src.getTop() * src.getRowPitch() + src.getFront() * src.getSlicePitch()) * srcPixelSize;
|
|
|
- UINT8 *dstptr = static_cast<UINT8*>(dst.getData())
|
|
|
+ UINT8 *srcptr = static_cast<UINT8*>(src.getData())
|
|
|
+ + (src.getLeft() + src.getTop() * src.getRowPitch() + src.getFront() * src.getSlicePitch()) * srcPixelSize;
|
|
|
+ UINT8 *dstptr = static_cast<UINT8*>(dst.getData())
|
|
|
+ (dst.getLeft() + dst.getTop() * dst.getRowPitch() + dst.getFront() * dst.getSlicePitch()) * dstPixelSize;
|
|
|
|
|
|
- // Calculate pitches+skips in bytes
|
|
|
+ // Calculate pitches+skips in bytes
|
|
|
const UINT32 srcRowPitchBytes = src.getRowPitch()*srcPixelSize;
|
|
|
const UINT32 srcSliceSkipBytes = src.getSliceSkip()*srcPixelSize;
|
|
|
|
|
|
const UINT32 dstRowPitchBytes = dst.getRowPitch()*dstPixelSize;
|
|
|
const UINT32 dstSliceSkipBytes = dst.getSliceSkip()*dstPixelSize;
|
|
|
|
|
|
- // Otherwise, copy per row
|
|
|
+ // Otherwise, copy per row
|
|
|
const UINT32 rowSize = src.getWidth()*srcPixelSize;
|
|
|
for (UINT32 z = src.getFront(); z < src.getBack(); z++)
|
|
|
- {
|
|
|
- for(UINT32 y = src.getTop(); y < src.getBottom(); y++)
|
|
|
- {
|
|
|
+ {
|
|
|
+ for (UINT32 y = src.getTop(); y < src.getBottom(); y++)
|
|
|
+ {
|
|
|
memcpy(dstptr, srcptr, rowSize);
|
|
|
|
|
|
- srcptr += srcRowPitchBytes;
|
|
|
- dstptr += dstRowPitchBytes;
|
|
|
- }
|
|
|
+ srcptr += srcRowPitchBytes;
|
|
|
+ dstptr += dstRowPitchBytes;
|
|
|
+ }
|
|
|
|
|
|
- srcptr += srcSliceSkipBytes;
|
|
|
- dstptr += dstSliceSkipBytes;
|
|
|
- }
|
|
|
+ srcptr += srcSliceSkipBytes;
|
|
|
+ dstptr += dstSliceSkipBytes;
|
|
|
+ }
|
|
|
|
|
|
- return;
|
|
|
- }
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
UINT32 srcPixelSize = PixelUtil::getNumElemBytes(src.getFormat());
|
|
|
UINT32 dstPixelSize = PixelUtil::getNumElemBytes(dst.getFormat());
|
|
|
- UINT8 *srcptr = static_cast<UINT8*>(src.getData())
|
|
|
- + (src.getLeft() + src.getTop() * src.getRowPitch() + src.getFront() * src.getSlicePitch()) * srcPixelSize;
|
|
|
- UINT8 *dstptr = static_cast<UINT8*>(dst.getData())
|
|
|
- + (dst.getLeft() + dst.getTop() * dst.getRowPitch() + dst.getFront() * dst.getSlicePitch()) * dstPixelSize;
|
|
|
-
|
|
|
- // Calculate pitches+skips in bytes
|
|
|
+ UINT8 *srcptr = static_cast<UINT8*>(src.getData())
|
|
|
+ + (src.getLeft() + src.getTop() * src.getRowPitch() + src.getFront() * src.getSlicePitch()) * srcPixelSize;
|
|
|
+ UINT8 *dstptr = static_cast<UINT8*>(dst.getData())
|
|
|
+ + (dst.getLeft() + dst.getTop() * dst.getRowPitch() + dst.getFront() * dst.getSlicePitch()) * dstPixelSize;
|
|
|
+
|
|
|
+ // Calculate pitches+skips in bytes
|
|
|
UINT32 srcRowSkipBytes = src.getRowSkip()*srcPixelSize;
|
|
|
UINT32 srcSliceSkipBytes = src.getSliceSkip()*srcPixelSize;
|
|
|
UINT32 dstRowSkipBytes = dst.getRowSkip()*dstPixelSize;
|
|
|
UINT32 dstSliceSkipBytes = dst.getSliceSkip()*dstPixelSize;
|
|
|
|
|
|
- // The brute force fallback
|
|
|
- float r,g,b,a;
|
|
|
- for (UINT32 z = src.getFront(); z<src.getBack(); z++)
|
|
|
+ // The brute force fallback
|
|
|
+ float r, g, b, a;
|
|
|
+ for (UINT32 z = src.getFront(); z < src.getBack(); z++)
|
|
|
{
|
|
|
for (UINT32 y = src.getTop(); y < src.getBottom(); y++)
|
|
|
- {
|
|
|
- for (UINT32 x = src.getLeft(); x<src.getRight(); x++)
|
|
|
- {
|
|
|
- unpackColor(&r, &g, &b, &a, src.getFormat(), srcptr);
|
|
|
- packColor(r, g, b, a, dst.getFormat(), dstptr);
|
|
|
-
|
|
|
- srcptr += srcPixelSize;
|
|
|
- dstptr += dstPixelSize;
|
|
|
- }
|
|
|
-
|
|
|
- srcptr += srcRowSkipBytes;
|
|
|
- dstptr += dstRowSkipBytes;
|
|
|
- }
|
|
|
-
|
|
|
- srcptr += srcSliceSkipBytes;
|
|
|
- dstptr += dstSliceSkipBytes;
|
|
|
- }
|
|
|
- }
|
|
|
+ {
|
|
|
+ for (UINT32 x = src.getLeft(); x < src.getRight(); x++)
|
|
|
+ {
|
|
|
+ unpackColor(&r, &g, &b, &a, src.getFormat(), srcptr);
|
|
|
+ packColor(r, g, b, a, dst.getFormat(), dstptr);
|
|
|
+
|
|
|
+ srcptr += srcPixelSize;
|
|
|
+ dstptr += dstPixelSize;
|
|
|
+ }
|
|
|
+
|
|
|
+ srcptr += srcRowSkipBytes;
|
|
|
+ dstptr += dstRowSkipBytes;
|
|
|
+ }
|
|
|
+
|
|
|
+ srcptr += srcSliceSkipBytes;
|
|
|
+ dstptr += dstSliceSkipBytes;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
void PixelUtil::flipComponentOrder(PixelData& data)
|
|
|
{
|