Blender  V2.93
image_shader.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2020, Blender Foundation.
17  */
18 
23 #include "DRW_render.h"
24 
25 #include "BLI_dynstr.h"
26 
27 #include "GPU_batch.h"
28 
29 #include "image_engine.h"
30 #include "image_private.h"
31 
34 extern char datatoc_common_view_lib_glsl[];
35 
36 extern char datatoc_engine_image_frag_glsl[];
37 extern char datatoc_engine_image_vert_glsl[];
38 
39 typedef struct IMAGE_Shaders {
42 
43 static struct {
46 } e_data = {{{0}}}; /* Engine data */
47 
49 {
50  if (e_data.lib == NULL) {
52  /* NOTE: These need to be ordered by dependencies. */
53  DRW_SHADER_LIB_ADD(e_data.lib, common_colormanagement_lib);
54  DRW_SHADER_LIB_ADD(e_data.lib, common_globals_lib);
55  DRW_SHADER_LIB_ADD(e_data.lib, common_view_lib);
56  }
57 }
58 
59 GPUShader *IMAGE_shader_image_get(bool is_tiled_image)
60 {
61  const int index = is_tiled_image ? 1 : 0;
62  IMAGE_Shaders *sh_data = &e_data.shaders;
63  if (!sh_data->image_sh[index]) {
64  sh_data->image_sh[index] = DRW_shader_create_with_shaderlib(
66  NULL,
68  e_data.lib,
69  is_tiled_image ? "#define TILED_IMAGE\n" : NULL);
70  }
71  return sh_data->image_sh[index];
72 }
73 
75 {
76  GPUShader **sh_data_as_array = (GPUShader **)&e_data.shaders;
77  for (int i = 0; i < (sizeof(IMAGE_Shaders) / sizeof(GPUShader *)); i++) {
78  DRW_SHADER_FREE_SAFE(sh_data_as_array[i]);
79  }
80 
82 }
A dynamically sized string ADT.
#define DRW_SHADER_LIB_FREE_SAFE(lib)
Definition: DRW_render.h:298
#define DRW_SHADER_LIB_ADD(lib, lib_name)
Definition: DRW_render.h:291
#define DRW_SHADER_FREE_SAFE(shader)
Definition: DRW_render.h:279
#define DRW_shader_create_with_shaderlib(vert, geom, frag, lib, defines)
Definition: DRW_render.h:239
struct GPUShader GPUShader
Definition: GPU_shader.h:33
BASIC_Shaders sh_data[GPU_SHADER_CFG_LEN]
Definition: basic_engine.c:76
DRWShaderLibrary * DRW_shader_library_create(void)
IMAGE_Shaders shaders
Definition: image_shader.c:44
GPUShader * IMAGE_shader_image_get(bool is_tiled_image)
Definition: image_shader.c:59
void IMAGE_shader_library_ensure(void)
Definition: image_shader.c:48
struct IMAGE_Shaders IMAGE_Shaders
static struct @214 e_data
char datatoc_common_view_lib_glsl[]
DRWShaderLibrary * lib
Definition: image_shader.c:45
char datatoc_common_colormanagement_lib_glsl[]
char datatoc_common_globals_lib_glsl[]
char datatoc_engine_image_frag_glsl[]
void IMAGE_shader_free(void)
Definition: image_shader.c:74
char datatoc_engine_image_vert_glsl[]
GPUShader * image_sh[2]
Definition: image_shader.c:40