DDraceNetwork 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/system.h>
14
16
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:
31 struct CTexture
32 {
37
39 TWGLuint m_Tex2DArray; // or 3D texture as fallback
41 TWGLuint m_Sampler2DArray; // or 3D texture as fallback
43
45
51 };
52 std::vector<CTexture> m_vTextures;
53 std::atomic<uint64_t> *m_pTextureMemoryUsage;
54
55 uint32_t m_CanvasWidth = 0;
56 uint32_t m_CanvasHeight = 0;
57
59
66
68 int m_LastBlendMode; // avoid all possible opengl state changes
70
72
74
75 bool IsTexturedState(const CCommandBuffer::SState &State);
76
77 bool InitOpenGL(const SCommand_Init *pCommand);
78
79 void SetState(const CCommandBuffer::SState &State, bool Use2DArrayTexture = false);
80 virtual bool IsNewApi() { return false; }
81 void DestroyTexture(int Slot);
82
83 bool GetPresentedImageData(uint32_t &Width, uint32_t &Height, CImageInfo::EImageFormat &Format, std::vector<uint8_t> &vDstData) override;
84
85 static size_t GLFormatToPixelSize(int GLFormat);
86
87 void TextureUpdate(int Slot, int X, int Y, int Width, int Height, int GLFormat, uint8_t *pTexData);
88 void TextureCreate(int Slot, int Width, int Height, int GLFormat, int GLStoreFormat, int Flags, uint8_t *pTexData);
89
90 virtual bool Cmd_Init(const SCommand_Init *pCommand);
91 virtual void Cmd_Shutdown(const SCommand_Shutdown *pCommand) {}
99 virtual void Cmd_RenderTex3D(const CCommandBuffer::SCommand_RenderTex3D *pCommand) { dbg_assert(false, "Call of unsupported Cmd_RenderTex3D"); }
102
104
105 virtual void Cmd_CreateBufferObject(const CCommandBuffer::SCommand_CreateBufferObject *pCommand) { dbg_assert(false, "Call of unsupported Cmd_CreateBufferObject"); }
106 virtual void Cmd_RecreateBufferObject(const CCommandBuffer::SCommand_RecreateBufferObject *pCommand) { dbg_assert(false, "Call of unsupported Cmd_RecreateBufferObject"); }
107 virtual void Cmd_UpdateBufferObject(const CCommandBuffer::SCommand_UpdateBufferObject *pCommand) { dbg_assert(false, "Call of unsupported Cmd_UpdateBufferObject"); }
108 virtual void Cmd_CopyBufferObject(const CCommandBuffer::SCommand_CopyBufferObject *pCommand) { dbg_assert(false, "Call of unsupported Cmd_CopyBufferObject"); }
109 virtual void Cmd_DeleteBufferObject(const CCommandBuffer::SCommand_DeleteBufferObject *pCommand) { dbg_assert(false, "Call of unsupported Cmd_DeleteBufferObject"); }
110
111 virtual void Cmd_CreateBufferContainer(const CCommandBuffer::SCommand_CreateBufferContainer *pCommand) { dbg_assert(false, "Call of unsupported Cmd_CreateBufferContainer"); }
112 virtual void Cmd_UpdateBufferContainer(const CCommandBuffer::SCommand_UpdateBufferContainer *pCommand) { dbg_assert(false, "Call of unsupported Cmd_UpdateBufferContainer"); }
113 virtual void Cmd_DeleteBufferContainer(const CCommandBuffer::SCommand_DeleteBufferContainer *pCommand) { dbg_assert(false, "Call of unsupported Cmd_DeleteBufferContainer"); }
114 virtual void Cmd_IndicesRequiredNumNotify(const CCommandBuffer::SCommand_IndicesRequiredNumNotify *pCommand) { dbg_assert(false, "Call of unsupported Cmd_IndicesRequiredNumNotify"); }
115
116 virtual void Cmd_RenderTileLayer(const CCommandBuffer::SCommand_RenderTileLayer *pCommand) { dbg_assert(false, "Call of unsupported Cmd_RenderTileLayer"); }
117 virtual void Cmd_RenderBorderTile(const CCommandBuffer::SCommand_RenderBorderTile *pCommand) { dbg_assert(false, "Call of unsupported Cmd_RenderBorderTile"); }
118 virtual void Cmd_RenderQuadLayer(const CCommandBuffer::SCommand_RenderQuadLayer *pCommand, bool Grouped) { dbg_assert(false, "Call of unsupported Cmd_RenderQuadLayer"); }
119 virtual void Cmd_RenderText(const CCommandBuffer::SCommand_RenderText *pCommand) { dbg_assert(false, "Call of unsupported Cmd_RenderText"); }
120 virtual void Cmd_RenderQuadContainer(const CCommandBuffer::SCommand_RenderQuadContainer *pCommand) { dbg_assert(false, "Call of unsupported Cmd_RenderQuadContainer"); }
121 virtual void Cmd_RenderQuadContainerEx(const CCommandBuffer::SCommand_RenderQuadContainerEx *pCommand) { dbg_assert(false, "Call of unsupported Cmd_RenderQuadContainerEx"); }
122 virtual void Cmd_RenderQuadContainerAsSpriteMultiple(const CCommandBuffer::SCommand_RenderQuadContainerAsSpriteMultiple *pCommand) { dbg_assert(false, "Call of unsupported Cmd_RenderQuadContainerAsSpriteMultiple"); }
123
124public:
127
129};
130
132{
137 std::vector<SBufferContainer> m_vBufferContainers;
138
139#ifndef BACKEND_AS_OPENGL_ES
141#endif
142
155
156 std::vector<SBufferObject> m_vBufferObjectIndices;
157
158#ifndef BACKEND_GL_MODERN_API
161#endif
162
164
165protected:
167
168#ifndef BACKEND_GL_MODERN_API
169 bool Cmd_Init(const SCommand_Init *pCommand) override;
170 void Cmd_Shutdown(const SCommand_Shutdown *pCommand) override;
171
173
179
184
187#endif
188
195};
196
200
201#if defined(BACKEND_AS_OPENGL_ES) && defined(CONF_BACKEND_OPENGL_ES3)
202#undef BACKEND_GL_MODERN_API
203#endif
204
205#endif
ERunCommandReturnTypes
Definition backend_base.h:28
Definition graphics_threaded.h:19
Definition backend_base.h:83
Definition backend_opengl.h:132
CGLSLTileProgram * m_pBorderTileProgramTextured
Definition backend_opengl.h:192
CGLSLPrimitiveProgram * m_pPrimitive3DProgram
Definition backend_opengl.h:193
CGLSLTileProgram * m_pBorderTileProgram
Definition backend_opengl.h:191
std::vector< SBufferContainer > m_vBufferContainers
Definition backend_opengl.h:137
void Cmd_RenderBorderTile(const CCommandBuffer::SCommand_RenderBorderTile *pCommand) override
Definition backend_opengl.cpp:1991
void SetState(const CCommandBuffer::SState &State, CGLSLTWProgram *pProgram, bool Use2DArrayTextures=false)
Definition backend_opengl.cpp:1115
void Cmd_CopyBufferObject(const CCommandBuffer::SCommand_CopyBufferObject *pCommand) override
Definition backend_opengl.cpp:1904
GL_SVertexTex3D m_aStreamVertices[1024 *4]
Definition backend_opengl.h:140
void Cmd_RenderTileLayer(const CCommandBuffer::SCommand_RenderTileLayer *pCommand) override
Definition backend_opengl.cpp:2038
CGLSLPrimitiveProgram * m_pPrimitive3DProgramTextured
Definition backend_opengl.h:194
bool IsTileMapAnalysisSucceeded()
Definition backend_opengl.cpp:1362
void Cmd_UpdateBufferContainer(const CCommandBuffer::SCommand_UpdateBufferContainer *pCommand) override
Definition backend_opengl.cpp:1953
void Cmd_RecreateBufferObject(const CCommandBuffer::SCommand_RecreateBufferObject *pCommand) override
Definition backend_opengl.cpp:1867
bool DoAnalyzeStep(size_t CheckCount, size_t VerticesCount, uint8_t aFakeTexture[], size_t SingleImageSize)
Definition backend_opengl.cpp:1263
void Cmd_RenderTex3D(const CCommandBuffer::SCommand_RenderTex3D *pCommand) override
Definition backend_opengl.cpp:1788
void Cmd_UpdateBufferObject(const CCommandBuffer::SCommand_UpdateBufferObject *pCommand) override
Definition backend_opengl.cpp:1887
bool Cmd_Init(const SCommand_Init *pCommand) override
Definition backend_opengl.cpp:1540
void UseProgram(CGLSLTWProgram *pProgram)
Definition backend_opengl.cpp:1110
CGLSLTileProgram * m_pTileProgram
Definition backend_opengl.h:189
void Cmd_CreateBufferObject(const CCommandBuffer::SCommand_CreateBufferObject *pCommand) override
Definition backend_opengl.cpp:1839
void Cmd_IndicesRequiredNumNotify(const CCommandBuffer::SCommand_IndicesRequiredNumNotify *pCommand) override
Definition backend_opengl.cpp:1987
CGLSLTileProgram * m_pTileProgramTextured
Definition backend_opengl.h:190
void Cmd_CreateBufferContainer(const CCommandBuffer::SCommand_CreateBufferContainer *pCommand) override
Definition backend_opengl.cpp:1930
void Cmd_Shutdown(const SCommand_Shutdown *pCommand) override
Definition backend_opengl.cpp:1777
std::vector< SBufferObject > m_vBufferObjectIndices
Definition backend_opengl.h:156
void Cmd_DeleteBufferContainer(const CCommandBuffer::SCommand_DeleteBufferContainer *pCommand) override
Definition backend_opengl.cpp:1968
void Cmd_DeleteBufferObject(const CCommandBuffer::SCommand_DeleteBufferObject *pCommand) override
Definition backend_opengl.cpp:1919
Definition backend_opengl.h:198
Definition backend_opengl.h:29
bool GetPresentedImageData(uint32_t &Width, uint32_t &Height, CImageInfo::EImageFormat &Format, std::vector< uint8_t > &vDstData) override
Definition backend_opengl.cpp:275
virtual void Cmd_RenderQuadContainerAsSpriteMultiple(const CCommandBuffer::SCommand_RenderQuadContainerAsSpriteMultiple *pCommand)
Definition backend_opengl.h:122
virtual ~CCommandProcessorFragment_OpenGL()=default
virtual void Cmd_RenderQuadLayer(const CCommandBuffer::SCommand_RenderQuadLayer *pCommand, bool Grouped)
Definition backend_opengl.h:118
virtual void Cmd_RenderTileLayer(const CCommandBuffer::SCommand_RenderTileLayer *pCommand)
Definition backend_opengl.h:116
bool m_HasShaders
Definition backend_opengl.h:67
virtual void Cmd_Texture_Destroy(const CCommandBuffer::SCommand_Texture_Destroy *pCommand)
Definition backend_opengl.cpp:692
bool m_Has3DTextures
Definition backend_opengl.h:63
virtual void Cmd_CreateBufferContainer(const CCommandBuffer::SCommand_CreateBufferContainer *pCommand)
Definition backend_opengl.h:111
virtual void Cmd_DeleteBufferObject(const CCommandBuffer::SCommand_DeleteBufferObject *pCommand)
Definition backend_opengl.h:109
virtual void Cmd_TextTexture_Update(const CCommandBuffer::SCommand_TextTexture_Update *pCommand)
Definition backend_opengl.cpp:910
virtual void Cmd_RenderBorderTile(const CCommandBuffer::SCommand_RenderBorderTile *pCommand)
Definition backend_opengl.h:117
std::atomic< uint64_t > * m_pTextureMemoryUsage
Definition backend_opengl.h:53
virtual void Cmd_Render(const CCommandBuffer::SCommand_Render *pCommand)
Definition backend_opengl.cpp:943
virtual void Cmd_Clear(const CCommandBuffer::SCommand_Clear *pCommand)
Definition backend_opengl.cpp:927
virtual void Cmd_ReadPixel(const CCommandBuffer::SCommand_TrySwapAndReadPixel *pCommand)
Definition backend_opengl.cpp:974
bool m_Has2DArrayTexturesAsExtension
Definition backend_opengl.h:61
virtual void Cmd_RenderTex3D(const CCommandBuffer::SCommand_RenderTex3D *pCommand)
Definition backend_opengl.h:99
virtual void Cmd_CreateBufferObject(const CCommandBuffer::SCommand_CreateBufferObject *pCommand)
Definition backend_opengl.h:105
bool IsTexturedState(const CCommandBuffer::SState &State)
Definition backend_opengl.cpp:58
std::vector< CTexture > m_vTextures
Definition backend_opengl.h:52
ERunCommandReturnTypes RunCommand(const CCommandBuffer::SCommand *pBaseCommand) override
Definition backend_opengl.cpp:1039
virtual void Cmd_UpdateBufferObject(const CCommandBuffer::SCommand_UpdateBufferObject *pCommand)
Definition backend_opengl.h:107
virtual void Cmd_TextTextures_Create(const CCommandBuffer::SCommand_TextTextures_Create *pCommand)
Definition backend_opengl.cpp:921
bool m_Has2DArrayTextures
Definition backend_opengl.h:60
CCommandProcessorFragment_OpenGL()
Definition backend_opengl.cpp:1033
bool m_HasMipMaps
Definition backend_opengl.h:64
virtual void Cmd_RenderQuadContainer(const CCommandBuffer::SCommand_RenderQuadContainer *pCommand)
Definition backend_opengl.h:120
void TextureUpdate(int Slot, int X, int Y, int Width, int Height, int GLFormat, uint8_t *pTexData)
Definition backend_opengl.cpp:615
virtual bool IsNewApi()
Definition backend_opengl.h:80
virtual void Cmd_DeleteBufferContainer(const CCommandBuffer::SCommand_DeleteBufferContainer *pCommand)
Definition backend_opengl.h:113
TWGLenum m_2DArrayTarget
Definition backend_opengl.h:62
bool m_IsOpenGLES
Definition backend_opengl.h:73
virtual bool Cmd_Init(const SCommand_Init *pCommand)
Definition backend_opengl.cpp:582
bool m_LastClipEnable
Definition backend_opengl.h:69
virtual void Cmd_Update_Viewport(const CCommandBuffer::SCommand_Update_Viewport *pCommand)
Definition backend_opengl.cpp:36
uint32_t m_CanvasHeight
Definition backend_opengl.h:56
virtual void Cmd_Shutdown(const SCommand_Shutdown *pCommand)
Definition backend_opengl.h:91
virtual void Cmd_RenderText(const CCommandBuffer::SCommand_RenderText *pCommand)
Definition backend_opengl.h:119
void TextureCreate(int Slot, int Width, int Height, int GLFormat, int GLStoreFormat, int Flags, uint8_t *pTexData)
Definition backend_opengl.cpp:697
bool InitOpenGL(const SCommand_Init *pCommand)
Definition backend_opengl.cpp:306
virtual void Cmd_RecreateBufferObject(const CCommandBuffer::SCommand_RecreateBufferObject *pCommand)
Definition backend_opengl.h:106
virtual void Cmd_Screenshot(const CCommandBuffer::SCommand_TrySwapAndScreenshot *pCommand)
Definition backend_opengl.cpp:993
TWGLint m_MaxTexSize
Definition backend_opengl.h:58
virtual void Cmd_RenderQuadContainerEx(const CCommandBuffer::SCommand_RenderQuadContainerEx *pCommand)
Definition backend_opengl.h:121
int m_LastBlendMode
Definition backend_opengl.h:68
virtual void Cmd_CopyBufferObject(const CCommandBuffer::SCommand_CopyBufferObject *pCommand)
Definition backend_opengl.h:108
int m_OpenGLTextureLodBIAS
Definition backend_opengl.h:71
void DestroyTexture(int Slot)
Definition backend_opengl.cpp:659
virtual void Cmd_UpdateBufferContainer(const CCommandBuffer::SCommand_UpdateBufferContainer *pCommand)
Definition backend_opengl.h:112
static size_t GLFormatToPixelSize(int GLFormat)
Definition backend_opengl.cpp:46
void SetState(const CCommandBuffer::SState &State, bool Use2DArrayTexture=false)
Definition backend_opengl.cpp:63
uint32_t m_CanvasWidth
Definition backend_opengl.h:55
bool m_HasNPOTTextures
Definition backend_opengl.h:65
virtual void Cmd_TextTextures_Destroy(const CCommandBuffer::SCommand_TextTextures_Destroy *pCommand)
Definition backend_opengl.cpp:915
virtual void Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand)
Definition backend_opengl.cpp:905
virtual void Cmd_IndicesRequiredNumNotify(const CCommandBuffer::SCommand_IndicesRequiredNumNotify *pCommand)
Definition backend_opengl.h:114
Definition opengl_sl_program.h:98
Definition opengl_sl_program.h:55
Definition opengl_sl_program.h:150
EImageFormat
Definition image.h:18
Definition vmath.h:15
uint32_t TWGLuint
Definition graphics_defines.h:7
int32_t TWGLint
Definition graphics_defines.h:8
uint32_t TWGLenum
Definition graphics_defines.h:9
#define dbg_assert(test, fmt,...)
Definition system.h:64
Definition graphics_threaded.h:211
Definition graphics_threaded.h:287
Definition graphics_threaded.h:308
Definition graphics_threaded.h:246
Definition graphics_threaded.h:336
Definition graphics_threaded.h:300
Definition graphics_threaded.h:345
Definition graphics_threaded.h:260
Definition graphics_threaded.h:368
Definition graphics_threaded.h:423
Definition graphics_threaded.h:411
Definition graphics_threaded.h:382
Definition graphics_threaded.h:236
Definition graphics_threaded.h:394
Definition graphics_threaded.h:353
Definition graphics_threaded.h:226
Definition graphics_threaded.h:562
Definition graphics_threaded.h:536
Definition graphics_threaded.h:552
Definition graphics_threaded.h:512
Definition graphics_threaded.h:527
Definition graphics_threaded.h:458
Definition graphics_threaded.h:467
Definition graphics_threaded.h:322
Definition graphics_threaded.h:274
Definition graphics_threaded.h:500
Definition graphics_threaded.h:184
Definition graphics_threaded.h:195
SBufferContainerInfo m_ContainerInfo
Definition backend_opengl.h:135
uint8_t * m_pData
Definition backend_opengl.h:152
size_t m_DataSize
Definition backend_opengl.h:153
SBufferObject(TWGLuint BufferObjectId)
Definition backend_opengl.h:145
TWGLuint m_BufferObjectId
Definition backend_opengl.h:151
Definition backend_opengl.h:32
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
int m_LastWrapMode
Definition backend_opengl.h:42
float m_ResizeHeight
Definition backend_opengl.h:50
Definition graphics.h:119
Definition graphics.h:26