2016-12-24 17:36:27 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
2017-01-03 14:57:46 +00:00
|
|
|
#include <Combiner.h>
|
2017-01-01 14:59:54 +00:00
|
|
|
#include "ObjectHandle.h"
|
2016-12-25 15:19:03 +00:00
|
|
|
#include "Parameter.h"
|
2017-01-03 14:57:46 +00:00
|
|
|
#include "CombinerProgram.h"
|
2017-01-06 07:33:49 +00:00
|
|
|
#include "ShaderProgram.h"
|
|
|
|
#include "PixelBuffer.h"
|
2017-01-16 13:55:57 +00:00
|
|
|
#include "FramebufferTextureFormats.h"
|
2016-12-24 17:36:27 +00:00
|
|
|
|
2016-12-27 04:15:29 +00:00
|
|
|
#define GRAPHICS_CONTEXT
|
|
|
|
|
2017-01-23 14:57:32 +00:00
|
|
|
struct CachedTexture;
|
|
|
|
|
2016-12-24 17:36:27 +00:00
|
|
|
namespace graphics {
|
|
|
|
|
2017-01-10 15:22:32 +00:00
|
|
|
enum class SpecialFeatures {
|
|
|
|
Multisampling,
|
2017-01-20 11:47:19 +00:00
|
|
|
BlitFramebuffer,
|
|
|
|
WeakBlitFramebuffer,
|
2017-01-21 11:55:14 +00:00
|
|
|
DepthFramebufferTextures,
|
2017-01-22 13:43:05 +00:00
|
|
|
ShaderProgramBinary,
|
2018-04-05 14:43:30 +00:00
|
|
|
ImageTextures,
|
2018-04-06 17:17:04 +00:00
|
|
|
IntegerTextures,
|
2021-02-14 17:10:34 +00:00
|
|
|
N64DepthWithFbFetchDepth,
|
2020-11-08 19:38:42 +00:00
|
|
|
FramebufferFetchColor,
|
2019-10-04 18:22:19 +00:00
|
|
|
TextureBarrier,
|
2019-11-29 22:09:09 +00:00
|
|
|
EglImage,
|
2020-04-28 15:24:26 +00:00
|
|
|
EglImageFramebuffer,
|
|
|
|
DualSourceBlending
|
2017-01-10 15:22:32 +00:00
|
|
|
};
|
|
|
|
|
2018-03-10 20:36:46 +00:00
|
|
|
enum class ClampMode {
|
|
|
|
ClippingEnabled,
|
|
|
|
NoNearPlaneClipping,
|
|
|
|
NoClipping
|
|
|
|
};
|
|
|
|
|
2016-12-24 17:36:27 +00:00
|
|
|
class ContextImpl;
|
2017-01-23 14:57:32 +00:00
|
|
|
class ColorBufferReader;
|
2016-12-24 17:36:27 +00:00
|
|
|
|
|
|
|
class Context
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Context();
|
|
|
|
~Context();
|
2016-12-25 15:19:03 +00:00
|
|
|
|
2016-12-24 17:36:27 +00:00
|
|
|
void init();
|
2016-12-25 15:19:03 +00:00
|
|
|
|
2016-12-24 17:36:27 +00:00
|
|
|
void destroy();
|
|
|
|
|
2018-03-10 20:36:46 +00:00
|
|
|
void setClampMode(ClampMode _mode);
|
|
|
|
|
|
|
|
ClampMode getClampMode();
|
|
|
|
|
2017-01-28 09:52:09 +00:00
|
|
|
void enable(EnableParam _parameter, bool _enable);
|
2017-01-10 15:22:32 +00:00
|
|
|
|
2018-03-10 20:36:46 +00:00
|
|
|
u32 isEnabled(EnableParam _parameter);
|
|
|
|
|
2017-01-28 09:52:09 +00:00
|
|
|
void cullFace(CullModeParam _mode);
|
2017-01-10 15:22:32 +00:00
|
|
|
|
|
|
|
void enableDepthWrite(bool _enable);
|
|
|
|
|
2017-01-28 09:52:09 +00:00
|
|
|
void setDepthCompare(CompareParam _mode);
|
2017-01-10 15:22:32 +00:00
|
|
|
|
|
|
|
void setViewport(s32 _x, s32 _y, s32 _width, s32 _height);
|
|
|
|
|
|
|
|
void setScissor(s32 _x, s32 _y, s32 _width, s32 _height);
|
|
|
|
|
2017-01-28 09:52:09 +00:00
|
|
|
void setBlending(BlendParam _sfactor, BlendParam _dfactor);
|
2017-01-10 15:22:32 +00:00
|
|
|
|
2020-05-10 08:11:59 +00:00
|
|
|
void setBlendingSeparate(BlendParam _sfactorcolor, BlendParam _dfactorcolor, BlendParam _sfactoralpha, BlendParam _dfactoralpha);
|
|
|
|
|
2017-01-10 15:22:32 +00:00
|
|
|
void setBlendColor(f32 _red, f32 _green, f32 _blue, f32 _alpha);
|
|
|
|
|
2017-01-11 10:07:20 +00:00
|
|
|
void clearColorBuffer(f32 _red, f32 _green, f32 _blue, f32 _alpha);
|
|
|
|
|
|
|
|
void clearDepthBuffer();
|
|
|
|
|
2017-01-14 14:24:48 +00:00
|
|
|
void setPolygonOffset(f32 _factor, f32 _units);
|
|
|
|
|
2017-01-12 15:22:53 +00:00
|
|
|
/*---------------Texture-------------*/
|
|
|
|
|
2017-01-01 14:59:54 +00:00
|
|
|
ObjectHandle createTexture(Parameter _target);
|
2016-12-25 15:19:03 +00:00
|
|
|
|
2018-05-07 15:43:57 +00:00
|
|
|
void deleteTexture(ObjectHandle _name);
|
2016-12-25 15:19:03 +00:00
|
|
|
|
2016-12-29 10:51:38 +00:00
|
|
|
struct InitTextureParams {
|
2017-01-01 14:59:54 +00:00
|
|
|
ObjectHandle handle;
|
2017-01-28 09:52:09 +00:00
|
|
|
TextureUnitParam textureUnitIndex{0};
|
2019-10-04 18:22:19 +00:00
|
|
|
TextureTargetParam target = textureTarget::TEXTURE_2D;
|
2016-12-29 10:51:38 +00:00
|
|
|
u32 msaaLevel = 0;
|
|
|
|
u32 width = 0;
|
|
|
|
u32 height = 0;
|
|
|
|
u32 mipMapLevel = 0;
|
2017-01-01 14:59:54 +00:00
|
|
|
u32 mipMapLevels = 1;
|
2017-01-28 09:52:09 +00:00
|
|
|
ColorFormatParam format;
|
|
|
|
InternalColorFormatParam internalFormat;
|
|
|
|
DatatypeParam dataType;
|
2017-01-01 13:30:28 +00:00
|
|
|
const void * data = nullptr;
|
2016-12-29 10:51:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void init2DTexture(const InitTextureParams & _params);
|
2016-12-24 17:36:27 +00:00
|
|
|
|
2017-01-06 07:33:49 +00:00
|
|
|
struct UpdateTextureDataParams {
|
|
|
|
ObjectHandle handle;
|
2017-01-28 09:52:09 +00:00
|
|
|
TextureUnitParam textureUnitIndex{0};
|
2017-01-06 07:33:49 +00:00
|
|
|
u32 x = 0;
|
|
|
|
u32 y = 0;
|
|
|
|
u32 width = 0;
|
|
|
|
u32 height = 0;
|
|
|
|
u32 mipMapLevel = 0;
|
2017-01-28 09:52:09 +00:00
|
|
|
ColorFormatParam format;
|
|
|
|
InternalColorFormatParam internalFormat;
|
|
|
|
DatatypeParam dataType;
|
2017-01-06 07:33:49 +00:00
|
|
|
const void * data = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
void update2DTexture(const UpdateTextureDataParams & _params);
|
|
|
|
|
2017-01-01 14:59:54 +00:00
|
|
|
struct TexParameters {
|
|
|
|
ObjectHandle handle;
|
2017-01-28 09:52:09 +00:00
|
|
|
TextureUnitParam textureUnitIndex{0};
|
|
|
|
TextureTargetParam target;
|
|
|
|
TextureParam magFilter;
|
|
|
|
TextureParam minFilter;
|
|
|
|
TextureParam wrapS;
|
|
|
|
TextureParam wrapT;
|
2017-01-01 14:59:54 +00:00
|
|
|
Parameter maxMipmapLevel;
|
|
|
|
Parameter maxAnisotropy;
|
|
|
|
};
|
|
|
|
|
|
|
|
void setTextureParameters(const TexParameters & _parameters);
|
|
|
|
|
2017-01-22 11:10:52 +00:00
|
|
|
struct BindTextureParameters {
|
|
|
|
ObjectHandle texture;
|
2017-01-28 09:52:09 +00:00
|
|
|
TextureUnitParam textureUnitIndex;
|
|
|
|
TextureTargetParam target;
|
2017-01-22 11:10:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void bindTexture(const BindTextureParameters & _params);
|
|
|
|
|
|
|
|
void setTextureUnpackAlignment(s32 _param);
|
|
|
|
|
|
|
|
s32 getTextureUnpackAlignment() const;
|
|
|
|
|
2017-01-22 13:43:05 +00:00
|
|
|
s32 getMaxTextureSize() const;
|
|
|
|
|
2021-07-22 05:05:13 +00:00
|
|
|
f32 getMaxAnisotropy() const;
|
|
|
|
|
2017-01-21 11:44:56 +00:00
|
|
|
struct BindImageTextureParameters {
|
2017-01-28 09:52:09 +00:00
|
|
|
ImageUnitParam imageUnit;
|
2017-01-21 11:44:56 +00:00
|
|
|
ObjectHandle texture;
|
2017-01-28 09:52:09 +00:00
|
|
|
ImageAccessModeParam accessMode;
|
|
|
|
InternalColorFormatParam textureFormat;
|
2017-01-21 11:44:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void bindImageTexture(const BindImageTextureParameters & _params);
|
|
|
|
|
2017-02-10 09:58:17 +00:00
|
|
|
u32 convertInternalTextureFormat(u32 _format) const;
|
2017-02-05 13:26:40 +00:00
|
|
|
|
2018-04-07 16:22:09 +00:00
|
|
|
void textureBarrier();
|
|
|
|
|
2017-01-12 15:22:53 +00:00
|
|
|
/*---------------Framebuffer-------------*/
|
|
|
|
|
2017-01-16 13:55:57 +00:00
|
|
|
const FramebufferTextureFormats & getFramebufferTextureFormats();
|
|
|
|
|
2017-01-02 14:00:49 +00:00
|
|
|
ObjectHandle createFramebuffer();
|
|
|
|
|
|
|
|
void deleteFramebuffer(ObjectHandle _name);
|
|
|
|
|
2017-01-28 09:52:09 +00:00
|
|
|
void bindFramebuffer(BufferTargetParam _target, ObjectHandle _name);
|
2017-01-15 07:57:25 +00:00
|
|
|
|
2017-01-02 15:40:41 +00:00
|
|
|
ObjectHandle createRenderbuffer();
|
|
|
|
|
|
|
|
struct InitRenderbufferParams {
|
|
|
|
ObjectHandle handle;
|
2017-01-28 09:52:09 +00:00
|
|
|
TextureTargetParam target;
|
|
|
|
InternalColorFormatParam format;
|
2017-01-02 15:40:41 +00:00
|
|
|
u32 width = 0;
|
|
|
|
u32 height = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
void initRenderbuffer(const InitRenderbufferParams & _params);
|
|
|
|
|
2017-01-02 14:00:49 +00:00
|
|
|
struct FrameBufferRenderTarget {
|
|
|
|
ObjectHandle bufferHandle;
|
2017-01-28 09:52:09 +00:00
|
|
|
BufferTargetParam bufferTarget;
|
|
|
|
BufferAttachmentParam attachment;
|
2017-01-02 14:00:49 +00:00
|
|
|
Parameter textureTarget;
|
|
|
|
ObjectHandle textureHandle;
|
|
|
|
};
|
|
|
|
|
|
|
|
void addFrameBufferRenderTarget(const FrameBufferRenderTarget & _params);
|
|
|
|
|
2017-01-14 10:08:02 +00:00
|
|
|
struct BlitFramebuffersParams
|
|
|
|
{
|
|
|
|
ObjectHandle readBuffer;
|
|
|
|
ObjectHandle drawBuffer;
|
|
|
|
s32 srcX0;
|
|
|
|
s32 srcY0;
|
|
|
|
s32 srcX1;
|
|
|
|
s32 srcY1;
|
|
|
|
s32 dstX0;
|
|
|
|
s32 dstY0;
|
|
|
|
s32 dstX1;
|
|
|
|
s32 dstY1;
|
|
|
|
Parameter mask;
|
|
|
|
Parameter filter;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool blitFramebuffers(const BlitFramebuffersParams & _params);
|
|
|
|
|
2018-04-12 15:15:45 +00:00
|
|
|
void setDrawBuffers(u32 _num);
|
|
|
|
|
2017-01-23 09:03:38 +00:00
|
|
|
/*---------------Pixelbuffer-------------*/
|
|
|
|
|
|
|
|
PixelReadBuffer * createPixelReadBuffer(size_t _sizeInBytes);
|
|
|
|
|
2017-01-23 14:57:32 +00:00
|
|
|
ColorBufferReader * createColorBufferReader(CachedTexture * _pTexture);
|
|
|
|
|
2017-01-12 15:22:53 +00:00
|
|
|
/*---------------Shaders-------------*/
|
|
|
|
|
2017-10-29 08:49:44 +00:00
|
|
|
bool isCombinerProgramBuilderObsolete();
|
|
|
|
|
|
|
|
void resetCombinerProgramBuilder();
|
|
|
|
|
2017-01-03 14:57:46 +00:00
|
|
|
CombinerProgram * createCombinerProgram(Combiner & _color, Combiner & _alpha, const CombinerKey & _key);
|
|
|
|
|
2017-01-07 15:46:51 +00:00
|
|
|
bool saveShadersStorage(const Combiners & _combiners);
|
|
|
|
|
|
|
|
bool loadShadersStorage(Combiners & _combiners);
|
|
|
|
|
2017-01-06 07:33:49 +00:00
|
|
|
ShaderProgram * createDepthFogShader();
|
|
|
|
|
2017-02-12 15:21:20 +00:00
|
|
|
TexrectDrawerShaderProgram * createTexrectDrawerDrawShader();
|
2017-01-08 13:23:38 +00:00
|
|
|
|
2017-02-12 15:21:20 +00:00
|
|
|
ShaderProgram * createTexrectDrawerClearShader();
|
2017-01-08 13:23:38 +00:00
|
|
|
|
2020-05-05 10:20:25 +00:00
|
|
|
ShaderProgram * createTexrectUpscaleCopyShader();
|
2017-01-08 13:23:38 +00:00
|
|
|
|
2020-05-05 10:20:25 +00:00
|
|
|
ShaderProgram * createTexrectColorAndDepthUpscaleCopyShader();
|
|
|
|
|
|
|
|
ShaderProgram * createTexrectDownscaleCopyShader();
|
|
|
|
|
|
|
|
ShaderProgram * createTexrectColorAndDepthDownscaleCopyShader();
|
2019-06-27 09:21:51 +00:00
|
|
|
|
2019-11-30 08:31:43 +00:00
|
|
|
ShaderProgram * createGammaCorrectionShader();
|
2017-01-18 15:39:10 +00:00
|
|
|
|
2019-11-30 08:31:43 +00:00
|
|
|
ShaderProgram * createFXAAShader();
|
2018-08-26 10:03:02 +00:00
|
|
|
|
2017-05-26 09:00:01 +00:00
|
|
|
TextDrawerShaderProgram * createTextDrawerShader();
|
2017-02-12 07:27:26 +00:00
|
|
|
|
2017-01-18 15:39:10 +00:00
|
|
|
void resetShaderProgram();
|
|
|
|
|
2017-01-12 15:22:53 +00:00
|
|
|
/*---------------Draw-------------*/
|
|
|
|
|
|
|
|
struct DrawTriangleParameters
|
|
|
|
{
|
2017-01-28 09:52:09 +00:00
|
|
|
DrawModeParam mode;
|
2017-01-12 15:22:53 +00:00
|
|
|
Parameter elementsType;
|
|
|
|
u32 verticesCount = 0;
|
|
|
|
u32 elementsCount = 0;
|
|
|
|
bool flatColors = false;
|
|
|
|
SPVertex * vertices = nullptr;
|
|
|
|
void * elements = nullptr;
|
|
|
|
const CombinerProgram * combiner = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
void drawTriangles(const DrawTriangleParameters & _params);
|
2017-01-10 14:58:09 +00:00
|
|
|
|
2017-01-12 15:22:53 +00:00
|
|
|
struct DrawRectParameters
|
|
|
|
{
|
2017-01-28 09:52:09 +00:00
|
|
|
DrawModeParam mode;
|
2017-03-11 05:46:40 +00:00
|
|
|
bool texrect = true;
|
2017-01-12 15:22:53 +00:00
|
|
|
u32 verticesCount = 0;
|
|
|
|
RectVertex * vertices = nullptr;
|
|
|
|
const CombinerProgram * combiner = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
void drawRects(const DrawRectParameters & _params);
|
|
|
|
|
|
|
|
void drawLine(f32 _width, SPVertex * _vertices);
|
2017-01-11 10:07:20 +00:00
|
|
|
|
|
|
|
f32 getMaxLineWidth();
|
|
|
|
|
2017-01-12 15:22:53 +00:00
|
|
|
/*---------------Misc-------------*/
|
2020-12-23 22:47:13 +00:00
|
|
|
s32 getMaxMSAALevel();
|
2017-01-12 15:22:53 +00:00
|
|
|
|
2017-01-15 07:57:25 +00:00
|
|
|
bool isError() const;
|
|
|
|
|
2017-01-22 13:43:05 +00:00
|
|
|
bool isFramebufferError() const;
|
|
|
|
|
2018-04-06 17:17:04 +00:00
|
|
|
static bool Multisampling;
|
|
|
|
static bool BlitFramebuffer;
|
|
|
|
static bool WeakBlitFramebuffer;
|
|
|
|
static bool DepthFramebufferTextures;
|
|
|
|
static bool ShaderProgramBinary;
|
|
|
|
static bool ImageTextures;
|
|
|
|
static bool IntegerTextures;
|
2020-11-08 19:38:42 +00:00
|
|
|
static bool FramebufferFetchDepth;
|
|
|
|
static bool FramebufferFetchColor;
|
2018-04-16 19:13:18 +00:00
|
|
|
static bool TextureBarrier;
|
2019-10-04 18:22:19 +00:00
|
|
|
static bool EglImage;
|
2019-11-29 22:09:09 +00:00
|
|
|
static bool EglImageFramebuffer;
|
2020-04-28 15:24:26 +00:00
|
|
|
static bool DualSourceBlending;
|
2018-04-06 17:17:04 +00:00
|
|
|
|
2016-12-24 17:36:27 +00:00
|
|
|
private:
|
|
|
|
std::unique_ptr<ContextImpl> m_impl;
|
2017-01-16 13:55:57 +00:00
|
|
|
std::unique_ptr<FramebufferTextureFormats> m_fbTexFormats;
|
2016-12-24 17:36:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extern graphics::Context gfxContext;
|