2020-09-16 20:14:35 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-26 15:17:35 +00:00
|
|
|
//
|
2020-09-16 20:14:35 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-26 15:17:35 +00:00
|
|
|
// Renderer.h
|
|
|
|
//
|
2022-03-14 18:51:48 +00:00
|
|
|
// Generic rendering functions.
|
2020-06-26 15:17:35 +00:00
|
|
|
//
|
|
|
|
|
2019-08-08 20:16:11 +00:00
|
|
|
#ifndef ES_CORE_RENDERER_RENDERER_H
|
|
|
|
#define ES_CORE_RENDERER_RENDERER_H
|
|
|
|
|
2020-08-30 20:19:37 +00:00
|
|
|
#include "Log.h"
|
2021-08-17 20:11:16 +00:00
|
|
|
#include "utils/MathUtil.h"
|
2020-08-30 20:19:37 +00:00
|
|
|
|
2022-03-14 18:51:48 +00:00
|
|
|
#include <stack>
|
2020-08-30 20:19:37 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2019-08-08 20:16:11 +00:00
|
|
|
|
|
|
|
struct SDL_Window;
|
2022-03-14 18:51:48 +00:00
|
|
|
class Shader;
|
2019-08-08 20:16:11 +00:00
|
|
|
|
2022-03-14 18:51:48 +00:00
|
|
|
class Renderer
|
2019-08-08 20:16:11 +00:00
|
|
|
{
|
2022-03-14 18:51:48 +00:00
|
|
|
public:
|
2021-07-07 18:31:46 +00:00
|
|
|
struct Vertex {
|
2022-03-11 22:51:41 +00:00
|
|
|
glm::vec2 position;
|
|
|
|
glm::vec2 texture;
|
|
|
|
unsigned int color;
|
2022-03-11 22:17:04 +00:00
|
|
|
float opacity;
|
|
|
|
float saturation;
|
2022-03-11 22:51:41 +00:00
|
|
|
float dimming;
|
2022-03-11 22:17:04 +00:00
|
|
|
bool convertBGRAToRGBA;
|
2022-03-13 22:52:32 +00:00
|
|
|
bool font;
|
2022-03-12 16:57:59 +00:00
|
|
|
bool postProcessing;
|
2022-03-11 22:17:04 +00:00
|
|
|
unsigned int shaders;
|
|
|
|
|
|
|
|
Vertex()
|
|
|
|
: opacity {1.0f}
|
|
|
|
, saturation {1.0f}
|
2022-03-11 22:51:41 +00:00
|
|
|
, dimming {1.0f}
|
2022-03-11 22:17:04 +00:00
|
|
|
, convertBGRAToRGBA {false}
|
2022-03-13 22:52:32 +00:00
|
|
|
, font {false}
|
2022-03-12 16:57:59 +00:00
|
|
|
, postProcessing {false}
|
2022-03-11 22:17:04 +00:00
|
|
|
, shaders {0}
|
|
|
|
{
|
|
|
|
}
|
2022-03-14 18:51:48 +00:00
|
|
|
|
2021-08-19 19:39:01 +00:00
|
|
|
Vertex(const glm::vec2& position, const glm::vec2& textureCoord, const unsigned int color)
|
2022-03-11 22:51:41 +00:00
|
|
|
: position(position)
|
|
|
|
, texture(textureCoord)
|
|
|
|
, color(color)
|
2022-03-11 22:17:04 +00:00
|
|
|
, opacity {1.0f}
|
|
|
|
, saturation {1.0f}
|
2022-03-11 22:51:41 +00:00
|
|
|
, dimming {1.0f}
|
2022-03-11 22:17:04 +00:00
|
|
|
, convertBGRAToRGBA {false}
|
2022-03-13 22:52:32 +00:00
|
|
|
, font {false}
|
2022-03-12 16:57:59 +00:00
|
|
|
, postProcessing {false}
|
2022-03-11 22:17:04 +00:00
|
|
|
, shaders {0}
|
2021-07-07 18:31:46 +00:00
|
|
|
{
|
|
|
|
}
|
2020-06-26 15:17:35 +00:00
|
|
|
};
|
|
|
|
|
2022-03-14 18:51:48 +00:00
|
|
|
enum class BlendFactor {
|
|
|
|
ZERO,
|
|
|
|
ONE,
|
|
|
|
SRC_COLOR,
|
|
|
|
ONE_MINUS_SRC_COLOR,
|
|
|
|
SRC_ALPHA,
|
|
|
|
ONE_MINUS_SRC_ALPHA,
|
|
|
|
DST_COLOR,
|
|
|
|
ONE_MINUS_DST_COLOR,
|
|
|
|
DST_ALPHA,
|
|
|
|
ONE_MINUS_DST_ALPHA
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class TextureType {
|
|
|
|
RGBA, // Replace with AllowShortEnumsOnASingleLine: false (clang-format >=11.0).
|
|
|
|
BGRA,
|
|
|
|
RED
|
|
|
|
};
|
|
|
|
|
|
|
|
struct postProcessingParams {
|
|
|
|
float opacity;
|
|
|
|
float saturation;
|
|
|
|
float dimming;
|
|
|
|
bool convertBGRAToRGBA;
|
|
|
|
unsigned int blurPasses;
|
|
|
|
unsigned int shaders;
|
|
|
|
|
|
|
|
postProcessingParams()
|
|
|
|
: opacity {1.0f}
|
|
|
|
, saturation {1.0f}
|
|
|
|
, dimming {1.0f}
|
|
|
|
, convertBGRAToRGBA {false}
|
|
|
|
, blurPasses {1}
|
|
|
|
, shaders {0}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Rect {
|
|
|
|
Rect(const int xValue, const int yValue, const int wValue, const int hValue)
|
|
|
|
: x(xValue)
|
|
|
|
, y(yValue)
|
|
|
|
, w(wValue)
|
|
|
|
, h(hValue)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int w;
|
|
|
|
int h;
|
|
|
|
};
|
|
|
|
|
|
|
|
static Renderer* getInstance();
|
|
|
|
|
|
|
|
void setIcon();
|
|
|
|
bool createWindow();
|
|
|
|
void destroyWindow();
|
2020-06-26 15:17:35 +00:00
|
|
|
bool init();
|
|
|
|
void deinit();
|
2022-03-14 18:51:48 +00:00
|
|
|
|
|
|
|
virtual bool loadShaders() = 0;
|
|
|
|
|
2021-08-19 19:39:01 +00:00
|
|
|
void pushClipRect(const glm::ivec2& pos, const glm::ivec2& size);
|
2020-06-26 15:17:35 +00:00
|
|
|
void popClipRect();
|
2022-03-14 18:51:48 +00:00
|
|
|
|
2021-08-19 19:39:01 +00:00
|
|
|
void drawRect(const float x,
|
|
|
|
const float y,
|
|
|
|
const float w,
|
|
|
|
const float h,
|
|
|
|
const unsigned int color,
|
|
|
|
const unsigned int colorEnd,
|
2021-07-07 18:31:46 +00:00
|
|
|
bool horizontalGradient = false,
|
2021-08-19 19:39:01 +00:00
|
|
|
const float opacity = 1.0,
|
2022-03-11 22:51:41 +00:00
|
|
|
const float dimming = 1.0,
|
2022-03-14 18:51:48 +00:00
|
|
|
const BlendFactor srcBlendFactor = BlendFactor::SRC_ALPHA,
|
|
|
|
const BlendFactor dstBlendFactor = BlendFactor::ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
const glm::mat4& getProjectionMatrix()
|
|
|
|
{
|
|
|
|
if (mScreenRotated)
|
|
|
|
return mProjectionMatrixRotated;
|
|
|
|
else
|
|
|
|
return mProjectionMatrix;
|
|
|
|
}
|
|
|
|
const glm::mat4& getProjectionMatrixNormal() { return mProjectionMatrix; }
|
|
|
|
SDL_Window* getSDLWindow() { return mSDLWindow; }
|
|
|
|
const bool getScreenRotated() { return mScreenRotated; }
|
|
|
|
const float getWindowWidth() { return static_cast<float>(mWindowWidth); }
|
|
|
|
const float getWindowHeight() { return static_cast<float>(mWindowHeight); }
|
|
|
|
static const float getScreenWidth() { return static_cast<float>(sScreenWidth); }
|
|
|
|
static const float getScreenHeight() { return static_cast<float>(sScreenHeight); }
|
|
|
|
static const float getScreenWidthModifier() { return sScreenWidthModifier; }
|
|
|
|
static const float getScreenHeightModifier() { return sScreenHeightModifier; }
|
|
|
|
static const float getScreenAspectRatio() { return sScreenAspectRatio; }
|
|
|
|
|
|
|
|
static constexpr glm::mat4 getIdentity() { return glm::mat4 {1.0f}; }
|
|
|
|
glm::mat4 mTrans {getIdentity()};
|
|
|
|
|
|
|
|
virtual void shaderPostprocessing(
|
2022-03-11 22:17:04 +00:00
|
|
|
const unsigned int shaders,
|
|
|
|
const Renderer::postProcessingParams& parameters = postProcessingParams(),
|
2022-03-14 18:51:48 +00:00
|
|
|
unsigned char* textureRGBA = nullptr) = 0;
|
|
|
|
|
|
|
|
virtual void setup() = 0;
|
|
|
|
virtual bool createContext() = 0;
|
|
|
|
virtual void destroyContext() = 0;
|
|
|
|
virtual unsigned int createTexture(const TextureType type,
|
|
|
|
const bool linearMinify,
|
|
|
|
const bool linearMagnify,
|
|
|
|
const bool repeat,
|
|
|
|
const unsigned int width,
|
|
|
|
const unsigned int height,
|
|
|
|
void* data) = 0;
|
|
|
|
virtual void destroyTexture(const unsigned int texture) = 0;
|
|
|
|
virtual void updateTexture(const unsigned int texture,
|
|
|
|
const TextureType type,
|
|
|
|
const unsigned int x,
|
|
|
|
const unsigned int y,
|
2021-08-19 18:16:42 +00:00
|
|
|
const unsigned int width,
|
|
|
|
const unsigned int height,
|
2022-03-14 18:51:48 +00:00
|
|
|
void* data) = 0;
|
|
|
|
virtual void bindTexture(const unsigned int texture) = 0;
|
|
|
|
virtual void drawTriangleStrips(
|
|
|
|
const Vertex* vertices,
|
|
|
|
const unsigned int numVertices,
|
|
|
|
const BlendFactor srcBlendFactor = BlendFactor::SRC_ALPHA,
|
|
|
|
const BlendFactor dstBlendFactor = BlendFactor::ONE_MINUS_SRC_ALPHA) = 0;
|
|
|
|
virtual void setMatrix(const glm::mat4& matrix) = 0;
|
|
|
|
virtual void setScissor(const Rect& scissor) = 0;
|
|
|
|
virtual void setSwapInterval() = 0;
|
|
|
|
virtual void swapBuffers() = 0;
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
static constexpr unsigned int SHADER_CORE {0x00000001};
|
|
|
|
static constexpr unsigned int SHADER_BLUR_HORIZONTAL {0x00000002};
|
|
|
|
static constexpr unsigned int SHADER_BLUR_VERTICAL {0x00000004};
|
|
|
|
static constexpr unsigned int SHADER_SCANLINES {0x00000008};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
std::stack<Rect> mClipStack;
|
|
|
|
SDL_Window* mSDLWindow {nullptr};
|
|
|
|
glm::mat4 mProjectionMatrix {};
|
|
|
|
glm::mat4 mProjectionMatrixRotated {};
|
|
|
|
int mWindowWidth {0};
|
|
|
|
int mWindowHeight {0};
|
|
|
|
static inline int sScreenWidth {0};
|
|
|
|
static inline int sScreenHeight {0};
|
|
|
|
int mScreenOffsetX {0};
|
|
|
|
int mScreenOffsetY {0};
|
|
|
|
bool mScreenRotated {0};
|
|
|
|
bool mInitialCursorState {1};
|
|
|
|
// Screen resolution modifiers relative to the 1920x1080 reference.
|
|
|
|
static inline float sScreenHeightModifier {0.0f};
|
|
|
|
static inline float sScreenWidthModifier {0.0f};
|
|
|
|
static inline float sScreenAspectRatio {0.0f};
|
|
|
|
};
|
2019-08-08 20:16:11 +00:00
|
|
|
|
|
|
|
#endif // ES_CORE_RENDERER_RENDERER_H
|