dawn-cmake/src/backend/opengl/BufferGL.cpp

62 lines
2.2 KiB
C++
Raw Normal View History

2017-07-14 21:27:32 +00:00
// Copyright 2017 The NXT Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "backend/opengl/BufferGL.h"
#include "backend/opengl/OpenGLBackend.h"
2017-11-24 19:16:15 +00:00
namespace backend { namespace opengl {
2017-07-14 21:27:32 +00:00
// Buffer
2017-11-24 19:16:15 +00:00
Buffer::Buffer(BufferBuilder* builder) : BufferBase(builder) {
2017-11-23 19:24:20 +00:00
glGenBuffers(1, &mBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
2017-07-14 21:27:32 +00:00
glBufferData(GL_ARRAY_BUFFER, GetSize(), nullptr, GL_STATIC_DRAW);
}
GLuint Buffer::GetHandle() const {
2017-11-23 19:24:20 +00:00
return mBuffer;
2017-07-14 21:27:32 +00:00
}
void Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) {
2017-11-23 19:24:20 +00:00
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
2017-07-14 21:27:32 +00:00
glBufferSubData(GL_ARRAY_BUFFER, start * sizeof(uint32_t), count * sizeof(uint32_t), data);
}
void Buffer::MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) {
// TODO(cwallez@chromium.org): this does GPU->CPU synchronization, we could require a high
// version of OpenGL that would let us map the buffer unsynchronized.
2017-11-24 19:16:15 +00:00
// TODO(cwallez@chromium.org): this crashes on Mac NVIDIA, use GetBufferSubData there
// instead?
2017-11-23 19:24:20 +00:00
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
void* data = glMapBufferRange(GL_ARRAY_BUFFER, start, count, GL_MAP_READ_BIT);
CallMapReadCallback(serial, NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data);
2017-07-14 21:27:32 +00:00
}
void Buffer::UnmapImpl() {
2017-11-23 19:24:20 +00:00
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
glUnmapBuffer(GL_ARRAY_BUFFER);
2017-07-14 21:27:32 +00:00
}
void Buffer::TransitionUsageImpl(nxt::BufferUsageBit, nxt::BufferUsageBit) {
}
// BufferView
2017-11-24 19:16:15 +00:00
BufferView::BufferView(BufferViewBuilder* builder) : BufferViewBase(builder) {
2017-07-14 21:27:32 +00:00
}
2017-11-24 19:16:15 +00:00
}} // namespace backend::opengl