Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/gpu/intern/gpu_storage_buffer.cc')
-rw-r--r--source/blender/gpu/intern/gpu_storage_buffer.cc108
1 files changed, 108 insertions, 0 deletions
diff --git a/source/blender/gpu/intern/gpu_storage_buffer.cc b/source/blender/gpu/intern/gpu_storage_buffer.cc
new file mode 100644
index 00000000000..adbc71319b3
--- /dev/null
+++ b/source/blender/gpu/intern/gpu_storage_buffer.cc
@@ -0,0 +1,108 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2020 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup gpu
+ */
+
+#include "MEM_guardedalloc.h"
+#include <cstring>
+
+#include "BLI_blenlib.h"
+#include "BLI_math_base.h"
+
+#include "gpu_backend.hh"
+#include "gpu_node_graph.h"
+
+#include "GPU_material.h"
+#include "GPU_vertex_buffer.h" /* For GPUUsageType. */
+
+#include "GPU_storage_buffer.h"
+#include "gpu_storage_buffer_private.hh"
+
+/* -------------------------------------------------------------------- */
+/** \name Creation & Deletion
+ * \{ */
+
+namespace blender::gpu {
+
+StorageBuf::StorageBuf(size_t size, const char *name)
+{
+ /* Make sure that UBO is padded to size of vec4 */
+ BLI_assert((size % 16) == 0);
+
+ size_in_bytes_ = size;
+
+ BLI_strncpy(name_, name, sizeof(name_));
+}
+
+StorageBuf::~StorageBuf()
+{
+ MEM_SAFE_FREE(data_);
+}
+
+} // namespace blender::gpu
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name C-API
+ * \{ */
+
+using namespace blender::gpu;
+
+GPUStorageBuf *GPU_storagebuf_create_ex(size_t size,
+ const void *data,
+ GPUUsageType usage,
+ const char *name)
+{
+ StorageBuf *ubo = GPUBackend::get()->storagebuf_alloc(size, usage, name);
+ /* Direct init. */
+ if (data != nullptr) {
+ ubo->update(data);
+ }
+ return wrap(ubo);
+}
+
+void GPU_storagebuf_free(GPUStorageBuf *ubo)
+{
+ delete unwrap(ubo);
+}
+
+void GPU_storagebuf_update(GPUStorageBuf *ubo, const void *data)
+{
+ unwrap(ubo)->update(data);
+}
+
+void GPU_storagebuf_bind(GPUStorageBuf *ubo, int slot)
+{
+ unwrap(ubo)->bind(slot);
+}
+
+void GPU_storagebuf_unbind(GPUStorageBuf *ubo)
+{
+ unwrap(ubo)->unbind();
+}
+
+void GPU_storagebuf_unbind_all()
+{
+ /* FIXME */
+}
+
+/** \} */