MNN/source/backend/opengl/GLSSBOBuffer.cpp

45 lines
979 B
C++
Raw Normal View History

2019-04-17 10:49:11 +08:00
//
// GLSSBOBuffer.cpp
// MNN
//
// Created by MNN on 2019/01/31.
// Copyright © 2018, Alibaba Group Holding Limited
//
2019-12-27 22:16:57 +08:00
#include "backend/opengl/GLSSBOBuffer.hpp"
2019-04-17 10:49:11 +08:00
namespace MNN {
namespace OpenGL {
2019-04-17 10:49:11 +08:00
GLSSBOBuffer::GLSSBOBuffer(GLsizeiptr size, GLenum type, GLenum usage) {
mType = type;
GLASSERT(size > 0);
glGenBuffers(1, &mId);
OPENGL_CHECK_ERROR;
glBindBuffer(mType, mId);
OPENGL_CHECK_ERROR;
GLASSERT(mId > 0);
glBufferData(mType, size, NULL, usage);
OPENGL_CHECK_ERROR;
mSize = size;
}
GLSSBOBuffer::~GLSSBOBuffer() {
glDeleteBuffers(1, &mId);
OPENGL_CHECK_ERROR;
}
void *GLSSBOBuffer::map(GLbitfield bufMask) {
glBindBuffer(mType, mId);
OPENGL_CHECK_ERROR;
auto ptr = glMapBufferRange(mType, 0, mSize, bufMask);
OPENGL_CHECK_ERROR;
return ptr;
}
void GLSSBOBuffer::unmap() {
glBindBuffer(mType, mId);
glUnmapBuffer(mType);
OPENGL_CHECK_ERROR;
}
} // namespace OpenGL
2019-04-17 10:49:11 +08:00
} // namespace MNN