Forráskód Böngészése

Add new engine parameter for enabling/disabling high DPI window mode.
Temporary fix for issue #1252. The high DPI mode is disabled by default.

Yao Wei Tjong 姚伟忠 9 éve
szülő
commit
31d362f879

+ 1 - 0
Docs/GettingStarted.dox

@@ -387,6 +387,7 @@ The engine can be configured using the following command line options.
 -t           Enable triple buffering
 -w           Start in windowed mode
 -s           Enable resizing when in windowed mode
+-hd          Enable high DPI, only supported by Apple platforms (OSX, iOS, and tvOS)
 -q           Enable quiet mode which does not log to standard output stream
 -b <length>  Sound buffer length in milliseconds
 -r <freq>    Sound mixing frequency in Hz

+ 2 - 1
Docs/Reference.dox

@@ -196,9 +196,10 @@ The full list of supported parameters, their datatypes and default values:
 - WindowHeight (int) %Window vertical dimension. Default 0 (use desktop resolution, or 768 in windowed mode.)
 - WindowPositionX (int) %Window horizontal position. Default center to screen.
 - WindowPositionY (int) %Window vertical position. Default center to screen.
-- WindowResizable (bool) Whether window is resizable. Default false.
 - FullScreen (bool) Whether to create a full-screen window. Default true.
 - Borderless (bool) Whether to create the window as borderless. Default false.
+- WindowResizable (bool) Whether window is resizable. Default false.
+- HighDPI (bool) Whether window is high DPI. Default false. Currently only supported by Apple platforms (OSX, iOS, and tvOS).
 - TripleBuffer (bool) Whether to use triple-buffering. Default false.
 - VSync (bool) Whether to wait for vertical sync when presenting rendering window contents. Default false.
 - FlushGPU (bool) Whether to flush GPU command buffer each frame (Direct3D9) or limit the amount of buffered frames (Direct3D11) for less input latency. Ineffective on OpenGL. Default false.

+ 1 - 0
Source/Tools/Urho3DPlayer/Urho3DPlayer.cpp

@@ -84,6 +84,7 @@ void Urho3DPlayer::Setup()
             "-t           Enable triple buffering\n"
             "-w           Start in windowed mode\n"
             "-s           Enable resizing when in windowed mode\n"
+            "-hd          Enable high DPI, only supported by Apple platforms (OSX, iOS, and tvOS)\n"
             "-q           Enable quiet mode which does not log to standard output stream\n"
             "-b <length>  Sound buffer length in milliseconds\n"
             "-r <freq>    Sound mixing frequency in Hz\n"

+ 2 - 2
Source/Urho3D/AngelScript/GraphicsAPI.cpp

@@ -527,7 +527,7 @@ static void RegisterTextures(asIScriptEngine* engine)
     RegisterTexture<TextureCube>(engine, "TextureCube");
     engine->RegisterObjectMethod("TextureCube", "bool SetSize(int, uint, TextureUsage usage = TEXTURE_STATIC)", asMETHOD(TextureCube, SetSize), asCALL_THISCALL);
     engine->RegisterObjectMethod("TextureCube", "bool SetData(CubeMapFace, Image@+, bool useAlpha = false)", asMETHODPR(TextureCube, SetData, (CubeMapFace, Image*, bool), bool), asCALL_THISCALL);
-    engine->RegisterObjectMethod("TextureCube", "Image@+ GetImage(CubeMapFace) const", asFUNCTION(TextureCubeGetImage), asCALL_CDECL_OBJLAST); 
+    engine->RegisterObjectMethod("TextureCube", "Image@+ GetImage(CubeMapFace) const", asFUNCTION(TextureCubeGetImage), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("TextureCube", "RenderSurface@+ get_renderSurfaces(CubeMapFace) const", asMETHOD(TextureCube, GetRenderSurface), asCALL_THISCALL);
 
     engine->RegisterGlobalFunction("uint GetAlphaFormat()", asFUNCTION(Graphics::GetAlphaFormat), asCALL_CDECL);
@@ -1721,7 +1721,7 @@ static Graphics* GetGraphics()
 static void RegisterGraphics(asIScriptEngine* engine)
 {
     RegisterObject<Graphics>(engine, "Graphics");
-    engine->RegisterObjectMethod("Graphics", "bool SetMode(int, int, bool, bool, bool, bool, bool, int)", asMETHODPR(Graphics, SetMode, (int, int, bool, bool, bool, bool, bool, int), bool), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Graphics", "bool SetMode(int, int, bool, bool, bool, bool, bool, bool, int)", asMETHODPR(Graphics, SetMode, (int, int, bool, bool, bool, bool, bool, bool, int), bool), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool SetMode(int, int)", asMETHODPR(Graphics, SetMode, (int, int), bool), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "void SetWindowPosition(int, int)", asMETHODPR(Graphics, SetWindowPosition, (int, int), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool ToggleFullscreen()", asMETHOD(Graphics, ToggleFullscreen), asCALL_THISCALL);

+ 5 - 2
Source/Urho3D/Engine/Engine.cpp

@@ -370,6 +370,7 @@ bool Engine::Initialize(const VariantMap& parameters)
             GetParameter(parameters, "FullScreen", true).GetBool(),
             GetParameter(parameters, "Borderless", false).GetBool(),
             GetParameter(parameters, "WindowResizable", false).GetBool(),
+            GetParameter(parameters, "HighDPI", false).GetBool(),
             GetParameter(parameters, "VSync", false).GetBool(),
             GetParameter(parameters, "TripleBuffer", false).GetBool(),
             GetParameter(parameters, "MultiSample", 1).GetInt()
@@ -790,10 +791,12 @@ VariantMap Engine::ParseParameters(const Vector<String>& arguments)
                 ret["TripleBuffer"] = true;
             else if (argument == "w")
                 ret["FullScreen"] = false;
-            else if (argument == "s")
-                ret["WindowResizable"] = true;
             else if (argument == "borderless")
                 ret["Borderless"] = true;
+            else if (argument == "s")
+                ret["WindowResizable"] = true;
+            else if (argument == "hd")
+                ret["HighDPI"] = true;
             else if (argument == "q")
                 ret["LogQuiet"] = true;
             else if (argument == "log" && !value.Empty())

+ 10 - 5
Source/Urho3D/Graphics/Direct3D11/D3D11Graphics.cpp

@@ -226,6 +226,7 @@ Graphics::Graphics(Context* context) :
     fullscreen_(false),
     borderless_(false),
     resizable_(false),
+    highDPI_(false),
     vsync_(false),
     tripleBuffer_(false),
     flushGPU_(false),
@@ -345,11 +346,13 @@ void Graphics::SetWindowPosition(int x, int y)
     SetWindowPosition(IntVector2(x, y));
 }
 
-bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless, bool resizable, bool vsync, bool tripleBuffer,
+bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless, bool resizable, bool highDPI, bool vsync, bool tripleBuffer,
     int multiSample)
 {
     URHO3D_PROFILE(SetScreenMode);
 
+    highDPI = false;   // SDL does not support High DPI mode on Windows platform yet, so always disable it for now
+
     bool maximize = false;
 
     // Find out the full screen mode display format (match desktop color depth)
@@ -433,6 +436,7 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
     fullscreen_ = fullscreen;
     borderless_ = borderless;
     resizable_ = resizable;
+    highDPI_ = highDPI;
     vsync_ = vsync;
     tripleBuffer_ = tripleBuffer;
 
@@ -458,8 +462,9 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
     eventData[P_WIDTH] = width_;
     eventData[P_HEIGHT] = height_;
     eventData[P_FULLSCREEN] = fullscreen_;
-    eventData[P_RESIZABLE] = resizable_;
     eventData[P_BORDERLESS] = borderless_;
+    eventData[P_RESIZABLE] = resizable_;
+    eventData[P_HIGHDPI] = highDPI_;
     SendEvent(E_SCREENMODE, eventData);
 
     return true;
@@ -467,7 +472,7 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
 
 bool Graphics::SetMode(int width, int height)
 {
-    return SetMode(width, height, fullscreen_, borderless_, resizable_, vsync_, tripleBuffer_, multiSample_);
+    return SetMode(width, height, fullscreen_, borderless_, resizable_, highDPI_, vsync_, tripleBuffer_, multiSample_);
 }
 
 void Graphics::SetSRGB(bool enable)
@@ -509,7 +514,7 @@ void Graphics::SetOrientations(const String& orientations)
 
 bool Graphics::ToggleFullscreen()
 {
-    return SetMode(width_, height_, !fullscreen_, borderless_, resizable_, vsync_, tripleBuffer_, multiSample_);
+    return SetMode(width_, height_, !fullscreen_, borderless_, resizable_, highDPI_, vsync_, tripleBuffer_, multiSample_);
 }
 
 void Graphics::Close()
@@ -2585,7 +2590,7 @@ void Graphics::PrepareDraw()
             newVertexDeclarationHash += vertexShader_->GetElementHash();
             if (newVertexDeclarationHash != vertexDeclarationHash_)
             {
-                HashMap<unsigned long long, SharedPtr<VertexDeclaration> >::Iterator i = 
+                HashMap<unsigned long long, SharedPtr<VertexDeclaration> >::Iterator i =
                     vertexDeclarations_.Find(newVertexDeclarationHash);
                 if (i == vertexDeclarations_.End())
                 {

+ 9 - 3
Source/Urho3D/Graphics/Direct3D11/D3D11Graphics.h

@@ -100,7 +100,8 @@ public:
     void SetWindowPosition(int x, int y);
     /// Set screen mode. Return true if successful.
     bool SetMode
-        (int width, int height, bool fullscreen, bool borderless, bool resizable, bool vsync, bool tripleBuffer, int multiSample);
+        (int width, int height, bool fullscreen, bool borderless, bool resizable, bool highDPI, bool vsync, bool tripleBuffer,
+            int multiSample);
     /// Set screen resolution only. Return true if successful.
     bool SetMode(int width, int height);
     /// Set whether the main window uses sRGB conversion on write.
@@ -265,11 +266,14 @@ public:
     /// Return whether window is fullscreen.
     bool GetFullscreen() const { return fullscreen_; }
 
+    /// Return whether window is borderless.
+    bool GetBorderless() const { return borderless_; }
+
     /// Return whether window is resizable.
     bool GetResizable() const { return resizable_; }
 
-    /// Return whether window is borderless.
-    bool GetBorderless() const { return borderless_; }
+    /// Return whether window is high DPI.
+    bool GetHighDPI() const { return highDPI_; }
 
     /// Return whether vertical sync is on.
     bool GetVSync() const { return vsync_; }
@@ -541,6 +545,8 @@ private:
     bool borderless_;
     /// Resizable flag.
     bool resizable_;
+    /// High DPI flag.
+    bool highDPI_;
     /// Vertical sync flag.
     bool vsync_;
     /// Triple buffering flag.

+ 10 - 5
Source/Urho3D/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -268,6 +268,7 @@ Graphics::Graphics(Context* context) :
     fullscreen_(false),
     borderless_(false),
     resizable_(false),
+    highDPI_(false),
     vsync_(false),
     tripleBuffer_(false),
     flushGPU_(false),
@@ -366,11 +367,13 @@ void Graphics::SetWindowPosition(int x, int y)
     SetWindowPosition(IntVector2(x, y));
 }
 
-bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless, bool resizable, bool vsync, bool tripleBuffer,
-    int multiSample)
+bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless, bool resizable, bool highDPI, bool vsync,
+    bool tripleBuffer, int multiSample)
 {
     URHO3D_PROFILE(SetScreenMode);
 
+    highDPI = false;   // SDL does not support High DPI mode on Windows platform yet, so always disable it for now
+
     bool maximize = false;
 
     // Find out the full screen mode display format (match desktop color depth)
@@ -501,6 +504,7 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
     fullscreen_ = fullscreen;
     borderless_ = borderless;
     resizable_ = resizable;
+    highDPI_ = highDPI;
     vsync_ = vsync;
     tripleBuffer_ = tripleBuffer;
 
@@ -553,8 +557,9 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
     eventData[P_WIDTH] = width_;
     eventData[P_HEIGHT] = height_;
     eventData[P_FULLSCREEN] = fullscreen_;
-    eventData[P_RESIZABLE] = resizable_;
     eventData[P_BORDERLESS] = borderless_;
+    eventData[P_RESIZABLE] = resizable_;
+    eventData[P_HIGHDPI] = highDPI_;
     SendEvent(E_SCREENMODE, eventData);
 
     return true;
@@ -562,7 +567,7 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
 
 bool Graphics::SetMode(int width, int height)
 {
-    return SetMode(width, height, fullscreen_, borderless_, resizable_, vsync_, tripleBuffer_, multiSample_);
+    return SetMode(width, height, fullscreen_, borderless_, resizable_, highDPI_, vsync_, tripleBuffer_, multiSample_);
 }
 
 void Graphics::SetSRGB(bool enable)
@@ -583,7 +588,7 @@ void Graphics::SetOrientations(const String& orientations)
 
 bool Graphics::ToggleFullscreen()
 {
-    return SetMode(width_, height_, !fullscreen_, borderless_, resizable_, vsync_, tripleBuffer_, multiSample_);
+    return SetMode(width_, height_, !fullscreen_, borderless_, resizable_, highDPI_, vsync_, tripleBuffer_, multiSample_);
 }
 
 void Graphics::Close()

+ 9 - 3
Source/Urho3D/Graphics/Direct3D9/D3D9Graphics.h

@@ -97,7 +97,8 @@ public:
     void SetWindowPosition(int x, int y);
     /// Set screen mode. Return true if successful.
     bool SetMode
-        (int width, int height, bool fullscreen, bool borderless, bool resizable, bool vsync, bool tripleBuffer, int multiSample);
+        (int width, int height, bool fullscreen, bool borderless, bool resizable, bool vsync, bool highDPI, bool tripleBuffer,
+            int multiSample);
     /// Set screen resolution only. Return true if successful.
     bool SetMode(int width, int height);
     /// Set whether the main window uses sRGB conversion on write.
@@ -260,11 +261,14 @@ public:
     /// Return whether window is fullscreen.
     bool GetFullscreen() const { return fullscreen_; }
 
+    /// Return whether window is borderless.
+    bool GetBorderless() const { return borderless_; }
+
     /// Return whether window is resizable.
     bool GetResizable() const { return resizable_; }
 
-    /// Return whether window is borderless.
-    bool GetBorderless() const { return borderless_; }
+    /// Return whether window is high DPI.
+    bool GetHighDPI() const { return highDPI_; }
 
     /// Return whether vertical sync is on.
     bool GetVSync() const { return vsync_; }
@@ -540,6 +544,8 @@ private:
     bool borderless_;
     /// Resizable flag.
     bool resizable_;
+    /// High DPI flag.
+    bool highDPI_;
     /// Vertical sync flag.
     bool vsync_;
     /// Triple buffering flag.

+ 2 - 1
Source/Urho3D/Graphics/GraphicsEvents.h

@@ -33,8 +33,9 @@ URHO3D_EVENT(E_SCREENMODE, ScreenMode)
     URHO3D_PARAM(P_WIDTH, Width);                  // int
     URHO3D_PARAM(P_HEIGHT, Height);                // int
     URHO3D_PARAM(P_FULLSCREEN, Fullscreen);        // bool
-    URHO3D_PARAM(P_RESIZABLE, Resizable);          // bool
     URHO3D_PARAM(P_BORDERLESS, Borderless);        // bool
+    URHO3D_PARAM(P_RESIZABLE, Resizable);          // bool
+    URHO3D_PARAM(P_HIGHDPI, HighDPI);              // bool
 }
 
 /// Window position changed.

+ 14 - 12
Source/Urho3D/Graphics/OpenGL/OGLGraphics.cpp

@@ -250,6 +250,7 @@ Graphics::Graphics(Context* context_) :
     fullscreen_(false),
     borderless_(false),
     resizable_(false),
+    highDPI_(false),
     vsync_(false),
     tripleBuffer_(false),
     sRGB_(false),
@@ -335,8 +336,8 @@ void Graphics::SetWindowPosition(int x, int y)
     SetWindowPosition(IntVector2(x, y));
 }
 
-bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless, bool resizable, bool vsync, bool tripleBuffer,
-    int multiSample)
+bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless, bool resizable, bool highDPI, bool vsync,
+    bool tripleBuffer, int multiSample)
 {
     URHO3D_PROFILE(SetScreenMode);
 
@@ -475,13 +476,12 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
         unsigned flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
         if (fullscreen)
             flags |= SDL_WINDOW_FULLSCREEN;
-        if (resizable)
-            flags |= SDL_WINDOW_RESIZABLE;
         if (borderless)
             flags |= SDL_WINDOW_BORDERLESS;
-#ifdef __APPLE__
+        if (resizable)
+            flags |= SDL_WINDOW_RESIZABLE;
+        if (highDPI)
             flags |= SDL_WINDOW_ALLOW_HIGHDPI;
-#endif
 
         SDL_SetHint(SDL_HINT_ORIENTATIONS, orientations_.CString());
 
@@ -542,8 +542,9 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
 #endif
 
     fullscreen_ = fullscreen;
-    resizable_ = resizable;
     borderless_ = borderless;
+    resizable_ = resizable;
+    highDPI_ = highDPI;
     vsync_ = vsync;
     tripleBuffer_ = tripleBuffer;
     multiSample_ = multiSample;
@@ -579,8 +580,9 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
     eventData[P_WIDTH] = width_;
     eventData[P_HEIGHT] = height_;
     eventData[P_FULLSCREEN] = fullscreen_;
-    eventData[P_RESIZABLE] = resizable_;
     eventData[P_BORDERLESS] = borderless_;
+    eventData[P_RESIZABLE] = resizable_;
+    eventData[P_HIGHDPI] = highDPI_;
     SendEvent(E_SCREENMODE, eventData);
 
     return true;
@@ -588,7 +590,7 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
 
 bool Graphics::SetMode(int width, int height)
 {
-    return SetMode(width, height, fullscreen_, borderless_, resizable_, vsync_, tripleBuffer_, multiSample_);
+    return SetMode(width, height, fullscreen_, borderless_, resizable_, highDPI_, vsync_, tripleBuffer_, multiSample_);
 }
 
 void Graphics::SetSRGB(bool enable)
@@ -625,7 +627,7 @@ void Graphics::SetOrientations(const String& orientations)
 
 bool Graphics::ToggleFullscreen()
 {
-    return SetMode(width_, height_, !fullscreen_, borderless_, resizable_, vsync_, tripleBuffer_, multiSample_);
+    return SetMode(width_, height_, !fullscreen_, borderless_, resizable_, highDPI_, vsync_, tripleBuffer_, multiSample_);
 }
 
 void Graphics::Close()
@@ -886,7 +888,7 @@ void Graphics::DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned i
 #endif
 }
 
-void Graphics::DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex, 
+void Graphics::DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex,
         unsigned vertexCount, unsigned instanceCount)
 {
 #ifndef GL_ES_VERSION_2_0
@@ -3099,7 +3101,7 @@ void Graphics::PrepareDraw()
             for (PODVector<VertexElement>::ConstIterator j = elements.Begin(); j != elements.End(); ++j)
             {
                 const VertexElement& element = *j;
-                HashMap<Pair<unsigned char, unsigned char>, unsigned>::ConstIterator k = 
+                HashMap<Pair<unsigned char, unsigned char>, unsigned>::ConstIterator k =
                     impl_->vertexAttributes_->Find(MakePair((unsigned char)element.semantic_, element.index_));
 
                 if (k != impl_->vertexAttributes_->End())

+ 8 - 2
Source/Urho3D/Graphics/OpenGL/OGLGraphics.h

@@ -97,7 +97,8 @@ public:
     void SetWindowPosition(int x, int y);
     /// Set screen mode. Return true if successful.
     bool SetMode
-        (int width, int height, bool fullscreen, bool borderless, bool resizable, bool vsync, bool tripleBuffer, int multiSample);
+        (int width, int height, bool fullscreen, bool borderless, bool resizable, bool highDPI, bool vsync, bool tripleBuffer,
+            int multiSample);
     /// Set screen resolution only. Return true if successful.
     bool SetMode(int width, int height);
     /// Set whether the main window uses sRGB conversion on write.
@@ -132,7 +133,7 @@ public:
     void DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount,
         unsigned instanceCount);
     /// Draw indexed, instanced geometry with vertex index offset. Only supported on desktop OpenGL 3.2 or greater.
-    void DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex, 
+    void DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex,
         unsigned vertexCount, unsigned instanceCount);
     /// Set vertex buffer.
     void SetVertexBuffer(VertexBuffer* buffer);
@@ -272,6 +273,9 @@ public:
     /// Return whether window is resizable.
     bool GetResizable() const { return resizable_; }
 
+    /// Return whether window is high DPI.
+    bool GetHighDPI() const { return highDPI_; }
+
     /// Return whether vertical sync is on.
     bool GetVSync() const { return vsync_; }
 
@@ -577,6 +581,8 @@ private:
     bool borderless_;
     /// Resizable flag.
     bool resizable_;
+    /// High DPI flag.
+    bool highDPI_;
     /// Vertical sync flag.
     bool vsync_;
     /// Triple buffering flag.

+ 2 - 2
Source/Urho3D/LuaScript/pkgs/Graphics/Graphics.pkg

@@ -8,9 +8,9 @@ class Graphics : public Object
     void SetWindowPosition(const IntVector2& position);
     void SetWindowPosition(int x, int y);
 
-    bool SetMode(int width, int height, bool fullscreen, bool borderless, bool resizable, bool vsync, bool tripleBuffer, int multiSample);
+    bool SetMode(int width, int height, bool fullscreen, bool borderless, bool resizable, bool highDPI, bool vsync, bool tripleBuffer, int multiSample);
     bool SetMode(int width, int height);
-    
+
     void SetSRGB(bool enable);
     void SetFlushGPU(bool enable);
     void SetOrientations(const String orientations);