ddnet/src/engine/graphics.h

578 lines
20 KiB
C
Raw Normal View History

2010-11-20 10:37:14 +00:00
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
2010-05-29 07:25:38 +00:00
#ifndef ENGINE_GRAPHICS_H
#define ENGINE_GRAPHICS_H
#include "kernel.h"
#include "warning.h"
2010-05-29 07:25:38 +00:00
2019-04-26 22:11:15 +00:00
#include <base/color.h>
#include <base/system.h>
2019-04-26 22:11:15 +00:00
#include <cstddef>
#include <cstdint>
2021-08-21 19:41:51 +00:00
#include <functional>
#include <vector>
#define GRAPHICS_TYPE_UNSIGNED_BYTE 0x1401
#define GRAPHICS_TYPE_UNSIGNED_SHORT 0x1403
#define GRAPHICS_TYPE_INT 0x1404
#define GRAPHICS_TYPE_UNSIGNED_INT 0x1405
#define GRAPHICS_TYPE_FLOAT 0x1406
struct SBufferContainerInfo
{
int m_Stride;
2022-03-20 17:03:25 +00:00
int m_VertBufferBindingIndex;
// the attributes of the container
struct SAttribute
{
int m_DataTypeCount;
unsigned int m_Type;
bool m_Normalized;
2018-08-02 16:26:12 +00:00
void *m_pOffset;
//0: float, 1:integer
unsigned int m_FuncType;
};
std::vector<SAttribute> m_vAttributes;
};
struct SQuadRenderInfo
{
ColorRGBA m_Color;
vec2 m_Offsets;
float m_Rotation;
2022-03-20 17:04:00 +00:00
// allows easier upload for uniform buffers because of the alignment requirements
float m_Padding;
};
struct SGraphicTile
{
vec2 m_TopLeft;
vec2 m_TopRight;
vec2 m_BottomRight;
vec2 m_BottomLeft;
};
struct SGraphicTileTexureCoords
{
ubvec4 m_TexCoordTopLeft;
ubvec4 m_TexCoordTopRight;
ubvec4 m_TexCoordBottomRight;
ubvec4 m_TexCoordBottomLeft;
};
2010-05-29 07:25:38 +00:00
class CImageInfo
{
public:
enum EImageFormat
2010-05-29 07:25:38 +00:00
{
FORMAT_ERROR = -1,
FORMAT_RGB = 0,
FORMAT_RGBA = 1,
2022-03-20 17:03:25 +00:00
FORMAT_SINGLE_COMPONENT = 2,
2010-05-29 07:25:38 +00:00
};
/**
* Contains the width of the image
*/
int m_Width = 0;
/**
* Contains the height of the image
*/
int m_Height = 0;
/**
* Contains the format of the image.
*
* @see EImageFormat
*/
EImageFormat m_Format = FORMAT_ERROR;
2010-05-29 07:25:38 +00:00
/**
* Pointer to the image data.
*/
void *m_pData = nullptr;
static size_t PixelSize(EImageFormat Format)
{
dbg_assert(Format != FORMAT_ERROR, "Format invalid");
static const size_t s_aSizes[] = {3, 4, 1};
return s_aSizes[(int)Format];
}
size_t PixelSize() const
{
return PixelSize(m_Format);
}
static EImageFormat ImageFormatFromInt(int Format)
{
if(Format < (int)FORMAT_RGB || Format > (int)FORMAT_SINGLE_COMPONENT)
return FORMAT_ERROR;
return (EImageFormat)Format;
}
2010-05-29 07:25:38 +00:00
};
/*
Structure: CVideoMode
*/
class CVideoMode
{
public:
2021-05-06 10:59:30 +00:00
int m_CanvasWidth, m_CanvasHeight;
int m_WindowWidth, m_WindowHeight;
2021-08-21 19:41:51 +00:00
int m_RefreshRate;
2010-05-29 07:25:38 +00:00
int m_Red, m_Green, m_Blue;
2021-08-21 19:41:51 +00:00
uint32_t m_Format;
2010-05-29 07:25:38 +00:00
};
typedef vec2 GL_SPoint;
typedef vec2 GL_STexCoord;
struct GL_STexCoord3D
{
GL_STexCoord3D &operator=(const GL_STexCoord &TexCoord)
{
u = TexCoord.u;
v = TexCoord.v;
return *this;
}
GL_STexCoord3D &operator=(const vec3 &TexCoord)
{
u = TexCoord.u;
v = TexCoord.v;
w = TexCoord.w;
return *this;
}
float u, v, w;
};
2018-04-03 15:40:21 +00:00
typedef ColorRGBA GL_SColorf;
2018-04-03 15:40:21 +00:00
//use normalized color values
typedef vector4_base<unsigned char> GL_SColor;
2018-04-03 15:40:21 +00:00
struct GL_SVertex
{
GL_SPoint m_Pos;
GL_STexCoord m_Tex;
GL_SColor m_Color;
};
2018-03-21 14:48:48 +00:00
struct GL_SVertexTex3D
{
GL_SPoint m_Pos;
GL_SColorf m_Color;
GL_STexCoord3D m_Tex;
};
struct GL_SVertexTex3DStream
{
GL_SPoint m_Pos;
GL_SColor m_Color;
GL_STexCoord3D m_Tex;
};
2022-03-20 17:04:00 +00:00
static constexpr size_t gs_GraphicsMaxQuadsRenderCount = 256;
static constexpr size_t gs_GraphicsMaxParticlesRenderCount = 512;
enum EGraphicsDriverAgeType
{
GRAPHICS_DRIVER_AGE_TYPE_LEGACY = 0,
GRAPHICS_DRIVER_AGE_TYPE_DEFAULT,
GRAPHICS_DRIVER_AGE_TYPE_MODERN,
2022-03-20 17:04:00 +00:00
GRAPHICS_DRIVER_AGE_TYPE_COUNT,
};
enum EBackendType
{
BACKEND_TYPE_OPENGL = 0,
BACKEND_TYPE_OPENGL_ES,
BACKEND_TYPE_VULKAN,
// special value to tell the backend to identify the current backend
BACKEND_TYPE_AUTO,
BACKEND_TYPE_COUNT,
};
2022-03-20 17:03:25 +00:00
struct STWGraphicGPU
{
2022-04-18 07:39:23 +00:00
enum ETWGraphicsGPUType
{
GRAPHICS_GPU_TYPE_DISCRETE = 0,
GRAPHICS_GPU_TYPE_INTEGRATED,
GRAPHICS_GPU_TYPE_VIRTUAL,
GRAPHICS_GPU_TYPE_CPU,
// should stay at last position in this enum
GRAPHICS_GPU_TYPE_INVALID,
};
2022-03-20 17:03:25 +00:00
struct STWGraphicGPUItem
{
char m_aName[256];
2022-04-18 07:39:23 +00:00
ETWGraphicsGPUType m_GPUType;
2022-03-20 17:03:25 +00:00
};
std::vector<STWGraphicGPUItem> m_vGPUs;
2022-03-20 17:03:25 +00:00
STWGraphicGPUItem m_AutoGPU;
};
typedef STWGraphicGPU TTWGraphicsGPUList;
typedef std::function<void()> WINDOW_RESIZE_FUNC;
typedef std::function<void()> WINDOW_PROPS_CHANGED_FUNC;
2018-03-21 14:48:48 +00:00
typedef std::function<bool(uint32_t &Width, uint32_t &Height, CImageInfo::EImageFormat &Format, std::vector<uint8_t> &vDstData)> TGLBackendReadPresentedImageData;
2022-03-20 17:03:25 +00:00
2010-05-29 07:25:38 +00:00
class IGraphics : public IInterface
{
MACRO_INTERFACE("graphics")
2010-05-29 07:25:38 +00:00
protected:
int m_ScreenWidth;
int m_ScreenHeight;
2021-08-21 19:41:51 +00:00
int m_ScreenRefreshRate;
2021-05-06 10:59:30 +00:00
float m_ScreenHiDPIScale;
2010-05-29 07:25:38 +00:00
public:
enum
{
TEXLOAD_NOMIPMAPS = 1 << 1,
TEXLOAD_NO_COMPRESSION = 1 << 2,
2020-08-19 05:05:51 +00:00
TEXLOAD_TO_3D_TEXTURE = (1 << 3),
TEXLOAD_TO_2D_ARRAY_TEXTURE = (1 << 4),
TEXLOAD_NO_2D_TEXTURE = (1 << 5),
2010-05-29 07:25:38 +00:00
};
class CTextureHandle
{
friend class IGraphics;
int m_Id;
public:
CTextureHandle() :
m_Id(-1)
{
}
bool IsValid() const { return Id() >= 0; }
bool IsNullTexture() const { return Id() == 0; }
int Id() const { return m_Id; }
void Invalidate() { m_Id = -1; }
};
2010-05-29 07:25:38 +00:00
int ScreenWidth() const { return m_ScreenWidth; }
int ScreenHeight() const { return m_ScreenHeight; }
float ScreenAspect() const { return (float)ScreenWidth() / (float)ScreenHeight(); }
2021-05-06 10:59:30 +00:00
float ScreenHiDPIScale() const { return m_ScreenHiDPIScale; }
int WindowWidth() const { return m_ScreenWidth / m_ScreenHiDPIScale; }
int WindowHeight() const { return m_ScreenHeight / m_ScreenHiDPIScale; }
virtual void WarnPngliteIncompatibleImages(bool Warn) = 0;
virtual void SetWindowParams(int FullscreenMode, bool IsBorderless) = 0;
virtual bool SetWindowScreen(int Index) = 0;
virtual bool SetVSync(bool State) = 0;
2022-04-26 18:09:47 +00:00
virtual bool SetMultiSampling(uint32_t ReqMultiSamplingCount, uint32_t &MultiSamplingCountBackend) = 0;
virtual int GetWindowScreen() = 0;
virtual void Move(int x, int y) = 0;
virtual void Resize(int w, int h, int RefreshRate) = 0;
virtual void GotResized(int w, int h, int RefreshRate) = 0;
virtual void UpdateViewport(int X, int Y, int W, int H, bool ByResize) = 0;
/**
* Listens to a resize event of the canvas, which is usually caused by a window resize.
* Will only be triggered if the actual size changed.
*/
virtual void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc) = 0;
/**
* Listens to various window property changes, such as minimize, maximize, move, fullscreen mode
*/
virtual void AddWindowPropChangeListener(WINDOW_PROPS_CHANGED_FUNC pFunc) = 0;
2021-08-24 10:18:20 +00:00
virtual void WindowDestroyNtf(uint32_t WindowID) = 0;
virtual void WindowCreateNtf(uint32_t WindowID) = 0;
2022-03-20 17:04:00 +00:00
// ForceClearNow forces the backend to trigger a clear, even at performance cost, else it might be delayed by one frame
virtual void Clear(float r, float g, float b, bool ForceClearNow = false) = 0;
2010-05-29 07:25:38 +00:00
virtual void ClipEnable(int x, int y, int w, int h) = 0;
virtual void ClipDisable() = 0;
2010-05-29 07:25:38 +00:00
virtual void MapScreen(float TopLeftX, float TopLeftY, float BottomRightX, float BottomRightY) = 0;
virtual void GetScreen(float *pTopLeftX, float *pTopLeftY, float *pBottomRightX, float *pBottomRightY) = 0;
2010-05-29 07:25:38 +00:00
// TODO: These should perhaps not be virtuals
virtual void BlendNone() = 0;
virtual void BlendNormal() = 0;
virtual void BlendAdditive() = 0;
virtual void WrapNormal() = 0;
virtual void WrapClamp() = 0;
2022-03-20 17:03:25 +00:00
virtual uint64_t TextureMemoryUsage() const = 0;
virtual uint64_t BufferMemoryUsage() const = 0;
virtual uint64_t StreamedMemoryUsage() const = 0;
virtual uint64_t StagingMemoryUsage() const = 0;
virtual const TTWGraphicsGPUList &GetGPUs() const = 0;
2023-11-20 18:18:45 +00:00
virtual bool LoadPNG(CImageInfo *pImg, const char *pFilename, int StorageType) = 0;
2020-11-25 12:05:53 +00:00
virtual void FreePNG(CImageInfo *pImg) = 0;
virtual bool CheckImageDivisibility(const char *pFileName, CImageInfo &Img, int DivX, int DivY, bool AllowResize) = 0;
virtual bool IsImageFormatRGBA(const char *pFileName, CImageInfo &Img) = 0;
2020-09-08 13:11:32 +00:00
// destination and source buffer require to have the same width and height
virtual void CopyTextureBufferSub(uint8_t *pDestBuffer, uint8_t *pSourceBuffer, size_t FullWidth, size_t FullHeight, size_t PixelSize, size_t SubOffsetX, size_t SubOffsetY, size_t SubCopyWidth, size_t SubCopyHeight) = 0;
2020-09-08 13:11:32 +00:00
// destination width must be equal to the subwidth of the source
virtual void CopyTextureFromTextureBufferSub(uint8_t *pDestBuffer, size_t DestWidth, size_t DestHeight, uint8_t *pSourceBuffer, size_t SrcWidth, size_t SrcHeight, size_t PixelSize, size_t SrcSubOffsetX, size_t SrcSubOffsetY, size_t SrcSubCopyWidth, size_t SrcSubCopyHeight) = 0;
virtual int UnloadTexture(CTextureHandle *pIndex) = 0;
virtual CTextureHandle LoadTextureRaw(size_t Width, size_t Height, CImageInfo::EImageFormat Format, const void *pData, int Flags, const char *pTexName = nullptr) = 0;
virtual CTextureHandle LoadTextureRawMove(size_t Width, size_t Height, CImageInfo::EImageFormat Format, void *pData, int Flags, const char *pTexName = nullptr) = 0;
virtual int LoadTextureRawSub(CTextureHandle TextureID, int x, int y, size_t Width, size_t Height, CImageInfo::EImageFormat Format, const void *pData) = 0;
virtual CTextureHandle LoadTexture(const char *pFilename, int StorageType, int Flags = 0) = 0;
virtual CTextureHandle NullTexture() const = 0;
virtual void TextureSet(CTextureHandle Texture) = 0;
void TextureClear() { TextureSet(CTextureHandle()); }
2022-03-20 17:03:25 +00:00
// pTextData & pTextOutlineData are automatically free'd
2023-07-19 11:25:37 +00:00
virtual bool LoadTextTextures(size_t Width, size_t Height, CTextureHandle &TextTexture, CTextureHandle &TextOutlineTexture, void *pTextData, void *pTextOutlineData) = 0;
2022-03-20 17:03:25 +00:00
virtual bool UnloadTextTextures(CTextureHandle &TextTexture, CTextureHandle &TextOutlineTexture) = 0;
2023-07-19 11:25:37 +00:00
virtual bool UpdateTextTexture(CTextureHandle TextureID, int x, int y, size_t Width, size_t Height, const void *pData) = 0;
2022-03-20 17:03:25 +00:00
virtual CTextureHandle LoadSpriteTexture(CImageInfo &FromImageInfo, struct CDataSprite *pSprite) = 0;
virtual bool IsImageSubFullyTransparent(CImageInfo &FromImageInfo, int x, int y, int w, int h) = 0;
virtual bool IsSpriteTextureFullyTransparent(CImageInfo &FromImageInfo, struct CDataSprite *pSprite) = 0;
virtual void FlushVertices(bool KeepVertices = false) = 0;
virtual void FlushVerticesTex3D() = 0;
// specific render functions
virtual void RenderTileLayer(int BufferContainerIndex, const ColorRGBA &Color, char **pOffsets, unsigned int *pIndicedVertexDrawNum, size_t NumIndicesOffset) = 0;
virtual void RenderBorderTiles(int BufferContainerIndex, const ColorRGBA &Color, char *pIndexBufferOffset, const vec2 &Offset, const vec2 &Scale, uint32_t DrawNum) = 0;
2023-07-19 11:25:37 +00:00
virtual void RenderQuadLayer(int BufferContainerIndex, SQuadRenderInfo *pQuadInfo, size_t QuadNum, int QuadOffset) = 0;
virtual void RenderText(int BufferContainerIndex, int TextQuadNum, int TextureSize, int TextureTextIndex, int TextureTextOutlineIndex, const ColorRGBA &TextColor, const ColorRGBA &TextOutlineColor) = 0;
2019-04-26 22:11:15 +00:00
// opengl 3.3 functions
2022-03-20 17:03:25 +00:00
enum EBufferObjectCreateFlags
{
// tell the backend that the buffer only needs to be valid for the span of one frame. Buffer size is not allowed to be bigger than GL_SVertex * MAX_VERTICES
BUFFER_OBJECT_CREATE_FLAGS_ONE_TIME_USE_BIT = 1 << 0,
};
// if a pointer is passed as moved pointer, it requires to be allocated with malloc()
2022-03-20 17:03:25 +00:00
virtual int CreateBufferObject(size_t UploadDataSize, void *pUploadData, int CreateFlags, bool IsMovedPointer = false) = 0;
virtual void RecreateBufferObject(int BufferIndex, size_t UploadDataSize, void *pUploadData, int CreateFlags, bool IsMovedPointer = false) = 0;
virtual void DeleteBufferObject(int BufferIndex) = 0;
virtual int CreateBufferContainer(struct SBufferContainerInfo *pContainerInfo) = 0;
// destroying all buffer objects means, that all referenced VBOs are destroyed automatically, so the user does not need to save references to them
virtual void DeleteBufferContainer(int &ContainerIndex, bool DestroyAllBO = true) = 0;
virtual void IndicesNumRequiredNotify(unsigned int RequiredIndicesCount) = 0;
2022-03-20 17:04:00 +00:00
// returns true if the driver age type is supported, passing BACKEND_TYPE_AUTO for BackendType will query the values for the currently used backend
virtual bool GetDriverVersion(EGraphicsDriverAgeType DriverAgeType, int &Major, int &Minor, int &Patch, const char *&pName, EBackendType BackendType) = 0;
virtual bool IsConfigModernAPI() = 0;
virtual bool IsTileBufferingEnabled() = 0;
virtual bool IsQuadBufferingEnabled() = 0;
virtual bool IsTextBufferingEnabled() = 0;
virtual bool IsQuadContainerBufferingEnabled() = 0;
virtual bool Uses2DTextureArrays() = 0;
virtual bool HasTextureArraysSupport() = 0;
2021-03-26 10:30:24 +00:00
virtual const char *GetVendorString() = 0;
virtual const char *GetVersionString() = 0;
virtual const char *GetRendererString() = 0;
2010-05-29 07:25:38 +00:00
struct CLineItem
{
float m_X0, m_Y0, m_X1, m_Y1;
CLineItem() {}
CLineItem(float x0, float y0, float x1, float y1) :
m_X0(x0), m_Y0(y0), m_X1(x1), m_Y1(y1) {}
2010-05-29 07:25:38 +00:00
};
virtual void LinesBegin() = 0;
virtual void LinesEnd() = 0;
virtual void LinesDraw(const CLineItem *pArray, int Num) = 0;
2010-05-29 07:25:38 +00:00
virtual void QuadsBegin() = 0;
virtual void QuadsEnd() = 0;
virtual void QuadsTex3DBegin() = 0;
virtual void QuadsTex3DEnd() = 0;
2020-10-20 17:11:19 +00:00
virtual void TrianglesBegin() = 0;
virtual void TrianglesEnd() = 0;
virtual void QuadsEndKeepVertices() = 0;
virtual void QuadsDrawCurrentVertices(bool KeepVertices = true) = 0;
2010-05-29 07:25:38 +00:00
virtual void QuadsSetRotation(float Angle) = 0;
2014-08-16 14:50:01 +00:00
virtual void QuadsSetSubset(float TopLeftU, float TopLeftV, float BottomRightU, float BottomRightV) = 0;
virtual void QuadsSetSubsetFree(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, int Index = -1) = 0;
2019-04-26 22:11:15 +00:00
2021-09-13 21:14:04 +00:00
struct CFreeformItem
{
float m_X0, m_Y0, m_X1, m_Y1, m_X2, m_Y2, m_X3, m_Y3;
CFreeformItem() {}
CFreeformItem(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) :
m_X0(x0), m_Y0(y0), m_X1(x1), m_Y1(y1), m_X2(x2), m_Y2(y2), m_X3(x3), m_Y3(y3) {}
};
2010-05-29 07:25:38 +00:00
struct CQuadItem
{
float m_X, m_Y, m_Width, m_Height;
CQuadItem() {}
CQuadItem(float x, float y, float w, float h) :
m_X(x), m_Y(y), m_Width(w), m_Height(h) {}
void Set(float x, float y, float w, float h)
{
m_X = x;
m_Y = y;
m_Width = w;
m_Height = h;
}
2021-09-13 21:14:04 +00:00
CFreeformItem ToFreeForm() const
{
return CFreeformItem(m_X, m_Y, m_X + m_Width, m_Y, m_X, m_Y + m_Height, m_X + m_Width, m_Y + m_Height);
}
2010-05-29 07:25:38 +00:00
};
virtual void QuadsDraw(CQuadItem *pArray, int Num) = 0;
virtual void QuadsDrawTL(const CQuadItem *pArray, int Num) = 0;
virtual void QuadsTex3DDrawTL(const CQuadItem *pArray, int Num) = 0;
2021-09-13 21:14:04 +00:00
virtual const GL_STexCoord *GetCurTextureCoordinates() = 0;
virtual const GL_SColor *GetCurColor() = 0;
2021-09-13 21:14:04 +00:00
virtual int CreateQuadContainer(bool AutomaticUpload = true) = 0;
virtual void QuadContainerChangeAutomaticUpload(int ContainerIndex, bool AutomaticUpload) = 0;
virtual void QuadContainerUpload(int ContainerIndex) = 0;
virtual int QuadContainerAddQuads(int ContainerIndex, CQuadItem *pArray, int Num) = 0;
virtual int QuadContainerAddQuads(int ContainerIndex, CFreeformItem *pArray, int Num) = 0;
virtual void QuadContainerReset(int ContainerIndex) = 0;
virtual void DeleteQuadContainer(int &ContainerIndex) = 0;
virtual void RenderQuadContainer(int ContainerIndex, int QuadDrawNum) = 0;
2021-09-13 21:14:04 +00:00
virtual void RenderQuadContainer(int ContainerIndex, int QuadOffset, int QuadDrawNum, bool ChangeWrapMode = true) = 0;
2020-10-13 20:08:52 +00:00
virtual void RenderQuadContainerEx(int ContainerIndex, int QuadOffset, int QuadDrawNum, float X, float Y, float ScaleX = 1.f, float ScaleY = 1.f) = 0;
virtual void RenderQuadContainerAsSprite(int ContainerIndex, int QuadOffset, float X, float Y, float ScaleX = 1.f, float ScaleY = 1.f) = 0;
struct SRenderSpriteInfo
{
vec2 m_Pos;
float m_Scale;
float m_Rotation;
};
virtual void RenderQuadContainerAsSpriteMultiple(int ContainerIndex, int QuadOffset, int DrawCount, SRenderSpriteInfo *pRenderInfo) = 0;
2010-05-29 07:25:38 +00:00
virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) = 0;
virtual void QuadsText(float x, float y, float Size, const char *pText) = 0;
enum
{
CORNER_NONE = 0,
CORNER_TL = 1,
CORNER_TR = 2,
CORNER_BL = 4,
CORNER_BR = 8,
CORNER_T = CORNER_TL | CORNER_TR,
CORNER_B = CORNER_BL | CORNER_BR,
CORNER_R = CORNER_TR | CORNER_BR,
CORNER_L = CORNER_TL | CORNER_BL,
CORNER_ALL = CORNER_T | CORNER_B,
};
virtual void DrawRectExt(float x, float y, float w, float h, float r, int Corners) = 0;
virtual void DrawRectExt4(float x, float y, float w, float h, ColorRGBA ColorTopLeft, ColorRGBA ColorTopRight, ColorRGBA ColorBottomLeft, ColorRGBA ColorBottomRight, float r, int Corners) = 0;
virtual int CreateRectQuadContainer(float x, float y, float w, float h, float r, int Corners) = 0;
virtual void DrawRect(float x, float y, float w, float h, ColorRGBA Color, int Corners, float Rounding) = 0;
virtual void DrawRect4(float x, float y, float w, float h, ColorRGBA ColorTopLeft, ColorRGBA ColorTopRight, ColorRGBA ColorBottomLeft, ColorRGBA ColorBottomRight, int Corners, float Rounding) = 0;
virtual void DrawCircle(float CenterX, float CenterY, float Radius, int Segments) = 0;
2010-05-29 07:25:38 +00:00
struct CColorVertex
{
int m_Index;
float m_R, m_G, m_B, m_A;
CColorVertex() {}
CColorVertex(int i, float r, float g, float b, float a) :
m_Index(i), m_R(r), m_G(g), m_B(b), m_A(a) {}
CColorVertex(int i, ColorRGBA Color) :
m_Index(i), m_R(Color.r), m_G(Color.g), m_B(Color.b), m_A(Color.a) {}
2010-05-29 07:25:38 +00:00
};
virtual void SetColorVertex(const CColorVertex *pArray, size_t Num) = 0;
2010-05-29 07:25:38 +00:00
virtual void SetColor(float r, float g, float b, float a) = 0;
virtual void SetColor(ColorRGBA Color) = 0;
virtual void SetColor4(ColorRGBA TopLeft, ColorRGBA TopRight, ColorRGBA BottomLeft, ColorRGBA BottomRight) = 0;
virtual void ChangeColorOfCurrentQuadVertices(float r, float g, float b, float a) = 0;
virtual void ChangeColorOfQuadVertices(size_t QuadOffset, unsigned char r, unsigned char g, unsigned char b, unsigned char a) = 0;
/**
* Reads the color at the specified position from the backbuffer once,
* after the next swap operation.
*
* @param Position The pixel position to read.
* @param pColor Pointer that will receive the read pixel color.
* The pointer must be valid until the next swap operation.
*/
virtual void ReadPixel(ivec2 Position, ColorRGBA *pColor) = 0;
virtual void TakeScreenshot(const char *pFilename) = 0;
2014-01-19 03:02:01 +00:00
virtual void TakeCustomScreenshot(const char *pFilename) = 0;
2015-08-24 20:46:28 +00:00
virtual int GetVideoModes(CVideoMode *pModes, int MaxModes, int Screen) = 0;
2024-02-06 23:01:06 +00:00
virtual void GetCurrentVideoMode(CVideoMode &pModes, int Screen) = 0;
2010-05-29 07:25:38 +00:00
virtual void Swap() = 0;
virtual int GetNumScreens() const = 0;
virtual const char *GetScreenName(int Screen) const = 0;
2018-02-04 15:00:47 +00:00
// synchronization
virtual void InsertSignal(class CSemaphore *pSemaphore) = 0;
virtual bool IsIdle() const = 0;
virtual void WaitForIdle() = 0;
virtual void SetWindowGrab(bool Grab) = 0;
virtual void NotifyWindow() = 0;
2022-03-20 17:03:25 +00:00
// be aware that this function should only be called from the graphics thread, and even then you should really know what you are doing
2022-03-20 17:04:00 +00:00
// this function always returns the pixels in RGB
2022-03-20 17:03:25 +00:00
virtual TGLBackendReadPresentedImageData &GetReadPresentedImageDataFuncUnsafe() = 0;
virtual SWarning *GetCurWarning() = 0;
// returns true if the error msg was shown
virtual bool ShowMessageBox(unsigned Type, const char *pTitle, const char *pMsg) = 0;
2023-05-27 07:51:22 +00:00
virtual bool IsBackendInitialized() = 0;
protected:
inline CTextureHandle CreateTextureHandle(int Index)
{
CTextureHandle Tex;
Tex.m_Id = Index;
return Tex;
}
2010-05-29 07:25:38 +00:00
};
class IEngineGraphics : public IGraphics
{
MACRO_INTERFACE("enginegraphics")
2010-05-29 07:25:38 +00:00
public:
virtual int Init() = 0;
virtual void Shutdown() override = 0;
2010-05-29 07:25:38 +00:00
virtual void Minimize() = 0;
virtual void Maximize() = 0;
2010-05-29 07:25:38 +00:00
virtual int WindowActive() = 0;
virtual int WindowOpen() = 0;
};
extern IEngineGraphics *CreateEngineGraphicsThreaded();
2010-05-29 07:25:38 +00:00
#endif