GPU: Fix triple buffer w/ basic glsl shader
Needed to add GL_TEXTURE_RECTANGLE support to basic-shader.
This commit is contained in:
parent
91c146c42e
commit
5bd9e83289
Notes:
blender-bot
2023-02-14 07:28:05 +01:00
Referenced by commit 070f22c440
, Fix T49861: Interlace stereo is broken in 2.78
Referenced by issue #49861, Interlace stereo is broken in 2.78
|
@ -46,11 +46,12 @@ typedef enum GPUBasicShaderOption {
|
|||
GPU_SHADER_LIGHTING = (1 << 1), /* use lighting */
|
||||
GPU_SHADER_TWO_SIDED = (1 << 2), /* flip normals towards viewer */
|
||||
GPU_SHADER_TEXTURE_2D = (1 << 3), /* use 2D texture to replace diffuse color */
|
||||
GPU_SHADER_TEXTURE_RECT = (1 << 4), /* same as GPU_SHADER_TEXTURE_2D, for GL_TEXTURE_RECTANGLE */
|
||||
|
||||
GPU_SHADER_SOLID_LIGHTING = (1 << 4), /* use faster lighting (set automatically) */
|
||||
GPU_SHADER_STIPPLE = (1 << 5), /* use stipple */
|
||||
GPU_SHADER_LINE = (1 << 6), /* draw lines */
|
||||
GPU_SHADER_OPTIONS_NUM = 7,
|
||||
GPU_SHADER_SOLID_LIGHTING = (1 << 5), /* use faster lighting (set automatically) */
|
||||
GPU_SHADER_STIPPLE = (1 << 6), /* use stipple */
|
||||
GPU_SHADER_LINE = (1 << 7), /* draw lines */
|
||||
GPU_SHADER_OPTIONS_NUM = 8,
|
||||
GPU_SHADER_OPTION_COMBINATIONS = (1 << GPU_SHADER_OPTIONS_NUM)
|
||||
} GPUBasicShaderOption;
|
||||
|
||||
|
|
|
@ -324,6 +324,9 @@ static int detect_options()
|
|||
|
||||
if (glIsEnabled(GL_TEXTURE_2D))
|
||||
options |= GPU_SHADER_TEXTURE_2D;
|
||||
if (glIsEnabled(GL_TEXTURE_RECTANGLE))
|
||||
options |= GPU_SHADER_TEXTURE_RECT;
|
||||
GPU_SHADER_TEXTURE_RECT
|
||||
if (glIsEnabled(GL_COLOR_MATERIAL))
|
||||
options |= GPU_SHADER_USE_COLOR;
|
||||
|
||||
|
@ -363,8 +366,10 @@ static GPUShader *gpu_basic_shader(int options)
|
|||
strcat(defines, "#define USE_COLOR\n");
|
||||
if (options & GPU_SHADER_TWO_SIDED)
|
||||
strcat(defines, "#define USE_TWO_SIDED\n");
|
||||
if (options & GPU_SHADER_TEXTURE_2D)
|
||||
if (options & (GPU_SHADER_TEXTURE_2D | GPU_SHADER_TEXTURE_RECT))
|
||||
strcat(defines, "#define USE_TEXTURE\n");
|
||||
if (options & GPU_SHADER_TEXTURE_RECT)
|
||||
strcat(defines, "#define USE_TEXTURE_RECTANGLE\n");
|
||||
if (options & GPU_SHADER_STIPPLE)
|
||||
strcat(defines, "#define USE_STIPPLE\n");
|
||||
if (options & GPU_SHADER_LINE) {
|
||||
|
@ -385,7 +390,7 @@ static GPUShader *gpu_basic_shader(int options)
|
|||
|
||||
if (shader) {
|
||||
/* set texture map to first texture unit */
|
||||
if (options & GPU_SHADER_TEXTURE_2D) {
|
||||
if (options & (GPU_SHADER_TEXTURE_2D | GPU_SHADER_TEXTURE_RECT)) {
|
||||
GPU_shader_bind(shader);
|
||||
glUniform1i(GPU_shader_get_uniform(shader, "texture_map"), 0);
|
||||
GPU_shader_unbind();
|
||||
|
@ -415,6 +420,23 @@ void GPU_basic_shader_bind(int options)
|
|||
{
|
||||
if (USE_GLSL) {
|
||||
if (options) {
|
||||
const int bound_options = GPU_MATERIAL_STATE.bound_options;
|
||||
|
||||
/* texture options need to be set for basic shader too */
|
||||
if (options & GPU_SHADER_TEXTURE_2D) {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
else if (bound_options & GPU_SHADER_TEXTURE_2D) {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
if (options & GPU_SHADER_TEXTURE_RECT) {
|
||||
glEnable(GL_TEXTURE_RECTANGLE);
|
||||
}
|
||||
else if (bound_options & GPU_SHADER_TEXTURE_RECT) {
|
||||
glDisable(GL_TEXTURE_RECTANGLE);
|
||||
}
|
||||
|
||||
GPUShader *shader = gpu_basic_shader(options);
|
||||
|
||||
if (shader) {
|
||||
|
@ -427,7 +449,7 @@ void GPU_basic_shader_bind(int options)
|
|||
}
|
||||
}
|
||||
else {
|
||||
int bound_options = GPU_MATERIAL_STATE.bound_options;
|
||||
const int bound_options = GPU_MATERIAL_STATE.bound_options;
|
||||
|
||||
if (options & GPU_SHADER_LIGHTING) {
|
||||
glEnable(GL_LIGHTING);
|
||||
|
@ -454,10 +476,24 @@ void GPU_basic_shader_bind(int options)
|
|||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, env_mode);
|
||||
}
|
||||
else if (bound_options & GPU_SHADER_TEXTURE_2D) {
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
if ((options & GPU_SHADER_TEXTURE_RECT) == 0) {
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
}
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
if (options & GPU_SHADER_TEXTURE_RECT) {
|
||||
GLint env_mode = (options & (GPU_SHADER_USE_COLOR | GPU_SHADER_LIGHTING)) ? GL_MODULATE : GL_REPLACE;
|
||||
glEnable(GL_TEXTURE_RECTANGLE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, env_mode);
|
||||
}
|
||||
else if (bound_options & GPU_SHADER_TEXTURE_RECT) {
|
||||
if ((options & GPU_SHADER_TEXTURE_2D) == 0) {
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
}
|
||||
glDisable(GL_TEXTURE_RECTANGLE);
|
||||
}
|
||||
|
||||
if ((options & GPU_SHADER_LINE) && (options & GPU_SHADER_STIPPLE)) {
|
||||
glEnable(GL_LINE_STIPPLE);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
*
|
||||
* USE_COLOR: use glColor for diffuse colors
|
||||
* USE_TEXTURE: use texture for diffuse colors
|
||||
* USE_TEXTURE_RECTANGLE: use GL_TEXTURE_RECTANGLE instead of GL_TEXTURE_2D
|
||||
* USE_SCENE_LIGHTING: use lights (up to 8)
|
||||
* USE_SOLID_LIGHTING: assume 3 directional lights for solid draw mode
|
||||
* USE_TWO_SIDED: flip normal towards viewer
|
||||
|
@ -39,8 +40,16 @@ varying vec4 varying_vertex_color;
|
|||
#endif
|
||||
|
||||
#ifdef USE_TEXTURE
|
||||
#ifdef USE_TEXTURE_RECTANGLE
|
||||
#define sampler2D_default sampler2DRect
|
||||
#define texture2D_default texture2DRect
|
||||
#else
|
||||
#define sampler2D_default sampler2D
|
||||
#define texture2D_default texture2D
|
||||
#endif
|
||||
|
||||
varying vec2 varying_texture_coord;
|
||||
uniform sampler2D texture_map;
|
||||
uniform sampler2D_default texture_map;
|
||||
#endif
|
||||
|
||||
#ifdef USE_STIPPLE
|
||||
|
@ -229,12 +238,12 @@ void main()
|
|||
float alpha;
|
||||
|
||||
#if defined(USE_TEXTURE) && defined(USE_COLOR)
|
||||
vec4 texture_color = texture2D(texture_map, varying_texture_coord);
|
||||
vec4 texture_color = texture2D_default(texture_map, varying_texture_coord);
|
||||
|
||||
L_diffuse *= texture_color.rgb * varying_vertex_color.rgb;
|
||||
alpha = texture_color.a * varying_vertex_color.a;
|
||||
#elif defined(USE_TEXTURE)
|
||||
vec4 texture_color = texture2D(texture_map, varying_texture_coord);
|
||||
vec4 texture_color = texture2D_default(texture_map, varying_texture_coord);
|
||||
|
||||
L_diffuse *= texture_color.rgb;
|
||||
alpha = texture_color.a;
|
||||
|
@ -259,9 +268,9 @@ void main()
|
|||
|
||||
/* no lighting */
|
||||
#if defined(USE_TEXTURE) && defined(USE_COLOR)
|
||||
gl_FragColor = texture2D(texture_map, varying_texture_coord) * varying_vertex_color;
|
||||
gl_FragColor = texture2D_default(texture_map, varying_texture_coord) * varying_vertex_color;
|
||||
#elif defined(USE_TEXTURE)
|
||||
gl_FragColor = texture2D(texture_map, varying_texture_coord);
|
||||
gl_FragColor = texture2D_default(texture_map, varying_texture_coord);
|
||||
#elif defined(USE_COLOR)
|
||||
gl_FragColor = varying_vertex_color;
|
||||
#else
|
||||
|
|
|
@ -437,8 +437,6 @@ void wm_triple_draw_textures(wmWindow *win, wmDrawTriple *triple, float alpha)
|
|||
|
||||
float halfx, halfy, ratiox, ratioy;
|
||||
|
||||
glEnable(triple->target);
|
||||
|
||||
/* wmOrtho for the screen has this same offset */
|
||||
ratiox = sizex;
|
||||
ratioy = sizey;
|
||||
|
@ -453,6 +451,8 @@ void wm_triple_draw_textures(wmWindow *win, wmDrawTriple *triple, float alpha)
|
|||
halfy /= triple->y;
|
||||
}
|
||||
|
||||
GPU_basic_shader_bind((triple->target == GL_TEXTURE_2D) ? GPU_SHADER_TEXTURE_2D : GPU_SHADER_TEXTURE_RECT);
|
||||
|
||||
glBindTexture(triple->target, triple->bind);
|
||||
|
||||
glColor4f(1.0f, 1.0f, 1.0f, alpha);
|
||||
|
@ -471,7 +471,8 @@ void wm_triple_draw_textures(wmWindow *win, wmDrawTriple *triple, float alpha)
|
|||
glEnd();
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue