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 <span>
8#include <SDL.h>
9
10namespace openmsx {
11
13{
14public:
15 SDLDirectPixelAccess(SDL_Surface* surface_);
17
18 template<std::unsigned_integral Pixel>
19 [[nodiscard]] std::span<Pixel> getLine(unsigned y) {
20 return {reinterpret_cast<Pixel*>(static_cast<char*>(surface->pixels) + y * surface->pitch),
21 size_t(surface->w)};
22 }
23
24private:
25 SDL_Surface* surface;
26};
27
33{
34public:
37
38 [[nodiscard]] SDL_Surface* getSDLSurface() const { return surface; }
39 [[nodiscard]] SDL_Renderer* getSDLRenderer() const { return renderer; }
40
53 {
54 return {getSDLSurface()};
55 }
56
60 virtual void flushFrameBuffer() {}
61
65 virtual void clearScreen() {}
66
67protected:
68 SDLOutputSurface() = default;
69
70 void setSDLPixelFormat(const SDL_PixelFormat& format);
71 void setSDLSurface(SDL_Surface* surface_) { surface = surface_; }
72 void setSDLRenderer(SDL_Renderer* r) { renderer = r; }
73
74private:
75 SDL_Surface* surface = nullptr;
76 SDL_Renderer* renderer = nullptr;
77};
78
79} // namespace openmsx
80
81#endif
A frame buffer where pixels can be written to.
std::span< Pixel > getLine(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.
SDL_Renderer * getSDLRenderer() const
SDL_Surface * getSDLSurface() const
virtual void clearScreen()
Clear frame buffer (paint it black).
SDLDirectPixelAccess getDirectPixelAccess()
Return a SDLDirectPixelAccess object.
void setSDLPixelFormat(const SDL_PixelFormat &format)
SDLOutputSurface(const SDLOutputSurface &)=delete
SDLOutputSurface & operator=(const SDLOutputSurface &)=delete
void setSDLRenderer(SDL_Renderer *r)
This file implemented 3 utility functions:
Definition: Autofire.cc:9
uint32_t Pixel