OpenTTD Source 20260304-master-g1baaa74679
32bpp_sse2.hpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef BLITTER_32BPP_SSE2_HPP
11#define BLITTER_32BPP_SSE2_HPP
12
13#ifdef WITH_SSE
14
15#ifndef SSE_VERSION
16#define SSE_VERSION 2
17#endif
18
19#ifndef SSE_TARGET
20#define SSE_TARGET "sse2"
21#endif
22
23#ifndef FULL_ANIMATION
24#define FULL_ANIMATION 0
25#endif
26
27#include "32bpp_sse_type.h"
28
30class Blitter_32bppSSE_Base {
31public:
33 virtual ~Blitter_32bppSSE_Base() = default;
34
35 struct MapValue {
36 uint8_t m;
37 uint8_t v;
38 };
39 static_assert(sizeof(MapValue) == 2);
40
42 enum ReadMode : uint8_t {
43 RM_WITH_SKIP,
44 RM_WITH_MARGIN,
45 RM_NONE,
46 };
47
49 enum BlockType : uint8_t {
50 BT_EVEN,
51 BT_ODD,
52 BT_NONE,
53 };
54
60 enum class SpriteFlag : uint8_t {
61 Translucent,
62 NoRemap,
63 NoAnim,
64 };
65
66 using SpriteFlags = EnumBitSet<SpriteFlag, uint8_t>;
67
69 struct SpriteInfo {
70 uint32_t sprite_offset = 0;
71 uint32_t mv_offset = 0;
72 uint16_t sprite_line_size = 0;
73 uint16_t sprite_width = 0;
74 };
75 struct SpriteData {
76 SpriteFlags flags{};
77 SpriteCollMap<SpriteInfo> infos{};
78 uint8_t data[];
79 };
80
81 Sprite *Encode(SpriteType sprite_type, const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator);
82};
83
85class Blitter_32bppSSE2 : public Blitter_32bppSimple, public Blitter_32bppSSE_Base {
86public:
87 void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
88 template <BlitterMode mode, Blitter_32bppSSE_Base::ReadMode read_mode, Blitter_32bppSSE_Base::BlockType bt_last, bool translucent>
89 void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
90
91 Sprite *Encode(SpriteType sprite_type, const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override
92 {
93 return Blitter_32bppSSE_Base::Encode(sprite_type, sprite, allocator);
94 }
95
96 std::string_view GetName() override { return "32bpp-sse2"; }
97};
98
100class FBlitter_32bppSSE2 : public BlitterFactory {
101public:
102 FBlitter_32bppSSE2() : BlitterFactory("32bpp-sse2", "32bpp SSE2 Blitter (no palette animation)", HasCPUIDFlag(1, 3, 26)) {}
103 std::unique_ptr<Blitter> CreateInstance() override { return std::make_unique<Blitter_32bppSSE2>(); }
104};
105
106#endif /* WITH_SSE */
107#endif /* BLITTER_32BPP_SSE2_HPP */
Types related to SSE 32 bpp blitter.
BlitterMode
The modes of blitting we can do.
Definition base.hpp:17
The base factory, keeping track of all blitters.
Definition factory.hpp:21
virtual std::unique_ptr< Blitter > CreateInstance()=0
Create an instance of this Blitter-class.
The most trivial 32 bpp blitter (without palette animation).
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override
Draw an image to the screen, given an amount of params defined above.
Sprite * Encode(SpriteType sprite_type, const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override
Convert a sprite from the loader to our own format.
std::string_view GetName() override
Get the name of the blitter, the same as the Factory-instance returns.
SpriteCollMap< Sprite > SpriteCollection
Type defining a collection of sprites, one for each zoom level.
@ Sprite
FaceVar describes an offset to the given SpriteID.
bool HasCPUIDFlag(uint type, uint index, uint bit)
Check whether the current CPU has the given flag.
Definition cpu.cpp:80
SpriteType
Types of sprites that might be loaded.
Definition gfx_type.h:357
ZoomLevel
All zoom levels we know.
Definition zoom_type.h:20