OpenTTD Source 20241224-master-gee860a5c8e
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 <http://www.gnu.org/licenses/>.
6 */
7
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:
32 virtual ~Blitter_32bppSSE_Base() = default;
33
34 struct MapValue {
35 uint8_t m;
36 uint8_t v;
37 };
38 static_assert(sizeof(MapValue) == 2);
39
41 enum ReadMode {
42 RM_WITH_SKIP,
43 RM_WITH_MARGIN,
44 RM_NONE,
45 };
46
48 enum BlockType {
49 BT_EVEN,
50 BT_ODD,
51 BT_NONE,
52 };
53
59 enum SpriteFlags {
60 SF_NONE = 0,
61 SF_TRANSLUCENT = 1 << 1,
62 SF_NO_REMAP = 1 << 2,
63 SF_NO_ANIM = 1 << 3,
64 };
65
67 struct SpriteInfo {
68 uint32_t sprite_offset;
69 uint32_t mv_offset;
70 uint16_t sprite_line_size;
71 uint16_t sprite_width;
72 };
73 struct SpriteData {
74 SpriteFlags flags;
75 SpriteInfo infos[ZOOM_LVL_END];
76 uint8_t data[];
77 };
78
79 Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator);
80};
81
82DECLARE_ENUM_AS_BIT_SET(Blitter_32bppSSE_Base::SpriteFlags);
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(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override {
92 return Blitter_32bppSSE_Base::Encode(sprite, allocator);
93 }
94
95 std::string_view GetName() override { return "32bpp-sse2"; }
96};
97
99class FBlitter_32bppSSE2 : public BlitterFactory {
100public:
101 FBlitter_32bppSSE2() : BlitterFactory("32bpp-sse2", "32bpp SSE2 Blitter (no palette animation)", HasCPUIDFlag(1, 3, 26)) {}
102 Blitter *CreateInstance() override { return new Blitter_32bppSSE2(); }
103};
104
105#endif /* WITH_SSE */
106#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 Blitter * CreateInstance()=0
Create an instance of this Blitter-class.
The most trivial 32 bpp blitter (without palette animation).
Sprite * Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override
Convert a sprite from the loader to our own format.
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override
Draw an image to the screen, given an amount of params defined above.
std::string_view GetName() override
Get the name of the blitter, the same as the Factory-instance returns.
How all blitters should look like.
Definition base.hpp:29
Interface for something that can allocate memory for a sprite.
std::array< Sprite, ZOOM_LVL_END > SpriteCollection
Type defining a collection of sprites, one for each zoom level.
bool HasCPUIDFlag(uint type, uint index, uint bit)
Check whether the current CPU has the given flag.
Definition cpu.cpp:84
#define DECLARE_ENUM_AS_BIT_SET(enum_type)
Operators to allow to work with enum as with type safe bit set in C++.
Definition enum_type.hpp:35
Parameters related to blitting.
Definition base.hpp:32
Data structure describing a sprite.
Definition spritecache.h:17
ZoomLevel
All zoom levels we know.
Definition zoom_type.h:16
@ ZOOM_LVL_END
End for iteration.
Definition zoom_type.h:25