convert icon_draw_texture to gawain imm mode replacements
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
|
||||
#include "GPU_extensions.h"
|
||||
#include "GPU_basic_shader.h"
|
||||
#include "GPU_immediate.h"
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_utildefines.h"
|
||||
@@ -1016,33 +1017,40 @@ static void icon_draw_texture(
|
||||
{
|
||||
float x1, x2, y1, y2;
|
||||
|
||||
if (rgb) glColor4f(rgb[0], rgb[1], rgb[2], alpha);
|
||||
else glColor4f(alpha, alpha, alpha, alpha);
|
||||
|
||||
x1 = ix * icongltex.invw;
|
||||
x2 = (ix + ih) * icongltex.invw;
|
||||
y1 = iy * icongltex.invh;
|
||||
y2 = (iy + ih) * icongltex.invh;
|
||||
|
||||
GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR);
|
||||
glBindTexture(GL_TEXTURE_2D, icongltex.id);
|
||||
|
||||
/* sharper downscaling, has no effect when scale matches with a mip level */
|
||||
glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, -0.5f);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(x1, y1);
|
||||
glVertex2f(x, y);
|
||||
glBindTexture(GL_TEXTURE_2D, icongltex.id);
|
||||
VertexFormat* format = immVertexFormat();
|
||||
unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
|
||||
unsigned texCoord = add_attrib(format, "texCoord", GL_FLOAT, 2, KEEP_FLOAT);
|
||||
|
||||
glTexCoord2f(x2, y1);
|
||||
glVertex2f(x + w, y);
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR);
|
||||
if (rgb) immUniform4f("color", rgb[0], rgb[1], rgb[2], alpha);
|
||||
else immUniform4f("color", alpha, alpha, alpha, alpha);
|
||||
|
||||
glTexCoord2f(x2, y2);
|
||||
glVertex2f(x + w, y + h);
|
||||
immUniform1i("image", 0);
|
||||
|
||||
glTexCoord2f(x1, y2);
|
||||
glVertex2f(x, y + h);
|
||||
glEnd();
|
||||
immBegin(GL_TRIANGLE_STRIP, 4);
|
||||
immAttrib2f(texCoord, x1, y2);
|
||||
immVertex2f(pos, x, y + h);
|
||||
|
||||
immAttrib2f(texCoord, x1, y1);
|
||||
immVertex2f(pos, x, y);
|
||||
|
||||
immAttrib2f(texCoord, x2, y2);
|
||||
immVertex2f(pos, x + w, y + h);
|
||||
|
||||
immAttrib2f(texCoord, x2, y1);
|
||||
immVertex2f(pos, x + w, y);
|
||||
immEnd();
|
||||
|
||||
immUnbindProgram();
|
||||
|
||||
glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, 0.0f);
|
||||
|
||||
|
||||
@@ -134,8 +134,10 @@ data_to_c_simple(shaders/gpu_shader_2D_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_2D_flat_color_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_2D_smooth_color_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_2D_smooth_color_frag.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_2D_image_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_image_mask_uniform_color_frag.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_image_modulate_alpha_frag.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_image_color_frag.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_image_rect_modulate_alpha_frag.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_image_depth_linear_frag.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_3D_image_vert.glsl SRC)
|
||||
|
||||
@@ -101,6 +101,7 @@ typedef enum GPUBuiltinShader {
|
||||
GPU_SHADER_2D_UNIFORM_COLOR,
|
||||
GPU_SHADER_2D_FLAT_COLOR,
|
||||
GPU_SHADER_2D_SMOOTH_COLOR,
|
||||
GPU_SHADER_2D_IMAGE_COLOR,
|
||||
/* for simple 3D drawing */
|
||||
GPU_SHADER_3D_UNIFORM_COLOR,
|
||||
GPU_SHADER_3D_FLAT_COLOR,
|
||||
|
||||
@@ -54,7 +54,10 @@ extern char datatoc_gpu_shader_2D_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_2D_flat_color_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_2D_smooth_color_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_2D_smooth_color_frag_glsl[];
|
||||
extern char datatoc_gpu_shader_2D_image_vert_glsl[];
|
||||
|
||||
extern char datatoc_gpu_shader_3D_image_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_image_color_frag_glsl[];
|
||||
extern char datatoc_gpu_shader_image_mask_uniform_color_frag_glsl[];
|
||||
extern char datatoc_gpu_shader_image_modulate_alpha_frag_glsl[];
|
||||
extern char datatoc_gpu_shader_image_rect_modulate_alpha_frag_glsl[];
|
||||
@@ -635,6 +638,8 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
|
||||
datatoc_gpu_shader_flat_color_frag_glsl },
|
||||
[GPU_SHADER_2D_SMOOTH_COLOR] = { datatoc_gpu_shader_2D_smooth_color_vert_glsl,
|
||||
datatoc_gpu_shader_2D_smooth_color_frag_glsl },
|
||||
[GPU_SHADER_2D_IMAGE_COLOR] = { datatoc_gpu_shader_2D_image_vert_glsl,
|
||||
datatoc_gpu_shader_image_color_frag_glsl },
|
||||
[GPU_SHADER_3D_UNIFORM_COLOR] = { datatoc_gpu_shader_3D_vert_glsl, datatoc_gpu_shader_uniform_color_frag_glsl },
|
||||
[GPU_SHADER_3D_FLAT_COLOR] = { datatoc_gpu_shader_3D_flat_color_vert_glsl,
|
||||
datatoc_gpu_shader_flat_color_frag_glsl },
|
||||
|
||||
18
source/blender/gpu/shaders/gpu_shader_2D_image_vert.glsl
Normal file
18
source/blender/gpu/shaders/gpu_shader_2D_image_vert.glsl
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
uniform mat4 ModelViewProjectionMatrix;
|
||||
|
||||
#if __VERSION__ == 120
|
||||
attribute vec2 texCoord;
|
||||
attribute vec2 pos;
|
||||
varying vec2 texCoord_interp;
|
||||
#else
|
||||
in vec2 texCoord;
|
||||
in vec2 pos;
|
||||
out vec2 texCoord_interp;
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = ModelViewProjectionMatrix * vec4(pos.xy, 0.0f, 1.0f);
|
||||
texCoord_interp = texCoord;
|
||||
}
|
||||
17
source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl
Normal file
17
source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
#if __VERSION__ == 120
|
||||
varying vec2 texCoord_interp;
|
||||
#define fragColor gl_FragColor
|
||||
#else
|
||||
in vec2 texCoord_interp;
|
||||
out vec4 fragColor;
|
||||
#define texture2D texture
|
||||
#endif
|
||||
|
||||
uniform vec4 color;
|
||||
uniform sampler2D image;
|
||||
|
||||
void main()
|
||||
{
|
||||
fragColor = texture2D(image, texCoord_interp) * color;
|
||||
}
|
||||
Reference in New Issue
Block a user