Initial import of new sphere effect. This effect uses a shader to transform the cube into a sphere. Caps are not yet working and are disabled. Fragment shader is shared with cylinder effect.
svn path=/trunk/KDE/kdebase/workspace/; revision=843611
This commit is contained in:
parent
085abe58b2
commit
6ba3e9fac4
5 changed files with 266 additions and 0 deletions
|
@ -119,6 +119,7 @@ if(KWIN_HAVE_OPENGL_COMPOSITING)
|
|||
magnifier.cpp
|
||||
mousemark.cpp
|
||||
sharpen.cpp
|
||||
sphere.cpp
|
||||
snow.cpp
|
||||
trackmouse.cpp
|
||||
wobblywindows.cpp
|
||||
|
@ -135,6 +136,7 @@ if(KWIN_HAVE_OPENGL_COMPOSITING)
|
|||
magnifier.desktop
|
||||
mousemark.desktop
|
||||
sharpen.desktop
|
||||
sphere.desktop
|
||||
snow.desktop
|
||||
trackmouse.desktop
|
||||
wobblywindows.desktop
|
||||
|
@ -162,6 +164,7 @@ if(KWIN_HAVE_OPENGL_COMPOSITING)
|
|||
data/cubecap.png
|
||||
data/cylinder.frag
|
||||
data/cylinder.vert
|
||||
data/sphere.vert
|
||||
DESTINATION ${DATA_INSTALL_DIR}/kwin )
|
||||
SET(kwin4_effect_builtins_config_sources ${kwin4_effect_builtins_config_sources}
|
||||
coverswitch_config.cpp
|
||||
|
|
40
effects/data/sphere.vert
Normal file
40
effects/data/sphere.vert
Normal file
|
@ -0,0 +1,40 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2008 Martin Gräßlin <ubuntu@martin-graesslin.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************/
|
||||
uniform float width;
|
||||
uniform float height;
|
||||
uniform float cubeAngle;
|
||||
uniform float xCoord;
|
||||
uniform float yCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_TexCoord[0].xy = gl_Vertex.xy;
|
||||
vec3 vertex = vec3( gl_Vertex.xy - vec2( width*0.5 - xCoord, height*0.5 - yCoord ), gl_Vertex.z );
|
||||
float radian = radians(cubeAngle*0.5);
|
||||
float radius = (width*0.5)/cos(radian);
|
||||
float zenithAngle = acos( vertex.y/radius );
|
||||
float azimuthAngle = asin( vertex.x/radius );
|
||||
vertex.z = radius * sin( zenithAngle ) * cos( azimuthAngle ) - radius*cos( radians( 90.0 - cubeAngle*0.5 ) );
|
||||
vertex.x = radius * sin( zenithAngle ) * sin( azimuthAngle );
|
||||
|
||||
vertex.xy += vec2( width*0.5 - xCoord, height*0.5 - yCoord );
|
||||
|
||||
gl_Position = gl_ModelViewProjectionMatrix * vec4( vertex, 1.0 );
|
||||
}
|
155
effects/sphere.cpp
Normal file
155
effects/sphere.cpp
Normal file
|
@ -0,0 +1,155 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2008 Martin Gräßlin <ubuntu@martin-graesslin.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************/
|
||||
#include "cube.h"
|
||||
#include "sphere.h"
|
||||
|
||||
#include <kdebug.h>
|
||||
#include <KStandardDirs>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
KWIN_EFFECT( sphere, SphereEffect )
|
||||
|
||||
SphereEffect::SphereEffect()
|
||||
: CubeEffect()
|
||||
, mInited( false )
|
||||
, mValid( true )
|
||||
, mShader( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
SphereEffect::~SphereEffect()
|
||||
{
|
||||
delete mShader;
|
||||
}
|
||||
|
||||
bool SphereEffect::loadData()
|
||||
{
|
||||
mInited = true;
|
||||
QString fragmentshader = KGlobal::dirs()->findResource("data", "kwin/cylinder.frag");
|
||||
QString vertexshader = KGlobal::dirs()->findResource("data", "kwin/sphere.vert");
|
||||
if( fragmentshader.isEmpty() || vertexshader.isEmpty() )
|
||||
{
|
||||
kError() << "Couldn't locate shader files" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
mShader = new GLShader( vertexshader, fragmentshader );
|
||||
if( !mShader->isValid() )
|
||||
{
|
||||
kError() << "The shader failed to load!" << endl;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
mShader->bind();
|
||||
mShader->setUniform( "winTexture", 0 );
|
||||
mShader->setUniform( "opacity", cubeOpacity );
|
||||
QRect rect = effects->clientArea( FullScreenArea, activeScreen, effects->currentDesktop());
|
||||
mShader->setUniform( "width", (float)rect.width() );
|
||||
mShader->setUniform( "height", (float)rect.height() );
|
||||
mShader->unbind();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SphereEffect::paintScene( int mask, QRegion region, ScreenPaintData& data )
|
||||
{
|
||||
glPushMatrix();
|
||||
QRect rect = effects->clientArea( FullArea, activeScreen, effects->currentDesktop() );
|
||||
|
||||
float cubeAngle = (effects->numberOfDesktops() - 2 )/(float)effects->numberOfDesktops() * 180.0f;
|
||||
float radian = (cubeAngle*0.5)*M_PI/180;
|
||||
// height of the triangle compound of one side of the cube and the two bisecting lines
|
||||
float midpoint = rect.width()*0.5*tan(radian);
|
||||
// radius of the circle
|
||||
float radius = (rect.width()*0.5)/cos(radian);
|
||||
//glTranslatef( 0.0, 0.0, midpoint - radius );
|
||||
CubeEffect::paintScene( mask, region, data );
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void SphereEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time )
|
||||
{
|
||||
if( activated )
|
||||
{
|
||||
if( cube_painting )
|
||||
{
|
||||
if( w->isOnDesktop( painting_desktop ))
|
||||
{
|
||||
data.quads = data.quads.makeGrid( 40 );
|
||||
QRect rect = effects->clientArea( FullArea, activeScreen, painting_desktop );
|
||||
if( w->x() < rect.width()/2 && w->x() + w->width() > rect.width()/ 2 )
|
||||
data.quads = data.quads.splitAtX( rect.width()/2 - w->x() );
|
||||
w->enablePainting( EffectWindow::PAINT_DISABLED_BY_DESKTOP );
|
||||
}
|
||||
else
|
||||
{
|
||||
w->disablePainting( EffectWindow::PAINT_DISABLED_BY_DESKTOP );
|
||||
}
|
||||
}
|
||||
}
|
||||
effects->prePaintWindow( w, data, time );
|
||||
}
|
||||
|
||||
void SphereEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
|
||||
{
|
||||
if( activated && cube_painting )
|
||||
{
|
||||
if( mValid && !mInited )
|
||||
mValid = loadData();
|
||||
bool useShader = mValid;
|
||||
if( useShader )
|
||||
{
|
||||
mShader->bind();
|
||||
mShader->setUniform( "windowWidth", (float)w->width() );
|
||||
mShader->setUniform( "windowHeight", (float)w->height() );
|
||||
mShader->setUniform( "xCoord", (float)w->x() );
|
||||
mShader->setUniform( "yCoord", (float)w->y() );
|
||||
mShader->setUniform( "cubeAngle", (effects->numberOfDesktops() - 2 )/(float)effects->numberOfDesktops() * 180.0f );
|
||||
data.shader = mShader;
|
||||
}
|
||||
CubeEffect::paintWindow( w, mask, region, data );
|
||||
if( useShader )
|
||||
{
|
||||
mShader->unbind();
|
||||
}
|
||||
}
|
||||
else
|
||||
effects->paintWindow( w, mask, region, data );
|
||||
}
|
||||
|
||||
void SphereEffect::desktopChanged( int old )
|
||||
{
|
||||
// cylinder effect is not useful to slide
|
||||
}
|
||||
|
||||
void SphereEffect::paintCap( float z, float zTexture )
|
||||
{
|
||||
// TODO: caps
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
17
effects/sphere.desktop
Normal file
17
effects/sphere.desktop
Normal file
|
@ -0,0 +1,17 @@
|
|||
[Desktop Entry]
|
||||
Name=Desktop Sphere
|
||||
Icon=preferences-system-windows-effect-sphere
|
||||
Comment=Map virtual desktops on a sphere
|
||||
|
||||
Type=Service
|
||||
X-KDE-ServiceTypes=KWin/Effect
|
||||
X-KDE-PluginInfo-Author=Martin Gräßlin
|
||||
X-KDE-PluginInfo-Email=ubuntu@martin-graesslin.com
|
||||
X-KDE-PluginInfo-Name=kwin4_effect_sphere
|
||||
X-KDE-PluginInfo-Version=0.1.0
|
||||
X-KDE-PluginInfo-Category=Window Management
|
||||
X-KDE-PluginInfo-Depends=
|
||||
X-KDE-PluginInfo-License=GPL
|
||||
X-KDE-PluginInfo-EnabledByDefault=false
|
||||
X-KDE-Library=kwin4_effect_builtins
|
||||
X-KDE-Ordering=50
|
51
effects/sphere.h
Normal file
51
effects/sphere.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2008 Martin Gräßlin <ubuntu@martin-graesslin.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************/
|
||||
|
||||
#ifndef KWIN_SPHERE_H
|
||||
#define KWIN_SPHERE_H
|
||||
|
||||
#include <kwineffects.h>
|
||||
#include <kwinglutils.h>
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
class SphereEffect
|
||||
: public CubeEffect
|
||||
{
|
||||
public:
|
||||
SphereEffect();
|
||||
~SphereEffect();
|
||||
virtual void prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time );
|
||||
virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
|
||||
virtual void desktopChanged( int old );
|
||||
protected:
|
||||
virtual void paintScene( int mask, QRegion region, ScreenPaintData& data );
|
||||
virtual void paintCap( float z, float zTexture );
|
||||
private:
|
||||
bool loadData();
|
||||
bool mInited;
|
||||
bool mValid;
|
||||
GLShader* mShader;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue