mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Replace pointer to Sprite array with reference to SpriteCollection. (#11580)
Add `SpriteLoader::SpriteCollection` type which is an array of `SpriteLoad::Sprite`. This removes the ambiguity of what `SpriteLoader::Sprite *` is pointing to, and cleans up mismatches using both dereference -> and array access [] for the same object.pull/11597/head
parent
7466c3c39e
commit
b85ecf9ac2
|
@ -39,7 +39,7 @@ public:
|
||||||
template <BlitterMode mode, Blitter_32bppSSE_Base::ReadMode read_mode, Blitter_32bppSSE_Base::BlockType bt_last, bool translucent, bool animated>
|
template <BlitterMode mode, Blitter_32bppSSE_Base::ReadMode read_mode, Blitter_32bppSSE_Base::BlockType bt_last, bool translucent, bool animated>
|
||||||
void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
|
void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
|
||||||
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
|
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
|
||||||
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override {
|
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override {
|
||||||
return Blitter_32bppSSE_Base::Encode(sprite, allocator);
|
return Blitter_32bppSSE_Base::Encode(sprite, allocator);
|
||||||
}
|
}
|
||||||
const char *GetName() override { return "32bpp-sse4-anim"; }
|
const char *GetName() override { return "32bpp-sse4-anim"; }
|
||||||
|
|
|
@ -272,7 +272,7 @@ void Blitter_32bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode,
|
||||||
this->Draw<false>(bp, mode, zoom);
|
this->Draw<false>(bp, mode, zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
|
template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
|
||||||
{
|
{
|
||||||
/* streams of pixels (a, r, g, b channels)
|
/* streams of pixels (a, r, g, b channels)
|
||||||
*
|
*
|
||||||
|
@ -293,7 +293,7 @@ template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const
|
||||||
ZoomLevel zoom_min;
|
ZoomLevel zoom_min;
|
||||||
ZoomLevel zoom_max;
|
ZoomLevel zoom_max;
|
||||||
|
|
||||||
if (sprite->type == SpriteType::Font) {
|
if (sprite[ZOOM_LVL_NORMAL].type == SpriteType::Font) {
|
||||||
zoom_min = ZOOM_LVL_NORMAL;
|
zoom_min = ZOOM_LVL_NORMAL;
|
||||||
zoom_max = ZOOM_LVL_NORMAL;
|
zoom_max = ZOOM_LVL_NORMAL;
|
||||||
} else {
|
} else {
|
||||||
|
@ -403,10 +403,10 @@ template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const
|
||||||
|
|
||||||
Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sizeof(SpriteData) + len);
|
Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sizeof(SpriteData) + len);
|
||||||
|
|
||||||
dest_sprite->height = sprite->height;
|
dest_sprite->height = sprite[ZOOM_LVL_NORMAL].height;
|
||||||
dest_sprite->width = sprite->width;
|
dest_sprite->width = sprite[ZOOM_LVL_NORMAL].width;
|
||||||
dest_sprite->x_offs = sprite->x_offs;
|
dest_sprite->x_offs = sprite[ZOOM_LVL_NORMAL].x_offs;
|
||||||
dest_sprite->y_offs = sprite->y_offs;
|
dest_sprite->y_offs = sprite[ZOOM_LVL_NORMAL].y_offs;
|
||||||
|
|
||||||
SpriteData *dst = (SpriteData *)dest_sprite->data;
|
SpriteData *dst = (SpriteData *)dest_sprite->data;
|
||||||
memset(dst, 0, sizeof(*dst));
|
memset(dst, 0, sizeof(*dst));
|
||||||
|
@ -425,10 +425,10 @@ template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const
|
||||||
return dest_sprite;
|
return dest_sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
template Sprite *Blitter_32bppOptimized::EncodeInternal<true>(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator);
|
template Sprite *Blitter_32bppOptimized::EncodeInternal<true>(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator);
|
||||||
template Sprite *Blitter_32bppOptimized::EncodeInternal<false>(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator);
|
template Sprite *Blitter_32bppOptimized::EncodeInternal<false>(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator);
|
||||||
|
|
||||||
Sprite *Blitter_32bppOptimized::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
|
Sprite *Blitter_32bppOptimized::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
|
||||||
{
|
{
|
||||||
return this->EncodeInternal<true>(sprite, allocator);
|
return this->EncodeInternal<true>(sprite, allocator);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
|
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
|
||||||
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
|
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
|
||||||
|
|
||||||
const char *GetName() override { return "32bpp-optimized"; }
|
const char *GetName() override { return "32bpp-optimized"; }
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
template <bool Tpal_to_rgb> void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
|
template <bool Tpal_to_rgb> void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
|
||||||
template <bool Tpal_to_rgb> Sprite *EncodeInternal(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator);
|
template <bool Tpal_to_rgb> Sprite *EncodeInternal(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator);
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Factory for the optimised 32 bpp blitter (without palette animation). */
|
/** Factory for the optimised 32 bpp blitter (without palette animation). */
|
||||||
|
|
|
@ -109,20 +109,20 @@ void Blitter_32bppSimple::DrawColourMappingRect(void *dst, int width, int height
|
||||||
Debug(misc, 0, "32bpp blitter doesn't know how to draw this colour table ('{}')", pal);
|
Debug(misc, 0, "32bpp blitter doesn't know how to draw this colour table ('{}')", pal);
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite *Blitter_32bppSimple::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
|
Sprite *Blitter_32bppSimple::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
|
||||||
{
|
{
|
||||||
Blitter_32bppSimple::Pixel *dst;
|
Blitter_32bppSimple::Pixel *dst;
|
||||||
Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + (size_t)sprite->height * (size_t)sprite->width * sizeof(*dst));
|
Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + (size_t)sprite[ZOOM_LVL_NORMAL].height * (size_t)sprite[ZOOM_LVL_NORMAL].width * sizeof(*dst));
|
||||||
|
|
||||||
dest_sprite->height = sprite->height;
|
dest_sprite->height = sprite[ZOOM_LVL_NORMAL].height;
|
||||||
dest_sprite->width = sprite->width;
|
dest_sprite->width = sprite[ZOOM_LVL_NORMAL].width;
|
||||||
dest_sprite->x_offs = sprite->x_offs;
|
dest_sprite->x_offs = sprite[ZOOM_LVL_NORMAL].x_offs;
|
||||||
dest_sprite->y_offs = sprite->y_offs;
|
dest_sprite->y_offs = sprite[ZOOM_LVL_NORMAL].y_offs;
|
||||||
|
|
||||||
dst = (Blitter_32bppSimple::Pixel *)dest_sprite->data;
|
dst = (Blitter_32bppSimple::Pixel *)dest_sprite->data;
|
||||||
SpriteLoader::CommonPixel *src = (SpriteLoader::CommonPixel *)sprite->data;
|
SpriteLoader::CommonPixel *src = (SpriteLoader::CommonPixel *)sprite[ZOOM_LVL_NORMAL].data;
|
||||||
|
|
||||||
for (int i = 0; i < sprite->height * sprite->width; i++) {
|
for (int i = 0; i < sprite[ZOOM_LVL_NORMAL].height * sprite[ZOOM_LVL_NORMAL].width; i++) {
|
||||||
if (src->m == 0) {
|
if (src->m == 0) {
|
||||||
dst[i].r = src->r;
|
dst[i].r = src->r;
|
||||||
dst[i].g = src->g;
|
dst[i].g = src->g;
|
||||||
|
|
|
@ -26,7 +26,7 @@ class Blitter_32bppSimple : public Blitter_32bppBase {
|
||||||
public:
|
public:
|
||||||
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
|
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
|
||||||
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override;
|
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override;
|
||||||
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
|
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
|
||||||
|
|
||||||
const char *GetName() override { return "32bpp-simple"; }
|
const char *GetName() override { return "32bpp-simple"; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
/** Instantiation of the SSE2 32bpp blitter factory. */
|
/** Instantiation of the SSE2 32bpp blitter factory. */
|
||||||
static FBlitter_32bppSSE2 iFBlitter_32bppSSE2;
|
static FBlitter_32bppSSE2 iFBlitter_32bppSSE2;
|
||||||
|
|
||||||
Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
|
Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
|
||||||
{
|
{
|
||||||
/* First uint32_t of a line = the number of transparent pixels from the left.
|
/* First uint32_t of a line = the number of transparent pixels from the left.
|
||||||
* Second uint32_t of a line = the number of transparent pixels from the right.
|
* Second uint32_t of a line = the number of transparent pixels from the right.
|
||||||
|
@ -28,7 +28,7 @@ Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::Sprite *sprite, Alloca
|
||||||
*/
|
*/
|
||||||
ZoomLevel zoom_min = ZOOM_LVL_NORMAL;
|
ZoomLevel zoom_min = ZOOM_LVL_NORMAL;
|
||||||
ZoomLevel zoom_max = ZOOM_LVL_NORMAL;
|
ZoomLevel zoom_max = ZOOM_LVL_NORMAL;
|
||||||
if (sprite->type != SpriteType::Font) {
|
if (sprite[ZOOM_LVL_NORMAL].type != SpriteType::Font) {
|
||||||
zoom_min = _settings_client.gui.zoom_min;
|
zoom_min = _settings_client.gui.zoom_min;
|
||||||
zoom_max = _settings_client.gui.zoom_max;
|
zoom_max = _settings_client.gui.zoom_max;
|
||||||
if (zoom_max == zoom_min) zoom_max = ZOOM_LVL_MAX;
|
if (zoom_max == zoom_min) zoom_max = ZOOM_LVL_MAX;
|
||||||
|
@ -52,10 +52,10 @@ Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::Sprite *sprite, Alloca
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite *dst_sprite = (Sprite *) allocator(sizeof(Sprite) + sizeof(SpriteData) + all_sprites_size);
|
Sprite *dst_sprite = (Sprite *) allocator(sizeof(Sprite) + sizeof(SpriteData) + all_sprites_size);
|
||||||
dst_sprite->height = sprite->height;
|
dst_sprite->height = sprite[ZOOM_LVL_NORMAL].height;
|
||||||
dst_sprite->width = sprite->width;
|
dst_sprite->width = sprite[ZOOM_LVL_NORMAL].width;
|
||||||
dst_sprite->x_offs = sprite->x_offs;
|
dst_sprite->x_offs = sprite[ZOOM_LVL_NORMAL].x_offs;
|
||||||
dst_sprite->y_offs = sprite->y_offs;
|
dst_sprite->y_offs = sprite[ZOOM_LVL_NORMAL].y_offs;
|
||||||
memcpy(dst_sprite->data, &sd, sizeof(SpriteData));
|
memcpy(dst_sprite->data, &sd, sizeof(SpriteData));
|
||||||
|
|
||||||
/* Copy colours and determine flags. */
|
/* Copy colours and determine flags. */
|
||||||
|
|
|
@ -76,7 +76,7 @@ public:
|
||||||
byte data[]; ///< Data, all zoomlevels.
|
byte data[]; ///< Data, all zoomlevels.
|
||||||
};
|
};
|
||||||
|
|
||||||
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator);
|
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator);
|
||||||
};
|
};
|
||||||
|
|
||||||
DECLARE_ENUM_AS_BIT_SET(Blitter_32bppSSE_Base::SpriteFlags);
|
DECLARE_ENUM_AS_BIT_SET(Blitter_32bppSSE_Base::SpriteFlags);
|
||||||
|
@ -88,7 +88,7 @@ public:
|
||||||
template <BlitterMode mode, Blitter_32bppSSE_Base::ReadMode read_mode, Blitter_32bppSSE_Base::BlockType bt_last, bool translucent>
|
template <BlitterMode mode, Blitter_32bppSSE_Base::ReadMode read_mode, Blitter_32bppSSE_Base::BlockType bt_last, bool translucent>
|
||||||
void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
|
void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
|
||||||
|
|
||||||
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override {
|
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override {
|
||||||
return Blitter_32bppSSE_Base::Encode(sprite, allocator);
|
return Blitter_32bppSSE_Base::Encode(sprite, allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -377,7 +377,7 @@ void Blitter_40bppAnim::DrawColourMappingRect(void *dst, int width, int height,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite *Blitter_40bppAnim::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
|
Sprite *Blitter_40bppAnim::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
|
||||||
{
|
{
|
||||||
return this->EncodeInternal<false>(sprite, allocator);
|
return this->EncodeInternal<false>(sprite, allocator);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ public:
|
||||||
void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) override;
|
void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) override;
|
||||||
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
|
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
|
||||||
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override;
|
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override;
|
||||||
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
|
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
|
||||||
size_t BufferSize(uint width, uint height) override;
|
size_t BufferSize(uint width, uint height) override;
|
||||||
Blitter::PaletteAnimation UsePaletteAnimation() override;
|
Blitter::PaletteAnimation UsePaletteAnimation() override;
|
||||||
bool NeedsAnimationBuffer() override;
|
bool NeedsAnimationBuffer() override;
|
||||||
|
|
|
@ -119,7 +119,7 @@ void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Z
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite *Blitter_8bppOptimized::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
|
Sprite *Blitter_8bppOptimized::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
|
||||||
{
|
{
|
||||||
/* Make memory for all zoom-levels */
|
/* Make memory for all zoom-levels */
|
||||||
uint memory = sizeof(SpriteData);
|
uint memory = sizeof(SpriteData);
|
||||||
|
@ -127,7 +127,7 @@ Sprite *Blitter_8bppOptimized::Encode(const SpriteLoader::Sprite *sprite, Alloca
|
||||||
ZoomLevel zoom_min;
|
ZoomLevel zoom_min;
|
||||||
ZoomLevel zoom_max;
|
ZoomLevel zoom_max;
|
||||||
|
|
||||||
if (sprite->type == SpriteType::Font) {
|
if (sprite[ZOOM_LVL_NORMAL].type == SpriteType::Font) {
|
||||||
zoom_min = ZOOM_LVL_NORMAL;
|
zoom_min = ZOOM_LVL_NORMAL;
|
||||||
zoom_max = ZOOM_LVL_NORMAL;
|
zoom_max = ZOOM_LVL_NORMAL;
|
||||||
} else {
|
} else {
|
||||||
|
@ -220,10 +220,10 @@ Sprite *Blitter_8bppOptimized::Encode(const SpriteLoader::Sprite *sprite, Alloca
|
||||||
/* Allocate the exact amount of memory we need */
|
/* Allocate the exact amount of memory we need */
|
||||||
Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + size);
|
Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + size);
|
||||||
|
|
||||||
dest_sprite->height = sprite->height;
|
dest_sprite->height = sprite[ZOOM_LVL_NORMAL].height;
|
||||||
dest_sprite->width = sprite->width;
|
dest_sprite->width = sprite[ZOOM_LVL_NORMAL].width;
|
||||||
dest_sprite->x_offs = sprite->x_offs;
|
dest_sprite->x_offs = sprite[ZOOM_LVL_NORMAL].x_offs;
|
||||||
dest_sprite->y_offs = sprite->y_offs;
|
dest_sprite->y_offs = sprite[ZOOM_LVL_NORMAL].y_offs;
|
||||||
memcpy(dest_sprite->data, temp_dst, size);
|
memcpy(dest_sprite->data, temp_dst, size);
|
||||||
|
|
||||||
return dest_sprite;
|
return dest_sprite;
|
||||||
|
|
|
@ -23,7 +23,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
|
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
|
||||||
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
|
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
|
||||||
|
|
||||||
const char *GetName() override { return "8bpp-optimized"; }
|
const char *GetName() override { return "8bpp-optimized"; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -60,19 +60,19 @@ void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoom
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite *Blitter_8bppSimple::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
|
Sprite *Blitter_8bppSimple::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
|
||||||
{
|
{
|
||||||
Sprite *dest_sprite;
|
Sprite *dest_sprite;
|
||||||
dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + (size_t)sprite->height * (size_t)sprite->width);
|
dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + (size_t)sprite[ZOOM_LVL_NORMAL].height * (size_t)sprite[ZOOM_LVL_NORMAL].width);
|
||||||
|
|
||||||
dest_sprite->height = sprite->height;
|
dest_sprite->height = sprite[ZOOM_LVL_NORMAL].height;
|
||||||
dest_sprite->width = sprite->width;
|
dest_sprite->width = sprite[ZOOM_LVL_NORMAL].width;
|
||||||
dest_sprite->x_offs = sprite->x_offs;
|
dest_sprite->x_offs = sprite[ZOOM_LVL_NORMAL].x_offs;
|
||||||
dest_sprite->y_offs = sprite->y_offs;
|
dest_sprite->y_offs = sprite[ZOOM_LVL_NORMAL].y_offs;
|
||||||
|
|
||||||
/* Copy over only the 'remap' channel, as that is what we care about in 8bpp */
|
/* Copy over only the 'remap' channel, as that is what we care about in 8bpp */
|
||||||
for (int i = 0; i < sprite->height * sprite->width; i++) {
|
for (int i = 0; i < sprite[ZOOM_LVL_NORMAL].height * sprite[ZOOM_LVL_NORMAL].width; i++) {
|
||||||
dest_sprite->data[i] = sprite->data[i].m;
|
dest_sprite->data[i] = sprite[ZOOM_LVL_NORMAL].data[i].m;
|
||||||
}
|
}
|
||||||
|
|
||||||
return dest_sprite;
|
return dest_sprite;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
class Blitter_8bppSimple FINAL : public Blitter_8bppBase {
|
class Blitter_8bppSimple FINAL : public Blitter_8bppBase {
|
||||||
public:
|
public:
|
||||||
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
|
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
|
||||||
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
|
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
|
||||||
|
|
||||||
const char *GetName() override { return "8bpp-simple"; }
|
const char *GetName() override { return "8bpp-simple"; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,15 +15,15 @@
|
||||||
/** Instantiation of the null blitter factory. */
|
/** Instantiation of the null blitter factory. */
|
||||||
static FBlitter_Null iFBlitter_Null;
|
static FBlitter_Null iFBlitter_Null;
|
||||||
|
|
||||||
Sprite *Blitter_Null::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
|
Sprite *Blitter_Null::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
|
||||||
{
|
{
|
||||||
Sprite *dest_sprite;
|
Sprite *dest_sprite;
|
||||||
dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite));
|
dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite));
|
||||||
|
|
||||||
dest_sprite->height = sprite->height;
|
dest_sprite->height = sprite[ZOOM_LVL_NORMAL].height;
|
||||||
dest_sprite->width = sprite->width;
|
dest_sprite->width = sprite[ZOOM_LVL_NORMAL].width;
|
||||||
dest_sprite->x_offs = sprite->x_offs;
|
dest_sprite->x_offs = sprite[ZOOM_LVL_NORMAL].x_offs;
|
||||||
dest_sprite->y_offs = sprite->y_offs;
|
dest_sprite->y_offs = sprite[ZOOM_LVL_NORMAL].y_offs;
|
||||||
|
|
||||||
return dest_sprite;
|
return dest_sprite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ public:
|
||||||
uint8_t GetScreenDepth() override { return 0; }
|
uint8_t GetScreenDepth() override { return 0; }
|
||||||
void Draw(Blitter::BlitterParams *, BlitterMode, ZoomLevel) override {};
|
void Draw(Blitter::BlitterParams *, BlitterMode, ZoomLevel) override {};
|
||||||
void DrawColourMappingRect(void *, int, int, PaletteID) override {};
|
void DrawColourMappingRect(void *, int, int, PaletteID) override {};
|
||||||
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
|
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
|
||||||
void *MoveTo(void *, int, int) override { return nullptr; };
|
void *MoveTo(void *, int, int) override { return nullptr; };
|
||||||
void SetPixel(void *, int, int, uint8_t) override {};
|
void SetPixel(void *, int, int, uint8_t) override {};
|
||||||
void DrawRect(void *, int, int, uint8_t) override {};
|
void DrawRect(void *, int, int, uint8_t) override {};
|
||||||
|
|
|
@ -235,7 +235,8 @@ const Sprite *FreeTypeFontCache::InternalGetGlyph(GlyphID key, bool aa)
|
||||||
if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) UserError("Font glyph is too large");
|
if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) UserError("Font glyph is too large");
|
||||||
|
|
||||||
/* FreeType has rendered the glyph, now we allocate a sprite and copy the image into it */
|
/* FreeType has rendered the glyph, now we allocate a sprite and copy the image into it */
|
||||||
SpriteLoader::Sprite sprite;
|
SpriteLoader::SpriteCollection spritecollection;
|
||||||
|
SpriteLoader::Sprite &sprite = spritecollection[ZOOM_LVL_NORMAL];
|
||||||
sprite.AllocateData(ZOOM_LVL_NORMAL, static_cast<size_t>(width) * height);
|
sprite.AllocateData(ZOOM_LVL_NORMAL, static_cast<size_t>(width) * height);
|
||||||
sprite.type = SpriteType::Font;
|
sprite.type = SpriteType::Font;
|
||||||
sprite.colours = (aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
|
sprite.colours = (aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
|
||||||
|
@ -266,7 +267,7 @@ const Sprite *FreeTypeFontCache::InternalGetGlyph(GlyphID key, bool aa)
|
||||||
}
|
}
|
||||||
|
|
||||||
GlyphEntry new_glyph;
|
GlyphEntry new_glyph;
|
||||||
new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(&sprite, SimpleSpriteAlloc);
|
new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(spritecollection, SimpleSpriteAlloc);
|
||||||
new_glyph.width = slot->advance.x >> 6;
|
new_glyph.width = slot->advance.x >> 6;
|
||||||
|
|
||||||
this->SetGlyphPtr(key, &new_glyph);
|
this->SetGlyphPtr(key, &new_glyph);
|
||||||
|
|
|
@ -136,7 +136,7 @@ const Sprite *TrueTypeFontCache::GetGlyph(GlyphID key)
|
||||||
};
|
};
|
||||||
#undef CPSET
|
#undef CPSET
|
||||||
#undef CP___
|
#undef CP___
|
||||||
static const SpriteLoader::Sprite builtin_questionmark = {
|
static const SpriteLoader::SpriteCollection builtin_questionmark = {{ {
|
||||||
10, // height
|
10, // height
|
||||||
8, // width
|
8, // width
|
||||||
0, // x_offs
|
0, // x_offs
|
||||||
|
@ -144,9 +144,9 @@ const Sprite *TrueTypeFontCache::GetGlyph(GlyphID key)
|
||||||
SpriteType::Font,
|
SpriteType::Font,
|
||||||
SCC_PAL,
|
SCC_PAL,
|
||||||
builtin_questionmark_data
|
builtin_questionmark_data
|
||||||
};
|
} }};
|
||||||
|
|
||||||
Sprite *spr = BlitterFactory::GetCurrentBlitter()->Encode(&builtin_questionmark, SimpleSpriteAlloc);
|
Sprite *spr = BlitterFactory::GetCurrentBlitter()->Encode(builtin_questionmark, SimpleSpriteAlloc);
|
||||||
assert(spr != nullptr);
|
assert(spr != nullptr);
|
||||||
GlyphEntry new_glyph;
|
GlyphEntry new_glyph;
|
||||||
new_glyph.sprite = spr;
|
new_glyph.sprite = spr;
|
||||||
|
|
|
@ -240,7 +240,8 @@ const Sprite *CoreTextFontCache::InternalGetGlyph(GlyphID key, bool use_aa)
|
||||||
/* Limit glyph size to prevent overflows later on. */
|
/* Limit glyph size to prevent overflows later on. */
|
||||||
if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) UserError("Font glyph is too large");
|
if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) UserError("Font glyph is too large");
|
||||||
|
|
||||||
SpriteLoader::Sprite sprite;
|
SpriteLoader::SpriteCollection spritecollection;
|
||||||
|
SpriteLoader::Sprite &sprite = spritecollection[ZOOM_LVL_NORMAL];
|
||||||
sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
|
sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
|
||||||
sprite.type = SpriteType::Font;
|
sprite.type = SpriteType::Font;
|
||||||
sprite.colours = (use_aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
|
sprite.colours = (use_aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
|
||||||
|
@ -290,7 +291,7 @@ const Sprite *CoreTextFontCache::InternalGetGlyph(GlyphID key, bool use_aa)
|
||||||
}
|
}
|
||||||
|
|
||||||
GlyphEntry new_glyph;
|
GlyphEntry new_glyph;
|
||||||
new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(&sprite, SimpleSpriteAlloc);
|
new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(spritecollection, SimpleSpriteAlloc);
|
||||||
new_glyph.width = (byte)std::round(CTFontGetAdvancesForGlyphs(this->font.get(), kCTFontOrientationDefault, &glyph, nullptr, 1));
|
new_glyph.width = (byte)std::round(CTFontGetAdvancesForGlyphs(this->font.get(), kCTFontOrientationDefault, &glyph, nullptr, 1));
|
||||||
this->SetGlyphPtr(key, &new_glyph);
|
this->SetGlyphPtr(key, &new_glyph);
|
||||||
|
|
||||||
|
|
|
@ -230,7 +230,8 @@ void Win32FontCache::ClearFontCache()
|
||||||
GetGlyphOutline(this->dc, key, GGO_GLYPH_INDEX | (aa ? GGO_GRAY8_BITMAP : GGO_BITMAP), &gm, size, bmp, &mat);
|
GetGlyphOutline(this->dc, key, GGO_GLYPH_INDEX | (aa ? GGO_GRAY8_BITMAP : GGO_BITMAP), &gm, size, bmp, &mat);
|
||||||
|
|
||||||
/* GDI has rendered the glyph, now we allocate a sprite and copy the image into it. */
|
/* GDI has rendered the glyph, now we allocate a sprite and copy the image into it. */
|
||||||
SpriteLoader::Sprite sprite;
|
SpriteLoader::SpriteCollection spritecollection;
|
||||||
|
SpriteLoader::Sprite &sprite = spritecollection[ZOOM_LVL_NORMAL];
|
||||||
sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
|
sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
|
||||||
sprite.type = SpriteType::Font;
|
sprite.type = SpriteType::Font;
|
||||||
sprite.colours = (aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
|
sprite.colours = (aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
|
||||||
|
@ -270,7 +271,7 @@ void Win32FontCache::ClearFontCache()
|
||||||
}
|
}
|
||||||
|
|
||||||
GlyphEntry new_glyph;
|
GlyphEntry new_glyph;
|
||||||
new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(&sprite, SimpleSpriteAlloc);
|
new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(spritecollection, SimpleSpriteAlloc);
|
||||||
new_glyph.width = gm.gmCellIncX;
|
new_glyph.width = gm.gmCellIncX;
|
||||||
|
|
||||||
this->SetGlyphPtr(key, &new_glyph);
|
this->SetGlyphPtr(key, &new_glyph);
|
||||||
|
|
|
@ -213,7 +213,7 @@ uint GetMaxSpriteID()
|
||||||
return _spritecache_items;
|
return _spritecache_items;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ResizeSpriteIn(SpriteLoader::Sprite *sprite, ZoomLevel src, ZoomLevel tgt)
|
static bool ResizeSpriteIn(SpriteLoader::SpriteCollection &sprite, ZoomLevel src, ZoomLevel tgt)
|
||||||
{
|
{
|
||||||
uint8_t scaled_1 = ScaleByZoom(1, (ZoomLevel)(src - tgt));
|
uint8_t scaled_1 = ScaleByZoom(1, (ZoomLevel)(src - tgt));
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ static bool ResizeSpriteIn(SpriteLoader::Sprite *sprite, ZoomLevel src, ZoomLeve
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ResizeSpriteOut(SpriteLoader::Sprite *sprite, ZoomLevel zoom)
|
static void ResizeSpriteOut(SpriteLoader::SpriteCollection &sprite, ZoomLevel zoom)
|
||||||
{
|
{
|
||||||
/* Algorithm based on 32bpp_Optimized::ResizeSprite() */
|
/* Algorithm based on 32bpp_Optimized::ResizeSprite() */
|
||||||
sprite[zoom].width = UnScaleByZoom(sprite[ZOOM_LVL_NORMAL].width, zoom);
|
sprite[zoom].width = UnScaleByZoom(sprite[ZOOM_LVL_NORMAL].width, zoom);
|
||||||
|
@ -323,7 +323,7 @@ static bool PadSingleSprite(SpriteLoader::Sprite *sprite, ZoomLevel zoom, uint p
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool PadSprites(SpriteLoader::Sprite *sprite, uint8_t sprite_avail, SpriteEncoder *encoder)
|
static bool PadSprites(SpriteLoader::SpriteCollection &sprite, uint8_t sprite_avail, SpriteEncoder *encoder)
|
||||||
{
|
{
|
||||||
/* Get minimum top left corner coordinates. */
|
/* Get minimum top left corner coordinates. */
|
||||||
int min_xoffs = INT32_MAX;
|
int min_xoffs = INT32_MAX;
|
||||||
|
@ -371,7 +371,7 @@ static bool PadSprites(SpriteLoader::Sprite *sprite, uint8_t sprite_avail, Sprit
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ResizeSprites(SpriteLoader::Sprite *sprite, uint8_t sprite_avail, SpriteEncoder *encoder)
|
static bool ResizeSprites(SpriteLoader::SpriteCollection &sprite, uint8_t sprite_avail, SpriteEncoder *encoder)
|
||||||
{
|
{
|
||||||
/* Create a fully zoomed image if it does not exist */
|
/* Create a fully zoomed image if it does not exist */
|
||||||
ZoomLevel first_avail = static_cast<ZoomLevel>(FIND_FIRST_BIT(sprite_avail));
|
ZoomLevel first_avail = static_cast<ZoomLevel>(FIND_FIRST_BIT(sprite_avail));
|
||||||
|
@ -457,7 +457,7 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty
|
||||||
|
|
||||||
Debug(sprite, 9, "Load sprite {}", id);
|
Debug(sprite, 9, "Load sprite {}", id);
|
||||||
|
|
||||||
SpriteLoader::Sprite sprite[ZOOM_LVL_END];
|
SpriteLoader::SpriteCollection sprite;
|
||||||
uint8_t sprite_avail = 0;
|
uint8_t sprite_avail = 0;
|
||||||
sprite[ZOOM_LVL_NORMAL].type = sprite_type;
|
sprite[ZOOM_LVL_NORMAL].type = sprite_type;
|
||||||
|
|
||||||
|
@ -509,7 +509,7 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty
|
||||||
return (void*)GetRawSprite(SPR_IMG_QUERY, SpriteType::Normal, allocator, encoder);
|
return (void*)GetRawSprite(SPR_IMG_QUERY, SpriteType::Normal, allocator, encoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sprite->type == SpriteType::Font && _font_zoom != ZOOM_LVL_NORMAL) {
|
if (sprite[ZOOM_LVL_NORMAL].type == SpriteType::Font && _font_zoom != ZOOM_LVL_NORMAL) {
|
||||||
/* Make ZOOM_LVL_NORMAL be ZOOM_LVL_GUI */
|
/* Make ZOOM_LVL_NORMAL be ZOOM_LVL_GUI */
|
||||||
sprite[ZOOM_LVL_NORMAL].width = sprite[_font_zoom].width;
|
sprite[ZOOM_LVL_NORMAL].width = sprite[_font_zoom].width;
|
||||||
sprite[ZOOM_LVL_NORMAL].height = sprite[_font_zoom].height;
|
sprite[ZOOM_LVL_NORMAL].height = sprite[_font_zoom].height;
|
||||||
|
|
|
@ -215,7 +215,7 @@ bool DecodeSingleSprite(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t f
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t LoadSpriteV1(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp)
|
uint8_t LoadSpriteV1(SpriteLoader::SpriteCollection &sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp)
|
||||||
{
|
{
|
||||||
/* Check the requested colour depth. */
|
/* Check the requested colour depth. */
|
||||||
if (load_32bpp) return 0;
|
if (load_32bpp) return 0;
|
||||||
|
@ -252,7 +252,7 @@ uint8_t LoadSpriteV1(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t file
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t LoadSpriteV2(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, byte control_flags)
|
uint8_t LoadSpriteV2(SpriteLoader::SpriteCollection &sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, byte control_flags)
|
||||||
{
|
{
|
||||||
static const ZoomLevel zoom_lvl_map[6] = {ZOOM_LVL_OUT_4X, ZOOM_LVL_NORMAL, ZOOM_LVL_OUT_2X, ZOOM_LVL_OUT_8X, ZOOM_LVL_OUT_16X, ZOOM_LVL_OUT_32X};
|
static const ZoomLevel zoom_lvl_map[6] = {ZOOM_LVL_OUT_4X, ZOOM_LVL_NORMAL, ZOOM_LVL_OUT_2X, ZOOM_LVL_OUT_8X, ZOOM_LVL_OUT_16X, ZOOM_LVL_OUT_32X};
|
||||||
|
|
||||||
|
@ -350,7 +350,7 @@ uint8_t LoadSpriteV2(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t file
|
||||||
return loaded_sprites;
|
return loaded_sprites;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t SpriteLoaderGrf::LoadSprite(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, byte control_flags)
|
uint8_t SpriteLoaderGrf::LoadSprite(SpriteLoader::SpriteCollection &sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, byte control_flags)
|
||||||
{
|
{
|
||||||
if (this->container_ver >= 2) {
|
if (this->container_ver >= 2) {
|
||||||
return LoadSpriteV2(sprite, file, file_pos, sprite_type, load_32bpp, control_flags);
|
return LoadSpriteV2(sprite, file, file_pos, sprite_type, load_32bpp, control_flags);
|
||||||
|
|
|
@ -17,7 +17,7 @@ class SpriteLoaderGrf : public SpriteLoader {
|
||||||
byte container_ver;
|
byte container_ver;
|
||||||
public:
|
public:
|
||||||
SpriteLoaderGrf(byte container_ver) : container_ver(container_ver) {}
|
SpriteLoaderGrf(byte container_ver) : container_ver(container_ver) {}
|
||||||
uint8_t LoadSprite(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, byte control_flags) override;
|
uint8_t LoadSprite(SpriteLoader::SpriteCollection &sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, byte control_flags) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SPRITELOADER_GRF_HPP */
|
#endif /* SPRITELOADER_GRF_HPP */
|
||||||
|
|
|
@ -65,6 +65,11 @@ public:
|
||||||
static ReusableBuffer<SpriteLoader::CommonPixel> buffer[ZOOM_LVL_END];
|
static ReusableBuffer<SpriteLoader::CommonPixel> buffer[ZOOM_LVL_END];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type defining a collection of sprites, one for each zoom level.
|
||||||
|
*/
|
||||||
|
using SpriteCollection = std::array<Sprite, ZOOM_LVL_END>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a sprite from the disk and return a sprite struct which is the same for all loaders.
|
* Load a sprite from the disk and return a sprite struct which is the same for all loaders.
|
||||||
* @param[out] sprite The sprites to fill with data.
|
* @param[out] sprite The sprites to fill with data.
|
||||||
|
@ -75,7 +80,7 @@ public:
|
||||||
* @param control_flags Control flags, see SpriteCacheCtrlFlags.
|
* @param control_flags Control flags, see SpriteCacheCtrlFlags.
|
||||||
* @return Bit mask of the zoom levels successfully loaded or 0 if no sprite could be loaded.
|
* @return Bit mask of the zoom levels successfully loaded or 0 if no sprite could be loaded.
|
||||||
*/
|
*/
|
||||||
virtual uint8_t LoadSprite(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, byte control_flags) = 0;
|
virtual uint8_t LoadSprite(SpriteLoader::SpriteCollection &sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, byte control_flags) = 0;
|
||||||
|
|
||||||
virtual ~SpriteLoader() = default;
|
virtual ~SpriteLoader() = default;
|
||||||
};
|
};
|
||||||
|
@ -94,7 +99,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Convert a sprite from the loader to our own format.
|
* Convert a sprite from the loader to our own format.
|
||||||
*/
|
*/
|
||||||
virtual Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) = 0;
|
virtual Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value which the height and width on a sprite have to be aligned by.
|
* Get the value which the height and width on a sprite have to be aligned by.
|
||||||
|
|
|
@ -1264,23 +1264,23 @@ void OpenGLBackend::ReleaseAnimBuffer(const Rect &update_rect)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual */ Sprite *OpenGLBackend::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
|
/* virtual */ Sprite *OpenGLBackend::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
|
||||||
{
|
{
|
||||||
/* Allocate and construct sprite data. */
|
/* Allocate and construct sprite data. */
|
||||||
Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sizeof(OpenGLSprite));
|
Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sizeof(OpenGLSprite));
|
||||||
|
|
||||||
OpenGLSprite *gl_sprite = (OpenGLSprite *)dest_sprite->data;
|
OpenGLSprite *gl_sprite = (OpenGLSprite *)dest_sprite->data;
|
||||||
new (gl_sprite) OpenGLSprite(sprite->width, sprite->height, sprite->type == SpriteType::Font ? 1 : ZOOM_LVL_END, sprite->colours);
|
new (gl_sprite) OpenGLSprite(sprite[ZOOM_LVL_NORMAL].width, sprite[ZOOM_LVL_NORMAL].height, sprite[ZOOM_LVL_NORMAL].type == SpriteType::Font ? 1 : ZOOM_LVL_END, sprite[ZOOM_LVL_NORMAL].colours);
|
||||||
|
|
||||||
/* Upload texture data. */
|
/* Upload texture data. */
|
||||||
for (int i = 0; i < (sprite->type == SpriteType::Font ? 1 : ZOOM_LVL_END); i++) {
|
for (int i = 0; i < (sprite[ZOOM_LVL_NORMAL].type == SpriteType::Font ? 1 : ZOOM_LVL_END); i++) {
|
||||||
gl_sprite->Update(sprite[i].width, sprite[i].height, i, sprite[i].data);
|
gl_sprite->Update(sprite[i].width, sprite[i].height, i, sprite[i].data);
|
||||||
}
|
}
|
||||||
|
|
||||||
dest_sprite->height = sprite->height;
|
dest_sprite->height = sprite[ZOOM_LVL_NORMAL].height;
|
||||||
dest_sprite->width = sprite->width;
|
dest_sprite->width = sprite[ZOOM_LVL_NORMAL].width;
|
||||||
dest_sprite->x_offs = sprite->x_offs;
|
dest_sprite->x_offs = sprite[ZOOM_LVL_NORMAL].x_offs;
|
||||||
dest_sprite->y_offs = sprite->y_offs;
|
dest_sprite->y_offs = sprite[ZOOM_LVL_NORMAL].y_offs;
|
||||||
|
|
||||||
return dest_sprite;
|
return dest_sprite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ public:
|
||||||
|
|
||||||
bool Is32BppSupported() override { return true; }
|
bool Is32BppSupported() override { return true; }
|
||||||
uint GetSpriteAlignment() override { return 1u << (ZOOM_LVL_END - 1); }
|
uint GetSpriteAlignment() override { return 1u << (ZOOM_LVL_END - 1); }
|
||||||
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
|
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue