openMSX
SDLOutputSurface.hh
Go to the documentation of this file.
1 #ifndef SDLOUTPUTSURFACE_HH
2 #define SDLOUTPUTSURFACE_HH
3 
4 #include "OutputSurface.hh"
5 #include <cassert>
6 #include <concepts>
7 #include <SDL.h>
8 
9 namespace openmsx {
10 
12 {
13 public:
14  SDLDirectPixelAccess(SDL_Surface* surface_);
16 
17  template<std::unsigned_integral Pixel>
18  [[nodiscard]] Pixel* getLinePtr(unsigned y) {
19  return reinterpret_cast<Pixel*>(static_cast<char*>(surface->pixels) + y * surface->pitch);
20  }
21 
22 private:
23  SDL_Surface* surface;
24 };
25 
31 {
32 public:
35 
36  [[nodiscard]] SDL_Surface* getSDLSurface() const { return surface; }
37  [[nodiscard]] SDL_Renderer* getSDLRenderer() const { return renderer; }
38 
51  {
53  }
54 
58  virtual void flushFrameBuffer() {}
59 
63  virtual void clearScreen() {}
64 
65 protected:
66  SDLOutputSurface() = default;
67 
68  void setSDLPixelFormat(const SDL_PixelFormat& format);
69  void setSDLSurface(SDL_Surface* surface_) { surface = surface_; }
70  void setSDLRenderer(SDL_Renderer* r) { renderer = r; }
71 
72 private:
73  SDL_Surface* surface = nullptr;
74  SDL_Renderer* renderer = nullptr;
75 };
76 
77 } // namespace openmsx
78 
79 #endif
A frame buffer where pixels can be written to.
Pixel * getLinePtr(unsigned y)
SDLDirectPixelAccess(SDL_Surface *surface_)
A frame buffer where pixels can be written to.
void setSDLSurface(SDL_Surface *surface_)
virtual void flushFrameBuffer()
Copy frame buffer to display buffer.
virtual void clearScreen()
Clear frame buffer (paint it black).
SDLDirectPixelAccess getDirectPixelAccess()
Return a SDLDirectPixelAccess object.
SDL_Surface * getSDLSurface() const
SDLOutputSurface & operator=(const SDLOutputSurface &)=delete
void setSDLPixelFormat(const SDL_PixelFormat &format)
SDL_Renderer * getSDLRenderer() const
SDLOutputSurface(const SDLOutputSurface &)=delete
void setSDLRenderer(SDL_Renderer *r)
This file implemented 3 utility functions:
Definition: Autofire.cc:9
uint32_t Pixel