From 41109553ebb5c1f315a7f794a1190ba031fe65ed Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 4 Nov 2016 22:56:18 -0700 Subject: [PATCH] Saving state before merge up --- libraries/gpu/src/gpu/Image.cpp | 2 +- libraries/gpu/src/gpu/Image.h | 167 ++++++++++++++++------- libraries/model/src/model/TextureMap.cpp | 3 + 3 files changed, 118 insertions(+), 54 deletions(-) diff --git a/libraries/gpu/src/gpu/Image.cpp b/libraries/gpu/src/gpu/Image.cpp index eddc1d60d7..5de1008d8f 100644 --- a/libraries/gpu/src/gpu/Image.cpp +++ b/libraries/gpu/src/gpu/Image.cpp @@ -32,7 +32,7 @@ template <> void uncompress(const CB_BC1& src, PB_RGB32& dst) { auto r = pixel::mix( c0, c1, - (pixel::Byte)bc1.table); + (Byte)bc1.table); } } diff --git a/libraries/gpu/src/gpu/Image.h b/libraries/gpu/src/gpu/Image.h index c9969b8e15..f456240503 100644 --- a/libraries/gpu/src/gpu/Image.h +++ b/libraries/gpu/src/gpu/Image.h @@ -2,6 +2,8 @@ Let s try compressing images */ + +#include #include "Forward.h" @@ -11,6 +13,20 @@ namespace image { using Byte = uint8_t; using Byte2 = uint16_t; using Byte4 = uint32_t; + using Byte8 = uint64_t; + + // Storage type selector based on size (sizeof of a type) + template + struct storage { typedef T1 type; }; + + template + struct storage<2, T1, T2, T4, T8> { typedef T2 type; }; + + template + struct storage<4, T1, T2, T4, T8> { typedef T4 type; }; + + template + struct storage<8, T1, T2, T4, T8> { typedef T8 type; }; static const Byte BLACK8 { 0 }; static const Byte WHITE8 { 255 }; @@ -25,7 +41,6 @@ namespace image { namespace pixel { - struct RGB32 { Byte r { BLACK8 }; Byte g { BLACK8 }; @@ -40,7 +55,6 @@ namespace image { Byte a { WHITE8 }; }; - struct RGB16_565 { Byte2 b : 5; Byte2 g : 6; @@ -49,58 +63,66 @@ namespace image { RGB16_565() : b(BLACK8), g(BLACK8), r(BLACK8) {} RGB16_565(Byte pR, Byte pG, Byte pB) : b(pB), g(pG), r(pR) {} }; + + struct R8 { + Byte r { BLACK8 }; + }; + template const P mix(const P p0, const P p1, const S alpha) { return p0; } template <> const RGB16_565 mix(const RGB16_565 p0, const RGB16_565 p1, const Byte alpha); - }; - - template class Pixel { - public: - using Format = F; - using Storage = S; - - union { - Storage raw; - Format val{ Format() }; // Format last to be initialized by Format's default constructor + template ::type > class Pixel { + public: + using Format = F; + using Storage = S; + + union { + Storage raw; + Format val{ Format() }; // Format last to be initialized by Format's default constructor + }; + + Pixel() {}; + Pixel(Format v) : val(v) {} + Pixel(Storage s) : raw(s) {} }; + - Pixel() {}; - Pixel(Format v) : val(v) {} - Pixel(Storage s) : raw(s) {} + template class PixelBlock { + public: + using Format = typename P::Format; + using Storage = typename P::Storage; + + static const uint32_t WIDTH { 4 }; + static const uint32_t HEIGHT { WIDTH }; + static const uint32_t SIZE { WIDTH * HEIGHT }; + + uint32_t getSize() const { return SIZE * sizeof(P); } + + P pixels[SIZE]; + + PixelBlock() {} + + + PixelBlock(const P* srcPixels) { + setPixels(srcPixels); + } + + void setPixels(const P* srcPixels) { + memcpy(pixels, srcPixels, getSize()); + } + + const Storage* getStorage() const { return static_cast (&pixels->raw); } + }; }; - using PixRGB565 = Pixel; - using PixRGB32 = Pixel; - using PixRGBA32 = Pixel; - - - template class PixelBlock { - public: - using Format = typename P::Format; - using Storage = typename P::Storage; - static const uint32_t WIDTH { 4 }; - static const uint32_t HEIGHT { WIDTH }; - static const uint32_t SIZE { WIDTH * HEIGHT }; - - uint32_t getSize() const { return SIZE * sizeof(P); } - - P pixels[SIZE]; - - PixelBlock() {} - - - PixelBlock(const P* srcPixels) { - setPixels(srcPixels); - } - - void setPixels(const P* srcPixels) { - memcpy(pixels, srcPixels, getSize()); - } - - const Storage* getStorage() const { return static_cast (&pixels->raw); } - }; + + using PixRGB565 = pixel::Pixel; + using PixRGB32 = pixel::Pixel; + using PixRGBA32 = pixel::Pixel; + using PixR8 = pixel::Pixel; + class BC { public: @@ -109,15 +131,13 @@ namespace image { struct BC1 { PixRGB565 color0; PixRGB565 color1; - pixel::Byte4 table; - - - Byte + Byte4 table; }; + struct BC4 { PixRGB565 color0; PixRGB565 color1; - pixel::Byte4 table; + Byte4 table; }; }; @@ -125,19 +145,20 @@ namespace image { public: static const uint32_t SIZE { sizeof(T) }; union { - pixel::Byte bytes[SIZE]; + Byte bytes[SIZE]; T bc; }; CompressedBlock() {} }; + template void compress(const PB& srcBlock, CB& dstBlock) { } template void uncompress(const CB& srcBlock, PB& dstBlock) { } - using PB_RGB32 = PixelBlock; - using PB_RGBA32 = PixelBlock; + using PB_RGB32 = pixel::PixelBlock; + using PB_RGBA32 = pixel::PixelBlock; using CB_BC1 = CompressedBlock; using CB_BC4 = CompressedBlock; @@ -147,4 +168,44 @@ namespace image { template <> void uncompress(const CB_BC1& src, PB_RGB32& dst); template <> void uncompress(const CB_BC4& src, PB_RGBA32& dst); + + + template + class PixelBlockArray { + public: + using Pixel = P; + using Block = pixel::PixelBlock; + + using Blocks = std::vector; + + }; + + class Grid { + public: + using Coord = uint16_t; + using Coord2 = glm::u16vec2; + using Size = uint32_t; + + Coord2 _block { 1, 1 }; + Coord2 _surface { 1, 1 }; + + Coord width() const { return _surface.x; } + Coord height() const { return _surface.y; } + Size size() const { return width() * height(); } + + Coord blockWidth() const { return _block.x; } + Coord blockHeight() const { return _block.y; } + Size blockSize() const { return blockWidth() * blockHeight(); } + + Coord pixelWidth() const { return _surface.x * _block.x; } + Coordisd pixelHeight() const { return _surface.y * _block.y; } + Size pixelSize() const { return pixelWidth() * pixelHeight(); } + + Coord2 pixelToBlock(const Coord2& coord) const { + auto blockX = coord.x / blockWidth(); + auto blockY = coord.y / blockHeight(); + return Coord2(blockX, blockY); + } + + }; } \ No newline at end of file diff --git a/libraries/model/src/model/TextureMap.cpp b/libraries/model/src/model/TextureMap.cpp index 1cbff8bd21..1b51d16883 100755 --- a/libraries/model/src/model/TextureMap.cpp +++ b/libraries/model/src/model/TextureMap.cpp @@ -252,6 +252,8 @@ gpu::Texture* TextureUsage::process2DTextureColorFromImage(const QImage& srcImag image::PixRGBA32 pix1; + image::PixR8 pix2; + image::PixRGB565 pix3; image::PB_RGB32 pb0; @@ -260,6 +262,7 @@ gpu::Texture* TextureUsage::process2DTextureColorFromImage(const QImage& srcImag auto pix0_s = sizeof(pix0); auto pix1_s = sizeof(pix1); + auto pix2_s = sizeof(pix2); auto pix3_s = sizeof(pix3); auto pb0_s = sizeof(pb0);