From b551e69b6f92bab6f9bb864bbbe0ef9b0ce240c8 Mon Sep 17 00:00:00 2001 From: psi29a Date: Tue, 9 Aug 2022 21:07:28 +0000 Subject: [PATCH] #5534 remove OSG 3.4 support and require at least 3.6.5 support --- CHANGELOG.md | 2 + CMakeLists.txt | 5 +- apps/opencs/view/render/scenewidget.cpp | 11 - apps/openmw/engine.cpp | 4 - apps/openmw/mwgui/loadingscreen.cpp | 6 - apps/openmw/mwrender/skyutil.cpp | 7 - appveyor.yml | 70 ------ components/nifosg/particle.cpp | 5 - components/sceneutil/lightmanager.cpp | 9 - components/sceneutil/morphgeometry.cpp | 4 - components/sceneutil/optimizer.cpp | 47 +--- components/sceneutil/riggeometry.cpp | 4 - .../sceneutil/riggeometryosgaextension.cpp | 1 - components/sdlutil/sdlcursormanager.cpp | 232 ++++-------------- 14 files changed, 59 insertions(+), 348 deletions(-) delete mode 100644 appveyor.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 627f5f6887..7ca7f1b81b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -157,6 +157,7 @@ Feature #2766: Warn user if their version of Morrowind is not the latest. Feature #2780: A way to see current OpenMW version in the console Feature #2858: Add a tab to the launcher for handling datafolders + Feature #3180: Support uncompressed colour-mapped TGA files Feature #3245: Grid and angle snapping for the OpenMW-CS Feature #3616: Allow Zoom levels on the World Map Feature #4067: Post Processing @@ -203,6 +204,7 @@ Feature #6867: Add a way to localize hardcoded strings in GUI Feature #6888: Add switch for armor degradation fix Feature #6925: Allow to use a mouse wheel to rotate a head in the race selection menu + Task #5534: Remove support for OSG 3.4 Task #6161: Refactor Sky to use shaders and be GLES/GL3 friendly Task #6162: Refactor GUI to use shaders and to be GLES and GL3+ friendly Task #6435: Add support for MSVC 2022 diff --git a/CMakeLists.txt b/CMakeLists.txt index 549e5d6c34..fbd3eda8ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -407,10 +407,7 @@ if(NOT HAVE_STDINT_H) endif() if(OPENMW_USE_SYSTEM_OSG) - find_package(OpenSceneGraph 3.4.0 REQUIRED ${USED_OSG_COMPONENTS}) - if (${OPENSCENEGRAPH_VERSION} VERSION_GREATER 3.6.2 AND ${OPENSCENEGRAPH_VERSION} VERSION_LESS 3.6.5) - message(FATAL_ERROR "OpenSceneGraph version ${OPENSCENEGRAPH_VERSION} has critical regressions which cause crashes. Please upgrade to 3.6.5 or later. We strongly recommend using the tip of the official 'OpenSceneGraph-3.6' branch or the tip of '3.6' OpenMW/osg (OSGoS).") - endif() + find_package(OpenSceneGraph 3.6.5 REQUIRED ${USED_OSG_COMPONENTS}) # Bump to 3.6.6 when released if(OSG_STATIC) find_package(OSGPlugins REQUIRED COMPONENTS ${USED_OSG_PLUGINS}) diff --git a/apps/opencs/view/render/scenewidget.cpp b/apps/opencs/view/render/scenewidget.cpp index 578723ccd8..5d875f4829 100644 --- a/apps/opencs/view/render/scenewidget.cpp +++ b/apps/opencs/view/render/scenewidget.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include @@ -97,14 +96,6 @@ RenderWidget::~RenderWidget() try { CompositeViewer::get().removeView(mView); - -#if OSG_VERSION_LESS_THAN(3,6,5) - // before OSG 3.6.4, the default font was a static object, and if it wasn't attached to the scene when a graphics context was destroyed, it's program wouldn't be released. - // 3.6.4 moved it into the object cache, which meant it usually got released, but not here. - // 3.6.5 improved cleanup with osgViewer::CompositeViewer::removeView so it more reliably released associated state for objects in the object cache. - osg::ref_ptr graphicsContext = mView->getCamera()->getGraphicsContext(); - osgText::Font::getDefaultFont()->releaseGLObjects(graphicsContext->getState()); -#endif } catch(const std::exception& e) { @@ -146,9 +137,7 @@ CompositeViewer::CompositeViewer() // https://gitlab.com/OpenMW/openmw/-/issues/5481 setThreadingModel(osgViewer::ViewerBase::SingleThreaded); -#if OSG_VERSION_GREATER_OR_EQUAL(3,5,5) setUseConfigureAffinity(false); -#endif // disable the default setting of viewer.done() by pressing Escape. setKeyEventSetsDone(0); diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index bb20451474..d0a3afc361 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -7,8 +7,6 @@ #include -#include - #include #include @@ -1032,10 +1030,8 @@ void OMW::Engine::go() mViewer = new osgViewer::Viewer; mViewer->setReleaseContextAtEndOfFrameHint(false); -#if OSG_VERSION_GREATER_OR_EQUAL(3,5,5) // Do not try to outsmart the OS thread scheduler (see bug #4785). mViewer->setUseConfigureAffinity(false); -#endif mEnvironment.setFrameRateLimit(Settings::Manager::getFloat("framerate limit", "Video")); diff --git a/apps/openmw/mwgui/loadingscreen.cpp b/apps/openmw/mwgui/loadingscreen.cpp index 61eca3d1d0..e52b1b24ba 100644 --- a/apps/openmw/mwgui/loadingscreen.cpp +++ b/apps/openmw/mwgui/loadingscreen.cpp @@ -1,12 +1,10 @@ #include "loadingscreen.hpp" #include -#include #include #include -#include #include #include @@ -305,12 +303,8 @@ namespace MWGui mCopyFramebufferToTextureCallback = new CopyFramebufferToTextureCallback(mTexture); } -#if OSG_VERSION_GREATER_OR_EQUAL(3, 5, 10) mViewer->getCamera()->removeInitialDrawCallback(mCopyFramebufferToTextureCallback); mViewer->getCamera()->addInitialDrawCallback(mCopyFramebufferToTextureCallback); -#else - mViewer->getCamera()->setInitialDrawCallback(mCopyFramebufferToTextureCallback); -#endif mCopyFramebufferToTextureCallback->reset(); mSplashImage->setBackgroundImage(""); diff --git a/apps/openmw/mwrender/skyutil.cpp b/apps/openmw/mwrender/skyutil.cpp index 29a82f7eb0..3c2cd1c6e9 100644 --- a/apps/openmw/mwrender/skyutil.cpp +++ b/apps/openmw/mwrender/skyutil.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include @@ -855,12 +854,8 @@ namespace MWRender osg::ref_ptr oqn = new osg::OcclusionQueryNode; oqn->setQueriesEnabled(true); -#if OSG_VERSION_GREATER_OR_EQUAL(3, 6, 5) // With OSG 3.6.5, the method of providing user defined query geometry has been completely replaced osg::ref_ptr queryGeom = new osg::QueryGeometry(oqn->getName()); -#else - osg::ref_ptr queryGeom = oqn->getQueryGeometry(); -#endif // Make it fast! A DYNAMIC query geometry means we can't break frame until the flare is rendered (which is rendered after all the other geometry, // so that would be pretty bad). STATIC should be safe, since our node's local bounds are static, thus computeBounds() which modifies the queryGeometry @@ -881,9 +876,7 @@ namespace MWRender // Still need a proper bounding sphere. oqn->setInitialBound(queryGeom->getBound()); -#if OSG_VERSION_GREATER_OR_EQUAL(3, 6, 5) oqn->setQueryGeometry(queryGeom.release()); -#endif osg::StateSet* queryStateSet = new osg::StateSet; if (queryVisible) diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 95f070a662..0000000000 --- a/appveyor.yml +++ /dev/null @@ -1,70 +0,0 @@ -version: "{build}" - -branches: - only: - - master - - /openmw-.*$/ - - appveyor - -environment: - matrix: - - msvc: 2017 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - - msvc: 2019 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 - -platform: - - x64 - -configuration: -# - Debug - - Release -# - RelWithDebInfo - -# We want the git revision for versioning, -# so shallow clones don't work. -clone_depth: 1 - -cache: - - C:\projects\openmw\deps\Bullet-2.89-msvc2017-win64-double.7z - - C:\projects\openmw\deps\MyGUI-3.4.1-msvc2017-win64.7z - - C:\projects\openmw\deps\MyGUI-3.4.1-msvc2019-win64.7z - - C:\projects\openmw\deps\OSGoS-3.6.5-b02abe2-msvc2017-win64.7z - - C:\projects\openmw\deps\OSGoS-3.6.5-b02abe2-msvc2019-win64.7z - - C:\projects\openmw\deps\ffmpeg-4.2.2-dev-win64.zip - - C:\projects\openmw\deps\ffmpeg-4.2.2-win64.zip - - C:\projects\openmw\deps\OpenAL-Soft-1.20.1.zip - - C:\projects\openmw\deps\SDL2-2.0.18.zip - -clone_folder: C:\projects\openmw - -install: - - set PATH=C:\Program Files\Git\mingw64\bin;%PATH% - -before_build: - - cmd: git submodule update --init --recursive - - cmd: sh %APPVEYOR_BUILD_FOLDER%\CI\before_script.msvc.sh -c %configuration% -p %PLATFORM% -v %msvc% -V -i %APPVEYOR_BUILD_FOLDER%\install - -build_script: - - cmd: if %PLATFORM%==x64 set build=MSVC%msvc%_64 - - cmd: msbuild %build%\OpenMW.sln /t:Build /p:Configuration=%configuration% /m:2 /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" - - cmd: cmake --install %build% --config %configuration% - -after_build: - - cmd: if %PLATFORM%==x64 7z a OpenMW_MSVC%msvc%_%platform%_%appveyor_pull_request_number%_%appveyor_pull_request_head_commit%.zip %APPVEYOR_BUILD_FOLDER%\install -xr"!*.pdb" - #- cmd: if %PLATFORM%==x64 7z a OpenMW_MSVC%msvc%_%platform%_%appveyor_pull_request_number%_%appveyor_pull_request_head_commit%_pdb.zip %APPVEYOR_BUILD_FOLDER%\MSVC%msvc%_64\%configuration%\*.pdb - -test: off - -#notifications: -# - provider: Email -# to: -# - -# on_build_failure: true -# on_build_status_changed: true - -artifacts: - - path: OpenMW_MSVC%msvc%_%platform%_%appveyor_pull_request_number%_%appveyor_pull_request_head_commit%.zip - name: OpenMW_MSVC%msvc%_%platform%_%appveyor_pull_request_number%_%appveyor_pull_request_head_commit% - #- path: OpenMW_MSVC%msvc%_%platform%_%appveyor_pull_request_number%_%appveyor_pull_request_head_commit%_pdb.zip - # name: OpenMW_MSVC%msvc%_%platform%_%appveyor_pull_request_number%_%appveyor_pull_request_head_commit%_pdb diff --git a/components/nifosg/particle.cpp b/components/nifosg/particle.cpp index 9706a1f91b..320c24164f 100644 --- a/components/nifosg/particle.cpp +++ b/components/nifosg/particle.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -138,7 +137,6 @@ osgParticle::Particle* ParticleSystem::createParticle(const osgParticle::Particl void ParticleSystem::drawImplementation(osg::RenderInfo& renderInfo) const { osg::State & state = *renderInfo.getState(); -#if OSG_MIN_VERSION_REQUIRED(3, 5, 6) if(state.useVertexArrayObject(getUseVertexArrayObject())) { state.getCurrentVertexArrayState()->assignNormalArrayDispatcher(); @@ -148,9 +146,6 @@ void ParticleSystem::drawImplementation(osg::RenderInfo& renderInfo) const { state.getAttributeDispatchers().activateNormalArray(mNormalArray); } -#else - state.Normal(0.3, 0.3, 0.3); -#endif osgParticle::ParticleSystem::drawImplementation(renderInfo); } diff --git a/components/sceneutil/lightmanager.cpp b/components/sceneutil/lightmanager.cpp index cd76440f3e..4f5261f04b 100644 --- a/components/sceneutil/lightmanager.cpp +++ b/components/sceneutil/lightmanager.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include @@ -301,11 +300,7 @@ namespace SceneUtil osg::ref_ptr ubo = new osg::UniformBufferObject; buffer->getData()->setBufferObject(ubo); -#if OSG_VERSION_GREATER_OR_EQUAL(3,5,7) osg::ref_ptr ubb = new osg::UniformBufferBinding(static_cast(Resource::SceneManager::UBOBinding::LightBuffer), buffer->getData(), 0, buffer->getData()->getTotalDataSize()); -#else - osg::ref_ptr ubb = new osg::UniformBufferBinding(static_cast(Resource::SceneManager::UBOBinding::LightBuffer), ubo, 0, buffer->getData()->getTotalDataSize()); -#endif stateset->setAttributeAndModes(ubb, mode); break; @@ -613,11 +608,7 @@ namespace SceneUtil for (size_t i = 0; i < mStateSet.size(); ++i) { auto& buffer = lightManager->getUBOManager()->getLightBuffer(i); -#if OSG_VERSION_GREATER_OR_EQUAL(3,5,7) osg::ref_ptr ubb = new osg::UniformBufferBinding(static_cast(Resource::SceneManager::UBOBinding::LightBuffer), buffer->getData(), 0, buffer->getData()->getTotalDataSize()); -#else - osg::ref_ptr ubb = new osg::UniformBufferBinding(static_cast(Resource::SceneManager::UBOBinding::LightBuffer), buffer->getData()->getBufferObject(), 0, buffer->getData()->getTotalDataSize()); -#endif mStateSet[i]->setAttributeAndModes(ubb, osg::StateAttribute::ON); } } diff --git a/components/sceneutil/morphgeometry.cpp b/components/sceneutil/morphgeometry.cpp index 3e34e3dedc..39102b575a 100644 --- a/components/sceneutil/morphgeometry.cpp +++ b/components/sceneutil/morphgeometry.cpp @@ -3,8 +3,6 @@ #include #include -#include - namespace SceneUtil { @@ -189,9 +187,7 @@ void MorphGeometry::cull(osg::NodeVisitor *nv) positionDst->dirty(); -#if OSG_MIN_VERSION_REQUIRED(3, 5, 10) geom.osg::Drawable::dirtyGLObjects(); -#endif nv->pushOntoNodePath(&geom); nv->apply(geom); diff --git a/components/sceneutil/optimizer.cpp b/components/sceneutil/optimizer.cpp index 9012349804..00ebd018e1 100644 --- a/components/sceneutil/optimizer.cpp +++ b/components/sceneutil/optimizer.cpp @@ -13,12 +13,8 @@ /* Modified for OpenMW */ -#include -#include - #include "optimizer.hpp" -#include #include #include #include @@ -37,7 +33,6 @@ #include #include -#include #include #include @@ -629,22 +624,11 @@ void Optimizer::FlattenStaticTransformsVisitor::apply(osg::Node& node) traverse(node); } -bool needvbo(const osg::Geometry* geom) -{ -#if OSG_MIN_VERSION_REQUIRED(3,5,6) - return true; -#else - return geom->getUseVertexBufferObjects(); -#endif -} - osg::Array* cloneArray(osg::Array* array, osg::VertexBufferObject*& vbo, const osg::Geometry* geom) { array = static_cast(array->clone(osg::CopyOp::DEEP_COPY_ALL)); - if (!vbo && needvbo(geom)) - vbo = new osg::VertexBufferObject; - if (vbo) - array->setVertexBufferObject(vbo); + if (!vbo) vbo = new osg::VertexBufferObject; + array->setVertexBufferObject(vbo); return array; } @@ -1199,10 +1183,8 @@ osg::PrimitiveSet* clonePrimitive(osg::PrimitiveSet* ps, osg::ElementBufferObjec osg::DrawElements* drawElements = ps->getDrawElements(); if (!drawElements) return ps; - if (!ebo && needvbo(geom)) - ebo = new osg::ElementBufferObject; - if (ebo) - drawElements->setElementBufferObject(ebo); + if (!ebo) ebo = new osg::ElementBufferObject; + drawElements->setElementBufferObject(ebo); return ps; } @@ -1808,11 +1790,8 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom { // must promote to a DrawElementsUInt osg::DrawElementsUInt* new_primitive = new osg::DrawElementsUInt(primitive->getMode()); - if (needvbo(&lhs)) - { - if (!ebo) ebo = new osg::ElementBufferObject; - new_primitive->setElementBufferObject(ebo); - } + if (!ebo) ebo = new osg::ElementBufferObject; + new_primitive->setElementBufferObject(ebo); std::copy(primitiveUByte->begin(),primitiveUByte->end(),std::back_inserter(*new_primitive)); new_primitive->offsetIndices(base); (*primItr) = new_primitive; @@ -1820,11 +1799,8 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom { // must promote to a DrawElementsUShort osg::DrawElementsUShort* new_primitive = new osg::DrawElementsUShort(primitive->getMode()); - if (needvbo(&lhs)) - { - if (!ebo) ebo = new osg::ElementBufferObject; - new_primitive->setElementBufferObject(ebo); - } + if (!ebo) ebo = new osg::ElementBufferObject; + new_primitive->setElementBufferObject(ebo); std::copy(primitiveUByte->begin(),primitiveUByte->end(),std::back_inserter(*new_primitive)); new_primitive->offsetIndices(base); (*primItr) = new_primitive; @@ -1851,11 +1827,8 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom { // must promote to a DrawElementsUInt osg::DrawElementsUInt* new_primitive = new osg::DrawElementsUInt(primitive->getMode()); - if (needvbo(&lhs)) - { - if (!ebo) ebo = new osg::ElementBufferObject; - new_primitive->setElementBufferObject(ebo); - } + if (!ebo) ebo = new osg::ElementBufferObject; + new_primitive->setElementBufferObject(ebo); std::copy(primitiveUShort->begin(),primitiveUShort->end(),std::back_inserter(*new_primitive)); new_primitive->offsetIndices(base); (*primItr) = new_primitive; diff --git a/components/sceneutil/riggeometry.cpp b/components/sceneutil/riggeometry.cpp index 84b31f4afc..5fca265877 100644 --- a/components/sceneutil/riggeometry.cpp +++ b/components/sceneutil/riggeometry.cpp @@ -1,7 +1,5 @@ #include "riggeometry.hpp" -#include - #include #include #include @@ -260,9 +258,7 @@ void RigGeometry::cull(osg::NodeVisitor* nv) if (tangentDst) tangentDst->dirty(); -#if OSG_MIN_VERSION_REQUIRED(3, 5, 10) geom.osg::Drawable::dirtyGLObjects(); -#endif nv->pushOntoNodePath(&geom); nv->apply(geom); diff --git a/components/sceneutil/riggeometryosgaextension.cpp b/components/sceneutil/riggeometryosgaextension.cpp index 75af4c4b82..8768eb403f 100644 --- a/components/sceneutil/riggeometryosgaextension.cpp +++ b/components/sceneutil/riggeometryosgaextension.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include diff --git a/components/sdlutil/sdlcursormanager.cpp b/components/sdlutil/sdlcursormanager.cpp index 626930291d..6a67119ad8 100644 --- a/components/sdlutil/sdlcursormanager.cpp +++ b/components/sdlutil/sdlcursormanager.cpp @@ -1,8 +1,6 @@ #include "sdlcursormanager.hpp" -#include #include -#include #include #include @@ -26,180 +24,6 @@ USE_GRAPHICSWINDOW() #endif -namespace CursorDecompression -{ - // macOS builds use the OSG fork that includes DXTC commit - #if OSG_VERSION_GREATER_OR_EQUAL(3, 5, 8) || defined(__APPLE__) - static const bool DXTCSupported = true; - #else - static const bool DXTCSupported = false; - #endif - - class MyGraphicsContext { - public: - MyGraphicsContext(int w, int h) - { - osg::ref_ptr traits = new osg::GraphicsContext::Traits; - traits->x = 0; - traits->y = 0; - traits->width = w; - traits->height = h; - traits->red = 8; - traits->green = 8; - traits->blue = 8; - traits->alpha = 8; - traits->windowDecoration = false; - traits->doubleBuffer = false; - traits->sharedContext = nullptr; - traits->pbuffer = true; - - osg::GraphicsContext::ScreenIdentifier si; - si.readDISPLAY(); - if (si.displayNum<0) si.displayNum = 0; - traits->displayNum = si.displayNum; - traits->screenNum = si.screenNum; - traits->hostName = si.hostName; - - _gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - - if (!_gc) - { - Log(Debug::Warning) << "Failed to create pbuffer, failing back to normal graphics window."; - - traits->pbuffer = false; - _gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - if (!_gc) - throw std::runtime_error("Failed to create graphics context for image decompression"); - } - - if (_gc.valid()) - { - _gc->realize(); - _gc->makeCurrent(); - } - } - - osg::ref_ptr getContext() - { - return _gc; - } - - bool valid() const { return _gc.valid() && _gc->isRealized(); } - - private: - osg::ref_ptr _gc; - }; - - SDLUtil::SurfaceUniquePtr hardwareDecompress (osg::ref_ptr source, float rotDegrees) - { - int width = source->s(); - int height = source->t(); - - MyGraphicsContext context(width, height); - - osg::ref_ptr state = context.getContext()->getState(); - - osg::ref_ptr texture = new osg::Texture2D; - texture->setImage(source); - texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_BORDER); - texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_BORDER); - texture->setBorderColor(osg::Vec4f(0.f, 0.f, 0.f, 0.f)); - - osg::ref_ptr texmat = new osg::TexMat; - osg::Matrix texRot (osg::Matrix::identity()); - float theta ( osg::DegreesToRadians(-rotDegrees) ); - float cosTheta = std::cos(theta); - float sinTheta = std::sin(theta); - - texRot(0,0) = cosTheta; - texRot(1,0) = -sinTheta; - texRot(0,1) = sinTheta; - texRot(1,1) = cosTheta; - // Offset center of rotation to center of texture - texRot(3,0) = 0.5f + ( (-0.5f * cosTheta) - (-0.5f * sinTheta) ); - texRot(3,1) = 0.5f + ( (-0.5f * sinTheta) + (-0.5f * cosTheta) ); - - texmat->setMatrix(texRot); - - state->applyTextureAttribute(0, texmat); - - osg::ref_ptr identity (new osg::RefMatrix(osg::Matrix::identity())); - state->applyModelViewMatrix(identity); - state->applyProjectionMatrix(identity); - - state->applyMode(GL_TEXTURE_2D, true); - state->applyTextureAttribute(0, texture); - - osg::ref_ptr resultImage = new osg::Image; - resultImage->allocateImage(width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE); - - osg::RenderInfo renderInfo; - renderInfo.setState(state); - - glViewport(0, 0, width, height); - - osg::ref_ptr geom; - - geom = osg::createTexturedQuadGeometry(osg::Vec3(-1,-1,0), osg::Vec3(2,0,0), osg::Vec3(0,2,0)); - - geom->drawImplementation(renderInfo); - - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, resultImage->data()); - - geom->releaseGLObjects(); - source->releaseGLObjects(); - texture->releaseGLObjects(); - - return SDLUtil::imageToSurface(resultImage, true); - } - - SDLUtil::SurfaceUniquePtr softwareDecompress (osg::ref_ptr source, float rotDegrees) - { - int width = source->s(); - int height = source->t(); - bool useAlpha = source->isImageTranslucent(); - - osg::ref_ptr decompressedImage = new osg::Image; - decompressedImage->setFileName(source->getFileName()); - decompressedImage->allocateImage(width, height, 1, useAlpha ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE); - for (int s=0; ssetColor(source->getColor(s,t,0), s,t,0); - - Uint32 redMask = 0x000000ff; - Uint32 greenMask = 0x0000ff00; - Uint32 blueMask = 0x00ff0000; - Uint32 alphaMask = useAlpha ? 0xff000000 : 0; - - SDL_Surface *cursorSurface = SDL_CreateRGBSurfaceFrom(decompressedImage->data(), - width, - height, - decompressedImage->getPixelSizeInBits(), - decompressedImage->getRowSizeInBytes(), - redMask, - greenMask, - blueMask, - alphaMask); - - SDL_Surface *targetSurface = SDL_CreateRGBSurface(0, width, height, 32, redMask, greenMask, blueMask, alphaMask); - SDL_Renderer *renderer = SDL_CreateSoftwareRenderer(targetSurface); - - SDL_RenderClear(renderer); - - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"); - SDL_Texture *cursorTexture = SDL_CreateTextureFromSurface(renderer, cursorSurface); - - SDL_RenderCopyEx(renderer, cursorTexture, nullptr, nullptr, -rotDegrees, nullptr, SDL_FLIP_VERTICAL); - - SDL_DestroyTexture(cursorTexture); - SDL_FreeSurface(cursorSurface); - SDL_DestroyRenderer(renderer); - - return SDLUtil::SurfaceUniquePtr(targetSurface, SDL_FreeSurface); - } - -} - namespace SDLUtil { @@ -262,22 +86,58 @@ namespace SDLUtil #endif } + SDLUtil::SurfaceUniquePtr decompress(osg::ref_ptr source, float rotDegrees) + { + int width = source->s(); + int height = source->t(); + bool useAlpha = source->isImageTranslucent(); + + osg::ref_ptr decompressedImage = new osg::Image; + decompressedImage->setFileName(source->getFileName()); + decompressedImage->allocateImage(width, height, 1, useAlpha ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE); + for (int s=0; ssetColor(source->getColor(s,t,0), s,t,0); + + Uint32 redMask = 0x000000ff; + Uint32 greenMask = 0x0000ff00; + Uint32 blueMask = 0x00ff0000; + Uint32 alphaMask = useAlpha ? 0xff000000 : 0; + + SDL_Surface *cursorSurface = SDL_CreateRGBSurfaceFrom(decompressedImage->data(), + width, + height, + decompressedImage->getPixelSizeInBits(), + decompressedImage->getRowSizeInBytes(), + redMask, + greenMask, + blueMask, + alphaMask); + + SDL_Surface *targetSurface = SDL_CreateRGBSurface(0, width, height, 32, redMask, greenMask, blueMask, alphaMask); + SDL_Renderer *renderer = SDL_CreateSoftwareRenderer(targetSurface); + + SDL_RenderClear(renderer); + + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"); + SDL_Texture *cursorTexture = SDL_CreateTextureFromSurface(renderer, cursorSurface); + + SDL_RenderCopyEx(renderer, cursorTexture, nullptr, nullptr, -rotDegrees, nullptr, SDL_FLIP_VERTICAL); + + SDL_DestroyTexture(cursorTexture); + SDL_FreeSurface(cursorSurface); + SDL_DestroyRenderer(renderer); + + return SDLUtil::SurfaceUniquePtr(targetSurface, SDL_FreeSurface); + } + void SDLCursorManager::_createCursorFromResource(const std::string& name, int rotDegrees, osg::Image* image, Uint8 hotspot_x, Uint8 hotspot_y) { if (mCursorMap.find(name) != mCursorMap.end()) return; - static bool forceSoftwareDecompression = (getenv("OPENMW_DECOMPRESS_TEXTURES") != nullptr); - - SurfaceUniquePtr (*decompressionFunction)(osg::ref_ptr, float); - if (forceSoftwareDecompression || CursorDecompression::DXTCSupported) { - decompressionFunction = CursorDecompression::softwareDecompress; - } else { - decompressionFunction = CursorDecompression::hardwareDecompress; - } - try { - auto surface = decompressionFunction(image, static_cast(rotDegrees)); + auto surface = decompress(image, static_cast(rotDegrees)); //set the cursor and store it for later SDL_Cursor* curs = SDL_CreateColorCursor(surface.get(), hotspot_x, hotspot_y);