From 9f414720853c3f31e369522151e99ab50bbfdc13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Fri, 4 Feb 2011 16:41:55 +0100 Subject: [PATCH 1/7] kwin: Change the shader source code parameters from QStrings to QByteArrays. This eliminates the QByteArray -> QString -> QByteArray conversions. --- lib/kwinglutils.cpp | 22 +++++++++++----------- lib/kwinglutils.h | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/kwinglutils.cpp b/lib/kwinglutils.cpp index 4cd5c56842..276911e191 100644 --- a/lib/kwinglutils.cpp +++ b/lib/kwinglutils.cpp @@ -860,23 +860,23 @@ bool GLShader::loadFromFiles(const QString& vertexfile, const QString& fragmentf kError(1212) << "Couldn't open '" << vertexfile << "' for reading!" << endl; return false; } - QString vertexsource(vf.readAll()); + const QByteArray vertexSource = vf.readAll(); QFile ff(fragmentfile); if (!ff.open(QIODevice::ReadOnly)) { kError(1212) << "Couldn't open '" << fragmentfile << "' for reading!" << endl; return false; } - QString fragsource(ff.readAll()); + const QByteArray fragmentSource = ff.readAll(); - return load(vertexsource, fragsource); + return load(vertexSource, fragmentSource); } -bool GLShader::load(const QString& vertexsource, const QString& fragmentsource) +bool GLShader::load(const QByteArray &vertexSource, const QByteArray &fragmentSource) { // Make sure shaders are actually supported - if ((!vertexsource.isEmpty() && !vertexShaderSupported()) || - (!fragmentsource.isEmpty() && !fragmentShaderSupported())) { + if ((!vertexSource.isEmpty() && !vertexShaderSupported()) || + (!fragmentSource.isEmpty() && !fragmentShaderSupported())) { kDebug(1212) << "Shaders not supported"; return false; } @@ -889,7 +889,7 @@ bool GLShader::load(const QString& vertexsource, const QString& fragmentsource) // Create program object mProgram = glCreateProgram(); - if (!vertexsource.isEmpty()) { + if (!vertexSource.isEmpty()) { // Create shader object vertexshader = glCreateShader(GL_VERTEX_SHADER); // Load it @@ -897,7 +897,7 @@ bool GLShader::load(const QString& vertexsource, const QString& fragmentsource) #ifdef KWIN_HAVE_OPENGLES srcba.append("#ifdef GL_ES\nprecision highp float;\n#endif\n"); #endif - srcba.append(vertexsource.toLatin1()); + srcba.append(vertexSource); const char* src = srcba.data(); glShaderSource(vertexshader, 1, &src, NULL); // Compile the shader @@ -923,14 +923,14 @@ bool GLShader::load(const QString& vertexsource, const QString& fragmentsource) } - if (!fragmentsource.isEmpty()) { + if (!fragmentSource.isEmpty()) { fragmentshader = glCreateShader(GL_FRAGMENT_SHADER); // Load it QByteArray srcba; #ifdef KWIN_HAVE_OPENGLES srcba.append("#ifdef GL_ES\nprecision highp float;\n#endif\n"); #endif - srcba.append(fragmentsource.toLatin1()); + srcba.append(fragmentSource); const char* src = srcba.data(); glShaderSource(fragmentshader, 1, &src, NULL); //glShaderSource(fragmentshader, 1, &fragmentsrc.latin1(), NULL); @@ -1272,7 +1272,7 @@ GLShader *ShaderManager::loadVertexShader(ShaderType fragment, const QString &ve return shader; } -GLShader *ShaderManager::loadShaderFromCode(const QString &vertexSource, const QString &fragmentSource) +GLShader *ShaderManager::loadShaderFromCode(const QByteArray &vertexSource, const QByteArray &fragmentSource) { GLShader *shader = new GLShader(); shader->load(vertexSource, fragmentSource); diff --git a/lib/kwinglutils.h b/lib/kwinglutils.h index 02c286eefa..83aa31cb2f 100644 --- a/lib/kwinglutils.h +++ b/lib/kwinglutils.h @@ -327,7 +327,7 @@ public: protected: GLShader(); bool loadFromFiles(const QString& vertexfile, const QString& fragmentfile); - bool load(const QString& vertexsource, const QString& fragmentsource); + bool load(const QByteArray &vertexSource, const QByteArray &fragmentSource); void bind(); void unbind(); @@ -455,7 +455,7 @@ public: * @param fragmentSource The source code of the fragment shader. * @return The created shader **/ - GLShader *loadShaderFromCode(const QString &vertexSource, const QString &fragmentSource); + GLShader *loadShaderFromCode(const QByteArray &vertexSource, const QByteArray &fragmentSource); /** * @return a pointer to the ShaderManager instance From f21ccf028a473b35c1a0ff61ce74407d7aba7999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Fri, 4 Feb 2011 17:03:56 +0100 Subject: [PATCH 2/7] kwin: Clean up the shader compilation code a bit. --- lib/kwinglutils.cpp | 171 +++++++++++++++++++++----------------------- lib/kwinglutils.h | 1 + 2 files changed, 83 insertions(+), 89 deletions(-) diff --git a/lib/kwinglutils.cpp b/lib/kwinglutils.cpp index 276911e191..badb0e9524 100644 --- a/lib/kwinglutils.cpp +++ b/lib/kwinglutils.cpp @@ -853,18 +853,18 @@ GLShader::~GLShader() } } -bool GLShader::loadFromFiles(const QString& vertexfile, const QString& fragmentfile) +bool GLShader::loadFromFiles(const QString &vertexFile, const QString &fragmentFile) { - QFile vf(vertexfile); + QFile vf(vertexFile); if (!vf.open(QIODevice::ReadOnly)) { - kError(1212) << "Couldn't open '" << vertexfile << "' for reading!" << endl; + kError(1212) << "Couldn't open" << vertexFile << "for reading!" << endl; return false; } const QByteArray vertexSource = vf.readAll(); - QFile ff(fragmentfile); + QFile ff(fragmentFile); if (!ff.open(QIODevice::ReadOnly)) { - kError(1212) << "Couldn't open '" << fragmentfile << "' for reading!" << endl; + kError(1212) << "Couldn't open" << fragmentFile << "for reading!" << endl; return false; } const QByteArray fragmentSource = ff.readAll(); @@ -872,107 +872,100 @@ bool GLShader::loadFromFiles(const QString& vertexfile, const QString& fragmentf return load(vertexSource, fragmentSource); } +bool GLShader::compile(GLuint program, GLenum shaderType, const QByteArray &source) const +{ + GLuint shader = glCreateShader(shaderType); + + // Prepare the source code + QByteArray ba; +#ifdef KWIN_HAVE_OPENGLES + ba.append("#ifdef GL_ES\nprecision highp float;\n#endif\n"); +#endif + ba.append(source); + + const char* src = ba.constData(); + glShaderSource(shader, 1, &src, NULL); + + // Compile the shader + glCompileShader(shader); + + // Get the shader info log + int maxLength, length; + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength); + + QByteArray log(maxLength, 0); + glGetShaderInfoLog(shader, maxLength, &length, log.data()); + + // Check the status + int status; + glGetShaderiv(shader, GL_COMPILE_STATUS, &status); + + if (status == 0) { + const char *typeName = (shaderType == GL_VERTEX_SHADER ? "vertex" : "fragment"); + kError(1212) << "Failed to compile" << typeName << "shader:" << endl << log << endl; + } else if (length > 0) + kDebug(1212) << "Shader compile log:" << log; + + if (status != 0) + glAttachShader(program, shader); + + glDeleteShader(shader); + return status != 0; +} + bool GLShader::load(const QByteArray &vertexSource, const QByteArray &fragmentSource) { // Make sure shaders are actually supported - if ((!vertexSource.isEmpty() && !vertexShaderSupported()) || - (!fragmentSource.isEmpty() && !fragmentShaderSupported())) { - kDebug(1212) << "Shaders not supported"; + if (!vertexShaderSupported() || !fragmentShaderSupported()) { + kError(1212) << "Shaders are not supported"; return false; } - GLuint vertexshader; - GLuint fragmentshader; - - GLsizei logsize, logarraysize; - char* log = 0; - - // Create program object + // Create the shader program mProgram = glCreateProgram(); + + // Compile the vertex shader if (!vertexSource.isEmpty()) { - // Create shader object - vertexshader = glCreateShader(GL_VERTEX_SHADER); - // Load it - QByteArray srcba; -#ifdef KWIN_HAVE_OPENGLES - srcba.append("#ifdef GL_ES\nprecision highp float;\n#endif\n"); -#endif - srcba.append(vertexSource); - const char* src = srcba.data(); - glShaderSource(vertexshader, 1, &src, NULL); - // Compile the shader - glCompileShader(vertexshader); - // Make sure it compiled correctly - int compiled; - glGetShaderiv(vertexshader, GL_COMPILE_STATUS, &compiled); - // Get info log - glGetShaderiv(vertexshader, GL_INFO_LOG_LENGTH, &logarraysize); - log = new char[logarraysize]; - glGetShaderInfoLog(vertexshader, logarraysize, &logsize, log); - if (!compiled) { - kError(1212) << "Couldn't compile vertex shader! Log:" << endl << log << endl; - delete[] log; + bool success = compile(mProgram, GL_VERTEX_SHADER, vertexSource); + + if (!success) { + glDeleteProgram(mProgram); + mProgram = 0; return false; - } else if (logsize > 0) - kDebug(1212) << "Vertex shader compilation log:" << log; - // Attach the shader to the program - glAttachShader(mProgram, vertexshader); - // Delete shader - glDeleteShader(vertexshader); - delete[] log; + } } - + // Compile the fragment shader if (!fragmentSource.isEmpty()) { - fragmentshader = glCreateShader(GL_FRAGMENT_SHADER); - // Load it - QByteArray srcba; -#ifdef KWIN_HAVE_OPENGLES - srcba.append("#ifdef GL_ES\nprecision highp float;\n#endif\n"); -#endif - srcba.append(fragmentSource); - const char* src = srcba.data(); - glShaderSource(fragmentshader, 1, &src, NULL); - //glShaderSource(fragmentshader, 1, &fragmentsrc.latin1(), NULL); - // Compile the shader - glCompileShader(fragmentshader); - // Make sure it compiled correctly - int compiled; - glGetShaderiv(fragmentshader, GL_COMPILE_STATUS, &compiled); - // Get info log - glGetShaderiv(fragmentshader, GL_INFO_LOG_LENGTH, &logarraysize); - log = new char[logarraysize]; - glGetShaderInfoLog(fragmentshader, logarraysize, &logsize, log); - if (!compiled) { - kError(1212) << "Couldn't compile fragment shader! Log:" << endl << log << endl; - delete[] log; + bool success = compile(mProgram, GL_FRAGMENT_SHADER, fragmentSource); + + if (!success) { + glDeleteProgram(mProgram); + mProgram = 0; return false; - } else if (logsize > 0) - kDebug(1212) << "Fragment shader compilation log:" << log; - // Attach the shader to the program - glAttachShader(mProgram, fragmentshader); - // Delete shader - glDeleteShader(fragmentshader); - delete[] log; + } } - - // Link the program glLinkProgram(mProgram); - // Make sure it linked correctly - int linked; - glGetProgramiv(mProgram, GL_LINK_STATUS, &linked); - // Get info log - glGetProgramiv(mProgram, GL_INFO_LOG_LENGTH, &logarraysize); - log = new char[logarraysize]; - glGetProgramInfoLog(mProgram, logarraysize, &logsize, log); - if (!linked) { - kError(1212) << "Couldn't link the program! Log" << endl << log << endl; - delete[] log; + + // Get the program info log + int maxLength, length; + glGetProgramiv(mProgram, GL_INFO_LOG_LENGTH, &maxLength); + + QByteArray log(maxLength, 0); + glGetProgramInfoLog(mProgram, maxLength, &length, log.data()); + + // Make sure the program linked successfully + int status; + glGetProgramiv(mProgram, GL_LINK_STATUS, &status); + + if (status == 0) { + kError(1212) << "Failed to link shader:" << endl << log << endl; + glDeleteProgram(mProgram); + mProgram = 0; return false; - } else if (logsize > 0) - kDebug(1212) << "Shader linking log:" << log; - delete[] log; + } else if (length > 0) + kDebug(1212) << "Shader link log:" << log; mValid = true; return true; diff --git a/lib/kwinglutils.h b/lib/kwinglutils.h index 83aa31cb2f..cf64e4b449 100644 --- a/lib/kwinglutils.h +++ b/lib/kwinglutils.h @@ -328,6 +328,7 @@ protected: GLShader(); bool loadFromFiles(const QString& vertexfile, const QString& fragmentfile); bool load(const QByteArray &vertexSource, const QByteArray &fragmentSource); + bool compile(GLuint program, GLenum shaderType, const QByteArray &sourceCode) const; void bind(); void unbind(); From 9dfc0332c6572e7a13afa6f08e9022f6b092db6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Fri, 4 Feb 2011 17:06:28 +0100 Subject: [PATCH 3/7] kwin: Fix a compiler warning about initialization order. --- lib/kwinglutils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/kwinglutils.cpp b/lib/kwinglutils.cpp index badb0e9524..878c0d8dcf 100644 --- a/lib/kwinglutils.cpp +++ b/lib/kwinglutils.cpp @@ -829,8 +829,8 @@ void GLShader::initStatic() } GLShader::GLShader() - : mValid(false) - , mProgram(0) + : mProgram(0) + , mValid(false) , mTextureWidth(-1.0f) , mTextureHeight(-1.0f) { From f7633fff23bedf6f17bde2e6214f1b46eb2cd1e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Fri, 4 Feb 2011 17:30:36 +0100 Subject: [PATCH 4/7] kwin: Static member variables shouldn't have the m prefix. --- lib/kwinglutils.cpp | 38 +++++++++++++++++++------------------- lib/kwinglutils.h | 24 ++++++++++++------------ 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/kwinglutils.cpp b/lib/kwinglutils.cpp index 878c0d8dcf..72438b9472 100644 --- a/lib/kwinglutils.cpp +++ b/lib/kwinglutils.cpp @@ -357,9 +357,9 @@ void popMatrix() // GLTexture //**************************************** -bool GLTexture::mNPOTTextureSupported = false; -bool GLTexture::mFramebufferObjectSupported = false; -bool GLTexture::mSaturationSupported = false; +bool GLTexture::sNPOTTextureSupported = false; +bool GLTexture::sFramebufferObjectSupported = false; +bool GLTexture::sSaturationSupported = false; GLTexture::GLTexture() { @@ -432,13 +432,13 @@ void GLTexture::init() void GLTexture::initStatic() { #ifdef KWIN_HAVE_OPENGLES - mNPOTTextureSupported = true; - mFramebufferObjectSupported = true; - mSaturationSupported = true; + sNPOTTextureSupported = true; + sFramebufferObjectSupported = true; + sSaturationSupported = true; #else - mNPOTTextureSupported = hasGLExtension("GL_ARB_texture_non_power_of_two"); - mFramebufferObjectSupported = hasGLExtension("GL_EXT_framebuffer_object"); - mSaturationSupported = ((hasGLExtension("GL_ARB_texture_env_crossbar") + sNPOTTextureSupported = hasGLExtension("GL_ARB_texture_non_power_of_two"); + sFramebufferObjectSupported = hasGLExtension("GL_EXT_framebuffer_object"); + sSaturationSupported = ((hasGLExtension("GL_ARB_texture_env_crossbar") && hasGLExtension("GL_ARB_texture_env_dot3")) || hasGLVersion(1, 4)) && (glTextureUnitsCount >= 4) && glActiveTexture != NULL; #endif @@ -813,18 +813,18 @@ QImage GLTexture::convertToGLFormat(const QImage& img) const // GLShader //**************************************** -bool GLShader::mFragmentShaderSupported = false; -bool GLShader::mVertexShaderSupported = false; +bool GLShader::sFragmentShaderSupported = false; +bool GLShader::sVertexShaderSupported = false; void GLShader::initStatic() { #ifdef KWIN_HAVE_OPENGLES - mFragmentShaderSupported = mVertexShaderSupported = true; + sFragmentShaderSupported = sVertexShaderSupported = true; #else - mFragmentShaderSupported = mVertexShaderSupported = + sFragmentShaderSupported = sVertexShaderSupported = hasGLExtension("GL_ARB_shader_objects") && hasGLExtension("GL_ARB_shading_language_100"); - mVertexShaderSupported &= hasGLExtension("GL_ARB_vertex_shader"); - mFragmentShaderSupported &= hasGLExtension("GL_ARB_fragment_shader"); + sVertexShaderSupported &= hasGLExtension("GL_ARB_vertex_shader"); + sFragmentShaderSupported &= hasGLExtension("GL_ARB_fragment_shader"); #endif } @@ -1382,14 +1382,14 @@ void ShaderManager::resetShader(ShaderType type) } /*** GLRenderTarget ***/ -bool GLRenderTarget::mSupported = false; +bool GLRenderTarget::sSupported = false; void GLRenderTarget::initStatic() { #ifdef KWIN_HAVE_OPENGLES - mSupported = true; + sSupported = true; #else - mSupported = hasGLExtension("GL_EXT_framebuffer_object") && glFramebufferTexture2D; + sSupported = hasGLExtension("GL_EXT_framebuffer_object") && glFramebufferTexture2D; #endif } @@ -1401,7 +1401,7 @@ GLRenderTarget::GLRenderTarget(GLTexture* color) mTexture = color; // Make sure FBO is supported - if (mSupported && mTexture && !mTexture->isNull()) { + if (sSupported && mTexture && !mTexture->isNull()) { initFBO(); } else kError(1212) << "Render targets aren't supported!" << endl; diff --git a/lib/kwinglutils.h b/lib/kwinglutils.h index cf64e4b449..468d7b4bb5 100644 --- a/lib/kwinglutils.h +++ b/lib/kwinglutils.h @@ -249,13 +249,13 @@ public: static void initStatic(); static bool NPOTTextureSupported() { - return mNPOTTextureSupported; + return sNPOTTextureSupported; } static bool framebufferObjectSupported() { - return mFramebufferObjectSupported; + return sFramebufferObjectSupported; } static bool saturationSupported() { - return mSaturationSupported; + return sSaturationSupported; } protected: @@ -278,9 +278,9 @@ private: GLVertexBuffer* m_vbo; QSize m_cachedSize; - static bool mNPOTTextureSupported; - static bool mFramebufferObjectSupported; - static bool mSaturationSupported; + static bool sNPOTTextureSupported; + static bool sFramebufferObjectSupported; + static bool sSaturationSupported; Q_DISABLE_COPY(GLTexture) }; @@ -317,10 +317,10 @@ public: static void initStatic(); static bool fragmentShaderSupported() { - return mFragmentShaderSupported; + return sFragmentShaderSupported; } static bool vertexShaderSupported() { - return mVertexShaderSupported; + return sVertexShaderSupported; } @@ -336,8 +336,8 @@ protected: private: unsigned int mProgram; bool mValid; - static bool mFragmentShaderSupported; - static bool mVertexShaderSupported; + static bool sFragmentShaderSupported; + static bool sVertexShaderSupported; float mTextureWidth; float mTextureHeight; friend class ShaderManager; @@ -520,7 +520,7 @@ public: static void initStatic(); static bool supported() { - return mSupported; + return sSupported; } @@ -529,7 +529,7 @@ protected: private: - static bool mSupported; + static bool sSupported; GLTexture* mTexture; bool mValid; From 2e2a7948fb8a41bbdb5b18415cd99d10e7c18618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 4 Feb 2011 19:37:31 +0100 Subject: [PATCH 5/7] Remove renderGLGeometry from kwinglutils. Not used anymore - completely replaced by VBO. --- lib/kwinglutils.cpp | 119 -------------------------------------------- lib/kwinglutils.h | 38 -------------- 2 files changed, 157 deletions(-) diff --git a/lib/kwinglutils.cpp b/lib/kwinglutils.cpp index 72438b9472..99b648716f 100644 --- a/lib/kwinglutils.cpp +++ b/lib/kwinglutils.cpp @@ -170,125 +170,6 @@ int nearestPowerOfTwo(int x) return 1 << last; } -void renderGLGeometry(int count, const float* vertices, const float* texture, const float* color, - int dim, int stride) -{ - return renderGLGeometry(infiniteRegion(), count, vertices, texture, color, dim, stride); -} - -void renderGLGeometry(const QRegion& region, int count, - const float* vertices, const float* texture, const float* color, - int dim, int stride) -{ -#ifdef KWIN_HAVE_OPENGLES - Q_UNUSED(region) - Q_UNUSED(count) - Q_UNUSED(vertices) - Q_UNUSED(texture) - Q_UNUSED(color) - Q_UNUSED(dim) - Q_UNUSED(stride) -#else - // Using arrays only makes sense if we have larger number of vertices. - // Otherwise overhead of enabling/disabling them is too big. - bool use_arrays = (count > 5); - - if (use_arrays) { - glPushAttrib(GL_ENABLE_BIT); - glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); - // Enable arrays - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(dim, GL_FLOAT, stride, vertices); - if (texture != NULL) { - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, stride, texture); - } - if (color != NULL) { - glEnableClientState(GL_COLOR_ARRAY); - glColorPointer(4, GL_FLOAT, stride, color); - } - } - - // Clip using scissoring - if (!effects->isRenderTargetBound()) { - PaintClipper pc(region); - for (PaintClipper::Iterator iterator; - !iterator.isDone(); - iterator.next()) { - if (use_arrays) - glDrawArrays(GL_QUADS, 0, count); - else - renderGLGeometryImmediate(count, vertices, texture, color, dim, stride); - } - } else { - if (use_arrays) - glDrawArrays(GL_QUADS, 0, count); - else - renderGLGeometryImmediate(count, vertices, texture, color, dim, stride); - } - - if (use_arrays) { - glPopClientAttrib(); - glPopAttrib(); - } -#endif -} - -void renderGLGeometryImmediate(int count, const float* vertices, const float* texture, const float* color, - int dim, int stride) -{ -#ifdef KWIN_HAVE_OPENGLES - Q_UNUSED(count) - Q_UNUSED(vertices) - Q_UNUSED(texture) - Q_UNUSED(color) - Q_UNUSED(dim) - Q_UNUSED(stride) -#else - // Find out correct glVertex*fv function according to dim parameter. - void (*glVertexFunc)(const float*) = glVertex2fv; - if (dim == 3) - glVertexFunc = glVertex3fv; - else if (dim == 4) - glVertexFunc = glVertex4fv; - - // These are number of _floats_ per item, not _bytes_ per item as opengl uses. - int vsize, tsize, csize; - vsize = tsize = csize = stride / sizeof(float); - if (!stride) { - // 0 means that arrays are tightly packed. This gives us different - // strides for different arrays - vsize = dim; - tsize = 2; - csize = 4; - } - - glBegin(GL_QUADS); - // This sucks. But makes it faster. - if (texture && color) { - for (int i = 0; i < count; i++) { - glTexCoord2fv(texture + i * tsize); - glColor4fv(color + i * csize); - glVertexFunc(vertices + i * vsize); - } - } else if (texture) { - for (int i = 0; i < count; i++) { - glTexCoord2fv(texture + i * tsize); - glVertexFunc(vertices + i * vsize); - } - } else if (color) { - for (int i = 0; i < count; i++) { - glColor4fv(color + i * csize); - glVertexFunc(vertices + i * vsize); - } - } else { - for (int i = 0; i < count; i++) - glVertexFunc(vertices + i * vsize); - } - glEnd(); -#endif -} - void addQuadVertices(QVector& verts, float x1, float y1, float x2, float y2) { verts << x1 << y1; diff --git a/lib/kwinglutils.h b/lib/kwinglutils.h index 468d7b4bb5..829d5fe580 100644 --- a/lib/kwinglutils.h +++ b/lib/kwinglutils.h @@ -85,44 +85,6 @@ inline bool KWIN_EXPORT isPowerOfTwo(int x) **/ int KWIN_EXPORT nearestPowerOfTwo(int x); -/** - * Renders quads using given vertices. - * If texture is not 0, each texture coordinate much have two components (st). - * If color is not 0, each color much have four components (rgba). - * Note that texture coordinates must match texture type (normalized/unnormalized - * for GL_TEXTURE_2D/GL_TEXTURE_ARB). - * - * In OpenGL ES this method is a no-op. - * - * @param count number of vertices to use. - * @param dim number of components per vertex coordinate in vertices array. - * @param stride byte offset of consecutive elements in arrays. If 0, then - * arrays must be tighly packed. Stride must be a multiple of sizeof(float)! - * @deprecated Use GLVertexBuffer - * @see GLVertexBuffer - **/ -KWIN_EXPORT void renderGLGeometry(const QRegion& region, int count, - const float* vertices, const float* texture = 0, const float* color = 0, - int dim = 2, int stride = 0); -/** - * Same as above, renders without specified region - * @deprecated Use GLVertexBuffer - * @see GLVertexBuffer - **/ -KWIN_EXPORT void renderGLGeometry(int count, - const float* vertices, const float* texture = 0, const float* color = 0, - int dim = 2, int stride = 0); - -/** - * In OpenGL ES this method is a no-op. - * - * @deprecated Use GLVertexBuffer - * @see GLVertexBuffer - **/ -KWIN_EXPORT void renderGLGeometryImmediate(int count, - const float* vertices, const float* texture = 0, const float* color = 0, - int dim = 2, int stride = 0); - /** * @deprecated Quads are not available in OpenGL ES **/ From 859dadffd8b51a7e4a0ef05fb6f49fb2f479565c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 4 Feb 2011 19:46:20 +0100 Subject: [PATCH 6/7] Drop addQuadVertices from kwinglutils. KWin does not use GL_QUADS anymore for rendering windows. This makes this method rather useless and isn't used anywhere either. --- lib/kwinglutils.cpp | 8 -------- lib/kwinglutils.h | 5 ----- 2 files changed, 13 deletions(-) diff --git a/lib/kwinglutils.cpp b/lib/kwinglutils.cpp index 99b648716f..82ebb1fa6e 100644 --- a/lib/kwinglutils.cpp +++ b/lib/kwinglutils.cpp @@ -170,14 +170,6 @@ int nearestPowerOfTwo(int x) return 1 << last; } -void addQuadVertices(QVector& verts, float x1, float y1, float x2, float y2) -{ - verts << x1 << y1; - verts << x1 << y2; - verts << x2 << y2; - verts << x2 << y1; -} - void pushMatrix() { #ifndef KWIN_HAVE_OPENGLES diff --git a/lib/kwinglutils.h b/lib/kwinglutils.h index 829d5fe580..a7cff39d89 100644 --- a/lib/kwinglutils.h +++ b/lib/kwinglutils.h @@ -85,11 +85,6 @@ inline bool KWIN_EXPORT isPowerOfTwo(int x) **/ int KWIN_EXPORT nearestPowerOfTwo(int x); -/** - * @deprecated Quads are not available in OpenGL ES - **/ -KWIN_EXPORT void addQuadVertices(QVector& verts, float x1, float y1, float x2, float y2); - /** * Push a new matrix on the GL matrix stack. * In GLES this method is a noop. This method should be preferred over glPushMatrix From 8bc586e613ead9cada4b7eb2e61f2e7a1f634bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Fri, 4 Feb 2011 19:57:19 +0100 Subject: [PATCH 7/7] kwin: Add overloads for setUniform() that take a location. --- lib/kwinglutils.cpp | 71 +++++++++++++++++++++++++++++++++------------ lib/kwinglutils.h | 10 +++++++ 2 files changed, 63 insertions(+), 18 deletions(-) diff --git a/lib/kwinglutils.cpp b/lib/kwinglutils.cpp index 82ebb1fa6e..ff75932a39 100644 --- a/lib/kwinglutils.cpp +++ b/lib/kwinglutils.cpp @@ -854,60 +854,96 @@ void GLShader::unbind() glUseProgram(0); } -int GLShader::uniformLocation(const char* name) +int GLShader::uniformLocation(const char *name) { int location = glGetUniformLocation(mProgram, name); return location; } -bool GLShader::setUniform(const char* name, float value) +bool GLShader::setUniform(const char *name, float value) +{ + const int location = uniformLocation(name); + return setUniform(location, value); +} + +bool GLShader::setUniform(const char *name, int value) +{ + const int location = uniformLocation(name); + return setUniform(location, value); +} + +bool GLShader::setUniform(const char *name, const QVector2D& value) +{ + const int location = uniformLocation(name); + return setUniform(location, value); +} + +bool GLShader::setUniform(const char *name, const QVector3D& value) +{ + const int location = uniformLocation(name); + return setUniform(location, value); +} + +bool GLShader::setUniform(const char *name, const QVector4D& value) +{ + const int location = uniformLocation(name); + return setUniform(location, value); +} + +bool GLShader::setUniform(const char *name, const QMatrix4x4& value) +{ + const int location = uniformLocation(name); + return setUniform(location, value); +} + +bool GLShader::setUniform(const char *name, const QColor& color) +{ + const int location = uniformLocation(name); + return setUniform(location, color); +} + +bool GLShader::setUniform(int location, float value) { - int location = uniformLocation(name); if (location >= 0) { glUniform1f(location, value); } return (location >= 0); } -bool GLShader::setUniform(const char* name, int value) +bool GLShader::setUniform(int location, int value) { - int location = uniformLocation(name); if (location >= 0) { glUniform1i(location, value); } return (location >= 0); } -bool GLShader::setUniform(const char* name, const QVector2D& value) +bool GLShader::setUniform(int location, const QVector2D &value) { - const int location = uniformLocation(name); if (location >= 0) { - glUniform2f(location, value.x(), value.y()); + glUniform2fv(location, 1, (const GLfloat*)&value); } return (location >= 0); } -bool GLShader::setUniform(const char* name, const QVector3D& value) +bool GLShader::setUniform(int location, const QVector3D &value) { - const int location = uniformLocation(name); if (location >= 0) { - glUniform3f(location, value.x(), value.y(), value.z()); + glUniform3fv(location, 1, (const GLfloat*)&value); } return (location >= 0); } -bool GLShader::setUniform(const char* name, const QVector4D& value) +bool GLShader::setUniform(int location, const QVector4D &value) { - const int location = uniformLocation(name); if (location >= 0) { - glUniform4f(location, value.x(), value.y(), value.z(), value.w()); + glUniform4fv(location, 1, (const GLfloat*)&value); } return (location >= 0); } -bool GLShader::setUniform(const char* name, const QMatrix4x4& value) +bool GLShader::setUniform(int location, const QMatrix4x4 &value) { - const int location = uniformLocation(name); if (location >= 0) { GLfloat m[16]; const qreal *data = value.constData(); @@ -922,9 +958,8 @@ bool GLShader::setUniform(const char* name, const QMatrix4x4& value) return (location >= 0); } -bool GLShader::setUniform(const char* name, const QColor& color) +bool GLShader::setUniform(int location, const QColor &color) { - const int location = uniformLocation(name); if (location >= 0) { glUniform4f(location, color.redF(), color.greenF(), color.blueF(), color.alphaF()); } diff --git a/lib/kwinglutils.h b/lib/kwinglutils.h index a7cff39d89..37820981ca 100644 --- a/lib/kwinglutils.h +++ b/lib/kwinglutils.h @@ -252,6 +252,7 @@ public: } int uniformLocation(const char* name); + bool setUniform(const char* name, float value); bool setUniform(const char* name, int value); bool setUniform(const char* name, const QVector2D& value); @@ -259,6 +260,15 @@ public: bool setUniform(const char* name, const QVector4D& value); bool setUniform(const char* name, const QMatrix4x4& value); bool setUniform(const char* name, const QColor& color); + + bool setUniform(int location, float value); + bool setUniform(int location, int value); + bool setUniform(int location, const QVector2D &value); + bool setUniform(int location, const QVector3D &value); + bool setUniform(int location, const QVector4D &value); + bool setUniform(int location, const QMatrix4x4 &value); + bool setUniform(int location, const QColor &value); + int attributeLocation(const char* name); bool setAttribute(const char* name, float value); /**