Skip to content
Merged

Devel #3867

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions Components/Bites/src/OgreApplicationContextBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,21 +452,19 @@ void ApplicationContextBase::_destroyWindow(const NativeWindowPair& win)
void ApplicationContextBase::_fireInputEvent(const Event& event, uint32_t windowID) const
{
Event scaled = event;
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
// events arrive in view points, while Ogre uses pixels throughout
// (assumes all windows have the same scale)
float viewScale = getRenderWindow()->getViewPointToPixelScale();
if (event.type == MOUSEMOTION)
{
// assumes all windows have the same scale
float viewScale = getRenderWindow()->getViewPointToPixelScale();
scaled.motion.x *= viewScale;
scaled.motion.y *= viewScale;
}
else if(event.type == MOUSEBUTTONDOWN || event.type == MOUSEBUTTONUP)
{
float viewScale = getRenderWindow()->getViewPointToPixelScale();
scaled.button.x *= viewScale;
scaled.button.y *= viewScale;
}
#endif

for(const auto & li : mInputListeners)
{
Expand Down
3 changes: 3 additions & 0 deletions Components/Bites/src/OgreApplicationContextQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ namespace OgreBites

p.miscParams["externalWlDisplay"] = Ogre::StringConverter::toString(size_t(display));
p.miscParams["externalWlSurface"] = Ogre::StringConverter::toString(size_t(surface));
// an explicit value from the render system options or the caller wins
if (p.miscParams.find("contentScalingFactor") == p.miscParams.end())
p.miscParams["contentScalingFactor"] = Ogre::StringConverter::toString(window->devicePixelRatio());
#endif
}
if (!mWindows.empty())
Expand Down
30 changes: 30 additions & 0 deletions Components/Bites/src/OgreApplicationContextSDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@

namespace OgreBites {

// returns the window size in view points and the scale to its pixel size
static void getWindowSize(SDL_Window* win, int& width, int& height, float& scale)
{
SDL_GetWindowSize(win, &width, &height);
scale = 1.0f;
#if SDL_VERSION_ATLEAST(2, 26, 0)
int pixelWidth, pixelHeight;
SDL_GetWindowSizeInPixels(win, &pixelWidth, &pixelHeight);
if (width > 0 && pixelWidth > 0)
scale = float(pixelWidth) / width;
else if (height > 0 && pixelHeight > 0)
scale = float(pixelHeight) / height;
#endif
}

ApplicationContextSDL::ApplicationContextSDL(const Ogre::String& appName) : ApplicationContextBase(appName)
{
}
Expand Down Expand Up @@ -70,6 +85,12 @@ NativeWindowPair ApplicationContextSDL::createWindow(const Ogre::String& name, O
}

int flags = p.useFullScreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE;
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
// ALLOW_HIGHDPI makes SDL size the Wayland drawable in physical pixels and
// enables wp_fractional_scale. Ogre still gets view point dimensions and
// allocates the backbuffer in pixels using contentScalingFactor.
flags |= SDL_WINDOW_ALLOW_HIGHDPI;
#endif
int d = Ogre::StringConverter::parseInt(miscParams["monitorIndex"], 1) - 1;
ret.native =
SDL_CreateWindow(p.name.c_str(), SDL_WINDOWPOS_UNDEFINED_DISPLAY(d),
Expand All @@ -91,6 +112,15 @@ NativeWindowPair ApplicationContextSDL::createWindow(const Ogre::String& name, O
Ogre::LogManager::getSingleton().logMessage("[SDL] Creating Wayland window");
p.miscParams["externalWlDisplay"] = Ogre::StringConverter::toString(size_t(wmInfo.info.wl.display));
p.miscParams["externalWlSurface"] = Ogre::StringConverter::toString(size_t(wmInfo.info.wl.surface));

int widthPt, heightPt;
float scale;
getWindowSize(ret.native, widthPt, heightPt, scale);
p.width = widthPt;
p.height = heightPt;
// an explicit value from the render system options or the caller wins
if (p.miscParams.find("contentScalingFactor") == p.miscParams.end())
p.miscParams["contentScalingFactor"] = Ogre::StringConverter::toString(scale);
#endif
}
else if (wmInfo.subsystem == SDL_SYSWM_X11)
Expand Down
4 changes: 2 additions & 2 deletions OgreMain/include/OgreRenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ namespace Ogre
| FSAA | 0 | concatenation of "FSAA" and "FSAAHint" as in @ref _createRenderWindow |
| Video Mode | - | Window resolution |
| Display Frequency | - | "displayFrequency" in @ref _createRenderWindow |
| Content Scaling Factor | 1.0 | "contentScalingFactor" in @ref _createRenderWindow |
| Content Scaling Factor | Auto | pixels per view point; "contentScalingFactor" in @ref _createRenderWindow. "Auto" detects the scale of the monitor the window is created on |
@param
name The name of the option to alter.
@param
Expand Down Expand Up @@ -414,7 +414,7 @@ namespace Ogre
| useNVPerfHUD | true, false | false | Enable the use of nVidia NVPerfHUD | D3D |
| depthBuffer | true, false | true | Use depth buffer | D3D |
| NSOpenGLCPSurfaceOrder | -1 or 1 | 1 | [NSOpenGLCPSurfaceOrder](https://developer.apple.com/documentation/appkit/nsopenglcpsurfaceorder) | OSX |
| contentScalingFactor | Positive Float | The default content scaling factor of the screen | On IOS specifies the CAEAGLLayer content scaling factor. This can be useful to limit the resolution of the OpenGL ES backing store. For example, the iPhone 4's native resolution is 960 x 640\. Windows are always 320 x 480, if you would like to limit the display to 720 x 480, specify 1.5 as the scaling factor. | OSX, iOS, Android |
| contentScalingFactor | Positive Float | The default content scaling factor of the screen | On IOS specifies the CAEAGLLayer content scaling factor. This can be useful to limit the resolution of the OpenGL ES backing store. For example, the iPhone 4's native resolution is 960 x 640\. Windows are always 320 x 480, if you would like to limit the display to 720 x 480, specify 1.5 as the scaling factor. On Wayland it is the number of physical pixels per view point, which the backends use to allocate the backbuffer at native resolution. | OSX, iOS, Android, Wayland |
| externalViewHandle | UIView pointer as an integer | 0 | External view handle, for rendering OGRE render in an existing view | iOS |
| externalViewControllerHandle | UIViewController pointer as an integer | 0 | External view controller handle, for embedding OGRE in an existing view controller | iOS |
| externalSharegroup | EAGLSharegroup pointer as an integer | 0 | External sharegroup, used to shared GL resources between contexts | iOS |
Expand Down
18 changes: 17 additions & 1 deletion OgreMain/src/OgreRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ namespace Ogre {
if((opt = mOptions.find("Display Frequency")) != end)
miscParams.emplace("displayFrequency", opt->second.currentValue);

if((opt = mOptions.find("Content Scaling Factor")) != end)
// "Auto" means the window provider detects the scale of the monitor the
// window is created on; there is no usable value to pass along.
if ((opt = mOptions.find("Content Scaling Factor")) != end && opt->second.currentValue != "Auto")
miscParams["contentScalingFactor"] = opt->second.currentValue;

if((opt = mOptions.find("Rendering Device")) != end)
Expand Down Expand Up @@ -886,6 +888,20 @@ namespace Ogre {
optHDRDisplay.currentValue = optHDRDisplay.possibleValues[0];
mOptions[optHDRDisplay.name] = optHDRDisplay;

// Windows are sized in view points while the backbuffer is allocated in
// pixels. "Auto" lets the window provider detect the scale of the monitor
// the window is created on; the list is for discoverability only, the
// value can be anything the backend understands.
if (mOptions.find("Content Scaling Factor") == mOptions.end())
{
ConfigOption optContentScaling;
optContentScaling.name = "Content Scaling Factor";
optContentScaling.immutable = false;
optContentScaling.possibleValues = {"Auto", "1.0", "1.25", "1.5", "1.75", "2.0", "3.0"};
optContentScaling.currentValue = optContentScaling.possibleValues.front();
mOptions[optContentScaling.name] = optContentScaling;
}

#if OGRE_NO_QUAD_BUFFER_STEREO == 0
ConfigOption optStereoMode;
optStereoMode.name = "Frame Sequential Stereo";
Expand Down
11 changes: 0 additions & 11 deletions RenderSystems/GLES2/src/EAGL/OgreEAGL2Support.mm
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ of this software and associated documentation files (the "Software"), to deal
ConfigOptionMap EAGL2Support::getConfigOptions(void)
{
ConfigOptionMap mOptions;
ConfigOption optContentScalingFactor;

// Get the application frame size. On all iPhones(including iPhone 4) this will be 320 x 480
// The iPad, at least with iPhone OS 3.2 will report 768 x 1024
Expand All @@ -67,21 +66,11 @@ of this software and associated documentation files (the "Software"), to deal
mVideoModes.push_back({320, 568, 0});
mVideoModes.push_back({768, 1024, 0});

optContentScalingFactor.name = "Content Scaling Factor";
optContentScalingFactor.possibleValues.push_back( "1.0" );
optContentScalingFactor.possibleValues.push_back( "1.33" );
optContentScalingFactor.possibleValues.push_back( "1.5" );
optContentScalingFactor.possibleValues.push_back( "2.0" );
optContentScalingFactor.currentValue = StringConverter::toString([UIScreen mainScreen].scale);
optContentScalingFactor.immutable = false;

mFSAALevels.push_back(0);
mFSAALevels.push_back(2);
mFSAALevels.push_back(4);
mFSAALevels.push_back(8);

mOptions[optContentScalingFactor.name] = optContentScalingFactor;

return mOptions;
}

Expand Down
3 changes: 2 additions & 1 deletion RenderSystems/GLES2/src/EAGL/OgreEAGL2Window.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ of this software and associated documentation files (the "Software"), to deal

#import <UIKit/UIWindow.h>
#import <UIKit/UIGraphics.h>
#import <UIKit/UIScreen.h>
#include "ARCMacros.h"
#include "OgreDepthBuffer.h"

Expand All @@ -59,7 +60,7 @@ of this software and associated documentation files (the "Software"), to deal
mUsingExternalView(false),
mUsingExternalViewController(false),
mIsContentScalingSupported(EAGLCurrentOSVersion >= 4.0),
mContentScalingFactor(1.0),
mContentScalingFactor([[UIScreen mainScreen] scale]),
mGLSupport(glsupport),
mContext(NULL),
mWindow(nil),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class _OgrePrivate WaylandEGLWindow : public EGLWindow
protected:
WaylandEGLSupport* mGLSupport;
wl_surface* mWlSurface;
float mContentScalingFactor = 1.0f;

void initNativeCreatedWindow(const NameValuePairList* miscParams);
void createNativeWindow(uint& width, uint& height);
Expand All @@ -28,6 +29,8 @@ class _OgrePrivate WaylandEGLWindow : public EGLWindow

void create(const String& name, unsigned int width, unsigned int height, bool fullScreen,
const NameValuePairList* miscParams) override;

float getViewPointToPixelScale() override { return mContentScalingFactor; }
};
} // namespace Ogre

Expand Down
39 changes: 33 additions & 6 deletions RenderSystems/GLSupport/src/EGL/Wayland/OgreWaylandEGLWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <EGL/eglext.h>

#include <chrono>
#include <cmath>
#include <thread>

namespace Ogre
Expand Down Expand Up @@ -75,14 +76,18 @@ void WaylandEGLWindow::createNativeWindow(uint& width, uint& height)
wl_display_flush(reinterpret_cast<wl_display*>(mNativeDisplay));
}

void WaylandEGLWindow::resize(uint width, uint height)
void WaylandEGLWindow::resize(uint widthPt, uint heightPt)
{

if (mClosed)
{
return;
}

// the compositor is told a size in view points, but the backbuffer has to
// be allocated in physical pixels for a 1:1 mapping (HiDPI / fractional scaling)
const uint width = std::lround(widthPt * mContentScalingFactor);
const uint height = std::lround(heightPt * mContentScalingFactor);

if (mWidth == width && mHeight == height)
{
return;
Expand All @@ -109,9 +114,19 @@ void WaylandEGLWindow::windowMovedOrResized()
if (mClosed || !mWindow)
return;

// the attached size is already the physical backbuffer size
int width, height;
wl_egl_window_get_attached_size(reinterpret_cast<wl_egl_window*>(mWindow), &width, &height);
resize(width, height);
if (width <= 0 || height <= 0)
return;

const uint oldWidth = mWidth;
const uint oldHeight = mHeight;
RenderWindow::resize(width, height);
wl_surface_damage(mWlSurface, 0, 0, oldWidth, oldHeight);
wl_surface_commit(mWlSurface);
wl_display_dispatch_pending(reinterpret_cast<wl_display*>(mNativeDisplay));
wl_display_flush(reinterpret_cast<wl_display*>(mNativeDisplay));
}

void WaylandEGLWindow::create(const String& name, uint width, uint height, bool fullScreen,
Expand Down Expand Up @@ -192,6 +207,13 @@ void WaylandEGLWindow::create(const String& name, uint width, uint height, bool
mHwGamma = StringConverter::parseBool(opt->second);
}

if ((opt = miscParams->find("contentScalingFactor")) != end)
{
const float scale = StringConverter::parseReal(opt->second);
if (scale > 0.0f)
mContentScalingFactor = scale;
}

if ((opt = miscParams->find("hdrDisplay")) != end)
{
mHdrDisplay = StringConverter::parseBool(opt->second);
Expand Down Expand Up @@ -260,7 +282,12 @@ void WaylandEGLWindow::create(const String& name, uint width, uint height, bool
mGLSupport->switchMode(width, height, frequency);
}

createNativeWindow(width, height);
// width/height are view points, while the EGL window and RenderWindow use
// the physical pixel size the compositor will map 1:1 to the display
uint pixelWidth = std::lround(width * mContentScalingFactor);
uint pixelHeight = std::lround(height * mContentScalingFactor);

createNativeWindow(pixelWidth, pixelHeight);
mEglSurface = createSurfaceFromWindow(mGLSupport->getGLDisplay(), mWindow);
mContext = createEGLContext(eglContext);

Expand All @@ -270,8 +297,8 @@ void WaylandEGLWindow::create(const String& name, uint width, uint height, bool
setVSyncEnabled(vsync);

mName = name;
mWidth = width;
mHeight = height;
mWidth = pixelWidth;
mHeight = pixelHeight;

finaliseWindow();
wl_surface_commit(mWlSurface);
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/GLSupport/src/OSX/OgreOSXCocoaWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ - (BOOL)acceptsFirstResponder

CocoaWindow::CocoaWindow() : GLWindow(), mWindow(nil), mView(nil), mGLContext(nil), mGLPixelFormat(nil), mWindowOriginPt(NSZeroPoint),
mHasResized(false), mWindowTitle(""),
mUseOgreGLView(true), mContentScalingFactor(1.0), mStyleMask(NSResizableWindowMask|NSTitledWindowMask)
mUseOgreGLView(true), mContentScalingFactor([[NSScreen mainScreen] backingScaleFactor]), mStyleMask(NSResizableWindowMask|NSTitledWindowMask)
{
// Set vsync by default to save battery and reduce tearing
}
Expand Down
9 changes: 0 additions & 9 deletions RenderSystems/GLSupport/src/OSX/OgreOSXGL3PlusSupport.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ of this software and associated documentation files (the "Software"), to deal
#import <dlfcn.h>

#import <OpenGL/OpenGL.h>
#import <AppKit/NSScreen.h>

namespace Ogre {

Expand All @@ -52,20 +51,12 @@ of this software and associated documentation files (the "Software"), to deal
{
ConfigOptionMap mOptions;
ConfigOption optBitDepth;
ConfigOption optContentScalingFactor;

optBitDepth.name = "Colour Depth";
optBitDepth.currentValue = "32";
optBitDepth.immutable = false;

optContentScalingFactor.name = "Content Scaling Factor";
optContentScalingFactor.possibleValues.push_back( "1.0" );
optContentScalingFactor.possibleValues.push_back( "2.0" );
optContentScalingFactor.currentValue = StringConverter::toString((float)[NSScreen mainScreen].backingScaleFactor);
optContentScalingFactor.immutable = false;

mOptions[ optBitDepth.name ] = optBitDepth;
mOptions[ optContentScalingFactor.name ] = optContentScalingFactor;

CGLRendererInfoObj rend;
GLint nrend = 0, maxSamples = 0;
Expand Down
3 changes: 3 additions & 0 deletions RenderSystems/Vulkan/include/OgreVulkanWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace Ogre

bool mLowestLatencyVSync;
bool mHdrDisplay;
float mContentScalingFactor = 1.0f;

bool mVisible;
bool mHidden;
Expand Down Expand Up @@ -133,6 +134,8 @@ namespace Ogre

void windowMovedOrResized() override;

float getViewPointToPixelScale() override { return mContentScalingFactor; }

void _setDevice( VulkanDevice *device );

void create(const String& name, unsigned int widthPt, unsigned int heightPt, bool fullScreen,
Expand Down
Loading
Loading