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"
|
|
|
|
|
|
|
|
namespace backend {
|
|
|
|
namespace opengl {
|
|
|
|
|
|
|
|
// Buffer
|
|
|
|
|
|
|
|
Buffer::Buffer(BufferBuilder* builder)
|
|
|
|
: BufferBase(builder) {
|
|
|
|
glGenBuffers(1, &buffer);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, GetSize(), nullptr, GL_STATIC_DRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
GLuint Buffer::GetHandle() const {
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) {
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, start * sizeof(uint32_t), count * sizeof(uint32_t), data);
|
|
|
|
}
|
|
|
|
|
2017-07-14 21:38:17 +00:00
|
|
|
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.
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
|
|
|
void* data = glMapBufferRange(GL_ARRAY_BUFFER, start, count, GL_MAP_READ_BIT);
|
|
|
|
CallMapReadCallback(serial, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, data);
|
2017-07-14 21:27:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Buffer::UnmapImpl() {
|
2017-07-14 21:38:17 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
|
|
|
glUnmapBuffer(GL_ARRAY_BUFFER);
|
2017-07-14 21:27:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Buffer::TransitionUsageImpl(nxt::BufferUsageBit, nxt::BufferUsageBit) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// BufferView
|
|
|
|
|
|
|
|
BufferView::BufferView(BufferViewBuilder* builder)
|
|
|
|
: BufferViewBase(builder) {
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|