Browse Source
* Implemented a format-agnostic way of plotting pixels and getting the number of bytes per pixel. * PlipInput can no longer be inherited. * Added width/height getters to the video subsystem. * Properly initialized SDL2 and added a temporary event loop (required to get the window to appear on macOS). * Sorted all source files into appropriately named directories.master
Ian Burgmyer
4 years ago
29 changed files with 254 additions and 106 deletions
@ -1,35 +0,0 @@
|
||||
/* PlipVideo.h
|
||||
* |
||||
* Provides a toolkit-agnostic video interface. |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include <string> |
||||
|
||||
namespace Plip { |
||||
enum class PlipVideoFormat { |
||||
Unknown, |
||||
RGB888, |
||||
BGR888, |
||||
ARGB8888, |
||||
ABGR8888, |
||||
RGBA8888, |
||||
BGRA8888 |
||||
}; |
||||
|
||||
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; |
||||
}; |
||||
} |
@ -0,0 +1,46 @@
|
||||
/* PlipVideo.cpp
|
||||
* |
||||
* Provides a toolkit-agnostic video interface. |
||||
*/ |
||||
|
||||
#include "PlipVideo.h" |
||||
#include "PlipVideoException.h" |
||||
|
||||
namespace Plip { |
||||
PlipVideoFormatInfo PlipVideo::GetFormatInfo(PlipVideoFormat format) { |
||||
switch(format) { |
||||
case PlipVideoFormat::RGB888: |
||||
return { .pixelWidth = 3, .plot = PlipVideo::PlotRgb888 }; |
||||
|
||||
case PlipVideoFormat::BGR888: |
||||
return { .pixelWidth = 3, .plot = PlipVideo::PlotBgr888 }; |
||||
|
||||
case PlipVideoFormat::XRGB8888: |
||||
return { .pixelWidth = 4, .plot = PlipVideo::PlotArgb8888 }; |
||||
|
||||
case PlipVideoFormat::XBGR8888: |
||||
return { .pixelWidth = 4, .plot = PlipVideo::PlotAbgr8888 }; |
||||
|
||||
case PlipVideoFormat::ARGB8888: |
||||
return { .pixelWidth = 4, .plot = PlipVideo::PlotArgb8888 }; |
||||
|
||||
case PlipVideoFormat::ABGR8888: |
||||
return { .pixelWidth = 4, .plot = PlipVideo::PlotAbgr8888 }; |
||||
|
||||
case PlipVideoFormat::RGBX8888: |
||||
return { .pixelWidth = 4, .plot = PlipVideo::PlotRgba8888 }; |
||||
|
||||
case PlipVideoFormat::BGRX8888: |
||||
return { .pixelWidth = 4, .plot = PlipVideo::PlotBgra8888 }; |
||||
|
||||
case PlipVideoFormat::RGBA8888: |
||||
return { .pixelWidth = 4, .plot = PlipVideo::PlotRgba8888 }; |
||||
|
||||
case PlipVideoFormat::BGRA8888: |
||||
return { .pixelWidth = 4, .plot = PlipVideo::PlotBgra8888 }; |
||||
|
||||
default: |
||||
throw PlipVideoException("Unsupported pixel format."); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,77 @@
|
||||
/* PlipVideo.h
|
||||
* |
||||
* Provides a toolkit-agnostic video interface. |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include <string> |
||||
|
||||
namespace Plip { |
||||
enum class PlipVideoFormat { |
||||
Unknown, |
||||
RGB888, |
||||
BGR888, |
||||
XRGB8888, |
||||
XBGR8888, |
||||
ARGB8888, |
||||
ABGR8888, |
||||
RGBX8888, |
||||
BGRX8888, |
||||
RGBA8888, |
||||
BGRA8888 |
||||
}; |
||||
|
||||
struct PlipVideoFormatInfo { |
||||
uint8_t pixelWidth; |
||||
void (*plot)(void* data, int offset, uint8_t r, uint8_t g, uint8_t b); |
||||
}; |
||||
|
||||
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 int GetHeight() = 0; |
||||
virtual int GetWidth() = 0; |
||||
virtual void Resize(int width, int height) = 0; |
||||
virtual void SetTitle(std::string title) = 0; |
||||
virtual void Render() = 0; |
||||
|
||||
static PlipVideoFormatInfo GetFormatInfo(PlipVideoFormat format); |
||||
|
||||
// Pixel format functions.
|
||||
static void PlotRgb888(void *data, int offset, uint8_t r, uint8_t g, uint8_t b) { |
||||
((uint8_t*)data)[offset * 3] = r; |
||||
((uint8_t*)data)[offset * 3 + 1] = g; |
||||
((uint8_t*)data)[offset * 3 + 2] = b; |
||||
} |
||||
|
||||
static void PlotBgr888(void *data, int offset, uint8_t r, uint8_t g, uint8_t b) { |
||||
((uint8_t*)data)[offset * 3] = b; |
||||
((uint8_t*)data)[offset * 3 + 1] = g; |
||||
((uint8_t*)data)[offset * 3 + 2] = r; |
||||
} |
||||
|
||||
static void PlotArgb8888(void *data, int offset, uint8_t r, uint8_t g, uint8_t b) { |
||||
((uint32_t*)data)[offset] = (0xFF << 24) + (r << 16) + (g << 8) + b; |
||||
} |
||||
|
||||
static void PlotAbgr8888(void *data, int offset, uint8_t r, uint8_t g, uint8_t b) { |
||||
((uint32_t*)data)[offset] = (0xFF << 24) + (b << 16) + (g << 8) + r; |
||||
} |
||||
|
||||
static void PlotRgba8888(void *data, int offset, uint8_t r, uint8_t g, uint8_t b) { |
||||
((uint32_t*)data)[offset] = (r << 24) + (g << 16) + (b << 8) + 0xFF; |
||||
} |
||||
|
||||
static void PlotBgra8888(void *data, int offset, uint8_t r, uint8_t g, uint8_t b) { |
||||
((uint32_t*)data)[offset] = (b << 24) + (g << 16) + (r << 8) + 0xFF; |
||||
} |
||||
|
||||
protected: |
||||
PlipVideo() = default; |
||||
}; |
||||
} |
@ -0,0 +1,13 @@
|
||||
/* SdlEvent.h
|
||||
* |
||||
* An SDL2 event handler. |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include "Input/PlipInput.h" |
||||
|
||||
namespace PlipSdl { |
||||
class SdlEvent { |
||||
}; |
||||
} |
@ -1,15 +0,0 @@
|
||||
/* SdlEvent.h
|
||||
* |
||||
* An SDL2 event handler. |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include "PlipInput.h" |
||||
|
||||
namespace PlipSdl { |
||||
class SdlEvent : public Plip::PlipInput { |
||||
public: |
||||
SdlEvent() = default; |
||||
}; |
||||
} |
Loading…
Reference in new issue