2017-03-12 21:16:03 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright 2016, Blender Foundation.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Blender Institute
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** \file blender/draw/modes/particle_mode.c
|
|
|
|
|
* \ingroup draw
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "DRW_engine.h"
|
|
|
|
|
#include "DRW_render.h"
|
|
|
|
|
|
2018-05-08 17:11:42 +02:00
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_particle_types.h"
|
|
|
|
|
|
|
|
|
|
#include "BKE_particle.h"
|
|
|
|
|
#include "BKE_pointcache.h"
|
|
|
|
|
|
2017-03-12 21:16:03 +01:00
|
|
|
#include "GPU_shader.h"
|
2018-05-08 17:11:42 +02:00
|
|
|
#include "GPU_batch.h"
|
2017-03-12 21:16:03 +01:00
|
|
|
|
|
|
|
|
#include "draw_common.h"
|
|
|
|
|
|
|
|
|
|
#include "draw_mode_engines.h"
|
|
|
|
|
|
2018-05-08 17:11:42 +02:00
|
|
|
#include "ED_particle.h"
|
|
|
|
|
|
|
|
|
|
#include "DEG_depsgraph_query.h"
|
|
|
|
|
|
|
|
|
|
#include "draw_cache_impl.h"
|
|
|
|
|
|
|
|
|
|
extern char datatoc_particle_vert_glsl[];
|
|
|
|
|
extern char datatoc_particle_strand_frag_glsl[];
|
|
|
|
|
|
2017-03-12 21:16:03 +01:00
|
|
|
/* *********** LISTS *********** */
|
|
|
|
|
|
|
|
|
|
typedef struct PARTICLE_PassList {
|
2018-05-08 17:11:42 +02:00
|
|
|
struct DRWPass *hair_pass;
|
2017-03-12 21:16:03 +01:00
|
|
|
} PARTICLE_PassList;
|
|
|
|
|
|
|
|
|
|
typedef struct PARTICLE_FramebufferList {
|
2017-03-13 11:39:41 +01:00
|
|
|
struct GPUFrameBuffer *fb;
|
2017-03-12 21:16:03 +01:00
|
|
|
} PARTICLE_FramebufferList;
|
|
|
|
|
|
|
|
|
|
typedef struct PARTICLE_TextureList {
|
2017-03-13 11:39:41 +01:00
|
|
|
struct GPUTexture *texture;
|
2017-03-12 21:16:03 +01:00
|
|
|
} PARTICLE_TextureList;
|
|
|
|
|
|
|
|
|
|
typedef struct PARTICLE_StorageList {
|
2017-03-13 11:39:41 +01:00
|
|
|
struct CustomStruct *block;
|
2017-04-29 16:52:12 +10:00
|
|
|
struct PARTICLE_PrivateData *g_data;
|
2017-03-12 21:16:03 +01:00
|
|
|
} PARTICLE_StorageList;
|
|
|
|
|
|
|
|
|
|
typedef struct PARTICLE_Data {
|
2017-04-03 19:32:05 +02:00
|
|
|
void *engine_type; /* Required */
|
2017-03-12 21:16:03 +01:00
|
|
|
PARTICLE_FramebufferList *fbl;
|
|
|
|
|
PARTICLE_TextureList *txl;
|
|
|
|
|
PARTICLE_PassList *psl;
|
|
|
|
|
PARTICLE_StorageList *stl;
|
|
|
|
|
} PARTICLE_Data;
|
|
|
|
|
|
|
|
|
|
/* *********** STATIC *********** */
|
|
|
|
|
|
2017-03-18 22:14:53 +01:00
|
|
|
static struct {
|
2018-05-08 17:11:42 +02:00
|
|
|
struct GPUShader *hair_shader;
|
2017-03-18 22:14:53 +01:00
|
|
|
} e_data = {NULL}; /* Engine data */
|
|
|
|
|
|
2017-04-29 16:52:12 +10:00
|
|
|
typedef struct PARTICLE_PrivateData {
|
2018-05-08 17:11:42 +02:00
|
|
|
DRWShadingGroup *hair_group;
|
2017-04-29 16:52:12 +10:00
|
|
|
} PARTICLE_PrivateData; /* Transient data */
|
2017-03-12 21:16:03 +01:00
|
|
|
|
|
|
|
|
/* *********** FUNCTIONS *********** */
|
|
|
|
|
|
2018-05-08 17:11:42 +02:00
|
|
|
static void particle_engine_init(void *UNUSED(vedata))
|
2017-03-12 21:16:03 +01:00
|
|
|
{
|
2018-05-08 17:11:42 +02:00
|
|
|
if (!e_data.hair_shader) {
|
|
|
|
|
e_data.hair_shader = DRW_shader_create(
|
|
|
|
|
datatoc_particle_vert_glsl,
|
|
|
|
|
NULL,
|
|
|
|
|
datatoc_particle_strand_frag_glsl,
|
|
|
|
|
"#define MAX_MATERIAL 1\n" );
|
2017-03-12 21:16:03 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-08 17:11:42 +02:00
|
|
|
static void particle_cache_init(void *vedata)
|
2017-03-12 21:16:03 +01:00
|
|
|
{
|
2017-03-26 19:10:53 +02:00
|
|
|
PARTICLE_PassList *psl = ((PARTICLE_Data *)vedata)->psl;
|
|
|
|
|
PARTICLE_StorageList *stl = ((PARTICLE_Data *)vedata)->stl;
|
2017-03-12 21:16:03 +01:00
|
|
|
|
2017-03-26 20:13:34 +02:00
|
|
|
if (!stl->g_data) {
|
|
|
|
|
/* Alloc transient pointers */
|
2017-04-29 16:52:12 +10:00
|
|
|
stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
|
2017-03-26 20:13:34 +02:00
|
|
|
}
|
2017-03-14 18:40:23 +11:00
|
|
|
|
2018-05-08 17:11:42 +02:00
|
|
|
/* Create a pass */
|
|
|
|
|
psl->hair_pass = DRW_pass_create("Hair Pass", (DRW_STATE_WRITE_COLOR |
|
|
|
|
|
DRW_STATE_WRITE_DEPTH |
|
|
|
|
|
DRW_STATE_DEPTH_LESS |
|
|
|
|
|
DRW_STATE_WIRE));
|
2017-03-12 21:16:03 +01:00
|
|
|
|
2018-05-08 17:11:42 +02:00
|
|
|
stl->g_data->hair_group = DRW_shgroup_create(e_data.hair_shader,
|
|
|
|
|
psl->hair_pass);
|
2017-03-12 21:16:03 +01:00
|
|
|
}
|
|
|
|
|
|
2018-05-08 17:11:42 +02:00
|
|
|
static void particle_cache_populate(void *vedata, Object *object)
|
2017-03-12 21:16:03 +01:00
|
|
|
{
|
2017-03-26 19:10:53 +02:00
|
|
|
PARTICLE_StorageList *stl = ((PARTICLE_Data *)vedata)->stl;
|
2018-05-08 17:11:42 +02:00
|
|
|
for (ParticleSystem *psys = object->particlesystem.first;
|
|
|
|
|
psys != NULL;
|
|
|
|
|
psys = psys->next)
|
|
|
|
|
{
|
|
|
|
|
if (!psys_check_enabled(object, psys, false)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (PE_get_current_from_psys(psys) == NULL) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
/* NOTE: Particle edit mode visualizes particles as strands. */
|
|
|
|
|
struct Gwn_Batch *hair = DRW_cache_particles_get_hair(psys, NULL);
|
|
|
|
|
DRW_shgroup_call_add(stl->g_data->hair_group, hair, NULL);
|
|
|
|
|
break;
|
2017-03-12 21:16:03 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-14 18:40:23 +11:00
|
|
|
/* Optional: Post-cache_populate callback */
|
2018-05-08 17:11:42 +02:00
|
|
|
static void particle_cache_finish(void *UNUSED(vedata))
|
2017-03-12 21:16:03 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Draw time ! Control rendering pipeline from here */
|
2018-05-08 17:11:42 +02:00
|
|
|
static void particle_draw_scene(void *vedata)
|
2017-03-12 21:16:03 +01:00
|
|
|
{
|
2017-03-26 19:10:53 +02:00
|
|
|
|
|
|
|
|
PARTICLE_PassList *psl = ((PARTICLE_Data *)vedata)->psl;
|
2017-03-12 21:16:03 +01:00
|
|
|
|
2018-05-08 17:11:42 +02:00
|
|
|
DRW_draw_pass(psl->hair_pass);
|
2017-03-12 21:16:03 +01:00
|
|
|
}
|
|
|
|
|
|
2018-05-08 17:11:42 +02:00
|
|
|
static void particle_engine_free(void)
|
2017-03-12 21:16:03 +01:00
|
|
|
{
|
2018-05-08 17:11:42 +02:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.hair_shader);
|
2017-03-12 21:16:03 +01:00
|
|
|
}
|
|
|
|
|
|
2018-05-08 17:11:42 +02:00
|
|
|
static const DrawEngineDataSize particle_data_size =
|
|
|
|
|
DRW_VIEWPORT_DATA_SIZE(PARTICLE_Data);
|
2017-04-12 19:49:19 +10:00
|
|
|
|
2017-03-12 21:16:03 +01:00
|
|
|
DrawEngineType draw_engine_particle_type = {
|
|
|
|
|
NULL, NULL,
|
2018-05-08 17:11:42 +02:00
|
|
|
N_("Particle Mode"),
|
|
|
|
|
&particle_data_size,
|
|
|
|
|
&particle_engine_init,
|
|
|
|
|
&particle_engine_free,
|
|
|
|
|
&particle_cache_init,
|
|
|
|
|
&particle_cache_populate,
|
|
|
|
|
&particle_cache_finish,
|
2017-03-12 21:16:03 +01:00
|
|
|
NULL, /* draw_background but not needed by mode engines */
|
2018-05-08 17:11:42 +02:00
|
|
|
&particle_draw_scene,
|
2017-09-25 20:07:02 +02:00
|
|
|
NULL,
|
2018-01-29 14:56:16 +01:00
|
|
|
NULL,
|
2017-03-12 21:16:03 +01:00
|
|
|
};
|