A VAO is not needed to draw background images
This commit is contained in:
parent
9bf24bdff5
commit
8e7b8b70dc
@ -6,17 +6,16 @@ uniform float bgimage_opacity;
|
||||
#ifdef TILED
|
||||
uniform float bgimage_scale;
|
||||
|
||||
// These are of the window, not the screen.
|
||||
uniform float width;
|
||||
uniform float height;
|
||||
uniform float window_width;
|
||||
uniform float window_height;
|
||||
#endif
|
||||
in vec2 texcoord;
|
||||
out vec4 color;
|
||||
|
||||
void main() {
|
||||
#ifdef TILED
|
||||
vec2 txsz = vec2(width,height) / textureSize(image,0);
|
||||
txsz /= bgimage_scale;
|
||||
ivec2 image_size = textureSize(image, 0);
|
||||
vec2 txsz = vec2(window_width / (float(image_size[0]) * bgimage_scale), window_height / (float(image_size[1]) * bgimage_scale));
|
||||
color = texture(image, texcoord * txsz);
|
||||
#endif
|
||||
#ifdef SIMPLE
|
||||
|
||||
@ -1,9 +1,21 @@
|
||||
#version GLSL_VERSION
|
||||
#define left -1.0f
|
||||
#define top 1.0f
|
||||
#define right 1.0f
|
||||
#define bottom -1.0f
|
||||
|
||||
layout(location=0) in vec4 src;
|
||||
out vec2 texcoord;
|
||||
|
||||
const vec2 pos_map[] = vec2[4](
|
||||
vec2(left, top),
|
||||
vec2(left, bottom),
|
||||
vec2(right, bottom),
|
||||
vec2(right, top)
|
||||
);
|
||||
|
||||
|
||||
void main() {
|
||||
texcoord = clamp(vec2(src[0], src[1]*-1), 0, 1);
|
||||
gl_Position = src;
|
||||
vec2 vertex = pos_map[gl_VertexID];
|
||||
texcoord = clamp(vec2(vertex[0], vertex[1]*-1), 0, 1);
|
||||
gl_Position = vec4(vertex, 0, 1);
|
||||
}
|
||||
|
||||
@ -334,28 +334,11 @@ cell_prepare_to_render(ssize_t vao_idx, ssize_t gvao_idx, Screen *screen, GLfloa
|
||||
|
||||
static void
|
||||
draw_bg(int program, OSWindow *w) {
|
||||
if (w->bvao_idx == 0) {
|
||||
const GLfloat screenrect[4][2] = {
|
||||
{ -1.0, 1.0 },
|
||||
{ -1.0, -1.0 },
|
||||
{ 1.0, -1.0 },
|
||||
{ 1.0, 1.0 },
|
||||
};
|
||||
w->bvao_idx = create_vao();
|
||||
bind_vertex_array(w->bvao_idx);
|
||||
glGenBuffers(1, &w->vbo_idx);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, w->vbo_idx);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(screenrect), screenrect, GL_STATIC_DRAW);
|
||||
}
|
||||
bind_vertex_array(w->bvao_idx);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, w->vbo_idx);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
bind_program(program);
|
||||
static bool bgimage_constants_set;
|
||||
bind_vertex_array(blit_vertex_array);
|
||||
|
||||
static bool bgimage_constants_set = false;
|
||||
if (!bgimage_constants_set) {
|
||||
glUniform1i(glGetUniformLocation(program_id(program), "image"), BGIMAGE_UNIT);
|
||||
glUniform1f(glGetUniformLocation(program_id(program), "bgimage_scale"), OPT(background_image_scale));
|
||||
@ -658,15 +641,11 @@ create_border_vao(void) {
|
||||
|
||||
void
|
||||
draw_borders(ssize_t vao_idx, unsigned int num_border_rects, BorderRect *rect_buf, bool rect_data_is_dirty, uint32_t viewport_width, uint32_t viewport_height, color_type active_window_bg, unsigned int num_visible_windows, bool all_windows_have_same_bg, OSWindow *w) {
|
||||
glEnable(GL_BLEND);
|
||||
BLEND_ONTO_OPAQUE;
|
||||
|
||||
if (w->bgimage != NULL) {
|
||||
int program;
|
||||
if (OPT(background_image_layout) == TILING || OPT(background_image_layout) == MIRRORED) program = BGIMAGE_TILED_PROGRAM;
|
||||
else program = BGIMAGE_PROGRAM;
|
||||
|
||||
draw_bg(program, w);
|
||||
glEnable(GL_BLEND);
|
||||
BLEND_ONTO_OPAQUE;
|
||||
draw_bg((OPT(background_image_layout) == TILING || OPT(background_image_layout) == MIRRORED) ? BGIMAGE_TILED_PROGRAM : BGIMAGE_PROGRAM, w);
|
||||
}
|
||||
|
||||
if (num_border_rects) {
|
||||
@ -691,7 +670,7 @@ draw_borders(ssize_t vao_idx, unsigned int num_border_rects, BorderRect *rect_bu
|
||||
unbind_vertex_array();
|
||||
unbind_program();
|
||||
}
|
||||
glDisable(GL_BLEND);
|
||||
if (w->bgimage != NULL) glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
@ -169,8 +169,7 @@ typedef struct {
|
||||
monotonic_t last_render_frame_received_at;
|
||||
uint64_t render_calls;
|
||||
id_type last_focused_counter;
|
||||
ssize_t gvao_idx, bvao_idx;
|
||||
unsigned int vbo_idx;
|
||||
ssize_t gvao_idx;
|
||||
} OSWindow;
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user