2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-10-03 15:35:01 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* 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
|
2011-11-29 10:54:47 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2009-10-03 15:35:01 +00:00
|
|
|
*
|
|
|
|
|
* 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-10-03 15:35:01 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2005 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Brecht Van Lommel.
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-27 20:25:53 +00:00
|
|
|
/** \file blender/gpu/intern/gpu_buffers.c
|
|
|
|
|
* \ingroup gpu
|
2014-01-19 23:14:24 +11:00
|
|
|
*
|
2015-11-25 19:49:31 -05:00
|
|
|
* Mesh drawing using OpenGL VBO (Vertex Buffer Objects)
|
2011-02-27 20:25:53 +00:00
|
|
|
*/
|
|
|
|
|
|
2009-11-25 13:40:43 +00:00
|
|
|
#include <limits.h>
|
2009-11-25 18:20:46 +00:00
|
|
|
#include <stddef.h>
|
2009-10-03 15:35:01 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
2009-10-05 16:48:52 +00:00
|
|
|
|
2012-03-14 06:32:25 +00:00
|
|
|
#include "BLI_bitmap.h"
|
2010-07-13 13:31:43 +00:00
|
|
|
#include "BLI_math.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
#include "BLI_ghash.h"
|
2010-07-13 13:31:43 +00:00
|
|
|
#include "BLI_threads.h"
|
2009-10-05 16:48:52 +00:00
|
|
|
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
|
|
2012-05-10 20:33:09 +00:00
|
|
|
#include "BKE_ccg.h"
|
2009-10-03 15:35:01 +00:00
|
|
|
#include "BKE_DerivedMesh.h"
|
2012-03-14 06:32:25 +00:00
|
|
|
#include "BKE_paint.h"
|
2015-07-31 21:04:23 +10:00
|
|
|
#include "BKE_mesh.h"
|
2014-05-05 22:21:30 +03:00
|
|
|
#include "BKE_pbvh.h"
|
2009-10-05 16:48:52 +00:00
|
|
|
|
2010-07-14 10:46:12 +00:00
|
|
|
#include "GPU_buffers.h"
|
2012-10-22 17:33:53 +00:00
|
|
|
#include "GPU_draw.h"
|
2017-03-02 21:40:13 -05:00
|
|
|
#include "GPU_immediate.h"
|
2017-05-10 20:14:52 +10:00
|
|
|
#include "GPU_batch.h"
|
|
|
|
|
|
2012-12-30 18:24:54 +00:00
|
|
|
#include "bmesh.h"
|
|
|
|
|
|
2013-08-19 10:06:05 +00:00
|
|
|
static ThreadMutex buffer_mutex = BLI_MUTEX_INITIALIZER;
|
|
|
|
|
|
2015-07-16 16:22:28 +02:00
|
|
|
/* multires global buffer, can be used for many grids having the same grid size */
|
Fix T47637: Multiple multires objects in Sculpt mode make blender crash.
That was a nice and funny hunt, albeit rather time consumming!
To summarize, so far code was using a static global gpu_buffer for pbvh vbo drawing
of 'grid' types (multires mostly?).
There were two issues here:
1) Global gpu buffer was assigned to GPU_PBVH_Buffers->index_buf, but then nearly no
check was done when freeing that buffer, to ensure we were not freeing the global one
(not totally sure this one was actually causing any issue, but was bad and unsafe anyway).
Was solved by adding a flag to GPU_PBVH_Buffers to indicate when we are using some
'common' buffer here, which freeing is handled separately.
2) Main issue: if several multires objects in sculpt mode with different grid size
were present simultaneously, the global gpu buffer had to be resized for each object draw
(i.e., freed and re-allocated), but then the pbvh nodes from other objects storing freed reference
to that global buffer had no way to know that it had been freed, which was causing the segfault & crash.
Was solved by getting rid of that global buffer, and instead allocating one 'grid_commmon_gpu_buffer' per pbvh.
Told ya baby, globals are *PURE EVIL*!
2016-06-02 15:57:58 +02:00
|
|
|
typedef struct GridCommonGPUBuffer {
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_IndexBuf *mres_buffer;
|
Fix T47637: Multiple multires objects in Sculpt mode make blender crash.
That was a nice and funny hunt, albeit rather time consumming!
To summarize, so far code was using a static global gpu_buffer for pbvh vbo drawing
of 'grid' types (multires mostly?).
There were two issues here:
1) Global gpu buffer was assigned to GPU_PBVH_Buffers->index_buf, but then nearly no
check was done when freeing that buffer, to ensure we were not freeing the global one
(not totally sure this one was actually causing any issue, but was bad and unsafe anyway).
Was solved by adding a flag to GPU_PBVH_Buffers to indicate when we are using some
'common' buffer here, which freeing is handled separately.
2) Main issue: if several multires objects in sculpt mode with different grid size
were present simultaneously, the global gpu buffer had to be resized for each object draw
(i.e., freed and re-allocated), but then the pbvh nodes from other objects storing freed reference
to that global buffer had no way to know that it had been freed, which was causing the segfault & crash.
Was solved by getting rid of that global buffer, and instead allocating one 'grid_commmon_gpu_buffer' per pbvh.
Told ya baby, globals are *PURE EVIL*!
2016-06-02 15:57:58 +02:00
|
|
|
int mres_prev_gridsize;
|
|
|
|
|
unsigned mres_prev_totquad;
|
|
|
|
|
} GridCommonGPUBuffer;
|
2015-07-16 16:22:28 +02:00
|
|
|
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
/* XXX: the rest of the code in this file is used for optimized PBVH
|
2012-04-22 11:54:53 +00:00
|
|
|
* drawing and doesn't interact at all with the buffer code above */
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
|
2014-01-02 22:22:36 +02:00
|
|
|
struct GPU_PBVH_Buffers {
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_IndexBuf *index_buf, *index_buf_fast;
|
|
|
|
|
Gwn_VertBuf *vert_buf;
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *triangles;
|
|
|
|
|
Gwn_Batch *triangles_fast;
|
2015-08-03 19:08:50 +02:00
|
|
|
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
/* mesh pointers in case buffer allocation fails */
|
2015-07-17 03:36:03 +10:00
|
|
|
const MPoly *mpoly;
|
|
|
|
|
const MLoop *mloop;
|
|
|
|
|
const MLoopTri *looptri;
|
2015-07-11 03:25:28 +10:00
|
|
|
const MVert *mvert;
|
2015-07-17 03:36:03 +10:00
|
|
|
|
2014-04-27 00:24:11 +10:00
|
|
|
const int *face_indices;
|
2015-07-17 03:36:03 +10:00
|
|
|
int face_indices_len;
|
2012-05-10 20:36:34 +00:00
|
|
|
const float *vmask;
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
|
|
|
|
|
/* grid pointers */
|
2012-05-10 20:33:09 +00:00
|
|
|
CCGKey gridkey;
|
|
|
|
|
CCGElem **grids;
|
2012-03-06 02:40:08 +00:00
|
|
|
const DMFlagMat *grid_flag_mats;
|
2013-07-22 23:20:48 +00:00
|
|
|
BLI_bitmap * const *grid_hidden;
|
2014-04-27 00:24:11 +10:00
|
|
|
const int *grid_indices;
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
int totgrid;
|
2015-11-25 19:49:31 -05:00
|
|
|
bool has_hidden;
|
Fix T47637: Multiple multires objects in Sculpt mode make blender crash.
That was a nice and funny hunt, albeit rather time consumming!
To summarize, so far code was using a static global gpu_buffer for pbvh vbo drawing
of 'grid' types (multires mostly?).
There were two issues here:
1) Global gpu buffer was assigned to GPU_PBVH_Buffers->index_buf, but then nearly no
check was done when freeing that buffer, to ensure we were not freeing the global one
(not totally sure this one was actually causing any issue, but was bad and unsafe anyway).
Was solved by adding a flag to GPU_PBVH_Buffers to indicate when we are using some
'common' buffer here, which freeing is handled separately.
2) Main issue: if several multires objects in sculpt mode with different grid size
were present simultaneously, the global gpu buffer had to be resized for each object draw
(i.e., freed and re-allocated), but then the pbvh nodes from other objects storing freed reference
to that global buffer had no way to know that it had been freed, which was causing the segfault & crash.
Was solved by getting rid of that global buffer, and instead allocating one 'grid_commmon_gpu_buffer' per pbvh.
Told ya baby, globals are *PURE EVIL*!
2016-06-02 15:57:58 +02:00
|
|
|
bool is_index_buf_global; /* Means index_buf uses global bvh's grid_common_gpu_buffer, **DO NOT** free it! */
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
|
2015-11-25 19:49:31 -05:00
|
|
|
bool use_bmesh;
|
2012-12-30 18:24:54 +00:00
|
|
|
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
unsigned int tot_tri, tot_quad;
|
2012-10-06 16:42:11 +00:00
|
|
|
|
|
|
|
|
/* The PBVH ensures that either all faces in the node are
|
2013-06-06 06:02:46 +00:00
|
|
|
* smooth-shaded or all faces are flat-shaded */
|
2015-11-25 19:49:31 -05:00
|
|
|
bool smooth;
|
2012-10-22 17:33:53 +00:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
bool show_diffuse_color;
|
2018-01-15 11:38:56 +01:00
|
|
|
bool show_mask;
|
|
|
|
|
|
2012-10-22 17:33:53 +00:00
|
|
|
float diffuse_color[4];
|
2011-11-05 03:29:37 +00:00
|
|
|
};
|
2015-03-23 15:29:42 -04:00
|
|
|
|
2018-03-19 18:09:00 -03:00
|
|
|
static struct {
|
2017-05-10 20:14:52 +10:00
|
|
|
uint pos, nor, col;
|
2018-03-19 18:09:00 -03:00
|
|
|
} g_vbo_id = {0};
|
2017-05-10 20:14:52 +10:00
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
static void gpu_material_diffuse_get(int UNUSED(nr), float diff[4])
|
|
|
|
|
{
|
|
|
|
|
/* TODO: sculpt diffuse color option not supported in 2.8 yet. */
|
|
|
|
|
diff[0] = 0.8f;
|
|
|
|
|
diff[1] = 0.8f;
|
|
|
|
|
diff[2] = 0.8f;
|
|
|
|
|
diff[3] = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-19 18:09:00 -03:00
|
|
|
/* Allocates a non-initialized buffer to be sent to GPU.
|
|
|
|
|
* Return is false it indicates that the memory map failed. */
|
2018-07-08 13:14:49 +02:00
|
|
|
static bool gpu_pbvh_vert_buf_data_set(GPU_PBVH_Buffers *buffers, unsigned int vert_len)
|
2017-05-10 20:14:52 +10:00
|
|
|
{
|
2018-03-19 18:09:00 -03:00
|
|
|
if (buffers->vert_buf == NULL) {
|
|
|
|
|
/* Initialize vertex buffer */
|
|
|
|
|
/* match 'VertexBufferFormat' */
|
|
|
|
|
|
|
|
|
|
static Gwn_VertFormat format = {0};
|
2018-07-08 13:05:41 +02:00
|
|
|
if (format.attr_len == 0) {
|
2018-03-19 18:09:00 -03:00
|
|
|
g_vbo_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
|
|
|
|
g_vbo_id.nor = GWN_vertformat_attr_add(&format, "nor", GWN_COMP_I16, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
|
|
|
|
|
g_vbo_id.col = GWN_vertformat_attr_add(&format, "color", GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
|
|
|
|
|
}
|
|
|
|
|
#if 0
|
|
|
|
|
buffers->vert_buf = GWN_vertbuf_create_with_format_ex(&format, GWN_USAGE_DYNAMIC);
|
2018-07-08 13:14:49 +02:00
|
|
|
GWN_vertbuf_data_alloc(buffers->vert_buf, vert_len);
|
2018-03-19 18:09:00 -03:00
|
|
|
}
|
2018-07-08 13:14:49 +02:00
|
|
|
else if (vert_len != buffers->vert_buf->vertex_len) {
|
|
|
|
|
GWN_vertbuf_data_resize(buffers->vert_buf, vert_len);
|
2018-03-19 18:09:00 -03:00
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
buffers->vert_buf = GWN_vertbuf_create_with_format_ex(&format, GWN_USAGE_STATIC);
|
|
|
|
|
}
|
2018-07-08 13:14:49 +02:00
|
|
|
GWN_vertbuf_data_alloc(buffers->vert_buf, vert_len);
|
2018-03-19 18:09:00 -03:00
|
|
|
#endif
|
|
|
|
|
return buffers->vert_buf->data != NULL;
|
2017-05-10 20:14:52 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void gpu_pbvh_batch_init(GPU_PBVH_Buffers *buffers)
|
|
|
|
|
{
|
|
|
|
|
/* force flushing to the GPU */
|
|
|
|
|
if (buffers->vert_buf->data) {
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_use(buffers->vert_buf);
|
2017-05-10 20:14:52 +10:00
|
|
|
}
|
|
|
|
|
|
2018-03-19 18:09:00 -03:00
|
|
|
if (buffers->triangles == NULL) {
|
|
|
|
|
buffers->triangles = GWN_batch_create(
|
|
|
|
|
GWN_PRIM_TRIS, buffers->vert_buf,
|
|
|
|
|
/* can be NULL */
|
|
|
|
|
buffers->index_buf);
|
|
|
|
|
}
|
2017-05-10 20:14:52 +10:00
|
|
|
|
2018-03-19 18:09:00 -03:00
|
|
|
if ((buffers->triangles_fast == NULL) && buffers->index_buf_fast) {
|
2017-06-19 20:18:04 +10:00
|
|
|
buffers->triangles_fast = GWN_batch_create(
|
|
|
|
|
GWN_PRIM_TRIS, buffers->vert_buf,
|
2017-05-10 20:14:52 +10:00
|
|
|
/* can be NULL */
|
|
|
|
|
buffers->index_buf_fast);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-10 20:36:34 +00:00
|
|
|
static float gpu_color_from_mask(float mask)
|
|
|
|
|
{
|
2012-10-22 17:33:53 +00:00
|
|
|
return 1.0f - mask * 0.75f;
|
2012-05-10 20:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-22 17:33:53 +00:00
|
|
|
static void gpu_color_from_mask_copy(float mask, const float diffuse_color[4], unsigned char out[3])
|
2012-05-10 20:36:34 +00:00
|
|
|
{
|
2012-10-22 17:33:53 +00:00
|
|
|
float mask_color;
|
|
|
|
|
|
|
|
|
|
mask_color = gpu_color_from_mask(mask) * 255.0f;
|
2012-05-10 20:36:34 +00:00
|
|
|
|
2012-10-22 17:33:53 +00:00
|
|
|
out[0] = diffuse_color[0] * mask_color;
|
|
|
|
|
out[1] = diffuse_color[1] * mask_color;
|
|
|
|
|
out[2] = diffuse_color[2] * mask_color;
|
2012-05-10 20:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void gpu_color_from_mask_quad_copy(const CCGKey *key,
|
2012-05-11 08:05:47 +00:00
|
|
|
CCGElem *a, CCGElem *b,
|
|
|
|
|
CCGElem *c, CCGElem *d,
|
2012-10-22 17:33:53 +00:00
|
|
|
const float *diffuse_color,
|
2012-05-11 08:05:47 +00:00
|
|
|
unsigned char out[3])
|
2012-05-10 20:36:34 +00:00
|
|
|
{
|
2012-10-22 17:33:53 +00:00
|
|
|
float mask_color =
|
2012-05-11 08:05:47 +00:00
|
|
|
gpu_color_from_mask((*CCG_elem_mask(key, a) +
|
|
|
|
|
*CCG_elem_mask(key, b) +
|
|
|
|
|
*CCG_elem_mask(key, c) +
|
|
|
|
|
*CCG_elem_mask(key, d)) * 0.25f) * 255.0f;
|
2012-05-10 20:36:34 +00:00
|
|
|
|
2012-10-22 17:33:53 +00:00
|
|
|
out[0] = diffuse_color[0] * mask_color;
|
|
|
|
|
out[1] = diffuse_color[1] * mask_color;
|
|
|
|
|
out[2] = diffuse_color[2] * mask_color;
|
2012-05-10 20:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-11 22:03:50 +10:00
|
|
|
void GPU_pbvh_mesh_buffers_update(
|
2015-07-11 03:25:28 +10:00
|
|
|
GPU_PBVH_Buffers *buffers, const MVert *mvert,
|
|
|
|
|
const int *vert_indices, int totvert, const float *vmask,
|
2018-01-12 17:35:26 +01:00
|
|
|
const int (*face_vert_indices)[3],
|
|
|
|
|
const int update_flags)
|
2009-10-03 15:35:01 +00:00
|
|
|
{
|
2018-01-12 17:35:26 +01:00
|
|
|
const bool show_diffuse_color = (update_flags & GPU_PBVH_BUFFERS_SHOW_DIFFUSE_COLOR) != 0;
|
2018-01-15 11:38:56 +01:00
|
|
|
const bool show_mask = (update_flags & GPU_PBVH_BUFFERS_SHOW_MASK) != 0;
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
|
2012-05-10 20:36:34 +00:00
|
|
|
buffers->vmask = vmask;
|
2014-04-01 20:17:23 +03:00
|
|
|
buffers->show_diffuse_color = show_diffuse_color;
|
2018-01-15 11:38:56 +01:00
|
|
|
buffers->show_mask = show_mask;
|
2012-05-10 20:36:34 +00:00
|
|
|
|
2015-07-16 16:22:28 +02:00
|
|
|
{
|
2012-10-06 16:52:52 +00:00
|
|
|
int totelem = (buffers->smooth ? totvert : (buffers->tot_tri * 3));
|
2014-04-02 17:33:47 +03:00
|
|
|
float diffuse_color[4] = {0.8f, 0.8f, 0.8f, 0.8f};
|
2012-10-22 17:33:53 +00:00
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
if (show_diffuse_color) {
|
2015-07-17 03:36:03 +10:00
|
|
|
const MLoopTri *lt = &buffers->looptri[buffers->face_indices[0]];
|
|
|
|
|
const MPoly *mp = &buffers->mpoly[lt->poly];
|
2012-10-22 17:33:53 +00:00
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
gpu_material_diffuse_get(mp->mat_nr + 1, diffuse_color);
|
2012-10-22 17:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
copy_v4_v4(buffers->diffuse_color, diffuse_color);
|
2012-10-06 16:52:52 +00:00
|
|
|
|
2017-05-11 07:34:56 +10:00
|
|
|
uchar diffuse_color_ub[4];
|
|
|
|
|
rgba_float_to_uchar(diffuse_color_ub, diffuse_color);
|
|
|
|
|
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
/* Build VBO */
|
2018-03-19 18:09:00 -03:00
|
|
|
if (gpu_pbvh_vert_buf_data_set(buffers, totelem)) {
|
2013-02-03 10:28:28 +00:00
|
|
|
/* Vertex data is shared if smooth-shaded, but separate
|
2013-06-06 06:02:46 +00:00
|
|
|
* copies are made for flat shading because normals
|
|
|
|
|
* shouldn't be shared. */
|
2012-10-06 16:52:52 +00:00
|
|
|
if (buffers->smooth) {
|
2017-05-10 20:14:52 +10:00
|
|
|
for (uint i = 0; i < totvert; ++i) {
|
2015-07-11 03:25:28 +10:00
|
|
|
const MVert *v = &mvert[vert_indices[i]];
|
2018-03-19 18:09:00 -03:00
|
|
|
GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.pos, i, v->co);
|
|
|
|
|
GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.nor, i, v->no);
|
2012-10-06 16:52:52 +00:00
|
|
|
}
|
2012-10-22 17:33:53 +00:00
|
|
|
|
2017-05-10 20:14:52 +10:00
|
|
|
for (uint i = 0; i < buffers->face_indices_len; i++) {
|
2015-07-17 03:36:03 +10:00
|
|
|
const MLoopTri *lt = &buffers->looptri[buffers->face_indices[i]];
|
2017-05-10 20:14:52 +10:00
|
|
|
for (uint j = 0; j < 3; j++) {
|
2017-05-11 07:51:27 +10:00
|
|
|
int vidx = face_vert_indices[i][j];
|
2018-01-15 11:38:56 +01:00
|
|
|
if (vmask && show_mask) {
|
2017-05-11 07:51:27 +10:00
|
|
|
int v_index = buffers->mloop[lt->tri[j]].v;
|
|
|
|
|
uchar color_ub[3];
|
|
|
|
|
gpu_color_from_mask_copy(vmask[v_index], diffuse_color, color_ub);
|
2018-03-19 18:09:00 -03:00
|
|
|
GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vidx, color_ub);
|
2017-05-10 20:14:52 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2018-03-19 18:09:00 -03:00
|
|
|
GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vidx, diffuse_color_ub);
|
2017-05-10 20:14:52 +10:00
|
|
|
}
|
|
|
|
|
}
|
2012-10-22 17:33:53 +00:00
|
|
|
}
|
2012-10-06 16:52:52 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2015-07-31 21:04:23 +10:00
|
|
|
/* calculate normal for each polygon only once */
|
|
|
|
|
unsigned int mpoly_prev = UINT_MAX;
|
|
|
|
|
short no[3];
|
2017-05-10 20:14:52 +10:00
|
|
|
int vbo_index = 0;
|
2015-07-31 21:04:23 +10:00
|
|
|
|
2017-05-10 20:14:52 +10:00
|
|
|
for (uint i = 0; i < buffers->face_indices_len; i++) {
|
2015-07-17 03:36:03 +10:00
|
|
|
const MLoopTri *lt = &buffers->looptri[buffers->face_indices[i]];
|
|
|
|
|
const unsigned int vtri[3] = {
|
|
|
|
|
buffers->mloop[lt->tri[0]].v,
|
|
|
|
|
buffers->mloop[lt->tri[1]].v,
|
|
|
|
|
buffers->mloop[lt->tri[2]].v,
|
|
|
|
|
};
|
2012-10-06 16:52:52 +00:00
|
|
|
|
2015-07-17 03:36:03 +10:00
|
|
|
if (paint_is_face_hidden(lt, mvert, buffers->mloop))
|
2012-10-23 11:07:05 +00:00
|
|
|
continue;
|
|
|
|
|
|
2012-10-06 16:52:52 +00:00
|
|
|
/* Face normal and mask */
|
2015-07-31 21:04:23 +10:00
|
|
|
if (lt->poly != mpoly_prev) {
|
|
|
|
|
const MPoly *mp = &buffers->mpoly[lt->poly];
|
|
|
|
|
float fno[3];
|
|
|
|
|
BKE_mesh_calc_poly_normal(mp, &buffers->mloop[mp->loopstart], mvert, fno);
|
|
|
|
|
normal_float_to_short_v3(no, fno);
|
|
|
|
|
mpoly_prev = lt->poly;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-11 07:34:56 +10:00
|
|
|
uchar color_ub[3];
|
2018-01-15 11:38:56 +01:00
|
|
|
if (vmask && show_mask) {
|
2017-05-11 07:34:56 +10:00
|
|
|
float fmask = (vmask[vtri[0]] + vmask[vtri[1]] + vmask[vtri[2]]) / 3.0f;
|
|
|
|
|
gpu_color_from_mask_copy(fmask, diffuse_color, color_ub);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
copy_v3_v3_uchar(color_ub, diffuse_color_ub);
|
2012-10-06 16:52:52 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-10 20:14:52 +10:00
|
|
|
for (uint j = 0; j < 3; j++) {
|
2015-07-17 03:36:03 +10:00
|
|
|
const MVert *v = &mvert[vtri[j]];
|
2012-10-06 16:52:52 +00:00
|
|
|
|
2018-03-19 18:09:00 -03:00
|
|
|
GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.pos, vbo_index, v->co);
|
|
|
|
|
GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.nor, vbo_index, no);
|
|
|
|
|
GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vbo_index, color_ub);
|
2012-10-06 16:52:52 +00:00
|
|
|
|
2017-05-10 20:14:52 +10:00
|
|
|
vbo_index++;
|
2012-10-06 16:52:52 +00:00
|
|
|
}
|
2012-10-01 05:19:57 +00:00
|
|
|
}
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-10 20:14:52 +10:00
|
|
|
gpu_pbvh_batch_init(buffers);
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
}
|
2009-10-03 15:35:01 +00:00
|
|
|
}
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
|
|
|
|
|
buffers->mvert = mvert;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-11 22:03:50 +10:00
|
|
|
GPU_PBVH_Buffers *GPU_pbvh_mesh_buffers_build(
|
2016-07-06 19:15:47 +10:00
|
|
|
const int (*face_vert_indices)[3],
|
2015-07-17 03:36:03 +10:00
|
|
|
const MPoly *mpoly, const MLoop *mloop, const MLoopTri *looptri,
|
|
|
|
|
const MVert *mvert,
|
2015-07-11 03:25:28 +10:00
|
|
|
const int *face_indices,
|
2015-07-17 03:36:03 +10:00
|
|
|
const int face_indices_len)
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
{
|
2014-01-02 22:22:36 +02:00
|
|
|
GPU_PBVH_Buffers *buffers;
|
2017-05-10 20:14:52 +10:00
|
|
|
int i, tottri;
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
|
2014-01-02 22:22:36 +02:00
|
|
|
buffers = MEM_callocN(sizeof(GPU_PBVH_Buffers), "GPU_Buffers");
|
2017-05-10 20:14:52 +10:00
|
|
|
|
2017-05-11 21:21:59 +10:00
|
|
|
/* smooth or flat for all */
|
|
|
|
|
#if 0
|
2015-07-24 16:28:18 +02:00
|
|
|
buffers->smooth = mpoly[looptri[face_indices[0]].poly].flag & ME_SMOOTH;
|
2017-05-11 21:21:59 +10:00
|
|
|
#else
|
|
|
|
|
/* for DrawManager we dont support mixed smooth/flat */
|
|
|
|
|
buffers->smooth = (mpoly[0].flag & ME_SMOOTH) != 0;
|
|
|
|
|
#endif
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
buffers->show_diffuse_color = false;
|
2018-01-15 11:38:56 +01:00
|
|
|
buffers->show_mask = true;
|
2012-10-22 17:33:53 +00:00
|
|
|
|
2012-03-14 06:32:25 +00:00
|
|
|
/* Count the number of visible triangles */
|
2015-07-17 03:36:03 +10:00
|
|
|
for (i = 0, tottri = 0; i < face_indices_len; ++i) {
|
|
|
|
|
const MLoopTri *lt = &looptri[face_indices[i]];
|
|
|
|
|
if (!paint_is_face_hidden(lt, mvert, mloop))
|
|
|
|
|
tottri++;
|
2012-03-14 06:32:25 +00:00
|
|
|
}
|
2012-10-06 16:52:52 +00:00
|
|
|
|
2014-05-05 21:13:27 +03:00
|
|
|
if (tottri == 0) {
|
|
|
|
|
buffers->tot_tri = 0;
|
|
|
|
|
|
2015-07-17 03:36:03 +10:00
|
|
|
buffers->mpoly = mpoly;
|
|
|
|
|
buffers->mloop = mloop;
|
|
|
|
|
buffers->looptri = looptri;
|
2014-05-05 21:13:27 +03:00
|
|
|
buffers->face_indices = face_indices;
|
2015-07-17 03:36:03 +10:00
|
|
|
buffers->face_indices_len = 0;
|
2014-05-05 21:13:27 +03:00
|
|
|
|
|
|
|
|
return buffers;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-06 16:52:52 +00:00
|
|
|
/* An element index buffer is used for smooth shading, but flat
|
2013-06-06 06:02:46 +00:00
|
|
|
* shading requires separate vertex normals so an index buffer is
|
|
|
|
|
* can't be used there. */
|
Fix T47637: Multiple multires objects in Sculpt mode make blender crash.
That was a nice and funny hunt, albeit rather time consumming!
To summarize, so far code was using a static global gpu_buffer for pbvh vbo drawing
of 'grid' types (multires mostly?).
There were two issues here:
1) Global gpu buffer was assigned to GPU_PBVH_Buffers->index_buf, but then nearly no
check was done when freeing that buffer, to ensure we were not freeing the global one
(not totally sure this one was actually causing any issue, but was bad and unsafe anyway).
Was solved by adding a flag to GPU_PBVH_Buffers to indicate when we are using some
'common' buffer here, which freeing is handled separately.
2) Main issue: if several multires objects in sculpt mode with different grid size
were present simultaneously, the global gpu buffer had to be resized for each object draw
(i.e., freed and re-allocated), but then the pbvh nodes from other objects storing freed reference
to that global buffer had no way to know that it had been freed, which was causing the segfault & crash.
Was solved by getting rid of that global buffer, and instead allocating one 'grid_commmon_gpu_buffer' per pbvh.
Told ya baby, globals are *PURE EVIL*!
2016-06-02 15:57:58 +02:00
|
|
|
if (buffers->smooth) {
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
/* Fill the triangle buffer */
|
2017-05-10 20:14:52 +10:00
|
|
|
buffers->index_buf = NULL;
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_IndexBufBuilder elb;
|
|
|
|
|
GWN_indexbuf_init(&elb, GWN_PRIM_TRIS, tottri, INT_MAX);
|
2017-05-10 20:14:52 +10:00
|
|
|
|
|
|
|
|
for (i = 0; i < face_indices_len; ++i) {
|
|
|
|
|
const MLoopTri *lt = &looptri[face_indices[i]];
|
|
|
|
|
|
|
|
|
|
/* Skip hidden faces */
|
|
|
|
|
if (paint_is_face_hidden(lt, mvert, mloop))
|
|
|
|
|
continue;
|
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_indexbuf_add_tri_verts(&elb, UNPACK3(face_vert_indices[i]));
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
}
|
2017-06-19 20:18:04 +10:00
|
|
|
buffers->index_buf = GWN_indexbuf_build(&elb);
|
2017-05-10 20:14:52 +10:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (!buffers->is_index_buf_global) {
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_INDEXBUF_DISCARD_SAFE(buffers->index_buf);
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
}
|
2017-05-10 20:14:52 +10:00
|
|
|
buffers->index_buf = NULL;
|
|
|
|
|
buffers->is_index_buf_global = false;
|
2009-10-03 15:35:01 +00:00
|
|
|
}
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
|
|
|
|
|
buffers->tot_tri = tottri;
|
|
|
|
|
|
2015-07-17 03:36:03 +10:00
|
|
|
buffers->mpoly = mpoly;
|
|
|
|
|
buffers->mloop = mloop;
|
|
|
|
|
buffers->looptri = looptri;
|
|
|
|
|
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
buffers->face_indices = face_indices;
|
2015-07-17 03:36:03 +10:00
|
|
|
buffers->face_indices_len = face_indices_len;
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
|
|
|
|
|
return buffers;
|
2009-10-05 16:48:52 +00:00
|
|
|
}
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
|
2017-05-11 22:03:50 +10:00
|
|
|
void GPU_pbvh_grid_buffers_update(
|
2017-05-10 20:14:52 +10:00
|
|
|
GPU_PBVH_Buffers *buffers, CCGElem **grids,
|
|
|
|
|
const DMFlagMat *grid_flag_mats, int *grid_indices,
|
2018-01-12 17:35:26 +01:00
|
|
|
int totgrid, const CCGKey *key,
|
|
|
|
|
const int update_flags)
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
{
|
2018-01-12 17:35:26 +01:00
|
|
|
const bool show_diffuse_color = (update_flags & GPU_PBVH_BUFFERS_SHOW_DIFFUSE_COLOR) != 0;
|
2018-01-15 11:38:56 +01:00
|
|
|
const bool show_mask = (update_flags & GPU_PBVH_BUFFERS_SHOW_MASK) != 0;
|
2012-05-10 20:36:24 +00:00
|
|
|
int i, j, k, x, y;
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
|
2014-04-01 20:17:23 +03:00
|
|
|
buffers->show_diffuse_color = show_diffuse_color;
|
2018-01-15 11:38:56 +01:00
|
|
|
buffers->show_mask = show_mask;
|
2015-11-25 19:49:31 -05:00
|
|
|
buffers->smooth = grid_flag_mats[grid_indices[0]].flag & ME_SMOOTH;
|
2012-10-22 17:33:53 +00:00
|
|
|
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
/* Build VBO */
|
2017-05-10 20:14:52 +10:00
|
|
|
if (buffers->index_buf) {
|
2012-10-01 05:19:57 +00:00
|
|
|
const int has_mask = key->has_mask;
|
2014-04-02 17:33:47 +03:00
|
|
|
float diffuse_color[4] = {0.8f, 0.8f, 0.8f, 1.0f};
|
2012-10-22 17:33:53 +00:00
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
if (show_diffuse_color) {
|
2012-10-22 17:33:53 +00:00
|
|
|
const DMFlagMat *flags = &grid_flag_mats[grid_indices[0]];
|
|
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
gpu_material_diffuse_get(flags->mat_nr + 1, diffuse_color);
|
2012-10-22 17:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
copy_v4_v4(buffers->diffuse_color, diffuse_color);
|
2012-03-06 02:40:08 +00:00
|
|
|
|
2017-05-10 20:14:52 +10:00
|
|
|
uint vbo_index_offset = 0;
|
2018-03-19 18:09:00 -03:00
|
|
|
/* Build VBO */
|
|
|
|
|
if (gpu_pbvh_vert_buf_data_set(buffers, totgrid * key->grid_area)) {
|
2012-03-24 06:38:07 +00:00
|
|
|
for (i = 0; i < totgrid; ++i) {
|
2012-05-11 08:05:47 +00:00
|
|
|
CCGElem *grid = grids[grid_indices[i]];
|
2017-05-10 20:14:52 +10:00
|
|
|
int vbo_index = vbo_index_offset;
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
|
2012-05-10 20:36:24 +00:00
|
|
|
for (y = 0; y < key->grid_size; y++) {
|
|
|
|
|
for (x = 0; x < key->grid_size; x++) {
|
|
|
|
|
CCGElem *elem = CCG_grid_elem(key, grid, x, y);
|
2018-03-19 18:09:00 -03:00
|
|
|
GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.pos, vbo_index, CCG_elem_co(key, elem));
|
2017-05-10 20:14:52 +10:00
|
|
|
|
2015-11-25 19:49:31 -05:00
|
|
|
if (buffers->smooth) {
|
2017-05-10 20:14:52 +10:00
|
|
|
short no_short[3];
|
|
|
|
|
normal_float_to_short_v3(no_short, CCG_elem_no(key, elem));
|
2018-03-19 18:09:00 -03:00
|
|
|
GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.nor, vbo_index, no_short);
|
2012-05-10 20:36:34 +00:00
|
|
|
|
2018-01-16 14:46:48 +01:00
|
|
|
if (has_mask) {
|
2017-05-10 20:14:52 +10:00
|
|
|
uchar color_ub[3];
|
2018-01-16 14:46:48 +01:00
|
|
|
if (show_mask) {
|
|
|
|
|
gpu_color_from_mask_copy(*CCG_elem_mask(key, elem),
|
2018-01-16 14:52:43 +01:00
|
|
|
diffuse_color, color_ub);
|
2018-01-16 14:46:48 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2018-05-07 18:02:48 +02:00
|
|
|
unit_float_to_uchar_clamp_v3(color_ub, diffuse_color);
|
2018-01-16 14:46:48 +01:00
|
|
|
}
|
2018-03-19 18:09:00 -03:00
|
|
|
GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vbo_index, color_ub);
|
2012-10-01 05:19:57 +00:00
|
|
|
}
|
2012-05-10 20:36:24 +00:00
|
|
|
}
|
2017-05-10 20:14:52 +10:00
|
|
|
vbo_index += 1;
|
2012-05-10 20:36:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
2018-06-04 09:09:12 +02:00
|
|
|
|
2015-11-25 19:49:31 -05:00
|
|
|
if (!buffers->smooth) {
|
2012-05-10 20:33:09 +00:00
|
|
|
for (j = 0; j < key->grid_size - 1; j++) {
|
|
|
|
|
for (k = 0; k < key->grid_size - 1; k++) {
|
2012-05-10 20:36:34 +00:00
|
|
|
CCGElem *elems[4] = {
|
2012-05-11 08:05:47 +00:00
|
|
|
CCG_grid_elem(key, grid, k, j + 1),
|
|
|
|
|
CCG_grid_elem(key, grid, k + 1, j + 1),
|
|
|
|
|
CCG_grid_elem(key, grid, k + 1, j),
|
2012-05-10 20:36:34 +00:00
|
|
|
CCG_grid_elem(key, grid, k, j)
|
|
|
|
|
};
|
2012-02-28 05:00:28 +00:00
|
|
|
float fno[3];
|
2012-05-10 20:36:34 +00:00
|
|
|
|
2012-02-28 05:00:28 +00:00
|
|
|
normal_quad_v3(fno,
|
2012-05-11 08:05:47 +00:00
|
|
|
CCG_elem_co(key, elems[0]),
|
|
|
|
|
CCG_elem_co(key, elems[1]),
|
|
|
|
|
CCG_elem_co(key, elems[2]),
|
|
|
|
|
CCG_elem_co(key, elems[3]));
|
2012-02-28 05:00:28 +00:00
|
|
|
|
2017-05-10 20:14:52 +10:00
|
|
|
vbo_index = vbo_index_offset + ((j + 1) * key->grid_size + k);
|
|
|
|
|
short no_short[3];
|
|
|
|
|
normal_float_to_short_v3(no_short, fno);
|
2018-03-19 18:09:00 -03:00
|
|
|
GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.nor, vbo_index, no_short);
|
2012-10-01 05:19:57 +00:00
|
|
|
|
|
|
|
|
if (has_mask) {
|
2017-05-10 20:14:52 +10:00
|
|
|
uchar color_ub[3];
|
2018-01-16 14:31:52 +01:00
|
|
|
if (show_mask) {
|
|
|
|
|
gpu_color_from_mask_quad_copy(key,
|
|
|
|
|
elems[0],
|
|
|
|
|
elems[1],
|
|
|
|
|
elems[2],
|
|
|
|
|
elems[3],
|
|
|
|
|
diffuse_color,
|
2018-01-16 14:52:43 +01:00
|
|
|
color_ub);
|
2018-01-16 14:31:52 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2018-05-07 18:02:48 +02:00
|
|
|
unit_float_to_uchar_clamp_v3(color_ub, diffuse_color);
|
2018-01-16 14:31:52 +01:00
|
|
|
}
|
2018-03-19 18:09:00 -03:00
|
|
|
GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vbo_index, color_ub);
|
2012-10-01 05:19:57 +00:00
|
|
|
}
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 20:14:52 +10:00
|
|
|
vbo_index_offset += key->grid_area;
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
}
|
2015-07-16 16:22:28 +02:00
|
|
|
|
2017-05-10 20:14:52 +10:00
|
|
|
gpu_pbvh_batch_init(buffers);
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buffers->grids = grids;
|
|
|
|
|
buffers->grid_indices = grid_indices;
|
|
|
|
|
buffers->totgrid = totgrid;
|
2012-03-06 02:40:08 +00:00
|
|
|
buffers->grid_flag_mats = grid_flag_mats;
|
2012-05-10 20:33:09 +00:00
|
|
|
buffers->gridkey = *key;
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
|
2012-01-02 19:01:16 +00:00
|
|
|
//printf("node updated %p\n", buffers);
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-22 23:30:56 +00:00
|
|
|
/* Build the element array buffer of grid indices using either
|
2012-04-22 11:54:53 +00:00
|
|
|
* unsigned shorts or unsigned ints. */
|
2017-05-10 20:14:52 +10:00
|
|
|
#define FILL_QUAD_BUFFER(max_vert_, tot_quad_, buffer_) \
|
2015-03-23 15:29:42 -04:00
|
|
|
{ \
|
|
|
|
|
int offset = 0; \
|
|
|
|
|
int i, j, k; \
|
2017-05-10 20:14:52 +10:00
|
|
|
\
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_IndexBufBuilder elb; \
|
|
|
|
|
GWN_indexbuf_init( \
|
|
|
|
|
&elb, GWN_PRIM_TRIS, tot_quad_ * 2, max_vert_); \
|
2015-03-23 15:29:42 -04:00
|
|
|
\
|
|
|
|
|
/* Fill the buffer */ \
|
2017-05-10 20:14:52 +10:00
|
|
|
for (i = 0; i < totgrid; ++i) { \
|
|
|
|
|
BLI_bitmap *gh = NULL; \
|
|
|
|
|
if (grid_hidden) \
|
|
|
|
|
gh = grid_hidden[(grid_indices)[i]]; \
|
2015-03-23 15:29:42 -04:00
|
|
|
\
|
2017-05-10 20:14:52 +10:00
|
|
|
for (j = 0; j < gridsize - 1; ++j) { \
|
|
|
|
|
for (k = 0; k < gridsize - 1; ++k) { \
|
|
|
|
|
/* Skip hidden grid face */ \
|
|
|
|
|
if (gh && paint_is_grid_face_hidden( \
|
|
|
|
|
gh, gridsize, k, j)) \
|
|
|
|
|
{ \
|
|
|
|
|
continue; \
|
|
|
|
|
} \
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_indexbuf_add_generic_vert(&elb, offset + j * gridsize + k + 1); \
|
|
|
|
|
GWN_indexbuf_add_generic_vert(&elb, offset + j * gridsize + k); \
|
|
|
|
|
GWN_indexbuf_add_generic_vert(&elb, offset + (j + 1) * gridsize + k); \
|
2017-05-10 20:14:52 +10:00
|
|
|
\
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_indexbuf_add_generic_vert(&elb, offset + (j + 1) * gridsize + k + 1); \
|
|
|
|
|
GWN_indexbuf_add_generic_vert(&elb, offset + j * gridsize + k + 1); \
|
|
|
|
|
GWN_indexbuf_add_generic_vert(&elb, offset + (j + 1) * gridsize + k); \
|
2017-05-10 20:14:52 +10:00
|
|
|
} \
|
2015-03-23 15:29:42 -04:00
|
|
|
} \
|
2017-05-10 20:14:52 +10:00
|
|
|
\
|
|
|
|
|
offset += gridsize * gridsize; \
|
2015-03-23 15:29:42 -04:00
|
|
|
} \
|
2017-06-19 20:18:04 +10:00
|
|
|
buffer_ = GWN_indexbuf_build(&elb); \
|
2015-03-23 15:29:42 -04:00
|
|
|
} (void)0
|
2012-02-22 23:30:56 +00:00
|
|
|
/* end FILL_QUAD_BUFFER */
|
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_IndexBuf *gpu_get_grid_buffer(
|
2017-05-10 20:14:52 +10:00
|
|
|
int gridsize, unsigned *totquad, GridCommonGPUBuffer **grid_common_gpu_buffer,
|
|
|
|
|
/* remove this arg when gawain gets base-vertex support! */
|
|
|
|
|
int totgrid)
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
{
|
2012-03-14 06:32:25 +00:00
|
|
|
/* used in the FILL_QUAD_BUFFER macro */
|
2013-07-22 23:20:48 +00:00
|
|
|
BLI_bitmap * const *grid_hidden = NULL;
|
2014-04-27 00:24:11 +10:00
|
|
|
const int *grid_indices = NULL;
|
2017-05-10 20:14:52 +10:00
|
|
|
// int totgrid = 1;
|
2012-03-14 06:32:25 +00:00
|
|
|
|
Fix T47637: Multiple multires objects in Sculpt mode make blender crash.
That was a nice and funny hunt, albeit rather time consumming!
To summarize, so far code was using a static global gpu_buffer for pbvh vbo drawing
of 'grid' types (multires mostly?).
There were two issues here:
1) Global gpu buffer was assigned to GPU_PBVH_Buffers->index_buf, but then nearly no
check was done when freeing that buffer, to ensure we were not freeing the global one
(not totally sure this one was actually causing any issue, but was bad and unsafe anyway).
Was solved by adding a flag to GPU_PBVH_Buffers to indicate when we are using some
'common' buffer here, which freeing is handled separately.
2) Main issue: if several multires objects in sculpt mode with different grid size
were present simultaneously, the global gpu buffer had to be resized for each object draw
(i.e., freed and re-allocated), but then the pbvh nodes from other objects storing freed reference
to that global buffer had no way to know that it had been freed, which was causing the segfault & crash.
Was solved by getting rid of that global buffer, and instead allocating one 'grid_commmon_gpu_buffer' per pbvh.
Told ya baby, globals are *PURE EVIL*!
2016-06-02 15:57:58 +02:00
|
|
|
GridCommonGPUBuffer *gridbuff = *grid_common_gpu_buffer;
|
|
|
|
|
|
|
|
|
|
if (gridbuff == NULL) {
|
|
|
|
|
*grid_common_gpu_buffer = gridbuff = MEM_mallocN(sizeof(GridCommonGPUBuffer), __func__);
|
|
|
|
|
gridbuff->mres_buffer = NULL;
|
|
|
|
|
gridbuff->mres_prev_gridsize = -1;
|
|
|
|
|
gridbuff->mres_prev_totquad = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-09 09:30:03 +00:00
|
|
|
/* VBO is already built */
|
Fix T47637: Multiple multires objects in Sculpt mode make blender crash.
That was a nice and funny hunt, albeit rather time consumming!
To summarize, so far code was using a static global gpu_buffer for pbvh vbo drawing
of 'grid' types (multires mostly?).
There were two issues here:
1) Global gpu buffer was assigned to GPU_PBVH_Buffers->index_buf, but then nearly no
check was done when freeing that buffer, to ensure we were not freeing the global one
(not totally sure this one was actually causing any issue, but was bad and unsafe anyway).
Was solved by adding a flag to GPU_PBVH_Buffers to indicate when we are using some
'common' buffer here, which freeing is handled separately.
2) Main issue: if several multires objects in sculpt mode with different grid size
were present simultaneously, the global gpu buffer had to be resized for each object draw
(i.e., freed and re-allocated), but then the pbvh nodes from other objects storing freed reference
to that global buffer had no way to know that it had been freed, which was causing the segfault & crash.
Was solved by getting rid of that global buffer, and instead allocating one 'grid_commmon_gpu_buffer' per pbvh.
Told ya baby, globals are *PURE EVIL*!
2016-06-02 15:57:58 +02:00
|
|
|
if (gridbuff->mres_buffer && gridbuff->mres_prev_gridsize == gridsize) {
|
|
|
|
|
*totquad = gridbuff->mres_prev_totquad;
|
|
|
|
|
return gridbuff->mres_buffer;
|
2015-07-16 16:22:28 +02:00
|
|
|
}
|
|
|
|
|
/* we can't reuse old, delete the existing buffer */
|
Fix T47637: Multiple multires objects in Sculpt mode make blender crash.
That was a nice and funny hunt, albeit rather time consumming!
To summarize, so far code was using a static global gpu_buffer for pbvh vbo drawing
of 'grid' types (multires mostly?).
There were two issues here:
1) Global gpu buffer was assigned to GPU_PBVH_Buffers->index_buf, but then nearly no
check was done when freeing that buffer, to ensure we were not freeing the global one
(not totally sure this one was actually causing any issue, but was bad and unsafe anyway).
Was solved by adding a flag to GPU_PBVH_Buffers to indicate when we are using some
'common' buffer here, which freeing is handled separately.
2) Main issue: if several multires objects in sculpt mode with different grid size
were present simultaneously, the global gpu buffer had to be resized for each object draw
(i.e., freed and re-allocated), but then the pbvh nodes from other objects storing freed reference
to that global buffer had no way to know that it had been freed, which was causing the segfault & crash.
Was solved by getting rid of that global buffer, and instead allocating one 'grid_commmon_gpu_buffer' per pbvh.
Told ya baby, globals are *PURE EVIL*!
2016-06-02 15:57:58 +02:00
|
|
|
else if (gridbuff->mres_buffer) {
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_indexbuf_discard(gridbuff->mres_buffer);
|
2017-05-10 20:14:52 +10:00
|
|
|
gridbuff->mres_buffer = NULL;
|
2012-03-09 09:30:03 +00:00
|
|
|
}
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
|
2012-03-09 09:30:03 +00:00
|
|
|
/* Build new VBO */
|
2017-05-10 20:14:52 +10:00
|
|
|
*totquad = (gridsize - 1) * (gridsize - 1) * totgrid;
|
|
|
|
|
int max_vert = gridsize * gridsize * totgrid;
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
|
2017-05-10 20:14:52 +10:00
|
|
|
FILL_QUAD_BUFFER(max_vert, *totquad, gridbuff->mres_buffer);
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
|
Fix T47637: Multiple multires objects in Sculpt mode make blender crash.
That was a nice and funny hunt, albeit rather time consumming!
To summarize, so far code was using a static global gpu_buffer for pbvh vbo drawing
of 'grid' types (multires mostly?).
There were two issues here:
1) Global gpu buffer was assigned to GPU_PBVH_Buffers->index_buf, but then nearly no
check was done when freeing that buffer, to ensure we were not freeing the global one
(not totally sure this one was actually causing any issue, but was bad and unsafe anyway).
Was solved by adding a flag to GPU_PBVH_Buffers to indicate when we are using some
'common' buffer here, which freeing is handled separately.
2) Main issue: if several multires objects in sculpt mode with different grid size
were present simultaneously, the global gpu buffer had to be resized for each object draw
(i.e., freed and re-allocated), but then the pbvh nodes from other objects storing freed reference
to that global buffer had no way to know that it had been freed, which was causing the segfault & crash.
Was solved by getting rid of that global buffer, and instead allocating one 'grid_commmon_gpu_buffer' per pbvh.
Told ya baby, globals are *PURE EVIL*!
2016-06-02 15:57:58 +02:00
|
|
|
gridbuff->mres_prev_gridsize = gridsize;
|
|
|
|
|
gridbuff->mres_prev_totquad = *totquad;
|
|
|
|
|
return gridbuff->mres_buffer;
|
2012-03-09 09:30:03 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-10 20:14:52 +10:00
|
|
|
#define FILL_FAST_BUFFER() \
|
2015-07-14 16:48:23 +02:00
|
|
|
{ \
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_IndexBufBuilder elb; \
|
|
|
|
|
GWN_indexbuf_init(&elb, GWN_PRIM_TRIS, 6 * totgrid, INT_MAX); \
|
2017-05-10 20:14:52 +10:00
|
|
|
for (int i = 0; i < totgrid; i++) { \
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_indexbuf_add_generic_vert(&elb, i * gridsize * gridsize + gridsize - 1); \
|
|
|
|
|
GWN_indexbuf_add_generic_vert(&elb, i * gridsize * gridsize); \
|
|
|
|
|
GWN_indexbuf_add_generic_vert(&elb, (i + 1) * gridsize * gridsize - gridsize); \
|
|
|
|
|
GWN_indexbuf_add_generic_vert(&elb, (i + 1) * gridsize * gridsize - 1); \
|
|
|
|
|
GWN_indexbuf_add_generic_vert(&elb, i * gridsize * gridsize + gridsize - 1); \
|
|
|
|
|
GWN_indexbuf_add_generic_vert(&elb, (i + 1) * gridsize * gridsize - gridsize); \
|
2015-08-06 12:34:31 +10:00
|
|
|
} \
|
2017-06-19 20:18:04 +10:00
|
|
|
buffers->index_buf_fast = GWN_indexbuf_build(&elb); \
|
2015-07-14 16:48:23 +02:00
|
|
|
} (void)0
|
|
|
|
|
|
2017-05-11 22:03:50 +10:00
|
|
|
GPU_PBVH_Buffers *GPU_pbvh_grid_buffers_build(
|
2017-05-10 20:14:52 +10:00
|
|
|
int *grid_indices, int totgrid, BLI_bitmap **grid_hidden, int gridsize, const CCGKey *UNUSED(key),
|
Fix T47637: Multiple multires objects in Sculpt mode make blender crash.
That was a nice and funny hunt, albeit rather time consumming!
To summarize, so far code was using a static global gpu_buffer for pbvh vbo drawing
of 'grid' types (multires mostly?).
There were two issues here:
1) Global gpu buffer was assigned to GPU_PBVH_Buffers->index_buf, but then nearly no
check was done when freeing that buffer, to ensure we were not freeing the global one
(not totally sure this one was actually causing any issue, but was bad and unsafe anyway).
Was solved by adding a flag to GPU_PBVH_Buffers to indicate when we are using some
'common' buffer here, which freeing is handled separately.
2) Main issue: if several multires objects in sculpt mode with different grid size
were present simultaneously, the global gpu buffer had to be resized for each object draw
(i.e., freed and re-allocated), but then the pbvh nodes from other objects storing freed reference
to that global buffer had no way to know that it had been freed, which was causing the segfault & crash.
Was solved by getting rid of that global buffer, and instead allocating one 'grid_commmon_gpu_buffer' per pbvh.
Told ya baby, globals are *PURE EVIL*!
2016-06-02 15:57:58 +02:00
|
|
|
GridCommonGPUBuffer **grid_common_gpu_buffer)
|
2012-03-09 09:30:03 +00:00
|
|
|
{
|
2014-01-02 22:22:36 +02:00
|
|
|
GPU_PBVH_Buffers *buffers;
|
2012-03-14 06:32:25 +00:00
|
|
|
int totquad;
|
2012-05-11 08:05:47 +00:00
|
|
|
int fully_visible_totquad = (gridsize - 1) * (gridsize - 1) * totgrid;
|
2012-03-09 09:30:03 +00:00
|
|
|
|
2014-01-02 22:22:36 +02:00
|
|
|
buffers = MEM_callocN(sizeof(GPU_PBVH_Buffers), "GPU_Buffers");
|
2012-03-14 06:32:25 +00:00
|
|
|
buffers->grid_hidden = grid_hidden;
|
|
|
|
|
buffers->totgrid = totgrid;
|
|
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
buffers->show_diffuse_color = false;
|
2018-01-15 11:38:56 +01:00
|
|
|
buffers->show_mask = true;
|
2012-10-22 17:33:53 +00:00
|
|
|
|
2012-03-14 06:32:25 +00:00
|
|
|
/* Count the number of quads */
|
2014-05-05 22:21:30 +03:00
|
|
|
totquad = BKE_pbvh_count_grid_quads(grid_hidden, grid_indices, totgrid, gridsize);
|
2012-03-14 06:32:25 +00:00
|
|
|
|
2014-05-05 21:13:27 +03:00
|
|
|
/* totally hidden node, return here to avoid BufferData with zero below. */
|
|
|
|
|
if (totquad == 0)
|
|
|
|
|
return buffers;
|
|
|
|
|
|
2015-07-14 16:48:23 +02:00
|
|
|
/* create and fill indices of the fast buffer too */
|
2017-05-10 20:14:52 +10:00
|
|
|
FILL_FAST_BUFFER();
|
2015-07-14 16:48:23 +02:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (totquad == fully_visible_totquad) {
|
Fix T47637: Multiple multires objects in Sculpt mode make blender crash.
That was a nice and funny hunt, albeit rather time consumming!
To summarize, so far code was using a static global gpu_buffer for pbvh vbo drawing
of 'grid' types (multires mostly?).
There were two issues here:
1) Global gpu buffer was assigned to GPU_PBVH_Buffers->index_buf, but then nearly no
check was done when freeing that buffer, to ensure we were not freeing the global one
(not totally sure this one was actually causing any issue, but was bad and unsafe anyway).
Was solved by adding a flag to GPU_PBVH_Buffers to indicate when we are using some
'common' buffer here, which freeing is handled separately.
2) Main issue: if several multires objects in sculpt mode with different grid size
were present simultaneously, the global gpu buffer had to be resized for each object draw
(i.e., freed and re-allocated), but then the pbvh nodes from other objects storing freed reference
to that global buffer had no way to know that it had been freed, which was causing the segfault & crash.
Was solved by getting rid of that global buffer, and instead allocating one 'grid_commmon_gpu_buffer' per pbvh.
Told ya baby, globals are *PURE EVIL*!
2016-06-02 15:57:58 +02:00
|
|
|
buffers->index_buf = gpu_get_grid_buffer(
|
2017-05-10 20:14:52 +10:00
|
|
|
gridsize, &buffers->tot_quad, grid_common_gpu_buffer, totgrid);
|
2015-11-25 19:49:31 -05:00
|
|
|
buffers->has_hidden = false;
|
Fix T47637: Multiple multires objects in Sculpt mode make blender crash.
That was a nice and funny hunt, albeit rather time consumming!
To summarize, so far code was using a static global gpu_buffer for pbvh vbo drawing
of 'grid' types (multires mostly?).
There were two issues here:
1) Global gpu buffer was assigned to GPU_PBVH_Buffers->index_buf, but then nearly no
check was done when freeing that buffer, to ensure we were not freeing the global one
(not totally sure this one was actually causing any issue, but was bad and unsafe anyway).
Was solved by adding a flag to GPU_PBVH_Buffers to indicate when we are using some
'common' buffer here, which freeing is handled separately.
2) Main issue: if several multires objects in sculpt mode with different grid size
were present simultaneously, the global gpu buffer had to be resized for each object draw
(i.e., freed and re-allocated), but then the pbvh nodes from other objects storing freed reference
to that global buffer had no way to know that it had been freed, which was causing the segfault & crash.
Was solved by getting rid of that global buffer, and instead allocating one 'grid_commmon_gpu_buffer' per pbvh.
Told ya baby, globals are *PURE EVIL*!
2016-06-02 15:57:58 +02:00
|
|
|
buffers->is_index_buf_global = true;
|
2012-03-14 06:32:25 +00:00
|
|
|
}
|
2015-07-16 16:22:28 +02:00
|
|
|
else {
|
2017-05-10 20:14:52 +10:00
|
|
|
uint max_vert = totgrid * gridsize * gridsize;
|
2015-07-16 16:22:28 +02:00
|
|
|
buffers->tot_quad = totquad;
|
2012-03-14 06:32:25 +00:00
|
|
|
|
2017-05-10 20:14:52 +10:00
|
|
|
FILL_QUAD_BUFFER(max_vert, totquad, buffers->index_buf);
|
2012-03-14 06:32:25 +00:00
|
|
|
|
2017-05-10 20:14:52 +10:00
|
|
|
buffers->has_hidden = false;
|
Fix T47637: Multiple multires objects in Sculpt mode make blender crash.
That was a nice and funny hunt, albeit rather time consumming!
To summarize, so far code was using a static global gpu_buffer for pbvh vbo drawing
of 'grid' types (multires mostly?).
There were two issues here:
1) Global gpu buffer was assigned to GPU_PBVH_Buffers->index_buf, but then nearly no
check was done when freeing that buffer, to ensure we were not freeing the global one
(not totally sure this one was actually causing any issue, but was bad and unsafe anyway).
Was solved by adding a flag to GPU_PBVH_Buffers to indicate when we are using some
'common' buffer here, which freeing is handled separately.
2) Main issue: if several multires objects in sculpt mode with different grid size
were present simultaneously, the global gpu buffer had to be resized for each object draw
(i.e., freed and re-allocated), but then the pbvh nodes from other objects storing freed reference
to that global buffer had no way to know that it had been freed, which was causing the segfault & crash.
Was solved by getting rid of that global buffer, and instead allocating one 'grid_commmon_gpu_buffer' per pbvh.
Told ya baby, globals are *PURE EVIL*!
2016-06-02 15:57:58 +02:00
|
|
|
buffers->is_index_buf_global = false;
|
2012-03-14 06:32:25 +00:00
|
|
|
}
|
2012-03-09 09:30:03 +00:00
|
|
|
|
2017-05-10 20:14:52 +10:00
|
|
|
#ifdef USE_BASE_ELEM
|
2012-03-09 09:30:03 +00:00
|
|
|
/* Build coord/normal VBO */
|
2015-11-22 11:35:21 -05:00
|
|
|
if (GLEW_ARB_draw_elements_base_vertex /* 3.2 */) {
|
2015-08-03 19:08:50 +02:00
|
|
|
int i;
|
|
|
|
|
buffers->baseelemarray = MEM_mallocN(sizeof(int) * totgrid * 2, "GPU_PBVH_Buffers.baseelemarray");
|
|
|
|
|
buffers->baseindex = MEM_mallocN(sizeof(void *) * totgrid, "GPU_PBVH_Buffers.baseindex");
|
|
|
|
|
for (i = 0; i < totgrid; i++) {
|
|
|
|
|
buffers->baseelemarray[i] = buffers->tot_quad * 6;
|
|
|
|
|
buffers->baseelemarray[i + totgrid] = i * key->grid_area;
|
2015-11-22 19:46:31 +01:00
|
|
|
buffers->baseindex[i] = NULL;
|
2015-08-03 19:08:50 +02:00
|
|
|
}
|
|
|
|
|
}
|
2017-05-10 20:14:52 +10:00
|
|
|
#endif
|
2015-08-03 19:08:50 +02:00
|
|
|
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
return buffers;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-22 23:30:56 +00:00
|
|
|
#undef FILL_QUAD_BUFFER
|
|
|
|
|
|
2012-12-30 18:24:54 +00:00
|
|
|
/* Output a BMVert into a VertexBufferFormat array
|
|
|
|
|
*
|
|
|
|
|
* The vertex is skipped if hidden, otherwise the output goes into
|
|
|
|
|
* index '*v_index' in the 'vert_data' array and '*v_index' is
|
|
|
|
|
* incremented.
|
|
|
|
|
*/
|
2017-05-10 20:14:52 +10:00
|
|
|
static void gpu_bmesh_vert_to_buffer_copy__gwn(
|
|
|
|
|
BMVert *v,
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vert_buf,
|
2017-05-10 20:14:52 +10:00
|
|
|
int *v_index,
|
|
|
|
|
const float fno[3],
|
|
|
|
|
const float *fmask,
|
|
|
|
|
const int cd_vert_mask_offset,
|
2018-01-15 13:55:52 +01:00
|
|
|
const float diffuse_color[4],
|
|
|
|
|
const bool show_mask)
|
2012-12-30 18:24:54 +00:00
|
|
|
{
|
|
|
|
|
if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN)) {
|
2013-05-02 06:09:05 +00:00
|
|
|
|
2012-12-30 18:24:54 +00:00
|
|
|
/* Set coord, normal, and mask */
|
2018-03-19 18:09:00 -03:00
|
|
|
GWN_vertbuf_attr_set(vert_buf, g_vbo_id.pos, *v_index, v->co);
|
2013-05-02 06:09:05 +00:00
|
|
|
|
2017-05-10 20:14:52 +10:00
|
|
|
{
|
|
|
|
|
short no_short[3];
|
|
|
|
|
normal_float_to_short_v3(no_short, fno ? fno : v->no);
|
2018-03-19 18:09:00 -03:00
|
|
|
GWN_vertbuf_attr_set(vert_buf, g_vbo_id.nor, *v_index, no_short);
|
2017-05-10 20:14:52 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
uchar color_ub[3];
|
2018-01-15 13:55:52 +01:00
|
|
|
float effective_mask;
|
|
|
|
|
if (show_mask) {
|
|
|
|
|
effective_mask = fmask ? *fmask
|
|
|
|
|
: BM_ELEM_CD_GET_FLOAT(v, cd_vert_mask_offset);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
effective_mask = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 20:14:52 +10:00
|
|
|
gpu_color_from_mask_copy(
|
2018-01-15 13:55:52 +01:00
|
|
|
effective_mask,
|
2017-05-10 20:14:52 +10:00
|
|
|
diffuse_color,
|
|
|
|
|
color_ub);
|
2018-03-19 18:09:00 -03:00
|
|
|
GWN_vertbuf_attr_set(vert_buf, g_vbo_id.col, *v_index, color_ub);
|
2017-05-10 20:14:52 +10:00
|
|
|
}
|
2012-12-30 18:24:54 +00:00
|
|
|
|
|
|
|
|
/* Assign index for use in the triangle index buffer */
|
2013-08-24 11:46:08 +00:00
|
|
|
/* note: caller must set: bm->elem_index_dirty |= BM_VERT; */
|
2012-12-30 18:24:54 +00:00
|
|
|
BM_elem_index_set(v, (*v_index)); /* set_dirty! */
|
|
|
|
|
|
|
|
|
|
(*v_index)++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return the total number of vertices that don't have BM_ELEM_HIDDEN set */
|
2013-08-25 20:03:45 +00:00
|
|
|
static int gpu_bmesh_vert_visible_count(GSet *bm_unique_verts,
|
|
|
|
|
GSet *bm_other_verts)
|
2012-12-30 18:24:54 +00:00
|
|
|
{
|
2013-08-25 20:03:45 +00:00
|
|
|
GSetIterator gs_iter;
|
2012-12-30 18:24:54 +00:00
|
|
|
int totvert = 0;
|
|
|
|
|
|
2013-08-25 20:03:45 +00:00
|
|
|
GSET_ITER (gs_iter, bm_unique_verts) {
|
|
|
|
|
BMVert *v = BLI_gsetIterator_getKey(&gs_iter);
|
2012-12-30 18:24:54 +00:00
|
|
|
if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN))
|
|
|
|
|
totvert++;
|
|
|
|
|
}
|
2013-08-25 20:03:45 +00:00
|
|
|
GSET_ITER (gs_iter, bm_other_verts) {
|
|
|
|
|
BMVert *v = BLI_gsetIterator_getKey(&gs_iter);
|
2012-12-30 18:24:54 +00:00
|
|
|
if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN))
|
|
|
|
|
totvert++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return totvert;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return the total number of visible faces */
|
2014-04-08 14:45:48 +10:00
|
|
|
static int gpu_bmesh_face_visible_count(GSet *bm_faces)
|
2012-12-30 18:24:54 +00:00
|
|
|
{
|
2014-04-08 14:45:48 +10:00
|
|
|
GSetIterator gh_iter;
|
2012-12-30 18:24:54 +00:00
|
|
|
int totface = 0;
|
|
|
|
|
|
2014-04-08 14:45:48 +10:00
|
|
|
GSET_ITER (gh_iter, bm_faces) {
|
|
|
|
|
BMFace *f = BLI_gsetIterator_getKey(&gh_iter);
|
2012-12-30 18:24:54 +00:00
|
|
|
|
2014-04-10 22:31:39 +03:00
|
|
|
if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN))
|
2012-12-30 18:24:54 +00:00
|
|
|
totface++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return totface;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Creates a vertex buffer (coordinate, normal, color) and, if smooth
|
2013-06-06 06:02:46 +00:00
|
|
|
* shading, an element index buffer. */
|
2017-05-11 22:03:50 +10:00
|
|
|
void GPU_pbvh_bmesh_buffers_update(
|
2017-05-10 20:14:52 +10:00
|
|
|
GPU_PBVH_Buffers *buffers,
|
|
|
|
|
BMesh *bm,
|
|
|
|
|
GSet *bm_faces,
|
|
|
|
|
GSet *bm_unique_verts,
|
|
|
|
|
GSet *bm_other_verts,
|
2018-01-12 17:35:26 +01:00
|
|
|
const int update_flags)
|
2012-12-30 18:24:54 +00:00
|
|
|
{
|
2018-01-12 17:35:26 +01:00
|
|
|
const bool show_diffuse_color = (update_flags & GPU_PBVH_BUFFERS_SHOW_DIFFUSE_COLOR) != 0;
|
2018-01-15 11:38:56 +01:00
|
|
|
const bool show_mask = (update_flags & GPU_PBVH_BUFFERS_SHOW_MASK) != 0;
|
2012-12-30 18:24:54 +00:00
|
|
|
int tottri, totvert, maxvert = 0;
|
2014-04-02 17:33:47 +03:00
|
|
|
float diffuse_color[4] = {0.8f, 0.8f, 0.8f, 1.0f};
|
2012-12-30 18:24:54 +00:00
|
|
|
|
2013-05-02 06:09:05 +00:00
|
|
|
/* TODO, make mask layer optional for bmesh buffer */
|
|
|
|
|
const int cd_vert_mask_offset = CustomData_get_offset(&bm->vdata, CD_PAINT_MASK);
|
|
|
|
|
|
2014-04-02 18:56:19 +03:00
|
|
|
buffers->show_diffuse_color = show_diffuse_color;
|
2018-01-15 11:38:56 +01:00
|
|
|
buffers->show_mask = show_mask;
|
2014-04-02 18:56:19 +03:00
|
|
|
|
2012-12-30 18:24:54 +00:00
|
|
|
/* Count visible triangles */
|
|
|
|
|
tottri = gpu_bmesh_face_visible_count(bm_faces);
|
|
|
|
|
|
|
|
|
|
if (buffers->smooth) {
|
2018-06-26 11:38:27 +02:00
|
|
|
/* Smooth needs to recreate index buffer, so we have to invalidate the batch. */
|
|
|
|
|
GWN_BATCH_DISCARD_SAFE(buffers->triangles);
|
2012-12-30 18:24:54 +00:00
|
|
|
/* Count visible vertices */
|
|
|
|
|
totvert = gpu_bmesh_vert_visible_count(bm_unique_verts, bm_other_verts);
|
|
|
|
|
}
|
2018-06-26 11:38:27 +02:00
|
|
|
else {
|
2012-12-30 18:24:54 +00:00
|
|
|
totvert = tottri * 3;
|
2018-06-26 11:38:27 +02:00
|
|
|
}
|
2012-12-30 18:24:54 +00:00
|
|
|
|
2014-04-02 01:40:05 +03:00
|
|
|
if (!tottri) {
|
|
|
|
|
buffers->tot_tri = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
if (show_diffuse_color) {
|
2014-04-02 17:33:47 +03:00
|
|
|
/* due to dynamic nature of dyntopo, only get first material */
|
2014-04-08 14:45:48 +10:00
|
|
|
GSetIterator gs_iter;
|
2014-04-02 18:56:19 +03:00
|
|
|
BMFace *f;
|
2014-04-08 14:45:48 +10:00
|
|
|
BLI_gsetIterator_init(&gs_iter, bm_faces);
|
|
|
|
|
f = BLI_gsetIterator_getKey(&gs_iter);
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
gpu_material_diffuse_get(f->mat_nr + 1, diffuse_color);
|
2014-04-02 18:56:19 +03:00
|
|
|
}
|
|
|
|
|
|
2014-04-03 04:03:46 +03:00
|
|
|
copy_v4_v4(buffers->diffuse_color, diffuse_color);
|
|
|
|
|
|
2012-12-30 18:24:54 +00:00
|
|
|
/* Fill vertex buffer */
|
2018-03-19 18:09:00 -03:00
|
|
|
if (gpu_pbvh_vert_buf_data_set(buffers, totvert)) {
|
2012-12-30 18:24:54 +00:00
|
|
|
int v_index = 0;
|
|
|
|
|
|
|
|
|
|
if (buffers->smooth) {
|
2013-08-25 20:03:45 +00:00
|
|
|
GSetIterator gs_iter;
|
|
|
|
|
|
2012-12-30 18:24:54 +00:00
|
|
|
/* Vertices get an index assigned for use in the triangle
|
2013-06-06 06:02:46 +00:00
|
|
|
* index buffer */
|
2012-12-30 18:24:54 +00:00
|
|
|
bm->elem_index_dirty |= BM_VERT;
|
|
|
|
|
|
2013-08-25 20:03:45 +00:00
|
|
|
GSET_ITER (gs_iter, bm_unique_verts) {
|
2017-05-10 20:14:52 +10:00
|
|
|
gpu_bmesh_vert_to_buffer_copy__gwn(
|
|
|
|
|
BLI_gsetIterator_getKey(&gs_iter),
|
2018-03-19 18:09:00 -03:00
|
|
|
buffers->vert_buf, &v_index, NULL, NULL,
|
2018-01-15 13:55:52 +01:00
|
|
|
cd_vert_mask_offset, diffuse_color,
|
|
|
|
|
show_mask);
|
2012-12-30 18:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-25 20:03:45 +00:00
|
|
|
GSET_ITER (gs_iter, bm_other_verts) {
|
2017-05-10 20:14:52 +10:00
|
|
|
gpu_bmesh_vert_to_buffer_copy__gwn(
|
|
|
|
|
BLI_gsetIterator_getKey(&gs_iter),
|
2018-03-19 18:09:00 -03:00
|
|
|
buffers->vert_buf, &v_index, NULL, NULL,
|
2018-01-15 13:55:52 +01:00
|
|
|
cd_vert_mask_offset, diffuse_color,
|
|
|
|
|
show_mask);
|
2012-12-30 18:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
maxvert = v_index;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2014-04-08 14:45:48 +10:00
|
|
|
GSetIterator gs_iter;
|
2013-08-25 20:03:45 +00:00
|
|
|
|
2014-04-08 14:45:48 +10:00
|
|
|
GSET_ITER (gs_iter, bm_faces) {
|
|
|
|
|
BMFace *f = BLI_gsetIterator_getKey(&gs_iter);
|
2012-12-30 18:24:54 +00:00
|
|
|
|
|
|
|
|
BLI_assert(f->len == 3);
|
|
|
|
|
|
2014-04-11 07:51:14 +10:00
|
|
|
if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
|
2012-12-30 18:24:54 +00:00
|
|
|
BMVert *v[3];
|
|
|
|
|
float fmask = 0;
|
|
|
|
|
int i;
|
|
|
|
|
|
2015-03-23 15:29:42 -04:00
|
|
|
#if 0
|
2018-04-19 08:18:16 +02:00
|
|
|
BM_iter_as_array(bm, BM_VERTS_OF_FACE, f, (void **)v, 3);
|
2015-03-23 15:29:42 -04:00
|
|
|
#endif
|
2013-01-16 21:09:54 +00:00
|
|
|
BM_face_as_array_vert_tri(f, v);
|
2012-12-30 18:24:54 +00:00
|
|
|
|
|
|
|
|
/* Average mask value */
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
2013-05-02 06:09:05 +00:00
|
|
|
fmask += BM_ELEM_CD_GET_FLOAT(v[i], cd_vert_mask_offset);
|
2012-12-30 18:24:54 +00:00
|
|
|
}
|
|
|
|
|
fmask /= 3.0f;
|
2018-06-04 09:09:12 +02:00
|
|
|
|
2012-12-30 18:24:54 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2017-05-10 20:14:52 +10:00
|
|
|
gpu_bmesh_vert_to_buffer_copy__gwn(
|
2018-03-19 18:09:00 -03:00
|
|
|
v[i], buffers->vert_buf,
|
2017-05-10 20:14:52 +10:00
|
|
|
&v_index, f->no, &fmask,
|
2018-01-15 13:55:52 +01:00
|
|
|
cd_vert_mask_offset, diffuse_color,
|
|
|
|
|
show_mask);
|
2012-12-30 18:24:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buffers->tot_tri = tottri;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-24 11:46:08 +00:00
|
|
|
/* gpu_bmesh_vert_to_buffer_copy sets dirty index values */
|
|
|
|
|
bm->elem_index_dirty |= BM_VERT;
|
2012-12-30 18:24:54 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Memory map failed */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (buffers->smooth) {
|
2017-05-10 20:14:52 +10:00
|
|
|
/* Fill the triangle buffer */
|
|
|
|
|
buffers->index_buf = NULL;
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_IndexBufBuilder elb;
|
|
|
|
|
GWN_indexbuf_init(&elb, GWN_PRIM_TRIS, tottri, maxvert);
|
2012-12-30 18:24:54 +00:00
|
|
|
|
|
|
|
|
/* Initialize triangle index buffer */
|
Fix T47637: Multiple multires objects in Sculpt mode make blender crash.
That was a nice and funny hunt, albeit rather time consumming!
To summarize, so far code was using a static global gpu_buffer for pbvh vbo drawing
of 'grid' types (multires mostly?).
There were two issues here:
1) Global gpu buffer was assigned to GPU_PBVH_Buffers->index_buf, but then nearly no
check was done when freeing that buffer, to ensure we were not freeing the global one
(not totally sure this one was actually causing any issue, but was bad and unsafe anyway).
Was solved by adding a flag to GPU_PBVH_Buffers to indicate when we are using some
'common' buffer here, which freeing is handled separately.
2) Main issue: if several multires objects in sculpt mode with different grid size
were present simultaneously, the global gpu buffer had to be resized for each object draw
(i.e., freed and re-allocated), but then the pbvh nodes from other objects storing freed reference
to that global buffer had no way to know that it had been freed, which was causing the segfault & crash.
Was solved by getting rid of that global buffer, and instead allocating one 'grid_commmon_gpu_buffer' per pbvh.
Told ya baby, globals are *PURE EVIL*!
2016-06-02 15:57:58 +02:00
|
|
|
buffers->is_index_buf_global = false;
|
2012-12-30 18:24:54 +00:00
|
|
|
|
|
|
|
|
/* Fill triangle index buffer */
|
2017-05-10 20:14:52 +10:00
|
|
|
|
|
|
|
|
{
|
2014-04-08 14:45:48 +10:00
|
|
|
GSetIterator gs_iter;
|
2012-12-30 18:24:54 +00:00
|
|
|
|
2014-04-08 14:45:48 +10:00
|
|
|
GSET_ITER (gs_iter, bm_faces) {
|
|
|
|
|
BMFace *f = BLI_gsetIterator_getKey(&gs_iter);
|
2012-12-30 18:24:54 +00:00
|
|
|
|
2014-04-11 07:51:14 +10:00
|
|
|
if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
|
2018-06-26 11:41:59 +02:00
|
|
|
BMVert *v[3];
|
2013-01-16 21:09:54 +00:00
|
|
|
|
2018-06-26 11:41:59 +02:00
|
|
|
BM_face_as_array_vert_tri(f, v);
|
|
|
|
|
GWN_indexbuf_add_tri_verts(
|
|
|
|
|
&elb, BM_elem_index_get(v[0]), BM_elem_index_get(v[1]), BM_elem_index_get(v[2]));
|
2012-12-30 18:24:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buffers->tot_tri = tottri;
|
2017-05-10 20:14:52 +10:00
|
|
|
|
2018-03-19 18:09:00 -03:00
|
|
|
if (buffers->index_buf == NULL) {
|
|
|
|
|
buffers->index_buf = GWN_indexbuf_build(&elb);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
GWN_indexbuf_build_in_place(&elb, buffers->index_buf);
|
|
|
|
|
}
|
2012-12-30 18:24:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
2015-07-16 16:22:28 +02:00
|
|
|
else if (buffers->index_buf) {
|
Fix T47637: Multiple multires objects in Sculpt mode make blender crash.
That was a nice and funny hunt, albeit rather time consumming!
To summarize, so far code was using a static global gpu_buffer for pbvh vbo drawing
of 'grid' types (multires mostly?).
There were two issues here:
1) Global gpu buffer was assigned to GPU_PBVH_Buffers->index_buf, but then nearly no
check was done when freeing that buffer, to ensure we were not freeing the global one
(not totally sure this one was actually causing any issue, but was bad and unsafe anyway).
Was solved by adding a flag to GPU_PBVH_Buffers to indicate when we are using some
'common' buffer here, which freeing is handled separately.
2) Main issue: if several multires objects in sculpt mode with different grid size
were present simultaneously, the global gpu buffer had to be resized for each object draw
(i.e., freed and re-allocated), but then the pbvh nodes from other objects storing freed reference
to that global buffer had no way to know that it had been freed, which was causing the segfault & crash.
Was solved by getting rid of that global buffer, and instead allocating one 'grid_commmon_gpu_buffer' per pbvh.
Told ya baby, globals are *PURE EVIL*!
2016-06-02 15:57:58 +02:00
|
|
|
if (!buffers->is_index_buf_global) {
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_INDEXBUF_DISCARD_SAFE(buffers->index_buf);
|
Fix T47637: Multiple multires objects in Sculpt mode make blender crash.
That was a nice and funny hunt, albeit rather time consumming!
To summarize, so far code was using a static global gpu_buffer for pbvh vbo drawing
of 'grid' types (multires mostly?).
There were two issues here:
1) Global gpu buffer was assigned to GPU_PBVH_Buffers->index_buf, but then nearly no
check was done when freeing that buffer, to ensure we were not freeing the global one
(not totally sure this one was actually causing any issue, but was bad and unsafe anyway).
Was solved by adding a flag to GPU_PBVH_Buffers to indicate when we are using some
'common' buffer here, which freeing is handled separately.
2) Main issue: if several multires objects in sculpt mode with different grid size
were present simultaneously, the global gpu buffer had to be resized for each object draw
(i.e., freed and re-allocated), but then the pbvh nodes from other objects storing freed reference
to that global buffer had no way to know that it had been freed, which was causing the segfault & crash.
Was solved by getting rid of that global buffer, and instead allocating one 'grid_commmon_gpu_buffer' per pbvh.
Told ya baby, globals are *PURE EVIL*!
2016-06-02 15:57:58 +02:00
|
|
|
}
|
|
|
|
|
buffers->index_buf = NULL;
|
|
|
|
|
buffers->is_index_buf_global = false;
|
2015-07-16 16:22:28 +02:00
|
|
|
}
|
2017-05-10 20:14:52 +10:00
|
|
|
|
|
|
|
|
gpu_pbvh_batch_init(buffers);
|
2012-12-30 18:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-11 22:03:50 +10:00
|
|
|
GPU_PBVH_Buffers *GPU_pbvh_bmesh_buffers_build(bool smooth_shading)
|
2012-12-30 18:24:54 +00:00
|
|
|
{
|
2014-01-02 22:22:36 +02:00
|
|
|
GPU_PBVH_Buffers *buffers;
|
2012-12-30 18:24:54 +00:00
|
|
|
|
2014-01-02 22:22:36 +02:00
|
|
|
buffers = MEM_callocN(sizeof(GPU_PBVH_Buffers), "GPU_Buffers");
|
2014-04-01 11:34:00 +11:00
|
|
|
buffers->use_bmesh = true;
|
2012-12-30 18:24:54 +00:00
|
|
|
buffers->smooth = smooth_shading;
|
2014-04-02 18:56:19 +03:00
|
|
|
buffers->show_diffuse_color = false;
|
2018-01-15 11:38:56 +01:00
|
|
|
buffers->show_mask = true;
|
2012-12-30 18:24:54 +00:00
|
|
|
|
|
|
|
|
return buffers;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *GPU_pbvh_buffers_batch_get(GPU_PBVH_Buffers *buffers, bool fast)
|
2017-05-11 21:21:59 +10:00
|
|
|
{
|
|
|
|
|
return (fast && buffers->triangles_fast) ?
|
|
|
|
|
buffers->triangles_fast : buffers->triangles;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-08 14:45:48 +10:00
|
|
|
bool GPU_pbvh_buffers_diffuse_changed(GPU_PBVH_Buffers *buffers, GSet *bm_faces, bool show_diffuse_color)
|
2012-10-22 17:33:53 +00:00
|
|
|
{
|
|
|
|
|
float diffuse_color[4];
|
|
|
|
|
|
|
|
|
|
if (buffers->show_diffuse_color != show_diffuse_color)
|
2014-04-01 11:34:00 +11:00
|
|
|
return true;
|
2014-04-02 17:33:47 +03:00
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
if (buffers->show_diffuse_color == false)
|
2014-04-01 11:34:00 +11:00
|
|
|
return false;
|
2012-10-22 17:33:53 +00:00
|
|
|
|
2015-07-17 03:36:03 +10:00
|
|
|
if (buffers->looptri) {
|
|
|
|
|
const MLoopTri *lt = &buffers->looptri[buffers->face_indices[0]];
|
|
|
|
|
const MPoly *mp = &buffers->mpoly[lt->poly];
|
2012-10-22 17:33:53 +00:00
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
gpu_material_diffuse_get(mp->mat_nr + 1, diffuse_color);
|
2012-10-22 17:33:53 +00:00
|
|
|
}
|
2014-04-02 18:56:19 +03:00
|
|
|
else if (buffers->use_bmesh) {
|
2015-03-23 15:29:42 -04:00
|
|
|
/* due to dynamic nature of dyntopo, only get first material */
|
2018-02-15 23:36:11 +11:00
|
|
|
if (BLI_gset_len(bm_faces) > 0) {
|
2014-08-07 14:57:59 +02:00
|
|
|
GSetIterator gs_iter;
|
|
|
|
|
BMFace *f;
|
|
|
|
|
|
|
|
|
|
BLI_gsetIterator_init(&gs_iter, bm_faces);
|
|
|
|
|
f = BLI_gsetIterator_getKey(&gs_iter);
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
gpu_material_diffuse_get(f->mat_nr + 1, diffuse_color);
|
2014-08-07 14:57:59 +02:00
|
|
|
}
|
2014-08-13 10:38:08 +10:00
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-04-02 18:56:19 +03:00
|
|
|
}
|
2012-10-22 17:33:53 +00:00
|
|
|
else {
|
|
|
|
|
const DMFlagMat *flags = &buffers->grid_flag_mats[buffers->grid_indices[0]];
|
|
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
gpu_material_diffuse_get(flags->mat_nr + 1, diffuse_color);
|
2012-10-22 17:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-13 10:38:08 +10:00
|
|
|
return !equals_v3v3(diffuse_color, buffers->diffuse_color);
|
2012-10-22 17:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-15 11:38:56 +01:00
|
|
|
bool GPU_pbvh_buffers_mask_changed(GPU_PBVH_Buffers *buffers, bool show_mask)
|
|
|
|
|
{
|
|
|
|
|
return (buffers->show_mask != show_mask);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-11 22:03:50 +10:00
|
|
|
void GPU_pbvh_buffers_free(GPU_PBVH_Buffers *buffers)
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
{
|
2012-03-24 06:38:07 +00:00
|
|
|
if (buffers) {
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_BATCH_DISCARD_SAFE(buffers->triangles);
|
|
|
|
|
GWN_BATCH_DISCARD_SAFE(buffers->triangles_fast);
|
2017-05-10 20:14:52 +10:00
|
|
|
if (!buffers->is_index_buf_global) {
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_INDEXBUF_DISCARD_SAFE(buffers->index_buf);
|
2017-05-10 20:14:52 +10:00
|
|
|
}
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_INDEXBUF_DISCARD_SAFE(buffers->index_buf_fast);
|
2018-01-19 19:35:27 +11:00
|
|
|
GWN_VERTBUF_DISCARD_SAFE(buffers->vert_buf);
|
2017-05-10 20:14:52 +10:00
|
|
|
|
|
|
|
|
#ifdef USE_BASE_ELEM
|
2015-08-03 19:08:50 +02:00
|
|
|
if (buffers->baseelemarray)
|
|
|
|
|
MEM_freeN(buffers->baseelemarray);
|
|
|
|
|
if (buffers->baseindex)
|
|
|
|
|
MEM_freeN(buffers->baseindex);
|
2017-05-10 20:14:52 +10:00
|
|
|
#endif
|
== GPU Buffers ==
This patch attempts to clean up and document the GPU buffers
code. There are a few bug fixes as well.
Patch reviewed here: http://codereview.appspot.com/4631052/
Summary:
* Bugfix: make GPU_buffer_copy_normal convert from shorts to floats
correctly, also fixed the use of cached face normal CustomData.
* Bugfix: changed the `mat_nr' field of GPUBufferMaterial from char to
short.
* Changed color buffer setup to not alloc a temporary copy of color
data, just passes the MCol data in directly.
* Changed the GPU buffer pool code to make clearer what operates
specifically on the global pool.
* Lots of refactoring for GPU_drawobject_new; should operate mostly
the same (except got rid of one unecessary allocation), just split
into more functions and without macros now.
* Converted some #defines into enumerations.
* Made some stuff private, pulled out of header file.
* Deleted unused function GPU_buffer_pool_free_unused().
* Removed GPU_interleaved_setup and related #defines. (I think this
was used for editmode VBOs, but those were disabled.)
* Added lots of comments.
* Added a few comments in the code signed `--nicholas' to note places
where I am unsure about design or usage, would be good to address
these better.
* Code formatting changed to be more consistent with the rest of
Blender.
* Renamed some fields and variables to be more consistent with
Blender's naming conventions.
* Renamed some fields and variables to use more descriptive names,
e.g. renamed `redir' to `mat_orig_to_new'.
* Removed print outs with DEBUG_VBO -- don't feel too strongly about
this one, just not used elsewhere in Blender, could be easily added
back if others disagree though.
* Moved the PBVH drawing code down to the bottom of the file, before
was sitting in the middle of the other VBO code
2011-07-08 19:58:02 +00:00
|
|
|
|
|
|
|
|
MEM_freeN(buffers);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-30 23:42:58 +03:00
|
|
|
|
2017-05-11 22:03:50 +10:00
|
|
|
void GPU_pbvh_multires_buffers_free(GridCommonGPUBuffer **grid_common_gpu_buffer)
|
Fix T47637: Multiple multires objects in Sculpt mode make blender crash.
That was a nice and funny hunt, albeit rather time consumming!
To summarize, so far code was using a static global gpu_buffer for pbvh vbo drawing
of 'grid' types (multires mostly?).
There were two issues here:
1) Global gpu buffer was assigned to GPU_PBVH_Buffers->index_buf, but then nearly no
check was done when freeing that buffer, to ensure we were not freeing the global one
(not totally sure this one was actually causing any issue, but was bad and unsafe anyway).
Was solved by adding a flag to GPU_PBVH_Buffers to indicate when we are using some
'common' buffer here, which freeing is handled separately.
2) Main issue: if several multires objects in sculpt mode with different grid size
were present simultaneously, the global gpu buffer had to be resized for each object draw
(i.e., freed and re-allocated), but then the pbvh nodes from other objects storing freed reference
to that global buffer had no way to know that it had been freed, which was causing the segfault & crash.
Was solved by getting rid of that global buffer, and instead allocating one 'grid_commmon_gpu_buffer' per pbvh.
Told ya baby, globals are *PURE EVIL*!
2016-06-02 15:57:58 +02:00
|
|
|
{
|
|
|
|
|
GridCommonGPUBuffer *gridbuff = *grid_common_gpu_buffer;
|
|
|
|
|
|
|
|
|
|
if (gridbuff) {
|
|
|
|
|
if (gridbuff->mres_buffer) {
|
|
|
|
|
BLI_mutex_lock(&buffer_mutex);
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_INDEXBUF_DISCARD_SAFE(gridbuff->mres_buffer);
|
Fix T47637: Multiple multires objects in Sculpt mode make blender crash.
That was a nice and funny hunt, albeit rather time consumming!
To summarize, so far code was using a static global gpu_buffer for pbvh vbo drawing
of 'grid' types (multires mostly?).
There were two issues here:
1) Global gpu buffer was assigned to GPU_PBVH_Buffers->index_buf, but then nearly no
check was done when freeing that buffer, to ensure we were not freeing the global one
(not totally sure this one was actually causing any issue, but was bad and unsafe anyway).
Was solved by adding a flag to GPU_PBVH_Buffers to indicate when we are using some
'common' buffer here, which freeing is handled separately.
2) Main issue: if several multires objects in sculpt mode with different grid size
were present simultaneously, the global gpu buffer had to be resized for each object draw
(i.e., freed and re-allocated), but then the pbvh nodes from other objects storing freed reference
to that global buffer had no way to know that it had been freed, which was causing the segfault & crash.
Was solved by getting rid of that global buffer, and instead allocating one 'grid_commmon_gpu_buffer' per pbvh.
Told ya baby, globals are *PURE EVIL*!
2016-06-02 15:57:58 +02:00
|
|
|
BLI_mutex_unlock(&buffer_mutex);
|
|
|
|
|
}
|
|
|
|
|
MEM_freeN(gridbuff);
|
|
|
|
|
*grid_common_gpu_buffer = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-30 23:42:58 +03:00
|
|
|
|
|
|
|
|
/* debug function, draws the pbvh BB */
|
2017-05-11 22:15:58 +10:00
|
|
|
void GPU_pbvh_BB_draw(float min[3], float max[3], bool leaf, unsigned int pos)
|
2014-04-30 23:42:58 +03:00
|
|
|
{
|
|
|
|
|
if (leaf)
|
2017-03-02 21:40:13 -05:00
|
|
|
immUniformColor4f(0.0, 1.0, 0.0, 0.5);
|
2014-04-30 23:42:58 +03:00
|
|
|
else
|
2017-03-02 21:40:13 -05:00
|
|
|
immUniformColor4f(1.0, 0.0, 0.0, 0.5);
|
2014-04-30 23:42:58 +03:00
|
|
|
|
2017-03-02 21:40:13 -05:00
|
|
|
/* TODO(merwin): revisit this after we have mutable VertexBuffers
|
|
|
|
|
* could keep a static batch & index buffer, change the VBO contents per draw
|
|
|
|
|
*/
|
2014-04-30 23:42:58 +03:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
immBegin(GWN_PRIM_LINES, 24);
|
2014-04-30 23:42:58 +03:00
|
|
|
|
2017-03-02 21:40:13 -05:00
|
|
|
/* top */
|
|
|
|
|
immVertex3f(pos, min[0], min[1], max[2]);
|
|
|
|
|
immVertex3f(pos, min[0], max[1], max[2]);
|
|
|
|
|
|
|
|
|
|
immVertex3f(pos, min[0], max[1], max[2]);
|
|
|
|
|
immVertex3f(pos, max[0], max[1], max[2]);
|
|
|
|
|
|
|
|
|
|
immVertex3f(pos, max[0], max[1], max[2]);
|
|
|
|
|
immVertex3f(pos, max[0], min[1], max[2]);
|
|
|
|
|
|
|
|
|
|
immVertex3f(pos, max[0], min[1], max[2]);
|
|
|
|
|
immVertex3f(pos, min[0], min[1], max[2]);
|
|
|
|
|
|
|
|
|
|
/* bottom */
|
|
|
|
|
immVertex3f(pos, min[0], min[1], min[2]);
|
|
|
|
|
immVertex3f(pos, min[0], max[1], min[2]);
|
|
|
|
|
|
|
|
|
|
immVertex3f(pos, min[0], max[1], min[2]);
|
|
|
|
|
immVertex3f(pos, max[0], max[1], min[2]);
|
|
|
|
|
|
|
|
|
|
immVertex3f(pos, max[0], max[1], min[2]);
|
|
|
|
|
immVertex3f(pos, max[0], min[1], min[2]);
|
|
|
|
|
|
|
|
|
|
immVertex3f(pos, max[0], min[1], min[2]);
|
|
|
|
|
immVertex3f(pos, min[0], min[1], min[2]);
|
|
|
|
|
|
|
|
|
|
/* sides */
|
|
|
|
|
immVertex3f(pos, min[0], min[1], min[2]);
|
|
|
|
|
immVertex3f(pos, min[0], min[1], max[2]);
|
|
|
|
|
|
|
|
|
|
immVertex3f(pos, min[0], max[1], min[2]);
|
|
|
|
|
immVertex3f(pos, min[0], max[1], max[2]);
|
|
|
|
|
|
|
|
|
|
immVertex3f(pos, max[0], max[1], min[2]);
|
|
|
|
|
immVertex3f(pos, max[0], max[1], max[2]);
|
|
|
|
|
|
|
|
|
|
immVertex3f(pos, max[0], min[1], min[2]);
|
|
|
|
|
immVertex3f(pos, max[0], min[1], max[2]);
|
|
|
|
|
|
|
|
|
|
immEnd();
|
2014-04-30 23:42:58 +03:00
|
|
|
}
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
|
|
|
|
|
void GPU_pbvh_fix_linking()
|
|
|
|
|
{
|
|
|
|
|
}
|