Przeglądaj źródła

Set GAPI even in headless mode

1vanK 3 lat temu
rodzic
commit
18e410188b

+ 3 - 0
Source/Urho3D/AngelScript/Generated_Members.h

@@ -10619,6 +10619,9 @@ template <class T> void RegisterMembers_Graphics(asIScriptEngine* engine, const
     // static GAPI Graphics::GetGAPI()
     // static GAPI Graphics::GetGAPI()
     engine->SetDefaultNamespace(className);engine->RegisterGlobalFunction("GAPI GetGAPI()", AS_FUNCTIONPR(T::GetGAPI, (), GAPI), AS_CALL_CDECL);engine->SetDefaultNamespace("");
     engine->SetDefaultNamespace(className);engine->RegisterGlobalFunction("GAPI GetGAPI()", AS_FUNCTIONPR(T::GetGAPI, (), GAPI), AS_CALL_CDECL);engine->SetDefaultNamespace("");
 
 
+    // static GAPI Graphics::SetGAPI(GAPI value)
+    engine->SetDefaultNamespace(className);engine->RegisterGlobalFunction("GAPI SetGAPI(GAPI)", AS_FUNCTIONPR(T::SetGAPI, (GAPI), GAPI), AS_CALL_CDECL);engine->SetDefaultNamespace("");
+
     // static unsigned Graphics::GetAlphaFormat()
     // static unsigned Graphics::GetAlphaFormat()
     engine->SetDefaultNamespace(className);engine->RegisterGlobalFunction("uint GetAlphaFormat()", AS_FUNCTIONPR(T::GetAlphaFormat, (), unsigned), AS_CALL_CDECL);engine->SetDefaultNamespace("");
     engine->SetDefaultNamespace(className);engine->RegisterGlobalFunction("uint GetAlphaFormat()", AS_FUNCTIONPR(T::GetAlphaFormat, (), unsigned), AS_CALL_CDECL);engine->SetDefaultNamespace("");
 
 

+ 23 - 19
Source/Urho3D/Engine/Engine.cpp

@@ -158,46 +158,50 @@ bool Engine::Initialize(const VariantMap& parameters)
     // Set headless mode
     // Set headless mode
     headless_ = GetParameter(parameters, EP_HEADLESS, false).GetBool();
     headless_ = GetParameter(parameters, EP_HEADLESS, false).GetBool();
 
 
-    // Register the rest of the subsystems
-    if (!headless_)
-    {
-        GAPI gapi = GAPI_NONE;
+    // Detect GAPI even in headless mode
+    // https://github.com/urho3d/Urho3D/issues/3040
+    GAPI gapi = GAPI_NONE;
 
 
-        // Try to set any possible graphics API as default
+    // Try to set any possible graphics API as default
 
 
 #ifdef URHO3D_OPENGL
 #ifdef URHO3D_OPENGL
-        gapi = GAPI_OPENGL;
+    gapi = GAPI_OPENGL;
 #endif
 #endif
 
 
 #ifdef URHO3D_D3D11
 #ifdef URHO3D_D3D11
-        gapi = GAPI_D3D11;
+    gapi = GAPI_D3D11;
 #endif
 #endif
 
 
-        // Use command line parameters
+    // Use command line parameters
 
 
 #ifdef URHO3D_OPENGL
 #ifdef URHO3D_OPENGL
-        bool gapi_gl = GetParameter(parameters, EP_OPENGL, false).GetBool();
-        if (gapi_gl)
-            gapi = GAPI_OPENGL;
+    bool gapi_gl = GetParameter(parameters, EP_OPENGL, false).GetBool();
+    if (gapi_gl)
+        gapi = GAPI_OPENGL;
 #endif
 #endif
 
 
 #ifdef URHO3D_D3D11
 #ifdef URHO3D_D3D11
-        bool gapi_d3d11 = GetParameter(parameters, EP_DIRECT3D11, false).GetBool();
-        if (gapi_d3d11)
-            gapi = GAPI_D3D11;
+    bool gapi_d3d11 = GetParameter(parameters, EP_DIRECT3D11, false).GetBool();
+    if (gapi_d3d11)
+        gapi = GAPI_D3D11;
 #endif
 #endif
 
 
-        if (gapi == GAPI_NONE)
-        {
-            URHO3D_LOGERROR("Graphics API not selected");
-            return false;
-        }
+    if (gapi == GAPI_NONE)
+    {
+        URHO3D_LOGERROR("Graphics API not selected");
+        return false;
+    }
 
 
+    // Register the rest of the subsystems
+    if (!headless_)
+    {
         context_->RegisterSubsystem(new Graphics(context_, gapi));
         context_->RegisterSubsystem(new Graphics(context_, gapi));
         context_->RegisterSubsystem(new Renderer(context_));
         context_->RegisterSubsystem(new Renderer(context_));
     }
     }
     else
     else
     {
     {
+        Graphics::SetGAPI(gapi); // https://github.com/urho3d/Urho3D/issues/3040
+
         // Register graphics library objects explicitly in headless mode to allow them to work without using actual GPU resources
         // Register graphics library objects explicitly in headless mode to allow them to work without using actual GPU resources
         RegisterGraphicsLibrary(context_);
         RegisterGraphicsLibrary(context_);
     }
     }

+ 3 - 0
Source/Urho3D/Graphics/Graphics.h

@@ -684,6 +684,9 @@ public:
     /// Get used graphics API.
     /// Get used graphics API.
     static GAPI GetGAPI() { return gapi; }
     static GAPI GetGAPI() { return gapi; }
 
 
+    /// Set GAP manually. Used for headless mode only https://github.com/urho3d/Urho3D/issues/3040
+    static GAPI SetGAPI(GAPI value) { return gapi = value; }
+
     /// Return the API-specific alpha texture format.
     /// Return the API-specific alpha texture format.
     static unsigned GetAlphaFormat();
     static unsigned GetAlphaFormat();
     /// Return the API-specific luminance texture format.
     /// Return the API-specific luminance texture format.