UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AndroidEGL.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 AndroidEGL.h: Private EGL definitions for Android-specific functionality
5=============================================================================*/
6#pragma once
7
9
10#if USE_ANDROID_OPENGL
11
12#include "CoreMinimal.h"
13#include "Logging/LogMacros.h"
14#include <EGL/egl.h>
15#include <EGL/eglext.h>
16#include <GLES3/gl31.h>
18
19struct AndroidESPImpl;
20struct ANativeWindow;
21
22#ifndef USE_ANDROID_EGL_NO_ERROR_CONTEXT
23#if UE_BUILD_SHIPPING
24#define USE_ANDROID_EGL_NO_ERROR_CONTEXT 1
25#else
26#define USE_ANDROID_EGL_NO_ERROR_CONTEXT 0
27#endif
28#endif // USE_ANDROID_EGL_NO_ERROR_CONTEXT
29
31
33{
41
43 {
44 Reset();
45 }
46
47 void Reset()
48 {
56 }
57};
58
59
60class AndroidEGL
61{
62public:
63 enum APIVariant
64 {
67 };
68
69 static AndroidEGL* GetInstance();
70 ~AndroidEGL();
71
72 bool IsInitialized();
73
74 void InitBackBuffer();
75 void DestroyBackBuffer();
76
77 void Init(APIVariant API, uint32 MajorVersion, uint32 MinorVersion);
78
79 void UnBindRender();
80
81 void Terminate();
82
83 // Initialize the surface of the context.
84 // when using the new window locking behavior, if WindowContainer is not set an off screen surface will be used.
85 // TODO: remove bCreateWndSurface (and possibly bUseSmallSurface), these can be inferred from WindowContainer.
89
90 void GetDimensions(uint32& OutWidth, uint32& OutHeight);
91 bool IsUsingRobustContext() const { return bIsEXTRobustContextActive; }
92
93 EGLDisplay GetDisplay() const;
94 EGLSurface GetSurface() const;
95 EGLConfig GetConfig() const;
96 ANativeWindow* GetNativeWindow() const;
98
100 int32 GetError();
102
105
107 EGLContext GetCurrentContext();
108
112
114
115 // recreate the EGL surface for the current hardware window.
117
118 // Called from game thread when a window is reinited.
120
121 // true if the current surface is associated with a window.
122 bool IsUsingWindowedSurface() const;
123
124protected:
125 AndroidEGL();
126 static AndroidEGL* Singleton;
127
128private:
129 void InitEGL(APIVariant API);
130 void TerminateEGL();
131
134
135 bool InitContexts();
136 void DestroyContext(EGLContext InContext);
137
138 void ResetDisplay();
139
141
142 void ResetInternal();
144
145 // Actual Update to the egl surface to match the GT's requested size.
147
148 bool bSupportsKHRCreateContext = false;
150 bool bSupportsKHRNoErrorContext = false;
151 bool bSupportsEXTRobustContext = false;
152 bool bIsEXTRobustContextActive = false;
153
154 int* ContextAttributes = nullptr;
155};
156
157#define ENABLE_CONFIG_FILTER 1
158#define ENABLE_EGL_DEBUG 0
159#define ENABLE_VERIFY_EGL 0
160#define ENABLE_VERIFY_EGL_TRACE 0
161
162#if ENABLE_VERIFY_EGL
163
164#define VERIFY_EGL(msg) { VerifyEGLResult(eglGetError(),TEXT(#msg),TEXT(""),TEXT(__FILE__),__LINE__); }
165
166void VerifyEGLResult(EGLint ErrorCode, const TCHAR* Msg1, const TCHAR* Msg2, const TCHAR* Filename, uint32 Line)
167{
168 if (ErrorCode != EGL_SUCCESS)
169 {
170 static const TCHAR* EGLErrorStrings[] =
171 {
172 TEXT("EGL_NOT_INITIALIZED"),
173 TEXT("EGL_BAD_ACCESS"),
174 TEXT("EGL_BAD_ALLOC"),
175 TEXT("EGL_BAD_ATTRIBUTE"),
176 TEXT("EGL_BAD_CONFIG"),
177 TEXT("EGL_BAD_CONTEXT"),
178 TEXT("EGL_BAD_CURRENT_SURFACE"),
179 TEXT("EGL_BAD_DISPLAY"),
180 TEXT("EGL_BAD_MATCH"),
181 TEXT("EGL_BAD_NATIVE_PIXMAP"),
182 TEXT("EGL_BAD_NATIVE_WINDOW"),
183 TEXT("EGL_BAD_PARAMETER"),
184 TEXT("EGL_BAD_SURFACE"),
185 TEXT("EGL_CONTEXT_LOST"),
186 TEXT("UNKNOWN EGL ERROR")
187 };
188
189 uint32 ErrorIndex = FMath::Min<uint32>(ErrorCode - EGL_SUCCESS, UE_ARRAY_COUNT(EGLErrorStrings) - 1);
190 UE_LOG(LogRHI, Warning, TEXT("%s(%u): %s%s failed with error %s (0x%x)"),
191 Filename, Line, Msg1, Msg2, EGLErrorStrings[ErrorIndex], ErrorCode);
192 check(0);
193 }
194}
195
196class FEGLErrorScope
197{
198public:
200 const TCHAR* InFunctionName,
201 const TCHAR* InFilename,
202 const uint32 InLine)
203 : FunctionName(InFunctionName)
204 , Filename(InFilename)
205 , Line(InLine)
206 {
207#if ENABLE_VERIFY_EGL_TRACE
208 UE_LOG(LogRHI, Log, TEXT("EGL log before %s(%d): %s"), InFilename, InLine, InFunctionName);
209#endif
210 CheckForErrors(TEXT("Before "));
211 }
212
214 {
215#if ENABLE_VERIFY_EGL_TRACE
216 UE_LOG(LogRHI, Log, TEXT("EGL log after %s(%d): %s"), Filename, Line, FunctionName);
217#endif
218 CheckForErrors(TEXT("After "));
219 }
220
221private:
222 const TCHAR* FunctionName;
223 const TCHAR* Filename;
224 const uint32 Line;
225
226 void CheckForErrors(const TCHAR* PrefixString)
227 {
228 VerifyEGLResult(eglGetError(), PrefixString, FunctionName, Filename, Line);
229 }
230};
231
232#define MACRO_TOKENIZER(IdentifierName, Msg, FileName, LineNumber) FEGLErrorScope IdentifierName_ ## LineNumber (Msg, FileName, LineNumber)
233#define MACRO_TOKENIZER2(IdentifierName, Msg, FileName, LineNumber) MACRO_TOKENIZER(IdentiferName, Msg, FileName, LineNumber)
234#define VERIFY_EGL_SCOPE_WITH_MSG_STR(MsgStr) MACRO_TOKENIZER2(ErrorScope_, MsgStr, TEXT(__FILE__), __LINE__)
235#define VERIFY_EGL_SCOPE() VERIFY_EGL_SCOPE_WITH_MSG_STR(ANSI_TO_TCHAR(__FUNCTION__))
236#define VERIFY_EGL_FUNC(Func, ...) { VERIFY_EGL_SCOPE_WITH_MSG_STR(TEXT(#Func)); Func(__VA_ARGS__); }
237#else
238#define VERIFY_EGL(...)
239#define VERIFY_EGL_SCOPE(...)
240#endif
241
242
243
244#endif
#define check(expr)
Definition AssertionMacros.h:314
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
void Init()
Definition LockFreeList.h:4
#define DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity)
Definition LogMacros.h:361
#define UE_LOG(CategoryName, Verbosity, Format,...)
Definition LogMacros.h:270
#define UE_ARRAY_COUNT(array)
Definition UnrealTemplate.h:212
uint32_t uint32
Definition binka_ue_file_header.h:6
UTickableTransformConstraint * GetConfig(const UClass *InConstraintClass)
Definition TransformConstraintUtil.cpp:878
Definition LinuxOpenGLPlatform.cpp:39
GLuint ViewportFramebuffer
Definition LinuxOpenGLPlatform.cpp:45
GLuint BackBufferResource
Definition WindowsOpenGLPlatform.cpp:43
GLenum BackBufferTarget
Definition WindowsOpenGLPlatform.cpp:44
Definition Optional.h:131