void glw_wirebox(glw_root_t *gr, const glw_rctx_t *rc) { glw_backend_root_t *gbr = &gr->gr_be; if(gbr->gbr_delayed_rendering) return; glw_load_program(gbr, NULL); glMatrixMode(GL_PROJECTION); glLoadMatrixf(projection); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(glw_mtx_get(rc->rc_mtx)); glDisable(GL_TEXTURE_2D); glBegin(GL_LINE_LOOP); glColor4f(1,1,1,1); glVertex3f(-1.0, -1.0, 0.0); glVertex3f( 1.0, -1.0, 0.0); glVertex3f( 1.0, 1.0, 0.0); glVertex3f(-1.0, 1.0, 0.0); glEnd(); glEnable(GL_TEXTURE_2D); }
void glw_wirecube(glw_root_t *gr, const glw_rctx_t *rc) { glw_backend_root_t *gbr = &gr->gr_be; if(gbr->gbr_delayed_rendering) return; glw_load_program(gbr, gbr->gbr_renderer_flat); glw_program_set_modelview(gbr, rc); glw_program_set_uniform_color(gbr, 1,1,1,1); glBegin(GL_LINE_LOOP); glVertex3f(-1.0, -1.0, -1.0); glVertex3f( 1.0, -1.0, -1.0); glVertex3f( 1.0, 1.0, -1.0); glVertex3f(-1.0, 1.0, -1.0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3f(-1.0, -1.0, 1.0); glVertex3f( 1.0, -1.0, 1.0); glVertex3f( 1.0, 1.0, 1.0); glVertex3f(-1.0, 1.0, 1.0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3f(-1.0, -1.0, 1.0); glVertex3f(-1.0, -1.0, -1.0); glVertex3f(-1.0, 1.0, -1.0); glVertex3f(-1.0, 1.0, 1.0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3f( 1.0, -1.0, 1.0); glVertex3f( 1.0, -1.0, -1.0); glVertex3f( 1.0, 1.0, -1.0); glVertex3f( 1.0, 1.0, 1.0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3f( 1.0, -1.0, 1.0); glVertex3f( 1.0, -1.0, -1.0); glVertex3f(-1.0, -1.0, -1.0); glVertex3f(-1.0, -1.0, 1.0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3f( 1.0, 1.0, 1.0); glVertex3f( 1.0, 1.0, -1.0); glVertex3f(-1.0, 1.0, -1.0); glVertex3f(-1.0, 1.0, 1.0); glEnd(); }
/** * Video widget render */ void glw_render_video_quad(int interlace, int rectmode, int width, int height, int bob1, int bob2, glw_backend_root_t *gbr, glw_program_t *gp, const glw_video_t *gv, glw_rctx_t *rc) { float x1, x2, y1, y2; float b1 = 0, b2 = 0; static const float vertices[8] = {-1, -1, 1, -1, 1, 1, -1, 1}; const uint8_t elements[6] = {0,1,2,0,2,3}; float tc[12]; x1 = 0; y1 = 0; if(rectmode) { x2 = width; y2 = height; } else { x2 = 1; y2 = 1; if(interlace) { b1 = (0.5 * bob1) / (float)height; b2 = (0.5 * bob2) / (float)height; } } tc[0] = x1; tc[1] = y2 - b1; tc[2] = y2 - b2; tc[3] = x2; tc[4] = y2 - b1; tc[5] = y2 - b2; tc[6] = x2; tc[7] = y1 - b1; tc[8] = y1 - b2; tc[9] = x1; tc[10] = y1 - b1; tc[11] = y1 - b2; glw_load_program(gbr, gp); glw_program_set_uniform_color(gbr, 1, 1, 1, rc->rc_alpha); glw_program_set_modelview(gbr, rc); if(gp->gp_uniform_blend != -1) glUniform1f(gp->gp_uniform_blend, gv->gv_blend); if(gp->gp_uniform_colormtx != -1) glUniformMatrix4fv(gp->gp_uniform_colormtx, 1, GL_FALSE, gv->gv_cmatrix_cur); glVertexAttribPointer(gp->gp_attribute_texcoord, 3, GL_FLOAT, 0, 0, tc); glVertexAttribPointer(gp->gp_attribute_position, 2, GL_FLOAT, 0, 0, vertices); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, elements); }
static void vdpau_render(glw_video_t *gv, glw_rctx_t *rc) { glw_root_t *gr = gv->w.glw_root; vdpau_dev_t *vd = gr->gr_be.gbr_vdpau_dev; glw_backend_root_t *gbr = &gv->w.glw_root->gr_be; if(!gv->gv_vdpau_running) return; glDisable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_RECTANGLE_ARB); if(gv->gv_vdpau_texture == 0) { glGenTextures(1, &gv->gv_vdpau_texture); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, gv->gv_vdpau_texture); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } else { glBindTexture(GL_TEXTURE_RECTANGLE_ARB, gv->gv_vdpau_texture); } gr->gr_be.gbr_bind_tex_image(vd->vd_dpy, gv->gv_glx_pixmap, GLX_FRONT_LEFT_EXT, NULL); #if 0 int w = gv->gv_rwidth - 1; int h = gv->gv_rheight - 1; #else int w = gv->gv_fwidth - 1; int h = gv->gv_fheight - 1; #endif glMatrixMode(GL_PROJECTION); glLoadMatrixf(projmtx); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(glw_mtx_get(rc->rc_mtx)); glw_load_program(gbr, NULL); glColor4f(1,1,1,1); glBegin(GL_QUADS); glTexCoord2f(0, h); glVertex3f(-1.0, -1.0, 0.0); glTexCoord2f(w, h); glVertex3f( 1.0, -1.0, 0.0); glTexCoord2f(w, 0); glVertex3f( 1.0, 1.0, 0.0); glTexCoord2f(0, 0); glVertex3f(-1.0, 1.0, 0.0); glEnd(); gr->gr_be.gbr_release_tex_image(vd->vd_dpy, gv->gv_glx_pixmap, GLX_FRONT_LEFT_EXT); glDisable(GL_TEXTURE_RECTANGLE_ARB); glEnable(GL_TEXTURE_2D); }
/** * Render function using OpenGL shaders */ static void shader_render(struct glw_root *root, Mtx m, struct glw_backend_texture *tex, const struct glw_rgb *rgb_mul, const struct glw_rgb *rgb_off, float alpha, float blur, const float *vertices, int num_vertices, const uint16_t *indices, int num_triangles, int flags) { glw_backend_root_t *gbr = &root->gr_be; glw_program_t *gp; if(tex == NULL) { gp = gbr->gbr_renderer_flat; } else { if(blur > 0.05) { gp = gbr->gbr_renderer_tex_blur; } else { gp = gbr->gbr_renderer_tex; } glBindTexture(gbr->gbr_primary_texture_mode, tex->tex); } if(gp == NULL) return; glw_load_program(gbr, gp); if(rgb_off != NULL) glUniform4f(gp->gp_uniform_color_offset, rgb_off->r, rgb_off->g, rgb_off->b, 0); else glUniform4f(gp->gp_uniform_color_offset, 0,0,0,0); switch(gbr->be_blendmode) { case GLW_BLEND_NORMAL: glw_program_set_uniform_color(gbr, rgb_mul->r, rgb_mul->g, rgb_mul->b, alpha); break; case GLW_BLEND_ADDITIVE: glw_program_set_uniform_color(gbr, rgb_mul->r * alpha, rgb_mul->g * alpha, rgb_mul->b * alpha, 1); break; } if(blur > 0.05 && tex != NULL) { glUniform2f(gp->gp_uniform_blur_amount, 1.5 * blur / tex->width, 1.5 * blur / tex->height); } glUniformMatrix4fv(gp->gp_uniform_modelview, 1, 0, glw_mtx_get(m) ?: glw_identitymtx); glVertexAttribPointer(gp->gp_attribute_position, 3, GL_FLOAT, 0, sizeof(float) * VERTEX_SIZE, vertices); glVertexAttribPointer(gp->gp_attribute_color, 4, GL_FLOAT, 0, sizeof(float) * VERTEX_SIZE, vertices + 5); if(gp->gp_attribute_texcoord != -1) glVertexAttribPointer(gp->gp_attribute_texcoord, 2, GL_FLOAT, 0, sizeof(float) * VERTEX_SIZE, vertices + 3); if(indices != NULL) glDrawElements(GL_TRIANGLES, num_triangles * 3, GL_UNSIGNED_SHORT, indices); else glDrawArrays(GL_TRIANGLES, 0, num_vertices); }
/** * Render function using OpenGL shaders */ static void shader_render(struct glw_root *root, const Mtx m, const struct glw_backend_texture *t0, const struct glw_backend_texture *t1, const struct glw_rgb *rgb_mul, const struct glw_rgb *rgb_off, float alpha, float blur, const float *vertices, int num_vertices, const uint16_t *indices, int num_triangles, int flags, glw_program_t *up, const glw_rctx_t *rc) { glw_backend_root_t *gbr = &root->gr_be; if(rgb_off != NULL) flags |= GLW_RENDER_COLOR_OFFSET; glw_program_t *gp = get_program(gbr, t0, t1, blur, flags, up); if(gp == NULL) return; glw_load_program(gbr, gp); if(rgb_off != NULL) glUniform4f(gp->gp_uniform_color_offset, rgb_off->r, rgb_off->g, rgb_off->b, 0); else glUniform4f(gp->gp_uniform_color_offset, 0,0,0,0); switch(gbr->gbr_blendmode) { case GLW_BLEND_NORMAL: glw_program_set_uniform_color(gbr, rgb_mul->r, rgb_mul->g, rgb_mul->b, alpha); break; case GLW_BLEND_ADDITIVE: glw_program_set_uniform_color(gbr, rgb_mul->r * alpha, rgb_mul->g * alpha, rgb_mul->b * alpha, 1); break; } if(gp->gp_uniform_time != -1) glUniform1f(gp->gp_uniform_time, root->gr_time_sec); if(gp->gp_uniform_resolution != -1) glUniform2f(gp->gp_uniform_resolution, rc->rc_width, rc->rc_height); if(gp->gp_uniform_blur != -1 && t0 != NULL) glUniform3f(gp->gp_uniform_blur, blur, 1.5 / t0->width, 1.5 / t0->height); glUniformMatrix4fv(gp->gp_uniform_modelview, 1, 0, glw_mtx_get(m) ?: glw_identitymtx); glVertexAttribPointer(gp->gp_attribute_position, 4, GL_FLOAT, 0, sizeof(float) * VERTEX_SIZE, vertices); glVertexAttribPointer(gp->gp_attribute_color, 4, GL_FLOAT, 0, sizeof(float) * VERTEX_SIZE, vertices + 4); if(gp->gp_attribute_texcoord != -1) glVertexAttribPointer(gp->gp_attribute_texcoord, 4, GL_FLOAT, 0, sizeof(float) * VERTEX_SIZE, vertices + 8); if(indices != NULL) glDrawElements(GL_TRIANGLES, num_triangles * 3, GL_UNSIGNED_SHORT, indices); else glDrawArrays(GL_TRIANGLES, 0, num_vertices); }
static void render_unlocked(glw_root_t *gr) { glw_backend_root_t *gbr = &gr->gr_be; int i; struct render_job *rj = gbr->gbr_render_jobs; int64_t ts = showtime_get_ts(); int current_blendmode = GLW_BLEND_NORMAL; glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); int program_switches = 0; const float *vertices = gbr->gbr_vertex_buffer; glBindBuffer(GL_ARRAY_BUFFER, gbr->gbr_vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(float) * VERTEX_SIZE * gbr->gbr_vertex_offset, vertices, GL_STATIC_DRAW); vertices = NULL; glVertexAttribPointer(0, 4, GL_FLOAT, 0, sizeof(float) * VERTEX_SIZE, vertices); glVertexAttribPointer(1, 4, GL_FLOAT, 0, sizeof(float) * VERTEX_SIZE, vertices + 4); glVertexAttribPointer(2, 4, GL_FLOAT, 0, sizeof(float) * VERTEX_SIZE, vertices + 8); for(i = 0; i < gbr->gbr_num_render_jobs; i++, rj++) { const struct glw_backend_texture *t0 = rj->t0; glw_program_t *gp = get_program(gbr, t0, rj->t1, rj->blur, rj->flags, rj->up); if(gp == NULL) continue; if(glw_load_program(gbr, gp)) { program_switches++; } glUniform4f(gp->gp_uniform_color_offset, rj->rgb_off.r, rj->rgb_off.g, rj->rgb_off.b, 0); glw_program_set_uniform_color(gbr, rj->rgb_mul.r, rj->rgb_mul.g, rj->rgb_mul.b, rj->alpha); if(gp->gp_uniform_time != -1) glUniform1f(gp->gp_uniform_time, gr->gr_time_sec); if(gp->gp_uniform_resolution != -1) glUniform2f(gp->gp_uniform_resolution, rj->width, rj->height); if(gp->gp_uniform_blur != -1 && t0 != NULL) glUniform3f(gp->gp_uniform_blur, rj->blur, 1.5 / t0->width, 1.5 / t0->height); if(rj->eyespace) { glUniformMatrix4fv(gp->gp_uniform_modelview, 1, 0, glw_identitymtx); } else { glUniformMatrix4fv(gp->gp_uniform_modelview, 1, 0, glw_mtx_get(rj->m)); } if(current_blendmode != rj->blendmode) { current_blendmode = rj->blendmode; switch(current_blendmode) { case GLW_BLEND_NORMAL: glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); break; case GLW_BLEND_ADDITIVE: glBlendFuncSeparate(GL_SRC_COLOR, GL_ONE, GL_ONE, GL_ONE); break; } } glDrawArrays(GL_TRIANGLES, rj->vertex_offset, rj->num_vertices); } if(current_blendmode != GLW_BLEND_NORMAL) { glBlendFuncSeparate(GL_SRC_COLOR, GL_ONE, GL_ONE, GL_ONE); } ts = showtime_get_ts() - ts; static int hold; hold++; if(hold < 20) return; static int cnt; static int64_t tssum; tssum += ts; cnt++; // printf("%16d (%d) %d switches\n", (int)ts, (int)(tssum/cnt), program_switches); }