@@ -104,14 +104,12 @@ glx_init(session_t *ps, bool need_render) {
ps->psglx = cmalloc (1 , glx_session_t );
memcpy (ps->psglx , &CGLX_SESSION_DEF, sizeof (glx_session_t ));
#ifdef CONFIG_VSYNC_OPENGL_GLSL
for (int i = 0 ; i < MAX_BLUR_PASS; ++i) {
glx_blur_pass_t *ppass = &ps->psglx ->blur_passes [i];
ppass->unifm_factor_center = -1 ;
ppass->unifm_offset_x = -1 ;
ppass->unifm_offset_y = -1 ;
}
#endif
}
glx_session_t *psglx = ps->psglx ;
@@ -277,8 +275,6 @@ glx_init(session_t *ps, bool need_render) {
return success;
}
#ifdef CONFIG_VSYNC_OPENGL_GLSL
static void
glx_free_prog_main (session_t *ps, glx_prog_main_t *pprogram) {
if (!pprogram)
@@ -292,8 +288,6 @@ glx_free_prog_main(session_t *ps, glx_prog_main_t *pprogram) {
pprogram->unifm_tex = -1 ;
}
#endif
/* *
* Destroy GLX related resources.
*/
@@ -306,7 +300,6 @@ glx_destroy(session_t *ps) {
for (win *w = ps->list ; w; w = w->next )
free_win_res_glx (ps, w);
#ifdef CONFIG_VSYNC_OPENGL_GLSL
// Free GLSL shaders/programs
for (int i = 0 ; i < MAX_BLUR_PASS; ++i) {
glx_blur_pass_t *ppass = &ps->psglx ->blur_passes [i];
@@ -319,7 +312,6 @@ glx_destroy(session_t *ps) {
glx_free_prog_main (ps, &ps->o .glx_prog_win );
glx_check_err (ps);
#endif
// Free FBConfigs
for (int i = 0 ; i <= OPENGL_MAX_DEPTH; ++i) {
@@ -383,7 +375,6 @@ glx_init_blur(session_t *ps) {
// Allocate PBO if more than one blur kernel is present
if (ps->o .blur_kerns [1 ]) {
#ifdef CONFIG_VSYNC_OPENGL_FBO
// Try to generate a framebuffer
GLuint fbo = 0 ;
glGenFramebuffers (1 , &fbo);
@@ -393,14 +384,8 @@ glx_init_blur(session_t *ps) {
return false ;
}
glDeleteFramebuffers (1 , &fbo);
#else
printf_errf (" (): FBO support not compiled in. Cannot do multi-pass blur "
" with GLX backend." );
return false ;
#endif
}
#ifdef CONFIG_VSYNC_OPENGL_GLSL
{
char *lc_numeric_old = mstrcpy (setlocale (LC_NUMERIC, NULL ));
// Enforce LC_NUMERIC locale "C" here to make sure decimal point is sane
@@ -482,6 +467,12 @@ glx_init_blur(session_t *ps) {
assert (strlen (shader_str) < len);
}
ppass->frag_shader = glx_create_shader (GL_FRAGMENT_SHADER, shader_str);
{
FILE* fd = fopen (" shader.glsl" , " w" );
fprintf (fd, " %s \n " , shader_str);
fflush (fd);
}
free (shader_str);
}
@@ -524,14 +515,8 @@ glx_init_blur(session_t *ps) {
glx_check_err (ps);
return true ;
#else
printf_errf (" (): GLSL support not compiled in. Cannot do blur with GLX backend." );
return false ;
#endif
}
#ifdef CONFIG_VSYNC_OPENGL_GLSL
/* *
* Load a GLSL main program from shader strings.
*/
@@ -565,8 +550,6 @@ glx_load_prog_main(session_t *ps,
return true ;
}
#endif
/* *
* @brief Update the FBConfig of given depth.
*/
@@ -1157,7 +1140,6 @@ glx_copy_region_to_tex(session_t *ps, GLenum tex_tgt, int basex, int basey,
dx, ps->root_height - dy - height, width, height);
}
#ifdef CONFIG_VSYNC_OPENGL_GLSL
/* *
* Blur contents in a particular region.
*/
@@ -1220,22 +1202,18 @@ glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
pbc->width = mwidth;
pbc->height = mheight;
GLuint tex_scr2 = pbc->textures [1 ];
#ifdef CONFIG_VSYNC_OPENGL_FBO
if (more_passes && !pbc->fbo )
glGenFramebuffers (1 , &pbc->fbo );
const GLuint fbo = pbc->fbo ;
#endif
if (!tex_scr || (more_passes && !tex_scr2)) {
printf_errf (" (): Failed to allocate texture." );
goto glx_blur_dst_end;
}
#ifdef CONFIG_VSYNC_OPENGL_FBO
if (more_passes && !fbo) {
printf_errf (" (): Failed to allocate framebuffer." );
goto glx_blur_dst_end;
}
#endif
// Read destination pixels into a texture
glEnable (tex_tgt);
@@ -1275,7 +1253,6 @@ glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
assert (tex_scr);
glBindTexture (tex_tgt, tex_scr);
#ifdef CONFIG_VSYNC_OPENGL_FBO
if (!last_pass) {
static const GLenum DRAWBUFS[2 ] = { GL_COLOR_ATTACHMENT0 };
glBindFramebuffer (GL_FRAMEBUFFER, fbo);
@@ -1297,7 +1274,6 @@ glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
if (have_stencil)
glEnable (GL_STENCIL_TEST);
}
#endif
// Color negation for testing...
// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
@@ -1364,9 +1340,7 @@ glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
ret = true ;
glx_blur_dst_end:
#ifdef CONFIG_VSYNC_OPENGL_FBO
glBindFramebuffer (GL_FRAMEBUFFER, 0 );
#endif
glBindTexture (tex_tgt, 0 );
glDisable (tex_tgt);
if (have_scissors)
@@ -1382,7 +1356,6 @@ glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
return ret;
}
#endif
bool
glx_dim_dst (session_t *ps, int dx, int dy, int width, int height, float z,
@@ -1427,9 +1400,7 @@ glx_render_(session_t *ps, const glx_texture_t *ptex,
int x, int y, int dx, int dy, int width, int height, int z,
double opacity, bool argb, bool neg,
XserverRegion reg_tgt, const reg_data_t *pcache_reg
#ifdef CONFIG_VSYNC_OPENGL_GLSL
, const glx_prog_main_t *pprogram
#endif
) {
if (!ptex || !ptex->texture ) {
printf_errf (" (): Missing texture." );
@@ -1443,9 +1414,7 @@ glx_render_(session_t *ps, const glx_texture_t *ptex,
argb = argb || (GLX_TEXTURE_FORMAT_RGBA_EXT ==
ps->psglx ->fbconfigs [ptex->depth ]->texture_fmt );
#ifdef CONFIG_VSYNC_OPENGL_GLSL
const bool has_prog = pprogram && pprogram->prog ;
#endif
bool dual_texture = false ;
// It's required by legacy versions of OpenGL to enable texture target
@@ -1466,9 +1435,7 @@ glx_render_(session_t *ps, const glx_texture_t *ptex,
glColor4f (opacity, opacity, opacity, opacity);
}
#ifdef CONFIG_VSYNC_OPENGL_GLSL
if (!has_prog)
#endif
{
// The default, fixed-function path
// Color negation
@@ -1543,7 +1510,6 @@ glx_render_(session_t *ps, const glx_texture_t *ptex,
}
}
}
#ifdef CONFIG_VSYNC_OPENGL_GLSL
else {
// Programmable path
assert (pprogram->prog );
@@ -1555,7 +1521,6 @@ glx_render_(session_t *ps, const glx_texture_t *ptex,
if (pprogram->unifm_tex >= 0 )
glUniform1i (pprogram->unifm_tex , 0 );
}
#endif
#ifdef DEBUG_GLX
printf_dbgf (" (): Draw: %d , %d , %d , %d -> %d , %d (%d , %d ) z %d \n " , x, y, width, height, dx, dy, ptex->width , ptex->height , z);
@@ -1638,10 +1603,8 @@ glx_render_(session_t *ps, const glx_texture_t *ptex,
glActiveTexture (GL_TEXTURE0);
}
#ifdef CONFIG_VSYNC_OPENGL_GLSL
if (has_prog)
glUseProgram (0 );
#endif
glx_check_err (ps);
@@ -1780,7 +1743,6 @@ glx_take_screenshot(session_t *ps, int *out_length) {
return buf;
}
#ifdef CONFIG_VSYNC_OPENGL_GLSL
GLuint
glx_create_shader (GLenum shader_type, const char *shader_str) {
#ifdef DEBUG_GLX_GLSL
@@ -1902,5 +1864,4 @@ glx_create_program_from_str(const char *vert_shader_str,
return prog;
}
#endif