[Bf-blender-cvs] [bb2aeb45049] master: GPUVertBuf: Rename GPUVertBuf to VertBuf and add some getters
Clément Foucault
noreply at git.blender.org
Mon Sep 7 14:03:18 CEST 2020
Commit: bb2aeb4504907cab1cf8c4afc4dd1d6495c940e4
Author: Clément Foucault
Date: Sun Sep 6 23:45:51 2020 +0200
Branches: master
https://developer.blender.org/rBbb2aeb4504907cab1cf8c4afc4dd1d6495c940e4
GPUVertBuf: Rename GPUVertBuf to VertBuf and add some getters
to avoid more typecasts.
===================================================================
M source/blender/gpu/CMakeLists.txt
M source/blender/gpu/GPU_vertex_buffer.h
M source/blender/gpu/intern/gpu_backend.hh
M source/blender/gpu/intern/gpu_batch.cc
M source/blender/gpu/intern/gpu_batch_private.hh
M source/blender/gpu/intern/gpu_immediate.cc
M source/blender/gpu/intern/gpu_texture.cc
M source/blender/gpu/intern/gpu_vertex_buffer.cc
M source/blender/gpu/intern/gpu_vertex_buffer_private.hh
M source/blender/gpu/intern/gpu_vertex_format.cc
M source/blender/gpu/intern/gpu_vertex_format_private.h
M source/blender/gpu/opengl/gl_backend.hh
M source/blender/gpu/opengl/gl_batch.cc
M source/blender/gpu/opengl/gl_batch.hh
M source/blender/gpu/opengl/gl_drawlist.cc
M source/blender/gpu/opengl/gl_shader.cc
M source/blender/gpu/opengl/gl_texture.cc
M source/blender/gpu/opengl/gl_vertex_array.cc
A source/blender/gpu/opengl/gl_vertex_buffer.cc
A source/blender/gpu/opengl/gl_vertex_buffer.hh
===================================================================
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 799e146183a..5cce4f84aea 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -100,6 +100,7 @@ set(SRC
opengl/gl_texture.cc
opengl/gl_uniform_buffer.cc
opengl/gl_vertex_array.cc
+ opengl/gl_vertex_buffer.cc
GPU_batch.h
GPU_batch_presets.h
@@ -166,6 +167,7 @@ set(SRC
opengl/gl_texture.hh
opengl/gl_uniform_buffer.hh
opengl/gl_vertex_array.hh
+ opengl/gl_vertex_buffer.hh
)
set(LIB
diff --git a/source/blender/gpu/GPU_vertex_buffer.h b/source/blender/gpu/GPU_vertex_buffer.h
index efed2725e27..e42d6c47b58 100644
--- a/source/blender/gpu/GPU_vertex_buffer.h
+++ b/source/blender/gpu/GPU_vertex_buffer.h
@@ -46,7 +46,6 @@ ENUM_OPERATORS(GPUVertBufStatus)
extern "C" {
#endif
-#define VRAM_USAGE 1
/**
* How to create a #GPUVertBuf:
* 1) verts = GPU_vertbuf_calloc()
@@ -64,9 +63,7 @@ typedef enum {
typedef struct GPUVertBuf GPUVertBuf;
-#define GPU_vertbuf_calloc() GPU_vertbuf_create(GPU_USAGE_STATIC);
-
-GPUVertBuf *GPU_vertbuf_create(GPUUsageType);
+GPUVertBuf *GPU_vertbuf_calloc(void);
GPUVertBuf *GPU_vertbuf_create_with_format_ex(const GPUVertFormat *, GPUUsageType);
#define GPU_vertbuf_create_with_format(format) \
@@ -79,7 +76,6 @@ void GPU_vertbuf_discard(GPUVertBuf *);
void GPU_vertbuf_handle_ref_add(GPUVertBuf *verts);
void GPU_vertbuf_handle_ref_remove(GPUVertBuf *verts);
-void GPU_vertbuf_init(GPUVertBuf *, GPUUsageType);
void GPU_vertbuf_init_with_format_ex(GPUVertBuf *, const GPUVertFormat *, GPUUsageType);
#define GPU_vertbuf_init_with_format(verts, format) \
@@ -87,7 +83,6 @@ void GPU_vertbuf_init_with_format_ex(GPUVertBuf *, const GPUVertFormat *, GPUUsa
GPUVertBuf *GPU_vertbuf_duplicate(GPUVertBuf *verts);
-uint GPU_vertbuf_size_get(const GPUVertBuf *);
void GPU_vertbuf_data_alloc(GPUVertBuf *, uint v_len);
void GPU_vertbuf_data_resize(GPUVertBuf *, uint v_len);
void GPU_vertbuf_data_len_set(GPUVertBuf *, uint v_len);
diff --git a/source/blender/gpu/intern/gpu_backend.hh b/source/blender/gpu/intern/gpu_backend.hh
index b5162fd820f..d074350e8d0 100644
--- a/source/blender/gpu/intern/gpu_backend.hh
+++ b/source/blender/gpu/intern/gpu_backend.hh
@@ -37,6 +37,7 @@ class IndexBuf;
class Shader;
class Texture;
class UniformBuf;
+class VertBuf;
class GPUBackend {
public:
@@ -55,6 +56,7 @@ class GPUBackend {
virtual Shader *shader_alloc(const char *name) = 0;
virtual Texture *texture_alloc(const char *name) = 0;
virtual UniformBuf *uniformbuf_alloc(int size, const char *name) = 0;
+ virtual VertBuf *vertbuf_alloc(void) = 0;
};
} // namespace gpu
diff --git a/source/blender/gpu/intern/gpu_batch.cc b/source/blender/gpu/intern/gpu_batch.cc
index 864843a6d01..34655c48ca4 100644
--- a/source/blender/gpu/intern/gpu_batch.cc
+++ b/source/blender/gpu/intern/gpu_batch.cc
@@ -267,14 +267,14 @@ void GPU_batch_draw_advanced(
v_count = batch->elem_()->index_len_get();
}
else {
- v_count = batch->verts[0]->vertex_len;
+ v_count = batch->verts_(0)->vertex_len;
}
}
if (i_count == 0) {
- i_count = (batch->inst[0]) ? batch->inst[0]->vertex_len : 1;
+ i_count = (batch->inst[0]) ? batch->inst_(0)->vertex_len : 1;
/* Meh. This is to be able to use different numbers of verts in instance vbos. */
if (batch->inst[1] != NULL) {
- i_count = min_ii(i_count, batch->inst[1]->vertex_len);
+ i_count = min_ii(i_count, batch->inst_(1)->vertex_len);
}
}
diff --git a/source/blender/gpu/intern/gpu_batch_private.hh b/source/blender/gpu/intern/gpu_batch_private.hh
index dae9c885ee1..c71670d4f1f 100644
--- a/source/blender/gpu/intern/gpu_batch_private.hh
+++ b/source/blender/gpu/intern/gpu_batch_private.hh
@@ -30,6 +30,7 @@
#include "GPU_context.h"
#include "gpu_index_buffer_private.hh"
+#include "gpu_vertex_buffer_private.hh"
namespace blender {
namespace gpu {
@@ -46,10 +47,18 @@ class Batch : public GPUBatch {
virtual void draw(int v_first, int v_count, int i_first, int i_count) = 0;
/* Convenience casts. */
- IndexBuf *elem_(void)
+ IndexBuf *elem_(void) const
{
return unwrap(elem);
- };
+ }
+ VertBuf *verts_(const int index) const
+ {
+ return unwrap(verts[index]);
+ }
+ VertBuf *inst_(const int index) const
+ {
+ return unwrap(inst[index]);
+ }
};
} // namespace gpu
diff --git a/source/blender/gpu/intern/gpu_immediate.cc b/source/blender/gpu/intern/gpu_immediate.cc
index c1b5e11698d..dd3e5bea604 100644
--- a/source/blender/gpu/intern/gpu_immediate.cc
+++ b/source/blender/gpu/intern/gpu_immediate.cc
@@ -165,7 +165,7 @@ GPUBatch *immBeginBatch(GPUPrimType prim_type, uint vertex_len)
GPUVertBuf *verts = GPU_vertbuf_create_with_format(&imm->vertex_format);
GPU_vertbuf_data_alloc(verts, vertex_len);
- imm->vertex_data = verts->data;
+ imm->vertex_data = (uchar *)GPU_vertbuf_get_data(verts);
imm->batch = GPU_batch_create_ex(prim_type, verts, NULL, GPU_BATCH_OWNS_VBO);
imm->batch->flag |= GPU_BATCH_BUILDING;
diff --git a/source/blender/gpu/intern/gpu_texture.cc b/source/blender/gpu/intern/gpu_texture.cc
index e2330b7f990..a4d0d039c8f 100644
--- a/source/blender/gpu/intern/gpu_texture.cc
+++ b/source/blender/gpu/intern/gpu_texture.cc
@@ -124,7 +124,7 @@ bool Texture::init_buffer(GPUVertBuf *vbo, eGPUTextureFormat format)
if (format == GPU_DEPTH_COMPONENT24) {
return false;
}
- w_ = vbo->vertex_len;
+ w_ = GPU_vertbuf_get_vertex_len(vbo);
h_ = 0;
d_ = 0;
format_ = format;
@@ -303,7 +303,7 @@ GPUTexture *GPU_texture_create_compressed_2d(
GPUTexture *GPU_texture_create_from_vertbuf(const char *name, GPUVertBuf *vert)
{
- eGPUTextureFormat tex_format = to_texture_format(&vert->format);
+ eGPUTextureFormat tex_format = to_texture_format(GPU_vertbuf_get_format(vert));
Texture *tex = GPUBackend::get()->texture_alloc(name);
bool success = tex->init_buffer(vert, tex_format);
diff --git a/source/blender/gpu/intern/gpu_vertex_buffer.cc b/source/blender/gpu/intern/gpu_vertex_buffer.cc
index 4f0caa19a5c..44c5c9deb37 100644
--- a/source/blender/gpu/intern/gpu_vertex_buffer.cc
+++ b/source/blender/gpu/intern/gpu_vertex_buffer.cc
@@ -25,64 +25,61 @@
#include "MEM_guardedalloc.h"
-#include "gpu_context_private.hh"
+#include "gpu_backend.hh"
#include "gpu_vertex_format_private.h"
+#include "gl_vertex_buffer.hh" /* TODO remove */
+#include "gpu_context_private.hh" /* TODO remove */
+
#include "gpu_vertex_buffer_private.hh"
-#define KEEP_SINGLE_COPY 1
+#include <cstring>
-static uint vbo_memory_usage;
+#define VRAM_USAGE 1
-static GLenum convert_usage_type_to_gl(GPUUsageType type)
-{
- switch (type) {
- case GPU_USAGE_STREAM:
- return GL_STREAM_DRAW;
- case GPU_USAGE_DYNAMIC:
- return GL_DYNAMIC_DRAW;
- case GPU_USAGE_STATIC:
- return GL_STATIC_DRAW;
- default:
- BLI_assert(0);
- return GL_STATIC_DRAW;
- }
-}
+/* -------------------------------------------------------------------- */
+/** \name VertBuf
+ * \{ */
+
+namespace blender::gpu {
+
+size_t VertBuf::memory_usage = 0;
+
+} // namespace blender::gpu
-GPUVertBuf *GPU_vertbuf_create(GPUUsageType usage)
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name C-API
+ * \{ */
+
+using namespace blender;
+using namespace blender::gpu;
+
+static uint GPU_vertbuf_size_get(const VertBuf *verts);
+
+/* -------- Creation & deletion -------- */
+
+GPUVertBuf *GPU_vertbuf_calloc(void)
{
- GPUVertBuf *verts = (GPUVertBuf *)MEM_mallocN(sizeof(GPUVertBuf), "GPUVertBuf");
- GPU_vertbuf_init(verts, usage);
- return verts;
+ return wrap(GPUBackend::get()->vertbuf_alloc());
}
GPUVertBuf *GPU_vertbuf_create_with_format_ex(const GPUVertFormat *format, GPUUsageType usage)
{
- GPUVertBuf *verts = GPU_vertbuf_create(usage);
- GPU_vertformat_copy(&verts->format, format);
- if (!format->packed) {
- VertexFormat_pack(&verts->format);
- }
- verts->flag |= GPU_VERTBUF_INIT;
+ GPUVertBuf *verts = GPU_vertbuf_calloc();
+ GPU_vertbuf_init_with_format_ex(verts, format, usage);
return verts;
-
- /* this function might seem redundant, but there is potential for memory savings here... */
- /* TODO: implement those memory savings */
}
-void GPU_vertbuf_init(GPUVertBuf *verts, GPUUsageType usage)
+void GPU_vertbuf_init_with_format_ex(GPUVertBuf *verts_,
+ const GPUVertFormat *format,
+ GPUUsageType usage)
{
- memset(verts, 0, sizeof(GPUVertBuf));
+ VertBuf *verts = unwrap(verts_);
verts->usage = usage;
verts->flag = GPU_VERTBUF_DATA_DIRTY;
verts->handle_refcount = 1;
-}
-
-void GPU_vertbuf_init_with_format_ex(GPUVertBuf *verts,
- const GPUVertFormat *format,
- GPUUsageType usage)
-{
- GPU_vertbuf_init(verts, usage);
GPU_vertformat_copy(&verts->format, format);
if (!format->packed) {
VertexFormat_pack(&verts->format);
@@ -90,11 +87,13 @@ void GPU_vertbuf_init_with_format_ex(GPUVertBuf *verts,
verts->flag |= GPU_VERTBUF_INIT;
}
-GPUVertBuf *GPU_vertbuf_duplicate(GPUVertBuf *verts)
+GPUVertBuf *GPU_vertbuf_duplicate(GPUVertBuf *verts_)
{
- GPUVertBuf *verts_dst = GPU_vertbuf_create(GPU_USAGE_STATIC);
+ VertBuf *verts = unwrap(verts_);
+ VertBuf *verts_dst = unwrap(GPU_vertbuf_calloc());
/* Full copy. */
*verts_dst = *verts;
+ verts_dst->handle_refcount = 1;
GPU_vertformat_copy(&verts_dst->format, &verts->format);
if (verts->vbo_id) {
@@ -105,33 +104,32 @@ GPUVertBuf *GPU_vertbuf_duplicate(GPUVertBuf *verts)
glBindBuffer(GL_COPY_READ_BUFFER, verts->vbo_id);
glBindBuffer(GL_COPY_WRITE_BUFFER, verts_dst->vbo_id);
- glBufferData(GL_COPY_WRITE_BUFFER, buffer_sz, NULL, convert_usage_type_to_gl(verts->usage));
+ glBufferData(GL_COPY_WRITE_BUFFER, buffer_sz, NULL, to_gl(verts->usage));
glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, 0, 0, buffer_sz);
-#if VRAM_USAGE
- vbo_memory_usage += GPU_vertbuf_size_get(verts);
-#endif
+
+ VertBuf::memory_usage += GPU_
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list