2017-05-01 14:55:59 +02:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
2019-01-23 11:29:18 +11:00
|
|
|
* Copyright 2017, Blender Foundation.
|
2017-05-01 14:55:59 +02:00
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup draw_engine
|
2017-05-01 14:55:59 +02:00
|
|
|
*
|
|
|
|
|
* Base engine for external render engines.
|
|
|
|
|
* We use it for depth and non-mesh objects.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "DRW_render.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
#include "DNA_view3d_types.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "ED_screen.h"
|
|
|
|
|
|
|
|
|
|
#include "GPU_matrix.h"
|
|
|
|
|
#include "GPU_shader.h"
|
|
|
|
|
#include "GPU_viewport.h"
|
|
|
|
|
|
|
|
|
|
/* Shaders */
|
|
|
|
|
|
|
|
|
|
#define EXTERNAL_ENGINE "BLENDER_EXTERNAL"
|
|
|
|
|
|
|
|
|
|
/* *********** LISTS *********** */
|
|
|
|
|
|
|
|
|
|
/* GPUViewport.storage
|
|
|
|
|
* Is freed everytime the viewport engine changes */
|
|
|
|
|
typedef struct EXTERNAL_Storage {
|
|
|
|
|
int dummy;
|
|
|
|
|
} EXTERNAL_Storage;
|
|
|
|
|
|
|
|
|
|
typedef struct EXTERNAL_StorageList {
|
|
|
|
|
struct EXTERNAL_Storage *storage;
|
|
|
|
|
struct EXTERNAL_PrivateData *g_data;
|
|
|
|
|
} EXTERNAL_StorageList;
|
|
|
|
|
|
|
|
|
|
typedef struct EXTERNAL_FramebufferList {
|
|
|
|
|
struct GPUFrameBuffer *default_fb;
|
|
|
|
|
} EXTERNAL_FramebufferList;
|
|
|
|
|
|
|
|
|
|
typedef struct EXTERNAL_TextureList {
|
|
|
|
|
/* default */
|
|
|
|
|
struct GPUTexture *depth;
|
|
|
|
|
} EXTERNAL_TextureList;
|
|
|
|
|
|
|
|
|
|
typedef struct EXTERNAL_PassList {
|
|
|
|
|
struct DRWPass *depth_pass;
|
|
|
|
|
} EXTERNAL_PassList;
|
|
|
|
|
|
|
|
|
|
typedef struct EXTERNAL_Data {
|
|
|
|
|
void *engine_type;
|
|
|
|
|
EXTERNAL_FramebufferList *fbl;
|
|
|
|
|
EXTERNAL_TextureList *txl;
|
|
|
|
|
EXTERNAL_PassList *psl;
|
|
|
|
|
EXTERNAL_StorageList *stl;
|
2017-05-04 15:46:09 +02:00
|
|
|
char info[GPU_INFO_SIZE];
|
2017-05-01 14:55:59 +02:00
|
|
|
} EXTERNAL_Data;
|
|
|
|
|
|
|
|
|
|
/* *********** STATIC *********** */
|
|
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
|
/* Depth Pre Pass */
|
|
|
|
|
struct GPUShader *depth_sh;
|
|
|
|
|
} e_data = {NULL}; /* Engine data */
|
|
|
|
|
|
|
|
|
|
typedef struct EXTERNAL_PrivateData {
|
|
|
|
|
DRWShadingGroup *depth_shgrp;
|
|
|
|
|
} EXTERNAL_PrivateData; /* Transient data */
|
|
|
|
|
|
|
|
|
|
/* Functions */
|
|
|
|
|
|
2017-11-29 12:30:55 +01:00
|
|
|
static void external_engine_init(void *UNUSED(vedata))
|
2017-05-01 14:55:59 +02:00
|
|
|
{
|
|
|
|
|
/* Depth prepass */
|
|
|
|
|
if (!e_data.depth_sh) {
|
2019-02-06 09:15:16 +11:00
|
|
|
e_data.depth_sh = DRW_shader_create_3D_depth_only(GPU_SHADER_CFG_DEFAULT);
|
2017-05-01 14:55:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 12:30:55 +01:00
|
|
|
static void external_cache_init(void *vedata)
|
2017-05-01 14:55:59 +02:00
|
|
|
{
|
|
|
|
|
EXTERNAL_PassList *psl = ((EXTERNAL_Data *)vedata)->psl;
|
|
|
|
|
EXTERNAL_StorageList *stl = ((EXTERNAL_Data *)vedata)->stl;
|
|
|
|
|
|
|
|
|
|
if (!stl->g_data) {
|
|
|
|
|
/* Alloc transient pointers */
|
|
|
|
|
stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Depth Pass */
|
|
|
|
|
{
|
2018-05-20 19:05:13 +02:00
|
|
|
psl->depth_pass = DRW_pass_create("Depth Pass", DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL);
|
2017-05-01 14:55:59 +02:00
|
|
|
stl->g_data->depth_shgrp = DRW_shgroup_create(e_data.depth_sh, psl->depth_pass);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 12:30:55 +01:00
|
|
|
static void external_cache_populate(void *vedata, Object *ob)
|
2017-05-01 14:55:59 +02:00
|
|
|
{
|
|
|
|
|
EXTERNAL_StorageList *stl = ((EXTERNAL_Data *)vedata)->stl;
|
|
|
|
|
|
2019-01-25 07:10:13 +11:00
|
|
|
if (!DRW_object_is_renderable(ob)) {
|
2017-05-01 14:55:59 +02:00
|
|
|
return;
|
2019-01-25 07:10:13 +11:00
|
|
|
}
|
2017-05-01 14:55:59 +02:00
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
struct GPUBatch *geom = DRW_cache_object_surface_get(ob);
|
2017-05-01 14:55:59 +02:00
|
|
|
if (geom) {
|
|
|
|
|
/* Depth Prepass */
|
|
|
|
|
DRW_shgroup_call_add(stl->g_data->depth_shgrp, geom, ob->obmat);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 12:30:55 +01:00
|
|
|
static void external_cache_finish(void *UNUSED(vedata))
|
2017-05-01 14:55:59 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 12:30:55 +01:00
|
|
|
static void external_draw_scene_do(void *vedata)
|
2017-05-01 14:55:59 +02:00
|
|
|
{
|
|
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
|
Scene *scene = draw_ctx->scene;
|
|
|
|
|
RegionView3D *rv3d = draw_ctx->rv3d;
|
|
|
|
|
ARegion *ar = draw_ctx->ar;
|
|
|
|
|
RenderEngineType *type;
|
|
|
|
|
|
2018-05-20 19:05:13 +02:00
|
|
|
DRW_state_reset_ex(DRW_STATE_DEFAULT & ~DRW_STATE_DEPTH_LESS_EQUAL);
|
2017-05-03 20:09:17 +10:00
|
|
|
|
2017-05-01 14:55:59 +02:00
|
|
|
/* Create render engine. */
|
|
|
|
|
if (!rv3d->render_engine) {
|
2017-11-28 15:06:32 +01:00
|
|
|
RenderEngineType *engine_type = draw_ctx->engine_type;
|
2017-05-01 14:55:59 +02:00
|
|
|
|
2018-05-30 14:32:47 +02:00
|
|
|
if (!(engine_type->view_update && engine_type->view_draw)) {
|
2017-05-01 14:55:59 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-16 17:15:03 -02:00
|
|
|
RenderEngine *engine = RE_engine_create_ex(engine_type, true);
|
2017-05-01 14:55:59 +02:00
|
|
|
engine->tile_x = scene->r.tilex;
|
|
|
|
|
engine->tile_y = scene->r.tiley;
|
2017-10-16 17:15:03 -02:00
|
|
|
engine_type->view_update(engine, draw_ctx->evil_C);
|
2017-05-01 14:55:59 +02:00
|
|
|
rv3d->render_engine = engine;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Rendered draw. */
|
2018-07-15 15:27:15 +02:00
|
|
|
GPU_matrix_push_projection();
|
2017-05-01 14:55:59 +02:00
|
|
|
ED_region_pixelspace(ar);
|
|
|
|
|
|
|
|
|
|
/* Render result draw. */
|
|
|
|
|
type = rv3d->render_engine->type;
|
2018-05-30 14:32:47 +02:00
|
|
|
type->view_draw(rv3d->render_engine, draw_ctx->evil_C);
|
2017-05-01 14:55:59 +02:00
|
|
|
|
2018-07-15 15:27:15 +02:00
|
|
|
GPU_matrix_pop_projection();
|
2017-05-04 15:46:09 +02:00
|
|
|
|
|
|
|
|
/* Set render info. */
|
|
|
|
|
EXTERNAL_Data *data = vedata;
|
2017-05-17 18:13:10 +02:00
|
|
|
if (rv3d->render_engine->text[0] != '\0') {
|
2017-05-04 15:46:09 +02:00
|
|
|
BLI_strncpy(data->info, rv3d->render_engine->text, sizeof(data->info));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
data->info[0] = '\0';
|
|
|
|
|
}
|
2017-05-01 14:55:59 +02:00
|
|
|
}
|
|
|
|
|
|
2017-11-29 12:30:55 +01:00
|
|
|
static void external_draw_scene(void *vedata)
|
2017-05-01 14:55:59 +02:00
|
|
|
{
|
2017-05-03 04:59:15 +10:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
2017-05-01 14:55:59 +02:00
|
|
|
EXTERNAL_PassList *psl = ((EXTERNAL_Data *)vedata)->psl;
|
2017-05-03 04:59:15 +10:00
|
|
|
|
|
|
|
|
/* Will be NULL during OpenGL render.
|
|
|
|
|
* OpenGL render is used for quick preview (thumbnails or sequencer preview)
|
|
|
|
|
* where using the rendering engine to preview doesn't make so much sense. */
|
|
|
|
|
if (draw_ctx->evil_C) {
|
2017-11-29 12:30:55 +01:00
|
|
|
external_draw_scene_do(vedata);
|
2017-05-03 04:59:15 +10:00
|
|
|
}
|
2017-05-01 14:55:59 +02:00
|
|
|
DRW_draw_pass(psl->depth_pass);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 12:30:55 +01:00
|
|
|
static void external_engine_free(void)
|
2017-05-01 14:55:59 +02:00
|
|
|
{
|
|
|
|
|
/* All shaders are builtin. */
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 12:30:55 +01:00
|
|
|
static const DrawEngineDataSize external_data_size = DRW_VIEWPORT_DATA_SIZE(EXTERNAL_Data);
|
2017-05-01 14:55:59 +02:00
|
|
|
|
|
|
|
|
DrawEngineType draw_engine_external_type = {
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
N_("External"),
|
2017-11-29 12:30:55 +01:00
|
|
|
&external_data_size,
|
|
|
|
|
&external_engine_init,
|
|
|
|
|
&external_engine_free,
|
|
|
|
|
&external_cache_init,
|
|
|
|
|
&external_cache_populate,
|
|
|
|
|
&external_cache_finish,
|
2017-05-01 14:55:59 +02:00
|
|
|
NULL,
|
2017-11-29 12:30:55 +01:00
|
|
|
&external_draw_scene,
|
2017-09-25 20:07:02 +02:00
|
|
|
NULL,
|
2017-11-28 17:05:52 +01:00
|
|
|
NULL,
|
2018-01-29 14:56:16 +01:00
|
|
|
NULL,
|
2017-05-01 14:55:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Note: currently unused, we should not register unless we want to see this when debugging the view. */
|
|
|
|
|
|
|
|
|
|
RenderEngineType DRW_engine_viewport_external_type = {
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
EXTERNAL_ENGINE, N_("External"), RE_INTERNAL,
|
2018-05-16 21:40:05 +02:00
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
2017-05-01 14:55:59 +02:00
|
|
|
&draw_engine_external_type,
|
2019-01-31 08:28:56 +11:00
|
|
|
{NULL, NULL, NULL},
|
2017-05-01 14:55:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#undef EXTERNAL_ENGINE
|