return program;
}
+unsigned create_2d_texture()
+{
+ unsigned texture;
+ glGenTextures(1, &texture);
+ glBindTexture(GL_TEXTURE_2D, texture);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ return texture;
+}
+
int create_gl_resources(Compositor *compositor, CompositedScreen *screen)
{
unsigned stride;
glBindBuffer(GL_ARRAY_BUFFER, 0);
- glGenTextures(1, &screen->fb_texture);
- glBindTexture(GL_TEXTURE_2D, screen->fb_texture);
+ screen->fb_texture = create_2d_texture();
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, screen->width, screen->height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D, 0);
glGenFramebuffers(1, &screen->framebuffer);
return NULL;
}
+CompositedWindow *find_window_global(Compositor *compositor, Window w, CompositedScreen **screen)
+{
+ unsigned i, j;
+
+ for(i=0; i<compositor->nscreens; ++i)
+ for(j=0; j<compositor->screens[i].nwindows; ++j)
+ if(compositor->screens[i].windows[j].window==w)
+ {
+ if(screen)
+ *screen = &compositor->screens[i];
+ return &compositor->screens[i].windows[j];
+ }
+
+ if(screen)
+ *screen = NULL;
+ return NULL;
+}
+
void create_window_pixmap(Compositor *compositor, CompositedScreen *screen, CompositedWindow *window)
{
int attribs[5];
if(window->map_state==IsViewable)
create_window_pixmap(compositor, screen, window);
- glGenTextures(1, &window->texture);
- glBindTexture(GL_TEXTURE_2D, window->texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ window->texture = create_2d_texture();
return window;
}
return NULL;
}
-CompositedScreen *find_screen_by_window(Compositor *compositor, Window w)
-{
- unsigned i, j;
-
- for(i=0; i<compositor->nscreens; ++i)
- for(j=0; j<compositor->screens[i].nwindows; ++j)
- if(compositor->screens[i].windows[j].window==w)
- return &compositor->screens[i];
-
- return NULL;
-}
-
void update_monitor_vertices(CompositedScreen *screen, CompositedMonitor *monitor)
{
unsigned t;
unsigned x, y;
unsigned i;
float aspect;
- float cyl_w_sq;
+ float cyl_radius;
+ float cyl_arc;
float sin_ksv;
float cos_ksv;
+ float distance;
+ float eye[3];
+ float look[3];
t = monitor->tessellation;
data_size = (t+1)*(t+1)*4*sizeof(float);
vertex_data = (float *)malloc(data_size);
+
aspect = (float)monitor->width/monitor->height;
- cyl_w_sq = 0.25f-(0.5f-monitor->cylinder_depth)*(0.5f-monitor->cylinder_depth);
+
+ if(monitor->cylinder_depth)
+ {
+ cyl_radius = (monitor->cylinder_depth*monitor->cylinder_depth+0.25f)/(2.0f*monitor->cylinder_depth);
+ cyl_arc = 2.0f*asin(0.5f/cyl_radius);
+ }
+
sin_ksv = monitor->keystone_vertical/sqrt(1.0f+monitor->keystone_vertical*monitor->keystone_vertical);
cos_ksv = sqrt(1.0f-sin_ksv*sin_ksv);
+ distance = monitor->perspective+sin_ksv*((sin_ksv>0)-monitor->vertical_center)/aspect;
+
+ eye[0] = 0.0f;
+ eye[1] = (monitor->vertical_center-0.5f)/aspect+sin_ksv*distance;
+ eye[2] = cos_ksv*distance;
+
+ look[0] = 0.0f;
+ look[1] = -sin_ksv;
+ look[2] = -cos_ksv;
+
for(y=0; y<=t; ++y)
for(x=0; x<=t; ++x)
{
- float xf, yf, z, rz;
- float scale;
float *v;
- xf = (float)x/t;
- yf = (float)y/t;
-
- v = vertex_data+(y*(t+1)+x)*4;
- v[2] = (monitor->x+xf*monitor->width)/screen->width;
- v[3] = (monitor->y+yf*monitor->height)/screen->height;
-
- z = sqrt(0.25f-(xf-0.5f)*(xf-0.5f)*4.0f*cyl_w_sq)-0.5f+monitor->cylinder_depth;
- if(monitor->keystone_vertical>0)
- {
- rz = (1.0f-yf)/aspect*sin_ksv+z*cos_ksv;
- yf = 1.0f-((1.0f-yf)*cos_ksv-z*aspect*sin_ksv);
- z = rz;
- }
- else if(monitor->keystone_vertical<0)
+ v = vertex_data+(y*(t+1)+x)*3;
+ v[0] = (float)x/t-0.5f;
+ v[1] = ((float)y/t-0.5f)/aspect;
+ v[2] = 0;
+ if(monitor->cylinder_depth)
{
- rz = z*cos_ksv-yf/aspect*sin_ksv;
- yf = yf*cos_ksv+z*aspect*sin_ksv;
- z = rz;
+ v[2] = (1.0f-cos(v[0]*cyl_arc))*cyl_radius-monitor->cylinder_depth;
+ v[0] = sin(v[0]*cyl_arc)*cyl_radius;
}
- scale = monitor->perspective/(monitor->perspective+z);
- v[0] = 0.5f+(xf-0.5f)*scale;
- v[1] = monitor->vertical_center+(yf-monitor->vertical_center)*scale;
}
+
+ for(y=t; y<=t; --y)
+ for(x=t; x<=t; --x)
+ {
+ float *v;
+ float px, py, pz;
+ float scale;
+
+ v = vertex_data+(y*(t+1)+x)*3;
+ px = v[0]-eye[0];
+ py = (v[0]-eye[0])*look[0] - (v[1]-eye[1])*look[2] + (v[2]-eye[2])*look[1];
+ pz = (v[0]-eye[0])*look[0] + (v[1]-eye[1])*look[1] + (v[2]-eye[2])*look[2];
+ scale = monitor->perspective/pz;
+
+ v = vertex_data+(y*(t+1)+x)*4;
+ v[0] = px*scale+0.5f;
+ v[1] = py*aspect*scale+monitor->vertical_center;
+ v[2] = (monitor->x+(float)x*monitor->width/t)/screen->width;
+ v[3] = 1.0f-(monitor->y+(1.0f-(float)y/t)*monitor->height)/screen->height;
+ }
+
glBindBuffer(GL_ARRAY_BUFFER, monitor->vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, data_size, vertex_data, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
monitor->vertical_center = values[i*4+2]/10000.0f;
monitor->perspective = values[i*4+3]/10000.0f;
- update_monitor_vertices(screen, monitor);
+ if(monitor->enabled)
+ update_monitor_vertices(screen, monitor);
}
name_ptr += strlen(name_ptr)+1;
CompositedScreen *screen;
CompositedWindow *window;
- screen = find_screen_by_window(compositor, event->drawable);
- if(!screen)
- return;
-
- window = find_window(screen, event->drawable);
- if(window->map_state==IsViewable)
+ window = find_window_global(compositor, event->drawable, &screen);
+ if(window && window->map_state==IsViewable)
mark_dirty(compositor, screen);
}
if(window->map_state!=IsViewable)
continue;
+ XDamageSubtract(compositor->display, window->damage, None, None);
+
glBindTexture(GL_TEXTURE_2D, window->texture);
compositor->glXBindTexImageEXT(compositor->display, window->glx_pixmap, GLX_FRONT_LEFT_EXT, NULL);
glUniform4f(screen->geometry_loc,
- (float)window->x/screen->width, ((float)screen->height-window->y-window->height)/screen->height,
+ (float)window->x/screen->width, 1.0f-(float)(window->y+window->height)/screen->height,
(float)(window->width+2*window->border)/screen->width, (float)(window->height+2*window->border)/screen->height);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
compositor->glXReleaseTexImageEXT(compositor->display, window->glx_pixmap, GLX_FRONT_LEFT_EXT);
- XDamageSubtract(compositor->display, window->damage, None, None);
}
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
continue;
glUniform4f(screen->geometry_loc,
- (float)monitor->x/screen->width, (float)monitor->y/screen->height,
+ (float)monitor->x/screen->width, 1.0f-(float)(monitor->y+monitor->height)/screen->height,
(float)monitor->width/screen->width, (float)monitor->height/screen->height);
glBindVertexArray(monitor->vertex_array);