[Bf-blender-cvs] [d2e9de93b8d] master: GPU: Cleanup implementation casts

Clément Foucault noreply at git.blender.org
Tue Sep 8 04:15:57 CEST 2020


Commit: d2e9de93b8d1d6cd45abce8164d0f92af8f636d0
Author: Clément Foucault
Date:   Tue Sep 8 03:34:47 2020 +0200
Branches: master
https://developer.blender.org/rBd2e9de93b8d1d6cd45abce8164d0f92af8f636d0

GPU: Cleanup implementation casts

- Use the syntactic wrap/unwrap method to make code more readable.
- Update comment about hidden struct behind opaque types.
- Cleanup GPUDrawList type.

===================================================================

M	source/blender/gpu/GPU_drawlist.h
M	source/blender/gpu/GPU_framebuffer.h
M	source/blender/gpu/GPU_index_buffer.h
M	source/blender/gpu/GPU_texture.h
M	source/blender/gpu/GPU_uniform_buffer.h
M	source/blender/gpu/GPU_vertex_buffer.h
M	source/blender/gpu/intern/gpu_drawlist.cc
M	source/blender/gpu/intern/gpu_drawlist_private.hh
M	source/blender/gpu/intern/gpu_framebuffer.cc
M	source/blender/gpu/intern/gpu_framebuffer_private.hh
M	source/blender/gpu/intern/gpu_shader.cc
M	source/blender/gpu/intern/gpu_shader_private.hh
M	source/blender/gpu/intern/gpu_texture_private.hh
M	source/blender/gpu/intern/gpu_uniform_buffer.cc
M	source/blender/gpu/intern/gpu_uniform_buffer_private.hh
M	source/blender/gpu/intern/gpu_vertex_buffer_private.hh

===================================================================

diff --git a/source/blender/gpu/GPU_drawlist.h b/source/blender/gpu/GPU_drawlist.h
index 27f70da8cf8..485b90f48d4 100644
--- a/source/blender/gpu/GPU_drawlist.h
+++ b/source/blender/gpu/GPU_drawlist.h
@@ -32,14 +32,15 @@ extern "C" {
 
 struct GPUBatch;
 
-typedef void *GPUDrawList; /* Opaque pointer. */
+/** Opaque type hiding blender::gpu::DrawList. */
+typedef struct GPUDrawList GPUDrawList;
 
 /* Create a list with at least length drawcalls. Length can affect performance. */
-GPUDrawList GPU_draw_list_create(int length);
-void GPU_draw_list_discard(GPUDrawList list);
+GPUDrawList *GPU_draw_list_create(int length);
+void GPU_draw_list_discard(GPUDrawList *list);
 
-void GPU_draw_list_append(GPUDrawList list, GPUBatch *batch, int i_first, int i_count);
-void GPU_draw_list_submit(GPUDrawList list);
+void GPU_draw_list_append(GPUDrawList *list, GPUBatch *batch, int i_first, int i_count);
+void GPU_draw_list_submit(GPUDrawList *list);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/gpu/GPU_framebuffer.h b/source/blender/gpu/GPU_framebuffer.h
index c0391d96e06..be55cd7af2d 100644
--- a/source/blender/gpu/GPU_framebuffer.h
+++ b/source/blender/gpu/GPU_framebuffer.h
@@ -54,10 +54,8 @@ typedef enum eGPUBackBuffer {
   GPU_BACKBUFFER_RIGHT,
 } eGPUBackBuffer;
 
-/** Opaque pointer hiding blender::gpu::FrameBuffer. */
-typedef struct GPUFrameBuffer {
-  void *dummy;
-} GPUFrameBuffer;
+/** Opaque type hiding blender::gpu::FrameBuffer. */
+typedef struct GPUFrameBuffer GPUFrameBuffer;
 
 typedef struct GPUOffScreen GPUOffScreen;
 
diff --git a/source/blender/gpu/GPU_index_buffer.h b/source/blender/gpu/GPU_index_buffer.h
index df24e07caef..0c71dd539a6 100644
--- a/source/blender/gpu/GPU_index_buffer.h
+++ b/source/blender/gpu/GPU_index_buffer.h
@@ -31,11 +31,7 @@
 extern "C" {
 #endif
 
-/**
- * IMPORTANT: Do not allocate manually as the real struct is bigger (i.e: GLIndexBuf). This is only
- * the common and "public" part of the struct. Use the provided allocator.
- * TODO(fclem) Make the content of this struct hidden and expose getters/setters.
- **/
+/** Opaque type hiding blender::gpu::IndexBuf. */
 typedef struct GPUIndexBuf GPUIndexBuf;
 
 GPUIndexBuf *GPU_indexbuf_calloc(void);
diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h
index f2ddb5d8a22..2ce2ba093cf 100644
--- a/source/blender/gpu/GPU_texture.h
+++ b/source/blender/gpu/GPU_texture.h
@@ -36,6 +36,8 @@ struct MovieClipUser;
 struct PreviewImage;
 
 struct GPUFrameBuffer;
+
+/** Opaque type hiding blender::gpu::Texture. */
 typedef struct GPUTexture GPUTexture;
 
 /* GPU Samplers state
diff --git a/source/blender/gpu/GPU_uniform_buffer.h b/source/blender/gpu/GPU_uniform_buffer.h
index 605e2b14434..ebcaa80e6f6 100644
--- a/source/blender/gpu/GPU_uniform_buffer.h
+++ b/source/blender/gpu/GPU_uniform_buffer.h
@@ -36,10 +36,8 @@ extern "C" {
 
 struct ListBase;
 
-/** Opaque pointer hiding blender::gpu::UniformBuf. */
-typedef struct GPUUniformBuf {
-  void *dummy;
-} GPUUniformBuf;
+/** Opaque type hiding blender::gpu::UniformBuf. */
+typedef struct GPUUniformBuf GPUUniformBuf;
 
 GPUUniformBuf *GPU_uniformbuf_create_ex(size_t size, const void *data, const char *name);
 GPUUniformBuf *GPU_uniformbuf_create_from_list(struct ListBase *inputs, const char *name);
diff --git a/source/blender/gpu/GPU_vertex_buffer.h b/source/blender/gpu/GPU_vertex_buffer.h
index 80f0501edc0..2af9929db35 100644
--- a/source/blender/gpu/GPU_vertex_buffer.h
+++ b/source/blender/gpu/GPU_vertex_buffer.h
@@ -61,6 +61,7 @@ typedef enum {
   GPU_USAGE_DYNAMIC,
 } GPUUsageType;
 
+/** Opaque type hiding blender::gpu::VertBuf. */
 typedef struct GPUVertBuf GPUVertBuf;
 
 GPUVertBuf *GPU_vertbuf_calloc(void);
diff --git a/source/blender/gpu/intern/gpu_drawlist.cc b/source/blender/gpu/intern/gpu_drawlist.cc
index 7b807a2fa80..ecea4f7c5e4 100644
--- a/source/blender/gpu/intern/gpu_drawlist.cc
+++ b/source/blender/gpu/intern/gpu_drawlist.cc
@@ -34,26 +34,26 @@
 
 using namespace blender::gpu;
 
-GPUDrawList GPU_draw_list_create(int list_length)
+GPUDrawList *GPU_draw_list_create(int list_length)
 {
   DrawList *list_ptr = GPUBackend::get()->drawlist_alloc(list_length);
-  return reinterpret_cast<DrawList *>(list_ptr);
+  return wrap(list_ptr);
 }
 
-void GPU_draw_list_discard(GPUDrawList list)
+void GPU_draw_list_discard(GPUDrawList *list)
 {
-  DrawList *list_ptr = reinterpret_cast<DrawList *>(list);
+  DrawList *list_ptr = unwrap(list);
   delete list_ptr;
 }
 
-void GPU_draw_list_append(GPUDrawList list, GPUBatch *batch, int i_first, int i_count)
+void GPU_draw_list_append(GPUDrawList *list, GPUBatch *batch, int i_first, int i_count)
 {
-  DrawList *list_ptr = reinterpret_cast<DrawList *>(list);
+  DrawList *list_ptr = unwrap(list);
   list_ptr->append(batch, i_first, i_count);
 }
 
-void GPU_draw_list_submit(GPUDrawList list)
+void GPU_draw_list_submit(GPUDrawList *list)
 {
-  DrawList *list_ptr = reinterpret_cast<DrawList *>(list);
+  DrawList *list_ptr = unwrap(list);
   list_ptr->submit();
 }
diff --git a/source/blender/gpu/intern/gpu_drawlist_private.hh b/source/blender/gpu/intern/gpu_drawlist_private.hh
index ddb09fb0c89..fd223c3f255 100644
--- a/source/blender/gpu/intern/gpu_drawlist_private.hh
+++ b/source/blender/gpu/intern/gpu_drawlist_private.hh
@@ -25,6 +25,8 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "GPU_drawlist.h"
+
 namespace blender {
 namespace gpu {
 
@@ -40,5 +42,19 @@ class DrawList {
   virtual void submit() = 0;
 };
 
+/* Syntacting suggar. */
+static inline GPUDrawList *wrap(DrawList *vert)
+{
+  return reinterpret_cast<GPUDrawList *>(vert);
+}
+static inline DrawList *unwrap(GPUDrawList *vert)
+{
+  return reinterpret_cast<DrawList *>(vert);
+}
+static inline const DrawList *unwrap(const GPUDrawList *vert)
+{
+  return reinterpret_cast<const DrawList *>(vert);
+}
+
 }  // namespace gpu
 }  // namespace blender
diff --git a/source/blender/gpu/intern/gpu_framebuffer.cc b/source/blender/gpu/intern/gpu_framebuffer.cc
index 05cc8a30a43..e548eb241cf 100644
--- a/source/blender/gpu/intern/gpu_framebuffer.cc
+++ b/source/blender/gpu/intern/gpu_framebuffer.cc
@@ -194,21 +194,20 @@ GPUFrameBuffer *GPU_framebuffer_create(const char *name)
 {
   /* We generate the FB object later at first use in order to
    * create the frame-buffer in the right opengl context. */
-  return (GPUFrameBuffer *)GPUBackend::get()->framebuffer_alloc(name);
+  return wrap(GPUBackend::get()->framebuffer_alloc(name));
 }
 
 void GPU_framebuffer_free(GPUFrameBuffer *gpu_fb)
 {
-  delete reinterpret_cast<FrameBuffer *>(gpu_fb);
+  delete unwrap(gpu_fb);
 }
 
 /* ---------- Binding ----------- */
 
 void GPU_framebuffer_bind(GPUFrameBuffer *gpu_fb)
 {
-  FrameBuffer *fb = reinterpret_cast<FrameBuffer *>(gpu_fb);
   const bool enable_srgb = true;
-  fb->bind(enable_srgb);
+  unwrap(gpu_fb)->bind(enable_srgb);
 }
 
 /**
@@ -216,9 +215,8 @@ void GPU_framebuffer_bind(GPUFrameBuffer *gpu_fb)
  */
 void GPU_framebuffer_bind_no_srgb(GPUFrameBuffer *gpu_fb)
 {
-  FrameBuffer *fb = reinterpret_cast<FrameBuffer *>(gpu_fb);
   const bool enable_srgb = false;
-  fb->bind(enable_srgb);
+  unwrap(gpu_fb)->bind(enable_srgb);
 }
 
 /**
@@ -244,14 +242,14 @@ void GPU_framebuffer_restore(void)
 GPUFrameBuffer *GPU_framebuffer_active_get(void)
 {
   GPUContext *ctx = GPU_context_active_get();
-  return reinterpret_cast<GPUFrameBuffer *>(ctx ? ctx->active_fb : NULL);
+  return wrap(ctx ? ctx->active_fb : NULL);
 }
 
 /* Returns the default frame-buffer. Will always exists even if it's just a dummy. */
 GPUFrameBuffer *GPU_framebuffer_back_get(void)
 {
   GPUContext *ctx = GPU_context_active_get();
-  return reinterpret_cast<GPUFrameBuffer *>(ctx ? ctx->back_left : NULL);
+  return wrap(ctx ? ctx->back_left : NULL);
 }
 
 bool GPU_framebuffer_bound(GPUFrameBuffer *gpu_fb)
@@ -263,14 +261,14 @@ bool GPU_framebuffer_bound(GPUFrameBuffer *gpu_fb)
 
 bool GPU_framebuffer_check_valid(GPUFrameBuffer *gpu_fb, char err_out[256])
 {
-  return reinterpret_cast<FrameBuffer *>(gpu_fb)->check(err_out);
+  return unwrap(gpu_fb)->check(err_out);
 }
 
 void GPU_framebuffer_texture_attach_ex(GPUFrameBuffer *gpu_fb, GPUAttachment attachment, int slot)
 {
   Texture *tex = reinterpret_cast<Texture *>(attachment.tex);
   GPUAttachmentType type = tex->attachment_type(slot);
-  reinterpret_cast<FrameBuffer *>(gpu_fb)->attachment_set(type, attachment);
+  unwrap(gpu_fb)->attachment_set(type, attachment);
 }
 
 void GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int mip)
@@ -293,10 +291,9 @@ void GPU_framebuffer_texture_cubeface_attach(
   GPU_framebuffer_texture_attach_ex(fb, attachment, slot);
 }
 
-void GPU_framebuffer_texture_detach(GPUFrameBuffer *gpu_fb, GPUTexture *tex)
+void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex)
 {
-  FrameBuffer *fb = reinterpret_cast<FrameBuffer *>(gpu_fb);
-  reinterpret_cast<Texture *>(tex)->detach_from(fb);
+  unwrap(tex)->detach_from(unwrap(fb));
 }
 
 /**
@@ -309,7 +306,7 @@ void GPU_framebuffer_config_array(GPUFrameBuffer *gpu_fb,
                                   const GPUAttachment *config,
                                   int config_len)
 {
-  FrameBuffer *fb = reinterpret_cast<FrameBuffer *>(gpu_fb);
+  FrameBuffer *fb = unwrap(gpu_fb);
 
   const GPUAttachment &depth_attachment = config[0];
   Span<GPUAttachment> color_attachments(config + 1, config_len - 1);
@@ -346,12 +343,12 @@ void GPU_framebuffer_config_array(GPUFrameBuffer *gpu_fb,
 void GPU_framebuffer_viewport_set(GPUFrameBuffer *gpu_fb, int x, int y, int width, int height)
 {
   int viewport_rect[4] = {x, y, width, height};
-  reinterpret_cast<FrameBuffer *>(gpu_fb)->viewport_set(viewport_rect);
+  unwrap(gpu_fb)->viewport_set(viewport_rect);
 }
 
 void GPU_framebuffer_viewport_get(GPUFrameBuffer *gpu_fb, int r_viewport[4])
 {
-  reinterpret_cast<FrameBuffer *>(gpu_fb)->viewport_get(r_viewport);
+  unwrap(gpu_fb)->viewport_get(r_viewport);
 }
 
 /**
@@ -359,7 +356,7 @@ void GPU_framebuffer_viewport_get(GPUFrameBuffer *gpu_fb, int r_viewport[4])
  */
 void GPU_framebuffer_viewport_reset(GPUFrameBuffer *gpu_fb)
 {
-  reinterpret_cast<FrameBuffer *>(gpu_fb)->viewport_reset();
+  unwrap(gp

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list