mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:23:54 +02:00
Adding Image utility to GPU
This commit is contained in:
parent
b5881146df
commit
4ac0c29d9b
3 changed files with 96 additions and 1 deletions
17
libraries/gpu/src/gpu/Image.cpp
Normal file
17
libraries/gpu/src/gpu/Image.cpp
Normal file
|
@ -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) {
|
||||
|
||||
}
|
||||
}
|
73
libraries/gpu/src/gpu/Image.h
Normal file
73
libraries/gpu/src/gpu/Image.h
Normal file
|
@ -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 <typename P> 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 <int Size> class CompressedBlock {
|
||||
public:
|
||||
uint8_t bytes[Size];
|
||||
};
|
||||
|
||||
template <typename PB, typename CB> void compress(const PB& srcPixelBlock, CB& dstBlock) { }
|
||||
|
||||
using PB_RGB32 = PixelBlock<Pixel::RGB32>;
|
||||
using PB_RGBA32 = PixelBlock<Pixel::RGBA32>;
|
||||
|
||||
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);
|
||||
|
||||
|
||||
}
|
|
@ -15,7 +15,7 @@
|
|||
#include <QDebug>
|
||||
|
||||
#include "ModelLogging.h"
|
||||
|
||||
#include <gpu/TextureUtils.h>
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue