2018-07-18 09:40:26 +00:00
|
|
|
// Copyright 2017 The Dawn Authors
|
2017-07-14 21:27:32 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/opengl/BufferGL.h"
|
2017-07-14 21:27:32 +00:00
|
|
|
|
2018-08-22 13:37:29 +00:00
|
|
|
#include "dawn_native/opengl/DeviceGL.h"
|
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
namespace dawn_native { namespace opengl {
|
2017-07-14 21:27:32 +00:00
|
|
|
|
|
|
|
// Buffer
|
|
|
|
|
2018-08-22 13:37:29 +00:00
|
|
|
Buffer::Buffer(Device* device, const BufferDescriptor* descriptor)
|
|
|
|
: BufferBase(device, descriptor) {
|
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
|
|
|
}
|
|
|
|
|
2019-01-29 00:10:07 +00:00
|
|
|
MaybeError Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint8_t* data) {
|
2017-11-23 19:24:20 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
|
2018-02-04 16:07:02 +00:00
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, start, count, data);
|
2019-01-29 00:10:07 +00:00
|
|
|
return {};
|
2017-07-14 21:27:32 +00:00
|
|
|
}
|
|
|
|
|
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.
|
2017-11-23 19:24:20 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
|
2017-07-14 21:38:17 +00:00
|
|
|
void* data = glMapBufferRange(GL_ARRAY_BUFFER, start, count, GL_MAP_READ_BIT);
|
2018-07-18 13:12:52 +00:00
|
|
|
CallMapReadCallback(serial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data);
|
2017-07-14 21:27:32 +00:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:56:39 +00:00
|
|
|
void Buffer::MapWriteAsyncImpl(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, mBuffer);
|
|
|
|
void* data = glMapBufferRange(GL_ARRAY_BUFFER, start, count, GL_MAP_WRITE_BIT);
|
2018-07-18 13:12:52 +00:00
|
|
|
CallMapWriteCallback(serial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data);
|
2018-03-21 00:56:39 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 21:27:32 +00:00
|
|
|
void Buffer::UnmapImpl() {
|
2017-11-23 19:24:20 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
|
2017-07-14 21:38:17 +00:00
|
|
|
glUnmapBuffer(GL_ARRAY_BUFFER);
|
2017-07-14 21:27:32 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
}} // namespace dawn_native::opengl
|