Display interface and transfered control to render modules
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "../display/display.hpp"
|
||||
#include "../pixel.hpp"
|
||||
#include "./renderer.hpp"
|
||||
|
||||
Renderer::Renderer(OperationMode mode) {
|
||||
@@ -35,14 +36,29 @@ void Renderer::Init() {
|
||||
|
||||
}
|
||||
|
||||
void Renderer::Init(Display* display) {
|
||||
void Renderer::Init(DisplayInterface* display) {
|
||||
// Add warning
|
||||
if (!display) return;
|
||||
m_framebuffer = display->Framebuffer;
|
||||
if(!m_framebuffer) {
|
||||
m_framebuffer = display->Framebuffer;
|
||||
}
|
||||
m_interface = display;
|
||||
}
|
||||
|
||||
void Renderer::RenderProgressive() {
|
||||
while (m_interface->Active) {
|
||||
SDL_Event e;
|
||||
while (SDL_PollEvent(&e) == SDL_TRUE)
|
||||
if (e.type == SDL_QUIT) m_interface->Close();
|
||||
|
||||
for (int i = 0; i < 360000; i++) {
|
||||
m_interface->SetPixelSafe(rand() % m_interface->XRes,
|
||||
rand() % m_interface->YRes,
|
||||
rgb888(rand() % 255, rand() % 255, rand() % 255));
|
||||
}
|
||||
|
||||
m_interface->Update();
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::RenderSamples() {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
class Display;
|
||||
class DisplayInterface;
|
||||
|
||||
// Function initProgressive or whatever takes a pointer to the display
|
||||
class Renderer {
|
||||
@@ -13,7 +13,8 @@ public:
|
||||
void SetMode(OperationMode mode, int samples = -1);
|
||||
|
||||
void Init();
|
||||
void Init(Display* display);
|
||||
|
||||
void Init(DisplayInterface* display);
|
||||
|
||||
void Render();
|
||||
void Render(uint32_t* framebuffer);
|
||||
@@ -22,6 +23,7 @@ private:
|
||||
int m_samples = -1;
|
||||
OperationMode m_mode = MODE_DEFAULT;
|
||||
|
||||
DisplayInterface* m_interface = nullptr;
|
||||
uint32_t* m_framebuffer = nullptr;
|
||||
|
||||
void RenderProgressive();
|
||||
|
||||
@@ -4,10 +4,15 @@
|
||||
|
||||
#include "../pixel.hpp"
|
||||
|
||||
Display::Display() {
|
||||
Display::Display()
|
||||
: DisplayInterface() {
|
||||
|
||||
}
|
||||
|
||||
bool Display::Init() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Display::InitVideoDisplay(std::string title, int x, int y) {
|
||||
this->XRes = x; this->YRes = y;
|
||||
|
||||
@@ -23,7 +28,7 @@ bool Display::InitVideoDisplay(std::string title, int x, int y) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->WindowOpen = true;
|
||||
this->Active = true;
|
||||
|
||||
m_renderer = SDL_CreateRenderer(
|
||||
m_window, -1, SDL_RENDERER_ACCELERATED
|
||||
@@ -83,13 +88,13 @@ void Display::SetFramebuffer(uint32_t* fb) {
|
||||
Framebuffer = fb;
|
||||
}
|
||||
|
||||
void Display::Refresh() {
|
||||
void Display::Update() {
|
||||
SDL_UpdateTexture(m_texture, NULL, Framebuffer, this->XRes * sizeof(uint32_t));
|
||||
SDL_RenderCopy(m_renderer, m_texture, NULL, NULL);
|
||||
SDL_RenderPresent(m_renderer);
|
||||
}
|
||||
|
||||
void Display::CloseDisplay() {
|
||||
void Display::Close() {
|
||||
free(Framebuffer);
|
||||
SDL_DestroyTexture(m_texture);
|
||||
SDL_DestroyRenderer(m_renderer);
|
||||
|
||||
@@ -5,32 +5,27 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "./displayinterface.hpp"
|
||||
|
||||
class Pixel;
|
||||
|
||||
class Display {
|
||||
class Display : public DisplayInterface {
|
||||
public:
|
||||
Display();
|
||||
|
||||
bool Init() override;
|
||||
bool InitVideoDisplay(std::string title, int x, int y);
|
||||
|
||||
bool WindowOpen = false;
|
||||
int XRes, YRes;
|
||||
std::string Title;
|
||||
unsigned int Scale = 1;
|
||||
void SetPixel(int x, int y, Pixel p) override;
|
||||
void SetPixel(int x, int y, uint32_t p) override;
|
||||
void SetPixelSafe(int x, int y, Pixel p) override;
|
||||
void SetPixelSafe(int x, int y, uint32_t p) override;
|
||||
|
||||
void SetPixel(int x, int y, Pixel p);
|
||||
void SetPixel(int x, int y, uint32_t p);
|
||||
void SetPixelSafe(int x, int y, Pixel p);
|
||||
void SetPixelSafe(int x, int y, uint32_t p);
|
||||
|
||||
uint32_t* Framebuffer;
|
||||
void SetFramebuffer(uint32_t* fb);
|
||||
|
||||
void Refresh();
|
||||
void Update() override;
|
||||
|
||||
// Error and warn
|
||||
|
||||
void CloseDisplay();
|
||||
void Close() override;
|
||||
|
||||
virtual ~Display();
|
||||
private:
|
||||
@@ -38,7 +33,6 @@ private:
|
||||
SDL_Window* m_window;
|
||||
SDL_Renderer* m_renderer;
|
||||
SDL_Texture* m_texture;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
5
src/display/displayinterface.cpp
Normal file
5
src/display/displayinterface.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "./displayinterface.hpp"
|
||||
|
||||
DisplayInterface::DisplayInterface() {
|
||||
|
||||
}
|
||||
29
src/display/displayinterface.hpp
Normal file
29
src/display/displayinterface.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef INFERNO_DISPLAY_DISPLAYINTERFACE_H_
|
||||
#define INFERNO_DISPLAY_DISPLAYINTERFACE_H_
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
class Pixel;
|
||||
|
||||
class DisplayInterface {
|
||||
public:
|
||||
DisplayInterface();
|
||||
|
||||
bool Active = false;
|
||||
int XRes, YRes;
|
||||
std::string Title;
|
||||
unsigned int Scale = 1;
|
||||
|
||||
uint32_t* Framebuffer;
|
||||
|
||||
virtual void SetPixel(int x, int y, Pixel p) = 0;
|
||||
virtual void SetPixel(int x, int y, uint32_t p) = 0;
|
||||
virtual void SetPixelSafe(int x, int y, Pixel p) = 0;
|
||||
virtual void SetPixelSafe(int x, int y, uint32_t p) = 0;
|
||||
|
||||
virtual bool Init() = 0;
|
||||
virtual void Update() = 0;
|
||||
virtual void Close() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -51,19 +51,6 @@ void InfernoEngine::Ready() {
|
||||
|
||||
void InfernoEngine::Render() {
|
||||
m_renderer->Render(m_display->Framebuffer);
|
||||
while (m_display->WindowOpen) {
|
||||
SDL_Event e;
|
||||
while (SDL_PollEvent(&e) == SDL_TRUE)
|
||||
if (e.type == SDL_QUIT) m_display->CloseDisplay();
|
||||
|
||||
for (int i = 0; i < 360000; i++) {
|
||||
m_display->SetPixelSafe(rand() % m_display->XRes,
|
||||
rand() % m_display->YRes,
|
||||
rgb888(rand() % 255, rand() % 255, rand() % 255));
|
||||
}
|
||||
|
||||
m_display->Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
std::string InfernoEngine::LastError() {
|
||||
|
||||
Reference in New Issue
Block a user