Welcome to mirror list, hosted at ThFree Co, Russian Federation.

select_debug_engine.c « select « engines « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f66eabdcdcc6891a8bed16333694a086dbd5e93c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * 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 debugging 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, /* instance_free */
    NULL,
    NULL,
    NULL,
    &select_debug_draw_scene,
    NULL,
    NULL,
    NULL,
    NULL,
};

/** \} */

#undef SELECT_DEBUG_ENGINE