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/>.
8 /** @file 32bpp_sse2.hpp SSE2 32 bpp blitter. */
10 #ifndef BLITTER_32BPP_SSE2_HPP
11 #define BLITTER_32BPP_SSE2_HPP
19 #ifndef FULL_ANIMATION
20 #define FULL_ANIMATION 0
23 #include "32bpp_sse_type.h"
25 /** Base methods for 32bpp SSE blitters. */
26 class Blitter_32bppSSE_Base
{
28 virtual ~Blitter_32bppSSE_Base() {}
34 assert_compile(sizeof(MapValue
) == 2);
36 /** Helper for creating specialised functions for specific optimisations. */
38 RM_WITH_SKIP
, ///< Use normal code for skipping empty pixels.
39 RM_WITH_MARGIN
, ///< Use cached number of empty pixels at begin and end of line to reduce work.
40 RM_NONE
, ///< No specialisation.
43 /** Helper for creating specialised functions for the case where the sprite width is odd or even. */
45 BT_EVEN
, ///< An even number of pixels in the width; no need for a special case for the last pixel.
46 BT_ODD
, ///< An odd number of pixels in the width; special case for the last pixel.
47 BT_NONE
, ///< No specialisation for either case.
50 /** Helper for using specialised functions designed to prevent whenever it's possible things like:
51 * - IO (reading video buffer),
52 * - calculations (alpha blending),
53 * - heavy branching (remap lookups and animation buffer handling).
57 SF_TRANSLUCENT
= 1 << 1, ///< The sprite has at least 1 translucent pixel.
58 SF_NO_REMAP
= 1 << 2, ///< The sprite has no remappable colour pixel.
59 SF_NO_ANIM
= 1 << 3, ///< The sprite has no palette animated pixel.
62 /** Data stored about a (single) sprite. */
64 uint32 sprite_offset
; ///< The offset to the sprite data.
65 uint32 mv_offset
; ///< The offset to the map value data.
66 uint16 sprite_line_size
; ///< The size of a single line (pitch).
67 uint16 sprite_width
; ///< The width of the sprite.
71 SpriteInfo infos
[ZOOM_LVL_COUNT
];
72 byte data
[]; ///< Data, all zoomlevels.
75 Sprite
*Encode(const SpriteLoader::Sprite
*sprite
, AllocatorProc
*allocator
);
78 DECLARE_ENUM_AS_BIT_SET(Blitter_32bppSSE_Base::SpriteFlags
);
80 /** The SSE2 32 bpp blitter (without palette animation). */
81 class Blitter_32bppSSE2
: public Blitter_32bppSimple
, public Blitter_32bppSSE_Base
{
83 void Draw(Blitter::BlitterParams
*bp
, BlitterMode mode
, ZoomLevel zoom
) override
;
84 template <BlitterMode mode
, Blitter_32bppSSE_Base::ReadMode read_mode
, Blitter_32bppSSE_Base::BlockType bt_last
, bool translucent
>
85 void Draw(const Blitter::BlitterParams
*bp
, ZoomLevel zoom
);
87 Sprite
*Encode(const SpriteLoader::Sprite
*sprite
, AllocatorProc
*allocator
) override
{
88 return Blitter_32bppSSE_Base::Encode(sprite
, allocator
);
91 const char *GetName() override
{ return "32bpp-sse2"; }
94 /** Factory for the SSE2 32 bpp blitter (without palette animation). */
95 class FBlitter_32bppSSE2
: public BlitterFactory
{
97 FBlitter_32bppSSE2() : BlitterFactory("32bpp-sse2", "32bpp SSE2 Blitter (no palette animation)", HasCPUIDFlag(1, 3, 26)) {}
98 Blitter
*CreateInstance() override
{ return new Blitter_32bppSSE2(); }
101 #endif /* WITH_SSE */
102 #endif /* BLITTER_32BPP_SSE2_HPP */