1 /* $Id$ */ 2 3 /* 4 * This file is part of OpenTTD. 5 * 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. 6 * 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. 7 * 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 */ 9 10 /** @file 40bpp_optimized.hpp Optimized 40 bpp blitter. */ 11 12 #ifndef BLITTER_40BPP_OPTIMIZED_HPP 13 #define BLITTER_40BPP_OPTIMIZED_HPP 14 15 16 #include "32bpp_optimized.hpp" 17 #include "../video/video_driver.hpp" 18 19 /** The optimized 40 bpp blitter (for OpenGL video driver). */ 20 class Blitter_40bppAnim : public Blitter_32bppOptimized { 21 public: 22 23 // void *MoveTo(void *video, int x, int y) override; 24 void SetPixel(void *video, int x, int y, uint8 colour) override; 25 void DrawRect(void *video, int width, int height, uint8 colour) override; 26 void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash) override; 27 void CopyFromBuffer(void *video, const void *src, int width, int height) override; 28 void CopyToBuffer(const void *video, void *dst, int width, int height) override; 29 void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) override; 30 void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) override; 31 void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override; 32 void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override; 33 Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override; 34 int BufferSize(int width, int height) override; 35 Blitter::PaletteAnimation UsePaletteAnimation() override; 36 bool NeedsAnimationBuffer() override; 37 GetName()38 const char *GetName() override { return "40bpp-anim"; } GetBytesPerPixel()39 int GetBytesPerPixel() override { return 5; } 40 41 template <BlitterMode mode> void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom); 42 43 protected: RealizeBlendedColour(uint8 anim,Colour c)44 static inline Colour RealizeBlendedColour(uint8 anim, Colour c) 45 { 46 return anim != 0 ? AdjustBrightness(LookupColourInPalette(anim), GetColourBrightness(c)) : c; 47 } 48 49 }; 50 51 /** Factory for the 40 bpp animated blitter (for OpenGL). */ 52 class FBlitter_40bppAnim : public BlitterFactory { 53 protected: IsUsable() const54 bool IsUsable() const override 55 { 56 return VideoDriver::GetInstance() == nullptr || VideoDriver::GetInstance()->HasAnimBuffer(); 57 } 58 59 public: FBlitter_40bppAnim()60 FBlitter_40bppAnim() : BlitterFactory("40bpp-anim", "40bpp Animation Blitter (OpenGL)") {} CreateInstance()61 Blitter *CreateInstance() override { return new Blitter_40bppAnim(); } 62 }; 63 64 #endif /* BLITTER_40BPP_OPTIMIZED_HPP */ 65