From 0225cac91761225f48fd817b702b046a7d16888e Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Wed, 8 Sep 2021 19:09:43 +0200 Subject: [PATCH] ~ changed glfw to use a custom library version until upstream adds proper support for this ~ brought back proper background rendering and position detection Signed-off-by: Alexis Maiquez --- .gitignore | 1 - CMakeLists.txt | 12 +- CMakeModules/FindGLFW3.cmake | 47 ----- README.md | 4 +- lib/glfw | 1 + main.cpp | 15 +- src/WallpaperEngine/Assets/CTexture.h | 2 +- src/WallpaperEngine/Irrlicht/CContext.cpp | 236 ---------------------- src/WallpaperEngine/Irrlicht/CContext.h | 57 ------ src/WallpaperEngine/Render/CContext.cpp | 108 ++++++++++ src/WallpaperEngine/Render/CContext.h | 26 +++ src/WallpaperEngine/Render/CScene.cpp | 4 +- src/WallpaperEngine/Render/CScene.h | 4 +- src/WallpaperEngine/Render/CVideo.cpp | 2 +- src/WallpaperEngine/Render/CVideo.h | 4 +- src/WallpaperEngine/Render/CWallpaper.cpp | 43 +++- src/WallpaperEngine/Render/CWallpaper.h | 7 +- 17 files changed, 210 insertions(+), 363 deletions(-) delete mode 100644 CMakeModules/FindGLFW3.cmake create mode 160000 lib/glfw delete mode 100644 src/WallpaperEngine/Irrlicht/CContext.cpp delete mode 100644 src/WallpaperEngine/Irrlicht/CContext.h create mode 100644 src/WallpaperEngine/Render/CContext.cpp create mode 100644 src/WallpaperEngine/Render/CContext.h diff --git a/.gitignore b/.gitignore index 5def830..62187ac 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ cmake-build-debug assets.zip .idea assets/ -lib/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c1b281..b2539da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,10 +9,12 @@ set(OpenGL_GL_PREFERENCE "LEGACY") # if you're developing you might find this debug option useful for shader output, although RenderDoc is encouraged add_compile_definitions(DEBUG=0) +# add glfw3 customized version to the compilation +add_subdirectory (lib/glfw) + find_package(X11 REQUIRED) find_package(Xrandr REQUIRED) find_package(OpenGL REQUIRED) -find_package(GLFW3 3.1 REQUIRED) find_package(GLEW REQUIRED) find_package(GLUT REQUIRED) find_package(ZLIB REQUIRED) @@ -26,7 +28,6 @@ include_directories( ${X11_INCLUDE_DIR} ${XRANDR_INCLUDE_DIR} ${GLEW_INCLUDE_DIR} - ${glfw3_INCLUDE_DIR} ${LZ4_INCLUDE_DIR} ${SDL_INCLUDE_DIRS} ${SDL_MIXER_INCLUDE_DIRS} @@ -69,6 +70,9 @@ add_executable( src/WallpaperEngine/Render/Shaders/Compiler.h src/WallpaperEngine/Render/Shaders/Compiler.cpp + src/WallpaperEngine/Render/CContext.h + src/WallpaperEngine/Render/CContext.cpp + src/WallpaperEngine/Render/CWallpaper.h src/WallpaperEngine/Render/CWallpaper.cpp src/WallpaperEngine/Render/CScene.h @@ -183,11 +187,11 @@ target_link_libraries(wallengine ${X11_Xxf86vm_LIB} ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES} - ${GLFW3_LIBRARY} ${GLUT_LIBRARIES} ${ZLIB_LIBRARIES} ${LZ4_LIBRARY} ${SDL_LIBRARY} ${SDL_MIXER_LIBRARIES} ${FFMPEG_LIBRARIES} - ${FREEIMAGE_LIBRARIES}) \ No newline at end of file + ${FREEIMAGE_LIBRARIES} + glfw) \ No newline at end of file diff --git a/CMakeModules/FindGLFW3.cmake b/CMakeModules/FindGLFW3.cmake deleted file mode 100644 index 134dea7..0000000 --- a/CMakeModules/FindGLFW3.cmake +++ /dev/null @@ -1,47 +0,0 @@ -# Locate the glfw3 library -# -# This module defines the following variables: -# -# GLFW3_LIBRARY the name of the library; -# GLFW3_INCLUDE_DIR where to find glfw include files. -# GLFW3_FOUND true if both the GLFW3_LIBRARY and GLFW3_INCLUDE_DIR have been found. -# -# To help locate the library and include file, you can define a -# variable called GLFW3_ROOT which points to the root of the glfw library -# installation. -# -# default search dirs -# -# Cmake file from: https://github.com/daw42/glslcookbook - -set( _glfw3_HEADER_SEARCH_DIRS - "/usr/include" - "/usr/local/include" - "${CMAKE_SOURCE_DIR}/includes" ) -set( _glfw3_LIB_SEARCH_DIRS - "/usr/lib" - "/usr/local/lib" - "${CMAKE_SOURCE_DIR}/lib") - -# Check environment for root search directory -set( _glfw3_ENV_ROOT $ENV{GLFW3_ROOT} ) -if( NOT GLFW3_ROOT AND _glfw3_ENV_ROOT ) - set(GLFW3_ROOT ${_glfw3_ENV_ROOT} ) -endif() - -# Put user specified location at beginning of search -if( GLFW3_ROOT ) - list( INSERT _glfw3_HEADER_SEARCH_DIRS 0 "${GLFW3_ROOT}/include" ) - list( INSERT _glfw3_LIB_SEARCH_DIRS 0 "${GLFW3_ROOT}/lib" ) -endif() - -# Search for the header -FIND_PATH(GLFW3_INCLUDE_DIR "GLFW/glfw3.h" - PATHS ${_glfw3_HEADER_SEARCH_DIRS} ) - -# Search for the library -FIND_LIBRARY(GLFW3_LIBRARY NAMES glfw3 glfw - PATHS ${_glfw3_LIB_SEARCH_DIRS} ) -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLFW3 DEFAULT_MSG - GLFW3_LIBRARY GLFW3_INCLUDE_DIR) diff --git a/README.md b/README.md index 772e916..ce582d4 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Wallpaper Engine is a software designed by [Kristjan Skutta](https://store.steam - FFmpeg - X11 - Xrandr -- GLW3 +- GLFW3 - GLM - FreeImage @@ -69,7 +69,7 @@ Uncompressed backgrounds are just plain folders including all the resources and ./wallengine --dir folder ``` -#### 5.4.3. Running as a screen's background (NOT SUPPORTED IN THIS BUILD YET) +#### 5.4.3. Running as a screen's background Only screens configured with the XRandr extension are supported. To specify the screen names (as reported from xrandr tool) just use the ```--screen-root``` switch. You can specify multiple screens at the same time, for example: ``` ./wallengine --screen-root HDMI-1 --screen-root DVI-D-1 diff --git a/lib/glfw b/lib/glfw new file mode 160000 index 0000000..f4d5f76 --- /dev/null +++ b/lib/glfw @@ -0,0 +1 @@ +Subproject commit f4d5f760fdd69731c39d20c41a80945d61299778 diff --git a/main.cpp b/main.cpp index 3c7703a..71785db 100644 --- a/main.cpp +++ b/main.cpp @@ -5,17 +5,16 @@ #include #include -#define GLFW_EXPOSE_NATIVE_X11 - #include -#include -// #include +#include +#include "GLFW/glfw3.h" #include #include #include "WallpaperEngine/Core/CProject.h" #include "WallpaperEngine/Render/CWallpaper.h" +#include "WallpaperEngine/Render/CContext.h" #include "WallpaperEngine/Render/CScene.h" #include "WallpaperEngine/Render/CVideo.h" @@ -179,6 +178,9 @@ int main (int argc, char* argv[]) auto project = WallpaperEngine::Core::CProject::fromFile ("project.json", containers); WallpaperEngine::Render::CWallpaper* wallpaper; + // initialize custom context class + WallpaperEngine::Render::CContext* context = new WallpaperEngine::Render::CContext (screens); + // auto projection = project->getWallpaper ()->as ()->getOrthogonalProjection (); // create the window! // TODO: DO WE NEED TO PASS MONITOR HERE OR ANYTHING? @@ -227,6 +229,9 @@ int main (int argc, char* argv[]) throw std::runtime_error ("Unsupported wallpaper type"); } + // ensure the context knows what wallpaper to render + context->setWallpaper (wallpaper); + if (shouldEnableAudio == true) { int mixer_flags = MIX_INIT_MP3 | MIX_INIT_FLAC | MIX_INIT_OGG; @@ -264,7 +269,7 @@ int main (int argc, char* argv[]) // get the start time of the frame startTime = clock (); // render the scene - wallpaper->render (); + context->render (); // do buffer swapping glfwSwapBuffers (window); // poll for events (like closing the window) diff --git a/src/WallpaperEngine/Assets/CTexture.h b/src/WallpaperEngine/Assets/CTexture.h index 083a9cc..8bd3c9a 100644 --- a/src/WallpaperEngine/Assets/CTexture.h +++ b/src/WallpaperEngine/Assets/CTexture.h @@ -73,7 +73,7 @@ namespace WallpaperEngine::Assets */ enum TextureFlags : uint32_t { - None = 0, + NoFlags = 0, NoInterpolation = 1, ClampUVs = 2, IsGif = 4, diff --git a/src/WallpaperEngine/Irrlicht/CContext.cpp b/src/WallpaperEngine/Irrlicht/CContext.cpp deleted file mode 100644 index ae0004f..0000000 --- a/src/WallpaperEngine/Irrlicht/CContext.cpp +++ /dev/null @@ -1,236 +0,0 @@ -#include -#include -#include - -#include -#include - -#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.h" -#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2Pointer.h" - -#include "CContext.h" - -using namespace WallpaperEngine; -using namespace WallpaperEngine::Irrlicht; - -CContext::CContext (std::vector screens, bool isRootWindow) : - m_screens (std::move(screens)), - m_isRootWindow (isRootWindow) -{ -} - -void CContext::setDevice (irr::IrrlichtDevice* device) -{ - this->m_device = device; -} - -void CContext::initializeContext () -{ - irr::SIrrlichtCreationParameters irrlichtCreationParameters; - - // initialize event receiver first - this->m_eventReceiver = new CEventReceiver (); - - // prepare basic configuration for irrlicht - irrlichtCreationParameters.AntiAlias = 8; - irrlichtCreationParameters.Bits = 16; - // _irr_params.DeviceType = Irrlicht::EIDT_X11; - irrlichtCreationParameters.DriverType = irr::video::EDT_OPENGL; - irrlichtCreationParameters.Doublebuffer = false; - irrlichtCreationParameters.EventReceiver = this->m_eventReceiver; - irrlichtCreationParameters.Fullscreen = false; - irrlichtCreationParameters.HandleSRGB = false; - irrlichtCreationParameters.IgnoreInput = false; - irrlichtCreationParameters.Stencilbuffer = true; - irrlichtCreationParameters.UsePerformanceTimer = false; - irrlichtCreationParameters.Vsync = false; - irrlichtCreationParameters.WithAlphaChannel = false; - irrlichtCreationParameters.ZBufferBits = 24; - irrlichtCreationParameters.LoggingLevel = irr::ELL_DEBUG; - - this->initializeViewports (irrlichtCreationParameters); - - this->setDevice (irr::createDeviceEx (irrlichtCreationParameters)); - - if (this->getDevice () == nullptr) - { - throw std::runtime_error ("Cannot create irrlicht device"); - } - - this->getDevice ()->setWindowCaption (L"Test game"); - - // check for ps and vs support - if ( - this->getDevice ()->getVideoDriver()->queryFeature (irr::video::EVDF_PIXEL_SHADER_2_0) == false && - this->getDevice ()->getVideoDriver()->queryFeature (irr::video::EVDF_ARB_FRAGMENT_PROGRAM_1) == false) - { - throw std::runtime_error ("Pixel Shader 2.0 not supported by your video driver/hardware"); - } - - if ( - this->getDevice ()->getVideoDriver()->queryFeature (irr::video::EVDF_VERTEX_SHADER_2_0) == false && - this->getDevice ()->getVideoDriver()->queryFeature (irr::video::EVDF_ARB_VERTEX_PROGRAM_1) == false) - { - throw std::runtime_error ("Vertex Shader 2.0 not supported by your video driver/hardware"); - } - - if (this->getDevice ()->getVideoDriver ()->queryFeature (irr::video::EVDF_RENDER_TO_TARGET) == false) - { - throw std::runtime_error ("Render to texture not supported by your video driver/hardware"); - } - - // load the assets from wallpaper engine - this->getDevice ()->getFileSystem ()->addFileArchive ("assets.zip", true, false); - - // register custom loaders - this->getDevice ()->getVideoDriver()->addExternalImageLoader ( - new WallpaperEngine::Irrlicht::CImageLoaderTex (this) - ); - this->getDevice ()->getFileSystem ()->addArchiveLoader ( - new WallpaperEngine::Irrlicht::CArchiveLoaderPkg (this) - ); - // register time shader variable - this->insertShaderVariable ( - new Render::Shaders::Variables::CShaderVariableFloatPointer (&this->m_time, "g_Time") - ); - // register normalized uv position for mouse - this->insertShaderVariable ( - new Render::Shaders::Variables::CShaderVariableVector2Pointer (&this->m_pointerPosition, "g_PointerPosition") - ); -} - -void CContext::initializeViewports (irr::SIrrlichtCreationParameters &irrlichtCreationParameters) -{ - if (this->m_isRootWindow == false || this->m_screens.empty () == true) - return; - - Display* display = XOpenDisplay (nullptr); - int xrandr_result, xrandr_error; - - if (!XRRQueryExtension (display, &xrandr_result, &xrandr_error)) - { - std::cerr << "XRandr is not present, cannot detect specified screens, running in window mode" << std::endl; - return; - } - - XRRScreenResources* screenResources = XRRGetScreenResources (display, DefaultRootWindow (display)); - - // there are some situations where xrandr returns null (like screen not using the extension) - if (screenResources == nullptr) - return; - - for (int i = 0; i < screenResources->noutput; i ++) - { - XRROutputInfo* info = XRRGetOutputInfo (display, screenResources, screenResources->outputs [i]); - - // there are some situations where xrandr returns null (like screen not using the extension) - if (info == nullptr) - continue; - - auto cur = this->m_screens.begin (); - auto end = this->m_screens.end (); - - for (; cur != end; cur ++) - { - if (info->connection == RR_Connected && strcmp (info->name, (*cur).c_str ()) == 0) - { - XRRCrtcInfo* crtc = XRRGetCrtcInfo (display, screenResources, info->crtc); - - std::cout << "Found requested screen: " << info->name << " -> " << crtc->x << "x" << crtc->y << ":" << crtc->width << "x" << crtc->height << std::endl; - - irr::core::rect viewport; - - viewport.UpperLeftCorner.X = crtc->x; - viewport.UpperLeftCorner.Y = crtc->y; - viewport.LowerRightCorner.X = crtc->x + crtc->width; - viewport.LowerRightCorner.Y = crtc->y + crtc->height; - - this->m_viewports.push_back (viewport); - - XRRFreeCrtcInfo (crtc); - } - } - - XRRFreeOutputInfo (info); - } - - XRRFreeScreenResources (screenResources); - - irrlichtCreationParameters.WindowId = reinterpret_cast (DefaultRootWindow (display)); -} - -void CContext::renderFrame (Render::CWallpaper* wallpaper) -{ - this->m_time = this->getDevice ()->getTimer ()->getTime () / 1000.0f; - this->m_pointerPosition.X = this->m_eventReceiver->getPosition ().X / (float) this->getDevice ()->getVideoDriver ()->getScreenSize ().Width; - this->m_pointerPosition.Y = this->m_eventReceiver->getPosition ().Y / (float) this->getDevice ()->getVideoDriver ()->getScreenSize ().Height; - - if (this->m_viewports.empty () == true) - { - this->drawWallpaper (wallpaper, true); - } - else - { - auto cur = this->m_viewports.begin (); - auto end = this->m_viewports.end (); - - for (; cur != end; cur ++) - { - // change viewport to render to the correct portion of the display - this->getDevice ()->getVideoDriver ()->setViewPort (*cur); - this->drawWallpaper (wallpaper, false); - } - } -} - -void CContext::drawWallpaper (Render::CWallpaper* wallpaper, bool backBuffer) -{ - // TODO: Get scene clear color - this->getDevice ()->getVideoDriver ()->beginScene (backBuffer, true); - this->getDevice ()->getSceneManager ()->drawAll (); - this->getDevice ()->getVideoDriver ()->endScene (); -} - -void CContext::insertShaderVariable (Render::Shaders::Variables::CShaderVariable* variable) -{ - this->m_globalShaderVariables.push_back (variable); -} - -const std::vector& CContext::getShaderVariables () const -{ - return this->m_globalShaderVariables; -} - -irr::IrrlichtDevice* CContext::getDevice () -{ - return this->m_device; -} - -irr::io::path CContext::resolveFile (const irr::io::path& file) -{ - if (this->getDevice ()->getFileSystem ()->existFile (file) == false) - { - throw std::runtime_error ("Cannot find file " + std::string (file.c_str ())); - } - - return file; -} - -irr::io::path CContext::resolveMaterials (const std::string& materialName) -{ - return this->resolveFile (std::string ("materials/" + materialName + ".tex").c_str ()); -} - -irr::io::path CContext::resolveVertexShader (const std::string& vertexShader) -{ - return this->resolveFile (std::string ("shaders/" + vertexShader + ".vert").c_str ()); -} -irr::io::path CContext::resolveFragmentShader (const std::string& fragmentShader) -{ - return this->resolveFile (std::string ("shaders/" + fragmentShader + ".frag").c_str ()); -} - -irr::io::path CContext::resolveIncludeShader (const std::string& includeShader) -{ - return this->resolveFile (std::string ("shaders/" + includeShader).c_str ()); -} \ No newline at end of file diff --git a/src/WallpaperEngine/Irrlicht/CContext.h b/src/WallpaperEngine/Irrlicht/CContext.h deleted file mode 100644 index 113bc57..0000000 --- a/src/WallpaperEngine/Irrlicht/CContext.h +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -#include -#include - -#include - -#include "WallpaperEngine/Render/CWallpaper.h" - -#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h" - -#include "CEventReceiver.h" - -namespace WallpaperEngine::Render -{ - class CWallpaper; -}; - -namespace WallpaperEngine::Irrlicht -{ - class CContext - { - public: - CContext (std::vector screens, bool isRootWindow = false); - - void setDevice (irr::IrrlichtDevice* device); - void initializeContext (); - - void insertShaderVariable (Render::Shaders::Variables::CShaderVariable* variable); - const std::vector& getShaderVariables () const; - - void renderFrame (Render::CWallpaper* wallpaper); - - irr::IrrlichtDevice* getDevice (); - irr::io::path resolveMaterials (const std::string& materialName); - irr::io::path resolveVertexShader (const std::string& vertexShader); - irr::io::path resolveFragmentShader (const std::string& fragmentShader); - irr::io::path resolveIncludeShader (const std::string& includeShader); - private: - void initializeViewports (irr::SIrrlichtCreationParameters& irrlichtCreationParameters); - void drawWallpaper (Render::CWallpaper* wallpaper, bool backBuffer); - - irr::io::path resolveFile (const irr::io::path& file); - - irr::IrrlichtDevice* m_device; - CEventReceiver* m_eventReceiver; - - std::vector m_globalShaderVariables; - - float m_time; - irr::core::vector2df m_pointerPosition; - - std::vector m_screens; - std::vector m_viewports; - bool m_isRootWindow; - }; -}; diff --git a/src/WallpaperEngine/Render/CContext.cpp b/src/WallpaperEngine/Render/CContext.cpp new file mode 100644 index 0000000..74e393a --- /dev/null +++ b/src/WallpaperEngine/Render/CContext.cpp @@ -0,0 +1,108 @@ +#include +#include +#include + +#include +#include + +#include "CContext.h" + +using namespace WallpaperEngine::Render; + +CContext::CContext (std::vector screens) : + m_wallpaper (nullptr), + m_screens (std::move (screens)), + m_isRootWindow (m_screens.empty () == false), + m_window (0) +{ + this->initializeViewports (); +} + +void CContext::initializeViewports () +{ + if (this->m_isRootWindow == false || this->m_screens.empty () == true) + return; + + Display* display = XOpenDisplay (nullptr); + + int xrandr_result, xrandr_error; + + if (!XRRQueryExtension (display, &xrandr_result, &xrandr_error)) + { + std::cerr << "XRandr is not present, cannot detect specified screens, running in window mode" << std::endl; + return; + } + + int fullWidth = DisplayWidth (display, DefaultScreen (display)); + int fullHeight = DisplayHeight (display, DefaultScreen (display)); + XRRScreenResources* screenResources = XRRGetScreenResources (display, DefaultRootWindow (display)); + + // there are some situations where xrandr returns null (like screen not using the extension) + if (screenResources == nullptr) + return; + + for (int i = 0; i < screenResources->noutput; i ++) + { + XRROutputInfo* info = XRRGetOutputInfo (display, screenResources, screenResources->outputs [i]); + + // there are some situations where xrandr returns null (like screen not using the extension) + if (info == nullptr) + continue; + + auto cur = this->m_screens.begin (); + auto end = this->m_screens.end (); + + for (; cur != end; cur ++) + { + if (info->connection == RR_Connected && strcmp (info->name, (*cur).c_str ()) == 0) + { + XRRCrtcInfo* crtc = XRRGetCrtcInfo (display, screenResources, info->crtc); + + std::cout << "Found requested screen: " << info->name << " -> " << crtc->x << "x" << crtc->y << ":" << crtc->width << "x" << crtc->height << std::endl; + + glm::vec4 viewport = { + crtc->x, fullHeight - (crtc->y + crtc->height), crtc->width, crtc->height + }; + + this->m_viewports.push_back (viewport); + + XRRFreeCrtcInfo (crtc); + } + } + + XRRFreeOutputInfo (info); + } + + XRRFreeScreenResources (screenResources); + + // store the window + this->m_window = DefaultRootWindow (display); + // set the + glfwWindowHintPointer (GLFW_NATIVE_PARENT_HANDLE, reinterpret_cast (DefaultRootWindow (display))); +} + +void CContext::render () +{ + if (this->m_wallpaper == nullptr) + return; + + if (this->m_viewports.empty () == false) + { + bool firstFrame = true; + auto cur = this->m_viewports.begin (); + auto end = this->m_viewports.end (); + + for (; cur != end; cur ++) + { + this->m_wallpaper->render (*cur, firstFrame); + firstFrame = false; + } + } + else + this->m_wallpaper->render ({0, 0, 1920, 1080}); +} + +void CContext::setWallpaper (CWallpaper* wallpaper) +{ + this->m_wallpaper = wallpaper; +} \ No newline at end of file diff --git a/src/WallpaperEngine/Render/CContext.h b/src/WallpaperEngine/Render/CContext.h new file mode 100644 index 0000000..dd2c9c0 --- /dev/null +++ b/src/WallpaperEngine/Render/CContext.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +#include "CWallpaper.h" + +namespace WallpaperEngine::Render +{ + class CContext + { + public: + CContext (std::vector screens); + + void initializeViewports (); + void render (); + void setWallpaper (CWallpaper* wallpaper); + + private: + Window m_window; + std::vector m_screens; + std::vector m_viewports; + CWallpaper* m_wallpaper; + bool m_isRootWindow; + }; +} \ No newline at end of file diff --git a/src/WallpaperEngine/Render/CScene.cpp b/src/WallpaperEngine/Render/CScene.cpp index 7d85be1..aacc859 100644 --- a/src/WallpaperEngine/Render/CScene.cpp +++ b/src/WallpaperEngine/Render/CScene.cpp @@ -45,7 +45,7 @@ CCamera* CScene::getCamera () const return this->m_camera; } -void CScene::render () +void CScene::renderFrame () { auto projection = this->getScene ()->getOrthogonalProjection (); auto cur = this->m_objects.begin (); @@ -66,8 +66,6 @@ void CScene::render () // ensure we render over the whole screen glViewport (0, 0, projection->getWidth (), projection->getHeight ()); - - CWallpaper::render (); } Core::CScene* CScene::getScene () diff --git a/src/WallpaperEngine/Render/CScene.h b/src/WallpaperEngine/Render/CScene.h index 5ba1c6e..985598d 100644 --- a/src/WallpaperEngine/Render/CScene.h +++ b/src/WallpaperEngine/Render/CScene.h @@ -19,11 +19,11 @@ namespace WallpaperEngine::Render CCamera* getCamera () const; - void render () override; - Core::CScene* getScene (); protected: + void renderFrame () override; + friend class CWallpaper; static const std::string Type; diff --git a/src/WallpaperEngine/Render/CVideo.cpp b/src/WallpaperEngine/Render/CVideo.cpp index 0f70d7d..ce6323d 100644 --- a/src/WallpaperEngine/Render/CVideo.cpp +++ b/src/WallpaperEngine/Render/CVideo.cpp @@ -114,7 +114,7 @@ void CVideo::setSize (int width, int height) SWS_BILINEAR, NULL, NULL, NULL); } -void CVideo::render () +void CVideo::renderFrame () { // do not render using the CWallpaper function, just use this one this->setSize (m_codecCtx->width, m_codecCtx->height); diff --git a/src/WallpaperEngine/Render/CVideo.h b/src/WallpaperEngine/Render/CVideo.h index 6f2d500..b3351f1 100644 --- a/src/WallpaperEngine/Render/CVideo.h +++ b/src/WallpaperEngine/Render/CVideo.h @@ -19,11 +19,11 @@ namespace WallpaperEngine::Render public: CVideo (Core::CVideo* video, CContainer* container); - void render () override; - Core::CVideo* getVideo (); protected: + void renderFrame () override; + friend class CWallpaper; static const std::string Type; diff --git a/src/WallpaperEngine/Render/CWallpaper.cpp b/src/WallpaperEngine/Render/CWallpaper.cpp index 649d6b3..95d3924 100644 --- a/src/WallpaperEngine/Render/CWallpaper.cpp +++ b/src/WallpaperEngine/Render/CWallpaper.cpp @@ -184,8 +184,48 @@ void CWallpaper::setupShaders () this->a_TexCoord = glGetAttribLocation (this->m_shader, "a_TexCoord"); } -void CWallpaper::render () +void CWallpaper::render (glm::vec4 viewport, bool newFrame) { + if (newFrame == true) + this->renderFrame (); + + int windowWidth = 1920; + int windowHeight = 1080; + + if (this->getWallpaperData ()->is ()) + { + auto projection = this->getWallpaperData ()->as ()->getOrthogonalProjection (); + + windowWidth = projection->getWidth (); + windowHeight = projection->getHeight (); + } + // TODO: SUPPORT VIDEO + float widthRatio = windowWidth / viewport.z; + float heightRatio = windowHeight / viewport.w; + + GLfloat position [] = { + widthRatio * -1.0f, heightRatio * 1.0f, 0.0f, + widthRatio * 1.0, heightRatio * 1.0f, 0.0f, + widthRatio * -1.0f, heightRatio * -1.0f, 0.0f, + widthRatio * -1.0f, heightRatio * -1.0f, 0.0f, + widthRatio * 1.0f, heightRatio * 1.0f, 0.0f, + widthRatio * 1.0f, heightRatio * -1.0f, 0.0f + }; + + glBindBuffer (GL_ARRAY_BUFFER, this->m_positionBuffer); + glBufferData (GL_ARRAY_BUFFER, sizeof (position), position, GL_STATIC_DRAW); + + /* + -1.0f, 1.0f, 0.0f, + 1.0, 1.0f, 0.0f, + -1.0f, -1.0f, 0.0f, + -1.0f, -1.0f, 0.0f, + 1.0f, 1.0f, 0.0f, + 1.0f, -1.0f, 0.0f + */ + + glViewport (viewport.x, viewport.y, viewport.z, viewport.w); + // write to default's framebuffer glBindFramebuffer (GL_FRAMEBUFFER, GL_NONE); @@ -244,6 +284,7 @@ void CWallpaper::createFramebuffer (GLuint* framebuffer, GLuint* depthbuffer, GL windowWidth = projection->getWidth (); windowHeight = projection->getHeight (); } + // TODO: SUPPORT VIDEO GLenum drawBuffers [1] = {GL_COLOR_ATTACHMENT0}; // create the main framebuffer diff --git a/src/WallpaperEngine/Render/CWallpaper.h b/src/WallpaperEngine/Render/CWallpaper.h index f790b15..7acea3c 100644 --- a/src/WallpaperEngine/Render/CWallpaper.h +++ b/src/WallpaperEngine/Render/CWallpaper.h @@ -32,7 +32,7 @@ namespace WallpaperEngine::Render /** * Performs a render pass of the wallpaper */ - virtual void render (); + void render (glm::vec4 viewport, bool newFrame = true); /** * @return The container to resolve files for this wallpaper @@ -57,6 +57,11 @@ namespace WallpaperEngine::Render GLuint getWallpaperTexture () const; protected: + /** + * Renders a frame of the wallpaper + */ + virtual void renderFrame () = 0; + void createFramebuffer (GLuint* framebuffer, GLuint* depthbuffer, GLuint* texture); CContainer* m_container;