diff --git a/libkwineffects/CMakeLists.txt b/libkwineffects/CMakeLists.txt index 97717197d..74158787c 100644 --- a/libkwineffects/CMakeLists.txt +++ b/libkwineffects/CMakeLists.txt @@ -1,120 +1,121 @@ ########### next target ############### include(ECMSetupVersion) ecm_setup_version(${PROJECT_VERSION} VARIABLE_PREFIX KWINEFFECTS VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kwineffects_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KWinEffectsConfigVersion.cmake" SOVERSION 11 ) ### xrenderutils lib ### set(kwin_XRENDERUTILS_SRCS kwinxrenderutils.cpp logging.cpp ) add_library(kwinxrenderutils SHARED ${kwin_XRENDERUTILS_SRCS}) generate_export_header(kwinxrenderutils EXPORT_FILE_NAME kwinxrenderutils_export.h) target_link_libraries(kwinxrenderutils PUBLIC Qt5::Core Qt5::Gui XCB::XCB XCB::XFIXES XCB::RENDER KF5::WaylandServer ) set_target_properties(kwinxrenderutils PROPERTIES VERSION ${KWINEFFECTS_VERSION_STRING} SOVERSION ${KWINEFFECTS_SOVERSION} ) set_target_properties(kwinxrenderutils PROPERTIES OUTPUT_NAME ${KWIN_NAME}xrenderutils) install(TARGETS kwinxrenderutils EXPORT kdeworkspaceLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) ### effects lib ### set(kwin_EFFECTSLIB_SRCS kwineffects.cpp anidata.cpp kwinanimationeffect.cpp logging.cpp ) set(kwineffects_QT_LIBS Qt5::DBus Qt5::Widgets ) set(kwineffects_KDE_LIBS KF5::ConfigCore KF5::CoreAddons KF5::WindowSystem ) set(kwineffects_XCB_LIBS XCB::XCB ) add_library(kwineffects SHARED ${kwin_EFFECTSLIB_SRCS}) generate_export_header(kwineffects EXPORT_FILE_NAME kwineffects_export.h) target_link_libraries(kwineffects PUBLIC ${kwineffects_QT_LIBS} ${kwineffects_KDE_LIBS} ${kwineffects_XCB_LIBS} ) if( KWIN_HAVE_XRENDER_COMPOSITING ) target_link_libraries(kwineffects PRIVATE kwinxrenderutils XCB::XFIXES) endif() set_target_properties(kwineffects PROPERTIES VERSION ${KWINEFFECTS_VERSION_STRING} SOVERSION ${KWINEFFECTS_SOVERSION} ) set_target_properties(kwineffects PROPERTIES OUTPUT_NAME ${KWIN_NAME}effects) install(TARGETS kwineffects EXPORT kdeworkspaceLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) # kwingl(es)utils library set(kwin_GLUTILSLIB_SRCS kwinglutils.cpp + kwinglrenderbuffer.cpp kwingltexture.cpp kwinglutils_funcs.cpp kwinglplatform.cpp logging.cpp ) macro( KWIN4_ADD_GLUTILS_BACKEND name glinclude ) include_directories(${glinclude}) add_library(${name} SHARED ${kwin_GLUTILSLIB_SRCS}) generate_export_header(${name} BASE_NAME kwinglutils EXPORT_FILE_NAME kwinglutils_export.h) target_link_libraries(${name} PUBLIC XCB::XCB KF5::CoreAddons KF5::ConfigCore KF5::WindowSystem) set_target_properties(${name} PROPERTIES VERSION ${KWINEFFECTS_VERSION_STRING} SOVERSION ${KWINEFFECTS_SOVERSION} ) target_link_libraries(${name} PUBLIC ${ARGN}) install(TARGETS ${name} EXPORT kdeworkspaceLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) endmacro() kwin4_add_glutils_backend(kwinglutils ${epoxy_INCLUDE_DIR} ${epoxy_LIBRARY}) set_target_properties(kwinglutils PROPERTIES OUTPUT_NAME ${KWIN_NAME}glutils) target_link_libraries(kwinglutils PUBLIC ${epoxy_LIBRARY}) install( FILES kwinglobals.h kwineffects.h kwinanimationeffect.h kwinglplatform.h kwinglutils.h kwinglutils_funcs.h kwingltexture.h kwinxrenderutils.h ${CMAKE_CURRENT_BINARY_DIR}/kwinconfig.h ${CMAKE_CURRENT_BINARY_DIR}/kwineffects_export.h ${CMAKE_CURRENT_BINARY_DIR}/kwinglutils_export.h ${CMAKE_CURRENT_BINARY_DIR}/kwinxrenderutils_export.h DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel) diff --git a/libkwineffects/kwinglrenderbuffer.cpp b/libkwineffects/kwinglrenderbuffer.cpp new file mode 100644 index 000000000..fd1fb2451 --- /dev/null +++ b/libkwineffects/kwinglrenderbuffer.cpp @@ -0,0 +1,162 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2018 Vlad Zagorodniy + +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 . +*********************************************************************/ + +#include "kwinglrenderbuffer.h" + +#include + + +namespace KWin +{ + +class Q_DECL_HIDDEN GLRenderbuffer::Private : public QSharedData +{ +public: + Private(); + ~Private(); + + GLuint renderbuffer = 0; + GLenum target = GL_RENDERBUFFER; + GLenum internalFormat = GL_RGBA8; + int width = 0; + int height = 0; + int samples = 0; + +private: + Q_DISABLE_COPY(Private) +}; + +GLRenderbuffer::Private::Private() +{ +} + +GLRenderbuffer::Private::~Private() +{ + if (renderbuffer != 0) { + glDeleteRenderbuffers(1, &renderbuffer); + } +} + +GLRenderbuffer::GLRenderbuffer(int width, int height, int samples, + GLenum format, GLenum target) + : d(new GLRenderbuffer::Private) +{ + d->target = target; + d->internalFormat = format; + d->width = width; + d->height = height; + d->samples = samples; + + glGenRenderbuffers(1, &d->renderbuffer); + + bind(); + if (samples > 0) { + glRenderbufferStorageMultisample(target, samples, format, width, height); + } else { + glRenderbufferStorage(target, format, width, height); + } + unbind(); +} + +GLRenderbuffer::GLRenderbuffer(const QSize &size, int samples, GLenum format, GLenum target) + : GLRenderbuffer(size.width(), size.height(), samples, format, target) +{ +} + +GLRenderbuffer::~GLRenderbuffer() +{ +} + +void GLRenderbuffer::bind() +{ + glBindRenderbuffer(d->target, d->renderbuffer); +} + +void GLRenderbuffer::unbind() +{ + glBindRenderbuffer(d->target, 0); +} + +GLuint GLRenderbuffer::renderbuffer() const +{ + return d->renderbuffer; +} + +GLenum GLRenderbuffer::target() const +{ + return d->target; +} + +GLenum GLRenderbuffer::internalFormat() const +{ + return d->internalFormat; +} + +int GLRenderbuffer::samples() const +{ + return d->samples; +} + +int GLRenderbuffer::width() const +{ + return d->width; +} + +int GLRenderbuffer::height() const +{ + return d->height; +} + +QSize GLRenderbuffer::size() const +{ + return QSize(d->width, d->height); +} + +void GLRenderbuffer::resize(int width, int height) +{ + if (d->width == width && d->height == height) { + return; + } + + if (d->renderbuffer != 0) { + glDeleteRenderbuffers(1, &d->renderbuffer); + } + + glGenRenderbuffers(1, &d->renderbuffer); + + bind(); + if (d->samples > 0) { + glRenderbufferStorageMultisample( + d->target, d->samples, d->internalFormat, d->width, d->height); + } else { + glRenderbufferStorage(d->target, d->internalFormat, d->width, d->height); + } + unbind(); + + d->width = width; + d->height = height; +} + +void GLRenderbuffer::resize(const QSize &size) +{ + resize(size.width(), size.height()); +} + +} diff --git a/libkwineffects/kwinglrenderbuffer.h b/libkwineffects/kwinglrenderbuffer.h new file mode 100644 index 000000000..62a56be1e --- /dev/null +++ b/libkwineffects/kwinglrenderbuffer.h @@ -0,0 +1,70 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2018 Vlad Zagorodniy + +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 . +*********************************************************************/ + +#ifndef KWIN_GLRENDERBUFFER_H +#define KWIN_GLRENDERBUFFER_H + +#include + +#include +#include + +#include + + +namespace KWin +{ + +class KWINGLUTILS_EXPORT GLRenderbuffer +{ +public: + GLRenderbuffer(int width, int height, int samples = 0, + GLenum format = GL_RGBA8, + GLenum target = GL_RENDERBUFFER); + GLRenderbuffer(const QSize &size, int samples = 0, + GLenum format = GL_RGBA8, + GLenum target = GL_RENDERBUFFER); + ~GLRenderbuffer(); + + void bind(); + void unbind(); + + GLuint renderbuffer() const; + GLenum target() const; + GLenum internalFormat() const; + int samples() const; + + int width() const; + int height() const; + QSize size() const; + + void resize(int width, int height); + void resize(const QSize &size); + +private: + class Private; + +private: + QExplicitlySharedDataPointer d; +}; + +} // namespace KWin + +#endif // KWIN_GLRENDERBUFFER_H