Browse Source

Completed video subsystem and SdlWindow impl.

master
Ian Burgmyer 4 years ago
parent
commit
a6b8d9f06e
  1. 5
      libplip/PlipVideo.h
  2. 24
      plip-sdl/SdlWindow.cpp
  3. 17
      plip-sdl/SdlWindow.h

5
libplip/PlipVideo.h

@ -20,9 +20,14 @@ namespace Plip {
class PlipVideo {
public:
virtual bool BeginDraw() = 0;
virtual void Draw(void *data) = 0;
virtual void Clear() = 0;
virtual bool EndDraw() = 0;
virtual PlipVideoFormat GetFormat() = 0;
virtual void Resize(int width, int height) = 0;
virtual void SetTitle(std::string title) = 0;
virtual void Render() = 0;
protected:
PlipVideo() = default;

24
plip-sdl/SdlWindow.cpp

@ -64,6 +64,14 @@ namespace PlipSdl {
if(m_window != nullptr) SDL_DestroyWindow(m_window);
}
bool SdlWindow::BeginDraw() {
return SDL_LockTexture(m_texture, nullptr, &m_texData, &m_pitch) == 0;
}
void SdlWindow::Clear() {
SDL_RenderClear(m_renderer);
}
void SdlWindow::CreateTexture() {
if(m_texture != nullptr) SDL_DestroyTexture(m_texture);
@ -87,6 +95,8 @@ namespace PlipSdl {
case Plip::PlipVideoFormat::BGRA8888:
pixelFormat = SDL_PIXELFORMAT_BGRA8888;
break;
default:
throw Plip::PlipVideoException("Unsupported pixel format.");
}
m_texture = nullptr;
@ -101,10 +111,24 @@ namespace PlipSdl {
}
}
void SdlWindow::Draw(void *data) {
memcpy(m_texData, data, m_pitch * m_height);
}
bool SdlWindow::EndDraw() {
SDL_UnlockTexture(m_texture);
return true;
}
Plip::PlipVideoFormat SdlWindow::GetFormat() {
return m_format;
}
void SdlWindow::Render() {
SDL_RenderCopy(m_renderer, m_texture, nullptr, nullptr);
SDL_RenderPresent(m_renderer);
}
void SdlWindow::Resize(int width, int height) {
m_width = width;
m_height = height;

17
plip-sdl/SdlWindow.h

@ -15,7 +15,12 @@ namespace PlipSdl {
explicit SdlWindow(int scale = 1, const std::string &title = "");
~SdlWindow();
bool BeginDraw() override;
void Clear() override;
void Draw(void *data) override;
bool EndDraw() override;
Plip::PlipVideoFormat GetFormat() override;
void Render() override;
void Resize(int width, int height) override;
void SetScale(int scale);
void SetTitle(std::string title) override;
@ -24,18 +29,20 @@ namespace PlipSdl {
void CreateTexture();
bool SelectFormat(uint32_t format);
const int m_init_width = 64;
const int m_init_height = 64;
const int m_initWidth = 64;
const int m_initHeight = 64;
int m_width = m_init_width;
int m_height = m_init_height;
int m_width = m_initWidth;
int m_height = m_initHeight;
int m_scale;
void *m_texData = nullptr;
int m_pitch = -1;
SDL_Window *m_window = nullptr;
SDL_Renderer *m_renderer = nullptr;
SDL_Texture *m_texture = nullptr;
Plip::PlipVideoFormat m_format = Plip::PlipVideoFormat::Unknown;
};
}

Loading…
Cancel
Save