Bläddra i källkod

Support Direct3D9Ex

JoshEngebretson 9 år sedan
förälder
incheckning
51e7334042

+ 62 - 11
Source/Atomic/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -237,6 +237,7 @@ static HWND GetWindowHandle(SDL_Window* window)
 static unsigned readableDepthFormat = 0;
 
 const Vector2 Graphics::pixelUVOffset(0.5f, 0.5f);
+bool Graphics::enableD3D9Ex_ = false;
 
 Graphics::Graphics(Context* context) :
     Object(context),
@@ -2458,7 +2459,24 @@ void Graphics::AdjustWindow(int& newWidth, int& newHeight, bool& newFullscreen,
 
 bool Graphics::CreateInterface()
 {
-    impl_->interface_ = Direct3DCreate9(D3D_SDK_VERSION);
+    if (!enableD3D9Ex_)
+    {
+        impl_->interface_ = Direct3DCreate9(D3D_SDK_VERSION);
+    }
+    else
+    {
+        // TODO: Code for checking whether OS supports Direct3DCreate9Ex: https://msdn.microsoft.com/en-us/library/windows/desktop/bb219676(v=vs.85).aspx
+        // Though, can just check for Windows XP probably
+        if ( FAILED(Direct3DCreate9Ex(D3D_SDK_VERSION, &impl_->interfaceD3D9Ex_)))
+        {
+            impl_->interfaceD3D9Ex_ = 0;
+            LOGERROR("Could not create Direct3D9Ex interface");
+            return false;
+        }
+
+        impl_->interface_ =  impl_->interfaceD3D9Ex_;
+    }
+
     if (!impl_->interface_)
     {
         LOGERROR("Could not create Direct3D9 interface");
@@ -2502,16 +2520,38 @@ bool Graphics::CreateDevice(unsigned adapter, unsigned deviceType)
     else
         behaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
 
-    if (FAILED(impl_->interface_->CreateDevice(
-        adapter,
-        (D3DDEVTYPE)deviceType,
-        GetWindowHandle(impl_->window_),
-        behaviorFlags,
-        &impl_->presentParams_,
-        &impl_->device_)))
+    if (enableD3D9Ex_)
     {
-        LOGERROR("Could not create Direct3D9 device");
-        return false;
+        if (FAILED(impl_->interfaceD3D9Ex_->CreateDeviceEx(
+            adapter,
+            (D3DDEVTYPE)deviceType,
+            GetWindowHandle(impl_->window_),
+            behaviorFlags,
+            &impl_->presentParams_,
+            NULL,
+            &impl_->deviceD3D9Ex_)))
+        {
+            impl_->deviceD3D9Ex_ = 0;
+
+            LOGERROR("Could not create Direct3D9Ex device");
+            return false;
+        }
+
+        impl_->device_ = impl_->deviceD3D9Ex_;
+    }
+    else
+    {
+        if (FAILED(impl_->interface_->CreateDevice(
+            adapter,
+            (D3DDEVTYPE)deviceType,
+            GetWindowHandle(impl_->window_),
+            behaviorFlags,
+            &impl_->presentParams_,
+            &impl_->device_)))
+        {
+            LOGERROR("Could not create Direct3D9 device");
+            return false;
+        }
     }
 
     impl_->adapter_ = adapter;
@@ -2519,7 +2559,7 @@ bool Graphics::CreateDevice(unsigned adapter, unsigned deviceType)
 
     OnDeviceReset();
 
-    LOGINFO("Created Direct3D9 device");
+    LOGINFO(enableD3D9Ex_ ?  "Created Direct3D9Ex device" : "Created Direct3D9 device");
     return true;
 }
 
@@ -2795,6 +2835,17 @@ IntVector2 Graphics::GetMonitorResolution(int monitorId) const
     SDL_GetDesktopDisplayMode(monitorId, &mode);
     return IntVector2(mode.w, mode.h);
 }
+
+unsigned Graphics::GetDefaultD3D9Usage()
+{
+    return enableD3D9Ex_ ? (unsigned)  D3DUSAGE_DYNAMIC : 0;
+}
+
+unsigned Graphics::GetDefaultD3D9Pool()
+{
+    return enableD3D9Ex_ ? (unsigned)  D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
+}
+
 // ATOMIC END
 
 }

+ 14 - 1
Source/Atomic/Graphics/Direct3D9/D3D9Graphics.h

@@ -493,14 +493,23 @@ public:
     static unsigned GetMaxBones() { return 64; }
 
     // ATOMIC BEGIN
+
     /// Return the current monitor number
     int GetCurrentMonitor();
-    /// Return the available monitors number
+    /// Return the available number of monitors
     int GetNumMonitors();
     /// Return true if window is maximized
     bool GetMaximized();
     /// Return monitor resolution
     IntVector2 GetMonitorResolution(int monitorId) const;
+
+    // Enabled Direct3D9Ex extended capabilities Windows Vista+
+    static void SetDirect3D9ExEnabled ( bool enabled) { enableD3D9Ex_ = enabled; }
+    static bool GetDirect3D9ExEnabled () { return enableD3D9Ex_; }
+
+    static unsigned GetDefaultD3D9Usage();
+    static unsigned GetDefaultD3D9Pool();
+
     // ATOMIC END
 
 private:
@@ -686,6 +695,10 @@ private:
 
     /// Pixel perfect UV offset.
     static const Vector2 pixelUVOffset;
+
+    // ATOMIC BEGIN
+    static bool enableD3D9Ex_;
+    // ATOMIC END
 };
 
 /// Register Graphics library objects.

+ 5 - 1
Source/Atomic/Graphics/Direct3D9/D3D9GraphicsImpl.cpp

@@ -38,7 +38,11 @@ GraphicsImpl::GraphicsImpl() :
     defaultDepthStencilSurface_(0),
     frameQuery_(0),
     adapter_(D3DADAPTER_DEFAULT),
-    deviceType_(D3DDEVTYPE_HAL)
+    deviceType_(D3DDEVTYPE_HAL),
+    // ATOMIC BEGIN
+    interfaceD3D9Ex_(0),
+    deviceD3D9Ex_(0)
+    // ATOMIC END
 {
     memset(&presentParams_, 0, sizeof presentParams_);
 }

+ 9 - 0
Source/Atomic/Graphics/Direct3D9/D3D9GraphicsImpl.h

@@ -105,6 +105,15 @@ private:
     D3DBLEND destBlend_;
     /// Blend operation.
     D3DBLENDOP blendOp_;
+
+    // ATOMIC BEGIN:
+
+    /// Direct3D9Ex interface.
+    IDirect3D9Ex* interfaceD3D9Ex_;
+    /// Direct3D9Ex device.
+    IDirect3DDevice9Ex* deviceD3D9Ex_;
+
+    // ATOMIC END
 };
 
 }

+ 2 - 2
Source/Atomic/Graphics/Direct3D9/D3D9IndexBuffer.cpp

@@ -38,7 +38,7 @@ IndexBuffer::IndexBuffer(Context* context) :
     GPUObject(GetSubsystem<Graphics>()),
     indexCount_(0),
     indexSize_(0),
-    pool_(D3DPOOL_MANAGED),
+    pool_(Graphics::GetDefaultD3D9Pool()),
     usage_(0),
     lockState_(LOCK_NONE),
     lockStart_(0),
@@ -120,7 +120,7 @@ bool IndexBuffer::SetSize(unsigned indexCount, bool largeIndices, bool dynamic)
     }
     else
     {
-        pool_ = D3DPOOL_MANAGED;
+        pool_ = Graphics::GetDefaultD3D9Pool();
         usage_ = 0;
     }
 

+ 2 - 2
Source/Atomic/Graphics/Direct3D9/D3D9Texture.cpp

@@ -58,8 +58,8 @@ Texture::Texture(Context* context) :
     Resource(context),
     GPUObject(GetSubsystem<Graphics>()),
     format_(D3DFMT_UNKNOWN),
-    pool_(D3DPOOL_MANAGED),
-    usage_(0),
+    pool_(Graphics::GetDefaultD3D9Pool()),
+    usage_(Graphics::GetDefaultD3D9Usage()),
     levels_(0),
     requestedLevels_(0),
     width_(0),

+ 5 - 2
Source/Atomic/Graphics/Direct3D9/D3D9Texture2D.cpp

@@ -161,16 +161,19 @@ bool Texture2D::SetSize(int width, int height, unsigned format, TextureUsage usa
 {
     // Delete the old rendersurface if any
     renderSurface_.Reset();
-    pool_ = D3DPOOL_MANAGED;
-    usage_ = 0;
+    pool_ = Graphics::GetDefaultD3D9Pool();
+    usage_ = Graphics::GetDefaultD3D9Usage();
 
     if (usage == TEXTURE_RENDERTARGET || usage == TEXTURE_DEPTHSTENCIL)
     {
+        usage_ &= ~Graphics::GetDefaultD3D9Usage();
+
         renderSurface_ = new RenderSurface(this);
         if (usage == TEXTURE_RENDERTARGET)
             usage_ |= D3DUSAGE_RENDERTARGET;
         else
             usage_ |= D3DUSAGE_DEPTHSTENCIL;
+
         pool_ = D3DPOOL_DEFAULT;
 
         // Clamp mode addressing by default, nearest filtering, and mipmaps disabled

+ 4 - 2
Source/Atomic/Graphics/Direct3D9/D3D9Texture3D.cpp

@@ -205,11 +205,13 @@ bool Texture3D::SetSize(int width, int height, int depth, unsigned format, Textu
 {
     // Delete the old rendersurface if any
     renderSurface_.Reset();
-    pool_ = D3DPOOL_MANAGED;
-    usage_ = 0;
+    pool_ = Graphics::GetDefaultD3D9Pool();
+    usage_ = Graphics::GetDefaultD3D9Usage();
 
     if (usage == TEXTURE_RENDERTARGET)
     {
+        usage_ &= ~Graphics::GetDefaultD3D9Usage();
+
         renderSurface_ = new RenderSurface(this);
         usage_ |= D3DUSAGE_RENDERTARGET;
         pool_ = D3DPOOL_DEFAULT;

+ 1 - 1
Source/Atomic/Graphics/Direct3D9/D3D9TextureCube.cpp

@@ -321,7 +321,7 @@ bool TextureCube::SetSize(int size, unsigned format, TextureUsage usage)
         faceMemoryUse_[i] = 0;
     }
 
-    pool_ = D3DPOOL_MANAGED;
+    pool_ = Graphics::GetDirect3D9ExEnabled() ? D3DPOOL_SYSTEMMEM : D3DPOOL_MANAGED;
     usage_ = 0;
 
     if (usage == TEXTURE_RENDERTARGET)

+ 2 - 2
Source/Atomic/Graphics/Direct3D9/D3D9VertexBuffer.cpp

@@ -54,7 +54,7 @@ VertexBuffer::VertexBuffer(Context* context) :
     GPUObject(GetSubsystem<Graphics>()),
     vertexCount_(0),
     elementMask_(0),
-    pool_(D3DPOOL_MANAGED),
+    pool_(Graphics::GetDefaultD3D9Pool()),
     usage_(0),
     lockState_(LOCK_NONE),
     lockStart_(0),
@@ -141,7 +141,7 @@ bool VertexBuffer::SetSize(unsigned vertexCount, unsigned elementMask, bool dyna
     }
     else
     {
-        pool_ = D3DPOOL_MANAGED;
+        pool_ = Graphics::GetDefaultD3D9Pool();
         usage_ = 0;
     }
 

+ 5 - 2
Source/AtomicEditor/Application/AEEditorCommon.cpp

@@ -98,13 +98,16 @@ void AEEditorCommon::Start()
     jsapi_init_atomicnet(vm_);
 #endif
 
-
-
 }
 
 void AEEditorCommon::Setup()
 {
 
+#if !defined(ATOMIC_OPENGL) && !defined(ATOMIC_D3D11)
+    // Enable Direct3D9Ex for extended features required by the editor
+    Graphics::SetDirect3D9ExEnabled(true);
+#endif
+
 #ifdef ATOMIC_3D
     RegisterEnvironmentLibrary(context_);
 #endif