DRW: New Select Debug Engine

This is a simple engine used only to debug the texture of select ids.

It is only used when the `WITH_DRAW_DEBUG` option is enabled and the
debug value is 31.

Reviewed By: fclem

Differential Revision: https://developer.blender.org/D5490
This commit is contained in:
Germano Cavalcante 2021-08-03 13:39:30 -03:00 committed by Germano Cavalcante
parent e844e9e8f3
commit cc4e674e41
6 changed files with 162 additions and 0 deletions

View File

@ -428,6 +428,10 @@ mark_as_advanced(WITH_CYCLES_NETWORK)
option(WITH_CUDA_DYNLOAD "Dynamically load CUDA libraries at runtime" ON)
mark_as_advanced(WITH_CUDA_DYNLOAD)
# Draw Manager
option(WITH_DRAW_DEBUG "Add extra debug capabilities to Draw Manager" OFF)
mark_as_advanced(WITH_DRAW_DEBUG)
# LLVM
option(WITH_LLVM "Use LLVM" OFF)
if(APPLE)

View File

@ -70,6 +70,7 @@ typedef struct Global {
* * -16384 and below: Reserved for python (add-ons) usage.
* * -1: Disable faster motion paths computation (since 08/2018).
* * 1 - 30: EEVEE debug/stats values (01/2018).
* * 31: Enable the Select Debug Engine. Only available with #WITH_DRAW_DEBUG (08/2021).
* * 101: Enable UI debug drawing of fullscreen area's corner widget (10/2014).
* * 666: Use quicker batch delete for outliners' delete hierarchy (01/2019).
* * 777: Enable UI node panel's sockets polling (11/2011).

View File

@ -483,6 +483,13 @@ data_to_c_simple(engines/image/shaders/engine_image_vert.glsl SRC)
list(APPEND INC
)
if(WITH_DRAW_DEBUG)
list(APPEND SRC
engines/select/select_debug_engine.c
)
add_definitions(-DWITH_DRAW_DEBUG)
endif()
if(WITH_MOD_FLUID)
list(APPEND INC
../../../intern/mantaflow/extern

View File

@ -0,0 +1,135 @@
/*
* 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.
*
* Copyright 2019, Blender Foundation.
*/
/** \file
* \ingroup draw_engine
*
* Engine for debuging the selection map drawing.
*/
#include "DNA_ID.h"
#include "DNA_vec_types.h"
#include "DRW_engine.h"
#include "DRW_select_buffer.h"
#include "draw_cache.h"
#include "draw_manager.h"
#include "select_engine.h"
#define SELECT_DEBUG_ENGINE "SELECT_DEBUG_ENGINE"
/* -------------------------------------------------------------------- */
/** \name Structs and static variables
* \{ */
typedef struct SELECTIDDEBUG_PassList {
struct DRWPass *debug_pass;
} SELECTIDDEBUG_PassList;
typedef struct SELECTIDDEBUG_Data {
void *engine_type;
DRWViewportEmptyList *fbl;
DRWViewportEmptyList *txl;
SELECTIDDEBUG_PassList *psl;
DRWViewportEmptyList *stl;
} SELECTIDDEBUG_Data;
static struct {
struct GPUShader *select_debug_sh;
} e_data = {{NULL}}; /* Engine data */
/** \} */
/* -------------------------------------------------------------------- */
/** \name Engine Functions
* \{ */
static void select_debug_engine_init(void *vedata)
{
SELECTIDDEBUG_PassList *psl = ((SELECTIDDEBUG_Data *)vedata)->psl;
if (!e_data.select_debug_sh) {
e_data.select_debug_sh = DRW_shader_create_fullscreen(
"uniform usampler2D image;"
"in vec4 uvcoordsvar;"
"out vec4 fragColor;"
"void main() {"
" uint px = texture(image, uvcoordsvar.xy).r;"
" fragColor = vec4(1.0, 1.0, 1.0, 0.0);"
" if (px != 0u) {"
" fragColor.a = 1.0;"
" px &= 0x3Fu;"
" fragColor.r = ((px >> 0) & 0x3u) / float(0x3u);"
" fragColor.g = ((px >> 2) & 0x3u) / float(0x3u);"
" fragColor.b = ((px >> 4) & 0x3u) / float(0x3u);"
" }"
"}\n",
NULL);
}
psl->debug_pass = DRW_pass_create("Debug Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA);
GPUTexture *texture_u32 = DRW_engine_select_texture_get();
if (texture_u32) {
DRWShadingGroup *shgrp = DRW_shgroup_create(e_data.select_debug_sh, psl->debug_pass);
DRW_shgroup_uniform_texture(shgrp, "image", texture_u32);
DRW_shgroup_call_procedural_triangles(shgrp, NULL, 1);
}
}
static void select_debug_draw_scene(void *vedata)
{
SELECTIDDEBUG_PassList *psl = ((SELECTIDDEBUG_Data *)vedata)->psl;
DRW_draw_pass(psl->debug_pass);
}
static void select_debug_engine_free(void)
{
DRW_SHADER_FREE_SAFE(e_data.select_debug_sh);
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Engine Type
* \{ */
static const DrawEngineDataSize select_debug_data_size = DRW_VIEWPORT_DATA_SIZE(
SELECTIDDEBUG_Data);
DrawEngineType draw_engine_debug_select_type = {
NULL,
NULL,
N_("Select ID Debug"),
&select_debug_data_size,
&select_debug_engine_init,
&select_debug_engine_free,
NULL,
NULL,
NULL,
&select_debug_draw_scene,
NULL,
NULL,
NULL,
NULL,
};
/** \} */
#undef SELECT_DEBUG_ENGINE

View File

@ -22,9 +22,15 @@
#pragma once
/* select_engine.c */
extern DrawEngineType draw_engine_select_type;
extern RenderEngineType DRW_engine_viewport_select_type;
#ifdef WITH_DRAW_DEBUG
/* select_debug_engine.c */
extern DrawEngineType draw_engine_debug_select_type;
#endif
struct SELECTID_Context *DRW_select_engine_context_get(void);
struct GPUFrameBuffer *DRW_engine_select_framebuffer_get(void);

View File

@ -1281,6 +1281,12 @@ static void drw_engines_enable(ViewLayer *UNUSED(view_layer),
use_drw_engine(&draw_engine_gpencil_type);
}
drw_engines_enable_overlays();
#ifdef WITH_DRAW_DEBUG
if (G.debug_value == 31) {
use_drw_engine(&draw_engine_debug_select_type);
}
#endif
}
static void drw_engines_disable(void)
@ -2940,6 +2946,9 @@ void DRW_engines_register(void)
DRW_engine_register(&draw_engine_overlay_type);
DRW_engine_register(&draw_engine_select_type);
DRW_engine_register(&draw_engine_basic_type);
#ifdef WITH_DRAW_DEBUG
DRW_engine_register(&draw_engine_debug_select_type);
#endif
DRW_engine_register(&draw_engine_image_type);
DRW_engine_register(DRW_engine_viewport_external_type.draw_engine);