OpenGL: move buffer to its own file

This commit is contained in:
Corentin Wallez 2017-07-14 17:27:32 -04:00 committed by Corentin Wallez
parent fec8c58a97
commit 9d4b9ab313
7 changed files with 114 additions and 55 deletions

View File

@ -38,6 +38,8 @@ if (NXT_ENABLE_OPENGL)
target_include_directories(opengl_autogen PUBLIC ${GENERATED_DIR})
list(APPEND BACKEND_SOURCES
${OPENGL_DIR}/BufferGL.cpp
${OPENGL_DIR}/BufferGL.h
${OPENGL_DIR}/CommandBufferGL.cpp
${OPENGL_DIR}/CommandBufferGL.h
${OPENGL_DIR}/DepthStencilStateGL.cpp

View File

@ -0,0 +1,58 @@
// 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);
}
void Buffer::MapReadAsyncImpl(uint32_t, uint32_t, uint32_t) {
// TODO(cwallez@chromium.org): Implement Map Read for the GL backend
}
void Buffer::UnmapImpl() {
// TODO(cwallez@chromium.org): Implement Map Read for the GL backend
}
void Buffer::TransitionUsageImpl(nxt::BufferUsageBit, nxt::BufferUsageBit) {
}
// BufferView
BufferView::BufferView(BufferViewBuilder* builder)
: BufferViewBase(builder) {
}
}
}

View File

@ -0,0 +1,51 @@
// 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.
#ifndef BACKEND_OPENGL_BUFFERGL_H_
#define BACKEND_OPENGL_BUFFERGL_H_
#include "backend/Buffer.h"
#include "common/SerialQueue.h"
#include "glad/glad.h"
namespace backend {
namespace opengl {
class Device;
class Buffer : public BufferBase {
public:
Buffer(BufferBuilder* builder);
GLuint GetHandle() const;
private:
void SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) override;
void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
void UnmapImpl() override;
void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) override;
GLuint buffer = 0;
};
class BufferView : public BufferViewBase {
public:
BufferView(BufferViewBuilder* builder);
};
}
}
#endif // BACKEND_OPENGL_BUFFERGL_H_

View File

@ -15,6 +15,7 @@
#include "backend/opengl/CommandBufferGL.h"
#include "backend/Commands.h"
#include "backend/opengl/BufferGL.h"
#include "backend/opengl/OpenGLBackend.h"
#include "backend/opengl/PersistentPipelineStateGL.h"
#include "backend/opengl/PipelineGL.h"

View File

@ -13,6 +13,7 @@
// limitations under the License.
#include "backend/opengl/OpenGLBackend.h"
#include "backend/opengl/BufferGL.h"
#include "backend/opengl/CommandBufferGL.h"
#include "backend/opengl/DepthStencilStateGL.h"
#include "backend/opengl/PersistentPipelineStateGL.h"

View File

@ -14,6 +14,7 @@
#include "backend/opengl/OpenGLBackend.h"
#include "backend/opengl/BufferGL.h"
#include "backend/opengl/CommandBufferGL.h"
#include "backend/opengl/DepthStencilStateGL.h"
#include "backend/opengl/PipelineGL.h"
@ -150,41 +151,6 @@ namespace opengl {
: BindGroupLayoutBase(builder) {
}
// 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);
}
void Buffer::MapReadAsyncImpl(uint32_t, uint32_t, uint32_t) {
// TODO(cwallez@chromium.org): Implement Map Read for the GL backend
}
void Buffer::UnmapImpl() {
// TODO(cwallez@chromium.org): Implement Map Read for the GL backend
}
void Buffer::TransitionUsageImpl(nxt::BufferUsageBit, nxt::BufferUsageBit) {
}
// BufferView
BufferView::BufferView(BufferViewBuilder* builder)
: BufferViewBase(builder) {
}
// InputState
InputState::InputState(InputStateBuilder* builder)

View File

@ -119,26 +119,6 @@ namespace opengl {
BindGroupLayout(BindGroupLayoutBuilder* builder);
};
class Buffer : public BufferBase {
public:
Buffer(BufferBuilder* builder);
GLuint GetHandle() const;
private:
void SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) override;
void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
void UnmapImpl() override;
void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) override;
GLuint buffer = 0;
};
class BufferView : public BufferViewBase {
public:
BufferView(BufferViewBuilder* builder);
};
class Framebuffer : public FramebufferBase {
public:
Framebuffer(FramebufferBuilder* builder);