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
17
18class CGLSLTWProgram;
21
22#if defined(BACKEND_AS_OPENGL_ES) && defined(CONF_BACKEND_OPENGL_ES3)
23#define BACKEND_GL_MODERN_API 1
24#endif
25
26// takes care of opengl related rendering
28{
29protected:
51 std::vector<CTexture> m_vTextures;
52 std::atomic<uint64_t> *m_pTextureMemoryUsage;
53
54 uint32_t m_CanvasWidth = 0;
55 uint32_t m_CanvasHeight = 0;
56
58
65
67 EBlendMode m_LastBlendMode; // avoid all possible opengl state changes
69
71
73
74 bool IsTexturedState(const CCommandBuffer::SState &State);
75
76 bool InitOpenGL(const SCommand_Init *pCommand);
77
78 void SetState(const CCommandBuffer::SState &State, bool Use2DArrayTexture = false);
79 virtual bool IsNewApi() { return false; }
80 void DestroyTexture(int Slot);
81
82 bool GetPresentedImageData(uint32_t &Width, uint32_t &Height, CImageInfo::EImageFormat &Format, std::vector<uint8_t> &vDstData) override;
83
84 static size_t GLFormatToPixelSize(int GLFormat);
85
86 void TextureUpdate(int Slot, int X, int Y, int Width, int Height, int GLFormat, uint8_t *pTexData);
87 void TextureCreate(int Slot, int Width, int Height, int GLFormat, int GLStoreFormat, int Flags, uint8_t *pTexData);
88
89 virtual bool Cmd_Init(const SCommand_Init *pCommand);
90 virtual void Cmd_Shutdown(const SCommand_Shutdown *pCommand) {}
96 virtual void Cmd_Clear(const CCommandBuffer::SCommand_Clear *pCommand);
97 virtual void Cmd_Render(const CCommandBuffer::SCommand_Render *pCommand);
98 virtual void Cmd_RenderTex3D(const CCommandBuffer::SCommand_RenderTex3D *pCommand) { dbg_assert_failed("Call of unsupported Cmd_RenderTex3D"); }
101
103
104 virtual void Cmd_CreateBufferObject(const CCommandBuffer::SCommand_CreateBufferObject *pCommand) { dbg_assert_failed("Call of unsupported Cmd_CreateBufferObject"); }
105 virtual void Cmd_RecreateBufferObject(const CCommandBuffer::SCommand_RecreateBufferObject *pCommand) { dbg_assert_failed("Call of unsupported Cmd_RecreateBufferObject"); }
106 virtual void Cmd_UpdateBufferObject(const CCommandBuffer::SCommand_UpdateBufferObject *pCommand) { dbg_assert_failed("Call of unsupported Cmd_UpdateBufferObject"); }
107 virtual void Cmd_CopyBufferObject(const CCommandBuffer::SCommand_CopyBufferObject *pCommand) { dbg_assert_failed("Call of unsupported Cmd_CopyBufferObject"); }
108 virtual void Cmd_DeleteBufferObject(const CCommandBuffer::SCommand_DeleteBufferObject *pCommand) { dbg_assert_failed("Call of unsupported Cmd_DeleteBufferObject"); }
109
110 virtual void Cmd_CreateBufferContainer(const CCommandBuffer::SCommand_CreateBufferContainer *pCommand) { dbg_assert_failed("Call of unsupported Cmd_CreateBufferContainer"); }
111 virtual void Cmd_UpdateBufferContainer(const CCommandBuffer::SCommand_UpdateBufferContainer *pCommand) { dbg_assert_failed("Call of unsupported Cmd_UpdateBufferContainer"); }
112 virtual void Cmd_DeleteBufferContainer(const CCommandBuffer::SCommand_DeleteBufferContainer *pCommand) { dbg_assert_failed("Call of unsupported Cmd_DeleteBufferContainer"); }
113 virtual void Cmd_IndicesRequiredNumNotify(const CCommandBuffer::SCommand_IndicesRequiredNumNotify *pCommand) { dbg_assert_failed("Call of unsupported Cmd_IndicesRequiredNumNotify"); }
114
115 virtual void Cmd_RenderTileLayer(const CCommandBuffer::SCommand_RenderTileLayer *pCommand) { dbg_assert_failed("Call of unsupported Cmd_RenderTileLayer"); }
116 virtual void Cmd_RenderBorderTile(const CCommandBuffer::SCommand_RenderBorderTile *pCommand) { dbg_assert_failed("Call of unsupported Cmd_RenderBorderTile"); }
117 virtual void Cmd_RenderQuadLayer(const CCommandBuffer::SCommand_RenderQuadLayer *pCommand, bool Grouped) { dbg_assert_failed("Call of unsupported Cmd_RenderQuadLayer"); }
118 virtual void Cmd_RenderText(const CCommandBuffer::SCommand_RenderText *pCommand) { dbg_assert_failed("Call of unsupported Cmd_RenderText"); }
119 virtual void Cmd_RenderQuadContainer(const CCommandBuffer::SCommand_RenderQuadContainer *pCommand) { dbg_assert_failed("Call of unsupported Cmd_RenderQuadContainer"); }
120 virtual void Cmd_RenderQuadContainerEx(const CCommandBuffer::SCommand_RenderQuadContainerEx *pCommand) { dbg_assert_failed("Call of unsupported Cmd_RenderQuadContainerEx"); }
121 virtual void Cmd_RenderQuadContainerAsSpriteMultiple(const CCommandBuffer::SCommand_RenderQuadContainerAsSpriteMultiple *pCommand) { dbg_assert_failed("Call of unsupported Cmd_RenderQuadContainerAsSpriteMultiple"); }
122
123public:
125
126 ERunCommandReturnTypes RunCommand(const CCommandBuffer::SCommand *pBaseCommand) override;
127};
128
130{
135 std::vector<SBufferContainer> m_vBufferContainers;
136
137#ifndef BACKEND_AS_OPENGL_ES
139#endif
140
142 {
143 SBufferObject(TWGLuint BufferObjectId) :
144 m_BufferObjectId(BufferObjectId)
145 {
146 m_pData = NULL;
147 m_DataSize = 0;
148 }
150 uint8_t *m_pData;
152 };
153
154 std::vector<SBufferObject> m_vBufferObjectIndices;
155
156#ifndef BACKEND_GL_MODERN_API
157 bool DoAnalyzeStep(size_t CheckCount, size_t VerticesCount, uint8_t aFakeTexture[], size_t SingleImageSize);
159#endif
160
161 void UseProgram(CGLSLTWProgram *pProgram);
162
163protected:
164 void SetState(const CCommandBuffer::SState &State, CGLSLTWProgram *pProgram, bool Use2DArrayTextures = false);
165
166#ifndef BACKEND_GL_MODERN_API
167 bool Cmd_Init(const SCommand_Init *pCommand) override;
168 void Cmd_Shutdown(const SCommand_Shutdown *pCommand) override;
169
170 void Cmd_RenderTex3D(const CCommandBuffer::SCommand_RenderTex3D *pCommand) override;
171
177
182
185#endif
186
193};
194
198
199#if defined(BACKEND_AS_OPENGL_ES) && defined(CONF_BACKEND_OPENGL_ES3)
200#undef BACKEND_GL_MODERN_API
201#endif
202
203#endif
ERunCommandReturnTypes
Definition backend_base.h:27
Definition backend_base.h:82
Definition backend_opengl.h:130
CGLSLTileProgram * m_pBorderTileProgramTextured
Definition backend_opengl.h:190
CGLSLPrimitiveProgram * m_pPrimitive3DProgram
Definition backend_opengl.h:191
CGLSLTileProgram * m_pBorderTileProgram
Definition backend_opengl.h:189
std::vector< SBufferContainer > m_vBufferContainers
Definition backend_opengl.h:135
void Cmd_RenderBorderTile(const CCommandBuffer::SCommand_RenderBorderTile *pCommand) override
Definition backend_opengl.cpp:1988
void SetState(const CCommandBuffer::SState &State, CGLSLTWProgram *pProgram, bool Use2DArrayTextures=false)
Definition backend_opengl.cpp:1112
void Cmd_CopyBufferObject(const CCommandBuffer::SCommand_CopyBufferObject *pCommand) override
Definition backend_opengl.cpp:1901
GL_SVertexTex3D m_aStreamVertices[1024 *4]
Definition backend_opengl.h:138
void Cmd_RenderTileLayer(const CCommandBuffer::SCommand_RenderTileLayer *pCommand) override
Definition backend_opengl.cpp:2035
CGLSLPrimitiveProgram * m_pPrimitive3DProgramTextured
Definition backend_opengl.h:192
bool IsTileMapAnalysisSucceeded()
Definition backend_opengl.cpp:1359
void Cmd_UpdateBufferContainer(const CCommandBuffer::SCommand_UpdateBufferContainer *pCommand) override
Definition backend_opengl.cpp:1950
void Cmd_RecreateBufferObject(const CCommandBuffer::SCommand_RecreateBufferObject *pCommand) override
Definition backend_opengl.cpp:1864
bool DoAnalyzeStep(size_t CheckCount, size_t VerticesCount, uint8_t aFakeTexture[], size_t SingleImageSize)
Definition backend_opengl.cpp:1260
void Cmd_RenderTex3D(const CCommandBuffer::SCommand_RenderTex3D *pCommand) override
Definition backend_opengl.cpp:1785
void Cmd_UpdateBufferObject(const CCommandBuffer::SCommand_UpdateBufferObject *pCommand) override
Definition backend_opengl.cpp:1884
bool Cmd_Init(const SCommand_Init *pCommand) override
Definition backend_opengl.cpp:1537
void UseProgram(CGLSLTWProgram *pProgram)
Definition backend_opengl.cpp:1107
CGLSLTileProgram * m_pTileProgram
Definition backend_opengl.h:187
void Cmd_CreateBufferObject(const CCommandBuffer::SCommand_CreateBufferObject *pCommand) override
Definition backend_opengl.cpp:1836
void Cmd_IndicesRequiredNumNotify(const CCommandBuffer::SCommand_IndicesRequiredNumNotify *pCommand) override
Definition backend_opengl.cpp:1984
CGLSLTileProgram * m_pTileProgramTextured
Definition backend_opengl.h:188
void Cmd_CreateBufferContainer(const CCommandBuffer::SCommand_CreateBufferContainer *pCommand) override
Definition backend_opengl.cpp:1927
void Cmd_Shutdown(const SCommand_Shutdown *pCommand) override
Definition backend_opengl.cpp:1774
std::vector< SBufferObject > m_vBufferObjectIndices
Definition backend_opengl.h:154
void Cmd_DeleteBufferContainer(const CCommandBuffer::SCommand_DeleteBufferContainer *pCommand) override
Definition backend_opengl.cpp:1965
void Cmd_DeleteBufferObject(const CCommandBuffer::SCommand_DeleteBufferObject *pCommand) override
Definition backend_opengl.cpp:1916
Definition backend_opengl.h:196
bool GetPresentedImageData(uint32_t &Width, uint32_t &Height, CImageInfo::EImageFormat &Format, std::vector< uint8_t > &vDstData) override
Definition backend_opengl.cpp:272
virtual void Cmd_RenderQuadContainerAsSpriteMultiple(const CCommandBuffer::SCommand_RenderQuadContainerAsSpriteMultiple *pCommand)
Definition backend_opengl.h:121
virtual void Cmd_RenderQuadLayer(const CCommandBuffer::SCommand_RenderQuadLayer *pCommand, bool Grouped)
Definition backend_opengl.h:117
virtual void Cmd_RenderTileLayer(const CCommandBuffer::SCommand_RenderTileLayer *pCommand)
Definition backend_opengl.h:115
bool m_HasShaders
Definition backend_opengl.h:66
virtual void Cmd_Texture_Destroy(const CCommandBuffer::SCommand_Texture_Destroy *pCommand)
Definition backend_opengl.cpp:689
bool m_Has3DTextures
Definition backend_opengl.h:62
virtual void Cmd_CreateBufferContainer(const CCommandBuffer::SCommand_CreateBufferContainer *pCommand)
Definition backend_opengl.h:110
virtual void Cmd_DeleteBufferObject(const CCommandBuffer::SCommand_DeleteBufferObject *pCommand)
Definition backend_opengl.h:108
EBlendMode m_LastBlendMode
Definition backend_opengl.h:67
virtual void Cmd_TextTexture_Update(const CCommandBuffer::SCommand_TextTexture_Update *pCommand)
Definition backend_opengl.cpp:907
virtual void Cmd_RenderBorderTile(const CCommandBuffer::SCommand_RenderBorderTile *pCommand)
Definition backend_opengl.h:116
std::atomic< uint64_t > * m_pTextureMemoryUsage
Definition backend_opengl.h:52
virtual void Cmd_Render(const CCommandBuffer::SCommand_Render *pCommand)
Definition backend_opengl.cpp:940
virtual void Cmd_Clear(const CCommandBuffer::SCommand_Clear *pCommand)
Definition backend_opengl.cpp:924
virtual void Cmd_ReadPixel(const CCommandBuffer::SCommand_TrySwapAndReadPixel *pCommand)
Definition backend_opengl.cpp:971
bool m_Has2DArrayTexturesAsExtension
Definition backend_opengl.h:60
virtual void Cmd_RenderTex3D(const CCommandBuffer::SCommand_RenderTex3D *pCommand)
Definition backend_opengl.h:98
virtual void Cmd_CreateBufferObject(const CCommandBuffer::SCommand_CreateBufferObject *pCommand)
Definition backend_opengl.h:104
bool IsTexturedState(const CCommandBuffer::SState &State)
Definition backend_opengl.cpp:55
std::vector< CTexture > m_vTextures
Definition backend_opengl.h:51
ERunCommandReturnTypes RunCommand(const CCommandBuffer::SCommand *pBaseCommand) override
Definition backend_opengl.cpp:1036
virtual void Cmd_UpdateBufferObject(const CCommandBuffer::SCommand_UpdateBufferObject *pCommand)
Definition backend_opengl.h:106
virtual void Cmd_TextTextures_Create(const CCommandBuffer::SCommand_TextTextures_Create *pCommand)
Definition backend_opengl.cpp:918
bool m_Has2DArrayTextures
Definition backend_opengl.h:59
CCommandProcessorFragment_OpenGL()
Definition backend_opengl.cpp:1030
bool m_HasMipMaps
Definition backend_opengl.h:63
virtual void Cmd_RenderQuadContainer(const CCommandBuffer::SCommand_RenderQuadContainer *pCommand)
Definition backend_opengl.h:119
void TextureUpdate(int Slot, int X, int Y, int Width, int Height, int GLFormat, uint8_t *pTexData)
Definition backend_opengl.cpp:612
virtual bool IsNewApi()
Definition backend_opengl.h:79
virtual void Cmd_DeleteBufferContainer(const CCommandBuffer::SCommand_DeleteBufferContainer *pCommand)
Definition backend_opengl.h:112
TWGLenum m_2DArrayTarget
Definition backend_opengl.h:61
bool m_IsOpenGLES
Definition backend_opengl.h:72
virtual bool Cmd_Init(const SCommand_Init *pCommand)
Definition backend_opengl.cpp:579
bool m_LastClipEnable
Definition backend_opengl.h:68
virtual void Cmd_Update_Viewport(const CCommandBuffer::SCommand_Update_Viewport *pCommand)
Definition backend_opengl.cpp:33
uint32_t m_CanvasHeight
Definition backend_opengl.h:55
virtual void Cmd_Shutdown(const SCommand_Shutdown *pCommand)
Definition backend_opengl.h:90
virtual void Cmd_RenderText(const CCommandBuffer::SCommand_RenderText *pCommand)
Definition backend_opengl.h:118
void TextureCreate(int Slot, int Width, int Height, int GLFormat, int GLStoreFormat, int Flags, uint8_t *pTexData)
Definition backend_opengl.cpp:694
bool InitOpenGL(const SCommand_Init *pCommand)
Definition backend_opengl.cpp:303
virtual void Cmd_RecreateBufferObject(const CCommandBuffer::SCommand_RecreateBufferObject *pCommand)
Definition backend_opengl.h:105
virtual void Cmd_Screenshot(const CCommandBuffer::SCommand_TrySwapAndScreenshot *pCommand)
Definition backend_opengl.cpp:990
TWGLint m_MaxTexSize
Definition backend_opengl.h:57
virtual void Cmd_RenderQuadContainerEx(const CCommandBuffer::SCommand_RenderQuadContainerEx *pCommand)
Definition backend_opengl.h:120
virtual void Cmd_CopyBufferObject(const CCommandBuffer::SCommand_CopyBufferObject *pCommand)
Definition backend_opengl.h:107
int m_OpenGLTextureLodBIAS
Definition backend_opengl.h:70
void DestroyTexture(int Slot)
Definition backend_opengl.cpp:656
virtual void Cmd_UpdateBufferContainer(const CCommandBuffer::SCommand_UpdateBufferContainer *pCommand)
Definition backend_opengl.h:111
static size_t GLFormatToPixelSize(int GLFormat)
Definition backend_opengl.cpp:43
void SetState(const CCommandBuffer::SState &State, bool Use2DArrayTexture=false)
Definition backend_opengl.cpp:60
uint32_t m_CanvasWidth
Definition backend_opengl.h:54
bool m_HasNPOTTextures
Definition backend_opengl.h:64
virtual void Cmd_TextTextures_Destroy(const CCommandBuffer::SCommand_TextTextures_Destroy *pCommand)
Definition backend_opengl.cpp:912
virtual void Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand)
Definition backend_opengl.cpp:902
virtual void Cmd_IndicesRequiredNumNotify(const CCommandBuffer::SCommand_IndicesRequiredNumNotify *pCommand)
Definition backend_opengl.h:113
Definition opengl_sl_program.h:99
Definition opengl_sl_program.h:56
Definition opengl_sl_program.h:151
EImageFormat
Definition image.h:18
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:41
@ REPEAT
Definition graphics_threaded.h:42
EBlendMode
Definition graphics_threaded.h:34
#define dbg_assert_failed(fmt,...)
Definition dbg.h:47
Definition graphics_threaded.h:207
Definition graphics_threaded.h:283
Definition graphics_threaded.h:304
Definition graphics_threaded.h:242
Definition graphics_threaded.h:332
Definition graphics_threaded.h:296
Definition graphics_threaded.h:341
Definition graphics_threaded.h:256
Definition graphics_threaded.h:364
Definition graphics_threaded.h:419
Definition graphics_threaded.h:407
Definition graphics_threaded.h:378
Definition graphics_threaded.h:232
Definition graphics_threaded.h:390
Definition graphics_threaded.h:349
Definition graphics_threaded.h:222
Definition graphics_threaded.h:558
Definition graphics_threaded.h:532
Definition graphics_threaded.h:548
Definition graphics_threaded.h:508
Definition graphics_threaded.h:523
Definition graphics_threaded.h:454
Definition graphics_threaded.h:463
Definition graphics_threaded.h:318
Definition graphics_threaded.h:270
Definition graphics_threaded.h:496
Definition graphics_threaded.h:182
Definition graphics_threaded.h:191
SBufferContainerInfo m_ContainerInfo
Definition backend_opengl.h:133
uint8_t * m_pData
Definition backend_opengl.h:150
size_t m_DataSize
Definition backend_opengl.h:151
SBufferObject(TWGLuint BufferObjectId)
Definition backend_opengl.h:143
TWGLuint m_BufferObjectId
Definition backend_opengl.h:149
EWrapMode m_LastWrapMode
Definition backend_opengl.h:41
CTexture()
Definition backend_opengl.h:32
TWGLuint m_Sampler
Definition backend_opengl.h:39
int m_RescaleCount
Definition backend_opengl.h:47
int m_Width
Definition backend_opengl.h:45
TWGLuint m_Tex2DArray
Definition backend_opengl.h:38
TWGLuint m_Sampler2DArray
Definition backend_opengl.h:40
int m_Height
Definition backend_opengl.h:46
int m_MemSize
Definition backend_opengl.h:43
TWGLuint m_Tex
Definition backend_opengl.h:37
float m_ResizeWidth
Definition backend_opengl.h:48
float m_ResizeHeight
Definition backend_opengl.h:49
Definition graphics.h:120
Definition graphics.h:27