[Bf-blender-cvs] [35481fde40c] master: GPUOffScreen: Remove the sample parameter

Clément Foucault noreply at git.blender.org
Thu Jul 2 17:29:19 CEST 2020


Commit: 35481fde40c78e004230d7909e7b7d83438cc64e
Author: Clément Foucault
Date:   Thu Jul 2 17:28:30 2020 +0200
Branches: master
https://developer.blender.org/rB35481fde40c78e004230d7909e7b7d83438cc64e

GPUOffScreen: Remove the sample parameter

This is because the DRW module is no longer compatible with drawing using
MSAA.

This also change the Python API.

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

M	source/blender/editors/gpencil/gpencil_fill.c
M	source/blender/editors/render/render_opengl.c
M	source/blender/editors/screen/screen_draw.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/gpu/GPU_framebuffer.h
M	source/blender/gpu/intern/gpu_framebuffer.c
M	source/blender/python/gpu/gpu_py_offscreen.c
M	source/blender/windowmanager/intern/wm_draw.c
M	source/blender/windowmanager/xr/intern/wm_xr_session.c

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

diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c
index 168693ff517..35bd44b88f9 100644
--- a/source/blender/editors/gpencil/gpencil_fill.c
+++ b/source/blender/editors/gpencil/gpencil_fill.c
@@ -352,8 +352,7 @@ static bool gpencil_render_offscreen(tGPDfill *tgpf)
   round_v2i_v2fl(tgpf->center, center);
 
   char err_out[256] = "unknown";
-  GPUOffScreen *offscreen = GPU_offscreen_create(
-      tgpf->sizex, tgpf->sizey, 0, true, false, err_out);
+  GPUOffScreen *offscreen = GPU_offscreen_create(tgpf->sizex, tgpf->sizey, true, false, err_out);
   if (offscreen == NULL) {
     printf("GPencil - Fill - Unable to create fill buffer\n");
     return false;
diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c
index 2861e851282..e2444d4e3b5 100644
--- a/source/blender/editors/render/render_opengl.c
+++ b/source/blender/editors/render/render_opengl.c
@@ -766,7 +766,7 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
 
   /* corrects render size with actual size, not every card supports non-power-of-two dimensions */
   DRW_opengl_context_enable(); /* Offscreen creation needs to be done in DRW context. */
-  ofs = GPU_offscreen_create(sizex, sizey, 0, true, true, err_out);
+  ofs = GPU_offscreen_create(sizex, sizey, true, true, err_out);
   DRW_opengl_context_disable();
 
   if (!ofs) {
diff --git a/source/blender/editors/screen/screen_draw.c b/source/blender/editors/screen/screen_draw.c
index 2452302561b..3700deb8d77 100644
--- a/source/blender/editors/screen/screen_draw.c
+++ b/source/blender/editors/screen/screen_draw.c
@@ -611,7 +611,7 @@ static void screen_preview_draw(const bScreen *screen, int size_x, int size_y)
 void ED_screen_preview_render(const bScreen *screen, int size_x, int size_y, uint *r_rect)
 {
   char err_out[256] = "unknown";
-  GPUOffScreen *offscreen = GPU_offscreen_create(size_x, size_y, 0, true, false, err_out);
+  GPUOffScreen *offscreen = GPU_offscreen_create(size_x, size_y, true, false, err_out);
 
   GPU_offscreen_bind(offscreen, true);
   GPU_clear_color(0.0, 0.0, 0.0, 0.0);
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index b3165c9fc78..6f7d815c33a 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -1888,7 +1888,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph,
 
   if (own_ofs) {
     /* bind */
-    ofs = GPU_offscreen_create(sizex, sizey, 0, true, false, err_out);
+    ofs = GPU_offscreen_create(sizex, sizey, true, false, err_out);
     if (ofs == NULL) {
       DRW_opengl_context_disable();
       return NULL;
diff --git a/source/blender/gpu/GPU_framebuffer.h b/source/blender/gpu/GPU_framebuffer.h
index 213cbe30794..fcbe3ef2a78 100644
--- a/source/blender/gpu/GPU_framebuffer.h
+++ b/source/blender/gpu/GPU_framebuffer.h
@@ -195,7 +195,7 @@ void GPU_framebuffer_recursive_downsample(GPUFrameBuffer *fb,
  */
 
 GPUOffScreen *GPU_offscreen_create(
-    int width, int height, int samples, bool depth, bool high_bitdepth, char err_out[256]);
+    int width, int height, bool depth, bool high_bitdepth, char err_out[256]);
 void GPU_offscreen_free(GPUOffScreen *ofs);
 void GPU_offscreen_bind(GPUOffScreen *ofs, bool save);
 void GPU_offscreen_unbind(GPUOffScreen *ofs, bool restore);
diff --git a/source/blender/gpu/intern/gpu_framebuffer.c b/source/blender/gpu/intern/gpu_framebuffer.c
index 5af9364b92c..3e806e1a982 100644
--- a/source/blender/gpu/intern/gpu_framebuffer.c
+++ b/source/blender/gpu/intern/gpu_framebuffer.c
@@ -876,7 +876,7 @@ static GPUFrameBuffer *gpu_offscreen_fb_get(GPUOffScreen *ofs)
 }
 
 GPUOffScreen *GPU_offscreen_create(
-    int width, int height, int samples, bool depth, bool high_bitdepth, char err_out[256])
+    int width, int height, bool depth, bool high_bitdepth, char err_out[256])
 {
   GPUOffScreen *ofs;
 
@@ -887,12 +887,11 @@ GPUOffScreen *GPU_offscreen_create(
   height = max_ii(1, height);
   width = max_ii(1, width);
 
-  ofs->color = GPU_texture_create_2d_multisample(
-      width, height, (high_bitdepth) ? GPU_RGBA16F : GPU_RGBA8, NULL, samples, err_out);
+  ofs->color = GPU_texture_create_2d(
+      width, height, (high_bitdepth) ? GPU_RGBA16F : GPU_RGBA8, NULL, err_out);
 
   if (depth) {
-    ofs->depth = GPU_texture_create_2d_multisample(
-        width, height, GPU_DEPTH24_STENCIL8, NULL, samples, err_out);
+    ofs->depth = GPU_texture_create_2d(width, height, GPU_DEPTH24_STENCIL8, NULL, err_out);
   }
 
   if ((depth && !ofs->depth) || !ofs->color) {
@@ -993,48 +992,7 @@ void GPU_offscreen_read_pixels(GPUOffScreen *ofs, int type, void *pixels)
 
   BLI_assert(type == GL_UNSIGNED_BYTE || type == GL_FLOAT);
 
-  if (GPU_texture_target(ofs->color) == GL_TEXTURE_2D_MULTISAMPLE) {
-    /* For a multi-sample texture,
-     * we need to create an intermediate buffer to blit to,
-     * before its copied using 'glReadPixels' */
-    GLuint fbo_blit = 0;
-    GLuint tex_blit = 0;
-
-    /* create texture for new 'fbo_blit' */
-    glGenTextures(1, &tex_blit);
-    glBindTexture(GL_TEXTURE_2D, tex_blit);
-    glTexImage2D(
-        GL_TEXTURE_2D, 0, (type == GL_FLOAT) ? GL_RGBA16F : GL_RGBA8, w, h, 0, GL_RGBA, type, 0);
-
-    /* write into new single-sample buffer */
-    glGenFramebuffers(1, &fbo_blit);
-    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_blit);
-    glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex_blit, 0);
-
-    GLenum status = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
-    if (status != GL_FRAMEBUFFER_COMPLETE) {
-      goto finally;
-    }
-
-    /* perform the copy */
-    glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST);
-
-    /* read the results */
-    glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo_blit);
-    glReadPixels(0, 0, w, h, GL_RGBA, type, pixels);
-
-    /* restore the original frame-bufer */
-    GPUFrameBuffer *ofs_fb = gpu_offscreen_fb_get(ofs);
-    glBindFramebuffer(GL_FRAMEBUFFER, ofs_fb->object);
-
-  finally:
-    /* cleanup */
-    glDeleteTextures(1, &tex_blit);
-    glDeleteFramebuffers(1, &fbo_blit);
-  }
-  else {
-    glReadPixels(0, 0, w, h, GL_RGBA, type, pixels);
-  }
+  glReadPixels(0, 0, w, h, GL_RGBA, type, pixels);
 }
 
 int GPU_offscreen_width(const GPUOffScreen *ofs)
diff --git a/source/blender/python/gpu/gpu_py_offscreen.c b/source/blender/python/gpu/gpu_py_offscreen.c
index 311cf2b8c73..e56f87e6221 100644
--- a/source/blender/python/gpu/gpu_py_offscreen.c
+++ b/source/blender/python/gpu/gpu_py_offscreen.c
@@ -86,17 +86,17 @@ static PyObject *bpygpu_offscreen_new(PyTypeObject *UNUSED(self), PyObject *args
   BPYGPU_IS_INIT_OR_ERROR_OBJ;
 
   GPUOffScreen *ofs = NULL;
-  int width, height, samples = 0;
+  int width, height;
   char err_out[256];
 
-  static const char *_keywords[] = {"width", "height", "samples", NULL};
+  static const char *_keywords[] = {"width", "height", NULL};
   static _PyArg_Parser _parser = {"ii|i:GPUOffScreen.__new__", _keywords, 0};
-  if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, &width, &height, &samples)) {
+  if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, &width, &height)) {
     return NULL;
   }
 
   if (GPU_context_active_get()) {
-    ofs = GPU_offscreen_create(width, height, samples, true, false, err_out);
+    ofs = GPU_offscreen_create(width, height, true, false, err_out);
   }
   else {
     strncpy(err_out, "No active GPU context found", 256);
@@ -345,16 +345,14 @@ static struct PyMethodDef bpygpu_offscreen_methods[] = {
 };
 
 PyDoc_STRVAR(bpygpu_offscreen_doc,
-             ".. class:: GPUOffScreen(width, height, samples=0)\n"
+             ".. class:: GPUOffScreen(width, height)\n"
              "\n"
              "   This object gives access to off screen buffers.\n"
              "\n"
              "   :arg width: Horizontal dimension of the buffer.\n"
              "   :type width: `int`\n"
              "   :arg height: Vertical dimension of the buffer.\n"
-             "   :type height: `int`\n"
-             "   :arg samples: OpenGL samples to use for MSAA or zero to disable.\n"
-             "   :type samples: `int`\n");
+             "   :type height: `int`\n");
 PyTypeObject BPyGPUOffScreen_Type = {
     PyVarObject_HEAD_INIT(NULL, 0).tp_name = "GPUOffScreen",
     .tp_basicsize = sizeof(BPyGPUOffScreen),
diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c
index 3c2bc14837d..2b679dfefde 100644
--- a/source/blender/windowmanager/intern/wm_draw.c
+++ b/source/blender/windowmanager/intern/wm_draw.c
@@ -443,7 +443,7 @@ static void wm_draw_region_buffer_create(ARegion *region, bool stereo, bool use_
        * depth or multisample buffers. 3D view creates own buffers with
        * the data it needs. */
       GPUOffScreen *offscreen = GPU_offscreen_create(
-          region->winx, region->winy, 0, false, false, NULL);
+          region->winx, region->winy, false, false, NULL);
       if (!offscreen) {
         return;
       }
@@ -861,7 +861,7 @@ static void wm_draw_window(bContext *C, wmWindow *win)
      * stereo methods, but it's less efficient than drawing directly. */
     const int width = WM_window_pixels_x(win);
     const int height = WM_window_pixels_y(win);
-    GPUOffScreen *offscreen = GPU_offscreen_create(width, height, 0, false, false, NULL);
+    GPUOffScreen *offscreen = GPU_offscreen_create(width, height, false, false, NULL);
 
     if (offscreen) {
       GPUTexture *texture = GPU_offscreen_color_texture(offscreen);
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_session.c b/source/blender/windowmanager/xr/intern/wm_xr_session.c
index 2f72b2b25a5..1baac10dbd8 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_session.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr_session.c
@@ -340,7 +340,7 @@ bool wm_xr_session_surface_offscreen_ensure(wmXrSurfaceData *surface_data,
   }
 
   if (!(surface_data->offscreen = GPU_offscreen_create(
-            draw_view->width, draw_view->height, 0, true, false, err_out))) {
+            draw_vie

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list