OpenTTD Source: src/blitter/32bpp_sse2.hpp Source File

OpenTTD Source 15.0-RC2

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
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 : uint8_t {
42 RM_WITH_SKIP,
43 RM_WITH_MARGIN,
44 RM_NONE,
45 };
46
48 enum BlockType : uint8_t {
49 BT_EVEN,
50 BT_ODD,
51 BT_NONE,
52 };
53
59 enum class SpriteFlag : uint8_t {
60 Translucent,
61 NoRemap,
62 NoAnim,
63 };
64
65 using SpriteFlags = EnumBitSet<SpriteFlag, uint8_t>;
66
68 struct SpriteInfo {
69 uint32_t sprite_offset = 0;
70 uint32_t mv_offset = 0;
71 uint16_t sprite_line_size = 0;
72 uint16_t sprite_width = 0;
73 };
74 struct SpriteData {
75 SpriteFlags flags{};
76 SpriteCollMap<SpriteInfo> infos{};
77 uint8_t data[];
78 };
79
80 Sprite *Encode(SpriteType sprite_type, const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator);
81};
82
84class Blitter_32bppSSE2 : public Blitter_32bppSimple, public Blitter_32bppSSE_Base {
85public:
86 void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
87 template <BlitterMode mode, Blitter_32bppSSE_Base::ReadMode read_mode, Blitter_32bppSSE_Base::BlockType bt_last, bool translucent>
88 void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
89
90 Sprite *Encode(SpriteType sprite_type, const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override
91 {
92 return Blitter_32bppSSE_Base::Encode(sprite_type, 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 std::unique_ptr<Blitter> CreateInstance() override { return std::make_unique<Blitter_32bppSSE2>(); }
103};
104
105#endif /* WITH_SSE */
106#endif /* BLITTER_32BPP_SSE2_HPP */
32bpp_sse_type.h
Types related to SSE 32 bpp blitter.
BlitterMode
BlitterMode
The modes of blitting we can do.
Definition base.hpp:17
BlitterFactory
The base factory, keeping track of all blitters.
Definition factory.hpp:21
BlitterFactory::CreateInstance
virtual std::unique_ptr< Blitter > CreateInstance()=0
Create an instance of this Blitter-class.
Blitter_32bppSimple
The most trivial 32 bpp blitter (without palette animation).
Definition 32bpp_simple.hpp:17
Blitter_32bppSimple::Draw
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override
Draw an image to the screen, given an amount of params defined above.
Definition 32bpp_simple.cpp:22
Blitter_32bppSimple::Encode
Sprite * Encode(SpriteType sprite_type, const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override
Convert a sprite from the loader to our own format.
Definition 32bpp_simple.cpp:118
Blitter_32bppSimple::GetName
std::string_view GetName() override
Get the name of the blitter, the same as the Factory-instance returns.
Definition 32bpp_simple.hpp:31
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
SpriteAllocator
Interface for something that can allocate memory for a sprite.
Definition spriteloader.hpp:104
SpriteCollMap
Map zoom level to data.
Definition spriteloader.hpp:34
HasCPUIDFlag
bool HasCPUIDFlag(uint type, uint index, uint bit)
Check whether the current CPU has the given flag.
Definition cpu.cpp:84
SpriteType
SpriteType
Types of sprites that might be loaded.
Definition gfx_type.h:357
Blitter::BlitterParams
Parameters related to blitting.
Definition base.hpp:32
Sprite
Data structure describing a sprite.
Definition spritecache_type.h:16
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition zoom_type.h:20