immediate mode: Triple Buffer and two new shaders for TEXTURE_2D and TEXTURE_RECT
Use the same vertex shader for both fragment shaders
This commit is contained in:
@@ -125,6 +125,9 @@ data_to_c_simple(shaders/gpu_shader_2D_no_color_vert.glsl SRC)
|
|||||||
data_to_c_simple(shaders/gpu_shader_2D_flat_color_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_vert.glsl SRC)
|
||||||
data_to_c_simple(shaders/gpu_shader_2D_smooth_color_frag.glsl SRC)
|
data_to_c_simple(shaders/gpu_shader_2D_smooth_color_frag.glsl SRC)
|
||||||
|
data_to_c_simple(shaders/gpu_shader_2D_texture_2D_frag.glsl SRC)
|
||||||
|
data_to_c_simple(shaders/gpu_shader_2D_texture_rect_frag.glsl SRC)
|
||||||
|
data_to_c_simple(shaders/gpu_shader_2D_texture_vert.glsl SRC)
|
||||||
data_to_c_simple(shaders/gpu_shader_3D_no_color_vert.glsl SRC)
|
data_to_c_simple(shaders/gpu_shader_3D_no_color_vert.glsl SRC)
|
||||||
data_to_c_simple(shaders/gpu_shader_3D_flat_color_vert.glsl SRC)
|
data_to_c_simple(shaders/gpu_shader_3D_flat_color_vert.glsl SRC)
|
||||||
data_to_c_simple(shaders/gpu_shader_3D_smooth_color_vert.glsl SRC)
|
data_to_c_simple(shaders/gpu_shader_3D_smooth_color_vert.glsl SRC)
|
||||||
|
@@ -101,6 +101,9 @@ typedef enum GPUBuiltinShader {
|
|||||||
GPU_SHADER_3D_FLAT_COLOR,
|
GPU_SHADER_3D_FLAT_COLOR,
|
||||||
GPU_SHADER_3D_SMOOTH_COLOR,
|
GPU_SHADER_3D_SMOOTH_COLOR,
|
||||||
GPU_SHADER_3D_DEPTH_ONLY,
|
GPU_SHADER_3D_DEPTH_ONLY,
|
||||||
|
/* basic 2D texture drawing */
|
||||||
|
GPU_SHADER_2D_TEXTURE_2D,
|
||||||
|
GPU_SHADER_2D_TEXTURE_RECT,
|
||||||
} GPUBuiltinShader;
|
} GPUBuiltinShader;
|
||||||
|
|
||||||
GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader);
|
GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader);
|
||||||
|
@@ -650,3 +650,14 @@ void immUniformColor4ubv(const unsigned char rgba[4])
|
|||||||
const float scale = 1.0f / 255.0f;
|
const float scale = 1.0f / 255.0f;
|
||||||
immUniform4f("color", scale * rgba[0], scale * rgba[1], scale * rgba[2], rgba[3]);
|
immUniform4f("color", scale * rgba[0], scale * rgba[1], scale * rgba[2], rgba[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void immUniform1i(const char *name, const unsigned int data)
|
||||||
|
{
|
||||||
|
int loc = glGetUniformLocation(imm.bound_program, name);
|
||||||
|
|
||||||
|
#if TRUST_NO_ONE
|
||||||
|
assert(loc != -1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
glUniform1i(loc, data);
|
||||||
|
}
|
@@ -72,3 +72,5 @@ void immUniform4f(const char* name, float x, float y, float z, float w);
|
|||||||
// TODO: treat as sRGB?
|
// TODO: treat as sRGB?
|
||||||
void immUniformColor3ubv(const unsigned char data[3]);
|
void immUniformColor3ubv(const unsigned char data[3]);
|
||||||
void immUniformColor4ubv(const unsigned char data[4]);
|
void immUniformColor4ubv(const unsigned char data[4]);
|
||||||
|
|
||||||
|
void immUniform1i(const char *name, const unsigned int data);
|
||||||
|
@@ -53,6 +53,9 @@ extern char datatoc_gpu_shader_2D_no_color_vert_glsl[];
|
|||||||
extern char datatoc_gpu_shader_2D_flat_color_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_vert_glsl[];
|
||||||
extern char datatoc_gpu_shader_2D_smooth_color_frag_glsl[];
|
extern char datatoc_gpu_shader_2D_smooth_color_frag_glsl[];
|
||||||
|
extern char datatoc_gpu_shader_2D_texture_vert_glsl[];
|
||||||
|
extern char datatoc_gpu_shader_2D_texture_2D_frag_glsl[];
|
||||||
|
extern char datatoc_gpu_shader_2D_texture_rect_frag_glsl[];
|
||||||
extern char datatoc_gpu_shader_3D_no_color_vert_glsl[];
|
extern char datatoc_gpu_shader_3D_no_color_vert_glsl[];
|
||||||
extern char datatoc_gpu_shader_3D_flat_color_vert_glsl[];
|
extern char datatoc_gpu_shader_3D_flat_color_vert_glsl[];
|
||||||
extern char datatoc_gpu_shader_3D_smooth_color_vert_glsl[];
|
extern char datatoc_gpu_shader_3D_smooth_color_vert_glsl[];
|
||||||
@@ -88,6 +91,9 @@ static struct GPUShadersGlobal {
|
|||||||
GPUShader *fx_shaders[MAX_FX_SHADERS * 2];
|
GPUShader *fx_shaders[MAX_FX_SHADERS * 2];
|
||||||
/* for drawing text */
|
/* for drawing text */
|
||||||
GPUShader *text;
|
GPUShader *text;
|
||||||
|
/* for drawing texture */
|
||||||
|
GPUShader *texture_2D;
|
||||||
|
GPUShader *texture_rect;
|
||||||
/* for simple 2D drawing */
|
/* for simple 2D drawing */
|
||||||
GPUShader *uniform_color_2D;
|
GPUShader *uniform_color_2D;
|
||||||
GPUShader *flat_color_2D;
|
GPUShader *flat_color_2D;
|
||||||
@@ -623,6 +629,22 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
|
|||||||
NULL, NULL, NULL, 0, 0, 0);
|
NULL, NULL, NULL, 0, 0, 0);
|
||||||
retval = GG.shaders.text;
|
retval = GG.shaders.text;
|
||||||
break;
|
break;
|
||||||
|
case GPU_SHADER_2D_TEXTURE_2D:
|
||||||
|
if (!GG.shaders.texture_2D)
|
||||||
|
GG.shaders.texture_2D = GPU_shader_create(
|
||||||
|
datatoc_gpu_shader_2D_texture_vert_glsl,
|
||||||
|
datatoc_gpu_shader_2D_texture_2D_frag_glsl,
|
||||||
|
NULL, NULL, NULL, 0, 0, 0);
|
||||||
|
retval = GG.shaders.texture_2D;
|
||||||
|
break;
|
||||||
|
case GPU_SHADER_2D_TEXTURE_RECT:
|
||||||
|
if (!GG.shaders.texture_rect)
|
||||||
|
GG.shaders.texture_rect = GPU_shader_create(
|
||||||
|
datatoc_gpu_shader_2D_texture_vert_glsl,
|
||||||
|
datatoc_gpu_shader_2D_texture_rect_frag_glsl,
|
||||||
|
NULL, NULL, NULL, 0, 0, 0);
|
||||||
|
retval = GG.shaders.texture_rect;
|
||||||
|
break;
|
||||||
case GPU_SHADER_2D_UNIFORM_COLOR:
|
case GPU_SHADER_2D_UNIFORM_COLOR:
|
||||||
if (!GG.shaders.uniform_color_2D)
|
if (!GG.shaders.uniform_color_2D)
|
||||||
GG.shaders.uniform_color_2D = GPU_shader_create(
|
GG.shaders.uniform_color_2D = GPU_shader_create(
|
||||||
@@ -795,6 +817,16 @@ void GPU_shader_free_builtin_shaders(void)
|
|||||||
GG.shaders.text = NULL;
|
GG.shaders.text = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GG.shaders.texture_2D) {
|
||||||
|
GPU_shader_free(GG.shaders.texture_2D);
|
||||||
|
GG.shaders.texture_2D = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GG.shaders.texture_rect) {
|
||||||
|
GPU_shader_free(GG.shaders.texture_rect);
|
||||||
|
GG.shaders.texture_rect = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (GG.shaders.uniform_color_2D) {
|
if (GG.shaders.uniform_color_2D) {
|
||||||
GPU_shader_free(GG.shaders.uniform_color_2D);
|
GPU_shader_free(GG.shaders.uniform_color_2D);
|
||||||
GG.shaders.uniform_color_2D = NULL;
|
GG.shaders.uniform_color_2D = NULL;
|
||||||
|
@@ -0,0 +1,14 @@
|
|||||||
|
#if __VERSION__ == 120
|
||||||
|
varying vec2 texture_coord;
|
||||||
|
#define fragColor gl_FragColor
|
||||||
|
#else
|
||||||
|
in vec2 texture_coord;
|
||||||
|
out vec4 fragColor;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uniform sampler2D texture_map;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
fragColor = texture2D(texture_map, texture_coord);
|
||||||
|
}
|
@@ -0,0 +1,14 @@
|
|||||||
|
#if __VERSION__ == 120
|
||||||
|
varying vec2 texture_coord;
|
||||||
|
#define fragColor gl_FragColor
|
||||||
|
#else
|
||||||
|
in vec2 texture_coord;
|
||||||
|
out vec4 fragColor;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uniform sampler2DRect texture_map;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
fragColor = texture2DRect(texture_map, texture_coord);
|
||||||
|
}
|
14
source/blender/gpu/shaders/gpu_shader_2D_texture_vert.glsl
Normal file
14
source/blender/gpu/shaders/gpu_shader_2D_texture_vert.glsl
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#if __VERSION__ == 120
|
||||||
|
varying vec2 texture_coord;
|
||||||
|
#else
|
||||||
|
out vec2 texture_coord;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
in vec2 texcoord;
|
||||||
|
in vec3 position;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0f);
|
||||||
|
texture_coord = texcoord;
|
||||||
|
}
|
@@ -59,6 +59,7 @@
|
|||||||
#include "GPU_extensions.h"
|
#include "GPU_extensions.h"
|
||||||
#include "GPU_glew.h"
|
#include "GPU_glew.h"
|
||||||
#include "GPU_basic_shader.h"
|
#include "GPU_basic_shader.h"
|
||||||
|
#include "GPU_immediate.h"
|
||||||
|
|
||||||
#include "RE_engine.h"
|
#include "RE_engine.h"
|
||||||
|
|
||||||
@@ -445,28 +446,36 @@ void wm_triple_draw_textures(wmWindow *win, wmDrawTriple *triple, float alpha)
|
|||||||
halfy /= triple->y;
|
halfy /= triple->y;
|
||||||
}
|
}
|
||||||
|
|
||||||
GPU_basic_shader_bind((triple->target == GL_TEXTURE_2D) ? GPU_SHADER_TEXTURE_2D : GPU_SHADER_TEXTURE_RECT);
|
VertexFormat *format = immVertexFormat();
|
||||||
|
unsigned texcoord = add_attrib(format, "texcoord", GL_FLOAT, 2, KEEP_FLOAT);
|
||||||
|
unsigned pos = add_attrib(format, "position", GL_FLOAT, 2, KEEP_FLOAT);
|
||||||
|
|
||||||
|
glEnable(triple->target);
|
||||||
|
immBindBuiltinProgram((triple->target == GL_TEXTURE_2D) ? GPU_SHADER_2D_TEXTURE_2D : GPU_SHADER_2D_TEXTURE_RECT);
|
||||||
|
|
||||||
glBindTexture(triple->target, triple->bind);
|
glBindTexture(triple->target, triple->bind);
|
||||||
|
|
||||||
glColor4f(1.0f, 1.0f, 1.0f, alpha);
|
immUniform1i("texture_map", 0);
|
||||||
glBegin(GL_QUADS);
|
|
||||||
glTexCoord2f(halfx, halfy);
|
|
||||||
glVertex2f(0, 0);
|
|
||||||
|
|
||||||
glTexCoord2f(ratiox + halfx, halfy);
|
immBegin(GL_QUADS, 4);
|
||||||
glVertex2f(sizex, 0);
|
|
||||||
|
|
||||||
glTexCoord2f(ratiox + halfx, ratioy + halfy);
|
immAttrib2f(texcoord, halfx, halfy);
|
||||||
glVertex2f(sizex, sizey);
|
immVertex2f(pos, 0.0f, 0.0f);
|
||||||
|
|
||||||
glTexCoord2f(halfx, ratioy + halfy);
|
immAttrib2f(texcoord, ratiox + halfx, halfy);
|
||||||
glVertex2f(0, sizey);
|
immVertex2f(pos, sizex, 0.0f);
|
||||||
glEnd();
|
|
||||||
|
immAttrib2f(texcoord, ratiox + halfx, ratioy + halfy);
|
||||||
|
immVertex2f(pos, sizex, sizey);
|
||||||
|
|
||||||
|
immAttrib2f(texcoord, halfx, ratioy + halfy);
|
||||||
|
immVertex2f(pos, 0.0f, sizey);
|
||||||
|
|
||||||
|
immEnd();
|
||||||
|
immUnbindProgram();
|
||||||
|
|
||||||
glBindTexture(triple->target, 0);
|
glBindTexture(triple->target, 0);
|
||||||
|
glDisable(triple->target);
|
||||||
GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wm_triple_copy_textures(wmWindow *win, wmDrawTriple *triple)
|
static void wm_triple_copy_textures(wmWindow *win, wmDrawTriple *triple)
|
||||||
|
Reference in New Issue
Block a user