当前位置:网站首页>How OpenGL handles errors
How OpenGL handles errors
2022-07-23 05:46:00 【Liu jingyiru】
This section focuses on glGetError, It's in almost every OpenGL In the version of , So in OpenGL It is commonly used in error handling . because OpenGL Implementation is related to version , But you can generally judge by prefix . Function function and version . If used correctly , But it can't render the expected effect , You can then use the document to determine whether it is a version problem .
The code framework :
For cleaning Error
static void GLClearError()
{
while (glGetError() != GL_NO_ERROR);
}
// Used for inspection Error
static void GLCheckError()
{
while (GLenum error = glGetError())
{
std::cout << "[OpenGL Error](" << error << ")" << std::endl;
}
}analysis : When using , We add these two functions to Error code to be detected Up and down . But the disadvantages of doing so are obvious , First of all, we don't know the specific type of error . secondly , We cannot pinpoint where the error occurred . technological process : The way to imitate a function is Find a reference object similar to the target function , Then analyze and imitate .

Target demand analysis :(1) One error check takes many times Call two functions , The process is tedious . Encapsulation makes calling easier .(2) Inaccurate positioning . Error code File path , Row number . Are important information for reporting errors .
Code implementation :
(1) terms of settlement : Macro wrapping can simplify the form of our calls , Handle misuse ASSERT.
__debugbreak() Is to compile built-in functions .
Be similar to DebugBreak, It's a portable Win32 Method ( Can't be in clang/gcc Next use ) To cause breakpoint exceptions . This allows the calling thread to signal the debugger to handle exceptions .
ps: Built in functions : Code is usually inserted inline , Avoid the overhead of function calls , But faster than the equivalent inline function assembly .
Compiler intrinsics | Microsoft Docs
(2) terms of settlement : Add more printing information .
// Show me the code #define ASSERT(x) if (!(x)) __debugbreak(); #define GLCall(x) GLClearError();x;ASSERT(GLLogCall(#x, __FILE__, __LINE__)) static void GLClearError() { while (glGetError() != GL_NO_ERROR); } static bool GLLogCall(const char* function, const char* file, int line) { while (GLenum error = glGetError()) { std::cout << "[OpenGL Error] (" << error << ")" << function << " " << file << ":" << line << std::endl; return false; } return true; } // call : By using GLCall To package every need to check for errors OpenGL function GLCall(glDrawElements(GL_TRIANGLES, 6, GL_INT,nullptr));
Running results :


If there is a mistake , Your advice are most welcome !!
边栏推荐
猜你喜欢
随机推荐
Linked list 2 linked list OJ problem solution and topic summary
Camera roaming
用两个栈实现一个队列。
[原创]软件测试实例指导
Epressif play firmware download
使用清华镜像安装librosa
软件测试分类
按是否运行源代码划分: 静态测试和动态测试
day04---禅道的使用
leetcode
金字塔型自动化的利弊
Compile and install redis-6.2.5 under Windows
Freshman summer internship Day5_ three
毫秒级上传批量附件
Print all the words in the string array -- the story of pointer and string
Freshman summer internship Day5_ two
day6_ Jigsaw puzzle follow-up - switch interface, random pictures and package exe
unity中3dUI或者模型始終面向攝像機,跟隨攝像機視角旋轉丨視角跟隨丨固定視角
Unity3D使用VRTK配置场景环境
day04--禅道的安装









