UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
OpenGLUtil.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 OpenGLUtil.h: OpenGL RHI utility definitions.
5=============================================================================*/
6
7#pragma once
8
9#include "RHICommandList.h"
10#include "OpenGLThirdParty.h"
12
13class FOpenGLTexture;
14
16#define ENABLE_VERIFY_GL (0 & DO_CHECK)
17#define ENABLE_VERIFY_GL_TRACE 0
18
19// Include GL debug output functionality on everything but shipping configs.
20// to enable the debug output specify '-OpenGLDebugLevel=[1-5]' via the command line.
21#define ENABLE_DEBUG_OUTPUT (!UE_BUILD_SHIPPING)
22#if !ENABLE_DEBUG_OUTPUT
23inline bool IsOGLDebugOutputEnabled() { return false; }
24inline int32 GetOGLDebugOutputLevel() { return 0; }
25#else
28#endif
29
30// Additional check that our GL calls are occurring on the expected thread
31#define ENABLE_VERIFY_GL_THREAD (!(UE_BUILD_TEST || UE_BUILD_SHIPPING))
32
34#define ENABLE_UNIFORM_BUFFER_LAYOUT_VERIFICATION ( 0 & UE_BUILD_DEBUG & (!PLATFORM_ANDROID))
35
37#define ENABLE_UNIFORM_BUFFER_LAYOUT_DUMP 0
38
43#define ENABLE_OPENGL_DEBUG_GROUPS 1
44
45#define OPENGL_PERFORMANCE_DATA_INVALID (ENABLE_VERIFY_GL | ENABLE_UNIFORM_BUFFER_LAYOUT_VERIFICATION | DEBUG_GL_SHADERS)
46
49
56
58
59#if ENABLE_VERIFY_GL_THREAD
60 #define CHECK_EXPECTED_GL_THREAD() \
61 if (!PlatformOpenGLThreadHasRenderingContext()) \
62 { \
63 UE_LOG(LogRHI, Fatal, TEXT("Potential use of GL context from incorrect thread. [IsInGameThread() = %d, IsInRenderingThread() = %d, IsInRHIThread() = %d, IsRunningRHIInSeparateThread() = %d]"), IsInGameThread(), IsInRenderingThread(), IsInRHIThread(), IsRunningRHIInSeparateThread()); \
64 }
65#else
66 #define CHECK_EXPECTED_GL_THREAD()
67#endif
68
69#if ENABLE_VERIFY_GL
71
72 void VerifyOpenGLResult(GLenum ErrorCode, const TCHAR* Msg1, const TCHAR* Msg2, const TCHAR* Filename, uint32 Line);
73 #define VERIFY_GL(msg) { CHECK_EXPECTED_GL_THREAD(); GLenum ErrorCode = PlatformGlGetError(); if (ErrorCode != GL_NO_ERROR) { VerifyOpenGLResult(ErrorCode,TEXT(#msg),TEXT(""),TEXT(__FILE__),__LINE__); } }
74
76 {
77 const char* FunctionName;
78 const TCHAR* Filename;
79 const uint32 Line;
80
82 const char* InFunctionName,
83 const TCHAR* InFilename,
84 const uint32 InLine)
85 : FunctionName(InFunctionName)
86 , Filename(InFilename)
87 , Line(InLine)
88 {
89#if ENABLE_VERIFY_GL_TRACE
90 UE_LOG(LogRHI, Log, TEXT("log before %s(%d): %s"), InFilename, InLine, ANSI_TO_TCHAR(InFunctionName));
91#endif
92 CheckForErrors(0);
93 }
94
96 {
97#if ENABLE_VERIFY_GL_TRACE
98 UE_LOG(LogRHI, Log, TEXT("log after %s(%d): %s"), Filename, Line, ANSI_TO_TCHAR(FunctionName));
99
100#endif
101
102 CheckForErrors(1);
103 }
104
105 void CheckForErrors(int32 BeforeOrAfter)
106 {
108
109 GLenum ErrorCode = PlatformGlGetError();
110 if (ErrorCode != GL_NO_ERROR)
111 {
112 const TCHAR* PrefixStrings[] = { TEXT("Before "), TEXT("During ") };
113 VerifyOpenGLResult(ErrorCode,PrefixStrings[BeforeOrAfter], ANSI_TO_TCHAR(FunctionName),Filename,Line);
114 }
115 }
116 };
117 #define MACRO_TOKENIZER(IdentifierName, Msg, FileName, LineNumber) FOpenGLErrorScope IdentifierName_ ## LineNumber (Msg, FileName, LineNumber)
118 #define MACRO_TOKENIZER2(IdentifierName, Msg, FileName, LineNumber) MACRO_TOKENIZER(IdentiferName, Msg, FileName, LineNumber)
119 #define VERIFY_GL_SCOPE_WITH_MSG_STR(MsgStr) CHECK_EXPECTED_GL_THREAD(); MACRO_TOKENIZER2(ErrorScope_, MsgStr, TEXT(__FILE__), __LINE__)
120 #define VERIFY_GL_SCOPE() VERIFY_GL_SCOPE_WITH_MSG_STR(__FUNCTION__)
121 #define VERIFY_GL_FUNC(Func, ...) { VERIFY_GL_SCOPE_WITH_MSG_STR((#Func)); Func(__VA_ARGS__); }
122
126 #define glBlitFramebuffer(...) VERIFY_GL_FUNC(glBlitFramebuffer, __VA_ARGS__)
127 #define glTexImage2D(...) VERIFY_GL_FUNC(glTexImage2D, __VA_ARGS__)
128 #define glTexSubImage2D(...) VERIFY_GL_FUNC(glTexSubImage2D, __VA_ARGS__)
129 #define glCompressedTexImage2D(...) VERIFY_GL_FUNC(glCompressedTexImage2D, __VA_ARGS__)
130
131#else
132 #define VERIFY_GL(...) CHECK_EXPECTED_GL_THREAD()
133 #define VERIFY_GL_SCOPE(...) CHECK_EXPECTED_GL_THREAD()
134#endif
135
137{
138 static const TCHAR* TStr() { return TEXT("FRHICommandGLCommand"); }
139};
140
141#define GL_CAPTURE_CALLSTACK 0 // Capture the callstack at the point of enqueuing the command.
142
#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
FPlatformTypes::ANSICHAR ANSICHAR
An ANSI character. Normally a signed type.
Definition Platform.h:1131
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
int32 PlatformGlGetError()
Definition LinuxOpenGLPlatform.cpp:807
bool PlatformOpenGLThreadHasRenderingContext()
Definition LinuxOpenGLPlatform.cpp:812
#define UE_LOG(CategoryName, Verbosity, Format,...)
Definition LogMacros.h:270
void VerifyOpenGLResult(GLenum ErrorCode, const TCHAR *Msg1, const TCHAR *Msg2, const TCHAR *Filename, uint32 Line)
Definition OpenGLUtil.cpp:73
bool IsOGLDebugOutputEnabled()
int32 GetOGLDebugOutputLevel()
void SetOpenGLResourceName(FOpenGLTexture *Texture, const ANSICHAR *Name)
Definition OpenGLUtil.cpp:13
bool PlatformOpenGLThreadHasRenderingContext()
Definition LinuxOpenGLPlatform.cpp:812
GLenum GetOpenGLCubeFace(ECubeFace Face)
Definition OpenGLUtil.cpp:95
ECubeFace
Definition RHIDefinitions.h:525
#define ANSI_TO_TCHAR(str)
Definition StringConv.h:1020
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition OpenGLResources.h:918
Definition OpenGLUtil.h:137
static const TCHAR * TStr()
Definition OpenGLUtil.h:138