iOS技术文章iOS进阶

OpenGL (ES) Shader的正确删除方式

2017-02-13  本文已影响345人  熊皮皮

在glLinkProgram之后应删除已链接的着色器,减少GPU资源占用。通常我们的删除方式是粗暴地glDeleteShader,然而,这并不是个好习惯。

根据StackOverflow Proper way to delete GLSL shader?,删除前应先进行glDetachShader,再glDeleteShader。

in fact it is highly desireable to detach and delete your shader objects as soon as possible. That way the driver can free up all the memory it is using to hold a copy of the shader source and unlinked object code, which can be quite substantial. Measurements I have done indicate that NOT deleting the shader objects increases the incremental memory use per shader by 5-10x

if (vertShader) {
    glDetachShader(_program, vertShader);
    glDeleteShader(vertShader);
}
if (fragShader) {
    glDetachShader(_program, fragShader);
    glDeleteShader(fragShader);
}
上一篇下一篇

猜你喜欢

热点阅读