summaryrefslogtreecommitdiff
path: root/src/mbgl/gl/command_encoder.cpp
blob: a7df14df09a96952e7f6d849a5687d6e0ffd1a73 (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
51
52
53
54
55
56
57
58
59
60
#include <mbgl/gl/command_encoder.hpp>
#include <mbgl/gl/upload_pass.hpp>
#include <mbgl/gl/render_pass.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/renderable_resource.hpp>
#include <mbgl/gl/debugging_extension.hpp>
#include <mbgl/platform/gl_functions.hpp>

#include <cstring>

namespace mbgl {
namespace gl {

CommandEncoder::~CommandEncoder() {
    const auto debugGroup(createDebugGroup("cleanup"));
    context.performCleanup();
}

std::unique_ptr<gfx::UploadPass>
CommandEncoder::createUploadPass(const char* name) {
    return std::make_unique<gl::UploadPass>(*this, name);
}

std::unique_ptr<gfx::RenderPass>
CommandEncoder::createRenderPass(const char* name, const gfx::RenderPassDescriptor& descriptor) {
    return std::make_unique<gl::RenderPass>(*this, name, descriptor);
}

void CommandEncoder::present(gfx::Renderable& renderable) {
    renderable.getResource<gl::RenderableResource>().swap();
}

void CommandEncoder::pushDebugGroup(const char* name) {
    (void)name;
#ifndef NDEBUG
    if (auto debugging = context.getDebuggingExtension()) {
        if (debugging->pushDebugGroup) {
            MBGL_CHECK_ERROR(debugging->pushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0,
                                                       platform::GLsizei(strlen(name)), name));
        } else if (debugging->pushGroupMarkerEXT) {
            MBGL_CHECK_ERROR(debugging->pushGroupMarkerEXT(platform::GLsizei(strlen(name) + 1), name));
        }
    }
#endif
}

void CommandEncoder::popDebugGroup() {
#ifndef NDEBUG
    if (auto debugging = context.getDebuggingExtension()) {
        if (debugging->popDebugGroup) {
            MBGL_CHECK_ERROR(debugging->popDebugGroup());
        } else if (debugging->popGroupMarkerEXT) {
            MBGL_CHECK_ERROR(debugging->popGroupMarkerEXT());
        }
    }
#endif
}

} // namespace gl
} // namespace mbgl