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:
authorClément Foucault <foucault.clem@gmail.com>2020-08-10 12:41:22 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-08-13 15:20:24 +0300
commit47bfb0f7ad2f70017585fe55a68e49ae09f1150c (patch)
tree3840e9e93bb3a1cc18735b512356fd4ec86108c8 /source/blender/gpu/opengl
parent9443da6166f58403eab07c7bff9eac55af04f981 (diff)
GPUBatch: Move allocator to backend
Diffstat (limited to 'source/blender/gpu/opengl')
-rw-r--r--source/blender/gpu/opengl/gl_backend.hh6
-rw-r--r--source/blender/gpu/opengl/gl_batch.cc50
-rw-r--r--source/blender/gpu/opengl/gl_batch.hh84
3 files changed, 140 insertions, 0 deletions
diff --git a/source/blender/gpu/opengl/gl_backend.hh b/source/blender/gpu/opengl/gl_backend.hh
index a1e0e53f329..eba275f0245 100644
--- a/source/blender/gpu/opengl/gl_backend.hh
+++ b/source/blender/gpu/opengl/gl_backend.hh
@@ -27,6 +27,7 @@
#include "BLI_vector.hh"
+#include "gl_batch.hh"
#include "gl_context.hh"
#include "gl_drawlist.hh"
@@ -43,6 +44,11 @@ class GLBackend : public GPUBackend {
return new GLContext(ghost_window, shared_orphan_list_);
};
+ Batch *batch_alloc(void)
+ {
+ return new GLBatch();
+ };
+
DrawList *drawlist_alloc(int list_length)
{
return new GLDrawList(list_length);
diff --git a/source/blender/gpu/opengl/gl_batch.cc b/source/blender/gpu/opengl/gl_batch.cc
new file mode 100644
index 00000000000..62d81ad9f5a
--- /dev/null
+++ b/source/blender/gpu/opengl/gl_batch.cc
@@ -0,0 +1,50 @@
+/*
+ * 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) 2016 by Mike Erwin.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup gpu
+ *
+ * GL implementation of GPUBatch.
+ * The only specificity of GL here is that it caches a list of
+ * Vertex Array Objects based on the bound shader interface.
+ */
+
+#include "BLI_assert.h"
+
+#include "glew-mx.h"
+
+#include "gpu_batch_private.hh"
+#include "gpu_primitive_private.h"
+
+#include "gl_batch.hh"
+
+using namespace blender::gpu;
+
+GLBatch::GLBatch(void)
+{
+}
+
+GLBatch::~GLBatch()
+{
+}
+
+void GLBatch::draw(int v_first, int v_count, int i_first, int i_count)
+{
+ UNUSED_VARS(v_first, v_count, i_first, i_count);
+} \ No newline at end of file
diff --git a/source/blender/gpu/opengl/gl_batch.hh b/source/blender/gpu/opengl/gl_batch.hh
new file mode 100644
index 00000000000..290c113205a
--- /dev/null
+++ b/source/blender/gpu/opengl/gl_batch.hh
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ *
+ * Copyright 2020, Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup gpu
+ *
+ * GPU geometry batch
+ * Contains VAOs + VBOs + Shader representing a drawable entity.
+ */
+
+#pragma once
+
+#include "MEM_guardedalloc.h"
+
+#include "gpu_batch_private.hh"
+
+#include "glew-mx.h"
+
+#include "GPU_shader_interface.h"
+
+namespace blender {
+namespace gpu {
+
+#define GPU_BATCH_VAO_STATIC_LEN 3
+
+class GLVaoCache {
+ /* Vao management: remembers all geometry state (vertex attribute bindings & element buffer)
+ * for each shader interface. Start with a static number of vaos and fallback to dynamic count
+ * if necessary. Once a batch goes dynamic it does not go back. */
+ bool is_dynamic_vao_count = false;
+ union {
+ /** Static handle count */
+ struct {
+ const GPUShaderInterface *interfaces[GPU_BATCH_VAO_STATIC_LEN];
+ GLuint vao_ids[GPU_BATCH_VAO_STATIC_LEN];
+ } static_vaos;
+ /** Dynamic handle count */
+ struct {
+ uint count;
+ const GPUShaderInterface **interfaces;
+ GLuint *vao_ids;
+ } dynamic_vaos;
+ };
+
+ GLuint search(const GPUShaderInterface *interface);
+ void insert(GLuint vao_id, const GPUShaderInterface *interface);
+ void clear(void);
+ void interface_remove(const GPUShaderInterface *interface);
+};
+
+class GLBatch : public Batch {
+ private:
+ /** Cached values (avoid dereferencing later). */
+ GLuint vao_id;
+ /** All vaos corresponding to all the GPUShaderInterface this batch was drawn with. */
+ GLVaoCache vaos;
+
+ public:
+ GLBatch();
+ ~GLBatch();
+
+ void draw(int v_first, int v_count, int i_first, int i_count) override;
+
+ MEM_CXX_CLASS_ALLOC_FUNCS("GLBatch");
+};
+
+} // namespace gpu
+} // namespace blender