Update: Translations from eints
[openttd-github.git] / src / blitter / 32bpp_sse2.hpp
blobebbb31e0593e3a81950b1ff81c0e836580e16f17
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 */
8 /** @file 32bpp_sse2.hpp SSE2 32 bpp blitter. */
10 #ifndef BLITTER_32BPP_SSE2_HPP
11 #define BLITTER_32BPP_SSE2_HPP
13 #ifdef WITH_SSE
15 #ifndef SSE_VERSION
16 #define SSE_VERSION 2
17 #endif
19 #ifndef SSE_TARGET
20 #define SSE_TARGET "sse2"
21 #endif
23 #ifndef FULL_ANIMATION
24 #define FULL_ANIMATION 0
25 #endif
27 #include "32bpp_sse_type.h"
29 /** Base methods for 32bpp SSE blitters. */
30 class Blitter_32bppSSE_Base {
31 public:
32 virtual ~Blitter_32bppSSE_Base() = default;
34 struct MapValue {
35 uint8_t m;
36 uint8_t v;
38 static_assert(sizeof(MapValue) == 2);
40 /** Helper for creating specialised functions for specific optimisations. */
41 enum ReadMode {
42 RM_WITH_SKIP, ///< Use normal code for skipping empty pixels.
43 RM_WITH_MARGIN, ///< Use cached number of empty pixels at begin and end of line to reduce work.
44 RM_NONE, ///< No specialisation.
47 /** Helper for creating specialised functions for the case where the sprite width is odd or even. */
48 enum BlockType {
49 BT_EVEN, ///< An even number of pixels in the width; no need for a special case for the last pixel.
50 BT_ODD, ///< An odd number of pixels in the width; special case for the last pixel.
51 BT_NONE, ///< No specialisation for either case.
54 /** Helper for using specialised functions designed to prevent whenever it's possible things like:
55 * - IO (reading video buffer),
56 * - calculations (alpha blending),
57 * - heavy branching (remap lookups and animation buffer handling).
59 enum SpriteFlags {
60 SF_NONE = 0,
61 SF_TRANSLUCENT = 1 << 1, ///< The sprite has at least 1 translucent pixel.
62 SF_NO_REMAP = 1 << 2, ///< The sprite has no remappable colour pixel.
63 SF_NO_ANIM = 1 << 3, ///< The sprite has no palette animated pixel.
66 /** Data stored about a (single) sprite. */
67 struct SpriteInfo {
68 uint32_t sprite_offset; ///< The offset to the sprite data.
69 uint32_t mv_offset; ///< The offset to the map value data.
70 uint16_t sprite_line_size; ///< The size of a single line (pitch).
71 uint16_t sprite_width; ///< The width of the sprite.
73 struct SpriteData {
74 SpriteFlags flags;
75 SpriteInfo infos[ZOOM_LVL_END];
76 uint8_t data[]; ///< Data, all zoomlevels.
79 Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator);
82 DECLARE_ENUM_AS_BIT_SET(Blitter_32bppSSE_Base::SpriteFlags);
84 /** The SSE2 32 bpp blitter (without palette animation). */
85 class Blitter_32bppSSE2 : public Blitter_32bppSimple, public Blitter_32bppSSE_Base {
86 public:
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);
91 Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override {
92 return Blitter_32bppSSE_Base::Encode(sprite, allocator);
95 std::string_view GetName() override { return "32bpp-sse2"; }
98 /** Factory for the SSE2 32 bpp blitter (without palette animation). */
99 class FBlitter_32bppSSE2 : public BlitterFactory {
100 public:
101 FBlitter_32bppSSE2() : BlitterFactory("32bpp-sse2", "32bpp SSE2 Blitter (no palette animation)", HasCPUIDFlag(1, 3, 26)) {}
102 Blitter *CreateInstance() override { return new Blitter_32bppSSE2(); }
105 #endif /* WITH_SSE */
106 #endif /* BLITTER_32BPP_SSE2_HPP */