summaryrefslogtreecommitdiff
path: root/src/mbgl/util/gl_object_store.cpp
blob: 78d6700237d6898ae0a53283d3114a078ff5e1f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <mbgl/util/gl_object_store.hpp>

#include <mbgl/util/thread.hpp>
#include <mbgl/geometry/vao.hpp>
#include <mbgl/platform/gl.hpp>

#include <cassert>

namespace mbgl {
namespace util {

void GLObjectStore::abandonVAO(GLuint vao) {
    assert(ThreadContext::currentlyOn(ThreadType::Map));
    abandonedVAOs.emplace_back(vao);
}

void GLObjectStore::abandonBuffer(GLuint buffer) {
    assert(ThreadContext::currentlyOn(ThreadType::Map));
    abandonedBuffers.emplace_back(buffer);
}

void GLObjectStore::abandonTexture(GLuint texture) {
    assert(ThreadContext::currentlyOn(ThreadType::Map));
    abandonedTextures.emplace_back(texture);
}

void GLObjectStore::performCleanup() {
    assert(ThreadContext::currentlyOn(ThreadType::Map));

    if (!abandonedVAOs.empty()) {
        MBGL_CHECK_ERROR(VertexArrayObject::Delete(static_cast<GLsizei>(abandonedVAOs.size()),
                                                   abandonedVAOs.data()));
        abandonedVAOs.clear();
    }

    if (!abandonedTextures.empty()) {
        MBGL_CHECK_ERROR(glDeleteTextures(static_cast<GLsizei>(abandonedTextures.size()),
                                          abandonedTextures.data()));
        abandonedTextures.clear();
    }

    if (!abandonedBuffers.empty()) {
        MBGL_CHECK_ERROR(glDeleteBuffers(static_cast<GLsizei>(abandonedBuffers.size()),
                                         abandonedBuffers.data()));
        abandonedBuffers.clear();
    }
}

} // namespace util
} // namespace mbgl