diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-04-06 15:22:20 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-04-06 15:22:20 +0300 |
commit | fcb4aaf7a9b08b4123a17846c02a9da40c274874 (patch) | |
tree | 50bee4d9f3b25965972e3d6119cb813be9a7e12d /source | |
parent | 4a73127a2b11056236c40e85ceb75230f2b4888d (diff) |
GPUShader: Add GPU_SHADER_2D_WIDGET_BASE_INST shader.
This will let us draw multiple widget base at once.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/gpu/GPU_shader.h | 1 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_shader.c | 3 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl | 40 |
3 files changed, 27 insertions, 17 deletions
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h index 8051855ffbe..b33df9fdb20 100644 --- a/source/blender/gpu/GPU_shader.h +++ b/source/blender/gpu/GPU_shader.h @@ -173,6 +173,7 @@ typedef enum GPUBuiltinShader { GPU_SHADER_INSTANCE_EDGES_VARIYING_COLOR, /* specialized for UI drawing */ GPU_SHADER_2D_WIDGET_BASE, + GPU_SHADER_2D_WIDGET_BASE_INST, GPU_SHADER_2D_WIDGET_SHADOW, GPU_SHADER_2D_NODELINK, GPU_SHADER_2D_NODELINK_INST, diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c index 08a2c0c2c09..7c7297e90fb 100644 --- a/source/blender/gpu/intern/gpu_shader.c +++ b/source/blender/gpu/intern/gpu_shader.c @@ -803,6 +803,8 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader) [GPU_SHADER_2D_WIDGET_BASE] = { datatoc_gpu_shader_2D_widget_base_vert_glsl, datatoc_gpu_shader_2D_smooth_color_frag_glsl}, + [GPU_SHADER_2D_WIDGET_BASE_INST] = { datatoc_gpu_shader_2D_widget_base_vert_glsl, + datatoc_gpu_shader_2D_smooth_color_frag_glsl}, [GPU_SHADER_2D_WIDGET_SHADOW] = { datatoc_gpu_shader_2D_widget_shadow_vert_glsl, datatoc_gpu_shader_2D_widget_shadow_frag_glsl }, [GPU_SHADER_2D_NODELINK] = { datatoc_gpu_shader_2D_nodelink_vert_glsl, @@ -823,6 +825,7 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader) /* just a few special cases */ const char *defines = NULL; switch (shader) { + case GPU_SHADER_2D_WIDGET_BASE_INST: case GPU_SHADER_2D_NODELINK_INST: defines = "#define USE_INSTANCE;\n"; break; diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl index 2686f443c87..f4dafd7de16 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl @@ -71,24 +71,30 @@ const vec2 triavec[34] = vec2[34]( uniform mat4 ModelViewProjectionMatrix; +#ifdef USE_INSTANCE +#define MAX_INSTANCE 6 +uniform vec4 parameters[11 * MAX_INSTANCE]; +#else uniform vec4 parameters[11]; -/* radi and rad per corner */ -#define recti parameters[0] -#define rect parameters[1] -#define radsi parameters[2].x -#define rads parameters[2].y -#define faci parameters[2].zw -#define roundCorners parameters[3] -#define colorInner1 parameters[4] -#define colorInner2 parameters[5] -#define colorEdge parameters[6] -#define colorEmboss parameters[7] -#define colorTria parameters[8] -#define tria1Center parameters[9].xy -#define tria2Center parameters[9].zw -#define tria1Size parameters[10].x -#define tria2Size parameters[10].y -#define shadeDir parameters[10].z +#endif + +/* gl_InstanceID is 0 if not drawing instances. */ +#define recti parameters[gl_InstanceID * 11 + 0] +#define rect parameters[gl_InstanceID * 11 + 1] +#define radsi parameters[gl_InstanceID * 11 + 2].x +#define rads parameters[gl_InstanceID * 11 + 2].y +#define faci parameters[gl_InstanceID * 11 + 2].zw +#define roundCorners parameters[gl_InstanceID * 11 + 3] +#define colorInner1 parameters[gl_InstanceID * 11 + 4] +#define colorInner2 parameters[gl_InstanceID * 11 + 5] +#define colorEdge parameters[gl_InstanceID * 11 + 6] +#define colorEmboss parameters[gl_InstanceID * 11 + 7] +#define colorTria parameters[gl_InstanceID * 11 + 8] +#define tria1Center parameters[gl_InstanceID * 11 + 9].xy +#define tria2Center parameters[gl_InstanceID * 11 + 9].zw +#define tria1Size parameters[gl_InstanceID * 11 + 10].x +#define tria2Size parameters[gl_InstanceID * 11 + 10].y +#define shadeDir parameters[gl_InstanceID * 11 + 10].z in uint vflag; |