Commit 78ac6aaf authored by Martin Flöser's avatar Martin Flöser

[effects] Runtime checks for GLES instead of compile time checks

parent fc2805d2
......@@ -113,12 +113,7 @@ void ContrastShader::init()
{
reset();
#ifdef KWIN_HAVE_OPENGLES
const bool glsl_140 = false;
#else
const bool glsl_140 = GLPlatform::instance()->glslVersion() >= kVersionNumber(1, 40);
#endif
const bool glsl_140 = !GLPlatform::instance()->isGLES() && GLPlatform::instance()->glslVersion() >= kVersionNumber(1, 40);
QByteArray vertexSource;
QByteArray fragmentSource;
......
......@@ -173,18 +173,18 @@ void GLSLBlurShader::unbind()
int GLSLBlurShader::maxKernelSize() const
{
#ifdef KWIN_HAVE_OPENGLES
// GL_MAX_VARYING_FLOATS not available in GLES
// querying for GL_MAX_VARYING_VECTORS crashes on nouveau
// using the minimum value of 8
return 8 * 2;
#else
int value;
glGetIntegerv(GL_MAX_VARYING_FLOATS, &value);
// Maximum number of vec4 varyings * 2
// The code generator will pack two vec2's into each vec4.
return value / 2;
#endif
if (GLPlatform::instance()->isGLES()) {
// GL_MAX_VARYING_FLOATS not available in GLES
// querying for GL_MAX_VARYING_VECTORS crashes on nouveau
// using the minimum value of 8
return 8 * 2;
} else {
int value;
glGetIntegerv(GL_MAX_VARYING_FLOATS, &value);
// Maximum number of vec4 varyings * 2
// The code generator will pack two vec2's into each vec4.
return value / 2;
}
}
void GLSLBlurShader::init()
......@@ -208,11 +208,7 @@ void GLSLBlurShader::init()
offsets << vec4;
}
#ifdef KWIN_HAVE_OPENGLES
const bool glsl_140 = false;
#else
const bool glsl_140 = GLPlatform::instance()->glslVersion() >= kVersionNumber(1, 40);
#endif
const bool glsl_140 = !GLPlatform::instance()->isGLES() && GLPlatform::instance()->glslVersion() >= kVersionNumber(1, 40);
QByteArray vertexSource;
QByteArray fragmentSource;
......
......@@ -61,11 +61,7 @@ CoverSwitchEffect::CoverSwitchEffect()
if (effects->compositingType() == OpenGL2Compositing) {
QString shadersDir = QStringLiteral("kwin/shaders/1.10/");
#ifdef KWIN_HAVE_OPENGLES
const qint64 coreVersionNumber = kVersionNumber(3, 0);
#else
const qint64 coreVersionNumber = kVersionNumber(1, 40);
#endif
const qint64 coreVersionNumber = GLPlatform::instance()->isGLES() ? kVersionNumber(3, 0) : kVersionNumber(1, 40);
if (GLPlatform::instance()->glslVersion() >= coreVersionNumber)
shadersDir = QStringLiteral("kwin/shaders/1.40/");
const QString fragmentshader = QStandardPaths::locate(QStandardPaths::GenericDataLocation, shadersDir + QStringLiteral("coverswitch-reflection.glsl"));
......
......@@ -96,11 +96,7 @@ CubeEffect::CubeEffect()
desktopNameFont.setBold(true);
desktopNameFont.setPointSize(14);
#ifdef KWIN_HAVE_OPENGLES
const qint64 coreVersionNumber = kVersionNumber(3, 0);
#else
const qint64 coreVersionNumber = kVersionNumber(1, 40);
#endif
const qint64 coreVersionNumber = GLPlatform::instance()->isGLES() ? kVersionNumber(3, 0) : kVersionNumber(1, 40);
if (GLPlatform::instance()->glslVersion() >= coreVersionNumber)
m_shadersDir = QStringLiteral("kwin/shaders/1.40/");
......@@ -262,9 +258,9 @@ void CubeEffect::slotCubeCapLoaded()
effects->makeOpenGLContextCurrent();
capTexture = new GLTexture(img);
capTexture->setFilter(GL_LINEAR);
#ifndef KWIN_HAVE_OPENGLES
capTexture->setWrapMode(GL_CLAMP_TO_BORDER);
#endif
if (!GLPlatform::instance()->isGLES()) {
capTexture->setWrapMode(GL_CLAMP_TO_BORDER);
}
// need to recreate the VBO for the cube cap
delete m_cubeCapBuffer;
m_cubeCapBuffer = NULL;
......@@ -445,10 +441,10 @@ void CubeEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
m_reflectionMatrix.translate(0.0, sin(fabs(manualAngle) * M_PI / 360.0f * float(effects->numberOfDesktops())) * addedHeight2 + addedHeight1 - float(rect.height()), 0.0);
}
#ifndef KWIN_HAVE_OPENGLES
// TODO: find a solution for GLES
glEnable(GL_CLIP_PLANE0);
#endif
if (!GLPlatform::instance()->isGLES()) {
glEnable(GL_CLIP_PLANE0);
}
reflectionPainting = true;
glEnable(GL_CULL_FACE);
paintCap(true, -point - zTranslate);
......@@ -463,10 +459,10 @@ void CubeEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
paintCap(false, -point - zTranslate);
glDisable(GL_CULL_FACE);
reflectionPainting = false;
#ifndef KWIN_HAVE_OPENGLES
// TODO: find a solution for GLES
glDisable(GL_CLIP_PLANE0);
#endif
if (!GLPlatform::instance()->isGLES()) {
glDisable(GL_CLIP_PLANE0);
}
const float width = rect.width();
const float height = rect.height();
......@@ -1784,14 +1780,14 @@ void CubeEffect::setActive(bool active)
desktopChangedWhileRotating = false;
if (reflection) {
QRect rect = effects->clientArea(FullArea, activeScreen, effects->currentDesktop());
#ifndef KWIN_HAVE_OPENGLES
// clip parts above the reflection area
double eqn[4] = {0.0, 1.0, 0.0, 0.0};
glPushMatrix();
glTranslatef(0.0, rect.height(), 0.0);
glClipPlane(GL_CLIP_PLANE0, eqn);
glPopMatrix();
#endif
if (!GLPlatform::instance()->isGLES()) {
double eqn[4] = {0.0, 1.0, 0.0, 0.0};
glPushMatrix();
glTranslatef(0.0, rect.height(), 0.0);
glClipPlane(GL_CLIP_PLANE0, eqn);
glPopMatrix();
}
float temporaryCoeff = float(rect.width()) / tan(M_PI / float(effects->numberOfDesktops()));
mAddedHeightCoeff1 = sqrt(float(rect.height()) * float(rect.height()) + temporaryCoeff * temporaryCoeff);
mAddedHeightCoeff2 = sqrt(float(rect.height()) * float(rect.height()) + float(rect.width()) * float(rect.width()) + temporaryCoeff * temporaryCoeff);
......
......@@ -74,11 +74,7 @@ bool InvertEffect::loadData()
m_inited = true;
QString shadersDir = QStringLiteral("kwin/shaders/1.10/");
#ifdef KWIN_HAVE_OPENGLES
const qint64 coreVersionNumber = kVersionNumber(3, 0);
#else
const qint64 coreVersionNumber = kVersionNumber(1, 40);
#endif
const qint64 coreVersionNumber = GLPlatform::instance()->isGLES() ? kVersionNumber(3, 0) : kVersionNumber(1, 40);
if (GLPlatform::instance()->glslVersion() >= coreVersionNumber)
shadersDir = QStringLiteral("kwin/shaders/1.40/");
const QString fragmentshader = QStandardPaths::locate(QStandardPaths::GenericDataLocation, shadersDir + QStringLiteral("invert.frag"));
......
......@@ -62,11 +62,7 @@ LogoutEffect::LogoutEffect()
connect(effects, SIGNAL(propertyNotify(KWin::EffectWindow*,long)), this, SLOT(slotPropertyNotify(KWin::EffectWindow*,long)));
if (effects->isOpenGLCompositing()) {
#ifdef KWIN_HAVE_OPENGLES
const qint64 coreVersionNumber = kVersionNumber(3, 0);
#else
const qint64 coreVersionNumber = kVersionNumber(1, 40);
#endif
const qint64 coreVersionNumber = GLPlatform::instance()->isGLES() ? kVersionNumber(3, 0) : kVersionNumber(1, 40);
if (GLPlatform::instance()->glslVersion() >= coreVersionNumber)
m_shadersDir = QStringLiteral("kwin/shaders/1.40/");
}
......
......@@ -112,11 +112,7 @@ bool LookingGlassEffect::loadData()
}
QString shadersDir = QStringLiteral("kwin/shaders/1.10/");
#ifdef KWIN_HAVE_OPENGLES
const qint64 coreVersionNumber = kVersionNumber(3, 0);
#else
const qint64 coreVersionNumber = kVersionNumber(1, 40);
#endif
const qint64 coreVersionNumber = GLPlatform::instance()->isGLES() ? kVersionNumber(3, 0) : kVersionNumber(1, 40);
if (GLPlatform::instance()->glslVersion() >= coreVersionNumber)
shadersDir = QStringLiteral("kwin/shaders/1.40/");
const QString fragmentshader = QStandardPaths::locate(QStandardPaths::GenericDataLocation, shadersDir + QStringLiteral("lookingglass.frag"));
......
......@@ -26,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QAction>
#include <kwinconfig.h>
#include <kwinglplatform.h>
#include <kwinglutils.h>
#include <KGlobalAccel>
#include <KLocalizedString>
......@@ -116,9 +117,9 @@ void MouseMarkEffect::paintScreen(int mask, QRegion region, ScreenPaintData& dat
if (marks.isEmpty() && drawing.isEmpty())
return;
if ( effects->isOpenGLCompositing()) {
#ifndef KWIN_HAVE_OPENGLES
glEnable(GL_LINE_SMOOTH);
#endif
if (!GLPlatform::instance()->isGLES()) {
glEnable(GL_LINE_SMOOTH);
}
glLineWidth(width);
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
vbo->reset();
......@@ -145,9 +146,9 @@ void MouseMarkEffect::paintScreen(int mask, QRegion region, ScreenPaintData& dat
vbo->render(GL_LINE_STRIP);
}
glLineWidth(1.0);
#ifndef KWIN_HAVE_OPENGLES
glDisable(GL_LINE_SMOOTH);
#endif
if (!GLPlatform::instance()->isGLES()) {
glDisable(GL_LINE_SMOOTH);
}
}
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
if ( effects->compositingType() == XRenderCompositing) {
......
......@@ -19,6 +19,7 @@ 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 "screenshot.h"
#include <kwinglplatform.h>
#include <kwinglutils.h>
#include <kwinxrenderutils.h>
#include <QtCore/QTemporaryFile>
......@@ -237,11 +238,11 @@ QString ScreenShotEffect::blitScreenshot(const QRect &geometry)
// copy content from framebuffer into image
tex.bind();
img = QImage(geometry.size(), QImage::Format_ARGB32);
#ifdef KWIN_HAVE_OPENGLES
glReadPixels(0, 0, img.width(), img.height(), GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)img.bits());
#else
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)img.bits());
#endif
if (GLPlatform::instance()->isGLES()) {
glReadPixels(0, 0, img.width(), img.height(), GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)img.bits());
} else {
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)img.bits());
}
tex.unbind();
ScreenShotEffect::convertFromGLImage(img, geometry.width(), geometry.height());
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment