DDNet documentation
Loading...
Searching...
No Matches
backend_opengl.h
Go to the documentation of this file.
1// This file can be included several times.
2#if (!defined(BACKEND_AS_OPENGL_ES) && !defined(ENGINE_CLIENT_BACKEND_OPENGL_BACKEND_OPENGL_H)) || \
3 (defined(BACKEND_AS_OPENGL_ES) && !defined(ENGINE_CLIENT_BACKEND_OPENGL_BACKEND_OPENGL_H_AS_ES))
4
5#if !defined(BACKEND_AS_OPENGL_ES) && !defined(ENGINE_CLIENT_BACKEND_OPENGL_BACKEND_OPENGL_H)
6#define ENGINE_CLIENT_BACKEND_OPENGL_BACKEND_OPENGL_H
7#endif
8
9#if defined(BACKEND_AS_OPENGL_ES) && !defined(ENGINE_CLIENT_BACKEND_OPENGL_BACKEND_OPENGL_H_AS_ES)
10#define ENGINE_CLIENT_BACKEND_OPENGL_BACKEND_OPENGL_H_AS_ES
11#endif
12
13#include <base/dbg.h>
14
18
19class CGLSLTWProgram;
22
23#if defined(BACKEND_AS_OPENGL_ES) && defined(CONF_BACKEND_OPENGL_ES3)
24#define BACKEND_GL_MODERN_API 1
25#endif
26
27// takes care of opengl related rendering
29{
30protected:
52 std::vector<CTexture> m_vTextures;
53 std::atomic<uint64_t> *m_pTextureMemoryUsage;
54
55 // Position of the viewport within the drawable area, with the bottom left origin
56 // that OpenGL uses. The rendered image is aligned to the top left, so this is not
57 // the origin of the drawable area when the viewport is clamped.
58 int m_ViewportX = 0;
59 int m_ViewportY = 0;
60 uint32_t m_CanvasWidth = 0;
61 uint32_t m_CanvasHeight = 0;
62 bool m_HasDisplayCutout = false;
63
65
72
74 EBlendMode m_LastBlendMode; // avoid all possible opengl state changes
76
78
80
81 bool IsTexturedState(const CCommandBuffer::SState &State);
82
83 bool InitOpenGL(const SCommand_Init *pCommand);
84
85 void SetState(const CCommandBuffer::SState &State, bool Use2DArrayTexture = false);
86 virtual bool IsNewApi() { return false; }
87 void DestroyTexture(int Slot);
88
89 bool GetPresentedImageData(uint32_t &Width, uint32_t &Height, CImageInfo::EImageFormat &Format, std::vector<uint8_t> &vDstData) override;
90
91 static size_t GLFormatToPixelSize(int GLFormat);
92
93 void TextureUpdate(int Slot, int X, int Y, int Width, int Height, int GLFormat, uint8_t *pTexData);
94 void TextureCreate(int Slot, int Width, int Height, int GLFormat, int GLStoreFormat, int Flags, uint8_t *pTexData);
95
96 virtual bool Cmd_Init(const SCommand_Init *pCommand);
97 virtual void Cmd_Shutdown(const SCommand_Shutdown *pCommand) {}
103 virtual void Cmd_Clear(const CCommandBuffer::SCommand_Clear *pCommand);
104 virtual void Cmd_Render(const CCommandBuffer::SCommand_Render *pCommand);
105 virtual void Cmd_RenderTex3D(const CCommandBuffer::SCommand_RenderTex3D *pCommand) { dbg_assert_failed("Call of unsupported Cmd_RenderTex3D"); }
108
110
111 virtual void Cmd_CreateBufferObject(const CCommandBuffer::SCommand_CreateBufferObject *pCommand) { dbg_assert_failed("Call of unsupported Cmd_CreateBufferObject"); }
112 virtual void Cmd_RecreateBufferObject(const CCommandBuffer::SCommand_RecreateBufferObject *pCommand) { dbg_assert_failed("Call of unsupported Cmd_RecreateBufferObject"); }
113 virtual void Cmd_UpdateBufferObject(const CCommandBuffer::SCommand_UpdateBufferObject *pCommand) { dbg_assert_failed("Call of unsupported Cmd_UpdateBufferObject"); }
114 virtual void Cmd_CopyBufferObject(const CCommandBuffer::SCommand_CopyBufferObject *pCommand) { dbg_assert_failed("Call of unsupported Cmd_CopyBufferObject"); }
115 virtual void Cmd_DeleteBufferObject(const CCommandBuffer::SCommand_DeleteBufferObject *pCommand) { dbg_assert_failed("Call of unsupported Cmd_DeleteBufferObject"); }
116
117 virtual void Cmd_CreateBufferContainer(const CCommandBuffer::SCommand_CreateBufferContainer *pCommand) { dbg_assert_failed("Call of unsupported Cmd_CreateBufferContainer"); }
118 virtual void Cmd_UpdateBufferContainer(const CCommandBuffer::SCommand_UpdateBufferContainer *pCommand) { dbg_assert_failed("Call of unsupported Cmd_UpdateBufferContainer"); }
119 virtual void Cmd_DeleteBufferContainer(const CCommandBuffer::SCommand_DeleteBufferContainer *pCommand) { dbg_assert_failed("Call of unsupported Cmd_DeleteBufferContainer"); }
120 virtual void Cmd_IndicesRequiredNumNotify(const CCommandBuffer::SCommand_IndicesRequiredNumNotify *pCommand) { dbg_assert_failed("Call of unsupported Cmd_IndicesRequiredNumNotify"); }
121
122 virtual void Cmd_RenderTileLayer(const CCommandBuffer::SCommand_RenderTileLayer *pCommand) { dbg_assert_failed("Call of unsupported Cmd_RenderTileLayer"); }
123 virtual void Cmd_RenderBorderTile(const CCommandBuffer::SCommand_RenderBorderTile *pCommand) { dbg_assert_failed("Call of unsupported Cmd_RenderBorderTile"); }
124 virtual void Cmd_RenderQuadLayer(const CCommandBuffer::SCommand_RenderQuadLayer *pCommand, bool Grouped) { dbg_assert_failed("Call of unsupported Cmd_RenderQuadLayer"); }
125 virtual void Cmd_RenderText(const CCommandBuffer::SCommand_RenderText *pCommand) { dbg_assert_failed("Call of unsupported Cmd_RenderText"); }
126 virtual void Cmd_RenderQuadContainer(const CCommandBuffer::SCommand_RenderQuadContainer *pCommand) { dbg_assert_failed("Call of unsupported Cmd_RenderQuadContainer"); }
127 virtual void Cmd_RenderQuadContainerEx(const CCommandBuffer::SCommand_RenderQuadContainerEx *pCommand) { dbg_assert_failed("Call of unsupported Cmd_RenderQuadContainerEx"); }
128 virtual void Cmd_RenderQuadContainerAsSpriteMultiple(const CCommandBuffer::SCommand_RenderQuadContainerAsSpriteMultiple *pCommand) { dbg_assert_failed("Call of unsupported Cmd_RenderQuadContainerAsSpriteMultiple"); }
129
130public:
132
133 ERunCommandReturnTypes RunCommand(const CCommandBuffer::SCommand *pBaseCommand) override;
134};
135
137{
142 std::vector<SBufferContainer> m_vBufferContainers;
143
144#ifndef BACKEND_AS_OPENGL_ES
146#endif
147
149 {
150 SBufferObject(TWGLuint BufferObjectId) :
151 m_BufferObjectId(BufferObjectId)
152 {
153 m_pData = nullptr;
154 m_DataSize = 0;
155 }
157 uint8_t *m_pData;
159 };
160
161 std::vector<SBufferObject> m_vBufferObjectIndices;
162
163#ifndef BACKEND_GL_MODERN_API
164 bool DoAnalyzeStep(size_t CheckCount, size_t VerticesCount, uint8_t aFakeTexture[], size_t SingleImageSize);
166#endif
167
168 void UseProgram(CGLSLTWProgram *pProgram);
169
170protected:
171 void SetState(const CCommandBuffer::SState &State, CGLSLTWProgram *pProgram, bool Use2DArrayTextures = false);
172
173#ifndef BACKEND_GL_MODERN_API
174 bool Cmd_Init(const SCommand_Init *pCommand) override;
175 void Cmd_Shutdown(const SCommand_Shutdown *pCommand) override;
176
177 void Cmd_RenderTex3D(const CCommandBuffer::SCommand_RenderTex3D *pCommand) override;
178
184
189
192#endif
193
200};
201
205
206#if defined(BACKEND_AS_OPENGL_ES) && defined(CONF_BACKEND_OPENGL_ES3)
207#undef BACKEND_GL_MODERN_API
208#endif
209
210#endif
ERunCommandReturnTypes
Definition backend_base.h:31
Definition backend_base.h:86
Definition backend_opengl.h:137
CGLSLTileProgram * m_pBorderTileProgramTextured
Definition backend_opengl.h:197
CGLSLPrimitiveProgram * m_pPrimitive3DProgram
Definition backend_opengl.h:198
CGLSLTileProgram * m_pBorderTileProgram
Definition backend_opengl.h:196
std::vector< SBufferContainer > m_vBufferContainers
Definition backend_opengl.h:142
void Cmd_RenderBorderTile(const CCommandBuffer::SCommand_RenderBorderTile *pCommand) override
Definition backend_opengl.cpp:2054
void SetState(const CCommandBuffer::SState &State, CGLSLTWProgram *pProgram, bool Use2DArrayTextures=false)
Definition backend_opengl.cpp:1163
void Cmd_CopyBufferObject(const CCommandBuffer::SCommand_CopyBufferObject *pCommand) override
Definition backend_opengl.cpp:1967
GL_SVertexTex3D m_aStreamVertices[1024 *4]
Definition backend_opengl.h:145
void Cmd_RenderTileLayer(const CCommandBuffer::SCommand_RenderTileLayer *pCommand) override
Definition backend_opengl.cpp:2101
CGLSLPrimitiveProgram * m_pPrimitive3DProgramTextured
Definition backend_opengl.h:199
bool IsTileMapAnalysisSucceeded()
Definition backend_opengl.cpp:1414
void Cmd_UpdateBufferContainer(const CCommandBuffer::SCommand_UpdateBufferContainer *pCommand) override
Definition backend_opengl.cpp:2016
void Cmd_RecreateBufferObject(const CCommandBuffer::SCommand_RecreateBufferObject *pCommand) override
Definition backend_opengl.cpp:1930
bool DoAnalyzeStep(size_t CheckCount, size_t VerticesCount, uint8_t aFakeTexture[], size_t SingleImageSize)
Definition backend_opengl.cpp:1313
void Cmd_RenderTex3D(const CCommandBuffer::SCommand_RenderTex3D *pCommand) override
Definition backend_opengl.cpp:1849
void Cmd_UpdateBufferObject(const CCommandBuffer::SCommand_UpdateBufferObject *pCommand) override
Definition backend_opengl.cpp:1950
bool Cmd_Init(const SCommand_Init *pCommand) override
Definition backend_opengl.cpp:1592
void UseProgram(CGLSLTWProgram *pProgram)
Definition backend_opengl.cpp:1158
CGLSLTileProgram * m_pTileProgram
Definition backend_opengl.h:194
void Cmd_CreateBufferObject(const CCommandBuffer::SCommand_CreateBufferObject *pCommand) override
Definition backend_opengl.cpp:1902
void Cmd_IndicesRequiredNumNotify(const CCommandBuffer::SCommand_IndicesRequiredNumNotify *pCommand) override
Definition backend_opengl.cpp:2050
CGLSLTileProgram * m_pTileProgramTextured
Definition backend_opengl.h:195
void Cmd_CreateBufferContainer(const CCommandBuffer::SCommand_CreateBufferContainer *pCommand) override
Definition backend_opengl.cpp:1993
void Cmd_Shutdown(const SCommand_Shutdown *pCommand) override
Definition backend_opengl.cpp:1816
std::vector< SBufferObject > m_vBufferObjectIndices
Definition backend_opengl.h:161
void Cmd_DeleteBufferContainer(const CCommandBuffer::SCommand_DeleteBufferContainer *pCommand) override
Definition backend_opengl.cpp:2031
void Cmd_DeleteBufferObject(const CCommandBuffer::SCommand_DeleteBufferObject *pCommand) override
Definition backend_opengl.cpp:1982
Definition backend_opengl.h:203
bool GetPresentedImageData(uint32_t &Width, uint32_t &Height, CImageInfo::EImageFormat &Format, std::vector< uint8_t > &vDstData) override
Definition backend_opengl.cpp:308
virtual void Cmd_RenderQuadContainerAsSpriteMultiple(const CCommandBuffer::SCommand_RenderQuadContainerAsSpriteMultiple *pCommand)
Definition backend_opengl.h:128
virtual void Cmd_RenderQuadLayer(const CCommandBuffer::SCommand_RenderQuadLayer *pCommand, bool Grouped)
Definition backend_opengl.h:124
virtual void Cmd_RenderTileLayer(const CCommandBuffer::SCommand_RenderTileLayer *pCommand)
Definition backend_opengl.h:122
bool m_HasShaders
Definition backend_opengl.h:73
virtual void Cmd_Texture_Destroy(const CCommandBuffer::SCommand_Texture_Destroy *pCommand)
Definition backend_opengl.cpp:732
bool m_Has3DTextures
Definition backend_opengl.h:69
virtual void Cmd_CreateBufferContainer(const CCommandBuffer::SCommand_CreateBufferContainer *pCommand)
Definition backend_opengl.h:117
virtual void Cmd_DeleteBufferObject(const CCommandBuffer::SCommand_DeleteBufferObject *pCommand)
Definition backend_opengl.h:115
EBlendMode m_LastBlendMode
Definition backend_opengl.h:74
virtual void Cmd_TextTexture_Update(const CCommandBuffer::SCommand_TextTexture_Update *pCommand)
Definition backend_opengl.cpp:940
virtual void Cmd_RenderBorderTile(const CCommandBuffer::SCommand_RenderBorderTile *pCommand)
Definition backend_opengl.h:123
std::atomic< uint64_t > * m_pTextureMemoryUsage
Definition backend_opengl.h:53
virtual void Cmd_Render(const CCommandBuffer::SCommand_Render *pCommand)
Definition backend_opengl.cpp:984
virtual void Cmd_Clear(const CCommandBuffer::SCommand_Clear *pCommand)
Definition backend_opengl.cpp:957
int m_ViewportX
Definition backend_opengl.h:58
virtual void Cmd_ReadPixel(const CCommandBuffer::SCommand_TrySwapAndReadPixel *pCommand)
Definition backend_opengl.cpp:1015
bool m_Has2DArrayTexturesAsExtension
Definition backend_opengl.h:67
virtual void Cmd_RenderTex3D(const CCommandBuffer::SCommand_RenderTex3D *pCommand)
Definition backend_opengl.h:105
virtual void Cmd_CreateBufferObject(const CCommandBuffer::SCommand_CreateBufferObject *pCommand)
Definition backend_opengl.h:111
bool IsTexturedState(const CCommandBuffer::SState &State)
Definition backend_opengl.cpp:72
std::vector< CTexture > m_vTextures
Definition backend_opengl.h:52
ERunCommandReturnTypes RunCommand(const CCommandBuffer::SCommand *pBaseCommand) override
Definition backend_opengl.cpp:1087
virtual void Cmd_UpdateBufferObject(const CCommandBuffer::SCommand_UpdateBufferObject *pCommand)
Definition backend_opengl.h:113
virtual void Cmd_TextTextures_Create(const CCommandBuffer::SCommand_TextTextures_Create *pCommand)
Definition backend_opengl.cpp:951
bool m_Has2DArrayTextures
Definition backend_opengl.h:66
CCommandProcessorFragment_OpenGL()
Definition backend_opengl.cpp:1081
bool m_HasMipMaps
Definition backend_opengl.h:70
virtual void Cmd_RenderQuadContainer(const CCommandBuffer::SCommand_RenderQuadContainer *pCommand)
Definition backend_opengl.h:126
void TextureUpdate(int Slot, int X, int Y, int Width, int Height, int GLFormat, uint8_t *pTexData)
Definition backend_opengl.cpp:655
virtual bool IsNewApi()
Definition backend_opengl.h:86
virtual void Cmd_DeleteBufferContainer(const CCommandBuffer::SCommand_DeleteBufferContainer *pCommand)
Definition backend_opengl.h:119
TWGLenum m_2DArrayTarget
Definition backend_opengl.h:68
bool m_IsOpenGLES
Definition backend_opengl.h:79
virtual bool Cmd_Init(const SCommand_Init *pCommand)
Definition backend_opengl.cpp:622
bool m_LastClipEnable
Definition backend_opengl.h:75
virtual void Cmd_Update_Viewport(const CCommandBuffer::SCommand_Update_Viewport *pCommand)
Definition backend_opengl.cpp:45
uint32_t m_CanvasHeight
Definition backend_opengl.h:61
virtual void Cmd_Shutdown(const SCommand_Shutdown *pCommand)
Definition backend_opengl.h:97
virtual void Cmd_RenderText(const CCommandBuffer::SCommand_RenderText *pCommand)
Definition backend_opengl.h:125
void TextureCreate(int Slot, int Width, int Height, int GLFormat, int GLStoreFormat, int Flags, uint8_t *pTexData)
Definition backend_opengl.cpp:737
bool InitOpenGL(const SCommand_Init *pCommand)
Definition backend_opengl.cpp:339
virtual void Cmd_RecreateBufferObject(const CCommandBuffer::SCommand_RecreateBufferObject *pCommand)
Definition backend_opengl.h:112
virtual void Cmd_Screenshot(const CCommandBuffer::SCommand_TrySwapAndScreenshot *pCommand)
Definition backend_opengl.cpp:1037
TWGLint m_MaxTexSize
Definition backend_opengl.h:64
virtual void Cmd_RenderQuadContainerEx(const CCommandBuffer::SCommand_RenderQuadContainerEx *pCommand)
Definition backend_opengl.h:127
virtual void Cmd_CopyBufferObject(const CCommandBuffer::SCommand_CopyBufferObject *pCommand)
Definition backend_opengl.h:114
int m_OpenGLTextureLodBIAS
Definition backend_opengl.h:77
void DestroyTexture(int Slot)
Definition backend_opengl.cpp:699
virtual void Cmd_UpdateBufferContainer(const CCommandBuffer::SCommand_UpdateBufferContainer *pCommand)
Definition backend_opengl.h:118
static size_t GLFormatToPixelSize(int GLFormat)
Definition backend_opengl.cpp:60
void SetState(const CCommandBuffer::SState &State, bool Use2DArrayTexture=false)
Definition backend_opengl.cpp:77
uint32_t m_CanvasWidth
Definition backend_opengl.h:60
int m_ViewportY
Definition backend_opengl.h:59
bool m_HasNPOTTextures
Definition backend_opengl.h:71
virtual void Cmd_TextTextures_Destroy(const CCommandBuffer::SCommand_TextTextures_Destroy *pCommand)
Definition backend_opengl.cpp:945
bool m_HasDisplayCutout
Definition backend_opengl.h:62
virtual void Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand)
Definition backend_opengl.cpp:935
virtual void Cmd_IndicesRequiredNumNotify(const CCommandBuffer::SCommand_IndicesRequiredNumNotify *pCommand)
Definition backend_opengl.h:120
Definition opengl_sl_program.h:99
Definition opengl_sl_program.h:56
Definition opengl_sl_program.h:151
EImageFormat
Definition image.h:21
uint32_t TWGLuint
Definition graphics_defines.h:7
int32_t TWGLint
Definition graphics_defines.h:8
uint32_t TWGLenum
Definition graphics_defines.h:9
EWrapMode
Definition graphics_threaded.h:42
@ REPEAT
Definition graphics_threaded.h:43
EBlendMode
Definition graphics_threaded.h:35
#define dbg_assert_failed(fmt,...)
Definition dbg.h:47
Definition graphics_threaded.h:208
Definition graphics_threaded.h:284
Definition graphics_threaded.h:305
Definition graphics_threaded.h:243
Definition graphics_threaded.h:333
Definition graphics_threaded.h:297
Definition graphics_threaded.h:342
Definition graphics_threaded.h:257
Definition graphics_threaded.h:365
Definition graphics_threaded.h:420
Definition graphics_threaded.h:408
Definition graphics_threaded.h:379
Definition graphics_threaded.h:233
Definition graphics_threaded.h:391
Definition graphics_threaded.h:350
Definition graphics_threaded.h:223
Definition graphics_threaded.h:563
Definition graphics_threaded.h:537
Definition graphics_threaded.h:553
Definition graphics_threaded.h:513
Definition graphics_threaded.h:528
Definition graphics_threaded.h:455
Definition graphics_threaded.h:464
Definition graphics_threaded.h:319
Definition graphics_threaded.h:271
Definition graphics_threaded.h:497
Definition graphics_threaded.h:183
Definition graphics_threaded.h:192
SBufferContainerInfo m_ContainerInfo
Definition backend_opengl.h:140
uint8_t * m_pData
Definition backend_opengl.h:157
size_t m_DataSize
Definition backend_opengl.h:158
SBufferObject(TWGLuint BufferObjectId)
Definition backend_opengl.h:150
TWGLuint m_BufferObjectId
Definition backend_opengl.h:156
EWrapMode m_LastWrapMode
Definition backend_opengl.h:42
CTexture()
Definition backend_opengl.h:33
TWGLuint m_Sampler
Definition backend_opengl.h:40
int m_RescaleCount
Definition backend_opengl.h:48
int m_Width
Definition backend_opengl.h:46
TWGLuint m_Tex2DArray
Definition backend_opengl.h:39
TWGLuint m_Sampler2DArray
Definition backend_opengl.h:41
int m_Height
Definition backend_opengl.h:47
int m_MemSize
Definition backend_opengl.h:44
TWGLuint m_Tex
Definition backend_opengl.h:38
float m_ResizeWidth
Definition backend_opengl.h:49
float m_ResizeHeight
Definition backend_opengl.h:50
Definition graphics.h:117
Definition graphics.h:26