From 4ac0c29d9bf09579fe7e53ea99d7bede2700ec1a Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 24 Oct 2016 09:40:34 -0700 Subject: [PATCH] Adding Image utility to GPU --- libraries/gpu/src/gpu/Image.cpp | 17 ++++++ libraries/gpu/src/gpu/Image.h | 73 ++++++++++++++++++++++++ libraries/model/src/model/TextureMap.cpp | 7 ++- 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 libraries/gpu/src/gpu/Image.cpp create mode 100644 libraries/gpu/src/gpu/Image.h diff --git a/libraries/gpu/src/gpu/Image.cpp b/libraries/gpu/src/gpu/Image.cpp new file mode 100644 index 0000000000..6649fc7876 --- /dev/null +++ b/libraries/gpu/src/gpu/Image.cpp @@ -0,0 +1,17 @@ +#include "TextureUtils.h" + + +int image::Pixel::cpp { 0 }; + +namespace image { +template <> void compress(const PB_RGB32& src, CB_8& dst) { + + for (auto& b : dst.bytes) { + b = 12; + } +} + +template <> void compress(const PB_RGBA32& src, CB_8& dst) { + +} +} \ No newline at end of file diff --git a/libraries/gpu/src/gpu/Image.h b/libraries/gpu/src/gpu/Image.h new file mode 100644 index 0000000000..a36990b215 --- /dev/null +++ b/libraries/gpu/src/gpu/Image.h @@ -0,0 +1,73 @@ +/* + Let s try compressing images + +*/ +#include "Forward.h" + + +namespace image { + + class Pixel { + public: + using Byte = uint8_t; + static const Byte BLACK { 0 }; + static const Byte WHITE { 255 }; + + struct RGB32 { + Byte r { BLACK }; + Byte g { BLACK }; + Byte b { BLACK }; + Byte x { WHITE }; + }; + + struct RGBA32 { + Byte r { BLACK }; + Byte g { BLACK }; + Byte b { BLACK }; + Byte a { WHITE }; + }; + + + static int cpp; + }; + + template class PixelBlock { + public: + static const uint32_t WIDTH { 4 }; + static const uint32_t HEIGHT { WIDTH }; + static const uint32_t SIZE { WIDTH * HEIGHT }; + constexpr uint32_t getByteSize() const { return SIZE * sizeof(P); } + + P pixels[SIZE]; + + PixelBlock() {} + + + PixelBlock(const P* srcPixels) { + setPixels(srcPixels); + } + + void setPixels(const P* srcPixels) { + memcpy(pixels, srcPixels, getByteSize()); + } + + }; + + template class CompressedBlock { + public: + uint8_t bytes[Size]; + }; + + template void compress(const PB& srcPixelBlock, CB& dstBlock) { } + + using PB_RGB32 = PixelBlock; + using PB_RGBA32 = PixelBlock; + + using CB_8 = CompressedBlock<8>; + using CB_16 = CompressedBlock<16>; + + template <> void compress(const PB_RGB32& src, CB_8& dst); + template <> void compress(const PB_RGBA32& src, CB_8& dst); + + +} \ No newline at end of file diff --git a/libraries/model/src/model/TextureMap.cpp b/libraries/model/src/model/TextureMap.cpp index 30f176b5a6..a6ae3f675b 100755 --- a/libraries/model/src/model/TextureMap.cpp +++ b/libraries/model/src/model/TextureMap.cpp @@ -15,7 +15,7 @@ #include #include "ModelLogging.h" - +#include using namespace model; using namespace gpu; @@ -201,6 +201,11 @@ gpu::Texture* TextureUsage::process2DTextureColorFromImage(const QImage& srcImag theTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits()); + image::PB_RGB32 pb; + image::CB_8 cb; + + image::compress(pb, cb); + if (generateMips) { ::generateMips(theTexture, image, formatMip); }