OpenTTD Source 20261123-master-g1c55c72fd0
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 "../cpu.h"
28#include "32bpp_sse_type.h"
29
31class Blitter_32bppSSE_Base {
32public:
34 virtual ~Blitter_32bppSSE_Base() = default;
35
36 struct MapValue {
37 uint8_t m;
38 uint8_t v;
39 };
40 static_assert(sizeof(MapValue) == 2);
41
43 enum class ReadMode : uint8_t {
44 WithSkip,
45 WithMargin,
46 None,
47 };
48
50 enum class BlockType : uint8_t {
51 Even,
52 Odd,
53 None,
54 };
55
61 enum class SpriteFlag : uint8_t {
62 Translucent,
63 NoRemap,
64 NoAnim,
65 };
66
68 using SpriteFlags = EnumBitSet<SpriteFlag, uint8_t>;
69
71 struct SpriteInfo {
72 uint32_t sprite_offset = 0;
73 uint32_t mv_offset = 0;
74 uint16_t sprite_line_size = 0;
75 uint16_t sprite_width = 0;
76 };
77 struct SpriteData {
78 SpriteFlags flags{};
79 SpriteCollMap<SpriteInfo> infos{};
80 uint8_t data[];
81 };
82
83 Sprite *Encode(SpriteType sprite_type, const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator);
84};
85
87class Blitter_32bppSSE2 : public Blitter_32bppSimple, public Blitter_32bppSSE_Base {
88public:
89 void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
90 template <BlitterMode mode, Blitter_32bppSSE_Base::ReadMode read_mode, Blitter_32bppSSE_Base::BlockType bt_last, bool translucent>
91 void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
92
93 Sprite *Encode(SpriteType sprite_type, const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override
94 {
95 return Blitter_32bppSSE_Base::Encode(sprite_type, sprite, allocator);
96 }
97
98 std::string_view GetName() override { return "32bpp-sse2"; }
99};
100
102class FBlitter_32bppSSE2 : public BlitterFactory {
103public:
104 FBlitter_32bppSSE2() : BlitterFactory("32bpp-sse2", "32bpp SSE2 Blitter (no palette animation)", HasCPUIDFlag(1, 3, 26)) {}
105 std::unique_ptr<Blitter> CreateInstance() override { return std::make_unique<Blitter_32bppSSE2>(); }
106};
107
108#endif /* WITH_SSE */
109#endif /* BLITTER_32BPP_SSE2_HPP */
Types related to SSE 32 bpp blitter.
@ None
Tile is not animated.
BlitterMode
The modes of blitting we can do.
Definition base.hpp:16
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
Functions related to CPU specific instructions.
SpriteType
Types of sprites that might be loaded.
Definition gfx_type.h:404
ZoomLevel
All zoom levels we know.
Definition zoom_type.h:20