Browse Source

Support building engine with multiple graphics API [cache clear] (#2885)

1vanK 3 years ago
parent
commit
70a858459e
94 changed files with 6135 additions and 1759 deletions
  1. 6 2
      Docs/GettingStarted.dox
  2. 4 1
      Source/CMakeLists.txt
  3. 4 5
      Source/ThirdParty/SDL/CMakeLists.txt
  4. 5 5
      Source/Urho3D/AngelScript/Generated_Classes.cpp
  5. 7 0
      Source/Urho3D/AngelScript/Generated_Enums.cpp
  6. 9 0
      Source/Urho3D/AngelScript/Generated_GlobalVariables.cpp
  7. 6 33
      Source/Urho3D/AngelScript/Generated_Members.h
  8. 12 10
      Source/Urho3D/CMakeLists.txt
  9. 54 5
      Source/Urho3D/Engine/Engine.cpp
  10. 3 0
      Source/Urho3D/Engine/EngineDefs.h
  11. 45 35
      Source/Urho3D/Graphics/Batch.cpp
  12. 15 11
      Source/Urho3D/Graphics/Camera.cpp
  13. 80 0
      Source/Urho3D/Graphics/ConstantBuffer.cpp
  14. 21 0
      Source/Urho3D/Graphics/ConstantBuffer.h
  15. 8 8
      Source/Urho3D/Graphics/Direct3D11/D3D11ConstantBuffer.cpp
  16. 258 216
      Source/Urho3D/Graphics/Direct3D11/D3D11Graphics.cpp
  17. 4 4
      Source/Urho3D/Graphics/Direct3D11/D3D11GraphicsImpl.cpp
  18. 9 9
      Source/Urho3D/Graphics/Direct3D11/D3D11GraphicsImpl.h
  19. 26 26
      Source/Urho3D/Graphics/Direct3D11/D3D11IndexBuffer.cpp
  20. 7 7
      Source/Urho3D/Graphics/Direct3D11/D3D11RenderSurface.cpp
  21. 3 3
      Source/Urho3D/Graphics/Direct3D11/D3D11ShaderProgram.h
  22. 21 21
      Source/Urho3D/Graphics/Direct3D11/D3D11ShaderVariation.cpp
  23. 12 12
      Source/Urho3D/Graphics/Direct3D11/D3D11Texture.cpp
  24. 39 39
      Source/Urho3D/Graphics/Direct3D11/D3D11Texture2D.cpp
  25. 33 33
      Source/Urho3D/Graphics/Direct3D11/D3D11Texture2DArray.cpp
  26. 31 31
      Source/Urho3D/Graphics/Direct3D11/D3D11Texture3D.cpp
  27. 36 36
      Source/Urho3D/Graphics/Direct3D11/D3D11TextureCube.cpp
  28. 29 29
      Source/Urho3D/Graphics/Direct3D11/D3D11VertexBuffer.cpp
  29. 6 6
      Source/Urho3D/Graphics/Direct3D11/D3D11VertexDeclaration.cpp
  30. 3 3
      Source/Urho3D/Graphics/Direct3D11/D3D11VertexDeclaration.h
  31. 4 4
      Source/Urho3D/Graphics/Direct3D9/D3D9ConstantBuffer.cpp
  32. 241 206
      Source/Urho3D/Graphics/Direct3D9/D3D9Graphics.cpp
  33. 4 4
      Source/Urho3D/Graphics/Direct3D9/D3D9GraphicsImpl.cpp
  34. 10 10
      Source/Urho3D/Graphics/Direct3D9/D3D9GraphicsImpl.h
  35. 26 26
      Source/Urho3D/Graphics/Direct3D9/D3D9IndexBuffer.cpp
  36. 6 6
      Source/Urho3D/Graphics/Direct3D9/D3D9RenderSurface.cpp
  37. 2 2
      Source/Urho3D/Graphics/Direct3D9/D3D9ShaderProgram.h
  38. 19 19
      Source/Urho3D/Graphics/Direct3D9/D3D9ShaderVariation.cpp
  39. 6 6
      Source/Urho3D/Graphics/Direct3D9/D3D9Texture.cpp
  40. 27 27
      Source/Urho3D/Graphics/Direct3D9/D3D9Texture2D.cpp
  41. 16 16
      Source/Urho3D/Graphics/Direct3D9/D3D9Texture2DArray.cpp
  42. 23 23
      Source/Urho3D/Graphics/Direct3D9/D3D9Texture3D.cpp
  43. 28 28
      Source/Urho3D/Graphics/Direct3D9/D3D9TextureCube.cpp
  44. 29 29
      Source/Urho3D/Graphics/Direct3D9/D3D9VertexBuffer.cpp
  45. 16 16
      Source/Urho3D/Graphics/Direct3D9/D3D9VertexDeclaration.cpp
  46. 7 7
      Source/Urho3D/Graphics/Direct3D9/D3D9VertexDeclaration.h
  47. 9 9
      Source/Urho3D/Graphics/GPUObject.cpp
  48. 2034 4
      Source/Urho3D/Graphics/Graphics.cpp
  49. 522 64
      Source/Urho3D/Graphics/Graphics.h
  50. 8 0
      Source/Urho3D/Graphics/GraphicsDefs.h
  51. 8 4
      Source/Urho3D/Graphics/GraphicsImpl.h
  52. 220 0
      Source/Urho3D/Graphics/IndexBuffer.cpp
  53. 42 0
      Source/Urho3D/Graphics/IndexBuffer.h
  54. 8 8
      Source/Urho3D/Graphics/OpenGL/OGLConstantBuffer.cpp
  55. 208 187
      Source/Urho3D/Graphics/OpenGL/OGLGraphics.cpp
  56. 6 6
      Source/Urho3D/Graphics/OpenGL/OGLGraphicsImpl.h
  57. 20 20
      Source/Urho3D/Graphics/OpenGL/OGLIndexBuffer.cpp
  58. 10 10
      Source/Urho3D/Graphics/OpenGL/OGLRenderSurface.cpp
  59. 19 19
      Source/Urho3D/Graphics/OpenGL/OGLShaderProgram.cpp
  60. 3 3
      Source/Urho3D/Graphics/OpenGL/OGLShaderProgram.h
  61. 8 15
      Source/Urho3D/Graphics/OpenGL/OGLShaderVariation.cpp
  62. 10 10
      Source/Urho3D/Graphics/OpenGL/OGLTexture.cpp
  63. 29 29
      Source/Urho3D/Graphics/OpenGL/OGLTexture2D.cpp
  64. 32 32
      Source/Urho3D/Graphics/OpenGL/OGLTexture2DArray.cpp
  65. 27 27
      Source/Urho3D/Graphics/OpenGL/OGLTexture3D.cpp
  66. 33 33
      Source/Urho3D/Graphics/OpenGL/OGLTextureCube.cpp
  67. 24 24
      Source/Urho3D/Graphics/OpenGL/OGLVertexBuffer.cpp
  68. 89 0
      Source/Urho3D/Graphics/RenderSurface.cpp
  69. 21 0
      Source/Urho3D/Graphics/RenderSurface.h
  70. 42 30
      Source/Urho3D/Graphics/Renderer.cpp
  71. 5 4
      Source/Urho3D/Graphics/Shader.cpp
  72. 0 33
      Source/Urho3D/Graphics/ShaderProgram.h
  73. 80 0
      Source/Urho3D/Graphics/ShaderVariation.cpp
  74. 55 6
      Source/Urho3D/Graphics/ShaderVariation.h
  75. 120 0
      Source/Urho3D/Graphics/Texture.cpp
  76. 52 15
      Source/Urho3D/Graphics/Texture.h
  77. 142 1
      Source/Urho3D/Graphics/Texture2D.cpp
  78. 30 0
      Source/Urho3D/Graphics/Texture2D.h
  79. 162 1
      Source/Urho3D/Graphics/Texture2DArray.cpp
  80. 33 0
      Source/Urho3D/Graphics/Texture2DArray.h
  81. 142 1
      Source/Urho3D/Graphics/Texture3D.cpp
  82. 30 0
      Source/Urho3D/Graphics/Texture3D.h
  83. 164 2
      Source/Urho3D/Graphics/TextureCube.cpp
  84. 33 0
      Source/Urho3D/Graphics/TextureCube.h
  85. 220 0
      Source/Urho3D/Graphics/VertexBuffer.cpp
  86. 42 0
      Source/Urho3D/Graphics/VertexBuffer.h
  87. 0 31
      Source/Urho3D/Graphics/VertexDeclaration.h
  88. 94 79
      Source/Urho3D/Graphics/View.cpp
  89. 1 1
      Source/Urho3D/Input/Input.cpp
  90. 5 9
      Source/Urho3D/UI/UI.cpp
  91. 12 9
      cmake/Modules/FindDirectX.cmake
  92. 1 1
      cmake/Modules/FindUrho3D.cmake
  93. 19 13
      cmake/Modules/UrhoCommon.cmake
  94. 1 0
      rakefile

+ 6 - 2
Docs/GettingStarted.dox

@@ -147,8 +147,9 @@ A number of build options can be defined when invoking the build scripts or when
 |URHO3D_THREADING     |*|Enable thread support, on Web platform default to 0, on other platforms default to 1|
 |URHO3D_TESTING       |0|Enable testing support|
 |URHO3D_TEST_TIMEOUT  |*|Number of seconds to test run the executables (when testing support is enabled only), default to 10 on Web platform and 5 on other platforms|
-|URHO3D_OPENGL        |0|Use OpenGL instead of Direct3D (Windows platform only)|
-|URHO3D_D3D11         |0|Use Direct3D11 instead of Direct3D9 (Windows platform only); overrides URHO3D_OPENGL option|
+|URHO3D_OPENGL        |1|Enable OpenGL support (Windows platform only)|
+|URHO3D_D3D9          |1|Enable Direct3D 9 support (Windows platform only)|
+|URHO3D_D3D11         |1|Enable Direct3D 11 support (Windows platform only)|
 |URHO3D_STATIC_RUNTIME|0|Use static C/C++ runtime libraries and eliminate the need for runtime DLLs installation (VS only)|
 |URHO3D_WIN32_CONSOLE |0|Use console main() instead of WinMain() as entry point when setting up Windows executable targets (Windows platform only)|
 |URHO3D_MACOSX_BUNDLE |0|Use MACOSX_BUNDLE when setting up macOS executable targets (macOS platform only)|
@@ -419,7 +420,10 @@ The engine can be configured using the following command line options.
 -tq <level>  Texture quality level, default 2 (high)
 -tf <level>  Texture filter mode, default 2 (trilinear)
 -af <level>  Texture anisotropy level, default 4. Also sets anisotropic filter mode
+-opengl      Use OpenGL API
 -gl2         Force OpenGL 2 use even if OpenGL 3 is available
+-d3d9        Use Direct3D 9 API
+-d3d11       Use Direct3D 11 API
 -flushgpu    Flush GPU command queue each frame. Effective only on Direct3D
 -borderless  Borderless window mode
 -lowdpi      Force low DPI mode on Retina display

+ 4 - 1
Source/CMakeLists.txt

@@ -134,9 +134,12 @@ endif ()
 if (NOT ANDROID AND NOT ARM AND NOT WEB)
     if (URHO3D_OPENGL)
         add_subdirectory (ThirdParty/GLEW)
-    elseif (NOT URHO3D_D3D11)
+    endif()
+    
+    if (URHO3D_D3D9)
         add_subdirectory (ThirdParty/MojoShader)
     endif ()
+    
     if (NOT CMAKE_SYSTEM_NAME STREQUAL Linux)
         add_subdirectory (ThirdParty/LibCpuId)
     endif ()

+ 4 - 5
Source/ThirdParty/SDL/CMakeLists.txt

@@ -339,13 +339,12 @@ else ()
   set (DIRECTX OFF)  # Make it off explicitly when not targeting Windows platform, just in case user passes it in accidentally via CLI
 endif ()
 dep_option(WASAPI              "Use the Windows WASAPI audio driver" ON WINDOWS OFF)
-# Urho3D - commented out RENDER_D3D as an option to avoid potential conflict with our URHO3D_OPENGL and URHO3D_D3D11 build options on Windows platform
-#          Instead just initialize the variable according to our build options; Urho3D also by default disables the SDL renderer subsystem
+# Urho3D
 if (WINDOWS)
-  if (URHO3D_OPENGL)
-    set (RENDER_D3D FALSE)
-  else ()
+  if (URHO3D_D3D9 OR URHO3D_D3D11)
     set (RENDER_D3D TRUE)
+  else ()
+    set (RENDER_D3D FALSE)
   endif ()
 endif ()
 dep_option(VIDEO_VIVANTE       "Use Vivante EGL video driver" ON UNIX_SYS OFF)

+ 5 - 5
Source/Urho3D/AngelScript/Generated_Classes.cpp

@@ -4333,18 +4333,18 @@ static void Register_Geometry(asIScriptEngine* engine)
     #endif
 }
 
-// explicit Graphics::Graphics(Context* context)
-static Graphics* Graphics__Graphics_Contextstar()
+// explicit Graphics::Graphics(Context* context, GAPI gapi)
+static Graphics* Graphics__Graphics_Contextstar_GAPI(GAPI gapi)
 {
     Context* context = GetScriptContext();
-    return new Graphics(context);
+    return new Graphics(context, gapi);
 }
 
 // class Graphics | File: ../Graphics/Graphics.h
 static void Register_Graphics(asIScriptEngine* engine)
 {
-    // explicit Graphics::Graphics(Context* context)
-    engine->RegisterObjectBehaviour("Graphics", asBEHAVE_FACTORY, "Graphics@+ f()", AS_FUNCTION(Graphics__Graphics_Contextstar) , AS_CALL_CDECL);
+    // explicit Graphics::Graphics(Context* context, GAPI gapi)
+    engine->RegisterObjectBehaviour("Graphics", asBEHAVE_FACTORY, "Graphics@+ f(GAPI)", AS_FUNCTION(Graphics__Graphics_Contextstar_GAPI) , AS_CALL_CDECL);
 
     RegisterSubclass<Object, Graphics>(engine, "Object", "Graphics");
     RegisterSubclass<RefCounted, Graphics>(engine, "RefCounted", "Graphics");

+ 7 - 0
Source/Urho3D/AngelScript/Generated_Enums.cpp

@@ -923,6 +923,13 @@ void ASRegisterGeneratedEnums(asIScriptEngine* engine)
     engine->RegisterEnumValue("FrustumPlane", "PLANE_DOWN", PLANE_DOWN);
     engine->RegisterEnumValue("FrustumPlane", "PLANE_FAR", PLANE_FAR);
 
+    // enum GAPI | File: ../Graphics/GraphicsDefs.h
+    engine->RegisterEnum("GAPI");
+    engine->RegisterEnumValue("GAPI", "GAPI_NONE", GAPI_NONE);
+    engine->RegisterEnumValue("GAPI", "GAPI_OPENGL", GAPI_OPENGL);
+    engine->RegisterEnumValue("GAPI", "GAPI_D3D9", GAPI_D3D9);
+    engine->RegisterEnumValue("GAPI", "GAPI_D3D11", GAPI_D3D11);
+
     // enum GeometryType | File: ../Graphics/GraphicsDefs.h
     engine->RegisterEnum("GeometryType");
     engine->RegisterEnumValue("GeometryType", "GEOM_STATIC", GEOM_STATIC);

+ 9 - 0
Source/Urho3D/AngelScript/Generated_GlobalVariables.cpp

@@ -109,6 +109,12 @@ void ASRegisterGeneratedGlobalVariables(asIScriptEngine* engine)
     // static const String EP_BORDERLESS | File: ../Engine/EngineDefs.h
     engine->RegisterGlobalProperty("const String EP_BORDERLESS", (void*)&EP_BORDERLESS);
 
+    // static const String EP_DIRECT3D11 | File: ../Engine/EngineDefs.h
+    engine->RegisterGlobalProperty("const String EP_DIRECT3D11", (void*)&EP_DIRECT3D11);
+
+    // static const String EP_DIRECT3D9 | File: ../Engine/EngineDefs.h
+    engine->RegisterGlobalProperty("const String EP_DIRECT3D9", (void*)&EP_DIRECT3D9);
+
     // static const String EP_DUMP_SHADERS | File: ../Engine/EngineDefs.h
     engine->RegisterGlobalProperty("const String EP_DUMP_SHADERS", (void*)&EP_DUMP_SHADERS);
 
@@ -157,6 +163,9 @@ void ASRegisterGeneratedGlobalVariables(asIScriptEngine* engine)
     // static const String EP_MULTI_SAMPLE | File: ../Engine/EngineDefs.h
     engine->RegisterGlobalProperty("const String EP_MULTI_SAMPLE", (void*)&EP_MULTI_SAMPLE);
 
+    // static const String EP_OPENGL | File: ../Engine/EngineDefs.h
+    engine->RegisterGlobalProperty("const String EP_OPENGL", (void*)&EP_OPENGL);
+
     // static const String EP_ORIENTATIONS | File: ../Engine/EngineDefs.h
     engine->RegisterGlobalProperty("const String EP_ORIENTATIONS", (void*)&EP_ORIENTATIONS);
 

+ 6 - 33
Source/Urho3D/AngelScript/Generated_Members.h

@@ -8561,7 +8561,9 @@ template <class T> void RegisterMembers_ShaderVariation(asIScriptEngine* engine,
     // void ShaderVariation::SetName(const String& name)
     engine->RegisterObjectMethod(className, "void SetName(const String&in)", AS_METHODPR(T, SetName, (const String&), void), AS_CALL_THISCALL);
 
-    // static const char* ShaderVariation::elementSemanticNames[]
+    // static const char* ShaderVariation::elementSemanticNames_OGL[]
+    // Error: type "const char*" can not automatically bind
+    // static const char* ShaderVariation::elementSemanticNames_D3D11[]
     // Error: type "const char*" can not automatically bind
 
     #ifdef REGISTER_MEMBERS_MANUAL_PART_ShaderVariation
@@ -9891,44 +9893,26 @@ template <class T> void RegisterMembers_Graphics(asIScriptEngine* engine, const
 
     // void Graphics::AddGPUObject(GPUObject* object)
     // Error: type "GPUObject*" can not automatically bind
-    // void Graphics::CleanupRenderSurface(RenderSurface* surface)
-    // Not registered because have @nobind mark
     // void Graphics::FreeScratchBuffer(void* buffer)
     // Error: type "void*" can not automatically bind
     // void* Graphics::GetExternalWindow() const
     // Error: type "void*" can not automatically bind
-    // GraphicsImpl* Graphics::GetImpl() const
-    // Error: type "GraphicsImpl*" can not automatically bind
     // ConstantBuffer* Graphics::GetOrCreateConstantBuffer(ShaderType type, unsigned index, unsigned size)
     // Not registered because have @nobind mark
     // ShaderVariation* Graphics::GetShader(ShaderType type, const char* name, const char* defines) const
     // Error: type "const char*" can not automatically bind
-    // ShaderProgram* Graphics::GetShaderProgram() const
-    // Not registered because have @nobind mark
     // SDL_Window* Graphics::GetWindow() const
     // Error: type "SDL_Window*" can not automatically bind
-    // void Graphics::MarkFBODirty()
-    // Not registered because have @nobind mark
     // bool Graphics::NeedParameterUpdate(ShaderParameterGroup group, const void* source)
     // Error: type "const void*" can not automatically bind
     // void Graphics::RemoveGPUObject(GPUObject* object)
     // Error: type "GPUObject*" can not automatically bind
     // void* Graphics::ReserveScratchBuffer(unsigned size)
     // Error: type "void*" can not automatically bind
-    // void Graphics::Restore()
-    // Not registered because have @nobind mark
     // void Graphics::SetExternalWindow(void* window)
     // Error: type "void*" can not automatically bind
     // void Graphics::SetShaderParameter(StringHash param, const float* data, unsigned count)
     // Error: type "const float*" can not automatically bind
-    // void Graphics::SetTextureForUpdate(Texture* texture)
-    // Not registered because have @nobind mark
-    // void Graphics::SetTextureParametersDirty()
-    // Not registered because have @nobind mark
-    // void Graphics::SetUBO(unsigned object)
-    // Not registered because have @nobind mark
-    // void Graphics::SetVBO(unsigned object)
-    // Not registered because have @nobind mark
     // bool Graphics::SetVertexBuffers(const PODVector<VertexBuffer*>& buffers, unsigned instanceOffset = 0)
     // Not registered because have @nobind mark
 
@@ -9941,9 +9925,6 @@ template <class T> void RegisterMembers_Graphics(asIScriptEngine* engine, const
     // void Graphics::CleanupScratchBuffers()
     engine->RegisterObjectMethod(className, "void CleanupScratchBuffers()", AS_METHODPR(T, CleanupScratchBuffers, (), void), AS_CALL_THISCALL);
 
-    // void Graphics::CleanupShaderPrograms(ShaderVariation* variation)
-    engine->RegisterObjectMethod(className, "void CleanupShaderPrograms(ShaderVariation@+)", AS_METHODPR(T, CleanupShaderPrograms, (ShaderVariation*), void), AS_CALL_THISCALL);
-
     // void Graphics::Clear(ClearTargetFlags flags, const Color& color = Color(0.0f, 0.0f, 0.0f, 0.0f), float depth = 1.0f, unsigned stencil = 0)
     engine->RegisterObjectMethod(className, "void Clear(ClearTargetFlags, const Color&in = Color(0.0f, 0.0f, 0.0f, 0.0f), float = 1.0f, uint = 0)", AS_METHODPR(T, Clear, (ClearTargetFlags, const Color&, float, unsigned), void), AS_CALL_THISCALL);
 
@@ -10467,6 +10448,9 @@ template <class T> void RegisterMembers_Graphics(asIScriptEngine* engine, const
     // bool Graphics::ToggleFullscreen()
     engine->RegisterObjectMethod(className, "bool ToggleFullscreen()", AS_METHODPR(T, ToggleFullscreen, (), bool), AS_CALL_THISCALL);
 
+    // static GAPI Graphics::GetGAPI()
+    engine->SetDefaultNamespace(className);engine->RegisterGlobalFunction("GAPI GetGAPI()", AS_FUNCTIONPR(T::GetGAPI, (), GAPI), AS_CALL_CDECL);engine->SetDefaultNamespace("");
+
     // static unsigned Graphics::GetAlphaFormat()
     engine->SetDefaultNamespace(className);engine->RegisterGlobalFunction("uint GetAlphaFormat()", AS_FUNCTIONPR(T::GetAlphaFormat, (), unsigned), AS_CALL_CDECL);engine->SetDefaultNamespace("");
 
@@ -15992,8 +15976,6 @@ template <class T> void RegisterMembers_Texture(asIScriptEngine* engine, const c
     // Error: type "void*" can not automatically bind
     // void* Texture::GetShaderResourceView() const
     // Error: type "void*" can not automatically bind
-    // unsigned Texture::GetSRGBFormat(unsigned format)
-    // Not registered because have @nobind mark
 
     // TextureAddressMode Texture::GetAddressMode(TextureCoordinate coord) const
     engine->RegisterObjectMethod(className, "TextureAddressMode GetAddressMode(TextureCoordinate) const", AS_METHODPR(T, GetAddressMode, (TextureCoordinate) const, TextureAddressMode), AS_CALL_THISCALL);
@@ -16154,15 +16136,6 @@ template <class T> void RegisterMembers_Texture(asIScriptEngine* engine, const c
     // void Texture::UpdateParameters()
     engine->RegisterObjectMethod(className, "void UpdateParameters()", AS_METHODPR(T, UpdateParameters, (), void), AS_CALL_THISCALL);
 
-    // static unsigned Texture::GetSRVFormat(unsigned format)
-    // Not registered because have @nobind mark
-    // static unsigned Texture::GetDSVFormat(unsigned format)
-    // Not registered because have @nobind mark
-    // static unsigned Texture::GetExternalFormat(unsigned format)
-    // Not registered because have @nobind mark
-    // static unsigned Texture::GetDataType(unsigned format)
-    // Not registered because have @nobind mark
-
     // static unsigned Texture::CheckMaxLevels(int width, int height, unsigned requestedLevels)
     engine->SetDefaultNamespace(className);engine->RegisterGlobalFunction("uint CheckMaxLevels(int, int, uint)", AS_FUNCTIONPR(T::CheckMaxLevels, (int, int, unsigned), unsigned), AS_CALL_CDECL);engine->SetDefaultNamespace("");
 

+ 12 - 10
Source/Urho3D/CMakeLists.txt

@@ -152,17 +152,19 @@ if (URHO3D_DATABASE)
 else ()
     list (APPEND EXCLUDED_SOURCE_DIRS Database)
 endif ()
-if (URHO3D_OPENGL)
-    # Exclude the opposite source directory
-    list (APPEND EXCLUDED_SOURCE_DIRS Graphics/Direct3D9 Graphics/Direct3D11)
-else ()
+
+if (NOT URHO3D_OPENGL)
     list (APPEND EXCLUDED_SOURCE_DIRS Graphics/OpenGL)
-    if (URHO3D_D3D11)
-        list (APPEND EXCLUDED_SOURCE_DIRS Graphics/Direct3D9)
-    else ()
-        list (APPEND EXCLUDED_SOURCE_DIRS Graphics/Direct3D11)
-    endif ()
 endif ()
+
+if (NOT URHO3D_D3D9)
+    list (APPEND EXCLUDED_SOURCE_DIRS Graphics/Direct3D9)
+endif ()
+
+if (NOT URHO3D_D3D11)
+    list (APPEND EXCLUDED_SOURCE_DIRS Graphics/Direct3D11)
+endif ()
+
 if (APPLE AND NOT ARM)
     set (GLOB_OBJC_PATTERN *.m)     # Should only pick up MacFileWatcher.m for macOS platform at the moment
 endif ()
@@ -377,7 +379,7 @@ if (URHO3D_CLANG_TOOLS)
     set (ANNOTATE_NONSCRIPTABLE "__attribute__((annotate(\"nonscriptable\")))")
 endif ()
 set (APPENDIX "${APPENDIX}\n#define NONSCRIPTABLE ${ANNOTATE_NONSCRIPTABLE}\n\n")
-foreach (DEFINE URHO3D_STATIC_DEFINE URHO3D_OPENGL URHO3D_D3D11 URHO3D_SSE URHO3D_DATABASE_ODBC URHO3D_DATABASE_SQLITE URHO3D_LUAJIT URHO3D_TESTING CLANG_PRE_STANDARD)
+foreach (DEFINE URHO3D_STATIC_DEFINE URHO3D_OPENGL URHO3D_D3D9 URHO3D_D3D11 URHO3D_SSE URHO3D_DATABASE_ODBC URHO3D_DATABASE_SQLITE URHO3D_LUAJIT URHO3D_TESTING CLANG_PRE_STANDARD)
     if (${DEFINE})
         set (APPENDIX "${APPENDIX}#define ${DEFINE}\n")
     endif ()

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

@@ -180,7 +180,49 @@ bool Engine::Initialize(const VariantMap& parameters)
     // Register the rest of the subsystems
     if (!headless_)
     {
-        context_->RegisterSubsystem(new Graphics(context_));
+        GAPI gapi = GAPI_NONE;
+
+        // Try to set any possible graphics API as default
+
+#ifdef URHO3D_OPENGL
+        gapi = GAPI_OPENGL;
+#endif
+
+#ifdef URHO3D_D3D9
+        gapi = GAPI_D3D9;
+#endif
+
+#ifdef URHO3D_D3D11
+        gapi = GAPI_D3D11;
+#endif
+
+        // Use command line parameters
+
+#ifdef URHO3D_OPENGL
+        bool gapi_gl = GetParameter(parameters, EP_OPENGL, false).GetBool();
+        if (gapi_gl)
+            gapi = GAPI_OPENGL;
+#endif
+
+#ifdef URHO3D_D3D9
+        bool gapi_d3d9 = GetParameter(parameters, EP_DIRECT3D9, false).GetBool();
+        if (gapi_d3d9)
+            gapi = GAPI_D3D9;
+#endif
+
+#ifdef URHO3D_D3D11
+        bool gapi_d3d11 = GetParameter(parameters, EP_DIRECT3D11, false).GetBool();
+        if (gapi_d3d11)
+            gapi = GAPI_D3D11;
+#endif
+
+        if (gapi == GAPI_NONE)
+        {
+            URHO3D_LOGERROR("Graphics API not selected");
+            return false;
+        }
+
+        context_->RegisterSubsystem(new Graphics(context_, gapi));
         context_->RegisterSubsystem(new Renderer(context_));
     }
     else
@@ -247,10 +289,11 @@ bool Engine::Initialize(const VariantMap& parameters)
             graphics->SetWindowPosition(GetParameter(parameters, EP_WINDOW_POSITION_X).GetInt(),
                 GetParameter(parameters, EP_WINDOW_POSITION_Y).GetInt());
 
-#ifdef URHO3D_OPENGL
-        if (HasParameter(parameters, EP_FORCE_GL2))
-            graphics->SetForceGL2(GetParameter(parameters, EP_FORCE_GL2).GetBool());
-#endif
+        if (Graphics::GetGAPI() == GAPI_OPENGL)
+        {
+            if (HasParameter(parameters, EP_FORCE_GL2))
+                graphics->SetForceGL2(GetParameter(parameters, EP_FORCE_GL2).GetBool());
+        }
 
         if (!graphics->SetMode(
             GetParameter(parameters, EP_WINDOW_WIDTH, 0).GetInt(),
@@ -825,6 +868,12 @@ VariantMap Engine::ParseParameters(const Vector<String>& arguments)
                 ret[EP_FRAME_LIMITER] = false;
             else if (argument == "flushgpu")
                 ret[EP_FLUSH_GPU] = true;
+            else if (argument == "opengl")
+                ret[EP_OPENGL] = true;
+            else if (argument == "d3d9")
+                ret[EP_DIRECT3D9] = true;
+            else if (argument == "d3d11")
+                ret[EP_DIRECT3D11] = true;
             else if (argument == "gl2")
                 ret[EP_FORCE_GL2] = true;
             else if (argument == "landscape")

+ 3 - 0
Source/Urho3D/Engine/EngineDefs.h

@@ -32,6 +32,9 @@ static const String EP_DUMP_SHADERS = "DumpShaders";
 static const String EP_EVENT_PROFILER = "EventProfiler";
 static const String EP_EXTERNAL_WINDOW = "ExternalWindow";
 static const String EP_FLUSH_GPU = "FlushGPU";
+static const String EP_OPENGL = "OpenGL";
+static const String EP_DIRECT3D9 = "Direct3D9";
+static const String EP_DIRECT3D11 = "Direct3D11";
 static const String EP_FORCE_GL2 = "ForceGL2";
 static const String EP_FRAME_LIMITER = "FrameLimiter";
 static const String EP_FULL_SCREEN = "FullScreen";

+ 45 - 35
Source/Urho3D/Graphics/Batch.cpp

@@ -113,13 +113,16 @@ void CalculateShadowMatrix(Matrix4& dest, LightBatchQueue* queue, unsigned split
     offset.x_ += scale.x_ + pixelUVOffset.x_ / width;
     offset.y_ += scale.y_ + pixelUVOffset.y_ / height;
 
-#ifdef URHO3D_OPENGL
-    offset.z_ = 0.5f;
-    scale.z_ = 0.5f;
-    offset.y_ = 1.0f - offset.y_;
-#else
-    scale.y_ = -scale.y_;
-#endif
+    if (Graphics::GetGAPI() == GAPI_OPENGL)
+    {
+        offset.z_ = 0.5f;
+        scale.z_ = 0.5f;
+        offset.y_ = 1.0f - offset.y_;
+    }
+    else
+    {
+        scale.y_ = -scale.y_;
+    }
 
     // If using 4 shadow samples, offset the position diagonally by half pixel
     if (renderer->GetShadowQuality() == SHADOWQUALITY_PCF_16BIT || renderer->GetShadowQuality() == SHADOWQUALITY_PCF_24BIT)
@@ -148,13 +151,16 @@ void CalculateSpotMatrix(Matrix4& dest, Light* light)
     spotProj.m22_ = 1.0f / Max(light->GetRange(), M_EPSILON);
     spotProj.m32_ = 1.0f;
 
-#ifdef URHO3D_OPENGL
-    texAdjust.SetTranslation(Vector3(0.5f, 0.5f, 0.5f));
-    texAdjust.SetScale(Vector3(0.5f, -0.5f, 0.5f));
-#else
-    texAdjust.SetTranslation(Vector3(0.5f, 0.5f, 0.0f));
-    texAdjust.SetScale(Vector3(0.5f, -0.5f, 1.0f));
-#endif
+    if (Graphics::GetGAPI() == GAPI_OPENGL)
+    {
+        texAdjust.SetTranslation(Vector3(0.5f, 0.5f, 0.5f));
+        texAdjust.SetScale(Vector3(0.5f, -0.5f, 0.5f));
+    }
+    else
+    {
+        texAdjust.SetTranslation(Vector3(0.5f, 0.5f, 0.0f));
+        texAdjust.SetScale(Vector3(0.5f, -0.5f, 1.0f));
+    }
 
     dest = texAdjust * spotProj * spotView;
 }
@@ -352,11 +358,10 @@ void Batch::Prepare(View* view, Camera* camera, bool setModelTransform, bool all
                         Matrix4 lightVecRot(lightNode->GetWorldRotation().RotationMatrix());
                         // HLSL compiler will pack the parameters as if the matrix is only 3x4, so must be careful to not overwrite
                         // the next parameter
-#ifdef URHO3D_OPENGL
-                        graphics->SetShaderParameter(VSP_LIGHTMATRICES, lightVecRot.Data(), 16);
-#else
-                        graphics->SetShaderParameter(VSP_LIGHTMATRICES, lightVecRot.Data(), 12);
-#endif
+                        if (Graphics::GetGAPI() == GAPI_OPENGL)
+                            graphics->SetShaderParameter(VSP_LIGHTMATRICES, lightVecRot.Data(), 16);
+                        else
+                            graphics->SetShaderParameter(VSP_LIGHTMATRICES, lightVecRot.Data(), 12);
                     }
                     break;
                 }
@@ -412,11 +417,10 @@ void Batch::Prepare(View* view, Camera* camera, bool setModelTransform, bool all
                         Matrix4 lightVecRot(lightNode->GetWorldRotation().RotationMatrix());
                         // HLSL compiler will pack the parameters as if the matrix is only 3x4, so must be careful to not overwrite
                         // the next parameter
-#ifdef URHO3D_OPENGL
-                        graphics->SetShaderParameter(PSP_LIGHTMATRICES, lightVecRot.Data(), 16);
-#else
-                        graphics->SetShaderParameter(PSP_LIGHTMATRICES, lightVecRot.Data(), 12);
-#endif
+                        if (Graphics::GetGAPI() == GAPI_OPENGL)
+                            graphics->SetShaderParameter(PSP_LIGHTMATRICES, lightVecRot.Data(), 16);
+                        else
+                            graphics->SetShaderParameter(PSP_LIGHTMATRICES, lightVecRot.Data(), 12);
                     }
                     break;
                 }
@@ -431,17 +435,23 @@ void Batch::Prepare(View* view, Camera* camera, bool setModelTransform, bool all
                     auto faceHeight = (unsigned)(shadowMap->GetHeight() / 3);
                     auto width = (float)shadowMap->GetWidth();
                     auto height = (float)shadowMap->GetHeight();
-#ifdef URHO3D_OPENGL
-                    float mulX = (float)(faceWidth - 3) / width;
-                    float mulY = (float)(faceHeight - 3) / height;
-                    float addX = 1.5f / width;
-                    float addY = 1.5f / height;
-#else
-                    float mulX = (float)(faceWidth - 4) / width;
-                    float mulY = (float)(faceHeight - 4) / height;
-                    float addX = 2.5f / width;
-                    float addY = 2.5f / height;
-#endif
+
+                    float mulX, mulY, addX, addY;
+                    if (Graphics::GetGAPI() == GAPI_OPENGL)
+                    {
+                        mulX = (float)(faceWidth - 3) / width;
+                        mulY = (float)(faceHeight - 3) / height;
+                        addX = 1.5f / width;
+                        addY = 1.5f / height;
+                    }
+                    else
+                    {
+                        mulX = (float)(faceWidth - 4) / width;
+                        mulY = (float)(faceHeight - 4) / height;
+                        addX = 2.5f / width;
+                        addY = 2.5f / height;
+                    }
+
                     // If using 4 shadow samples, offset the position diagonally by half pixel
                     if (renderer->GetShadowQuality() == SHADOWQUALITY_PCF_16BIT || renderer->GetShadowQuality() == SHADOWQUALITY_PCF_24BIT)
                     {

+ 15 - 11
Source/Urho3D/Graphics/Camera.cpp

@@ -26,6 +26,7 @@
 #include "../Graphics/Camera.h"
 #include "../Graphics/DebugRenderer.h"
 #include "../Graphics/Drawable.h"
+#include "../Graphics/Graphics.h"
 #include "../Scene/Node.h"
 
 #include "../DebugNew.h"
@@ -447,19 +448,22 @@ Matrix4 Camera::GetProjection() const
 
 Matrix4 Camera::GetGPUProjection() const
 {
-#ifndef URHO3D_OPENGL
-    return GetProjection(); // Already matches API-specific format
-#else
-    // See formulation for depth range conversion at http://www.ogre3d.org/forums/viewtopic.php?f=4&t=13357
-    Matrix4 ret = GetProjection();
+    if (Graphics::GetGAPI() != GAPI_OPENGL)
+    {
+        return GetProjection(); // Already matches API-specific format
+    }
+    else
+    {
+        // See formulation for depth range conversion at http://www.ogre3d.org/forums/viewtopic.php?f=4&t=13357
+        Matrix4 ret = GetProjection();
 
-    ret.m20_ = 2.0f * ret.m20_ - ret.m30_;
-    ret.m21_ = 2.0f * ret.m21_ - ret.m31_;
-    ret.m22_ = 2.0f * ret.m22_ - ret.m32_;
-    ret.m23_ = 2.0f * ret.m23_ - ret.m33_;
+        ret.m20_ = 2.0f * ret.m20_ - ret.m30_;
+        ret.m21_ = 2.0f * ret.m21_ - ret.m31_;
+        ret.m22_ = 2.0f * ret.m22_ - ret.m32_;
+        ret.m23_ = 2.0f * ret.m23_ - ret.m33_;
 
-    return ret;
-#endif
+        return ret;
+    }
 }
 
 void Camera::GetFrustumSize(Vector3& near, Vector3& far) const

+ 80 - 0
Source/Urho3D/Graphics/ConstantBuffer.cpp

@@ -70,4 +70,84 @@ void ConstantBuffer::SetVector3ArrayParameter(unsigned offset, unsigned rows, co
     dirty_ = true;
 }
 
+void ConstantBuffer::Release()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Release_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Release_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Release_D3D11();
+#endif
+}
+
+void ConstantBuffer::OnDeviceReset()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return OnDeviceReset_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return OnDeviceReset_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return OnDeviceReset_D3D11();
+#endif
+}
+
+bool ConstantBuffer::SetSize(unsigned size)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetSize_OGL(size);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetSize_D3D9(size);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetSize_D3D11(size);
+#endif
+}
+
+void ConstantBuffer::Apply()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Apply_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Apply_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Apply_D3D11();
+#endif
+}
+
 }

+ 21 - 0
Source/Urho3D/Graphics/ConstantBuffer.h

@@ -62,6 +62,27 @@ public:
     bool IsDirty() const { return dirty_; }
 
 private:
+#ifdef URHO3D_OPENGL
+    void Release_OGL();
+    void OnDeviceReset_OGL();
+    bool SetSize_OGL(unsigned size);
+    void Apply_OGL();
+#endif // def URHO3D_OPENGL
+
+#ifdef URHO3D_D3D9
+    void Release_D3D9();
+    void OnDeviceReset_D3D9();
+    bool SetSize_D3D9(unsigned size);
+    void Apply_D3D9();
+#endif // def URHO3D_D3D9
+
+#ifdef URHO3D_D3D11
+    void Release_D3D11();
+    void OnDeviceReset_D3D11();
+    bool SetSize_D3D11(unsigned size);
+    void Apply_D3D11();
+#endif // def URHO3D_D3D11
+
     /// Shadow data.
     SharedArrayPtr<unsigned char> shadowData_;
     /// Buffer byte size.

+ 8 - 8
Source/Urho3D/Graphics/Direct3D11/D3D11ConstantBuffer.cpp

@@ -23,21 +23,21 @@
 #include "../../Precompiled.h"
 
 #include "../../Graphics/Graphics.h"
-#include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/ConstantBuffer.h"
 #include "../../IO/Log.h"
+#include "D3D11GraphicsImpl.h"
 
 #include "../../DebugNew.h"
 
 namespace Urho3D
 {
 
-void ConstantBuffer::OnDeviceReset()
+void ConstantBuffer::OnDeviceReset_D3D11()
 {
     // No-op on Direct3D11
 }
 
-void ConstantBuffer::Release()
+void ConstantBuffer::Release_D3D11()
 {
     URHO3D_SAFE_RELEASE(object_.ptr_);
 
@@ -45,9 +45,9 @@ void ConstantBuffer::Release()
     size_ = 0;
 }
 
-bool ConstantBuffer::SetSize(unsigned size)
+bool ConstantBuffer::SetSize_D3D11(unsigned size)
 {
-    Release();
+    Release_D3D11();
 
     if (!size)
     {
@@ -74,7 +74,7 @@ bool ConstantBuffer::SetSize(unsigned size)
         bufferDesc.CPUAccessFlags = 0;
         bufferDesc.Usage = D3D11_USAGE_DEFAULT;
 
-        HRESULT hr = graphics_->GetImpl()->GetDevice()->CreateBuffer(&bufferDesc, 0, (ID3D11Buffer**)&object_.ptr_);
+        HRESULT hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateBuffer(&bufferDesc, 0, (ID3D11Buffer**)&object_.ptr_);
         if (FAILED(hr))
         {
             URHO3D_SAFE_RELEASE(object_.ptr_);
@@ -86,11 +86,11 @@ bool ConstantBuffer::SetSize(unsigned size)
     return true;
 }
 
-void ConstantBuffer::Apply()
+void ConstantBuffer::Apply_D3D11()
 {
     if (dirty_ && object_.ptr_)
     {
-        graphics_->GetImpl()->GetDeviceContext()->UpdateSubresource((ID3D11Buffer*)object_.ptr_, 0, 0, shadowData_.Get(), 0, 0);
+        graphics_->GetImpl_D3D11()->GetDeviceContext()->UpdateSubresource((ID3D11Buffer*)object_.ptr_, 0, 0, shadowData_.Get(), 0, 0);
         dirty_ = false;
     }
 }

File diff suppressed because it is too large
+ 258 - 216
Source/Urho3D/Graphics/Direct3D11/D3D11Graphics.cpp


+ 4 - 4
Source/Urho3D/Graphics/Direct3D11/D3D11GraphicsImpl.cpp

@@ -23,14 +23,14 @@
 #include "../../Precompiled.h"
 
 #include "../../Graphics/Graphics.h"
-#include "../../Graphics/GraphicsImpl.h"
+#include "D3D11GraphicsImpl.h"
 
 #include "../../DebugNew.h"
 
 namespace Urho3D
 {
 
-GraphicsImpl::GraphicsImpl() :
+GraphicsImpl_D3D11::GraphicsImpl_D3D11() :
     device_(nullptr),
     deviceContext_(nullptr),
     swapChain_(nullptr),
@@ -64,7 +64,7 @@ GraphicsImpl::GraphicsImpl() :
     }
 }
 
-bool GraphicsImpl::CheckMultiSampleSupport(DXGI_FORMAT format, unsigned sampleCount) const
+bool GraphicsImpl_D3D11::CheckMultiSampleSupport(DXGI_FORMAT format, unsigned sampleCount) const
 {
     if (sampleCount < 2)
         return true; // Not multisampled
@@ -76,7 +76,7 @@ bool GraphicsImpl::CheckMultiSampleSupport(DXGI_FORMAT format, unsigned sampleCo
         return numLevels > 0;
 }
 
-unsigned GraphicsImpl::GetMultiSampleQuality(DXGI_FORMAT format, unsigned sampleCount) const
+unsigned GraphicsImpl_D3D11::GetMultiSampleQuality(DXGI_FORMAT format, unsigned sampleCount) const
 {
     if (sampleCount < 2)
         return 0; // Not multisampled, should use quality 0

+ 9 - 9
Source/Urho3D/Graphics/Direct3D11/D3D11GraphicsImpl.h

@@ -24,9 +24,9 @@
 
 #include "../../Graphics/ConstantBuffer.h"
 #include "../../Graphics/GraphicsDefs.h"
-#include "../../Graphics/ShaderProgram.h"
-#include "../../Graphics/VertexDeclaration.h"
 #include "../../Math/Color.h"
+#include "D3D11ShaderProgram.h"
+#include "D3D11VertexDeclaration.h"
 
 #include <d3d11.h>
 #include <dxgi.h>
@@ -38,18 +38,18 @@ namespace Urho3D
 
 #define URHO3D_LOGD3DERROR(msg, hr) URHO3D_LOGERRORF("%s (HRESULT %x)", msg, (unsigned)hr)
 
-using ShaderProgramMap = HashMap<Pair<ShaderVariation*, ShaderVariation*>, SharedPtr<ShaderProgram> >;
-using VertexDeclarationMap = HashMap<unsigned long long, SharedPtr<VertexDeclaration> >;
+using ShaderProgramMap_D3D11 = HashMap<Pair<ShaderVariation*, ShaderVariation*>, SharedPtr<ShaderProgram_D3D11> >;
+using VertexDeclarationMap_D3D11 = HashMap<unsigned long long, SharedPtr<VertexDeclaration_D3D11> >;
 using ConstantBufferMap = HashMap<unsigned, SharedPtr<ConstantBuffer> >;
 
 /// %Graphics implementation. Holds API-specific objects.
-class URHO3D_API GraphicsImpl
+class URHO3D_API GraphicsImpl_D3D11
 {
     friend class Graphics;
 
 public:
     /// Construct.
-    GraphicsImpl();
+    GraphicsImpl_D3D11();
 
     /// Return Direct3D device.
     ID3D11Device* GetDevice() const { return device_; }
@@ -134,15 +134,15 @@ private:
     /// Last dirtied vertex buffer.
     unsigned lastDirtyVB_;
     /// Vertex declarations.
-    VertexDeclarationMap vertexDeclarations_;
+    VertexDeclarationMap_D3D11 vertexDeclarations_;
     /// Constant buffer search map.
     ConstantBufferMap allConstantBuffers_;
     /// Currently dirty constant buffers.
     PODVector<ConstantBuffer*> dirtyConstantBuffers_;
     /// Shader programs.
-    ShaderProgramMap shaderPrograms_;
+    ShaderProgramMap_D3D11 shaderPrograms_;
     /// Shader program in use.
-    ShaderProgram* shaderProgram_;
+    ShaderProgram_D3D11* shaderProgram_;
 };
 
 }

+ 26 - 26
Source/Urho3D/Graphics/Direct3D11/D3D11IndexBuffer.cpp

@@ -24,28 +24,28 @@
 
 #include "../../Core/Context.h"
 #include "../../Graphics/Graphics.h"
-#include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/IndexBuffer.h"
 #include "../../IO/Log.h"
+#include "D3D11GraphicsImpl.h"
 
 #include "../../DebugNew.h"
 
 namespace Urho3D
 {
 
-void IndexBuffer::OnDeviceLost()
+void IndexBuffer::OnDeviceLost_D3D11()
 {
     // No-op on Direct3D11
 }
 
-void IndexBuffer::OnDeviceReset()
+void IndexBuffer::OnDeviceReset_D3D11()
 {
     // No-op on Direct3D11
 }
 
-void IndexBuffer::Release()
+void IndexBuffer::Release_D3D11()
 {
-    Unlock();
+    Unlock_D3D11();
 
     if (graphics_ && graphics_->GetIndexBuffer() == this)
         graphics_->SetIndexBuffer(nullptr);
@@ -53,7 +53,7 @@ void IndexBuffer::Release()
     URHO3D_SAFE_RELEASE(object_.ptr_);
 }
 
-bool IndexBuffer::SetData(const void* data)
+bool IndexBuffer::SetData_D3D11(const void* data)
 {
     if (!data)
     {
@@ -74,7 +74,7 @@ bool IndexBuffer::SetData(const void* data)
     {
         if (dynamic_)
         {
-            void* hwData = MapBuffer(0, indexCount_, true);
+            void* hwData = MapBuffer_D3D11(0, indexCount_, true);
             if (hwData)
             {
                 memcpy(hwData, data, indexCount_ * indexSize_);
@@ -93,17 +93,17 @@ bool IndexBuffer::SetData(const void* data)
             destBox.front = 0;
             destBox.back = 1;
 
-            graphics_->GetImpl()->GetDeviceContext()->UpdateSubresource((ID3D11Buffer*)object_.ptr_, 0, &destBox, data, 0, 0);
+            graphics_->GetImpl_D3D11()->GetDeviceContext()->UpdateSubresource((ID3D11Buffer*)object_.ptr_, 0, &destBox, data, 0, 0);
         }
     }
 
     return true;
 }
 
-bool IndexBuffer::SetDataRange(const void* data, unsigned start, unsigned count, bool discard)
+bool IndexBuffer::SetDataRange_D3D11(const void* data, unsigned start, unsigned count, bool discard)
 {
     if (start == 0 && count == indexCount_)
-        return SetData(data);
+        return SetData_D3D11(data);
 
     if (!data)
     {
@@ -133,7 +133,7 @@ bool IndexBuffer::SetDataRange(const void* data, unsigned start, unsigned count,
     {
         if (dynamic_)
         {
-            void* hwData = MapBuffer(start, count, discard);
+            void* hwData = MapBuffer_D3D11(start, count, discard);
             if (hwData)
             {
                 memcpy(hwData, data, count * indexSize_);
@@ -152,14 +152,14 @@ bool IndexBuffer::SetDataRange(const void* data, unsigned start, unsigned count,
             destBox.front = 0;
             destBox.back = 1;
 
-            graphics_->GetImpl()->GetDeviceContext()->UpdateSubresource((ID3D11Buffer*)object_.ptr_, 0, &destBox, data, 0, 0);
+            graphics_->GetImpl_D3D11()->GetDeviceContext()->UpdateSubresource((ID3D11Buffer*)object_.ptr_, 0, &destBox, data, 0, 0);
         }
     }
 
     return true;
 }
 
-void* IndexBuffer::Lock(unsigned start, unsigned count, bool discard)
+void* IndexBuffer::Lock_D3D11(unsigned start, unsigned count, bool discard)
 {
     if (lockState_ != LOCK_NONE)
     {
@@ -187,7 +187,7 @@ void* IndexBuffer::Lock(unsigned start, unsigned count, bool discard)
 
     // Because shadow data must be kept in sync, can only lock hardware buffer if not shadowed
     if (object_.ptr_ && !shadowData_ && dynamic_)
-        return MapBuffer(start, count, discard);
+        return MapBuffer_D3D11(start, count, discard);
     else if (shadowData_)
     {
         lockState_ = LOCK_SHADOW;
@@ -203,7 +203,7 @@ void* IndexBuffer::Lock(unsigned start, unsigned count, bool discard)
         return nullptr;
 }
 
-void IndexBuffer::Unlock()
+void IndexBuffer::Unlock_D3D11()
 {
     switch (lockState_)
     {
@@ -212,12 +212,12 @@ void IndexBuffer::Unlock()
         break;
 
     case LOCK_SHADOW:
-        SetDataRange(shadowData_.Get() + lockStart_ * indexSize_, lockStart_, lockCount_);
+        SetDataRange_D3D11(shadowData_.Get() + lockStart_ * indexSize_, lockStart_, lockCount_);
         lockState_ = LOCK_NONE;
         break;
 
     case LOCK_SCRATCH:
-        SetDataRange(lockScratchData_, lockStart_, lockCount_);
+        SetDataRange_D3D11(lockScratchData_, lockStart_, lockCount_);
         if (graphics_)
             graphics_->FreeScratchBuffer(lockScratchData_);
         lockScratchData_ = nullptr;
@@ -228,9 +228,9 @@ void IndexBuffer::Unlock()
     }
 }
 
-bool IndexBuffer::Create()
+bool IndexBuffer::Create_D3D11()
 {
-    Release();
+    Release_D3D11();
 
     if (!indexCount_)
         return true;
@@ -244,7 +244,7 @@ bool IndexBuffer::Create()
         bufferDesc.Usage = dynamic_ ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT;
         bufferDesc.ByteWidth = (UINT)(indexCount_ * indexSize_);
 
-        HRESULT hr = graphics_->GetImpl()->GetDevice()->CreateBuffer(&bufferDesc, nullptr, (ID3D11Buffer**)&object_.ptr_);
+        HRESULT hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateBuffer(&bufferDesc, nullptr, (ID3D11Buffer**)&object_.ptr_);
         if (FAILED(hr))
         {
             URHO3D_SAFE_RELEASE(object_.ptr_);
@@ -256,15 +256,15 @@ bool IndexBuffer::Create()
     return true;
 }
 
-bool IndexBuffer::UpdateToGPU()
+bool IndexBuffer::UpdateToGPU_D3D11()
 {
     if (object_.ptr_ && shadowData_)
-        return SetData(shadowData_.Get());
+        return SetData_D3D11(shadowData_.Get());
     else
         return false;
 }
 
-void* IndexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
+void* IndexBuffer::MapBuffer_D3D11(unsigned start, unsigned count, bool discard)
 {
     void* hwData = nullptr;
 
@@ -273,7 +273,7 @@ void* IndexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
         D3D11_MAPPED_SUBRESOURCE mappedData;
         mappedData.pData = nullptr;
 
-        HRESULT hr = graphics_->GetImpl()->GetDeviceContext()->Map((ID3D11Buffer*)object_.ptr_, 0, discard ? D3D11_MAP_WRITE_DISCARD :
+        HRESULT hr = graphics_->GetImpl_D3D11()->GetDeviceContext()->Map((ID3D11Buffer*)object_.ptr_, 0, discard ? D3D11_MAP_WRITE_DISCARD :
             D3D11_MAP_WRITE, 0, &mappedData);
         if (FAILED(hr) || !mappedData.pData)
             URHO3D_LOGD3DERROR("Failed to map index buffer", hr);
@@ -287,11 +287,11 @@ void* IndexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
     return hwData;
 }
 
-void IndexBuffer::UnmapBuffer()
+void IndexBuffer::UnmapBuffer_D3D11()
 {
     if (object_.ptr_ && lockState_ == LOCK_HARDWARE)
     {
-        graphics_->GetImpl()->GetDeviceContext()->Unmap((ID3D11Buffer*)object_.ptr_, 0);
+        graphics_->GetImpl_D3D11()->GetDeviceContext()->Unmap((ID3D11Buffer*)object_.ptr_, 0);
         lockState_ = LOCK_NONE;
     }
 }

+ 7 - 7
Source/Urho3D/Graphics/Direct3D11/D3D11RenderSurface.cpp

@@ -34,14 +34,14 @@
 namespace Urho3D
 {
 
-RenderSurface::RenderSurface(Texture* parentTexture) :      // NOLINT(hicpp-member-init)
-    parentTexture_(parentTexture),
-    renderTargetView_(nullptr),
-    readOnlyView_(nullptr)
+void RenderSurface::Constructor_D3D11(Texture* parentTexture)
 {
+    parentTexture_ = parentTexture;
+    renderTargetView_ = nullptr;
+    readOnlyView_ = nullptr;
 }
 
-void RenderSurface::Release()
+void RenderSurface::Release_D3D11()
 {
     Graphics* graphics = parentTexture_->GetGraphics();
     if (graphics && renderTargetView_)
@@ -60,13 +60,13 @@ void RenderSurface::Release()
     URHO3D_SAFE_RELEASE(readOnlyView_);
 }
 
-bool RenderSurface::CreateRenderBuffer(unsigned width, unsigned height, unsigned format, int multiSample)
+bool RenderSurface::CreateRenderBuffer_D3D11(unsigned width, unsigned height, unsigned format, int multiSample)
 {
     // Not used on Direct3D
     return false;
 }
 
-void RenderSurface::OnDeviceLost()
+void RenderSurface::OnDeviceLost_D3D11()
 {
     // No-op on Direct3D
 }

+ 3 - 3
Source/Urho3D/Graphics/Direct3D11/D3D11ShaderProgram.h

@@ -31,11 +31,11 @@ namespace Urho3D
 {
 
 /// Combined information for specific vertex and pixel shaders.
-class URHO3D_API ShaderProgram : public RefCounted
+class URHO3D_API ShaderProgram_D3D11 : public RefCounted
 {
 public:
     /// Construct.
-    ShaderProgram(Graphics* graphics, ShaderVariation* vertexShader, ShaderVariation* pixelShader)
+    ShaderProgram_D3D11(Graphics* graphics, ShaderVariation* vertexShader, ShaderVariation* pixelShader)
     {
         // Create needed constant buffers
         const unsigned* vsBufferSizes = vertexShader->GetConstantBufferSizes();
@@ -73,7 +73,7 @@ public:
     }
 
     /// Destruct.
-    virtual ~ShaderProgram() override
+    virtual ~ShaderProgram_D3D11() override
     {
     }
 

+ 21 - 21
Source/Urho3D/Graphics/Direct3D11/D3D11ShaderVariation.cpp

@@ -23,13 +23,13 @@
 #include "../../Precompiled.h"
 
 #include "../../Graphics/Graphics.h"
-#include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/Shader.h"
 #include "../../Graphics/VertexBuffer.h"
 #include "../../IO/File.h"
 #include "../../IO/FileSystem.h"
 #include "../../IO/Log.h"
 #include "../../Resource/ResourceCache.h"
+#include "D3D11GraphicsImpl.h"
 
 #include <d3dcompiler.h>
 
@@ -38,7 +38,7 @@
 namespace Urho3D
 {
 
-const char* ShaderVariation::elementSemanticNames[] =
+const char* ShaderVariation::elementSemanticNames_D3D11[] =
 {
     "POSITION",
     "NORMAL",
@@ -51,14 +51,14 @@ const char* ShaderVariation::elementSemanticNames[] =
     "OBJECTINDEX"
 };
 
-void ShaderVariation::OnDeviceLost()
+void ShaderVariation::OnDeviceLost_D3D11()
 {
     // No-op on Direct3D11
 }
 
-bool ShaderVariation::Create()
+bool ShaderVariation::Create_D3D11()
 {
-    Release();
+    Release_D3D11();
 
     if (!graphics_)
         return false;
@@ -76,18 +76,18 @@ bool ShaderVariation::Create()
 
     String binaryShaderName = graphics_->GetShaderCacheDir() + name + "_" + StringHash(defines_).ToString() + extension;
 
-    if (!LoadByteCode(binaryShaderName))
+    if (!LoadByteCode_D3D11(binaryShaderName))
     {
         // Compile shader if don't have valid bytecode
-        if (!Compile())
+        if (!Compile_D3D11())
             return false;
         // Save the bytecode after successful compile, but not if the source is from a package
         if (owner_->GetTimeStamp())
-            SaveByteCode(binaryShaderName);
+            SaveByteCode_D3D11(binaryShaderName);
     }
 
     // Then create shader from the bytecode
-    ID3D11Device* device = graphics_->GetImpl()->GetDevice();
+    ID3D11Device* device = graphics_->GetImpl_D3D11()->GetDevice();
     if (type_ == VS)
     {
         if (device && byteCode_.Size())
@@ -120,14 +120,14 @@ bool ShaderVariation::Create()
     return object_.ptr_ != nullptr;
 }
 
-void ShaderVariation::Release()
+void ShaderVariation::Release_D3D11()
 {
     if (object_.ptr_)
     {
         if (!graphics_)
             return;
 
-        graphics_->CleanupShaderPrograms(this);
+        graphics_->CleanupShaderPrograms_D3D11(this);
 
         if (type_ == VS)
         {
@@ -154,7 +154,7 @@ void ShaderVariation::Release()
     elementHash_ = 0;
 }
 
-void ShaderVariation::SetDefines(const String& defines)
+void ShaderVariation::SetDefines_D3D11(const String& defines)
 {
     defines_ = defines;
 
@@ -164,7 +164,7 @@ void ShaderVariation::SetDefines(const String& defines)
         definesClipPlane_ += " CLIPPLANE";
 }
 
-bool ShaderVariation::LoadByteCode(const String& binaryShaderName)
+bool ShaderVariation::LoadByteCode_D3D11(const String& binaryShaderName)
 {
     ResourceCache* cache = owner_->GetSubsystem<ResourceCache>();
     if (!cache->Exists(binaryShaderName))
@@ -222,7 +222,7 @@ bool ShaderVariation::LoadByteCode(const String& binaryShaderName)
         else
             URHO3D_LOGDEBUG("Loaded cached pixel shader " + GetFullName());
 
-        CalculateConstantBufferSizes();
+        CalculateConstantBufferSizes_D3D11();
         return true;
     }
     else
@@ -232,7 +232,7 @@ bool ShaderVariation::LoadByteCode(const String& binaryShaderName)
     }
 }
 
-bool ShaderVariation::Compile()
+bool ShaderVariation::Compile_D3D11()
 {
     const String& sourceCode = owner_->GetSourceCode(type_);
     Vector<String> defines = defines_.Split(' ');
@@ -315,8 +315,8 @@ bool ShaderVariation::Compile()
         unsigned char* bufData = (unsigned char*)shaderCode->GetBufferPointer();
         unsigned bufSize = (unsigned)shaderCode->GetBufferSize();
         // Use the original bytecode to reflect the parameters
-        ParseParameters(bufData, bufSize);
-        CalculateConstantBufferSizes();
+        ParseParameters_D3D11(bufData, bufSize);
+        CalculateConstantBufferSizes_D3D11();
 
         // Then strip everything not necessary to use the shader
         ID3DBlob* strippedCode = nullptr;
@@ -333,7 +333,7 @@ bool ShaderVariation::Compile()
     return !byteCode_.Empty();
 }
 
-void ShaderVariation::ParseParameters(unsigned char* bufData, unsigned bufSize)
+void ShaderVariation::ParseParameters_D3D11(unsigned char* bufData, unsigned bufSize)
 {
     ID3D11ShaderReflection* reflection = nullptr;
     D3D11_SHADER_DESC shaderDesc;
@@ -355,7 +355,7 @@ void ShaderVariation::ParseParameters(unsigned char* bufData, unsigned bufSize)
         {
             D3D11_SIGNATURE_PARAMETER_DESC paramDesc;
             reflection->GetInputParameterDesc((UINT)i, &paramDesc);
-            VertexElementSemantic semantic = (VertexElementSemantic)GetStringListIndex(paramDesc.SemanticName, elementSemanticNames, MAX_VERTEX_ELEMENT_SEMANTICS, true);
+            VertexElementSemantic semantic = (VertexElementSemantic)GetStringListIndex(paramDesc.SemanticName, elementSemanticNames_D3D11, MAX_VERTEX_ELEMENT_SEMANTICS, true);
             if (semantic != MAX_VERTEX_ELEMENT_SEMANTICS)
             {
                 CombineHash(elementHash, semantic);
@@ -403,7 +403,7 @@ void ShaderVariation::ParseParameters(unsigned char* bufData, unsigned bufSize)
     reflection->Release();
 }
 
-void ShaderVariation::SaveByteCode(const String& binaryShaderName)
+void ShaderVariation::SaveByteCode_D3D11(const String& binaryShaderName)
 {
     ResourceCache* cache = owner_->GetSubsystem<ResourceCache>();
     FileSystem* fileSystem = owner_->GetSubsystem<FileSystem>();
@@ -461,7 +461,7 @@ void ShaderVariation::SaveByteCode(const String& binaryShaderName)
         file->Write(&byteCode_[0], byteCode_.Size());
 }
 
-void ShaderVariation::CalculateConstantBufferSizes()
+void ShaderVariation::CalculateConstantBufferSizes_D3D11()
 {
     for (unsigned i = 0; i < MAX_SHADER_PARAMETER_GROUPS; ++i)
         constantBufferSizes_[i] = 0;

+ 12 - 12
Source/Urho3D/Graphics/Direct3D11/D3D11Texture.cpp

@@ -24,12 +24,12 @@
 
 #include "../../Core/Profiler.h"
 #include "../../Graphics/Graphics.h"
-#include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/Material.h"
 #include "../../IO/FileSystem.h"
 #include "../../IO/Log.h"
 #include "../../Resource/ResourceCache.h"
 #include "../../Resource/XMLFile.h"
+#include "D3D11GraphicsImpl.h"
 
 #include "../../DebugNew.h"
 
@@ -58,7 +58,7 @@ static const D3D11_TEXTURE_ADDRESS_MODE d3dAddressMode[] =
     D3D11_TEXTURE_ADDRESS_BORDER
 };
 
-void Texture::SetSRGB(bool enable)
+void Texture::SetSRGB_D3D11(bool enable)
 {
     if (graphics_)
         enable &= graphics_->GetSRGBSupport();
@@ -72,17 +72,17 @@ void Texture::SetSRGB(bool enable)
     }
 }
 
-bool Texture::GetParametersDirty() const
+bool Texture::GetParametersDirty_D3D11() const
 {
     return parametersDirty_ || !sampler_;
 }
 
-bool Texture::IsCompressed() const
+bool Texture::IsCompressed_D3D11() const
 {
     return format_ == DXGI_FORMAT_BC1_UNORM || format_ == DXGI_FORMAT_BC2_UNORM || format_ == DXGI_FORMAT_BC3_UNORM;
 }
 
-unsigned Texture::GetRowDataSize(int width) const
+unsigned Texture::GetRowDataSize_D3D11(int width) const
 {
     switch (format_)
     {
@@ -123,7 +123,7 @@ unsigned Texture::GetRowDataSize(int width) const
     }
 }
 
-void Texture::UpdateParameters()
+void Texture::UpdateParameters_D3D11()
 {
     if ((!parametersDirty_ && sampler_) || !object_.ptr_)
         return;
@@ -146,7 +146,7 @@ void Texture::UpdateParameters()
     samplerDesc.MaxLOD = M_INFINITY;
     memcpy(&samplerDesc.BorderColor, borderColor_.Data(), 4 * sizeof(float));
 
-    HRESULT hr = graphics_->GetImpl()->GetDevice()->CreateSamplerState(&samplerDesc, (ID3D11SamplerState**)&sampler_);
+    HRESULT hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateSamplerState(&samplerDesc, (ID3D11SamplerState**)&sampler_);
     if (FAILED(hr))
     {
         URHO3D_SAFE_RELEASE(sampler_);
@@ -156,7 +156,7 @@ void Texture::UpdateParameters()
     parametersDirty_ = false;
 }
 
-unsigned Texture::GetSRVFormat(unsigned format)
+unsigned Texture::GetSRVFormat_D3D11(unsigned format)
 {
     if (format == DXGI_FORMAT_R24G8_TYPELESS)
         return DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
@@ -168,7 +168,7 @@ unsigned Texture::GetSRVFormat(unsigned format)
         return format;
 }
 
-unsigned Texture::GetDSVFormat(unsigned format)
+unsigned Texture::GetDSVFormat_D3D11(unsigned format)
 {
     if (format == DXGI_FORMAT_R24G8_TYPELESS)
         return DXGI_FORMAT_D24_UNORM_S8_UINT;
@@ -180,7 +180,7 @@ unsigned Texture::GetDSVFormat(unsigned format)
         return format;
 }
 
-unsigned Texture::GetSRGBFormat(unsigned format)
+unsigned Texture::GetSRGBFormat_D3D11(unsigned format)
 {
     if (format == DXGI_FORMAT_R8G8B8A8_UNORM)
         return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
@@ -194,12 +194,12 @@ unsigned Texture::GetSRGBFormat(unsigned format)
         return format;
 }
 
-void Texture::RegenerateLevels()
+void Texture::RegenerateLevels_D3D11()
 {
     if (!shaderResourceView_)
         return;
 
-    graphics_->GetImpl()->GetDeviceContext()->GenerateMips((ID3D11ShaderResourceView*)shaderResourceView_);
+    graphics_->GetImpl_D3D11()->GetDeviceContext()->GenerateMips((ID3D11ShaderResourceView*)shaderResourceView_);
     levelsDirty_ = false;
 }
 

+ 39 - 39
Source/Urho3D/Graphics/Direct3D11/D3D11Texture2D.cpp

@@ -26,30 +26,30 @@
 #include "../../Core/Profiler.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsEvents.h"
-#include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/Renderer.h"
 #include "../../Graphics/Texture2D.h"
 #include "../../IO/FileSystem.h"
 #include "../../IO/Log.h"
 #include "../../Resource/ResourceCache.h"
 #include "../../Resource/XMLFile.h"
+#include "D3D11GraphicsImpl.h"
 
 #include "../../DebugNew.h"
 
 namespace Urho3D
 {
 
-void Texture2D::OnDeviceLost()
+void Texture2D::OnDeviceLost_D3D11()
 {
     // No-op on Direct3D11
 }
 
-void Texture2D::OnDeviceReset()
+void Texture2D::OnDeviceReset_D3D11()
 {
     // No-op on Direct3D11
 }
 
-void Texture2D::Release()
+void Texture2D::Release_D3D11()
 {
     if (graphics_ && object_.ptr_)
     {
@@ -69,7 +69,7 @@ void Texture2D::Release()
     URHO3D_SAFE_RELEASE(sampler_);
 }
 
-bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, const void* data)
+bool Texture2D::SetData_D3D11(unsigned level, int x, int y, int width, int height, const void* data)
 {
     URHO3D_PROFILE(SetTextureData);
 
@@ -100,7 +100,7 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
     }
 
     // If compressed, align the update region on a block
-    if (IsCompressed())
+    if (IsCompressed_D3D11())
     {
         x &= ~3;
         y &= ~3;
@@ -111,13 +111,13 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
     }
 
     unsigned char* src = (unsigned char*)data;
-    unsigned rowSize = GetRowDataSize(width);
-    unsigned rowStart = GetRowDataSize(x);
+    unsigned rowSize = GetRowDataSize_D3D11(width);
+    unsigned rowStart = GetRowDataSize_D3D11(x);
     unsigned subResource = D3D11CalcSubresource(level, 0, levels_);
 
     if (usage_ == TEXTURE_DYNAMIC)
     {
-        if (IsCompressed())
+        if (IsCompressed_D3D11())
         {
             height = (height + 3) >> 2;
             y >>= 2;
@@ -126,7 +126,7 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
         D3D11_MAPPED_SUBRESOURCE mappedData;
         mappedData.pData = nullptr;
 
-        HRESULT hr = graphics_->GetImpl()->GetDeviceContext()->Map((ID3D11Resource*)object_.ptr_, subResource, D3D11_MAP_WRITE_DISCARD, 0,
+        HRESULT hr = graphics_->GetImpl_D3D11()->GetDeviceContext()->Map((ID3D11Resource*)object_.ptr_, subResource, D3D11_MAP_WRITE_DISCARD, 0,
             &mappedData);
         if (FAILED(hr) || !mappedData.pData)
         {
@@ -137,7 +137,7 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
         {
             for (int row = 0; row < height; ++row)
                 memcpy((unsigned char*)mappedData.pData + (row + y) * mappedData.RowPitch + rowStart, src + row * rowSize, rowSize);
-            graphics_->GetImpl()->GetDeviceContext()->Unmap((ID3D11Resource*)object_.ptr_, subResource);
+            graphics_->GetImpl_D3D11()->GetDeviceContext()->Unmap((ID3D11Resource*)object_.ptr_, subResource);
         }
     }
     else
@@ -150,14 +150,14 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
         destBox.front = 0;
         destBox.back = 1;
 
-        graphics_->GetImpl()->GetDeviceContext()->UpdateSubresource((ID3D11Resource*)object_.ptr_, subResource, &destBox, data,
+        graphics_->GetImpl_D3D11()->GetDeviceContext()->UpdateSubresource((ID3D11Resource*)object_.ptr_, subResource, &destBox, data,
             rowSize, 0);
     }
 
     return true;
 }
 
-bool Texture2D::SetData(Image* image, bool useAlpha)
+bool Texture2D::SetData_D3D11(Image* image, bool useAlpha)
 {
     if (!image)
     {
@@ -213,13 +213,13 @@ bool Texture2D::SetData(Image* image, bool useAlpha)
         }
 
         // If image was previously compressed, reset number of requested levels to avoid error if level count is too high for new size
-        if (IsCompressed() && requestedLevels_ > 1)
+        if (IsCompressed_D3D11() && requestedLevels_ > 1)
             requestedLevels_ = 0;
         SetSize(levelWidth, levelHeight, format);
 
         for (unsigned i = 0; i < levels_; ++i)
         {
-            SetData(i, 0, 0, levelWidth, levelHeight, levelData);
+            SetData_D3D11(i, 0, 0, levelWidth, levelHeight, levelData);
             memoryUse += levelWidth * levelHeight * components;
 
             if (i < levels_ - 1)
@@ -261,14 +261,14 @@ bool Texture2D::SetData(Image* image, bool useAlpha)
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
             if (!needDecompress)
             {
-                SetData(i, 0, 0, level.width_, level.height_, level.data_);
+                SetData_D3D11(i, 0, 0, level.width_, level.height_, level.data_);
                 memoryUse += level.rows_ * level.rowSize_;
             }
             else
             {
                 unsigned char* rgbaData = new unsigned char[level.width_ * level.height_ * 4];
                 level.Decompress(rgbaData);
-                SetData(i, 0, 0, level.width_, level.height_, rgbaData);
+                SetData_D3D11(i, 0, 0, level.width_, level.height_, rgbaData);
                 memoryUse += level.width_ * level.height_ * 4;
                 delete[] rgbaData;
             }
@@ -279,7 +279,7 @@ bool Texture2D::SetData(Image* image, bool useAlpha)
     return true;
 }
 
-bool Texture2D::GetData(unsigned level, void* dest) const
+bool Texture2D::GetData_D3D11(unsigned level, void* dest) const
 {
     if (!object_.ptr_)
     {
@@ -324,7 +324,7 @@ bool Texture2D::GetData(unsigned level, void* dest) const
     textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
 
     ID3D11Texture2D* stagingTexture = nullptr;
-    HRESULT hr = graphics_->GetImpl()->GetDevice()->CreateTexture2D(&textureDesc, nullptr, &stagingTexture);
+    HRESULT hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateTexture2D(&textureDesc, nullptr, &stagingTexture);
     if (FAILED(hr))
     {
         URHO3D_LOGD3DERROR("Failed to create staging texture for GetData", hr);
@@ -342,15 +342,15 @@ bool Texture2D::GetData(unsigned level, void* dest) const
     srcBox.bottom = (UINT)levelHeight;
     srcBox.front = 0;
     srcBox.back = 1;
-    graphics_->GetImpl()->GetDeviceContext()->CopySubresourceRegion(stagingTexture, 0, 0, 0, 0, srcResource,
+    graphics_->GetImpl_D3D11()->GetDeviceContext()->CopySubresourceRegion(stagingTexture, 0, 0, 0, 0, srcResource,
         srcSubResource, &srcBox);
 
     D3D11_MAPPED_SUBRESOURCE mappedData;
     mappedData.pData = nullptr;
-    unsigned rowSize = GetRowDataSize(levelWidth);
-    unsigned numRows = (unsigned)(IsCompressed() ? (levelHeight + 3) >> 2 : levelHeight);
+    unsigned rowSize = GetRowDataSize_D3D11(levelWidth);
+    unsigned numRows = (unsigned)(IsCompressed_D3D11() ? (levelHeight + 3) >> 2 : levelHeight);
 
-    hr = graphics_->GetImpl()->GetDeviceContext()->Map((ID3D11Resource*)stagingTexture, 0, D3D11_MAP_READ, 0, &mappedData);
+    hr = graphics_->GetImpl_D3D11()->GetDeviceContext()->Map((ID3D11Resource*)stagingTexture, 0, D3D11_MAP_READ, 0, &mappedData);
     if (FAILED(hr) || !mappedData.pData)
     {
         URHO3D_LOGD3DERROR("Failed to map staging texture for GetData", hr);
@@ -361,15 +361,15 @@ bool Texture2D::GetData(unsigned level, void* dest) const
     {
         for (unsigned row = 0; row < numRows; ++row)
             memcpy((unsigned char*)dest + row * rowSize, (unsigned char*)mappedData.pData + row * mappedData.RowPitch, rowSize);
-        graphics_->GetImpl()->GetDeviceContext()->Unmap((ID3D11Resource*)stagingTexture, 0);
+        graphics_->GetImpl_D3D11()->GetDeviceContext()->Unmap((ID3D11Resource*)stagingTexture, 0);
         URHO3D_SAFE_RELEASE(stagingTexture);
         return true;
     }
 }
 
-bool Texture2D::Create()
+bool Texture2D::Create_D3D11()
 {
-    Release();
+    Release_D3D11();
 
     if (!graphics_ || !width_ || !height_)
         return false;
@@ -378,10 +378,10 @@ bool Texture2D::Create()
 
     D3D11_TEXTURE2D_DESC textureDesc;
     memset(&textureDesc, 0, sizeof textureDesc);
-    textureDesc.Format = (DXGI_FORMAT)(sRGB_ ? GetSRGBFormat(format_) : format_);
+    textureDesc.Format = (DXGI_FORMAT)(sRGB_ ? GetSRGBFormat_D3D11(format_) : format_);
 
     // Disable multisampling if not supported
-    if (multiSample_ > 1 && !graphics_->GetImpl()->CheckMultiSampleSupport(textureDesc.Format, multiSample_))
+    if (multiSample_ > 1 && !graphics_->GetImpl_D3D11()->CheckMultiSampleSupport(textureDesc.Format, multiSample_))
     {
         multiSample_ = 1;
         autoResolve_ = false;
@@ -399,7 +399,7 @@ bool Texture2D::Create()
     textureDesc.MipLevels = (multiSample_ == 1 && usage_ != TEXTURE_DYNAMIC) ? levels_ : 1;
     textureDesc.ArraySize = 1;
     textureDesc.SampleDesc.Count = (UINT)multiSample_;
-    textureDesc.SampleDesc.Quality = graphics_->GetImpl()->GetMultiSampleQuality(textureDesc.Format, multiSample_);
+    textureDesc.SampleDesc.Quality = graphics_->GetImpl_D3D11()->GetMultiSampleQuality(textureDesc.Format, multiSample_);
 
     textureDesc.Usage = usage_ == TEXTURE_DYNAMIC ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT;
     textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
@@ -410,10 +410,10 @@ bool Texture2D::Create()
     textureDesc.CPUAccessFlags = usage_ == TEXTURE_DYNAMIC ? D3D11_CPU_ACCESS_WRITE : 0;
 
     // D3D feature level 10.0 or below does not support readable depth when multisampled
-    if (usage_ == TEXTURE_DEPTHSTENCIL && multiSample_ > 1 && graphics_->GetImpl()->GetDevice()->GetFeatureLevel() < D3D_FEATURE_LEVEL_10_1)
+    if (usage_ == TEXTURE_DEPTHSTENCIL && multiSample_ > 1 && graphics_->GetImpl_D3D11()->GetDevice()->GetFeatureLevel() < D3D_FEATURE_LEVEL_10_1)
         textureDesc.BindFlags &= ~D3D11_BIND_SHADER_RESOURCE;
 
-    HRESULT hr = graphics_->GetImpl()->GetDevice()->CreateTexture2D(&textureDesc, nullptr, (ID3D11Texture2D**)&object_);
+    HRESULT hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateTexture2D(&textureDesc, nullptr, (ID3D11Texture2D**)&object_);
     if (FAILED(hr))
     {
         URHO3D_LOGD3DERROR("Failed to create texture", hr);
@@ -430,7 +430,7 @@ bool Texture2D::Create()
         if (levels_ != 1)
             textureDesc.MiscFlags |= D3D11_RESOURCE_MISC_GENERATE_MIPS;
 
-        HRESULT hr = graphics_->GetImpl()->GetDevice()->CreateTexture2D(&textureDesc, nullptr, (ID3D11Texture2D**)&resolveTexture_);
+        HRESULT hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateTexture2D(&textureDesc, nullptr, (ID3D11Texture2D**)&resolveTexture_);
         if (FAILED(hr))
         {
             URHO3D_LOGD3DERROR("Failed to create resolve texture", hr);
@@ -443,14 +443,14 @@ bool Texture2D::Create()
     {
         D3D11_SHADER_RESOURCE_VIEW_DESC resourceViewDesc;
         memset(&resourceViewDesc, 0, sizeof resourceViewDesc);
-        resourceViewDesc.Format = (DXGI_FORMAT)GetSRVFormat(textureDesc.Format);
+        resourceViewDesc.Format = (DXGI_FORMAT)GetSRVFormat_D3D11(textureDesc.Format);
         resourceViewDesc.ViewDimension = (multiSample_ > 1 && !autoResolve_) ? D3D11_SRV_DIMENSION_TEXTURE2DMS :
             D3D11_SRV_DIMENSION_TEXTURE2D;
         resourceViewDesc.Texture2D.MipLevels = usage_ != TEXTURE_DYNAMIC ? (UINT)levels_ : 1;
 
         // Sample the resolve texture if created, otherwise the original
         ID3D11Resource* viewObject = resolveTexture_ ? (ID3D11Resource*)resolveTexture_ : (ID3D11Resource*)object_.ptr_;
-        hr = graphics_->GetImpl()->GetDevice()->CreateShaderResourceView(viewObject, &resourceViewDesc,
+        hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateShaderResourceView(viewObject, &resourceViewDesc,
             (ID3D11ShaderResourceView**)&shaderResourceView_);
         if (FAILED(hr))
         {
@@ -467,7 +467,7 @@ bool Texture2D::Create()
         renderTargetViewDesc.Format = textureDesc.Format;
         renderTargetViewDesc.ViewDimension = multiSample_ > 1 ? D3D11_RTV_DIMENSION_TEXTURE2DMS : D3D11_RTV_DIMENSION_TEXTURE2D;
 
-        hr = graphics_->GetImpl()->GetDevice()->CreateRenderTargetView((ID3D11Resource*)object_.ptr_, &renderTargetViewDesc,
+        hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateRenderTargetView((ID3D11Resource*)object_.ptr_, &renderTargetViewDesc,
             (ID3D11RenderTargetView**)&renderSurface_->renderTargetView_);
         if (FAILED(hr))
         {
@@ -480,10 +480,10 @@ bool Texture2D::Create()
     {
         D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
         memset(&depthStencilViewDesc, 0, sizeof depthStencilViewDesc);
-        depthStencilViewDesc.Format = (DXGI_FORMAT)GetDSVFormat(textureDesc.Format);
+        depthStencilViewDesc.Format = (DXGI_FORMAT)GetDSVFormat_D3D11(textureDesc.Format);
         depthStencilViewDesc.ViewDimension = multiSample_ > 1 ? D3D11_DSV_DIMENSION_TEXTURE2DMS : D3D11_DSV_DIMENSION_TEXTURE2D;
 
-        hr = graphics_->GetImpl()->GetDevice()->CreateDepthStencilView((ID3D11Resource*)object_.ptr_, &depthStencilViewDesc,
+        hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateDepthStencilView((ID3D11Resource*)object_.ptr_, &depthStencilViewDesc,
             (ID3D11DepthStencilView**)&renderSurface_->renderTargetView_);
         if (FAILED(hr))
         {
@@ -494,10 +494,10 @@ bool Texture2D::Create()
 
         // Create also a read-only version of the view for simultaneous depth testing and sampling in shader
         // Requires feature level 11
-        if (graphics_->GetImpl()->GetDevice()->GetFeatureLevel() >= D3D_FEATURE_LEVEL_11_0)
+        if (graphics_->GetImpl_D3D11()->GetDevice()->GetFeatureLevel() >= D3D_FEATURE_LEVEL_11_0)
         {
             depthStencilViewDesc.Flags = D3D11_DSV_READ_ONLY_DEPTH;
-            hr = graphics_->GetImpl()->GetDevice()->CreateDepthStencilView((ID3D11Resource*)object_.ptr_, &depthStencilViewDesc,
+            hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateDepthStencilView((ID3D11Resource*)object_.ptr_, &depthStencilViewDesc,
                 (ID3D11DepthStencilView**)&renderSurface_->readOnlyView_);
             if (FAILED(hr))
             {

+ 33 - 33
Source/Urho3D/Graphics/Direct3D11/D3D11Texture2DArray.cpp

@@ -26,13 +26,13 @@
 #include "../../Core/Profiler.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsEvents.h"
-#include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/Renderer.h"
 #include "../../Graphics/Texture2DArray.h"
 #include "../../IO/FileSystem.h"
 #include "../../IO/Log.h"
 #include "../../Resource/ResourceCache.h"
 #include "../../Resource/XMLFile.h"
+#include "D3D11GraphicsImpl.h"
 
 #include "../../DebugNew.h"
 
@@ -43,17 +43,17 @@
 namespace Urho3D
 {
 
-void Texture2DArray::OnDeviceLost()
+void Texture2DArray::OnDeviceLost_D3D11()
 {
     // No-op on Direct3D11
 }
 
-void Texture2DArray::OnDeviceReset()
+void Texture2DArray::OnDeviceReset_D3D11()
 {
     // No-op on Direct3D11
 }
 
-void Texture2DArray::Release()
+void Texture2DArray::Release_D3D11()
 {
     if (graphics_)
     {
@@ -74,7 +74,7 @@ void Texture2DArray::Release()
     levelsDirty_ = false;
 }
 
-bool Texture2DArray::SetData(unsigned layer, unsigned level, int x, int y, int width, int height, const void* data)
+bool Texture2DArray::SetData_D3D11(unsigned layer, unsigned level, int x, int y, int width, int height, const void* data)
 {
     URHO3D_PROFILE(SetTextureData);
 
@@ -111,7 +111,7 @@ bool Texture2DArray::SetData(unsigned layer, unsigned level, int x, int y, int w
     }
 
     // If compressed, align the update region on a block
-    if (IsCompressed())
+    if (IsCompressed_D3D11())
     {
         x &= ~3;
         y &= ~3;
@@ -122,13 +122,13 @@ bool Texture2DArray::SetData(unsigned layer, unsigned level, int x, int y, int w
     }
 
     unsigned char* src = (unsigned char*)data;
-    unsigned rowSize = GetRowDataSize(width);
-    unsigned rowStart = GetRowDataSize(x);
+    unsigned rowSize = GetRowDataSize_D3D11(width);
+    unsigned rowStart = GetRowDataSize_D3D11(x);
     unsigned subResource = D3D11CalcSubresource(level, layer, levels_);
 
     if (usage_ == TEXTURE_DYNAMIC)
     {
-        if (IsCompressed())
+        if (IsCompressed_D3D11())
         {
             height = (height + 3) >> 2;
             y >>= 2;
@@ -137,7 +137,7 @@ bool Texture2DArray::SetData(unsigned layer, unsigned level, int x, int y, int w
         D3D11_MAPPED_SUBRESOURCE mappedData;
         mappedData.pData = nullptr;
 
-        HRESULT hr = graphics_->GetImpl()->GetDeviceContext()->Map((ID3D11Resource*)object_.ptr_, subResource, D3D11_MAP_WRITE_DISCARD, 0,
+        HRESULT hr = graphics_->GetImpl_D3D11()->GetDeviceContext()->Map((ID3D11Resource*)object_.ptr_, subResource, D3D11_MAP_WRITE_DISCARD, 0,
             &mappedData);
         if (FAILED(hr) || !mappedData.pData)
         {
@@ -148,7 +148,7 @@ bool Texture2DArray::SetData(unsigned layer, unsigned level, int x, int y, int w
         {
             for (int row = 0; row < height; ++row)
                 memcpy((unsigned char*)mappedData.pData + (row + y) * mappedData.RowPitch + rowStart, src + row * rowSize, rowSize);
-            graphics_->GetImpl()->GetDeviceContext()->Unmap((ID3D11Resource*)object_.ptr_, subResource);
+            graphics_->GetImpl_D3D11()->GetDeviceContext()->Unmap((ID3D11Resource*)object_.ptr_, subResource);
         }
     }
     else
@@ -161,23 +161,23 @@ bool Texture2DArray::SetData(unsigned layer, unsigned level, int x, int y, int w
         destBox.front = 0;
         destBox.back = 1;
 
-        graphics_->GetImpl()->GetDeviceContext()->UpdateSubresource((ID3D11Resource*)object_.ptr_, subResource, &destBox, data,
+        graphics_->GetImpl_D3D11()->GetDeviceContext()->UpdateSubresource((ID3D11Resource*)object_.ptr_, subResource, &destBox, data,
             rowSize, 0);
     }
 
     return true;
 }
 
-bool Texture2DArray::SetData(unsigned layer, Deserializer& source)
+bool Texture2DArray::SetData_D3D11(unsigned layer, Deserializer& source)
 {
     SharedPtr<Image> image(new Image(context_));
     if (!image->Load(source))
         return false;
 
-    return SetData(layer, image);
+    return SetData_D3D11(layer, image);
 }
 
-bool Texture2DArray::SetData(unsigned layer, Image* image, bool useAlpha)
+bool Texture2DArray::SetData_D3D11(unsigned layer, Image* image, bool useAlpha)
 {
     if (!image)
     {
@@ -246,7 +246,7 @@ bool Texture2DArray::SetData(unsigned layer, Image* image, bool useAlpha)
         if (!layer)
         {
             // If image was previously compressed, reset number of requested levels to avoid error if level count is too high for new size
-            if (IsCompressed() && requestedLevels_ > 1)
+            if (IsCompressed_D3D11() && requestedLevels_ > 1)
                 requestedLevels_ = 0;
             // Create the texture array (the number of layers must have been already set)
             SetSize(0, levelWidth, levelHeight, format);
@@ -267,7 +267,7 @@ bool Texture2DArray::SetData(unsigned layer, Image* image, bool useAlpha)
 
         for (unsigned i = 0; i < levels_; ++i)
         {
-            SetData(layer, i, 0, 0, levelWidth, levelHeight, levelData);
+            SetData_D3D11(layer, i, 0, 0, levelWidth, levelHeight, levelData);
             memoryUse += levelWidth * levelHeight * components;
 
             if (i < levels_ - 1)
@@ -326,14 +326,14 @@ bool Texture2DArray::SetData(unsigned layer, Image* image, bool useAlpha)
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
             if (!needDecompress)
             {
-                SetData(layer, i, 0, 0, level.width_, level.height_, level.data_);
+                SetData_D3D11(layer, i, 0, 0, level.width_, level.height_, level.data_);
                 memoryUse += level.rows_ * level.rowSize_;
             }
             else
             {
                 unsigned char* rgbaData = new unsigned char[level.width_ * level.height_ * 4];
                 level.Decompress(rgbaData);
-                SetData(layer, i, 0, 0, level.width_, level.height_, rgbaData);
+                SetData_D3D11(layer, i, 0, 0, level.width_, level.height_, rgbaData);
                 memoryUse += level.width_ * level.height_ * 4;
                 delete[] rgbaData;
             }
@@ -349,7 +349,7 @@ bool Texture2DArray::SetData(unsigned layer, Image* image, bool useAlpha)
     return true;
 }
 
-bool Texture2DArray::GetData(unsigned layer, unsigned level, void* dest) const
+bool Texture2DArray::GetData_D3D11(unsigned layer, unsigned level, void* dest) const
 {
     if (!object_.ptr_)
     {
@@ -391,7 +391,7 @@ bool Texture2DArray::GetData(unsigned layer, unsigned level, void* dest) const
     textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
 
     ID3D11Texture2D* stagingTexture = nullptr;
-    HRESULT hr = graphics_->GetImpl()->GetDevice()->CreateTexture2D(&textureDesc, nullptr, &stagingTexture);
+    HRESULT hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateTexture2D(&textureDesc, nullptr, &stagingTexture);
     if (FAILED(hr))
     {
         URHO3D_LOGD3DERROR("Failed to create staging texture for GetData", hr);
@@ -407,15 +407,15 @@ bool Texture2DArray::GetData(unsigned layer, unsigned level, void* dest) const
     srcBox.bottom = (UINT)levelHeight;
     srcBox.front = 0;
     srcBox.back = 1;
-    graphics_->GetImpl()->GetDeviceContext()->CopySubresourceRegion(stagingTexture, 0, 0, 0, 0, (ID3D11Resource*)object_.ptr_,
+    graphics_->GetImpl_D3D11()->GetDeviceContext()->CopySubresourceRegion(stagingTexture, 0, 0, 0, 0, (ID3D11Resource*)object_.ptr_,
         srcSubResource, &srcBox);
 
     D3D11_MAPPED_SUBRESOURCE mappedData;
     mappedData.pData = nullptr;
-    unsigned rowSize = GetRowDataSize(levelWidth);
-    unsigned numRows = (unsigned)(IsCompressed() ? (levelHeight + 3) >> 2 : levelHeight);
+    unsigned rowSize = GetRowDataSize_D3D11(levelWidth);
+    unsigned numRows = (unsigned)(IsCompressed_D3D11() ? (levelHeight + 3) >> 2 : levelHeight);
 
-    hr = graphics_->GetImpl()->GetDeviceContext()->Map((ID3D11Resource*)stagingTexture, 0, D3D11_MAP_READ, 0, &mappedData);
+    hr = graphics_->GetImpl_D3D11()->GetDeviceContext()->Map((ID3D11Resource*)stagingTexture, 0, D3D11_MAP_READ, 0, &mappedData);
     if (FAILED(hr) || !mappedData.pData)
     {
         URHO3D_LOGD3DERROR("Failed to map staging texture for GetData", hr);
@@ -426,15 +426,15 @@ bool Texture2DArray::GetData(unsigned layer, unsigned level, void* dest) const
     {
         for (unsigned row = 0; row < numRows; ++row)
             memcpy((unsigned char*)dest + row * rowSize, (unsigned char*)mappedData.pData + row * mappedData.RowPitch, rowSize);
-        graphics_->GetImpl()->GetDeviceContext()->Unmap((ID3D11Resource*)stagingTexture, 0);
+        graphics_->GetImpl_D3D11()->GetDeviceContext()->Unmap((ID3D11Resource*)stagingTexture, 0);
         URHO3D_SAFE_RELEASE(stagingTexture);
         return true;
     }
 }
 
-bool Texture2DArray::Create()
+bool Texture2DArray::Create_D3D11()
 {
-    Release();
+    Release_D3D11();
 
     if (!graphics_ || !width_ || !height_ || !layers_)
         return false;
@@ -452,7 +452,7 @@ bool Texture2DArray::Create()
     textureDesc.Height = (UINT)height_;
     textureDesc.MipLevels = usage_ != TEXTURE_DYNAMIC ? levels_ : 1;
     textureDesc.ArraySize = layers_;
-    textureDesc.Format = (DXGI_FORMAT)(sRGB_ ? GetSRGBFormat(format_) : format_);
+    textureDesc.Format = (DXGI_FORMAT)(sRGB_ ? GetSRGBFormat_D3D11(format_) : format_);
     textureDesc.SampleDesc.Count = 1;
     textureDesc.SampleDesc.Quality = 0;
     textureDesc.Usage = usage_ == TEXTURE_DYNAMIC ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT;
@@ -463,7 +463,7 @@ bool Texture2DArray::Create()
         textureDesc.BindFlags |= D3D11_BIND_DEPTH_STENCIL;
     textureDesc.CPUAccessFlags = usage_ == TEXTURE_DYNAMIC ? D3D11_CPU_ACCESS_WRITE : 0;
 
-    HRESULT hr = graphics_->GetImpl()->GetDevice()->CreateTexture2D(&textureDesc, nullptr, (ID3D11Texture2D**)&object_);
+    HRESULT hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateTexture2D(&textureDesc, nullptr, (ID3D11Texture2D**)&object_);
     if (FAILED(hr))
     {
         URHO3D_LOGD3DERROR("Failed to create texture array", hr);
@@ -473,7 +473,7 @@ bool Texture2DArray::Create()
 
     D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
     memset(&srvDesc, 0, sizeof srvDesc);
-    srvDesc.Format = (DXGI_FORMAT)GetSRVFormat(textureDesc.Format);
+    srvDesc.Format = (DXGI_FORMAT)GetSRVFormat_D3D11(textureDesc.Format);
     if (layers_ == 1)
     {
         srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
@@ -489,7 +489,7 @@ bool Texture2DArray::Create()
         srvDesc.Texture2DArray.MostDetailedMip = 0;
     }
 
-    hr = graphics_->GetImpl()->GetDevice()->CreateShaderResourceView((ID3D11Resource*)object_.ptr_, &srvDesc,
+    hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateShaderResourceView((ID3D11Resource*)object_.ptr_, &srvDesc,
         (ID3D11ShaderResourceView**)&shaderResourceView_);
     if (FAILED(hr))
     {
@@ -516,7 +516,7 @@ bool Texture2DArray::Create()
             renderTargetViewDesc.Texture2DArray.FirstArraySlice = 0;
         }
 
-        hr = graphics_->GetImpl()->GetDevice()->CreateRenderTargetView((ID3D11Resource*)object_.ptr_, &renderTargetViewDesc,
+        hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateRenderTargetView((ID3D11Resource*)object_.ptr_, &renderTargetViewDesc,
             (ID3D11RenderTargetView**)&renderSurface_->renderTargetView_);
 
         if (FAILED(hr))

+ 31 - 31
Source/Urho3D/Graphics/Direct3D11/D3D11Texture3D.cpp

@@ -26,30 +26,30 @@
 #include "../../Core/Profiler.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsEvents.h"
-#include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/Renderer.h"
 #include "../../Graphics/Texture3D.h"
 #include "../../IO/FileSystem.h"
 #include "../../IO/Log.h"
 #include "../../Resource/ResourceCache.h"
 #include "../../Resource/XMLFile.h"
+#include "D3D11GraphicsImpl.h"
 
 #include "../../DebugNew.h"
 
 namespace Urho3D
 {
 
-void Texture3D::OnDeviceLost()
+void Texture3D::OnDeviceLost_D3D11()
 {
     // No-op on Direct3D11
 }
 
-void Texture3D::OnDeviceReset()
+void Texture3D::OnDeviceReset_D3D11()
 {
     // No-op on Direct3D11
 }
 
-void Texture3D::Release()
+void Texture3D::Release_D3D11()
 {
     if (graphics_ && object_.ptr_)
     {
@@ -65,7 +65,7 @@ void Texture3D::Release()
     URHO3D_SAFE_RELEASE(sampler_);
 }
 
-bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int height, int depth, const void* data)
+bool Texture3D::SetData_D3D11(unsigned level, int x, int y, int z, int width, int height, int depth, const void* data)
 {
     URHO3D_PROFILE(SetTextureData);
 
@@ -98,7 +98,7 @@ bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int heig
     }
 
     // If compressed, align the update region on a block
-    if (IsCompressed())
+    if (IsCompressed_D3D11())
     {
         x &= ~3;
         y &= ~3;
@@ -109,13 +109,13 @@ bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int heig
     }
 
     unsigned char* src = (unsigned char*)data;
-    unsigned rowSize = GetRowDataSize(width);
-    unsigned rowStart = GetRowDataSize(x);
+    unsigned rowSize = GetRowDataSize_D3D11(width);
+    unsigned rowStart = GetRowDataSize_D3D11(x);
     unsigned subResource = D3D11CalcSubresource(level, 0, levels_);
 
     if (usage_ == TEXTURE_DYNAMIC)
     {
-        if (IsCompressed())
+        if (IsCompressed_D3D11())
         {
             height = (height + 3) >> 2;
             y >>= 2;
@@ -124,7 +124,7 @@ bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int heig
         D3D11_MAPPED_SUBRESOURCE mappedData;
         mappedData.pData = nullptr;
 
-        HRESULT hr = graphics_->GetImpl()->GetDeviceContext()->Map((ID3D11Resource*)object_.ptr_, subResource, D3D11_MAP_WRITE_DISCARD, 0,
+        HRESULT hr = graphics_->GetImpl_D3D11()->GetDeviceContext()->Map((ID3D11Resource*)object_.ptr_, subResource, D3D11_MAP_WRITE_DISCARD, 0,
             &mappedData);
         if (FAILED(hr) || !mappedData.pData)
         {
@@ -142,12 +142,12 @@ bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int heig
                 }
             }
 
-            graphics_->GetImpl()->GetDeviceContext()->Unmap((ID3D11Resource*)object_.ptr_, subResource);
+            graphics_->GetImpl_D3D11()->GetDeviceContext()->Unmap((ID3D11Resource*)object_.ptr_, subResource);
         }
     }
     else
     {
-        if (IsCompressed())
+        if (IsCompressed_D3D11())
             levelHeight = (levelHeight + 3) >> 2;
 
         D3D11_BOX destBox;
@@ -158,14 +158,14 @@ bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int heig
         destBox.front = (UINT)z;
         destBox.back = (UINT)(z + depth);
 
-        graphics_->GetImpl()->GetDeviceContext()->UpdateSubresource((ID3D11Resource*)object_.ptr_, subResource, &destBox, data,
+        graphics_->GetImpl_D3D11()->GetDeviceContext()->UpdateSubresource((ID3D11Resource*)object_.ptr_, subResource, &destBox, data,
             rowSize, levelHeight * rowSize);
     }
 
     return true;
 }
 
-bool Texture3D::SetData(Image* image, bool useAlpha)
+bool Texture3D::SetData_D3D11(Image* image, bool useAlpha)
 {
     if (!image)
     {
@@ -223,13 +223,13 @@ bool Texture3D::SetData(Image* image, bool useAlpha)
         }
 
         // If image was previously compressed, reset number of requested levels to avoid error if level count is too high for new size
-        if (IsCompressed() && requestedLevels_ > 1)
+        if (IsCompressed_D3D11() && requestedLevels_ > 1)
             requestedLevels_ = 0;
         SetSize(levelWidth, levelHeight, levelDepth, format);
 
         for (unsigned i = 0; i < levels_; ++i)
         {
-            SetData(i, 0, 0, 0, levelWidth, levelHeight, levelDepth, levelData);
+            SetData_D3D11(i, 0, 0, 0, levelWidth, levelHeight, levelDepth, levelData);
             memoryUse += levelWidth * levelHeight * levelDepth * components;
 
             if (i < levels_ - 1)
@@ -274,14 +274,14 @@ bool Texture3D::SetData(Image* image, bool useAlpha)
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
             if (!needDecompress)
             {
-                SetData(i, 0, 0, 0, level.width_, level.height_, level.depth_, level.data_);
+                SetData_D3D11(i, 0, 0, 0, level.width_, level.height_, level.depth_, level.data_);
                 memoryUse += level.depth_ * level.rows_ * level.rowSize_;
             }
             else
             {
                 unsigned char* rgbaData = new unsigned char[level.width_ * level.height_ * level.depth_ * 4];
                 level.Decompress(rgbaData);
-                SetData(i, 0, 0, 0, level.width_, level.height_, level.depth_, rgbaData);
+                SetData_D3D11(i, 0, 0, 0, level.width_, level.height_, level.depth_, rgbaData);
                 memoryUse += level.width_ * level.height_ * level.depth_ * 4;
                 delete[] rgbaData;
             }
@@ -292,7 +292,7 @@ bool Texture3D::SetData(Image* image, bool useAlpha)
     return true;
 }
 
-bool Texture3D::GetData(unsigned level, void* dest) const
+bool Texture3D::GetData_D3D11(unsigned level, void* dest) const
 {
     if (!object_.ptr_)
     {
@@ -327,7 +327,7 @@ bool Texture3D::GetData(unsigned level, void* dest) const
     textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
 
     ID3D11Texture3D* stagingTexture = nullptr;
-    HRESULT hr = graphics_->GetImpl()->GetDevice()->CreateTexture3D(&textureDesc, nullptr, &stagingTexture);
+    HRESULT hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateTexture3D(&textureDesc, nullptr, &stagingTexture);
     if (FAILED(hr))
     {
         URHO3D_LOGD3DERROR("Failed to create staging texture for GetData", hr);
@@ -343,15 +343,15 @@ bool Texture3D::GetData(unsigned level, void* dest) const
     srcBox.bottom = (UINT)levelHeight;
     srcBox.front = 0;
     srcBox.back = (UINT)levelDepth;
-    graphics_->GetImpl()->GetDeviceContext()->CopySubresourceRegion(stagingTexture, 0, 0, 0, 0, (ID3D11Resource*)object_.ptr_,
+    graphics_->GetImpl_D3D11()->GetDeviceContext()->CopySubresourceRegion(stagingTexture, 0, 0, 0, 0, (ID3D11Resource*)object_.ptr_,
         srcSubResource, &srcBox);
 
     D3D11_MAPPED_SUBRESOURCE mappedData;
     mappedData.pData = nullptr;
-    unsigned rowSize = GetRowDataSize(levelWidth);
-    unsigned numRows = (unsigned)(IsCompressed() ? (levelHeight + 3) >> 2 : levelHeight);
+    unsigned rowSize = GetRowDataSize_D3D11(levelWidth);
+    unsigned numRows = (unsigned)(IsCompressed_D3D11() ? (levelHeight + 3) >> 2 : levelHeight);
 
-    hr = graphics_->GetImpl()->GetDeviceContext()->Map((ID3D11Resource*)stagingTexture, 0, D3D11_MAP_READ, 0, &mappedData);
+    hr = graphics_->GetImpl_D3D11()->GetDeviceContext()->Map((ID3D11Resource*)stagingTexture, 0, D3D11_MAP_READ, 0, &mappedData);
     if (FAILED(hr) || !mappedData.pData)
     {
         URHO3D_LOGD3DERROR("Failed to map staging texture for GetData", hr);
@@ -368,15 +368,15 @@ bool Texture3D::GetData(unsigned level, void* dest) const
                     (unsigned char*)mappedData.pData + page * mappedData.DepthPitch + row * mappedData.RowPitch, rowSize);
             }
         }
-        graphics_->GetImpl()->GetDeviceContext()->Unmap((ID3D11Resource*)stagingTexture, 0);
+        graphics_->GetImpl_D3D11()->GetDeviceContext()->Unmap((ID3D11Resource*)stagingTexture, 0);
         URHO3D_SAFE_RELEASE(stagingTexture);
         return true;
     }
 }
 
-bool Texture3D::Create()
+bool Texture3D::Create_D3D11()
 {
-    Release();
+    Release_D3D11();
 
     if (!graphics_ || !width_ || !height_ || !depth_)
         return false;
@@ -389,12 +389,12 @@ bool Texture3D::Create()
     textureDesc.Height = (UINT)height_;
     textureDesc.Depth = (UINT)depth_;
     textureDesc.MipLevels = usage_ != TEXTURE_DYNAMIC ? levels_ : 1;
-    textureDesc.Format = (DXGI_FORMAT)(sRGB_ ? GetSRGBFormat(format_) : format_);
+    textureDesc.Format = (DXGI_FORMAT)(sRGB_ ? GetSRGBFormat_D3D11(format_) : format_);
     textureDesc.Usage = usage_ == TEXTURE_DYNAMIC ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT;
     textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
     textureDesc.CPUAccessFlags = usage_ == TEXTURE_DYNAMIC ? D3D11_CPU_ACCESS_WRITE : 0;
 
-    HRESULT hr = graphics_->GetImpl()->GetDevice()->CreateTexture3D(&textureDesc, nullptr, (ID3D11Texture3D**)&object_.ptr_);
+    HRESULT hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateTexture3D(&textureDesc, nullptr, (ID3D11Texture3D**)&object_.ptr_);
     if (FAILED(hr))
     {
         URHO3D_LOGD3DERROR("Failed to create texture", hr);
@@ -404,11 +404,11 @@ bool Texture3D::Create()
 
     D3D11_SHADER_RESOURCE_VIEW_DESC resourceViewDesc;
     memset(&resourceViewDesc, 0, sizeof resourceViewDesc);
-    resourceViewDesc.Format = (DXGI_FORMAT)GetSRVFormat(textureDesc.Format);
+    resourceViewDesc.Format = (DXGI_FORMAT)GetSRVFormat_D3D11(textureDesc.Format);
     resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
     resourceViewDesc.Texture3D.MipLevels = usage_ != TEXTURE_DYNAMIC ? (UINT)levels_ : 1;
 
-    hr = graphics_->GetImpl()->GetDevice()->CreateShaderResourceView((ID3D11Resource*)object_.ptr_, &resourceViewDesc,
+    hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateShaderResourceView((ID3D11Resource*)object_.ptr_, &resourceViewDesc,
         (ID3D11ShaderResourceView**)&shaderResourceView_);
     if (FAILED(hr))
     {

+ 36 - 36
Source/Urho3D/Graphics/Direct3D11/D3D11TextureCube.cpp

@@ -26,13 +26,13 @@
 #include "../../Core/Profiler.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsEvents.h"
-#include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/Renderer.h"
 #include "../../Graphics/TextureCube.h"
 #include "../../IO/FileSystem.h"
 #include "../../IO/Log.h"
 #include "../../Resource/ResourceCache.h"
 #include "../../Resource/XMLFile.h"
+#include "D3D11GraphicsImpl.h"
 
 #include "../../DebugNew.h"
 
@@ -43,17 +43,17 @@
 namespace Urho3D
 {
 
-void TextureCube::OnDeviceLost()
+void TextureCube::OnDeviceLost_D3D11()
 {
     // No-op on Direct3D11
 }
 
-void TextureCube::OnDeviceReset()
+void TextureCube::OnDeviceReset_D3D11()
 {
     // No-op on Direct3D11
 }
 
-void TextureCube::Release()
+void TextureCube::Release_D3D11()
 {
     if (graphics_)
     {
@@ -76,7 +76,7 @@ void TextureCube::Release()
     URHO3D_SAFE_RELEASE(sampler_);
 }
 
-bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int width, int height, const void* data)
+bool TextureCube::SetData_D3D11(CubeMapFace face, unsigned level, int x, int y, int width, int height, const void* data)
 {
     URHO3D_PROFILE(SetTextureData);
 
@@ -107,7 +107,7 @@ bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int wi
     }
 
     // If compressed, align the update region on a block
-    if (IsCompressed())
+    if (IsCompressed_D3D11())
     {
         x &= ~3;
         y &= ~3;
@@ -118,13 +118,13 @@ bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int wi
     }
 
     unsigned char* src = (unsigned char*)data;
-    unsigned rowSize = GetRowDataSize(width);
-    unsigned rowStart = GetRowDataSize(x);
+    unsigned rowSize = GetRowDataSize_D3D11(width);
+    unsigned rowStart = GetRowDataSize_D3D11(x);
     unsigned subResource = D3D11CalcSubresource(level, face, levels_);
 
     if (usage_ == TEXTURE_DYNAMIC)
     {
-        if (IsCompressed())
+        if (IsCompressed_D3D11())
         {
             height = (height + 3) >> 2;
             y >>= 2;
@@ -133,7 +133,7 @@ bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int wi
         D3D11_MAPPED_SUBRESOURCE mappedData;
         mappedData.pData = nullptr;
 
-        HRESULT hr = graphics_->GetImpl()->GetDeviceContext()->Map((ID3D11Resource*)object_.ptr_, subResource, D3D11_MAP_WRITE_DISCARD, 0,
+        HRESULT hr = graphics_->GetImpl_D3D11()->GetDeviceContext()->Map((ID3D11Resource*)object_.ptr_, subResource, D3D11_MAP_WRITE_DISCARD, 0,
             &mappedData);
         if (FAILED(hr) || !mappedData.pData)
         {
@@ -144,7 +144,7 @@ bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int wi
         {
             for (int row = 0; row < height; ++row)
                 memcpy((unsigned char*)mappedData.pData + (row + y) * mappedData.RowPitch + rowStart, src + row * rowSize, rowSize);
-            graphics_->GetImpl()->GetDeviceContext()->Unmap((ID3D11Resource*)object_.ptr_, subResource);
+            graphics_->GetImpl_D3D11()->GetDeviceContext()->Unmap((ID3D11Resource*)object_.ptr_, subResource);
         }
     }
     else
@@ -157,23 +157,23 @@ bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int wi
         destBox.front = 0;
         destBox.back = 1;
 
-        graphics_->GetImpl()->GetDeviceContext()->UpdateSubresource((ID3D11Resource*)object_.ptr_, subResource, &destBox, data,
+        graphics_->GetImpl_D3D11()->GetDeviceContext()->UpdateSubresource((ID3D11Resource*)object_.ptr_, subResource, &destBox, data,
             rowSize, 0);
     }
 
     return true;
 }
 
-bool TextureCube::SetData(CubeMapFace face, Deserializer& source)
+bool TextureCube::SetData_D3D11(CubeMapFace face, Deserializer& source)
 {
     SharedPtr<Image> image(new Image(context_));
     if (!image->Load(source))
         return false;
 
-    return SetData(face, image);
+    return SetData_D3D11(face, image);
 }
 
-bool TextureCube::SetData(CubeMapFace face, Image* image, bool useAlpha)
+bool TextureCube::SetData_D3D11(CubeMapFace face, Image* image, bool useAlpha)
 {
     if (!image)
     {
@@ -238,7 +238,7 @@ bool TextureCube::SetData(CubeMapFace face, Image* image, bool useAlpha)
         if (!face)
         {
             // If image was previously compressed, reset number of requested levels to avoid error if level count is too high for new size
-            if (IsCompressed() && requestedLevels_ > 1)
+            if (IsCompressed_D3D11() && requestedLevels_ > 1)
                 requestedLevels_ = 0;
             SetSize(levelWidth, format);
         }
@@ -258,7 +258,7 @@ bool TextureCube::SetData(CubeMapFace face, Image* image, bool useAlpha)
 
         for (unsigned i = 0; i < levels_; ++i)
         {
-            SetData(face, i, 0, 0, levelWidth, levelHeight, levelData);
+            SetData_D3D11(face, i, 0, 0, levelWidth, levelHeight, levelData);
             memoryUse += levelWidth * levelHeight * components;
 
             if (i < levels_ - 1)
@@ -323,14 +323,14 @@ bool TextureCube::SetData(CubeMapFace face, Image* image, bool useAlpha)
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
             if (!needDecompress)
             {
-                SetData(face, i, 0, 0, level.width_, level.height_, level.data_);
+                SetData_D3D11(face, i, 0, 0, level.width_, level.height_, level.data_);
                 memoryUse += level.rows_ * level.rowSize_;
             }
             else
             {
                 unsigned char* rgbaData = new unsigned char[level.width_ * level.height_ * 4];
                 level.Decompress(rgbaData);
-                SetData(face, i, 0, 0, level.width_, level.height_, rgbaData);
+                SetData_D3D11(face, i, 0, 0, level.width_, level.height_, rgbaData);
                 memoryUse += level.width_ * level.height_ * 4;
                 delete[] rgbaData;
             }
@@ -346,7 +346,7 @@ bool TextureCube::SetData(CubeMapFace face, Image* image, bool useAlpha)
     return true;
 }
 
-bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
+bool TextureCube::GetData_D3D11(CubeMapFace face, unsigned level, void* dest) const
 {
     if (!object_.ptr_)
     {
@@ -391,7 +391,7 @@ bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
     textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
 
     ID3D11Texture2D* stagingTexture = nullptr;
-    HRESULT hr = graphics_->GetImpl()->GetDevice()->CreateTexture2D(&textureDesc, nullptr, &stagingTexture);
+    HRESULT hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateTexture2D(&textureDesc, nullptr, &stagingTexture);
     if (FAILED(hr))
     {
         URHO3D_LOGD3DERROR("Failed to create staging texture for GetData", hr);
@@ -409,15 +409,15 @@ bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
     srcBox.bottom = (UINT)levelHeight;
     srcBox.front = 0;
     srcBox.back = 1;
-    graphics_->GetImpl()->GetDeviceContext()->CopySubresourceRegion(stagingTexture, 0, 0, 0, 0, srcResource,
+    graphics_->GetImpl_D3D11()->GetDeviceContext()->CopySubresourceRegion(stagingTexture, 0, 0, 0, 0, srcResource,
         srcSubResource, &srcBox);
 
     D3D11_MAPPED_SUBRESOURCE mappedData;
     mappedData.pData = nullptr;
-    unsigned rowSize = GetRowDataSize(levelWidth);
-    unsigned numRows = (unsigned)(IsCompressed() ? (levelHeight + 3) >> 2 : levelHeight);
+    unsigned rowSize = GetRowDataSize_D3D11(levelWidth);
+    unsigned numRows = (unsigned)(IsCompressed_D3D11() ? (levelHeight + 3) >> 2 : levelHeight);
 
-    hr = graphics_->GetImpl()->GetDeviceContext()->Map((ID3D11Resource*)stagingTexture, 0, D3D11_MAP_READ, 0, &mappedData);
+    hr = graphics_->GetImpl_D3D11()->GetDeviceContext()->Map((ID3D11Resource*)stagingTexture, 0, D3D11_MAP_READ, 0, &mappedData);
     if (FAILED(hr) || !mappedData.pData)
     {
         URHO3D_LOGD3DERROR("Failed to map staging texture for GetData", hr);
@@ -428,15 +428,15 @@ bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
     {
         for (unsigned row = 0; row < numRows; ++row)
             memcpy((unsigned char*)dest + row * rowSize, (unsigned char*)mappedData.pData + row * mappedData.RowPitch, rowSize);
-        graphics_->GetImpl()->GetDeviceContext()->Unmap((ID3D11Resource*)stagingTexture, 0);
+        graphics_->GetImpl_D3D11()->GetDeviceContext()->Unmap((ID3D11Resource*)stagingTexture, 0);
         URHO3D_SAFE_RELEASE(stagingTexture);
         return true;
     }
 }
 
-bool TextureCube::Create()
+bool TextureCube::Create_D3D11()
 {
-    Release();
+    Release_D3D11();
 
     if (!graphics_ || !width_ || !height_)
         return false;
@@ -445,10 +445,10 @@ bool TextureCube::Create()
 
     D3D11_TEXTURE2D_DESC textureDesc;
     memset(&textureDesc, 0, sizeof textureDesc);
-    textureDesc.Format = (DXGI_FORMAT)(sRGB_ ? GetSRGBFormat(format_) : format_);
+    textureDesc.Format = (DXGI_FORMAT)(sRGB_ ? GetSRGBFormat_D3D11(format_) : format_);
 
     // Disable multisampling if not supported
-    if (multiSample_ > 1 && !graphics_->GetImpl()->CheckMultiSampleSupport(textureDesc.Format, multiSample_))
+    if (multiSample_ > 1 && !graphics_->GetImpl_D3D11()->CheckMultiSampleSupport(textureDesc.Format, multiSample_))
     {
         multiSample_ = 1;
         autoResolve_ = false;
@@ -464,7 +464,7 @@ bool TextureCube::Create()
     textureDesc.MipLevels = (multiSample_ == 1 && usage_ != TEXTURE_DYNAMIC) ? levels_ : 1;
     textureDesc.ArraySize = MAX_CUBEMAP_FACES;
     textureDesc.SampleDesc.Count = (UINT)multiSample_;
-    textureDesc.SampleDesc.Quality = graphics_->GetImpl()->GetMultiSampleQuality(textureDesc.Format, multiSample_);
+    textureDesc.SampleDesc.Quality = graphics_->GetImpl_D3D11()->GetMultiSampleQuality(textureDesc.Format, multiSample_);
     textureDesc.Usage = usage_ == TEXTURE_DYNAMIC ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT;
     textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
     if (usage_ == TEXTURE_RENDERTARGET)
@@ -477,7 +477,7 @@ bool TextureCube::Create()
     if (multiSample_ < 2)
         textureDesc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
 
-    HRESULT hr = graphics_->GetImpl()->GetDevice()->CreateTexture2D(&textureDesc, nullptr, (ID3D11Texture2D**)&object_.ptr_);
+    HRESULT hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateTexture2D(&textureDesc, nullptr, (ID3D11Texture2D**)&object_.ptr_);
     if (FAILED(hr))
     {
         URHO3D_LOGD3DERROR("Failed to create texture", hr);
@@ -494,7 +494,7 @@ bool TextureCube::Create()
         if (levels_ != 1)
             textureDesc.MiscFlags |= D3D11_RESOURCE_MISC_GENERATE_MIPS;
 
-        HRESULT hr = graphics_->GetImpl()->GetDevice()->CreateTexture2D(&textureDesc, nullptr, (ID3D11Texture2D**)&resolveTexture_);
+        HRESULT hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateTexture2D(&textureDesc, nullptr, (ID3D11Texture2D**)&resolveTexture_);
         if (FAILED(hr))
         {
             URHO3D_LOGD3DERROR("Failed to create resolve texture", hr);
@@ -505,13 +505,13 @@ bool TextureCube::Create()
 
     D3D11_SHADER_RESOURCE_VIEW_DESC resourceViewDesc;
     memset(&resourceViewDesc, 0, sizeof resourceViewDesc);
-    resourceViewDesc.Format = (DXGI_FORMAT)GetSRVFormat(textureDesc.Format);
+    resourceViewDesc.Format = (DXGI_FORMAT)GetSRVFormat_D3D11(textureDesc.Format);
     resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
     resourceViewDesc.Texture2D.MipLevels = usage_ != TEXTURE_DYNAMIC ? (UINT)levels_ : 1;
 
     // Sample the resolve texture if created, otherwise the original
     ID3D11Resource* viewObject = resolveTexture_ ? (ID3D11Resource*)resolveTexture_ : (ID3D11Resource*)object_.ptr_;
-    hr = graphics_->GetImpl()->GetDevice()->CreateShaderResourceView(viewObject, &resourceViewDesc,
+    hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateShaderResourceView(viewObject, &resourceViewDesc,
         (ID3D11ShaderResourceView**)&shaderResourceView_);
     if (FAILED(hr))
     {
@@ -541,7 +541,7 @@ bool TextureCube::Create()
                 renderTargetViewDesc.Texture2DArray.MipSlice = 0;
             }
 
-            hr = graphics_->GetImpl()->GetDevice()->CreateRenderTargetView((ID3D11Resource*)object_.ptr_, &renderTargetViewDesc,
+            hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateRenderTargetView((ID3D11Resource*)object_.ptr_, &renderTargetViewDesc,
                 (ID3D11RenderTargetView**)&renderSurfaces_[i]->renderTargetView_);
 
             if (FAILED(hr))

+ 29 - 29
Source/Urho3D/Graphics/Direct3D11/D3D11VertexBuffer.cpp

@@ -23,28 +23,28 @@
 #include "../../Precompiled.h"
 
 #include "../../Graphics/Graphics.h"
-#include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/VertexBuffer.h"
 #include "../../IO/Log.h"
+#include "D3D11GraphicsImpl.h"
 
 #include "../../DebugNew.h"
 
 namespace Urho3D
 {
 
-void VertexBuffer::OnDeviceLost()
+void VertexBuffer::OnDeviceLost_D3D11()
 {
     // No-op on Direct3D11
 }
 
-void VertexBuffer::OnDeviceReset()
+void VertexBuffer::OnDeviceReset_D3D11()
 {
     // No-op on Direct3D11
 }
 
-void VertexBuffer::Release()
+void VertexBuffer::Release_D3D11()
 {
-    Unlock();
+    Unlock_D3D11();
 
     if (graphics_)
     {
@@ -58,7 +58,7 @@ void VertexBuffer::Release()
     URHO3D_SAFE_RELEASE(object_.ptr_);
 }
 
-bool VertexBuffer::SetData(const void* data)
+bool VertexBuffer::SetData_D3D11(const void* data)
 {
     if (!data)
     {
@@ -79,11 +79,11 @@ bool VertexBuffer::SetData(const void* data)
     {
         if (dynamic_)
         {
-            void* hwData = MapBuffer(0, vertexCount_, true);
+            void* hwData = MapBuffer_D3D11(0, vertexCount_, true);
             if (hwData)
             {
                 memcpy(hwData, data, vertexCount_ * vertexSize_);
-                UnmapBuffer();
+                UnmapBuffer_D3D11();
             }
             else
                 return false;
@@ -98,17 +98,17 @@ bool VertexBuffer::SetData(const void* data)
             destBox.front = 0;
             destBox.back = 1;
 
-            graphics_->GetImpl()->GetDeviceContext()->UpdateSubresource((ID3D11Buffer*)object_.ptr_, 0, &destBox, data, 0, 0);
+            graphics_->GetImpl_D3D11()->GetDeviceContext()->UpdateSubresource((ID3D11Buffer*)object_.ptr_, 0, &destBox, data, 0, 0);
         }
     }
 
     return true;
 }
 
-bool VertexBuffer::SetDataRange(const void* data, unsigned start, unsigned count, bool discard)
+bool VertexBuffer::SetDataRange_D3D11(const void* data, unsigned start, unsigned count, bool discard)
 {
     if (start == 0 && count == vertexCount_)
-        return SetData(data);
+        return SetData_D3D11(data);
 
     if (!data)
     {
@@ -138,11 +138,11 @@ bool VertexBuffer::SetDataRange(const void* data, unsigned start, unsigned count
     {
         if (dynamic_)
         {
-            void* hwData = MapBuffer(start, count, discard);
+            void* hwData = MapBuffer_D3D11(start, count, discard);
             if (hwData)
             {
                 memcpy(hwData, data, count * vertexSize_);
-                UnmapBuffer();
+                UnmapBuffer_D3D11();
             }
             else
                 return false;
@@ -157,14 +157,14 @@ bool VertexBuffer::SetDataRange(const void* data, unsigned start, unsigned count
             destBox.front = 0;
             destBox.back = 1;
 
-            graphics_->GetImpl()->GetDeviceContext()->UpdateSubresource((ID3D11Buffer*)object_.ptr_, 0, &destBox, data, 0, 0);
+            graphics_->GetImpl_D3D11()->GetDeviceContext()->UpdateSubresource((ID3D11Buffer*)object_.ptr_, 0, &destBox, data, 0, 0);
         }
     }
 
     return true;
 }
 
-void* VertexBuffer::Lock(unsigned start, unsigned count, bool discard)
+void* VertexBuffer::Lock_D3D11(unsigned start, unsigned count, bool discard)
 {
     if (lockState_ != LOCK_NONE)
     {
@@ -192,7 +192,7 @@ void* VertexBuffer::Lock(unsigned start, unsigned count, bool discard)
 
     // Because shadow data must be kept in sync, can only lock hardware buffer if not shadowed
     if (object_.ptr_ && !shadowData_ && dynamic_)
-        return MapBuffer(start, count, discard);
+        return MapBuffer_D3D11(start, count, discard);
     else if (shadowData_)
     {
         lockState_ = LOCK_SHADOW;
@@ -208,21 +208,21 @@ void* VertexBuffer::Lock(unsigned start, unsigned count, bool discard)
         return nullptr;
 }
 
-void VertexBuffer::Unlock()
+void VertexBuffer::Unlock_D3D11()
 {
     switch (lockState_)
     {
     case LOCK_HARDWARE:
-        UnmapBuffer();
+        UnmapBuffer_D3D11();
         break;
 
     case LOCK_SHADOW:
-        SetDataRange(shadowData_.Get() + lockStart_ * vertexSize_, lockStart_, lockCount_);
+        SetDataRange_D3D11(shadowData_.Get() + lockStart_ * vertexSize_, lockStart_, lockCount_);
         lockState_ = LOCK_NONE;
         break;
 
     case LOCK_SCRATCH:
-        SetDataRange(lockScratchData_, lockStart_, lockCount_);
+        SetDataRange_D3D11(lockScratchData_, lockStart_, lockCount_);
         if (graphics_)
             graphics_->FreeScratchBuffer(lockScratchData_);
         lockScratchData_ = nullptr;
@@ -233,9 +233,9 @@ void VertexBuffer::Unlock()
     }
 }
 
-bool VertexBuffer::Create()
+bool VertexBuffer::Create_D3D11()
 {
-    Release();
+    Release_D3D11();
 
     if (!vertexCount_ || !elementMask_)
         return true;
@@ -249,7 +249,7 @@ bool VertexBuffer::Create()
         bufferDesc.Usage = dynamic_ ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT;
         bufferDesc.ByteWidth = (UINT)(vertexCount_ * vertexSize_);
 
-        HRESULT hr = graphics_->GetImpl()->GetDevice()->CreateBuffer(&bufferDesc, nullptr, (ID3D11Buffer**)&object_.ptr_);
+        HRESULT hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateBuffer(&bufferDesc, nullptr, (ID3D11Buffer**)&object_.ptr_);
         if (FAILED(hr))
         {
             URHO3D_SAFE_RELEASE(object_.ptr_);
@@ -261,15 +261,15 @@ bool VertexBuffer::Create()
     return true;
 }
 
-bool VertexBuffer::UpdateToGPU()
+bool VertexBuffer::UpdateToGPU_D3D11()
 {
     if (object_.ptr_ && shadowData_)
-        return SetData(shadowData_.Get());
+        return SetData_D3D11(shadowData_.Get());
     else
         return false;
 }
 
-void* VertexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
+void* VertexBuffer::MapBuffer_D3D11(unsigned start, unsigned count, bool discard)
 {
     void* hwData = nullptr;
 
@@ -278,7 +278,7 @@ void* VertexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
         D3D11_MAPPED_SUBRESOURCE mappedData;
         mappedData.pData = nullptr;
 
-        HRESULT hr = graphics_->GetImpl()->GetDeviceContext()->Map((ID3D11Buffer*)object_.ptr_, 0, discard ? D3D11_MAP_WRITE_DISCARD :
+        HRESULT hr = graphics_->GetImpl_D3D11()->GetDeviceContext()->Map((ID3D11Buffer*)object_.ptr_, 0, discard ? D3D11_MAP_WRITE_DISCARD :
             D3D11_MAP_WRITE, 0, &mappedData);
         if (FAILED(hr) || !mappedData.pData)
             URHO3D_LOGD3DERROR("Failed to map vertex buffer", hr);
@@ -292,11 +292,11 @@ void* VertexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
     return hwData;
 }
 
-void VertexBuffer::UnmapBuffer()
+void VertexBuffer::UnmapBuffer_D3D11()
 {
     if (object_.ptr_ && lockState_ == LOCK_HARDWARE)
     {
-        graphics_->GetImpl()->GetDeviceContext()->Unmap((ID3D11Buffer*)object_.ptr_, 0);
+        graphics_->GetImpl_D3D11()->GetDeviceContext()->Unmap((ID3D11Buffer*)object_.ptr_, 0);
         lockState_ = LOCK_NONE;
     }
 }

+ 6 - 6
Source/Urho3D/Graphics/Direct3D11/D3D11VertexDeclaration.cpp

@@ -23,11 +23,11 @@
 #include "../../Precompiled.h"
 
 #include "../../Graphics/Graphics.h"
-#include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/ShaderVariation.h"
 #include "../../Graphics/VertexBuffer.h"
-#include "../../Graphics/VertexDeclaration.h"
 #include "../../IO/Log.h"
+#include "D3D11GraphicsImpl.h"
+#include "D3D11VertexDeclaration.h"
 
 #include "../../DebugNew.h"
 
@@ -45,7 +45,7 @@ static const DXGI_FORMAT d3dElementFormats[] =
     DXGI_FORMAT_R8G8B8A8_UNORM
 };
 
-VertexDeclaration::VertexDeclaration(Graphics* graphics, ShaderVariation* vertexShader, VertexBuffer** vertexBuffers) :
+VertexDeclaration_D3D11::VertexDeclaration_D3D11(Graphics* graphics, ShaderVariation* vertexShader, VertexBuffer** vertexBuffers) :
     inputLayout_(nullptr)
 {
     PODVector<D3D11_INPUT_ELEMENT_DESC> elementDescs;
@@ -62,7 +62,7 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, ShaderVariation* vertex
         for (unsigned j = 0; j < srcElements.Size(); ++j)
         {
             const VertexElement& srcElement = srcElements[j];
-            const char* semanticName = ShaderVariation::elementSemanticNames[srcElement.semantic_];
+            const char* semanticName = ShaderVariation::elementSemanticNames_D3D11[srcElement.semantic_];
 
             // Override existing element if necessary
             for (unsigned k = 0; k < prevBufferDescs; ++k)
@@ -100,7 +100,7 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, ShaderVariation* vertex
 
     const PODVector<unsigned char>& byteCode = vertexShader->GetByteCode();
 
-    HRESULT hr = graphics->GetImpl()->GetDevice()->CreateInputLayout(&elementDescs[0], (UINT)elementDescs.Size(), &byteCode[0],
+    HRESULT hr = graphics->GetImpl_D3D11()->GetDevice()->CreateInputLayout(&elementDescs[0], (UINT)elementDescs.Size(), &byteCode[0],
         byteCode.Size(), (ID3D11InputLayout**)&inputLayout_);
     if (FAILED(hr))
     {
@@ -110,7 +110,7 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, ShaderVariation* vertex
     }
 }
 
-VertexDeclaration::~VertexDeclaration()
+VertexDeclaration_D3D11::~VertexDeclaration_D3D11()
 {
     URHO3D_SAFE_RELEASE(inputLayout_);
 }

+ 3 - 3
Source/Urho3D/Graphics/Direct3D11/D3D11VertexDeclaration.h

@@ -34,13 +34,13 @@ class ShaderVariation;
 class VertexBuffer;
 
 /// Vertex declaration.
-class URHO3D_API VertexDeclaration : public RefCounted
+class URHO3D_API VertexDeclaration_D3D11 : public RefCounted
 {
 public:
     /// Construct with vertex buffers and element masks to base declaration on.
-    VertexDeclaration(Graphics* graphics, ShaderVariation* vertexShader, VertexBuffer** buffers);
+    VertexDeclaration_D3D11(Graphics* graphics, ShaderVariation* vertexShader, VertexBuffer** buffers);
     /// Destruct.
-    virtual ~VertexDeclaration() override;
+    virtual ~VertexDeclaration_D3D11() override;
 
     /// Return input layout object corresponding to the declaration.
     void* GetInputLayout() const { return inputLayout_; }

+ 4 - 4
Source/Urho3D/Graphics/Direct3D9/D3D9ConstantBuffer.cpp

@@ -31,21 +31,21 @@
 namespace Urho3D
 {
 
-void ConstantBuffer::OnDeviceReset()
+void ConstantBuffer::OnDeviceReset_D3D9()
 {
 }
 
-void ConstantBuffer::Release()
+void ConstantBuffer::Release_D3D9()
 {
 }
 
-bool ConstantBuffer::SetSize(unsigned size)
+bool ConstantBuffer::SetSize_D3D9(unsigned size)
 {
     URHO3D_LOGERROR("Constant buffers are not supported on Direct3D9");
     return false;
 }
 
-void ConstantBuffer::Apply()
+void ConstantBuffer::Apply_D3D9()
 {
 }
 

File diff suppressed because it is too large
+ 241 - 206
Source/Urho3D/Graphics/Direct3D9/D3D9Graphics.cpp


+ 4 - 4
Source/Urho3D/Graphics/Direct3D9/D3D9GraphicsImpl.cpp

@@ -23,14 +23,14 @@
 #include "../../Precompiled.h"
 
 #include "../../Graphics/Graphics.h"
-#include "../../Graphics/GraphicsImpl.h"
+#include "D3D9GraphicsImpl.h"
 
 #include "../../DebugNew.h"
 
 namespace Urho3D
 {
 
-GraphicsImpl::GraphicsImpl() :
+GraphicsImpl_D3D9::GraphicsImpl_D3D9() :
     interface_(nullptr),
     device_(nullptr),
     defaultColorSurface_(nullptr),
@@ -45,13 +45,13 @@ GraphicsImpl::GraphicsImpl() :
     memset(&presentParams_, 0, sizeof presentParams_);
 }
 
-bool GraphicsImpl::CheckFormatSupport(D3DFORMAT format, DWORD usage, D3DRESOURCETYPE type)
+bool GraphicsImpl_D3D9::CheckFormatSupport(D3DFORMAT format, DWORD usage, D3DRESOURCETYPE type)
 {
     return interface_ ? SUCCEEDED(interface_->CheckDeviceFormat(adapter_, deviceType_, D3DFMT_X8R8G8B8, usage, type, format)) :
         false;
 }
 
-bool GraphicsImpl::CheckMultiSampleSupport(D3DFORMAT format, int level)
+bool GraphicsImpl_D3D9::CheckMultiSampleSupport(D3DFORMAT format, int level)
 {
     return interface_ ? SUCCEEDED(interface_->CheckDeviceMultiSampleType(adapter_, deviceType_, format, FALSE,
         (D3DMULTISAMPLE_TYPE)level, nullptr)) : false;

+ 10 - 10
Source/Urho3D/Graphics/Direct3D9/D3D9GraphicsImpl.h

@@ -22,9 +22,9 @@
 
 #pragma once
 
-#include "../../Graphics/ShaderProgram.h"
-#include "../../Graphics/VertexDeclaration.h"
 #include "../../Math/Color.h"
+#include "D3D9ShaderProgram.h"
+#include "D3D9VertexDeclaration.h"
 
 #include <d3d9.h>
 
@@ -35,17 +35,17 @@ namespace Urho3D
 
 #define URHO3D_LOGD3DERROR(msg, hr) URHO3D_LOGERRORF("%s (HRESULT %x)", msg, (unsigned)hr)
 
-using ShaderProgramMap = HashMap<Pair<ShaderVariation*, ShaderVariation*>, SharedPtr<ShaderProgram> >;
-using VertexDeclarationMap = HashMap<unsigned long long, SharedPtr<VertexDeclaration> >;
+using ShaderProgramMap_D3D9 = HashMap<Pair<ShaderVariation*, ShaderVariation*>, SharedPtr<ShaderProgram_D3D9> >;
+using VertexDeclarationMap_D3D9 = HashMap<unsigned long long, SharedPtr<VertexDeclaration_D3D9> >;
 
 /// %Graphics implementation. Holds API-specific objects.
-class URHO3D_API GraphicsImpl
+class URHO3D_API GraphicsImpl_D3D9
 {
     friend class Graphics;
 
 public:
     /// Construct.
-    GraphicsImpl();
+    GraphicsImpl_D3D9();
 
     /// Return Direct3D device.
     IDirect3DDevice9* GetDevice() const { return device_; }
@@ -120,17 +120,17 @@ private:
     /// Blend operation.
     D3DBLENDOP blendOp_;
     /// Vertex declarations.
-    VertexDeclarationMap vertexDeclarations_;
+    VertexDeclarationMap_D3D9 vertexDeclarations_;
     /// Stream frequencies by vertex buffer.
     unsigned streamFrequencies_[MAX_VERTEX_STREAMS];
     /// Stream offsets by vertex buffer.
     unsigned streamOffsets_[MAX_VERTEX_STREAMS];
     /// Vertex declaration in use.
-    VertexDeclaration* vertexDeclaration_;
+    VertexDeclaration_D3D9* vertexDeclaration_;
     /// Shader programs.
-    ShaderProgramMap shaderPrograms_;
+    ShaderProgramMap_D3D9 shaderPrograms_;
     /// Shader program in use.
-    ShaderProgram* shaderProgram_;
+    ShaderProgram_D3D9* shaderProgram_;
 
 };
 

+ 26 - 26
Source/Urho3D/Graphics/Direct3D9/D3D9IndexBuffer.cpp

@@ -24,39 +24,39 @@
 
 #include "../../Core/Context.h"
 #include "../../Graphics/Graphics.h"
-#include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/IndexBuffer.h"
 #include "../../IO/Log.h"
+#include "D3D9GraphicsImpl.h"
 
 #include "../../DebugNew.h"
 
 namespace Urho3D
 {
 
-void IndexBuffer::OnDeviceLost()
+void IndexBuffer::OnDeviceLost_D3D9()
 {
     // Dynamic buffers are in the default pool and need to be released on device loss
     if (dynamic_)
-        Release();
+        Release_D3D9();
 }
 
-void IndexBuffer::OnDeviceReset()
+void IndexBuffer::OnDeviceReset_D3D9()
 {
     // Dynamic buffers are in the default pool and need to be recreated after device reset
     if (dynamic_ || !object_.ptr_)
     {
-        Create();
-        dataLost_ = !UpdateToGPU();
+        Create_D3D9();
+        dataLost_ = !UpdateToGPU_D3D9();
     }
     else if (dataPending_)
-        dataLost_ = !UpdateToGPU();
+        dataLost_ = !UpdateToGPU_D3D9();
 
     dataPending_ = false;
 }
 
-void IndexBuffer::Release()
+void IndexBuffer::Release_D3D9()
 {
-    Unlock();
+    Unlock_D3D9();
 
     if (graphics_ && graphics_->GetIndexBuffer() == this)
         graphics_->SetIndexBuffer(nullptr);
@@ -64,7 +64,7 @@ void IndexBuffer::Release()
     URHO3D_SAFE_RELEASE(object_.ptr_);
 }
 
-bool IndexBuffer::SetData(const void* data)
+bool IndexBuffer::SetData_D3D9(const void* data)
 {
     if (!data)
     {
@@ -90,7 +90,7 @@ bool IndexBuffer::SetData(const void* data)
             return true;
         }
 
-        void* hwData = MapBuffer(0, indexCount_, true);
+        void* hwData = MapBuffer_D3D9(0, indexCount_, true);
         if (hwData)
         {
             memcpy(hwData, data, indexCount_ * indexSize_);
@@ -104,10 +104,10 @@ bool IndexBuffer::SetData(const void* data)
     return true;
 }
 
-bool IndexBuffer::SetDataRange(const void* data, unsigned start, unsigned count, bool discard)
+bool IndexBuffer::SetDataRange_D3D9(const void* data, unsigned start, unsigned count, bool discard)
 {
     if (start == 0 && count == indexCount_)
-        return SetData(data);
+        return SetData_D3D9(data);
 
     if (!data)
     {
@@ -142,7 +142,7 @@ bool IndexBuffer::SetDataRange(const void* data, unsigned start, unsigned count,
             return true;
         }
 
-        void* hwData = MapBuffer(start, count, discard);
+        void* hwData = MapBuffer_D3D9(start, count, discard);
         if (hwData)
         {
             memcpy(hwData, data, count * indexSize_);
@@ -155,7 +155,7 @@ bool IndexBuffer::SetDataRange(const void* data, unsigned start, unsigned count,
     return true;
 }
 
-void* IndexBuffer::Lock(unsigned start, unsigned count, bool discard)
+void* IndexBuffer::Lock_D3D9(unsigned start, unsigned count, bool discard)
 {
     if (lockState_ != LOCK_NONE)
     {
@@ -183,7 +183,7 @@ void* IndexBuffer::Lock(unsigned start, unsigned count, bool discard)
 
     // Because shadow data must be kept in sync, can only lock hardware buffer if not shadowed
     if (object_.ptr_ && !shadowData_ && !graphics_->IsDeviceLost())
-        return MapBuffer(start, count, discard);
+        return MapBuffer_D3D9(start, count, discard);
     else if (shadowData_)
     {
         lockState_ = LOCK_SHADOW;
@@ -199,7 +199,7 @@ void* IndexBuffer::Lock(unsigned start, unsigned count, bool discard)
         return nullptr;
 }
 
-void IndexBuffer::Unlock()
+void IndexBuffer::Unlock_D3D9()
 {
     switch (lockState_)
     {
@@ -208,12 +208,12 @@ void IndexBuffer::Unlock()
         break;
 
     case LOCK_SHADOW:
-        SetDataRange(shadowData_.Get() + lockStart_ * indexSize_, lockStart_, lockCount_);
+        SetDataRange_D3D9(shadowData_.Get() + lockStart_ * indexSize_, lockStart_, lockCount_);
         lockState_ = LOCK_NONE;
         break;
 
     case LOCK_SCRATCH:
-        SetDataRange(lockScratchData_, lockStart_, lockCount_);
+        SetDataRange_D3D9(lockScratchData_, lockStart_, lockCount_);
         if (graphics_)
             graphics_->FreeScratchBuffer(lockScratchData_);
         lockScratchData_ = nullptr;
@@ -224,9 +224,9 @@ void IndexBuffer::Unlock()
     }
 }
 
-bool IndexBuffer::Create()
+bool IndexBuffer::Create_D3D9()
 {
-    Release();
+    Release_D3D9();
 
     if (!indexCount_)
         return true;
@@ -242,7 +242,7 @@ bool IndexBuffer::Create()
         unsigned pool = dynamic_ ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
         unsigned d3dUsage = dynamic_ ? D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY : 0;
 
-        IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
+        IDirect3DDevice9* device = graphics_->GetImpl_D3D9()->GetDevice();
         HRESULT hr = device->CreateIndexBuffer(
             indexCount_ * indexSize_,
             d3dUsage,
@@ -261,15 +261,15 @@ bool IndexBuffer::Create()
     return true;
 }
 
-bool IndexBuffer::UpdateToGPU()
+bool IndexBuffer::UpdateToGPU_D3D9()
 {
     if (object_.ptr_ && shadowData_)
-        return SetData(shadowData_.Get());
+        return SetData_D3D9(shadowData_.Get());
     else
         return false;
 }
 
-void* IndexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
+void* IndexBuffer::MapBuffer_D3D9(unsigned start, unsigned count, bool discard)
 {
     void* hwData = nullptr;
 
@@ -290,7 +290,7 @@ void* IndexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
     return hwData;
 }
 
-void IndexBuffer::UnmapBuffer()
+void IndexBuffer::UnmapBuffer_D3D9()
 {
     if (object_.ptr_ && lockState_ == LOCK_HARDWARE)
     {

+ 6 - 6
Source/Urho3D/Graphics/Direct3D9/D3D9RenderSurface.cpp

@@ -34,13 +34,13 @@
 namespace Urho3D
 {
 
-RenderSurface::RenderSurface(Texture* parentTexture) :      // NOLINT(hicpp-member-init)
-    parentTexture_(parentTexture),
-    surface_(nullptr)
+void RenderSurface::Constructor_D3D9(Texture* parentTexture)
 {
+    parentTexture_ = parentTexture;
+    surface_ = nullptr;
 }
 
-void RenderSurface::Release()
+void RenderSurface::Release_D3D9()
 {
     Graphics* graphics = parentTexture_->GetGraphics();
     if (graphics)
@@ -58,13 +58,13 @@ void RenderSurface::Release()
     URHO3D_SAFE_RELEASE(surface_);
 }
 
-bool RenderSurface::CreateRenderBuffer(unsigned width, unsigned height, unsigned format, int multiSample)
+bool RenderSurface::CreateRenderBuffer_D3D9(unsigned width, unsigned height, unsigned format, int multiSample)
 {
     // Not used on Direct3D
     return false;
 }
 
-void RenderSurface::OnDeviceLost()
+void RenderSurface::OnDeviceLost_D3D9()
 {
     // No-op on Direct3D
 }

+ 2 - 2
Source/Urho3D/Graphics/Direct3D9/D3D9ShaderProgram.h

@@ -29,11 +29,11 @@ namespace Urho3D
 {
 
 /// Combined information for specific vertex and pixel shaders.
-class ShaderProgram : public RefCounted
+class ShaderProgram_D3D9 : public RefCounted
 {
 public:
     /// Construct.
-    ShaderProgram(ShaderVariation* vertexShader, ShaderVariation* pixelShader)
+    ShaderProgram_D3D9(ShaderVariation* vertexShader, ShaderVariation* pixelShader)
     {
         const HashMap<StringHash, ShaderParameter>& vsParams = vertexShader->GetParameters();
         for (HashMap<StringHash, ShaderParameter>::ConstIterator i = vsParams.Begin(); i != vsParams.End(); ++i)

+ 19 - 19
Source/Urho3D/Graphics/Direct3D9/D3D9ShaderVariation.cpp

@@ -23,13 +23,13 @@
 #include "../../Precompiled.h"
 
 #include "../../Graphics/Graphics.h"
-#include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/Shader.h"
 #include "../../Graphics/ShaderVariation.h"
 #include "../../IO/File.h"
 #include "../../IO/FileSystem.h"
 #include "../../IO/Log.h"
 #include "../../Resource/ResourceCache.h"
+#include "D3D9GraphicsImpl.h"
 
 #include <d3dcompiler.h>
 #include <MojoShader/mojoshader.h>
@@ -39,7 +39,7 @@
 namespace Urho3D
 {
 
-void CopyStrippedCode(PODVector<unsigned char>& byteCode, unsigned char* bufData, unsigned bufSize)
+static void CopyStrippedCode(PODVector<unsigned char>& byteCode, unsigned char* bufData, unsigned bufSize)
 {
     unsigned const D3DSIO_COMMENT = 0xFFFE;
     unsigned* srcWords = (unsigned*)bufData;
@@ -69,14 +69,14 @@ void CopyStrippedCode(PODVector<unsigned char>& byteCode, unsigned char* bufData
     }
 }
 
-void ShaderVariation::OnDeviceLost()
+void ShaderVariation::OnDeviceLost_D3D9()
 {
     // No-op on Direct3D9, shaders are preserved through a device loss & reset
 }
 
-bool ShaderVariation::Create()
+bool ShaderVariation::Create_D3D9()
 {
-    Release();
+    Release_D3D9();
 
     if (!graphics_)
         return false;
@@ -94,18 +94,18 @@ bool ShaderVariation::Create()
 
     String binaryShaderName = graphics_->GetShaderCacheDir() + name + "_" + StringHash(defines_).ToString() + extension;
 
-    if (!LoadByteCode(binaryShaderName))
+    if (!LoadByteCode_D3D9(binaryShaderName))
     {
         // Compile shader if don't have valid bytecode
-        if (!Compile())
+        if (!Compile_D3D9())
             return false;
         // Save the bytecode after successful compile, but not if the source is from a package
         if (owner_->GetTimeStamp())
-            SaveByteCode(binaryShaderName);
+            SaveByteCode_D3D9(binaryShaderName);
     }
 
     // Then create shader from the bytecode
-    IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
+    IDirect3DDevice9* device = graphics_->GetImpl_D3D9()->GetDevice();
     if (type_ == VS)
     {
         HRESULT hr = device->CreateVertexShader(
@@ -136,11 +136,11 @@ bool ShaderVariation::Create()
     return object_.ptr_ != nullptr;
 }
 
-void ShaderVariation::Release()
+void ShaderVariation::Release_D3D9()
 {
     if (object_.ptr_ && graphics_)
     {
-        graphics_->CleanupShaderPrograms(this);
+        graphics_->CleanupShaderPrograms_D3D9(this);
 
         if (type_ == VS)
         {
@@ -163,12 +163,12 @@ void ShaderVariation::Release()
     parameters_.Clear();
 }
 
-void ShaderVariation::SetDefines(const String& defines)
+void ShaderVariation::SetDefines_D3D9(const String& defines)
 {
     defines_ = defines;
 }
 
-bool ShaderVariation::LoadByteCode(const String& binaryShaderName)
+bool ShaderVariation::LoadByteCode_D3D9(const String& binaryShaderName)
 {
     ResourceCache* cache = owner_->GetSubsystem<ResourceCache>();
     if (!cache->Exists(binaryShaderName))
@@ -199,7 +199,7 @@ bool ShaderVariation::LoadByteCode(const String& binaryShaderName)
         unsigned reg = file->ReadUByte();
         unsigned regCount = file->ReadUByte();
 
-        parameters_[StringHash(name)] = ShaderParameter{type_, name, reg, regCount};
+        parameters_[StringHash(name)] = ShaderParameter{type_, name, reg, regCount};
     }
 
     unsigned numTextureUnits = file->ReadUInt();
@@ -232,7 +232,7 @@ bool ShaderVariation::LoadByteCode(const String& binaryShaderName)
     }
 }
 
-bool ShaderVariation::Compile()
+bool ShaderVariation::Compile_D3D9()
 {
     const String& sourceCode = owner_->GetSourceCode(type_);
     Vector<String> defines = defines_.Split(' ');
@@ -313,7 +313,7 @@ bool ShaderVariation::Compile()
         // Inspect the produced bytecode using MojoShader, then strip and store it
         unsigned char* bufData = (unsigned char*)shaderCode->GetBufferPointer();
         unsigned bufSize = (unsigned)shaderCode->GetBufferSize();
-        ParseParameters(bufData, bufSize);
+        ParseParameters_D3D9(bufData, bufSize);
         CopyStrippedCode(byteCode_, bufData, bufSize);
     }
 
@@ -323,7 +323,7 @@ bool ShaderVariation::Compile()
     return !byteCode_.Empty();
 }
 
-void ShaderVariation::ParseParameters(unsigned char* bufData, unsigned bufSize)
+void ShaderVariation::ParseParameters_D3D9(unsigned char* bufData, unsigned bufSize)
 {
     MOJOSHADER_parseData const* parseData = MOJOSHADER_parse("bytecode", bufData, bufSize, nullptr, 0, nullptr, 0, nullptr, nullptr, nullptr);
 
@@ -350,14 +350,14 @@ void ShaderVariation::ParseParameters(unsigned char* bufData, unsigned bufSize)
         }
         else
         {
-            parameters_[StringHash(name)] = ShaderParameter{type_, name, reg, regCount};
+            parameters_[StringHash(name)] = ShaderParameter{type_, name, reg, regCount};
         }
     }
 
     MOJOSHADER_freeParseData(parseData);
 }
 
-void ShaderVariation::SaveByteCode(const String& binaryShaderName)
+void ShaderVariation::SaveByteCode_D3D9(const String& binaryShaderName)
 {
     ResourceCache* cache = owner_->GetSubsystem<ResourceCache>();
     FileSystem* fileSystem = owner_->GetSubsystem<FileSystem>();

+ 6 - 6
Source/Urho3D/Graphics/Direct3D9/D3D9Texture.cpp

@@ -35,7 +35,7 @@
 namespace Urho3D
 {
 
-void Texture::SetSRGB(bool enable)
+void Texture::SetSRGB_D3D9(bool enable)
 {
     if (graphics_)
         enable &= graphics_->GetSRGBSupport();
@@ -43,22 +43,22 @@ void Texture::SetSRGB(bool enable)
     sRGB_ = enable;
 }
 
-void Texture::UpdateParameters()
+void Texture::UpdateParameters_D3D9()
 {
     // No-op on Direct3D9, handled by Graphics instead by modifying the sampler settings as necessary
 }
 
-bool Texture::GetParametersDirty() const
+bool Texture::GetParametersDirty_D3D9() const
 {
     return false;
 }
 
-bool Texture::IsCompressed() const
+bool Texture::IsCompressed_D3D9() const
 {
     return format_ == D3DFMT_DXT1 || format_ == D3DFMT_DXT3 || format_ == D3DFMT_DXT5;
 }
 
-unsigned Texture::GetRowDataSize(int width) const
+unsigned Texture::GetRowDataSize_D3D9(int width) const
 {
     switch (format_)
     {
@@ -104,7 +104,7 @@ unsigned Texture::GetRowDataSize(int width) const
     }
 }
 
-void Texture::RegenerateLevels()
+void Texture::RegenerateLevels_D3D9()
 {
     // No-op on Direct3D9
     levelsDirty_ = false;

+ 27 - 27
Source/Urho3D/Graphics/Direct3D9/D3D9Texture2D.cpp

@@ -26,26 +26,26 @@
 #include "../../Core/Profiler.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsEvents.h"
-#include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/Renderer.h"
 #include "../../Graphics/Texture2D.h"
 #include "../../IO/Log.h"
 #include "../../IO/FileSystem.h"
 #include "../../Resource/ResourceCache.h"
 #include "../../Resource/XMLFile.h"
+#include "D3D9GraphicsImpl.h"
 
 #include "../../DebugNew.h"
 
 namespace Urho3D
 {
 
-void Texture2D::OnDeviceLost()
+void Texture2D::OnDeviceLost_D3D9()
 {
     if (usage_ > TEXTURE_STATIC)
-        Release();
+        Release_D3D9();
 }
 
-void Texture2D::OnDeviceReset()
+void Texture2D::OnDeviceReset_D3D9()
 {
     if (usage_ > TEXTURE_STATIC || !object_.ptr_ || dataPending_)
     {
@@ -56,7 +56,7 @@ void Texture2D::OnDeviceReset()
 
         if (!object_.ptr_)
         {
-            Create();
+            Create_D3D9();
             dataLost_ = true;
         }
     }
@@ -64,7 +64,7 @@ void Texture2D::OnDeviceReset()
     dataPending_ = false;
 }
 
-void Texture2D::Release()
+void Texture2D::Release_D3D9()
 {
     if (graphics_)
     {
@@ -84,7 +84,7 @@ void Texture2D::Release()
     levelsDirty_ = false;
 }
 
-bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, const void* data)
+bool Texture2D::SetData_D3D9(unsigned level, int x, int y, int width, int height, const void* data)
 {
     URHO3D_PROFILE(SetTextureData);
 
@@ -113,7 +113,7 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
         return true;
     }
 
-    if (IsCompressed())
+    if (IsCompressed_D3D9())
     {
         x &= ~3;
         y &= ~3;
@@ -145,16 +145,16 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
         return false;
     }
 
-    if (IsCompressed())
+    if (IsCompressed_D3D9())
     {
         height = (height + 3) >> 2;
         y >>= 2;
     }
 
     unsigned char* src = (unsigned char*)data;
-    unsigned rowSize = GetRowDataSize(width);
+    unsigned rowSize = GetRowDataSize_D3D9(width);
 
-    // GetRowDataSize() returns CPU-side (source) data size, so need to convert for X8R8G8B8
+    // GetRowDataSize_D3D9() returns CPU-side (source) data size, so need to convert for X8R8G8B8
     if (format_ == D3DFMT_X8R8G8B8)
         rowSize = rowSize / 3 * 4;
 
@@ -205,7 +205,7 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
     return true;
 }
 
-bool Texture2D::SetData(Image* image, bool useAlpha)
+bool Texture2D::SetData_D3D9(Image* image, bool useAlpha)
 {
     if (!image)
     {
@@ -262,13 +262,13 @@ bool Texture2D::SetData(Image* image, bool useAlpha)
         }
 
         // If image was previously compressed, reset number of requested levels to avoid error if level count is too high for new size
-        if (IsCompressed() && requestedLevels_ > 1)
+        if (IsCompressed_D3D9() && requestedLevels_ > 1)
             requestedLevels_ = 0;
         SetSize(levelWidth, levelHeight, format);
 
         for (unsigned i = 0; i < levels_; ++i)
         {
-            SetData(i, 0, 0, levelWidth, levelHeight, levelData);
+            SetData_D3D9(i, 0, 0, levelWidth, levelHeight, levelData);
             memoryUse += levelWidth * levelHeight * components;
 
             if (i < levels_ - 1)
@@ -310,14 +310,14 @@ bool Texture2D::SetData(Image* image, bool useAlpha)
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
             if (!needDecompress)
             {
-                SetData(i, 0, 0, level.width_, level.height_, level.data_);
+                SetData_D3D9(i, 0, 0, level.width_, level.height_, level.data_);
                 memoryUse += level.rows_ * level.rowSize_;
             }
             else
             {
                 unsigned char* rgbaData = new unsigned char[level.width_ * level.height_ * 4];
                 level.Decompress(rgbaData);
-                SetData(i, 0, 0, level.width_, level.height_, rgbaData);
+                SetData_D3D9(i, 0, 0, level.width_, level.height_, rgbaData);
                 memoryUse += level.width_ * level.height_ * 4;
                 delete[] rgbaData;
             }
@@ -328,7 +328,7 @@ bool Texture2D::SetData(Image* image, bool useAlpha)
     return true;
 }
 
-bool Texture2D::GetData(unsigned level, void* dest) const
+bool Texture2D::GetData_D3D9(unsigned level, void* dest) const
 {
     if (!object_.ptr_)
     {
@@ -390,7 +390,7 @@ bool Texture2D::GetData(unsigned level, void* dest) const
             }
         }
 
-        IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
+        IDirect3DDevice9* device = graphics_->GetImpl_D3D9()->GetDevice();
         HRESULT hr = device->CreateOffscreenPlainSurface((UINT)width_, (UINT)height_, (D3DFORMAT)format_,
             D3DPOOL_SYSTEMMEM, &offscreenSurface, nullptr);
         if (FAILED(hr))
@@ -433,12 +433,12 @@ bool Texture2D::GetData(unsigned level, void* dest) const
     }
 
     int height = levelHeight;
-    if (IsCompressed())
+    if (IsCompressed_D3D9())
         height = (height + 3) >> 2;
 
     unsigned char* destPtr = (unsigned char*)dest;
-    unsigned rowSize = GetRowDataSize(levelWidth);
-    // GetRowDataSize() returns CPU-side (destination) data size, so need to convert for X8R8G8B8
+    unsigned rowSize = GetRowDataSize_D3D9(levelWidth);
+    // GetRowDataSize_D3D9() returns CPU-side (destination) data size, so need to convert for X8R8G8B8
     if (format_ == D3DFMT_X8R8G8B8)
         rowSize = rowSize / 3 * 4;
 
@@ -494,9 +494,9 @@ bool Texture2D::GetData(unsigned level, void* dest) const
     return true;
 }
 
-bool Texture2D::Create()
+bool Texture2D::Create_D3D9()
 {
-    Release();
+    Release_D3D9();
 
     if (!graphics_ || !width_ || !height_)
         return false;
@@ -513,7 +513,7 @@ bool Texture2D::Create()
         autoResolve_ = true;
     }
 
-    GraphicsImpl* impl = graphics_->GetImpl();
+    GraphicsImpl_D3D9* impl = graphics_->GetImpl_D3D9();
 
     unsigned pool = usage_ > TEXTURE_STATIC ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
     unsigned d3dUsage = 0;
@@ -556,10 +556,10 @@ bool Texture2D::Create()
         }
     }
 
-    IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
+    IDirect3DDevice9* device = graphics_->GetImpl_D3D9()->GetDevice();
     // If creating a depth-stencil texture, and it is not supported, create a depth-stencil surface instead
     // Multisampled surfaces need also to be created this way
-    if (usage_ == TEXTURE_DEPTHSTENCIL && (multiSample_ > 1 || !graphics_->GetImpl()->CheckFormatSupport((D3DFORMAT)format_,
+    if (usage_ == TEXTURE_DEPTHSTENCIL && (multiSample_ > 1 || !graphics_->GetImpl_D3D9()->CheckFormatSupport((D3DFORMAT)format_,
         d3dUsage, D3DRTYPE_TEXTURE)))
     {
         HRESULT hr = device->CreateDepthStencilSurface(
@@ -582,7 +582,7 @@ bool Texture2D::Create()
     }
     else
     {
-        HRESULT hr = graphics_->GetImpl()->GetDevice()->CreateTexture(
+        HRESULT hr = graphics_->GetImpl_D3D9()->GetDevice()->CreateTexture(
             (UINT)width_,
             (UINT)height_,
             requestedLevels_,

+ 16 - 16
Source/Urho3D/Graphics/Direct3D9/D3D9Texture2DArray.cpp

@@ -43,13 +43,13 @@
 namespace Urho3D
 {
 
-void Texture2DArray::OnDeviceLost()
+void Texture2DArray::OnDeviceLost_D3D9()
 {
     if (usage_ > TEXTURE_STATIC)
-        Release();
+        Release_D3D9();
 }
 
-void Texture2DArray::OnDeviceReset()
+void Texture2DArray::OnDeviceReset_D3D9()
 {
     if (usage_ > TEXTURE_STATIC || !object_.ptr_ || dataPending_)
     {
@@ -60,7 +60,7 @@ void Texture2DArray::OnDeviceReset()
 
         if (!object_.ptr_)
         {
-            Create();
+            Create_D3D9();
             dataLost_ = true;
         }
     }
@@ -68,7 +68,7 @@ void Texture2DArray::OnDeviceReset()
     dataPending_ = false;
 }
 
-void Texture2DArray::Release()
+void Texture2DArray::Release_D3D9()
 {
     if (graphics_)
     {
@@ -85,22 +85,22 @@ void Texture2DArray::Release()
     URHO3D_SAFE_RELEASE(object_.ptr_);
 }
 
-bool Texture2DArray::SetData(unsigned layer, unsigned level, int x, int y, int width, int height, const void* data)
+bool Texture2DArray::SetData_D3D9(unsigned layer, unsigned level, int x, int y, int width, int height, const void* data)
 {
     URHO3D_LOGERROR("Texture2DArray not supported on Direct3D9, can not set data");
     return false;
 }
 
-bool Texture2DArray::SetData(unsigned layer, Deserializer& source)
+bool Texture2DArray::SetData_D3D9(unsigned layer, Deserializer& source)
 {
     SharedPtr<Image> image(new Image(context_));
     if (!image->Load(source))
         return false;
 
-    return SetData(layer, image);
+    return SetData_D3D9(layer, image);
 }
 
-bool Texture2DArray::SetData(unsigned layer, Image* image, bool useAlpha)
+bool Texture2DArray::SetData_D3D9(unsigned layer, Image* image, bool useAlpha)
 {
     if (!image)
     {
@@ -160,7 +160,7 @@ bool Texture2DArray::SetData(unsigned layer, Image* image, bool useAlpha)
         if (!layer)
         {
             // If image was previously compressed, reset number of requested levels to avoid error if level count is too high for new size
-            if (IsCompressed() && requestedLevels_ > 1)
+            if (IsCompressed_D3D9() && requestedLevels_ > 1)
                 requestedLevels_ = 0;
             // Create the texture array (the number of layers must have been already set)
             SetSize(0, levelWidth, levelHeight, format);
@@ -182,7 +182,7 @@ bool Texture2DArray::SetData(unsigned layer, Image* image, bool useAlpha)
 
         for (unsigned i = 0; i < levels_; ++i)
         {
-            SetData(layer, i, 0, 0, levelWidth, levelHeight, levelData);
+            SetData_D3D9(layer, i, 0, 0, levelWidth, levelHeight, levelData);
             memoryUse += levelWidth * levelHeight * components;
 
             if (i < levels_ - 1)
@@ -241,14 +241,14 @@ bool Texture2DArray::SetData(unsigned layer, Image* image, bool useAlpha)
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
             if (!needDecompress)
             {
-                SetData(layer, i, 0, 0, level.width_, level.height_, level.data_);
+                SetData_D3D9(layer, i, 0, 0, level.width_, level.height_, level.data_);
                 memoryUse += level.rows_ * level.rowSize_;
             }
             else
             {
                 unsigned char* rgbaData = new unsigned char[level.width_ * level.height_ * 4];
                 level.Decompress(rgbaData);
-                SetData(layer, i, 0, 0, level.width_, level.height_, rgbaData);
+                SetData_D3D9(layer, i, 0, 0, level.width_, level.height_, rgbaData);
                 memoryUse += level.width_ * level.height_ * 4;
                 delete[] rgbaData;
             }
@@ -264,15 +264,15 @@ bool Texture2DArray::SetData(unsigned layer, Image* image, bool useAlpha)
     return true;
 }
 
-bool Texture2DArray::GetData(unsigned layer, unsigned level, void* dest) const
+bool Texture2DArray::GetData_D3D9(unsigned layer, unsigned level, void* dest) const
 {
     URHO3D_LOGERROR("Texture2DArray not supported on Direct3D9, can not get data");
     return false;
 }
 
-bool Texture2DArray::Create()
+bool Texture2DArray::Create_D3D9()
 {
-    Release();
+    Release_D3D9();
 
     if (!graphics_ || !width_ || !height_ || !layers_)
         return false;

+ 23 - 23
Source/Urho3D/Graphics/Direct3D9/D3D9Texture3D.cpp

@@ -26,26 +26,26 @@
 #include "../../Core/Profiler.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsEvents.h"
-#include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/Renderer.h"
 #include "../../Graphics/Texture3D.h"
 #include "../../IO/FileSystem.h"
 #include "../../IO/Log.h"
 #include "../../Resource/ResourceCache.h"
 #include "../../Resource/XMLFile.h"
+#include "D3D9GraphicsImpl.h"
 
 #include "../../DebugNew.h"
 
 namespace Urho3D
 {
 
-void Texture3D::OnDeviceLost()
+void Texture3D::OnDeviceLost_D3D9()
 {
     if (usage_ > TEXTURE_STATIC)
-        Release();
+        Release_D3D9();
 }
 
-void Texture3D::OnDeviceReset()
+void Texture3D::OnDeviceReset_D3D9()
 {
     if (usage_ > TEXTURE_STATIC || !object_.ptr_ || dataPending_)
     {
@@ -56,7 +56,7 @@ void Texture3D::OnDeviceReset()
 
         if (!object_.ptr_)
         {
-            Create();
+            Create_D3D9();
             dataLost_ = true;
         }
     }
@@ -64,7 +64,7 @@ void Texture3D::OnDeviceReset()
     dataPending_ = false;
 }
 
-void Texture3D::Release()
+void Texture3D::Release_D3D9()
 {
     if (graphics_)
     {
@@ -78,7 +78,7 @@ void Texture3D::Release()
     URHO3D_SAFE_RELEASE(object_.ptr_);
 }
 
-bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int height, int depth, const void* data)
+bool Texture3D::SetData_D3D9(unsigned level, int x, int y, int z, int width, int height, int depth, const void* data)
 {
     URHO3D_PROFILE(SetTextureData);
 
@@ -107,7 +107,7 @@ bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int heig
         return true;
     }
 
-    if (IsCompressed())
+    if (IsCompressed_D3D9())
     {
         x &= ~3;
         y &= ~3;
@@ -144,16 +144,16 @@ bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int heig
         return false;
     }
 
-    if (IsCompressed())
+    if (IsCompressed_D3D9())
     {
         height = (height + 3) >> 2;
         y >>= 2;
     }
 
     unsigned char* src = (unsigned char*)data;
-    unsigned rowSize = GetRowDataSize(width);
+    unsigned rowSize = GetRowDataSize_D3D9(width);
 
-    // GetRowDataSize() returns CPU-side (source) data size, so need to convert for X8R8G8B8
+    // GetRowDataSize_D3D9() returns CPU-side (source) data size, so need to convert for X8R8G8B8
     if (format_ == D3DFMT_X8R8G8B8)
         rowSize = rowSize / 3 * 4;
 
@@ -216,7 +216,7 @@ bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int heig
     return true;
 }
 
-bool Texture3D::SetData(Image* image, bool useAlpha)
+bool Texture3D::SetData_D3D9(Image* image, bool useAlpha)
 {
     if (!image)
     {
@@ -275,13 +275,13 @@ bool Texture3D::SetData(Image* image, bool useAlpha)
         }
 
         // If image was previously compressed, reset number of requested levels to avoid error if level count is too high for new size
-        if (IsCompressed() && requestedLevels_ > 1)
+        if (IsCompressed_D3D9() && requestedLevels_ > 1)
             requestedLevels_ = 0;
         SetSize(levelWidth, levelHeight, levelDepth, format);
 
         for (unsigned i = 0; i < levels_; ++i)
         {
-            SetData(i, 0, 0, 0, levelWidth, levelHeight, levelDepth, levelData);
+            SetData_D3D9(i, 0, 0, 0, levelWidth, levelHeight, levelDepth, levelData);
             memoryUse += levelWidth * levelHeight * levelDepth * components;
 
             if (i < levels_ - 1)
@@ -326,14 +326,14 @@ bool Texture3D::SetData(Image* image, bool useAlpha)
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
             if (!needDecompress)
             {
-                SetData(i, 0, 0, 0, level.width_, level.height_, level.depth_, level.data_);
+                SetData_D3D9(i, 0, 0, 0, level.width_, level.height_, level.depth_, level.data_);
                 memoryUse += level.depth_ * level.rows_ * level.rowSize_;
             }
             else
             {
                 unsigned char* rgbaData = new unsigned char[level.width_ * level.height_ * level.depth_ * 4];
                 level.Decompress(rgbaData);
-                SetData(i, 0, 0, 0, level.width_, level.height_, level.depth_, rgbaData);
+                SetData_D3D9(i, 0, 0, 0, level.width_, level.height_, level.depth_, rgbaData);
                 memoryUse += level.width_ * level.height_ * level.depth_ * 4;
                 delete[] rgbaData;
             }
@@ -344,7 +344,7 @@ bool Texture3D::SetData(Image* image, bool useAlpha)
     return true;
 }
 
-bool Texture3D::GetData(unsigned level, void* dest) const
+bool Texture3D::GetData_D3D9(unsigned level, void* dest) const
 {
     if (!object_.ptr_)
     {
@@ -391,12 +391,12 @@ bool Texture3D::GetData(unsigned level, void* dest) const
     }
 
     int height = levelHeight;
-    if (IsCompressed())
+    if (IsCompressed_D3D9())
         height = (height + 3) >> 2;
 
     unsigned char* destPtr = (unsigned char*)dest;
-    unsigned rowSize = GetRowDataSize(levelWidth);
-    // GetRowDataSize() returns CPU-side (destination) data size, so need to convert for X8R8G8B8
+    unsigned rowSize = GetRowDataSize_D3D9(levelWidth);
+    // GetRowDataSize_D3D9() returns CPU-side (destination) data size, so need to convert for X8R8G8B8
     if (format_ == D3DFMT_X8R8G8B8)
         rowSize = rowSize / 3 * 4;
 
@@ -456,9 +456,9 @@ bool Texture3D::GetData(unsigned level, void* dest) const
     return true;
 }
 
-bool Texture3D::Create()
+bool Texture3D::Create_D3D9()
 {
-    Release();
+    Release_D3D9();
 
     if (!graphics_ || !width_ || !height_)
         return false;
@@ -472,7 +472,7 @@ bool Texture3D::Create()
     unsigned pool = usage_ > TEXTURE_STATIC ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
     unsigned d3dUsage = usage_ == TEXTURE_DYNAMIC ? D3DUSAGE_DYNAMIC : 0;
 
-    IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
+    IDirect3DDevice9* device = graphics_->GetImpl_D3D9()->GetDevice();
     HRESULT hr = device->CreateVolumeTexture(
         (UINT)width_,
         (UINT)height_,

+ 28 - 28
Source/Urho3D/Graphics/Direct3D9/D3D9TextureCube.cpp

@@ -26,13 +26,13 @@
 #include "../../Core/Profiler.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsEvents.h"
-#include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/Renderer.h"
 #include "../../Graphics/TextureCube.h"
 #include "../../IO/FileSystem.h"
 #include "../../IO/Log.h"
 #include "../../Resource/ResourceCache.h"
 #include "../../Resource/XMLFile.h"
+#include "D3D9GraphicsImpl.h"
 
 #include "../../DebugNew.h"
 
@@ -43,13 +43,13 @@
 namespace Urho3D
 {
 
-void TextureCube::OnDeviceLost()
+void TextureCube::OnDeviceLost_D3D9()
 {
     if (usage_ > TEXTURE_STATIC)
-        Release();
+        Release_D3D9();
 }
 
-void TextureCube::OnDeviceReset()
+void TextureCube::OnDeviceReset_D3D9()
 {
     if (usage_ > TEXTURE_STATIC || !object_.ptr_ || dataPending_)
     {
@@ -60,7 +60,7 @@ void TextureCube::OnDeviceReset()
 
         if (!object_.ptr_)
         {
-            Create();
+            Create_D3D9();
             dataLost_ = true;
         }
     }
@@ -68,7 +68,7 @@ void TextureCube::OnDeviceReset()
     dataPending_ = false;
 }
 
-void TextureCube::Release()
+void TextureCube::Release_D3D9()
 {
     if (graphics_)
     {
@@ -91,7 +91,7 @@ void TextureCube::Release()
     levelsDirty_ = false;
 }
 
-bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int width, int height, const void* data)
+bool TextureCube::SetData_D3D9(CubeMapFace face, unsigned level, int x, int y, int width, int height, const void* data)
 {
     URHO3D_PROFILE(SetTextureData);
 
@@ -120,7 +120,7 @@ bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int wi
         return true;
     }
 
-    if (IsCompressed())
+    if (IsCompressed_D3D9())
     {
         x &= ~3;
         y &= ~3;
@@ -153,16 +153,16 @@ bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int wi
         return false;
     }
 
-    if (IsCompressed())
+    if (IsCompressed_D3D9())
     {
         height = (height + 3) >> 2;
         y >>= 2;
     }
 
     unsigned char* src = (unsigned char*)data;
-    unsigned rowSize = GetRowDataSize(width);
+    unsigned rowSize = GetRowDataSize_D3D9(width);
 
-    // GetRowDataSize() returns CPU-side (source) data size, so need to convert for X8R8G8B8
+    // GetRowDataSize_D3D9() returns CPU-side (source) data size, so need to convert for X8R8G8B8
     if (format_ == D3DFMT_X8R8G8B8)
         rowSize = rowSize / 3 * 4;
 
@@ -213,16 +213,16 @@ bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int wi
     return true;
 }
 
-bool TextureCube::SetData(CubeMapFace face, Deserializer& source)
+bool TextureCube::SetData_D3D9(CubeMapFace face, Deserializer& source)
 {
     SharedPtr<Image> image(new Image(context_));
     if (!image->Load(source))
         return false;
 
-    return SetData(face, image);
+    return SetData_D3D9(face, image);
 }
 
-bool TextureCube::SetData(CubeMapFace face, Image* image, bool useAlpha)
+bool TextureCube::SetData_D3D9(CubeMapFace face, Image* image, bool useAlpha)
 {
     if (!image)
     {
@@ -288,7 +288,7 @@ bool TextureCube::SetData(CubeMapFace face, Image* image, bool useAlpha)
         if (!face)
         {
             // If image was previously compressed, reset number of requested levels to avoid error if level count is too high for new size
-            if (IsCompressed() && requestedLevels_ > 1)
+            if (IsCompressed_D3D9() && requestedLevels_ > 1)
                 requestedLevels_ = 0;
             SetSize(levelWidth, format);
         }
@@ -308,7 +308,7 @@ bool TextureCube::SetData(CubeMapFace face, Image* image, bool useAlpha)
 
         for (unsigned i = 0; i < levels_; ++i)
         {
-            SetData(face, i, 0, 0, levelWidth, levelHeight, levelData);
+            SetData_D3D9(face, i, 0, 0, levelWidth, levelHeight, levelData);
             memoryUse += levelWidth * levelHeight * components;
 
             if (i < levels_ - 1)
@@ -373,14 +373,14 @@ bool TextureCube::SetData(CubeMapFace face, Image* image, bool useAlpha)
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
             if (!needDecompress)
             {
-                SetData(face, i, 0, 0, level.width_, level.height_, level.data_);
+                SetData_D3D9(face, i, 0, 0, level.width_, level.height_, level.data_);
                 memoryUse += level.rows_ * level.rowSize_;
             }
             else
             {
                 unsigned char* rgbaData = new unsigned char[level.width_ * level.height_ * 4];
                 level.Decompress(rgbaData);
-                SetData(face, i, 0, 0, level.width_, level.height_, rgbaData);
+                SetData_D3D9(face, i, 0, 0, level.width_, level.height_, rgbaData);
                 memoryUse += level.width_ * level.height_ * 4;
                 delete[] rgbaData;
             }
@@ -396,7 +396,7 @@ bool TextureCube::SetData(CubeMapFace face, Image* image, bool useAlpha)
     return true;
 }
 
-bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
+bool TextureCube::GetData_D3D9(CubeMapFace face, unsigned level, void* dest) const
 {
     if (!object_.ptr_)
     {
@@ -459,7 +459,7 @@ bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
             }
         }
 
-        IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
+        IDirect3DDevice9* device = graphics_->GetImpl_D3D9()->GetDevice();
         HRESULT hr = device->CreateOffscreenPlainSurface((UINT)width_, (UINT)height_, (D3DFORMAT)format_, D3DPOOL_SYSTEMMEM, &offscreenSurface, nullptr);
         if (FAILED(hr))
         {
@@ -499,12 +499,12 @@ bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
     }
 
     int height = levelHeight;
-    if (IsCompressed())
+    if (IsCompressed_D3D9())
         height = (height + 3) >> 2;
 
     unsigned char* destPtr = (unsigned char*)dest;
-    unsigned rowSize = GetRowDataSize(levelWidth);
-    // GetRowDataSize() returns CPU-side (destination) data size, so need to convert for X8R8G8B8
+    unsigned rowSize = GetRowDataSize_D3D9(levelWidth);
+    // GetRowDataSize_D3D9() returns CPU-side (destination) data size, so need to convert for X8R8G8B8
     if (format_ == D3DFMT_X8R8G8B8)
         rowSize = rowSize / 3 * 4;
 
@@ -560,9 +560,9 @@ bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
     return true;
 }
 
-bool TextureCube::Create()
+bool TextureCube::Create_D3D9()
 {
-    Release();
+    Release_D3D9();
 
     if (!graphics_ || !width_ || !height_)
         return false;
@@ -573,7 +573,7 @@ bool TextureCube::Create()
         return true;
     }
 
-    GraphicsImpl* impl = graphics_->GetImpl();
+    GraphicsImpl_D3D9* impl = graphics_->GetImpl_D3D9();
 
     unsigned pool = usage_ > TEXTURE_STATIC ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
     unsigned d3dUsage = 0;
@@ -604,7 +604,7 @@ bool TextureCube::Create()
     if (multiSample_ > 1)
     {
         // Fall back to non-multisampled if unsupported multisampling mode
-        GraphicsImpl* impl = graphics_->GetImpl();
+        GraphicsImpl_D3D9* impl = graphics_->GetImpl_D3D9();
         if (!impl->CheckMultiSampleSupport((D3DFORMAT)format_, multiSample_))
         {
             multiSample_ = 1;
@@ -612,7 +612,7 @@ bool TextureCube::Create()
         }
     }
 
-    IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
+    IDirect3DDevice9* device = graphics_->GetImpl_D3D9()->GetDevice();
     HRESULT hr = device->CreateCubeTexture(
         (UINT)width_,
         requestedLevels_,

+ 29 - 29
Source/Urho3D/Graphics/Direct3D9/D3D9VertexBuffer.cpp

@@ -23,39 +23,39 @@
 #include "../../Precompiled.h"
 
 #include "../../Graphics/Graphics.h"
-#include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/VertexBuffer.h"
 #include "../../IO/Log.h"
+#include "D3D9GraphicsImpl.h"
 
 #include "../../DebugNew.h"
 
 namespace Urho3D
 {
 
-void VertexBuffer::OnDeviceLost()
+void VertexBuffer::OnDeviceLost_D3D9()
 {
     // Dynamic buffers are in the default pool and need to be released on device loss
     if (dynamic_)
-        Release();
+        Release_D3D9();
 }
 
-void VertexBuffer::OnDeviceReset()
+void VertexBuffer::OnDeviceReset_D3D9()
 {
     // Dynamic buffers are in the default pool and need to be recreated after device reset
     if (dynamic_ || !object_.ptr_)
     {
-        Create();
-        dataLost_ = !UpdateToGPU();
+        Create_D3D9();
+        dataLost_ = !UpdateToGPU_D3D9();
     }
     else if (dataPending_)
-        dataLost_ = !UpdateToGPU();
+        dataLost_ = !UpdateToGPU_D3D9();
 
     dataPending_ = false;
 }
 
-void VertexBuffer::Release()
+void VertexBuffer::Release_D3D9()
 {
-    Unlock();
+    Unlock_D3D9();
 
     if (graphics_)
     {
@@ -69,7 +69,7 @@ void VertexBuffer::Release()
     URHO3D_SAFE_RELEASE(object_.ptr_);
 }
 
-bool VertexBuffer::SetData(const void* data)
+bool VertexBuffer::SetData_D3D9(const void* data)
 {
     if (!data)
     {
@@ -95,11 +95,11 @@ bool VertexBuffer::SetData(const void* data)
             return true;
         }
 
-        void* hwData = MapBuffer(0, vertexCount_, true);
+        void* hwData = MapBuffer_D3D9(0, vertexCount_, true);
         if (hwData)
         {
             memcpy(hwData, data, vertexCount_ * vertexSize_);
-            UnmapBuffer();
+            UnmapBuffer_D3D9();
         }
         else
             return false;
@@ -109,10 +109,10 @@ bool VertexBuffer::SetData(const void* data)
     return true;
 }
 
-bool VertexBuffer::SetDataRange(const void* data, unsigned start, unsigned count, bool discard)
+bool VertexBuffer::SetDataRange_D3D9(const void* data, unsigned start, unsigned count, bool discard)
 {
     if (start == 0 && count == vertexCount_)
-        return SetData(data);
+        return SetData_D3D9(data);
 
     if (!data)
     {
@@ -147,11 +147,11 @@ bool VertexBuffer::SetDataRange(const void* data, unsigned start, unsigned count
             return true;
         }
 
-        void* hwData = MapBuffer(start, count, discard);
+        void* hwData = MapBuffer_D3D9(start, count, discard);
         if (hwData)
         {
             memcpy(hwData, data, count * vertexSize_);
-            UnmapBuffer();
+            UnmapBuffer_D3D9();
         }
         else
             return false;
@@ -160,7 +160,7 @@ bool VertexBuffer::SetDataRange(const void* data, unsigned start, unsigned count
     return true;
 }
 
-void* VertexBuffer::Lock(unsigned start, unsigned count, bool discard)
+void* VertexBuffer::Lock_D3D9(unsigned start, unsigned count, bool discard)
 {
     if (lockState_ != LOCK_NONE)
     {
@@ -188,7 +188,7 @@ void* VertexBuffer::Lock(unsigned start, unsigned count, bool discard)
 
     // Because shadow data must be kept in sync, can only lock hardware buffer if not shadowed
     if (object_.ptr_ && !shadowData_ && !graphics_->IsDeviceLost())
-        return MapBuffer(start, count, discard);
+        return MapBuffer_D3D9(start, count, discard);
     else if (shadowData_)
     {
         lockState_ = LOCK_SHADOW;
@@ -204,21 +204,21 @@ void* VertexBuffer::Lock(unsigned start, unsigned count, bool discard)
         return nullptr;
 }
 
-void VertexBuffer::Unlock()
+void VertexBuffer::Unlock_D3D9()
 {
     switch (lockState_)
     {
     case LOCK_HARDWARE:
-        UnmapBuffer();
+        UnmapBuffer_D3D9();
         break;
 
     case LOCK_SHADOW:
-        SetDataRange(shadowData_.Get() + lockStart_ * vertexSize_, lockStart_, lockCount_);
+        SetDataRange_D3D9(shadowData_.Get() + lockStart_ * vertexSize_, lockStart_, lockCount_);
         lockState_ = LOCK_NONE;
         break;
 
     case LOCK_SCRATCH:
-        SetDataRange(lockScratchData_, lockStart_, lockCount_);
+        SetDataRange_D3D9(lockScratchData_, lockStart_, lockCount_);
         if (graphics_)
             graphics_->FreeScratchBuffer(lockScratchData_);
         lockScratchData_ = nullptr;
@@ -229,9 +229,9 @@ void VertexBuffer::Unlock()
     }
 }
 
-bool VertexBuffer::Create()
+bool VertexBuffer::Create_D3D9()
 {
-    Release();
+    Release_D3D9();
 
     if (!vertexCount_ || elements_.Empty())
         return true;
@@ -247,7 +247,7 @@ bool VertexBuffer::Create()
         unsigned pool = dynamic_ ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
         unsigned d3dUsage = dynamic_ ? D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY : 0;
 
-        IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
+        IDirect3DDevice9* device = graphics_->GetImpl_D3D9()->GetDevice();
         HRESULT hr = device->CreateVertexBuffer(
             vertexCount_ * vertexSize_,
             d3dUsage,
@@ -266,15 +266,15 @@ bool VertexBuffer::Create()
     return true;
 }
 
-bool VertexBuffer::UpdateToGPU()
+bool VertexBuffer::UpdateToGPU_D3D9()
 {
     if (object_.ptr_ && shadowData_)
-        return SetData(shadowData_.Get());
+        return SetData_D3D9(shadowData_.Get());
     else
         return false;
 }
 
-void* VertexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
+void* VertexBuffer::MapBuffer_D3D9(unsigned start, unsigned count, bool discard)
 {
     void* hwData = nullptr;
 
@@ -295,7 +295,7 @@ void* VertexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
     return hwData;
 }
 
-void VertexBuffer::UnmapBuffer()
+void VertexBuffer::UnmapBuffer_D3D9()
 {
     if (object_.ptr_ && lockState_ == LOCK_HARDWARE)
     {

+ 16 - 16
Source/Urho3D/Graphics/Direct3D9/D3D9VertexDeclaration.cpp

@@ -23,10 +23,10 @@
 #include "../../Precompiled.h"
 
 #include "../../Graphics/Graphics.h"
-#include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/VertexBuffer.h"
-#include "../../Graphics/VertexDeclaration.h"
 #include "../../IO/Log.h"
+#include "D3D9GraphicsImpl.h"
+#include "D3D9VertexDeclaration.h"
 
 #include "../../DebugNew.h"
 
@@ -57,10 +57,10 @@ const BYTE d3dElementUsage[] =
     D3DDECLUSAGE_TEXCOORD // Object index (not supported by D3D9)
 };
 
-VertexDeclaration::VertexDeclaration(Graphics* graphics, const PODVector<VertexElement>& srcElements) :
+VertexDeclaration_D3D9::VertexDeclaration_D3D9(Graphics* graphics, const PODVector<VertexElement>& srcElements) :
     declaration_(nullptr)
 {
-    PODVector<VertexDeclarationElement> elements;
+    PODVector<VertexDeclarationElement_D3D9> elements;
 
     for (unsigned i = 0; i < srcElements.Size(); ++i)
     {
@@ -72,7 +72,7 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, const PODVector<VertexE
             continue;
         }
 
-        VertexDeclarationElement element;
+        VertexDeclarationElement_D3D9 element;
         element.semantic_ = srcElement.semantic_;
         element.type_ = srcElement.type_;
         element.index_ = srcElement.index_;
@@ -84,10 +84,10 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, const PODVector<VertexE
     Create(graphics, elements);
 }
 
-VertexDeclaration::VertexDeclaration(Graphics* graphics, const PODVector<VertexBuffer*>& buffers) :
+VertexDeclaration_D3D9::VertexDeclaration_D3D9(Graphics* graphics, const PODVector<VertexBuffer*>& buffers) :
     declaration_(nullptr)
 {
-    PODVector<VertexDeclarationElement> elements;
+    PODVector<VertexDeclarationElement_D3D9> elements;
     unsigned prevBufferElements = 0;
 
     for (unsigned i = 0; i < buffers.Size(); ++i)
@@ -123,7 +123,7 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, const PODVector<VertexB
             if (isExisting)
                 continue;
 
-            VertexDeclarationElement element;
+            VertexDeclarationElement_D3D9 element;
             element.semantic_ = srcElement.semantic_;
             element.type_ = srcElement.type_;
             element.index_ = srcElement.index_;
@@ -138,10 +138,10 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, const PODVector<VertexB
     Create(graphics, elements);
 }
 
-VertexDeclaration::VertexDeclaration(Graphics* graphics, const Vector<SharedPtr<VertexBuffer> >& buffers) :
+VertexDeclaration_D3D9::VertexDeclaration_D3D9(Graphics* graphics, const Vector<SharedPtr<VertexBuffer> >& buffers) :
     declaration_(nullptr)
 {
-    PODVector<VertexDeclarationElement> elements;
+    PODVector<VertexDeclarationElement_D3D9> elements;
     unsigned prevBufferElements = 0;
 
     for (unsigned i = 0; i < buffers.Size(); ++i)
@@ -177,7 +177,7 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, const Vector<SharedPtr<
             if (isExisting)
                 continue;
 
-            VertexDeclarationElement element;
+            VertexDeclarationElement_D3D9 element;
             element.semantic_ = srcElement.semantic_;
             element.type_ = srcElement.type_;
             element.index_ = srcElement.index_;
@@ -192,17 +192,17 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, const Vector<SharedPtr<
     Create(graphics, elements);
 }
 
-VertexDeclaration::~VertexDeclaration()
+VertexDeclaration_D3D9::~VertexDeclaration_D3D9()
 {
     Release();
 }
 
-void VertexDeclaration::Create(Graphics* graphics, const PODVector<VertexDeclarationElement>& elements)
+void VertexDeclaration_D3D9::Create(Graphics* graphics, const PODVector<VertexDeclarationElement_D3D9>& elements)
 {
     SharedArrayPtr<D3DVERTEXELEMENT9> elementArray(new D3DVERTEXELEMENT9[elements.Size() + 1]);
 
     D3DVERTEXELEMENT9* dest = elementArray;
-    for (Vector<VertexDeclarationElement>::ConstIterator i = elements.Begin(); i != elements.End(); ++i)
+    for (Vector<VertexDeclarationElement_D3D9>::ConstIterator i = elements.Begin(); i != elements.End(); ++i)
     {
         dest->Stream = (WORD)i->streamIndex_;
         dest->Offset = (WORD)i->offset_;
@@ -220,7 +220,7 @@ void VertexDeclaration::Create(Graphics* graphics, const PODVector<VertexDeclara
     dest->Usage = 0;
     dest->UsageIndex = 0;
 
-    IDirect3DDevice9* device = graphics->GetImpl()->GetDevice();
+    IDirect3DDevice9* device = graphics->GetImpl_D3D9()->GetDevice();
     HRESULT hr = device->CreateVertexDeclaration(elementArray, &declaration_);
     if (FAILED(hr))
     {
@@ -229,7 +229,7 @@ void VertexDeclaration::Create(Graphics* graphics, const PODVector<VertexDeclara
     }
 }
 
-void VertexDeclaration::Release()
+void VertexDeclaration_D3D9::Release()
 {
     URHO3D_SAFE_RELEASE(declaration_);
 }

+ 7 - 7
Source/Urho3D/Graphics/Direct3D9/D3D9VertexDeclaration.h

@@ -35,7 +35,7 @@ class Graphics;
 class VertexBuffer;
 
 /// One element in a vertex declaration. In contrast to the VertexElement structure, takes into account the stream source index.
-struct VertexDeclarationElement
+struct VertexDeclarationElement_D3D9
 {
     /// Element type.
     VertexElementType type_;
@@ -50,24 +50,24 @@ struct VertexDeclarationElement
 };
 
 /// Vertex declaration.
-class URHO3D_API VertexDeclaration : public RefCounted
+class URHO3D_API VertexDeclaration_D3D9 : public RefCounted
 {
 public:
     /// Construct with a single buffer's vertex element list.
-    VertexDeclaration(Graphics* graphics, const PODVector<VertexElement>& srcElements);
+    VertexDeclaration_D3D9(Graphics* graphics, const PODVector<VertexElement>& srcElements);
     /// Construct with vertex buffers to base declaration on. Higher index buffers will override semantics on lower indices.
-    VertexDeclaration(Graphics* graphics, const PODVector<VertexBuffer*>& buffers);
+    VertexDeclaration_D3D9(Graphics* graphics, const PODVector<VertexBuffer*>& buffers);
     /// Construct with vertex buffers (shared pointer vector) to base declaration on. Higher index buffers will override semantics on lower indices.
-    VertexDeclaration(Graphics* graphics, const Vector<SharedPtr<VertexBuffer> >& buffers);
+    VertexDeclaration_D3D9(Graphics* graphics, const Vector<SharedPtr<VertexBuffer> >& buffers);
     /// Destruct.
-    ~VertexDeclaration();
+    ~VertexDeclaration_D3D9();
 
     /// Return Direct3D vertex declaration.
     IDirect3DVertexDeclaration9* GetDeclaration() const { return declaration_; }
 
 private:
     /// Create declaration.
-    void Create(Graphics* graphics, const PODVector<VertexDeclarationElement>& elements);
+    void Create(Graphics* graphics, const PODVector<VertexDeclarationElement_D3D9>& elements);
     /// Release declaration.
     void Release();
 

+ 9 - 9
Source/Urho3D/Graphics/GPUObject.cpp

@@ -33,11 +33,10 @@ namespace Urho3D
 GPUObject::GPUObject(Graphics* graphics) :
     graphics_(graphics)
 {
-#ifdef URHO3D_OPENGL
-    object_.name_ = 0;
-#else
-    object_.ptr_ = nullptr;
-#endif
+    if (Graphics::GetGAPI() == GAPI_OPENGL)
+        object_.name_ = 0;
+    else
+        object_.ptr_ = nullptr;
 
     if (graphics_)
         graphics->AddGPUObject(this);
@@ -51,10 +50,11 @@ GPUObject::~GPUObject()
 
 void GPUObject::OnDeviceLost()
 {
-#ifdef URHO3D_OPENGL
-    // On OpenGL the object has already been lost at this point; reset object name
-    object_.name_ = 0;
-#endif
+    if (Graphics::GetGAPI() == GAPI_OPENGL)
+    {
+        // On OpenGL the object has already been lost at this point; reset object name
+        object_.name_ = 0;
+    }
 }
 
 void GPUObject::OnDeviceReset()

+ 2034 - 4
Source/Urho3D/Graphics/Graphics.cpp

@@ -59,6 +59,16 @@
 
 #include "../DebugNew.h"
 
+#ifdef _WIN32
+// Prefer the high-performance GPU on switchable GPU systems
+#include <windows.h>
+extern "C"
+{
+    __declspec(dllexport) DWORD NvOptimusEnablement = 1;
+    __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
+}
+#endif
+
 namespace Urho3D
 {
 
@@ -89,7 +99,7 @@ void Graphics::SetWindowPosition(const IntVector2& position)
     if (window_)
         SDL_SetWindowPosition(window_, position.x_, position.y_);
     else
-        position_ = position; // Sets as initial position for OpenWindow()
+        position_ = position; // Sets as initial position for SDL_CreateWindow()
 }
 
 void Graphics::SetWindowPosition(int x, int y)
@@ -490,9 +500,8 @@ void Graphics::CreateWindowIcon()
 void Graphics::AdjustScreenMode(int& newWidth, int& newHeight, ScreenModeParams& params, bool& maximize) const
 {
     // High DPI is supported only for OpenGL backend
-#ifndef URHO3D_OPENGL
-    params.highDPI_ = false;
-#endif
+    if (Graphics::GetGAPI() != GAPI_OPENGL)
+        params.highDPI_ = false;
 
 #if defined(IOS) || defined(TVOS)
     // iOS and tvOS app always take the fullscreen (and with status bar hidden)
@@ -597,6 +606,2027 @@ void Graphics::OnScreenModeChanged()
     SendEvent(E_SCREENMODE, eventData);
 }
 
+Graphics::Graphics(Context* context, GAPI gapi)
+    : Object(context)
+{
+    Graphics::gapi = gapi;
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+    {
+        Constructor_OGL();
+        return;
+    }
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+    {
+        Constructor_D3D9();
+        return;
+    }
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+    {
+        Constructor_D3D11();
+        return;
+    }
+#endif
+}
+
+Graphics::~Graphics()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+    {
+        Destructor_OGL();
+        return;
+    }
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+    {
+        Destructor_D3D9();
+        return;
+    }
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+    {
+        Destructor_D3D11();
+        return;
+    }
+#endif
+}
+
+bool Graphics::SetScreenMode(int width, int height, const ScreenModeParams& params, bool maximize)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetScreenMode_OGL(width, height, params, maximize);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetScreenMode_D3D9(width, height, params, maximize);;
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetScreenMode_D3D11(width, height, params, maximize);;
+#endif
+}
+
+void Graphics::SetSRGB(bool enable)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetSRGB_OGL(enable);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetSRGB_D3D9(enable);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetSRGB_D3D11(enable);
+#endif
+}
+
+void Graphics::SetDither(bool enable)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetDither_OGL(enable);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetDither_D3D9(enable);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetDither_D3D11(enable);
+#endif
+}
+
+void Graphics::SetFlushGPU(bool enable)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetFlushGPU_OGL(enable);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetFlushGPU_D3D9(enable);;
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetFlushGPU_D3D11(enable);;
+#endif
+}
+
+void Graphics::SetForceGL2(bool enable)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetForceGL2_OGL(enable);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetForceGL2_D3D9(enable);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetForceGL2_D3D11(enable);
+#endif
+}
+
+void Graphics::Close()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Close_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Close_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Close_D3D11();
+#endif
+}
+
+bool Graphics::TakeScreenShot(Image& destImage)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return TakeScreenShot_OGL(destImage);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return TakeScreenShot_D3D9(destImage);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return TakeScreenShot_D3D11(destImage);
+#endif
+}
+
+bool Graphics::BeginFrame()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return BeginFrame_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return BeginFrame_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return BeginFrame_D3D11();
+#endif
+}
+
+void Graphics::EndFrame()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return EndFrame_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return EndFrame_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return EndFrame_D3D11();
+#endif
+}
+
+void Graphics::Clear(ClearTargetFlags flags, const Color& color, float depth, unsigned stencil)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Clear_OGL(flags, color, depth, stencil);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Clear_D3D9(flags, color, depth, stencil);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Clear_D3D11(flags, color, depth, stencil);
+#endif
+}
+
+bool Graphics::ResolveToTexture(Texture2D* destination, const IntRect& viewport)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return ResolveToTexture_OGL(destination, viewport);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return ResolveToTexture_D3D9(destination, viewport);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return ResolveToTexture_D3D11(destination, viewport);
+#endif
+}
+
+bool Graphics::ResolveToTexture(Texture2D* texture)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return ResolveToTexture_OGL(texture);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return ResolveToTexture_D3D9(texture);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return ResolveToTexture_D3D11(texture);
+#endif
+}
+
+bool Graphics::ResolveToTexture(TextureCube* texture)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return ResolveToTexture_OGL(texture);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return ResolveToTexture_D3D9(texture);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return ResolveToTexture_D3D11(texture);
+#endif
+}
+
+void Graphics::Draw(PrimitiveType type, unsigned vertexStart, unsigned vertexCount)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Draw_OGL(type, vertexStart, vertexCount);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Draw_D3D9(type, vertexStart, vertexCount);;
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Draw_D3D11(type, vertexStart, vertexCount);;
+#endif
+}
+
+void Graphics::Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Draw_OGL(type, indexStart, indexCount, minVertex, vertexCount);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Draw_D3D9(type, indexStart, indexCount, minVertex, vertexCount);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Draw_D3D11(type, indexStart, indexCount, minVertex, vertexCount);
+#endif
+}
+
+void Graphics::Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex, unsigned vertexCount)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Draw_OGL(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Draw_D3D9(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Draw_D3D11(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount);
+#endif
+}
+
+void Graphics::DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount, unsigned instanceCount)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return DrawInstanced_OGL(type, indexStart, indexCount, minVertex, vertexCount, instanceCount);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return DrawInstanced_D3D9(type, indexStart, indexCount, minVertex, vertexCount, instanceCount);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return DrawInstanced_D3D11(type, indexStart, indexCount, minVertex, vertexCount, instanceCount);
+#endif
+}
+
+void Graphics::DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex,
+    unsigned vertexCount, unsigned instanceCount)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return DrawInstanced_OGL(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount, instanceCount);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return DrawInstanced_D3D9(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount, instanceCount);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return DrawInstanced_D3D11(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount, instanceCount);
+#endif
+}
+
+void Graphics::SetVertexBuffer(VertexBuffer* buffer)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetVertexBuffer_OGL(buffer);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetVertexBuffer_D3D9(buffer);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetVertexBuffer_D3D11(buffer);
+#endif
+}
+
+bool Graphics::SetVertexBuffers(const PODVector<VertexBuffer*>& buffers, unsigned instanceOffset)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetVertexBuffers_OGL(buffers, instanceOffset);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetVertexBuffers_D3D9(buffers, instanceOffset);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetVertexBuffers_D3D11(buffers, instanceOffset);
+#endif
+}
+
+bool Graphics::SetVertexBuffers(const Vector<SharedPtr<VertexBuffer> >& buffers, unsigned instanceOffset)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetVertexBuffers_OGL(buffers, instanceOffset);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetVertexBuffers_D3D9(buffers, instanceOffset);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetVertexBuffers_D3D11(buffers, instanceOffset);
+#endif
+}
+
+void Graphics::SetIndexBuffer(IndexBuffer* buffer)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetIndexBuffer_OGL(buffer);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetIndexBuffer_D3D9(buffer);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetIndexBuffer_D3D11(buffer);
+#endif
+}
+
+void Graphics::SetShaders(ShaderVariation* vs, ShaderVariation* ps)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetShaders_OGL(vs, ps);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetShaders_D3D9(vs, ps);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetShaders_D3D11(vs, ps);
+#endif
+}
+
+void Graphics::SetShaderParameter(StringHash param, const float* data, unsigned count)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetShaderParameter_OGL(param, data, count);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetShaderParameter_D3D9(param, data, count);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetShaderParameter_D3D11(param, data, count);
+#endif
+}
+
+void Graphics::SetShaderParameter(StringHash param, float value)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetShaderParameter_OGL(param, value);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetShaderParameter_D3D9(param, value);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetShaderParameter_D3D11(param, value);
+#endif
+}
+
+void Graphics::SetShaderParameter(StringHash param, int value)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetShaderParameter_OGL(param, value);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetShaderParameter_D3D9(param, value);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetShaderParameter_D3D11(param, value);
+#endif
+}
+
+void Graphics::SetShaderParameter(StringHash param, bool value)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetShaderParameter_OGL(param, value);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetShaderParameter_D3D9(param, value);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetShaderParameter_D3D11(param, value);
+#endif
+}
+
+void Graphics::SetShaderParameter(StringHash param, const Color& color)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetShaderParameter_OGL(param, color);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetShaderParameter_D3D9(param, color);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetShaderParameter_D3D11(param, color);
+#endif
+}
+
+void Graphics::SetShaderParameter(StringHash param, const Vector2& vector)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetShaderParameter_OGL(param, vector);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetShaderParameter_D3D9(param, vector);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetShaderParameter_D3D11(param, vector);
+#endif
+}
+
+void Graphics::SetShaderParameter(StringHash param, const Matrix3& matrix)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetShaderParameter_OGL(param, matrix);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetShaderParameter_D3D9(param, matrix);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetShaderParameter_D3D11(param, matrix);
+#endif
+}
+
+void Graphics::SetShaderParameter(StringHash param, const Vector3& vector)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetShaderParameter_OGL(param, vector);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetShaderParameter_D3D9(param, vector);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetShaderParameter_D3D11(param, vector);
+#endif
+}
+
+void Graphics::SetShaderParameter(StringHash param, const Matrix4& matrix)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetShaderParameter_OGL(param, matrix);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetShaderParameter_D3D9(param, matrix);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetShaderParameter_D3D11(param, matrix);
+#endif
+}
+
+void Graphics::SetShaderParameter(StringHash param, const Vector4& vector)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetShaderParameter_OGL(param, vector);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetShaderParameter_D3D9(param, vector);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetShaderParameter_D3D11(param, vector);
+#endif
+}
+
+void Graphics::SetShaderParameter(StringHash param, const Matrix3x4& matrix)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetShaderParameter_OGL(param, matrix);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetShaderParameter_D3D9(param, matrix);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetShaderParameter_D3D11(param, matrix);
+#endif
+}
+
+bool Graphics::NeedParameterUpdate(ShaderParameterGroup group, const void* source)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return NeedParameterUpdate_OGL(group, source);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return NeedParameterUpdate_D3D9(group, source);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return NeedParameterUpdate_D3D11(group, source);
+#endif
+}
+
+bool Graphics::HasShaderParameter(StringHash param)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return HasShaderParameter_OGL(param);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return HasShaderParameter_D3D9(param);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return HasShaderParameter_D3D11(param);
+#endif
+}
+
+bool Graphics::HasTextureUnit(TextureUnit unit)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return HasTextureUnit_OGL(unit);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return HasTextureUnit_D3D9(unit);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return HasTextureUnit_D3D11(unit);
+#endif
+}
+
+void Graphics::ClearParameterSource(ShaderParameterGroup group)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return ClearParameterSource_OGL(group);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return ClearParameterSource_D3D9(group);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return ClearParameterSource_D3D11(group);
+#endif
+}
+
+void Graphics::ClearParameterSources()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return ClearParameterSources_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return ClearParameterSources_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return ClearParameterSources_D3D11();
+#endif
+}
+
+void Graphics::ClearTransformSources()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return ClearTransformSources_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return ClearTransformSources_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return ClearTransformSources_D3D11();
+#endif
+}
+
+void Graphics::SetTexture(unsigned index, Texture* texture)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetTexture_OGL(index, texture);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetTexture_D3D9(index, texture);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetTexture_D3D11(index, texture);
+#endif
+}
+
+void Graphics::SetDefaultTextureFilterMode(TextureFilterMode mode)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetDefaultTextureFilterMode_OGL(mode);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetDefaultTextureFilterMode_D3D9(mode);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetDefaultTextureFilterMode_D3D11(mode);
+#endif
+}
+
+void Graphics::SetDefaultTextureAnisotropy(unsigned level)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetDefaultTextureAnisotropy_OGL(level);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetDefaultTextureAnisotropy_D3D9(level);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetDefaultTextureAnisotropy_D3D11(level);
+#endif
+}
+
+void Graphics::ResetRenderTargets()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return ResetRenderTargets_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return ResetRenderTargets_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return ResetRenderTargets_D3D11();
+#endif
+}
+
+void Graphics::ResetRenderTarget(unsigned index)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return ResetRenderTarget_OGL(index);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return ResetRenderTarget_D3D9(index);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return ResetRenderTarget_D3D11(index);
+#endif
+}
+
+void Graphics::ResetDepthStencil()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return ResetDepthStencil_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return ResetDepthStencil_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return ResetDepthStencil_D3D11();
+#endif
+}
+
+void Graphics::SetRenderTarget(unsigned index, RenderSurface* renderTarget)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetRenderTarget_OGL(index, renderTarget);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetRenderTarget_D3D9(index, renderTarget);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetRenderTarget_D3D11(index, renderTarget);
+#endif
+}
+
+void Graphics::SetRenderTarget(unsigned index, Texture2D* texture)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetRenderTarget_OGL(index, texture);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetRenderTarget_D3D9(index, texture);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetRenderTarget_D3D11(index, texture);
+#endif
+}
+
+void Graphics::SetDepthStencil(RenderSurface* depthStencil)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetDepthStencil_OGL(depthStencil);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetDepthStencil_D3D9(depthStencil);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetDepthStencil_D3D11(depthStencil);
+#endif
+}
+
+void Graphics::SetDepthStencil(Texture2D* texture)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetDepthStencil_OGL(texture);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetDepthStencil_D3D9(texture);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetDepthStencil_D3D11(texture);
+#endif
+}
+
+void Graphics::SetViewport(const IntRect& rect)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetViewport_OGL(rect);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetViewport_D3D9(rect);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetViewport_D3D11(rect);
+#endif
+}
+
+void Graphics::SetBlendMode(BlendMode mode, bool alphaToCoverage)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetBlendMode_OGL(mode, alphaToCoverage);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetBlendMode_D3D9(mode, alphaToCoverage);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetBlendMode_D3D11(mode, alphaToCoverage);
+#endif
+}
+
+void Graphics::SetColorWrite(bool enable)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetColorWrite_OGL(enable);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetColorWrite_D3D9(enable);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetColorWrite_D3D11(enable);
+#endif
+}
+
+void Graphics::SetCullMode(CullMode mode)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetCullMode_OGL(mode);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetCullMode_D3D9(mode);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetCullMode_D3D11(mode);
+#endif
+}
+
+void Graphics::SetDepthBias(float constantBias, float slopeScaledBias)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetDepthBias_OGL(constantBias, slopeScaledBias);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetDepthBias_D3D9(constantBias, slopeScaledBias);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetDepthBias_D3D11(constantBias, slopeScaledBias);
+#endif
+}
+
+void Graphics::SetDepthTest(CompareMode mode)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetDepthTest_OGL(mode);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetDepthTest_D3D9(mode);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetDepthTest_D3D11(mode);
+#endif
+}
+
+void Graphics::SetDepthWrite(bool enable)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetDepthWrite_OGL(enable);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetDepthWrite_D3D9(enable);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetDepthWrite_D3D11(enable);
+#endif
+}
+
+void Graphics::SetFillMode(FillMode mode)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetFillMode_OGL(mode);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetFillMode_D3D9(mode);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetFillMode_D3D11(mode);
+#endif
+}
+
+void Graphics::SetLineAntiAlias(bool enable)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetLineAntiAlias_OGL(enable);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetLineAntiAlias_D3D9(enable);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetLineAntiAlias_D3D11(enable);
+#endif
+}
+
+void Graphics::SetScissorTest(bool enable, const Rect& rect, bool borderInclusive)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetScissorTest_OGL(enable, rect, borderInclusive);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetScissorTest_D3D9(enable, rect, borderInclusive);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetScissorTest_D3D11(enable, rect, borderInclusive);
+#endif
+}
+
+void Graphics::SetScissorTest(bool enable, const IntRect& rect)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetScissorTest_OGL(enable, rect);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetScissorTest_D3D9(enable, rect);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetScissorTest_D3D11(enable, rect);
+#endif
+}
+
+void Graphics::SetClipPlane(bool enable, const Plane& clipPlane, const Matrix3x4& view, const Matrix4& projection)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetClipPlane_OGL(enable, clipPlane, view, projection);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetClipPlane_D3D9(enable, clipPlane, view, projection);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetClipPlane_D3D11(enable, clipPlane, view, projection);
+#endif
+}
+
+void Graphics::SetStencilTest(bool enable, CompareMode mode, StencilOp pass, StencilOp fail, StencilOp zFail, unsigned stencilRef,
+    unsigned compareMask, unsigned writeMask)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetStencilTest_OGL(enable, mode, pass, fail, zFail, stencilRef, compareMask, writeMask);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetStencilTest_D3D9(enable, mode, pass, fail, zFail, stencilRef, compareMask, writeMask);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetStencilTest_D3D11(enable, mode, pass, fail, zFail, stencilRef, compareMask, writeMask);
+#endif
+}
+
+bool Graphics::IsInitialized() const
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return IsInitialized_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return IsInitialized_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return IsInitialized_D3D11();
+#endif
+}
+
+bool Graphics::GetDither() const
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetDither_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetDither_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetDither_D3D11();
+#endif
+}
+
+bool Graphics::IsDeviceLost() const
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return IsDeviceLost_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return IsDeviceLost_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return IsDeviceLost_D3D11();
+#endif
+}
+
+PODVector<int> Graphics::GetMultiSampleLevels() const
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetMultiSampleLevels_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetMultiSampleLevels_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetMultiSampleLevels_D3D11();
+#endif
+}
+
+unsigned Graphics::GetFormat(CompressedFormat format) const
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetFormat_OGL(format);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetFormat_D3D9(format);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetFormat_D3D11(format);
+#endif
+}
+
+ShaderVariation* Graphics::GetShader(ShaderType type, const String& name, const String& defines) const
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetShader_OGL(type, name, defines);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetShader_D3D9(type, name, defines);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetShader_D3D11(type, name, defines);
+#endif
+}
+
+ShaderVariation* Graphics::GetShader(ShaderType type, const char* name, const char* defines) const
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetShader_OGL(type, name, defines);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetShader_D3D9(type, name, defines);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetShader_D3D11(type, name, defines);
+#endif
+}
+
+VertexBuffer* Graphics::GetVertexBuffer(unsigned index) const
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetVertexBuffer_OGL(index);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetVertexBuffer_D3D9(index);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetVertexBuffer_D3D11(index);
+#endif
+}
+
+TextureUnit Graphics::GetTextureUnit(const String& name)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetTextureUnit_OGL(name);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetTextureUnit_D3D9(name);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetTextureUnit_D3D11(name);
+#endif
+}
+
+const String& Graphics::GetTextureUnitName(TextureUnit unit)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetTextureUnitName_OGL(unit);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetTextureUnitName_D3D9(unit);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetTextureUnitName_D3D11(unit);
+#endif
+}
+
+Texture* Graphics::GetTexture(unsigned index) const
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetTexture_OGL(index);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetTexture_D3D9(index);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetTexture_D3D11(index);
+#endif
+}
+
+RenderSurface* Graphics::GetRenderTarget(unsigned index) const
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetRenderTarget_OGL(index);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetRenderTarget_D3D9(index);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetRenderTarget_D3D11(index);
+#endif
+}
+
+IntVector2 Graphics::GetRenderTargetDimensions() const
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetRenderTargetDimensions_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetRenderTargetDimensions_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetRenderTargetDimensions_D3D11();
+#endif
+}
+
+void Graphics::OnWindowResized()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return OnWindowResized_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return OnWindowResized_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return OnWindowResized_D3D11();
+#endif
+}
+
+void Graphics::OnWindowMoved()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return OnWindowMoved_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return OnWindowMoved_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return OnWindowMoved_D3D11();
+#endif
+}
+
+ConstantBuffer* Graphics::GetOrCreateConstantBuffer(ShaderType type, unsigned index, unsigned size)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetOrCreateConstantBuffer_OGL(type, index, size);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetOrCreateConstantBuffer_D3D9(type, index, size);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetOrCreateConstantBuffer_D3D11(type, index, size);
+#endif
+}
+
+unsigned Graphics::GetMaxBones()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetMaxBones_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetMaxBones_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetMaxBones_D3D11();
+#endif
+}
+
+bool Graphics::GetGL3Support()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetGL3Support_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetGL3Support_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetGL3Support_D3D11();
+#endif
+}
+
+unsigned Graphics::GetAlphaFormat()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetAlphaFormat_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetAlphaFormat_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetAlphaFormat_D3D11();
+#endif
+}
+
+unsigned Graphics::GetLuminanceFormat()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetLuminanceFormat_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetLuminanceFormat_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetLuminanceFormat_D3D11();
+#endif
+}
+
+unsigned Graphics::GetLuminanceAlphaFormat()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetLuminanceAlphaFormat_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetLuminanceAlphaFormat_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetLuminanceAlphaFormat_D3D11();
+#endif
+}
+
+unsigned Graphics::GetRGBFormat()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetRGBFormat_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetRGBFormat_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetRGBFormat_D3D11();
+#endif
+}
+
+unsigned Graphics::GetRGBAFormat()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetRGBAFormat_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetRGBAFormat_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetRGBAFormat_D3D11();
+#endif
+}
+
+unsigned Graphics::GetRGBA16Format()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetRGBA16Format_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetRGBA16Format_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetRGBA16Format_D3D11();
+#endif
+}
+
+unsigned Graphics::GetRGBAFloat16Format()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetRGBAFloat16Format_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetRGBAFloat16Format_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetRGBAFloat16Format_D3D11();
+#endif
+}
+
+unsigned Graphics::GetRGBAFloat32Format()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetRGBAFloat32Format_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetRGBAFloat32Format_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetRGBAFloat32Format_D3D11();
+#endif
+}
+
+unsigned Graphics::GetRG16Format()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetRG16Format_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetRG16Format_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetRG16Format_D3D11();
+#endif
+}
+
+unsigned Graphics::GetRGFloat16Format()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetRGFloat16Format_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetRGFloat16Format_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetRGFloat16Format_D3D11();
+#endif
+}
+
+unsigned Graphics::GetRGFloat32Format()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetRGFloat32Format_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetRGFloat32Format_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetRGFloat32Format_D3D11();
+#endif
+}
+
+unsigned Graphics::GetFloat16Format()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetFloat16Format_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetFloat16Format_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetFloat16Format_D3D11();
+#endif
+}
+
+unsigned Graphics::GetFloat32Format()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetFloat32Format_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetFloat32Format_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetFloat32Format_D3D11();
+#endif
+}
+
+unsigned Graphics::GetLinearDepthFormat()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetLinearDepthFormat_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetLinearDepthFormat_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetLinearDepthFormat_D3D11();
+#endif
+}
+
+unsigned Graphics::GetDepthStencilFormat()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetDepthStencilFormat_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetDepthStencilFormat_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetDepthStencilFormat_D3D11();
+#endif
+}
+
+unsigned Graphics::GetReadableDepthFormat()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetReadableDepthFormat_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetReadableDepthFormat_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetReadableDepthFormat_D3D11();
+#endif
+}
+
+unsigned Graphics::GetFormat(const String& formatName)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetFormat_OGL(formatName);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetFormat_D3D9(formatName);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetFormat_D3D11(formatName);
+#endif
+}
+
 void RegisterGraphicsLibrary(Context* context)
 {
     Animation::RegisterObject(context);

+ 522 - 64
Source/Urho3D/Graphics/Graphics.h

@@ -43,11 +43,9 @@ class File;
 class Image;
 class IndexBuffer;
 class GPUObject;
-class GraphicsImpl;
 class RenderSurface;
 class Shader;
 class ShaderPrecache;
-class ShaderProgram;
 class ShaderVariation;
 class Texture;
 class Texture2D;
@@ -56,10 +54,37 @@ class TextureCube;
 class Vector3;
 class Vector4;
 class VertexBuffer;
-class VertexDeclaration;
+
+#ifdef URHO3D_OPENGL
+class GraphicsImpl_OGL;
+#endif
+
+#ifdef URHO3D_D3D9
+class GraphicsImpl_D3D9;
+#endif
+
+#ifdef URHO3D_D3D11
+class GraphicsImpl_D3D11;
+#endif
 
 struct ShaderParameter;
 
+#ifdef URHO3D_OPENGL
+// Note: ShaderProgram_OGL class is purposefully API-specific. It should not be used by Urho3D client applications.
+class ShaderProgram_OGL;
+#endif
+
+#ifdef URHO3D_D3D9
+// Note: ShaderProgram_D3D9 class is purposefully API-specific. It should not be used by Urho3D client applications.
+class ShaderProgram_D3D9;
+#endif
+
+#ifdef URHO3D_D3D11
+// Note: ShaderProgram_D3D11 class is purposefully API-specific. It should not be used by Urho3D client applications.
+class ShaderProgram_D3D11;
+#endif
+
+
 /// CPU-side scratch buffer for vertex data updates.
 struct ScratchBuffer
 {
@@ -142,7 +167,7 @@ class URHO3D_API Graphics : public Object
 
 public:
     /// Construct.
-    explicit Graphics(Context* context);
+    explicit Graphics(Context* context, GAPI gapi);
     /// Destruct. Release the Direct3D11 device and close the window.
     ~Graphics() override;
 
@@ -268,12 +293,6 @@ public:
     void ClearTransformSources();
     /// Set texture.
     void SetTexture(unsigned index, Texture* texture);
-    /// Bind texture unit 0 for update. Called by Texture. Used only on OpenGL.
-    /// @nobind
-    void SetTextureForUpdate(Texture* texture);
-    /// Dirty texture parameters of all textures (when global settings change.)
-    /// @nobind
-    void SetTextureParametersDirty();
     /// Set default texture filtering mode. Called by Renderer before rendering.
     void SetDefaultTextureFilterMode(TextureFilterMode mode);
     /// Set default texture anisotropy level. Called by Renderer before rendering.
@@ -335,8 +354,32 @@ public:
     /// @property
     bool IsInitialized() const;
 
+#ifdef URHO3D_OPENGL
+    /// Return graphics implementation, which holds the actual API-specific resources.
+    GraphicsImpl_OGL* GetImpl_OGL() const
+    {
+        assert(Graphics::GetGAPI() == GAPI_OPENGL);
+        return (GraphicsImpl_OGL*)impl_;
+    }
+#endif
+
+#ifdef URHO3D_D3D9
+    /// Return graphics implementation, which holds the actual API-specific resources.
+    GraphicsImpl_D3D9* GetImpl_D3D9() const
+    {
+        assert(Graphics::GetGAPI() == GAPI_D3D9);
+        return (GraphicsImpl_D3D9*)impl_;
+    }
+#endif
+
+#ifdef URHO3D_D3D11
     /// Return graphics implementation, which holds the actual API-specific resources.
-    GraphicsImpl* GetImpl() const { return impl_; }
+    GraphicsImpl_D3D11* GetImpl_D3D11() const
+    {
+        assert(Graphics::GetGAPI() == GAPI_D3D11);
+        return (GraphicsImpl_D3D11*)impl_;
+    }
+#endif
 
     /// Return OS-specific external window handle. Null if not in use.
     void* GetExternalWindow() const { return externalWindow_; }
@@ -408,7 +451,7 @@ public:
     /// @property
     bool GetSRGB() const { return sRGB_; }
 
-    /// Return whether rendering output is dithered.
+    /// Return whether rendering output is dithered. Always false on Direct3D.
     /// @property
     bool GetDither() const;
 
@@ -517,9 +560,32 @@ public:
     /// Return current pixel shader.
     ShaderVariation* GetPixelShader() const { return pixelShader_; }
 
+#ifdef URHO3D_OPENGL
+    // Note: ShaderProgram_OGL class is purposefully API-specific. It should not be used by Urho3D client applications.
+
     /// Return shader program. This is an API-specific class and should not be used by applications.
-    /// @nobind
-    ShaderProgram* GetShaderProgram() const;
+    ShaderProgram_OGL* GetShaderProgram_OGL() const;
+
+    /// Clean up shader parameters when a shader variation is released or destroyed.
+    void CleanupShaderPrograms_OGL(ShaderVariation* variation);
+#endif
+
+#ifdef URHO3D_D3D9
+    // Note: ShaderProgram_D3D9 class is purposefully API-specific. It should not be used by Urho3D client applications.
+
+    /// Clean up shader parameters when a shader variation is released or destroyed.
+    void CleanupShaderPrograms_D3D9(ShaderVariation* variation);
+#endif
+
+#ifdef URHO3D_D3D11
+    // Note: ShaderProgram_D3D11 class is purposefully API-specific. It should not be used by Urho3D client applications.
+
+    /// Return shader program. This is an API-specific class and should not be used by applications.
+    ShaderProgram_D3D11* GetShaderProgram_D3D11() const;
+
+    /// Clean up shader parameters when a shader variation is released or destroyed.
+    void CleanupShaderPrograms_D3D11(ShaderVariation* variation);
+#endif
 
     /// Return texture unit index by name.
     TextureUnit GetTextureUnit(const String& name);
@@ -617,9 +683,27 @@ public:
     void OnWindowResized();
     /// Window was moved through user interaction. Called by Input subsystem.
     void OnWindowMoved();
+
+#ifdef URHO3D_OPENGL
     /// Restore GPU objects and reinitialize state. Requires an open window. Used only on OpenGL.
-    /// @nobind
-    void Restore();
+    void Restore_OGL();
+    
+    /// Mark the FBO needing an update. Used only on OpenGL.
+    void MarkFBODirty_OGL();
+    
+    /// Bind a VBO, avoiding redundant operation. Used only on OpenGL.
+    void SetVBO_OGL(unsigned object);
+    
+    /// Bind a UBO, avoiding redundant operation. Used only on OpenGL.
+    void SetUBO_OGL(unsigned object);
+
+    /// Clean up a render surface from all FBOs. Used only on OpenGL.
+    void CleanupRenderSurface_OGL(RenderSurface* surface);
+
+    /// Bind texture unit 0 for update. Called by Texture. Used only on OpenGL.
+    void SetTextureForUpdate_OGL(Texture* texture);
+#endif // def URHO3D_OPENGL
+
     /// Maximize the window.
     void Maximize();
     /// Minimize the window.
@@ -636,23 +720,13 @@ public:
     void FreeScratchBuffer(void* buffer);
     /// Clean up too large scratch buffers.
     void CleanupScratchBuffers();
-    /// Clean up shader parameters when a shader variation is released or destroyed.
-    void CleanupShaderPrograms(ShaderVariation* variation);
-    /// Clean up a render surface from all FBOs. Used only on OpenGL.
-    /// @nobind
-    void CleanupRenderSurface(RenderSurface* surface);
-    /// Get or create a constant buffer. Will be shared between shaders if possible.
+
+    /// Get or create a constant buffer. Will be shared between shaders if possible. Used only on OpenGL and DirectX 11.
     /// @nobind
     ConstantBuffer* GetOrCreateConstantBuffer(ShaderType type, unsigned index, unsigned size);
-    /// Mark the FBO needing an update. Used only on OpenGL.
-    /// @nobind
-    void MarkFBODirty();
-    /// Bind a VBO, avoiding redundant operation. Used only on OpenGL.
-    /// @nobind
-    void SetVBO(unsigned object);
-    /// Bind a UBO, avoiding redundant operation. Used only on OpenGL.
-    /// @nobind
-    void SetUBO(unsigned object);
+
+    /// Get used graphics API.
+    static GAPI GetGAPI() { return gapi; }
 
     /// Return the API-specific alpha texture format.
     static unsigned GetAlphaFormat();
@@ -698,69 +772,450 @@ public:
     static bool GetGL3Support();
 
 private:
-    /// Create the application window.
-    bool OpenWindow(int width, int height, bool resizable, bool borderless);
     /// Create the application window icon.
     void CreateWindowIcon();
+
     /// Adjust parameters according to the platform. Fill in missing paramters and resolve possible conflicts.
     void AdjustScreenMode(int& newWidth, int& newHeight, ScreenModeParams& params, bool& maximize) const;
+
     /// Called when screen mode is successfully changed by the backend.
     void OnScreenModeChanged();
+
+#ifdef URHO3D_D3D11
+    /// Create the application window.
+    bool OpenWindow_D3D11(int width, int height, bool resizable, bool borderless);
+
     /// Adjust the window for new resolution and fullscreen mode.
-    void AdjustWindow(int& newWidth, int& newHeight, bool& newFullscreen, bool& newBorderless, int& monitor);
+    void AdjustWindow_D3D11(int& newWidth, int& newHeight, bool& newFullscreen, bool& newBorderless, int& monitor);
+
     /// Create the Direct3D11 device and swap chain. Requires an open window. Can also be called again to recreate swap chain. Return true on success.
-    bool CreateDevice(int width, int height);
+    bool CreateDevice_D3D11(int width, int height);
+
     /// Update Direct3D11 swap chain state for a new mode and create views for the backbuffer & default depth buffer. Return true on success.
-    bool UpdateSwapChain(int width, int height);
+    bool UpdateSwapChain_D3D11(int width, int height);
+
+    /// Create intermediate texture for multisampled backbuffer resolve. No-op if already exists.
+    void CreateResolveTexture_D3D11();
+
+    /// Process dirtied state before draw.
+    void PrepareDraw_D3D11();
+
+    /// Check supported rendering features.
+    void CheckFeatureSupport_D3D11();
+    
+    /// Reset cached rendering state.
+    void ResetCachedState_D3D11();
+
+    /// Initialize texture unit mappings.
+    void SetTextureUnitMappings_D3D11();
+
+    /// Dirty texture parameters of all textures (when global settings change). Used on OpenGL and DirectX 11.
+    void SetTextureParametersDirty_D3D11();
+#endif // def URHO3D_D3D11
+
+#ifdef URHO3D_D3D9
+    /// Create the application window.
+    bool OpenWindow_D3D9(int width, int height, bool resizable, bool borderless);
+
+    /// Adjust the window for new resolution and fullscreen mode.
+    void AdjustWindow_D3D9(int& newWidth, int& newHeight, bool& newFullscreen, bool& newBorderless, int& monitor);
+
     /// Create the Direct3D9 interface.
-    bool CreateInterface();
+    bool CreateInterface_D3D9();
+
     /// Create the Direct3D9 device.
-    bool CreateDevice(unsigned adapter, unsigned deviceType);
+    bool CreateDevice_D3D9(unsigned adapter, unsigned deviceType);
+
     /// Reset the Direct3D9 device.
-    void ResetDevice();
+    void ResetDevice_D3D9();
+
     /// Notify all GPU resources so they can release themselves as needed. Used only on Direct3D9.
-    void OnDeviceLost();
+    void OnDeviceLost_D3D9();
+
     /// Notify all GPU resources so they can recreate themselves as needed. Used only on Direct3D9.
-    void OnDeviceReset();
+    void OnDeviceReset_D3D9();
+
     /// Set vertex buffer stream frequency. Used only on Direct3D9.
-    void SetStreamFrequency(unsigned index, unsigned frequency);
+    void SetStreamFrequency_D3D9(unsigned index, unsigned frequency);
+
     /// Reset stream frequencies. Used only on Direct3D9.
-    void ResetStreamFrequencies();
+    void ResetStreamFrequencies_D3D9();
+
     /// Check supported rendering features.
-    void CheckFeatureSupport();
+    void CheckFeatureSupport_D3D9();
+    
     /// Reset cached rendering state.
-    void ResetCachedState();
+    void ResetCachedState_D3D9();
+    
     /// Initialize texture unit mappings.
-    void SetTextureUnitMappings();
-    /// Process dirtied state before draw.
-    void PrepareDraw();
-    /// Create intermediate texture for multisampled backbuffer resolve. No-op if already exists.
-    void CreateResolveTexture();
+    void SetTextureUnitMappings_D3D9();
+#endif // def URHO3D_D3D9
+
+#ifdef URHO3D_OPENGL
     /// Clean up all framebuffers. Called when destroying the context. Used only on OpenGL.
-    void CleanupFramebuffers();
+    void CleanupFramebuffers_OGL();
+    
     /// Create a framebuffer using either extension or core functionality. Used only on OpenGL.
-    unsigned CreateFramebuffer();
+    unsigned CreateFramebuffer_OGL();
+    
     /// Delete a framebuffer using either extension or core functionality. Used only on OpenGL.
-    void DeleteFramebuffer(unsigned fbo);
+    void DeleteFramebuffer_OGL(unsigned fbo);
+    
     /// Bind a framebuffer using either extension or core functionality. Used only on OpenGL.
-    void BindFramebuffer(unsigned fbo);
+    void BindFramebuffer_OGL(unsigned fbo);
+    
     /// Bind a framebuffer color attachment using either extension or core functionality. Used only on OpenGL.
-    void BindColorAttachment(unsigned index, unsigned target, unsigned object, bool isRenderBuffer);
+    void BindColorAttachment_OGL(unsigned index, unsigned target, unsigned object, bool isRenderBuffer);
+    
     /// Bind a framebuffer depth attachment using either extension or core functionality. Used only on OpenGL.
-    void BindDepthAttachment(unsigned object, bool isRenderBuffer);
+    void BindDepthAttachment_OGL(unsigned object, bool isRenderBuffer);
+    
     /// Bind a framebuffer stencil attachment using either extension or core functionality. Used only on OpenGL.
-    void BindStencilAttachment(unsigned object, bool isRenderBuffer);
+    void BindStencilAttachment_OGL(unsigned object, bool isRenderBuffer);
+    
     /// Check FBO completeness using either extension or core functionality. Used only on OpenGL.
-    bool CheckFramebuffer();
+    bool CheckFramebuffer_OGL();
+    
     /// Set vertex attrib divisor. No-op if unsupported. Used only on OpenGL.
-    void SetVertexAttribDivisor(unsigned location, unsigned divisor);
+    void SetVertexAttribDivisor_OGL(unsigned location, unsigned divisor);
+    
     /// Release/clear GPU objects and optionally close the window. Used only on OpenGL.
-    void Release(bool clearGPUObjects, bool closeWindow);
+    void Release_OGL(bool clearGPUObjects, bool closeWindow);
+
+    /// Process dirtied state before draw.
+    void PrepareDraw_OGL();
+
+    /// Check supported rendering features.
+    void CheckFeatureSupport_OGL();
+    
+    /// Reset cached rendering state.
+    void ResetCachedState_OGL();
+    
+    /// Initialize texture unit mappings.
+    void SetTextureUnitMappings_OGL();
+
+    /// Dirty texture parameters of all textures (when global settings change). Used on OpenGL and DirectX 11.
+    void SetTextureParametersDirty_OGL();
+#endif // def URHO3D_OPENGL
+
+    // For proxy functions
+
+#ifdef URHO3D_OPENGL
+    void Constructor_OGL();
+    void Destructor_OGL();
+    bool SetScreenMode_OGL(int width, int height, const ScreenModeParams& params, bool maximize);
+    void SetSRGB_OGL(bool enable);
+    void SetDither_OGL(bool enable);
+    void SetFlushGPU_OGL(bool enable);
+    void SetForceGL2_OGL(bool enable);
+    void Close_OGL();
+    bool TakeScreenShot_OGL(Image& destImage);
+    bool BeginFrame_OGL();
+    void EndFrame_OGL();
+    void Clear_OGL(ClearTargetFlags flags, const Color& color = Color(0.0f, 0.0f, 0.0f, 0.0f), float depth = 1.0f, unsigned stencil = 0);
+    bool ResolveToTexture_OGL(Texture2D* destination, const IntRect& viewport);
+    bool ResolveToTexture_OGL(Texture2D* texture);
+    bool ResolveToTexture_OGL(TextureCube* texture);
+    void Draw_OGL(PrimitiveType type, unsigned vertexStart, unsigned vertexCount);
+    void Draw_OGL(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount);
+    void Draw_OGL(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex, unsigned vertexCount);
+    void DrawInstanced_OGL(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount, unsigned instanceCount);
+    void DrawInstanced_OGL(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex, unsigned vertexCount, unsigned instanceCount);
+    void SetVertexBuffer_OGL(VertexBuffer* buffer);
+    bool SetVertexBuffers_OGL(const PODVector<VertexBuffer*>& buffers, unsigned instanceOffset = 0);
+    bool SetVertexBuffers_OGL(const Vector<SharedPtr<VertexBuffer> >& buffers, unsigned instanceOffset = 0);
+    void SetIndexBuffer_OGL(IndexBuffer* buffer);
+    void SetShaders_OGL(ShaderVariation* vs, ShaderVariation* ps);
+    void SetShaderParameter_OGL(StringHash param, const float* data, unsigned count);
+    void SetShaderParameter_OGL(StringHash param, float value);
+    void SetShaderParameter_OGL(StringHash param, int value);
+    void SetShaderParameter_OGL(StringHash param, bool value);
+    void SetShaderParameter_OGL(StringHash param, const Color& color);
+    void SetShaderParameter_OGL(StringHash param, const Vector2& vector);
+    void SetShaderParameter_OGL(StringHash param, const Matrix3& matrix);
+    void SetShaderParameter_OGL(StringHash param, const Vector3& vector);
+    void SetShaderParameter_OGL(StringHash param, const Matrix4& matrix);
+    void SetShaderParameter_OGL(StringHash param, const Vector4& vector);
+    void SetShaderParameter_OGL(StringHash param, const Matrix3x4& matrix);
+    bool NeedParameterUpdate_OGL(ShaderParameterGroup group, const void* source);
+    bool HasShaderParameter_OGL(StringHash param);
+    bool HasTextureUnit_OGL(TextureUnit unit);
+    void ClearParameterSource_OGL(ShaderParameterGroup group);
+    void ClearParameterSources_OGL();
+    void ClearTransformSources_OGL();
+    void SetTexture_OGL(unsigned index, Texture* texture);
+    void SetDefaultTextureFilterMode_OGL(TextureFilterMode mode);
+    void SetDefaultTextureAnisotropy_OGL(unsigned level);
+    void ResetRenderTargets_OGL();
+    void ResetRenderTarget_OGL(unsigned index);
+    void ResetDepthStencil_OGL();
+    void SetRenderTarget_OGL(unsigned index, RenderSurface* renderTarget);
+    void SetRenderTarget_OGL(unsigned index, Texture2D* texture);
+    void SetDepthStencil_OGL(RenderSurface* depthStencil);
+    void SetDepthStencil_OGL(Texture2D* texture);
+    void SetViewport_OGL(const IntRect& rect);
+    void SetBlendMode_OGL(BlendMode mode, bool alphaToCoverage = false);
+    void SetColorWrite_OGL(bool enable);
+    void SetCullMode_OGL(CullMode mode);
+    void SetDepthBias_OGL(float constantBias, float slopeScaledBias);
+    void SetDepthTest_OGL(CompareMode mode);
+    void SetDepthWrite_OGL(bool enable);
+    void SetFillMode_OGL(FillMode mode);
+    void SetLineAntiAlias_OGL(bool enable);
+    void SetScissorTest_OGL(bool enable, const Rect& rect = Rect::FULL, bool borderInclusive = true);
+    void SetScissorTest_OGL(bool enable, const IntRect& rect);
+    void SetClipPlane_OGL(bool enable, const Plane& clipPlane, const Matrix3x4& view, const Matrix4& projection);
+    void SetStencilTest_OGL(bool enable, CompareMode mode, StencilOp pass, StencilOp fail, StencilOp zFail, unsigned stencilRef, unsigned compareMask, unsigned writeMask);
+    bool IsInitialized_OGL() const;
+    bool GetDither_OGL() const;
+    bool IsDeviceLost_OGL() const;
+    PODVector<int> GetMultiSampleLevels_OGL() const;
+    unsigned GetFormat_OGL(CompressedFormat format) const;
+    ShaderVariation* GetShader_OGL(ShaderType type, const String& name, const String& defines = String::EMPTY) const;
+    ShaderVariation* GetShader_OGL(ShaderType type, const char* name, const char* defines) const;
+    VertexBuffer* GetVertexBuffer_OGL(unsigned index) const;
+    TextureUnit GetTextureUnit_OGL(const String& name);
+    const String& GetTextureUnitName_OGL(TextureUnit unit);
+    Texture* GetTexture_OGL(unsigned index) const;
+    RenderSurface* GetRenderTarget_OGL(unsigned index) const;
+    IntVector2 GetRenderTargetDimensions_OGL() const;
+    void OnWindowResized_OGL();
+    void OnWindowMoved_OGL();
+    ConstantBuffer* GetOrCreateConstantBuffer_OGL(ShaderType type, unsigned index, unsigned size);
+
+    static unsigned GetMaxBones_OGL();
+    static bool GetGL3Support_OGL();
+    static unsigned GetAlphaFormat_OGL();
+    static unsigned GetLuminanceFormat_OGL();
+    static unsigned GetLuminanceAlphaFormat_OGL();
+    static unsigned GetRGBFormat_OGL();
+    static unsigned GetRGBAFormat_OGL();
+    static unsigned GetRGBA16Format_OGL();
+    static unsigned GetRGBAFloat16Format_OGL();
+    static unsigned GetRGBAFloat32Format_OGL();
+    static unsigned GetRG16Format_OGL();
+    static unsigned GetRGFloat16Format_OGL();
+    static unsigned GetRGFloat32Format_OGL();
+    static unsigned GetFloat16Format_OGL();
+    static unsigned GetFloat32Format_OGL();
+    static unsigned GetLinearDepthFormat_OGL();
+    static unsigned GetDepthStencilFormat_OGL();
+    static unsigned GetReadableDepthFormat_OGL();
+    static unsigned GetFormat_OGL(const String& formatName);
+#endif // def URHO3D_OPENGL
+
+#ifdef URHO3D_D3D9
+    void Constructor_D3D9();
+    void Destructor_D3D9();
+    bool SetScreenMode_D3D9(int width, int height, const ScreenModeParams& params, bool maximize);
+    void SetSRGB_D3D9(bool enable);
+    void SetDither_D3D9(bool enable);
+    void SetFlushGPU_D3D9(bool enable);
+    void SetForceGL2_D3D9(bool enable);
+    void Close_D3D9();
+    bool TakeScreenShot_D3D9(Image& destImage);
+    bool BeginFrame_D3D9();
+    void EndFrame_D3D9();
+    void Clear_D3D9(ClearTargetFlags flags, const Color& color = Color(0.0f, 0.0f, 0.0f, 0.0f), float depth = 1.0f, unsigned stencil = 0);
+    bool ResolveToTexture_D3D9(Texture2D* destination, const IntRect& viewport);
+    bool ResolveToTexture_D3D9(Texture2D* texture);
+    bool ResolveToTexture_D3D9(TextureCube* texture);
+    void Draw_D3D9(PrimitiveType type, unsigned vertexStart, unsigned vertexCount);
+    void Draw_D3D9(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount);
+    void Draw_D3D9(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex, unsigned vertexCount);
+    void DrawInstanced_D3D9(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount, unsigned instanceCount);
+    void DrawInstanced_D3D9(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex, unsigned vertexCount, unsigned instanceCount);
+    void SetVertexBuffer_D3D9(VertexBuffer* buffer);
+    bool SetVertexBuffers_D3D9(const PODVector<VertexBuffer*>& buffers, unsigned instanceOffset = 0);
+    bool SetVertexBuffers_D3D9(const Vector<SharedPtr<VertexBuffer> >& buffers, unsigned instanceOffset = 0);
+    void SetIndexBuffer_D3D9(IndexBuffer* buffer);
+    void SetShaders_D3D9(ShaderVariation* vs, ShaderVariation* ps);
+    void SetShaderParameter_D3D9(StringHash param, const float* data, unsigned count);
+    void SetShaderParameter_D3D9(StringHash param, float value);
+    void SetShaderParameter_D3D9(StringHash param, int value);
+    void SetShaderParameter_D3D9(StringHash param, bool value);
+    void SetShaderParameter_D3D9(StringHash param, const Color& color);
+    void SetShaderParameter_D3D9(StringHash param, const Vector2& vector);
+    void SetShaderParameter_D3D9(StringHash param, const Matrix3& matrix);
+    void SetShaderParameter_D3D9(StringHash param, const Vector3& vector);
+    void SetShaderParameter_D3D9(StringHash param, const Matrix4& matrix);
+    void SetShaderParameter_D3D9(StringHash param, const Vector4& vector);
+    void SetShaderParameter_D3D9(StringHash param, const Matrix3x4& matrix);
+    bool NeedParameterUpdate_D3D9(ShaderParameterGroup group, const void* source);
+    bool HasShaderParameter_D3D9(StringHash param);
+    bool HasTextureUnit_D3D9(TextureUnit unit);
+    void ClearParameterSource_D3D9(ShaderParameterGroup group);
+    void ClearParameterSources_D3D9();
+    void ClearTransformSources_D3D9();
+    void SetTexture_D3D9(unsigned index, Texture* texture);
+    void SetDefaultTextureFilterMode_D3D9(TextureFilterMode mode);
+    void SetDefaultTextureAnisotropy_D3D9(unsigned level);
+    void ResetRenderTargets_D3D9();
+    void ResetRenderTarget_D3D9(unsigned index);
+    void ResetDepthStencil_D3D9();
+    void SetRenderTarget_D3D9(unsigned index, RenderSurface* renderTarget);
+    void SetRenderTarget_D3D9(unsigned index, Texture2D* texture);
+    void SetDepthStencil_D3D9(RenderSurface* depthStencil);
+    void SetDepthStencil_D3D9(Texture2D* texture);
+    void SetViewport_D3D9(const IntRect& rect);
+    void SetBlendMode_D3D9(BlendMode mode, bool alphaToCoverage = false);
+    void SetColorWrite_D3D9(bool enable);
+    void SetCullMode_D3D9(CullMode mode);
+    void SetDepthBias_D3D9(float constantBias, float slopeScaledBias);
+    void SetDepthTest_D3D9(CompareMode mode);
+    void SetDepthWrite_D3D9(bool enable);
+    void SetFillMode_D3D9(FillMode mode);
+    void SetLineAntiAlias_D3D9(bool enable);
+    void SetScissorTest_D3D9(bool enable, const Rect& rect = Rect::FULL, bool borderInclusive = true);
+    void SetScissorTest_D3D9(bool enable, const IntRect& rect);
+    void SetClipPlane_D3D9(bool enable, const Plane& clipPlane, const Matrix3x4& view, const Matrix4& projection);
+    void SetStencilTest_D3D9(bool enable, CompareMode mode = CMP_ALWAYS, StencilOp pass = OP_KEEP, StencilOp fail = OP_KEEP, StencilOp zFail = OP_KEEP, unsigned stencilRef = 0, unsigned compareMask = M_MAX_UNSIGNED, unsigned writeMask = M_MAX_UNSIGNED);
+    bool IsInitialized_D3D9() const;
+    bool GetDither_D3D9() const;
+    bool IsDeviceLost_D3D9() const;
+    PODVector<int> GetMultiSampleLevels_D3D9() const;
+    unsigned GetFormat_D3D9(CompressedFormat format) const;
+    ShaderVariation* GetShader_D3D9(ShaderType type, const String& name, const String& defines = String::EMPTY) const;
+    ShaderVariation* GetShader_D3D9(ShaderType type, const char* name, const char* defines) const;
+    VertexBuffer* GetVertexBuffer_D3D9(unsigned index) const;
+    TextureUnit GetTextureUnit_D3D9(const String& name);
+    const String& GetTextureUnitName_D3D9(TextureUnit unit);
+    Texture* GetTexture_D3D9(unsigned index) const;
+    RenderSurface* GetRenderTarget_D3D9(unsigned index) const;
+    IntVector2 GetRenderTargetDimensions_D3D9() const;
+    void OnWindowResized_D3D9();
+    void OnWindowMoved_D3D9();
+    ConstantBuffer* GetOrCreateConstantBuffer_D3D9(ShaderType type, unsigned index, unsigned size);
+
+    static unsigned GetMaxBones_D3D9();
+    static bool GetGL3Support_D3D9();
+    static unsigned GetAlphaFormat_D3D9();
+    static unsigned GetLuminanceFormat_D3D9();
+    static unsigned GetLuminanceAlphaFormat_D3D9();
+    static unsigned GetRGBFormat_D3D9();
+    static unsigned GetRGBAFormat_D3D9();
+    static unsigned GetRGBA16Format_D3D9();
+    static unsigned GetRGBAFloat16Format_D3D9();
+    static unsigned GetRGBAFloat32Format_D3D9();
+    static unsigned GetRG16Format_D3D9();
+    static unsigned GetRGFloat16Format_D3D9();
+    static unsigned GetRGFloat32Format_D3D9();
+    static unsigned GetFloat16Format_D3D9();
+    static unsigned GetFloat32Format_D3D9();
+    static unsigned GetLinearDepthFormat_D3D9();
+    static unsigned GetDepthStencilFormat_D3D9();
+    static unsigned GetReadableDepthFormat_D3D9();
+    static unsigned GetFormat_D3D9(const String& formatName);
+#endif // def URHO3D_D3D9
+
+#ifdef URHO3D_D3D11
+    void Constructor_D3D11();
+    void Destructor_D3D11();
+    bool SetScreenMode_D3D11(int width, int height, const ScreenModeParams& params, bool maximize);
+    void SetSRGB_D3D11(bool enable);
+    void SetDither_D3D11(bool enable);
+    void SetFlushGPU_D3D11(bool enable);
+    void SetForceGL2_D3D11(bool enable);
+    void Close_D3D11();
+    bool TakeScreenShot_D3D11(Image& destImage);
+    bool BeginFrame_D3D11();
+    void EndFrame_D3D11();
+    void Clear_D3D11(ClearTargetFlags flags, const Color& color = Color(0.0f, 0.0f, 0.0f, 0.0f), float depth = 1.0f, unsigned stencil = 0);
+    bool ResolveToTexture_D3D11(Texture2D* destination, const IntRect& viewport);
+    bool ResolveToTexture_D3D11(Texture2D* texture);
+    bool ResolveToTexture_D3D11(TextureCube* texture);
+    void Draw_D3D11(PrimitiveType type, unsigned vertexStart, unsigned vertexCount);
+    void Draw_D3D11(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount);
+    void Draw_D3D11(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex, unsigned vertexCount);
+    void DrawInstanced_D3D11(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount, unsigned instanceCount);
+    void DrawInstanced_D3D11(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex, unsigned vertexCount, unsigned instanceCount);
+    void SetVertexBuffer_D3D11(VertexBuffer* buffer);
+    bool SetVertexBuffers_D3D11(const PODVector<VertexBuffer*>& buffers, unsigned instanceOffset = 0);
+    bool SetVertexBuffers_D3D11(const Vector<SharedPtr<VertexBuffer> >& buffers, unsigned instanceOffset = 0);
+    void SetIndexBuffer_D3D11(IndexBuffer* buffer);
+    void SetShaders_D3D11(ShaderVariation* vs, ShaderVariation* ps);
+    void SetShaderParameter_D3D11(StringHash param, const float* data, unsigned count);
+    void SetShaderParameter_D3D11(StringHash param, float value);
+    void SetShaderParameter_D3D11(StringHash param, int value);
+    void SetShaderParameter_D3D11(StringHash param, bool value);
+    void SetShaderParameter_D3D11(StringHash param, const Color& color);
+    void SetShaderParameter_D3D11(StringHash param, const Vector2& vector);
+    void SetShaderParameter_D3D11(StringHash param, const Matrix3& matrix);
+    void SetShaderParameter_D3D11(StringHash param, const Vector3& vector);
+    void SetShaderParameter_D3D11(StringHash param, const Matrix4& matrix);
+    void SetShaderParameter_D3D11(StringHash param, const Vector4& vector);
+    void SetShaderParameter_D3D11(StringHash param, const Matrix3x4& matrix);
+    bool NeedParameterUpdate_D3D11(ShaderParameterGroup group, const void* source);
+    bool HasShaderParameter_D3D11(StringHash param);
+    bool HasTextureUnit_D3D11(TextureUnit unit);
+    void ClearParameterSource_D3D11(ShaderParameterGroup group);
+    void ClearParameterSources_D3D11();
+    void ClearTransformSources_D3D11();
+    void SetTexture_D3D11(unsigned index, Texture* texture);
+    void SetDefaultTextureFilterMode_D3D11(TextureFilterMode mode);
+    void SetDefaultTextureAnisotropy_D3D11(unsigned level);
+    void ResetRenderTargets_D3D11();
+    void ResetRenderTarget_D3D11(unsigned index);
+    void ResetDepthStencil_D3D11();
+    void SetRenderTarget_D3D11(unsigned index, RenderSurface* renderTarget);
+    void SetRenderTarget_D3D11(unsigned index, Texture2D* texture);
+    void SetDepthStencil_D3D11(RenderSurface* depthStencil);
+    void SetDepthStencil_D3D11(Texture2D* texture);
+    void SetViewport_D3D11(const IntRect& rect);
+    void SetBlendMode_D3D11(BlendMode mode, bool alphaToCoverage = false);
+    void SetColorWrite_D3D11(bool enable);
+    void SetCullMode_D3D11(CullMode mode);
+    void SetDepthBias_D3D11(float constantBias, float slopeScaledBias);
+    void SetDepthTest_D3D11(CompareMode mode);
+    void SetDepthWrite_D3D11(bool enable);
+    void SetFillMode_D3D11(FillMode mode);
+    void SetLineAntiAlias_D3D11(bool enable);
+    void SetScissorTest_D3D11(bool enable, const Rect& rect = Rect::FULL, bool borderInclusive = true);
+    void SetScissorTest_D3D11(bool enable, const IntRect& rect);
+    void SetClipPlane_D3D11(bool enable, const Plane& clipPlane, const Matrix3x4& view, const Matrix4& projection);
+    void SetStencilTest_D3D11(bool enable, CompareMode mode = CMP_ALWAYS, StencilOp pass = OP_KEEP, StencilOp fail = OP_KEEP, StencilOp zFail = OP_KEEP, unsigned stencilRef = 0, unsigned compareMask = M_MAX_UNSIGNED, unsigned writeMask = M_MAX_UNSIGNED);
+    bool IsInitialized_D3D11() const;
+    bool GetDither_D3D11() const;
+    bool IsDeviceLost_D3D11() const;
+    PODVector<int> GetMultiSampleLevels_D3D11() const;
+    unsigned GetFormat_D3D11(CompressedFormat format) const;
+    ShaderVariation* GetShader_D3D11(ShaderType type, const String& name, const String& defines = String::EMPTY) const;
+    ShaderVariation* GetShader_D3D11(ShaderType type, const char* name, const char* defines) const;
+    VertexBuffer* GetVertexBuffer_D3D11(unsigned index) const;
+    TextureUnit GetTextureUnit_D3D11(const String& name);
+    const String& GetTextureUnitName_D3D11(TextureUnit unit);
+    Texture* GetTexture_D3D11(unsigned index) const;
+    RenderSurface* GetRenderTarget_D3D11(unsigned index) const;
+    IntVector2 GetRenderTargetDimensions_D3D11() const;
+    void OnWindowResized_D3D11();
+    void OnWindowMoved_D3D11();
+    ConstantBuffer* GetOrCreateConstantBuffer_D3D11(ShaderType type, unsigned index, unsigned size);
+
+    static unsigned GetMaxBones_D3D11();
+    static bool GetGL3Support_D3D11();
+    static unsigned GetAlphaFormat_D3D11();
+    static unsigned GetLuminanceFormat_D3D11();
+    static unsigned GetLuminanceAlphaFormat_D3D11();
+    static unsigned GetRGBFormat_D3D11();
+    static unsigned GetRGBAFormat_D3D11();
+    static unsigned GetRGBA16Format_D3D11();
+    static unsigned GetRGBAFloat16Format_D3D11();
+    static unsigned GetRGBAFloat32Format_D3D11();
+    static unsigned GetRG16Format_D3D11();
+    static unsigned GetRGFloat16Format_D3D11();
+    static unsigned GetRGFloat32Format_D3D11();
+    static unsigned GetFloat16Format_D3D11();
+    static unsigned GetFloat32Format_D3D11();
+    static unsigned GetLinearDepthFormat_D3D11();
+    static unsigned GetDepthStencilFormat_D3D11();
+    static unsigned GetReadableDepthFormat_D3D11();
+    static unsigned GetFormat_D3D11(const String& formatName);
+#endif // def URHO3D_D3D11
 
     /// Mutex for accessing the GPU objects vector from several threads.
     Mutex gpuObjectMutex_;
     /// Implementation.
-    GraphicsImpl* impl_;
+    void* impl_;
     /// SDL window.
     SDL_Window* window_{};
     /// Window title.
@@ -916,13 +1371,16 @@ private:
     String apiName_;
 
     /// Pixel perfect UV offset.
-    static const Vector2 pixelUVOffset;
+    inline static Vector2 pixelUVOffset;
     /// OpenGL3 support flag.
-    static bool gl3Support;
+    inline static bool gl3Support;
+    /// Used graphics API.
+    inline static GAPI gapi;
 };
 
 /// Register Graphics library objects.
 /// @nobind
 void URHO3D_API RegisterGraphicsLibrary(Context* context);
 
-}
+} // namespace Urho3D
+

+ 8 - 0
Source/Urho3D/Graphics/GraphicsDefs.h

@@ -40,6 +40,14 @@ class Vector3;
 #define DESKTOP_GRAPHICS
 #endif
 
+enum GAPI
+{
+    GAPI_NONE = 0,
+    GAPI_OPENGL,
+    GAPI_D3D9,
+    GAPI_D3D11
+};
+
 /// Primitive type.
 enum PrimitiveType
 {

+ 8 - 4
Source/Urho3D/Graphics/GraphicsImpl.h

@@ -25,10 +25,14 @@
 // Note: GraphicsImpl class is purposefully API-specific. It should not be used by Urho3D client applications,
 // unless required for e.g. integration of 3rd party libraries that interface directly with the graphics device.
 
-#if defined(URHO3D_OPENGL)
+#ifdef URHO3D_OPENGL
 #include "OpenGL/OGLGraphicsImpl.h"
-#elif defined(URHO3D_D3D11)
-#include "Direct3D11/D3D11GraphicsImpl.h"
-#else
+#endif
+
+#ifdef URHO3D_D3D9
 #include "Direct3D9/D3D9GraphicsImpl.h"
 #endif
+
+#ifdef URHO3D_D3D11
+#include "Direct3D11/D3D11GraphicsImpl.h"
+#endif

+ 220 - 0
Source/Urho3D/Graphics/IndexBuffer.cpp

@@ -135,4 +135,224 @@ bool IndexBuffer::GetUsedVertexRange(unsigned start, unsigned count, unsigned& m
     return true;
 }
 
+void IndexBuffer::OnDeviceLost()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return OnDeviceLost_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return OnDeviceLost_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return OnDeviceLost_D3D11();
+#endif
+}
+
+void IndexBuffer::OnDeviceReset()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return OnDeviceReset_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return OnDeviceReset_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return OnDeviceReset_D3D11();
+#endif
+}
+
+void IndexBuffer::Release()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Release_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Release_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Release_D3D11();
+#endif
+}
+
+bool IndexBuffer::SetData(const void* data)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetData_OGL(data);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetData_D3D9(data);;
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetData_D3D11(data);;
+#endif
+}
+
+bool IndexBuffer::SetDataRange(const void* data, unsigned start, unsigned count, bool discard)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetDataRange_OGL(data, start, count, discard);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetDataRange_D3D9(data, start, count, discard);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetDataRange_D3D11(data, start, count, discard);
+#endif
+}
+
+void* IndexBuffer::Lock(unsigned start, unsigned count, bool discard)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Lock_OGL(start, count, discard);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Lock_D3D9(start, count, discard);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Lock_D3D11(start, count, discard);
+#endif
+}
+
+void IndexBuffer::Unlock()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Unlock_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Unlock_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Unlock_D3D11();
+#endif
+}
+
+bool IndexBuffer::Create()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Create_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Create_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Create_D3D11();
+#endif
+}
+
+bool IndexBuffer::UpdateToGPU()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return UpdateToGPU_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return UpdateToGPU_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return UpdateToGPU_D3D11();
+#endif
+}
+
+void* IndexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return MapBuffer_OGL(start, count, discard);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return MapBuffer_D3D9(start, count, discard);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return MapBuffer_D3D11(start, count, discard);
+#endif
+}
+
+void IndexBuffer::UnmapBuffer()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return UnmapBuffer_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return UnmapBuffer_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return UnmapBuffer_D3D11();
+#endif
+}
+
 }

+ 42 - 0
Source/Urho3D/Graphics/IndexBuffer.h

@@ -100,6 +100,48 @@ private:
     /// Unmap the GPU buffer. Not used on OpenGL.
     void UnmapBuffer();
 
+#ifdef URHO3D_OPENGL
+    void OnDeviceLost_OGL();
+    void OnDeviceReset_OGL();
+    void Release_OGL();
+    bool SetData_OGL(const void* data);
+    bool SetDataRange_OGL(const void* data, unsigned start, unsigned count, bool discard = false);
+    void* Lock_OGL(unsigned start, unsigned count, bool discard);
+    void Unlock_OGL();
+    bool Create_OGL();
+    bool UpdateToGPU_OGL();
+    void* MapBuffer_OGL(unsigned start, unsigned count, bool discard);
+    void UnmapBuffer_OGL();
+#endif // def URHO3D_OPENGL
+
+#ifdef URHO3D_D3D9
+    void OnDeviceLost_D3D9();
+    void OnDeviceReset_D3D9();
+    void Release_D3D9();
+    bool SetData_D3D9(const void* data);
+    bool SetDataRange_D3D9(const void* data, unsigned start, unsigned count, bool discard = false);
+    void* Lock_D3D9(unsigned start, unsigned count, bool discard);
+    void Unlock_D3D9();
+    bool Create_D3D9();
+    bool UpdateToGPU_D3D9();
+    void* MapBuffer_D3D9(unsigned start, unsigned count, bool discard);
+    void UnmapBuffer_D3D9();
+#endif // def URHO3D_D3D9
+
+#ifdef URHO3D_D3D11
+    void OnDeviceLost_D3D11();
+    void OnDeviceReset_D3D11();
+    void Release_D3D11();
+    bool SetData_D3D11(const void* data);
+    bool SetDataRange_D3D11(const void* data, unsigned start, unsigned count, bool discard = false);
+    void* Lock_D3D11(unsigned start, unsigned count, bool discard);
+    void Unlock_D3D11();
+    bool Create_D3D11();
+    bool UpdateToGPU_D3D11();
+    void* MapBuffer_D3D11(unsigned start, unsigned count, bool discard);
+    void UnmapBuffer_D3D11();
+#endif // def URHO3D_D3D11
+
     /// Shadow data.
     SharedArrayPtr<unsigned char> shadowData_;
     /// Number of indices.

+ 8 - 8
Source/Urho3D/Graphics/OpenGL/OGLConstantBuffer.cpp

@@ -32,7 +32,7 @@
 namespace Urho3D
 {
 
-void ConstantBuffer::Release()
+void ConstantBuffer::Release_OGL()
 {
     if (object_.name_)
     {
@@ -40,7 +40,7 @@ void ConstantBuffer::Release()
             return;
 
 #ifndef GL_ES_VERSION_2_0
-        graphics_->SetUBO(0);
+        graphics_->SetUBO_OGL(0);
         glDeleteBuffers(1, &object_.name_);
 #endif
         object_.name_ = 0;
@@ -50,13 +50,13 @@ void ConstantBuffer::Release()
     size_ = 0;
 }
 
-void ConstantBuffer::OnDeviceReset()
+void ConstantBuffer::OnDeviceReset_OGL()
 {
     if (size_)
-        SetSize(size_); // Recreate
+        SetSize_OGL(size_); // Recreate
 }
 
-bool ConstantBuffer::SetSize(unsigned size)
+bool ConstantBuffer::SetSize_OGL(unsigned size)
 {
     if (!size)
     {
@@ -78,7 +78,7 @@ bool ConstantBuffer::SetSize(unsigned size)
 #ifndef GL_ES_VERSION_2_0
         if (!object_.name_)
             glGenBuffers(1, &object_.name_);
-        graphics_->SetUBO(object_.name_);
+        graphics_->SetUBO_OGL(object_.name_);
         glBufferData(GL_UNIFORM_BUFFER, size_, shadowData_.Get(), GL_DYNAMIC_DRAW);
 #endif
     }
@@ -86,12 +86,12 @@ bool ConstantBuffer::SetSize(unsigned size)
     return true;
 }
 
-void ConstantBuffer::Apply()
+void ConstantBuffer::Apply_OGL()
 {
     if (dirty_ && object_.name_)
     {
 #ifndef GL_ES_VERSION_2_0
-        graphics_->SetUBO(object_.name_);
+        graphics_->SetUBO_OGL(object_.name_);
         glBufferData(GL_UNIFORM_BUFFER, size_, shadowData_.Get(), GL_DYNAMIC_DRAW);
 #endif
         dirty_ = false;

File diff suppressed because it is too large
+ 208 - 187
Source/Urho3D/Graphics/OpenGL/OGLGraphics.cpp


+ 6 - 6
Source/Urho3D/Graphics/OpenGL/OGLGraphicsImpl.h

@@ -25,9 +25,9 @@
 #include "../../Container/HashMap.h"
 #include "../../Core/Timer.h"
 #include "../../Graphics/ConstantBuffer.h"
-#include "../../Graphics/ShaderProgram.h"
 #include "../../Graphics/Texture2D.h"
 #include "../../Math/Color.h"
+#include "OGLShaderProgram.h"
 
 #if defined(IOS) || defined(TVOS)
 #include <OpenGLES/ES2/gl.h>
@@ -78,7 +78,7 @@ namespace Urho3D
 class Context;
 
 using ConstantBufferMap = HashMap<unsigned, SharedPtr<ConstantBuffer> >;
-using ShaderProgramMap = HashMap<Pair<ShaderVariation*, ShaderVariation*>, SharedPtr<ShaderProgram> >;
+using ShaderProgramMap_OGL = HashMap<Pair<ShaderVariation*, ShaderVariation*>, SharedPtr<ShaderProgram_OGL> >;
 
 /// Cached state of a frame buffer object.
 struct FrameBufferObject
@@ -96,13 +96,13 @@ struct FrameBufferObject
 };
 
 /// %Graphics subsystem implementation. Holds API-specific objects.
-class URHO3D_API GraphicsImpl
+class URHO3D_API GraphicsImpl_OGL
 {
     friend class Graphics;
 
 public:
     /// Construct.
-    GraphicsImpl() = default;
+    GraphicsImpl_OGL() = default;
 
     /// Return the GL Context.
     const SDL_GLContext& GetGLContext() { return context_; }
@@ -149,9 +149,9 @@ private:
     /// Map for additional depth textures, to emulate Direct3D9 ability to mix render texture and backbuffer rendering.
     HashMap<unsigned, SharedPtr<Texture2D> > depthTextures_;
     /// Shader program in use.
-    ShaderProgram* shaderProgram_{};
+    ShaderProgram_OGL* shaderProgram_{};
     /// Linked shader programs.
-    ShaderProgramMap shaderPrograms_;
+    ShaderProgramMap_OGL shaderPrograms_;
     /// Need FBO commit flag.
     bool fboDirty_{};
     /// Need vertex attribute pointer update flag.

+ 20 - 20
Source/Urho3D/Graphics/OpenGL/OGLIndexBuffer.cpp

@@ -33,7 +33,7 @@
 namespace Urho3D
 {
 
-void IndexBuffer::OnDeviceLost()
+void IndexBuffer::OnDeviceLost_OGL()
 {
     if (object_.name_ && !graphics_->IsDeviceLost())
         glDeleteBuffers(1, &object_.name_);
@@ -41,22 +41,22 @@ void IndexBuffer::OnDeviceLost()
     GPUObject::OnDeviceLost();
 }
 
-void IndexBuffer::OnDeviceReset()
+void IndexBuffer::OnDeviceReset_OGL()
 {
     if (!object_.name_)
     {
-        Create();
-        dataLost_ = !UpdateToGPU();
+        Create_OGL();
+        dataLost_ = !UpdateToGPU_OGL();
     }
     else if (dataPending_)
-        dataLost_ = !UpdateToGPU();
+        dataLost_ = !UpdateToGPU_OGL();
 
     dataPending_ = false;
 }
 
-void IndexBuffer::Release()
+void IndexBuffer::Release_OGL()
 {
-    Unlock();
+    Unlock_OGL();
 
     if (object_.name_)
     {
@@ -75,7 +75,7 @@ void IndexBuffer::Release()
     }
 }
 
-bool IndexBuffer::SetData(const void* data)
+bool IndexBuffer::SetData_OGL(const void* data)
 {
     if (!data)
     {
@@ -110,10 +110,10 @@ bool IndexBuffer::SetData(const void* data)
     return true;
 }
 
-bool IndexBuffer::SetDataRange(const void* data, unsigned start, unsigned count, bool discard)
+bool IndexBuffer::SetDataRange_OGL(const void* data, unsigned start, unsigned count, bool discard)
 {
     if (start == 0 && count == indexCount_)
-        return SetData(data);
+        return SetData_OGL(data);
 
     if (!data)
     {
@@ -159,7 +159,7 @@ bool IndexBuffer::SetDataRange(const void* data, unsigned start, unsigned count,
     return true;
 }
 
-void* IndexBuffer::Lock(unsigned start, unsigned count, bool discard)
+void* IndexBuffer::Lock_OGL(unsigned start, unsigned count, bool discard)
 {
     if (lockState_ != LOCK_NONE)
     {
@@ -201,17 +201,17 @@ void* IndexBuffer::Lock(unsigned start, unsigned count, bool discard)
         return nullptr;
 }
 
-void IndexBuffer::Unlock()
+void IndexBuffer::Unlock_OGL()
 {
     switch (lockState_)
     {
     case LOCK_SHADOW:
-        SetDataRange(shadowData_.Get() + lockStart_ * indexSize_, lockStart_, lockCount_, discardLock_);
+        SetDataRange_OGL(shadowData_.Get() + lockStart_ * indexSize_, lockStart_, lockCount_, discardLock_);
         lockState_ = LOCK_NONE;
         break;
 
     case LOCK_SCRATCH:
-        SetDataRange(lockScratchData_, lockStart_, lockCount_, discardLock_);
+        SetDataRange_OGL(lockScratchData_, lockStart_, lockCount_, discardLock_);
         if (graphics_)
             graphics_->FreeScratchBuffer(lockScratchData_);
         lockScratchData_ = nullptr;
@@ -223,11 +223,11 @@ void IndexBuffer::Unlock()
     }
 }
 
-bool IndexBuffer::Create()
+bool IndexBuffer::Create_OGL()
 {
     if (!indexCount_)
     {
-        Release();
+        Release_OGL();
         return true;
     }
 
@@ -254,21 +254,21 @@ bool IndexBuffer::Create()
     return true;
 }
 
-bool IndexBuffer::UpdateToGPU()
+bool IndexBuffer::UpdateToGPU_OGL()
 {
     if (object_.name_ && shadowData_)
-        return SetData(shadowData_.Get());
+        return SetData_OGL(shadowData_.Get());
     else
         return false;
 }
 
-void* IndexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
+void* IndexBuffer::MapBuffer_OGL(unsigned start, unsigned count, bool discard)
 {
     // Never called on OpenGL
     return nullptr;
 }
 
-void IndexBuffer::UnmapBuffer()
+void IndexBuffer::UnmapBuffer_OGL()
 {
     // Never called on OpenGL
 }

+ 10 - 10
Source/Urho3D/Graphics/OpenGL/OGLRenderSurface.cpp

@@ -42,20 +42,20 @@
 namespace Urho3D
 {
 
-RenderSurface::RenderSurface(Texture* parentTexture) :      // NOLINT(hicpp-member-init)
-    parentTexture_(parentTexture),
-    target_(GL_TEXTURE_2D),
-    renderBuffer_(0)
+void RenderSurface::Constructor_OGL(Texture* parentTexture)
 {
+    parentTexture_ = parentTexture;
+    target_ = GL_TEXTURE_2D;
+    renderBuffer_ = 0;
 }
 
-bool RenderSurface::CreateRenderBuffer(unsigned width, unsigned height, unsigned format, int multiSample)
+bool RenderSurface::CreateRenderBuffer_OGL(unsigned width, unsigned height, unsigned format, int multiSample)
 {
     Graphics* graphics = parentTexture_->GetGraphics();
     if (!graphics)
         return false;
 
-    Release();
+    Release_OGL();
 
 #ifndef GL_ES_VERSION_2_0
     if (Graphics::GetGL3Support())
@@ -85,7 +85,7 @@ bool RenderSurface::CreateRenderBuffer(unsigned width, unsigned height, unsigned
     return true;
 }
 
-void RenderSurface::OnDeviceLost()
+void RenderSurface::OnDeviceLost_OGL()
 {
     Graphics* graphics = parentTexture_->GetGraphics();
     if (!graphics)
@@ -101,7 +101,7 @@ void RenderSurface::OnDeviceLost()
         graphics->ResetDepthStencil();
 
     // Clean up also from non-active FBOs
-    graphics->CleanupRenderSurface(this);
+    graphics->CleanupRenderSurface_OGL(this);
 
     if (renderBuffer_ && !graphics->IsDeviceLost())
         glDeleteRenderbuffersEXT(1, &renderBuffer_);
@@ -109,7 +109,7 @@ void RenderSurface::OnDeviceLost()
     renderBuffer_ = 0;
 }
 
-void RenderSurface::Release()
+void RenderSurface::Release_OGL()
 {
     Graphics* graphics = parentTexture_->GetGraphics();
     if (!graphics)
@@ -127,7 +127,7 @@ void RenderSurface::Release()
             graphics->ResetDepthStencil();
 
         // Clean up also from non-active FBOs
-        graphics->CleanupRenderSurface(this);
+        graphics->CleanupRenderSurface_OGL(this);
 
         if (renderBuffer_)
             glDeleteRenderbuffersEXT(1, &renderBuffer_);

+ 19 - 19
Source/Urho3D/Graphics/OpenGL/OGLShaderProgram.cpp

@@ -25,9 +25,9 @@
 #include "../../Graphics/ConstantBuffer.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsImpl.h"
-#include "../../Graphics/ShaderProgram.h"
 #include "../../Graphics/ShaderVariation.h"
 #include "../../IO/Log.h"
+#include "OGLShaderProgram.h"
 
 #include "../../DebugNew.h"
 
@@ -55,10 +55,10 @@ static unsigned NumberPostfix(const String& str)
     return M_MAX_UNSIGNED;
 }
 
-unsigned ShaderProgram::globalFrameNumber = 0;
-const void* ShaderProgram::globalParameterSources[MAX_SHADER_PARAMETER_GROUPS];
+unsigned ShaderProgram_OGL::globalFrameNumber = 0;
+const void* ShaderProgram_OGL::globalParameterSources[MAX_SHADER_PARAMETER_GROUPS];
 
-ShaderProgram::ShaderProgram(Graphics* graphics, ShaderVariation* vertexShader, ShaderVariation* pixelShader) :
+ShaderProgram_OGL::ShaderProgram_OGL(Graphics* graphics, ShaderVariation* vertexShader, ShaderVariation* pixelShader) :
     GPUObject(graphics),
     vertexShader_(vertexShader),
     pixelShader_(pixelShader)
@@ -67,25 +67,25 @@ ShaderProgram::ShaderProgram(Graphics* graphics, ShaderVariation* vertexShader,
         parameterSource = (const void*)M_MAX_UNSIGNED;
 }
 
-ShaderProgram::~ShaderProgram()
+ShaderProgram_OGL::~ShaderProgram_OGL()
 {
     Release();
 }
 
-void ShaderProgram::OnDeviceLost()
+void ShaderProgram_OGL::OnDeviceLost()
 {
     if (object_.name_ && !graphics_->IsDeviceLost())
         glDeleteProgram(object_.name_);
 
     GPUObject::OnDeviceLost();
 
-    if (graphics_ && graphics_->GetShaderProgram() == this)
+    if (graphics_ && graphics_->GetShaderProgram_OGL() == this)
         graphics_->SetShaders(nullptr, nullptr);
 
     linkerOutput_.Clear();
 }
 
-void ShaderProgram::Release()
+void ShaderProgram_OGL::Release()
 {
     if (object_.name_)
     {
@@ -94,7 +94,7 @@ void ShaderProgram::Release()
 
         if (!graphics_->IsDeviceLost())
         {
-            if (graphics_->GetShaderProgram() == this)
+            if (graphics_->GetShaderProgram_OGL() == this)
                 graphics_->SetShaders(nullptr, nullptr);
 
             glDeleteProgram(object_.name_);
@@ -113,7 +113,7 @@ void ShaderProgram::Release()
     }
 }
 
-bool ShaderProgram::Link()
+bool ShaderProgram_OGL::Link()
 {
     Release();
 
@@ -168,7 +168,7 @@ bool ShaderProgram::Link()
         // Go in reverse order so that "binormal" is detected before "normal"
         for (unsigned j = MAX_VERTEX_ELEMENT_SEMANTICS - 1; j < MAX_VERTEX_ELEMENT_SEMANTICS; --j)
         {
-            if (name.Contains(ShaderVariation::elementSemanticNames[j], false))
+            if (name.Contains(ShaderVariation::elementSemanticNames_OGL[j], false))
             {
                 semantic = (VertexElementSemantic)j;
                 unsigned index = NumberPostfix(name);
@@ -320,22 +320,22 @@ bool ShaderProgram::Link()
     return true;
 }
 
-ShaderVariation* ShaderProgram::GetVertexShader() const
+ShaderVariation* ShaderProgram_OGL::GetVertexShader() const
 {
     return vertexShader_;
 }
 
-ShaderVariation* ShaderProgram::GetPixelShader() const
+ShaderVariation* ShaderProgram_OGL::GetPixelShader() const
 {
     return pixelShader_;
 }
 
-bool ShaderProgram::HasParameter(StringHash param) const
+bool ShaderProgram_OGL::HasParameter(StringHash param) const
 {
     return shaderParameters_.Find(param) != shaderParameters_.End();
 }
 
-const ShaderParameter* ShaderProgram::GetParameter(StringHash param) const
+const ShaderParameter* ShaderProgram_OGL::GetParameter(StringHash param) const
 {
     HashMap<StringHash, ShaderParameter>::ConstIterator i = shaderParameters_.Find(param);
     if (i != shaderParameters_.End())
@@ -344,7 +344,7 @@ const ShaderParameter* ShaderProgram::GetParameter(StringHash param) const
         return nullptr;
 }
 
-bool ShaderProgram::NeedParameterUpdate(ShaderParameterGroup group, const void* source)
+bool ShaderProgram_OGL::NeedParameterUpdate(ShaderParameterGroup group, const void* source)
 {
     // If global framenumber has changed, invalidate all per-program parameter sources now
     if (globalFrameNumber != frameNumber_)
@@ -384,7 +384,7 @@ bool ShaderProgram::NeedParameterUpdate(ShaderParameterGroup group, const void*
 #endif
 }
 
-void ShaderProgram::ClearParameterSource(ShaderParameterGroup group)
+void ShaderProgram_OGL::ClearParameterSource(ShaderParameterGroup group)
 {
     // The shader program may use a mixture of constant buffers and individual uniforms even in the same group
 #ifndef GL_ES_VERSION_2_0
@@ -400,7 +400,7 @@ void ShaderProgram::ClearParameterSource(ShaderParameterGroup group)
 #endif
 }
 
-void ShaderProgram::ClearParameterSources()
+void ShaderProgram_OGL::ClearParameterSources()
 {
     ++globalFrameNumber;
     if (!globalFrameNumber)
@@ -412,7 +412,7 @@ void ShaderProgram::ClearParameterSources()
 #endif
 }
 
-void ShaderProgram::ClearGlobalParameterSource(ShaderParameterGroup group)
+void ShaderProgram_OGL::ClearGlobalParameterSource(ShaderParameterGroup group)
 {
     globalParameterSources[group] = (const void*)M_MAX_UNSIGNED;
 }

+ 3 - 3
Source/Urho3D/Graphics/OpenGL/OGLShaderProgram.h

@@ -35,13 +35,13 @@ class ConstantBuffer;
 class Graphics;
 
 /// Linked shader program on the GPU.
-class URHO3D_API ShaderProgram : public RefCounted, public GPUObject
+class URHO3D_API ShaderProgram_OGL : public RefCounted, public GPUObject
 {
 public:
     /// Construct.
-    ShaderProgram(Graphics* graphics, ShaderVariation* vertexShader, ShaderVariation* pixelShader);
+    ShaderProgram_OGL(Graphics* graphics, ShaderVariation* vertexShader, ShaderVariation* pixelShader);
     /// Destruct.
-    ~ShaderProgram() override;
+    ~ShaderProgram_OGL() override;
 
     /// Mark the GPU resource destroyed on context destruction.
     void OnDeviceLost() override;

+ 8 - 15
Source/Urho3D/Graphics/OpenGL/OGLShaderVariation.cpp

@@ -25,16 +25,16 @@
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/Shader.h"
-#include "../../Graphics/ShaderProgram.h"
 #include "../../Graphics/ShaderVariation.h"
 #include "../../IO/Log.h"
+#include "OGLShaderProgram.h"
 
 #include "../../DebugNew.h"
 
 namespace Urho3D
 {
 
-const char* ShaderVariation::elementSemanticNames[] =
+const char* ShaderVariation::elementSemanticNames_OGL[] =
 {
     "POS",
     "NORMAL",
@@ -47,7 +47,7 @@ const char* ShaderVariation::elementSemanticNames[] =
     "OBJECTINDEX"
 };
 
-void ShaderVariation::OnDeviceLost()
+void ShaderVariation::OnDeviceLost_OGL()
 {
     if (object_.name_ && !graphics_->IsDeviceLost())
         glDeleteShader(object_.name_);
@@ -57,7 +57,7 @@ void ShaderVariation::OnDeviceLost()
     compilerOutput_.Clear();
 }
 
-void ShaderVariation::Release()
+void ShaderVariation::Release_OGL()
 {
     if (object_.name_)
     {
@@ -81,15 +81,15 @@ void ShaderVariation::Release()
         }
 
         object_.name_ = 0;
-        graphics_->CleanupShaderPrograms(this);
+        graphics_->CleanupShaderPrograms_OGL(this);
     }
 
     compilerOutput_.Clear();
 }
 
-bool ShaderVariation::Create()
+bool ShaderVariation::Create_OGL()
 {
-    Release();
+    Release_OGL();
 
     if (!owner_)
     {
@@ -190,16 +190,9 @@ bool ShaderVariation::Create()
     return object_.name_ != 0;
 }
 
-void ShaderVariation::SetDefines(const String& defines)
+void ShaderVariation::SetDefines_OGL(const String& defines)
 {
     defines_ = defines;
 }
 
-// These methods are no-ops for OpenGL
-bool ShaderVariation::LoadByteCode(const String& binaryShaderName) { return false; }
-bool ShaderVariation::Compile() { return false; }
-void ShaderVariation::ParseParameters(unsigned char* bufData, unsigned bufSize) {}
-void ShaderVariation::SaveByteCode(const String& binaryShaderName) {}
-void ShaderVariation::CalculateConstantBufferSizes() {}
-
 }

+ 10 - 10
Source/Urho3D/Graphics/OpenGL/OGLTexture.cpp

@@ -66,7 +66,7 @@ static GLenum GetWrapMode(TextureAddressMode mode)
 #endif
 }
 
-void Texture::SetSRGB(bool enable)
+void Texture::SetSRGB_OGL(bool enable)
 {
     if (graphics_)
         enable &= graphics_->GetSRGBSupport();
@@ -80,11 +80,11 @@ void Texture::SetSRGB(bool enable)
 
         // If texture in use in the framebuffer, mark it dirty
         if (graphics_ && graphics_->GetRenderTarget(0) && graphics_->GetRenderTarget(0)->GetParentTexture() == this)
-            graphics_->MarkFBODirty();
+            graphics_->MarkFBODirty_OGL();
     }
 }
 
-void Texture::UpdateParameters()
+void Texture::UpdateParameters_OGL()
 {
     if (!object_.name_ || !graphics_)
         return;
@@ -173,12 +173,12 @@ void Texture::UpdateParameters()
     parametersDirty_ = false;
 }
 
-bool Texture::GetParametersDirty() const
+bool Texture::GetParametersDirty_OGL() const
 {
     return parametersDirty_;
 }
 
-bool Texture::IsCompressed() const
+bool Texture::IsCompressed_OGL() const
 {
     return format_ == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT || format_ == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT ||
            format_ == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT || format_ == GL_ETC1_RGB8_OES ||
@@ -187,7 +187,7 @@ bool Texture::IsCompressed() const
            format_ == COMPRESSED_RGB_PVRTC_2BPPV1_IMG || format_ == COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
 }
 
-unsigned Texture::GetRowDataSize(int width) const
+unsigned Texture::GetRowDataSize_OGL(int width) const
 {
     switch (format_)
     {
@@ -253,7 +253,7 @@ unsigned Texture::GetRowDataSize(int width) const
     }
 }
 
-unsigned Texture::GetExternalFormat(unsigned format)
+unsigned Texture::GetExternalFormat_OGL(unsigned format)
 {
 #ifndef GL_ES_VERSION_2_0
     if (format == GL_DEPTH_COMPONENT16 || format == GL_DEPTH_COMPONENT24 || format == GL_DEPTH_COMPONENT32)
@@ -279,7 +279,7 @@ unsigned Texture::GetExternalFormat(unsigned format)
 #endif
 }
 
-unsigned Texture::GetDataType(unsigned format)
+unsigned Texture::GetDataType_OGL(unsigned format)
 {
 #ifndef GL_ES_VERSION_2_0
     if (format == GL_DEPTH24_STENCIL8_EXT)
@@ -302,7 +302,7 @@ unsigned Texture::GetDataType(unsigned format)
 #endif
 }
 
-unsigned Texture::GetSRGBFormat(unsigned format)
+unsigned Texture::GetSRGBFormat_OGL(unsigned format)
 {
 #ifndef GL_ES_VERSION_2_0
     if (!graphics_ || !graphics_->GetSRGBSupport())
@@ -332,7 +332,7 @@ unsigned Texture::GetSRGBFormat(unsigned format)
 #endif
 }
 
-void Texture::RegenerateLevels()
+void Texture::RegenerateLevels_OGL()
 {
     if (!object_.name_)
         return;

+ 29 - 29
Source/Urho3D/Graphics/OpenGL/OGLTexture2D.cpp

@@ -39,7 +39,7 @@
 namespace Urho3D
 {
 
-void Texture2D::OnDeviceLost()
+void Texture2D::OnDeviceLost_OGL()
 {
     if (object_.name_ && !graphics_->IsDeviceLost())
         glDeleteTextures(1, &object_.name_);
@@ -50,7 +50,7 @@ void Texture2D::OnDeviceLost()
         renderSurface_->OnDeviceLost();
 }
 
-void Texture2D::OnDeviceReset()
+void Texture2D::OnDeviceReset_OGL()
 {
     if (!object_.name_ || dataPending_)
     {
@@ -61,7 +61,7 @@ void Texture2D::OnDeviceReset()
 
         if (!object_.name_)
         {
-            Create();
+            Create_OGL();
             dataLost_ = true;
         }
     }
@@ -69,7 +69,7 @@ void Texture2D::OnDeviceReset()
     dataPending_ = false;
 }
 
-void Texture2D::Release()
+void Texture2D::Release_OGL()
 {
     if (object_.name_)
     {
@@ -102,7 +102,7 @@ void Texture2D::Release()
     levelsDirty_ = false;
 }
 
-bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, const void* data)
+bool Texture2D::SetData_OGL(unsigned level, int x, int y, int width, int height, const void* data)
 {
     URHO3D_PROFILE(SetTextureData);
 
@@ -131,7 +131,7 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
         return true;
     }
 
-    if (IsCompressed())
+    if (IsCompressed_OGL())
     {
         x &= ~3u;
         y &= ~3u;
@@ -145,17 +145,17 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
         return false;
     }
 
-    graphics_->SetTextureForUpdate(this);
+    graphics_->SetTextureForUpdate_OGL(this);
 
     bool wholeLevel = x == 0 && y == 0 && width == levelWidth && height == levelHeight;
-    unsigned format = GetSRGB() ? GetSRGBFormat(format_) : format_;
+    unsigned format = GetSRGB() ? GetSRGBFormat_OGL(format_) : format_;
 
-    if (!IsCompressed())
+    if (!IsCompressed_OGL())
     {
         if (wholeLevel)
-            glTexImage2D(target_, level, format, width, height, 0, GetExternalFormat(format_), GetDataType(format_), data);
+            glTexImage2D(target_, level, format, width, height, 0, GetExternalFormat_OGL(format_), GetDataType_OGL(format_), data);
         else
-            glTexSubImage2D(target_, level, x, y, width, height, GetExternalFormat(format_), GetDataType(format_), data);
+            glTexSubImage2D(target_, level, x, y, width, height, GetExternalFormat_OGL(format_), GetDataType_OGL(format_), data);
     }
     else
     {
@@ -169,7 +169,7 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
     return true;
 }
 
-bool Texture2D::SetData(Image* image, bool useAlpha)
+bool Texture2D::SetData_OGL(Image* image, bool useAlpha)
 {
     if (!image)
     {
@@ -235,7 +235,7 @@ bool Texture2D::SetData(Image* image, bool useAlpha)
         }
 
         // If image was previously compressed, reset number of requested levels to avoid error if level count is too high for new size
-        if (IsCompressed() && requestedLevels_ > 1)
+        if (IsCompressed_OGL() && requestedLevels_ > 1)
             requestedLevels_ = 0;
         SetSize(levelWidth, levelHeight, format);
         if (!object_.name_)
@@ -243,7 +243,7 @@ bool Texture2D::SetData(Image* image, bool useAlpha)
 
         for (unsigned i = 0; i < levels_; ++i)
         {
-            SetData(i, 0, 0, levelWidth, levelHeight, levelData);
+            SetData_OGL(i, 0, 0, levelWidth, levelHeight, levelData);
             memoryUse += levelWidth * levelHeight * components;
 
             if (i < levels_ - 1)
@@ -285,14 +285,14 @@ bool Texture2D::SetData(Image* image, bool useAlpha)
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
             if (!needDecompress)
             {
-                SetData(i, 0, 0, level.width_, level.height_, level.data_);
+                SetData_OGL(i, 0, 0, level.width_, level.height_, level.data_);
                 memoryUse += level.rows_ * level.rowSize_;
             }
             else
             {
                 auto* rgbaData = new unsigned char[level.width_ * level.height_ * 4];
                 level.Decompress(rgbaData);
-                SetData(i, 0, 0, level.width_, level.height_, rgbaData);
+                SetData_OGL(i, 0, 0, level.width_, level.height_, rgbaData);
                 memoryUse += level.width_ * level.height_ * 4;
                 delete[] rgbaData;
             }
@@ -303,7 +303,7 @@ bool Texture2D::SetData(Image* image, bool useAlpha)
     return true;
 }
 
-bool Texture2D::GetData(unsigned level, void* dest) const
+bool Texture2D::GetData_OGL(unsigned level, void* dest) const
 {
     if (!object_.name_ || !graphics_)
     {
@@ -339,10 +339,10 @@ bool Texture2D::GetData(unsigned level, void* dest) const
     if (resolveDirty_)
         graphics_->ResolveToTexture(const_cast<Texture2D*>(this));
 
-    graphics_->SetTextureForUpdate(const_cast<Texture2D*>(this));
+    graphics_->SetTextureForUpdate_OGL(const_cast<Texture2D*>(this));
 
-    if (!IsCompressed())
-        glGetTexImage(target_, level, GetExternalFormat(format_), GetDataType(format_), dest);
+    if (!IsCompressed_OGL())
+        glGetTexImage(target_, level, GetExternalFormat_OGL(format_), GetDataType_OGL(format_), dest);
     else
         glGetCompressedTexImage(target_, level, dest);
 
@@ -355,7 +355,7 @@ bool Texture2D::GetData(unsigned level, void* dest) const
         graphics_->SetRenderTarget(0, const_cast<Texture2D*>(this));
         // Ensure the FBO is current; this viewport is actually never rendered to
         graphics_->SetViewport(IntRect(0, 0, width_, height_));
-        glReadPixels(0, 0, width_, height_, GetExternalFormat(format_), GetDataType(format_), dest);
+        glReadPixels(0, 0, width_, height_, GetExternalFormat_OGL(format_), GetDataType_OGL(format_), dest);
         return true;
     }
 
@@ -364,9 +364,9 @@ bool Texture2D::GetData(unsigned level, void* dest) const
 #endif
 }
 
-bool Texture2D::Create()
+bool Texture2D::Create_OGL()
 {
-    Release();
+    Release_OGL();
 
     if (!graphics_ || !width_ || !height_)
         return false;
@@ -386,9 +386,9 @@ bool Texture2D::Create()
     }
 #endif
 
-    unsigned format = GetSRGB() ? GetSRGBFormat(format_) : format_;
-    unsigned externalFormat = GetExternalFormat(format_);
-    unsigned dataType = GetDataType(format_);
+    unsigned format = GetSRGB() ? GetSRGBFormat_OGL(format_) : format_;
+    unsigned externalFormat = GetExternalFormat_OGL(format_);
+    unsigned dataType = GetDataType_OGL(format_);
 
     // Create a renderbuffer instead of a texture if depth texture is not properly supported, or if this will be a packed
     // depth stencil texture
@@ -437,12 +437,12 @@ bool Texture2D::Create()
     glGenTextures(1, &object_.name_);
 
     // Ensure that our texture is bound to OpenGL texture unit 0
-    graphics_->SetTextureForUpdate(this);
+    graphics_->SetTextureForUpdate_OGL(this);
 
     // If not compressed, create the initial level 0 texture with null data
     bool success = true;
 
-    if (!IsCompressed())
+    if (!IsCompressed_OGL())
     {
         glGetError();
 #ifndef GL_ES_VERSION_2_0
@@ -474,7 +474,7 @@ bool Texture2D::Create()
         if (requestedLevels_ != 1)
         {
             // Generate levels for the first time now
-            RegenerateLevels();
+            RegenerateLevels_OGL();
             // Determine max. levels automatically
             requestedLevels_ = 0;
         }

+ 32 - 32
Source/Urho3D/Graphics/OpenGL/OGLTexture2DArray.cpp

@@ -43,7 +43,7 @@
 namespace Urho3D
 {
 
-void Texture2DArray::OnDeviceLost()
+void Texture2DArray::OnDeviceLost_OGL()
 {
     if (object_.name_ && !graphics_->IsDeviceLost())
         glDeleteTextures(1, &object_.name_);
@@ -54,7 +54,7 @@ void Texture2DArray::OnDeviceLost()
         renderSurface_->OnDeviceLost();
 }
 
-void Texture2DArray::OnDeviceReset()
+void Texture2DArray::OnDeviceReset_OGL()
 {
     if (!object_.name_ || dataPending_)
     {
@@ -65,7 +65,7 @@ void Texture2DArray::OnDeviceReset()
 
         if (!object_.name_)
         {
-            Create();
+            Create_OGL();
             dataLost_ = true;
         }
     }
@@ -73,7 +73,7 @@ void Texture2DArray::OnDeviceReset()
     dataPending_ = false;
 }
 
-void Texture2DArray::Release()
+void Texture2DArray::Release_OGL()
 {
     if (object_.name_)
     {
@@ -100,7 +100,7 @@ void Texture2DArray::Release()
     levelsDirty_ = false;
 }
 
-bool Texture2DArray::SetData(unsigned layer, unsigned level, int x, int y, int width, int height, const void* data)
+bool Texture2DArray::SetData_OGL(unsigned layer, unsigned level, int x, int y, int width, int height, const void* data)
 {
     URHO3D_PROFILE(SetTextureData);
 
@@ -135,7 +135,7 @@ bool Texture2DArray::SetData(unsigned layer, unsigned level, int x, int y, int w
         return true;
     }
 
-    if (IsCompressed())
+    if (IsCompressed_OGL())
     {
         x &= ~3u;
         y &= ~3u;
@@ -149,19 +149,19 @@ bool Texture2DArray::SetData(unsigned layer, unsigned level, int x, int y, int w
         return false;
     }
 
-    graphics_->SetTextureForUpdate(this);
+    graphics_->SetTextureForUpdate_OGL(this);
 
 #ifndef GL_ES_VERSION_2_0
     bool wholeLevel = x == 0 && y == 0 && width == levelWidth && height == levelHeight && layer == 0;
-    unsigned format = GetSRGB() ? GetSRGBFormat(format_) : format_;
+    unsigned format = GetSRGB() ? GetSRGBFormat_OGL(format_) : format_;
 
-    if (!IsCompressed())
+    if (!IsCompressed_OGL())
     {
         if (wholeLevel)
-            glTexImage3D(target_, level, format, width, height, layers_, 0, GetExternalFormat(format_),
-                GetDataType(format_), nullptr);
-        glTexSubImage3D(target_, level, x, y, layer, width, height, 1, GetExternalFormat(format_),
-            GetDataType(format_), data);
+            glTexImage3D(target_, level, format, width, height, layers_, 0, GetExternalFormat_OGL(format_),
+                GetDataType_OGL(format_), nullptr);
+        glTexSubImage3D(target_, level, x, y, layer, width, height, 1, GetExternalFormat_OGL(format_),
+            GetDataType_OGL(format_), data);
     }
     else
     {
@@ -177,16 +177,16 @@ bool Texture2DArray::SetData(unsigned layer, unsigned level, int x, int y, int w
     return true;
 }
 
-bool Texture2DArray::SetData(unsigned layer, Deserializer& source)
+bool Texture2DArray::SetData_OGL(unsigned layer, Deserializer& source)
 {
     SharedPtr<Image> image(new Image(context_));
     if (!image->Load(source))
         return false;
 
-    return SetData(layer, image);
+    return SetData_OGL(layer, image);
 }
 
-bool Texture2DArray::SetData(unsigned layer, Image* image, bool useAlpha)
+bool Texture2DArray::SetData_OGL(unsigned layer, Image* image, bool useAlpha)
 {
     if (!image)
     {
@@ -265,7 +265,7 @@ bool Texture2DArray::SetData(unsigned layer, Image* image, bool useAlpha)
         if (!layer)
         {
             // If image was previously compressed, reset number of requested levels to avoid error if level count is too high for new size
-            if (IsCompressed() && requestedLevels_ > 1)
+            if (IsCompressed_OGL() && requestedLevels_ > 1)
                 requestedLevels_ = 0;
             // Create the texture array (the number of layers must have been already set)
             SetSize(0, levelWidth, levelHeight, format);
@@ -286,7 +286,7 @@ bool Texture2DArray::SetData(unsigned layer, Image* image, bool useAlpha)
 
         for (unsigned i = 0; i < levels_; ++i)
         {
-            SetData(layer, i, 0, 0, levelWidth, levelHeight, levelData);
+            SetData_OGL(layer, i, 0, 0, levelWidth, levelHeight, levelData);
             memoryUse += levelWidth * levelHeight * components;
 
             if (i < levels_ - 1)
@@ -345,14 +345,14 @@ bool Texture2DArray::SetData(unsigned layer, Image* image, bool useAlpha)
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
             if (!needDecompress)
             {
-                SetData(layer, i, 0, 0, level.width_, level.height_, level.data_);
+                SetData_OGL(layer, i, 0, 0, level.width_, level.height_, level.data_);
                 memoryUse += level.rows_ * level.rowSize_;
             }
             else
             {
                 auto* rgbaData = new unsigned char[level.width_ * level.height_ * 4];
                 level.Decompress(rgbaData);
-                SetData(layer, i, 0, 0, level.width_, level.height_, rgbaData);
+                SetData_OGL(layer, i, 0, 0, level.width_, level.height_, rgbaData);
                 memoryUse += level.width_ * level.height_ * 4;
                 delete[] rgbaData;
             }
@@ -368,7 +368,7 @@ bool Texture2DArray::SetData(unsigned layer, Image* image, bool useAlpha)
     return true;
 }
 
-bool Texture2DArray::GetData(unsigned layer, unsigned level, void* dest) const
+bool Texture2DArray::GetData_OGL(unsigned layer, unsigned level, void* dest) const
 {
 #ifndef GL_ES_VERSION_2_0
     if (!object_.name_ || !graphics_)
@@ -401,10 +401,10 @@ bool Texture2DArray::GetData(unsigned layer, unsigned level, void* dest) const
         return false;
     }
 
-    graphics_->SetTextureForUpdate(const_cast<Texture2DArray*>(this));
+    graphics_->SetTextureForUpdate_OGL(const_cast<Texture2DArray*>(this));
 
-    if (!IsCompressed())
-        glGetTexImage(target_, level, GetExternalFormat(format_), GetDataType(format_), dest);
+    if (!IsCompressed_OGL())
+        glGetTexImage(target_, level, GetExternalFormat_OGL(format_), GetDataType_OGL(format_), dest);
     else
         glGetCompressedTexImage(target_, level, dest);
 
@@ -416,9 +416,9 @@ bool Texture2DArray::GetData(unsigned layer, unsigned level, void* dest) const
 #endif
 }
 
-bool Texture2DArray::Create()
+bool Texture2DArray::Create_OGL()
 {
-    Release();
+    Release_OGL();
 
 #ifdef GL_ES_VERSION_2_0
     URHO3D_LOGERROR("Failed to create 2D array texture, currently unsupported on OpenGL ES 2");
@@ -437,15 +437,15 @@ bool Texture2DArray::Create()
     glGenTextures(1, &object_.name_);
 
     // Ensure that our texture is bound to OpenGL texture unit 0
-    graphics_->SetTextureForUpdate(this);
+    graphics_->SetTextureForUpdate_OGL(this);
 
-    unsigned format = GetSRGB() ? GetSRGBFormat(format_) : format_;
-    unsigned externalFormat = GetExternalFormat(format_);
-    unsigned dataType = GetDataType(format_);
+    unsigned format = GetSRGB() ? GetSRGBFormat_OGL(format_) : format_;
+    unsigned externalFormat = GetExternalFormat_OGL(format_);
+    unsigned dataType = GetDataType_OGL(format_);
 
     // If not compressed, create the initial level 0 texture with null data
     bool success = true;
-    if (!IsCompressed())
+    if (!IsCompressed_OGL())
     {
         glGetError();
         glTexImage3D(target_, 0, format, width_, height_, layers_, 0, externalFormat, dataType, nullptr);
@@ -467,7 +467,7 @@ bool Texture2DArray::Create()
         if (requestedLevels_ != 1)
         {
             // Generate levels for the first time now
-            RegenerateLevels();
+            RegenerateLevels_OGL();
             // Determine max. levels automatically
             requestedLevels_ = 0;
         }

+ 27 - 27
Source/Urho3D/Graphics/OpenGL/OGLTexture3D.cpp

@@ -39,7 +39,7 @@
 namespace Urho3D
 {
 
-void Texture3D::OnDeviceLost()
+void Texture3D::OnDeviceLost_OGL()
 {
     if (object_.name_ && !graphics_->IsDeviceLost())
         glDeleteTextures(1, &object_.name_);
@@ -47,7 +47,7 @@ void Texture3D::OnDeviceLost()
     GPUObject::OnDeviceLost();
 }
 
-void Texture3D::OnDeviceReset()
+void Texture3D::OnDeviceReset_OGL()
 {
     if (!object_.name_ || dataPending_)
     {
@@ -58,7 +58,7 @@ void Texture3D::OnDeviceReset()
 
         if (!object_.name_)
         {
-            Create();
+            Create_OGL();
             dataLost_ = true;
         }
     }
@@ -66,7 +66,7 @@ void Texture3D::OnDeviceReset()
     dataPending_ = false;
 }
 
-void Texture3D::Release()
+void Texture3D::Release_OGL()
 {
     if (object_.name_)
     {
@@ -84,7 +84,7 @@ void Texture3D::Release()
     }
 }
 
-bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int height, int depth, const void* data)
+bool Texture3D::SetData_OGL(unsigned level, int x, int y, int z, int width, int height, int depth, const void* data)
 {
     URHO3D_PROFILE(SetTextureData);
 
@@ -113,7 +113,7 @@ bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int heig
         return true;
     }
 
-    if (IsCompressed())
+    if (IsCompressed_OGL())
     {
         x &= ~3u;
         y &= ~3u;
@@ -129,18 +129,18 @@ bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int heig
         return false;
     }
 
-    graphics_->SetTextureForUpdate(this);
+    graphics_->SetTextureForUpdate_OGL(this);
 
 #ifndef GL_ES_VERSION_2_0
     bool wholeLevel = x == 0 && y == 0 && z == 0 && width == levelWidth && height == levelHeight && depth == levelDepth;
-    unsigned format = GetSRGB() ? GetSRGBFormat(format_) : format_;
+    unsigned format = GetSRGB() ? GetSRGBFormat_OGL(format_) : format_;
 
-    if (!IsCompressed())
+    if (!IsCompressed_OGL())
     {
         if (wholeLevel)
-            glTexImage3D(target_, level, format, width, height, depth, 0, GetExternalFormat(format_), GetDataType(format_), data);
+            glTexImage3D(target_, level, format, width, height, depth, 0, GetExternalFormat_OGL(format_), GetDataType_OGL(format_), data);
         else
-            glTexSubImage3D(target_, level, x, y, z, width, height, depth, GetExternalFormat(format_), GetDataType(format_), data);
+            glTexSubImage3D(target_, level, x, y, z, width, height, depth, GetExternalFormat_OGL(format_), GetDataType_OGL(format_), data);
     }
     else
     {
@@ -156,7 +156,7 @@ bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int heig
     return true;
 }
 
-bool Texture3D::SetData(Image* image, bool useAlpha)
+bool Texture3D::SetData_OGL(Image* image, bool useAlpha)
 {
     if (!image)
     {
@@ -224,7 +224,7 @@ bool Texture3D::SetData(Image* image, bool useAlpha)
         }
 
         // If image was previously compressed, reset number of requested levels to avoid error if level count is too high for new size
-        if (IsCompressed() && requestedLevels_ > 1)
+        if (IsCompressed_OGL() && requestedLevels_ > 1)
             requestedLevels_ = 0;
         SetSize(levelWidth, levelHeight, levelDepth, format);
         if (!object_.name_)
@@ -232,7 +232,7 @@ bool Texture3D::SetData(Image* image, bool useAlpha)
 
         for (unsigned i = 0; i < levels_; ++i)
         {
-            SetData(i, 0, 0, 0, levelWidth, levelHeight, levelDepth, levelData);
+            SetData_OGL(i, 0, 0, 0, levelWidth, levelHeight, levelDepth, levelData);
             memoryUse += levelWidth * levelHeight * levelDepth * components;
 
             if (i < levels_ - 1)
@@ -277,14 +277,14 @@ bool Texture3D::SetData(Image* image, bool useAlpha)
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
             if (!needDecompress)
             {
-                SetData(i, 0, 0, 0, level.width_, level.height_, level.depth_, level.data_);
+                SetData_OGL(i, 0, 0, 0, level.width_, level.height_, level.depth_, level.data_);
                 memoryUse += level.depth_ * level.rows_ * level.rowSize_;
             }
             else
             {
                 auto* rgbaData = new unsigned char[level.width_ * level.height_ * level.depth_ * 4];
                 level.Decompress(rgbaData);
-                SetData(i, 0, 0, 0, level.width_, level.height_, level.depth_, rgbaData);
+                SetData_OGL(i, 0, 0, 0, level.width_, level.height_, level.depth_, rgbaData);
                 memoryUse += level.width_ * level.height_ * level.depth_ * 4;
                 delete[] rgbaData;
             }
@@ -295,7 +295,7 @@ bool Texture3D::SetData(Image* image, bool useAlpha)
     return true;
 }
 
-bool Texture3D::GetData(unsigned level, void* dest) const
+bool Texture3D::GetData_OGL(unsigned level, void* dest) const
 {
 #ifndef GL_ES_VERSION_2_0
     if (!object_.name_ || !graphics_)
@@ -322,10 +322,10 @@ bool Texture3D::GetData(unsigned level, void* dest) const
         return false;
     }
 
-    graphics_->SetTextureForUpdate(const_cast<Texture3D*>(this));
+    graphics_->SetTextureForUpdate_OGL(const_cast<Texture3D*>(this));
 
-    if (!IsCompressed())
-        glGetTexImage(target_, level, GetExternalFormat(format_), GetDataType(format_), dest);
+    if (!IsCompressed_OGL())
+        glGetTexImage(target_, level, GetExternalFormat_OGL(format_), GetDataType_OGL(format_), dest);
     else
         glGetCompressedTexImage(target_, level, dest);
 
@@ -337,9 +337,9 @@ bool Texture3D::GetData(unsigned level, void* dest) const
 #endif
 }
 
-bool Texture3D::Create()
+bool Texture3D::Create_OGL()
 {
-    Release();
+    Release_OGL();
 
 #ifdef GL_ES_VERSION_2_0
     URHO3D_LOGERROR("Failed to create 3D texture, currently unsupported on OpenGL ES 2");
@@ -354,19 +354,19 @@ bool Texture3D::Create()
         return true;
     }
 
-    unsigned format = GetSRGB() ? GetSRGBFormat(format_) : format_;
-    unsigned externalFormat = GetExternalFormat(format_);
-    unsigned dataType = GetDataType(format_);
+    unsigned format = GetSRGB() ? GetSRGBFormat_OGL(format_) : format_;
+    unsigned externalFormat = GetExternalFormat_OGL(format_);
+    unsigned dataType = GetDataType_OGL(format_);
 
     glGenTextures(1, &object_.name_);
 
     // Ensure that our texture is bound to OpenGL texture unit 0
-    graphics_->SetTextureForUpdate(this);
+    graphics_->SetTextureForUpdate_OGL(this);
 
     // If not compressed, create the initial level 0 texture with null data
     bool success = true;
 
-    if (!IsCompressed())
+    if (!IsCompressed_OGL())
     {
         glGetError();
         glTexImage3D(target_, 0, format, width_, height_, depth_, 0, externalFormat, dataType, nullptr);

+ 33 - 33
Source/Urho3D/Graphics/OpenGL/OGLTextureCube.cpp

@@ -43,7 +43,7 @@
 namespace Urho3D
 {
 
-void TextureCube::OnDeviceLost()
+void TextureCube::OnDeviceLost_OGL()
 {
     if (object_.name_ && !graphics_->IsDeviceLost())
         glDeleteTextures(1, &object_.name_);
@@ -57,7 +57,7 @@ void TextureCube::OnDeviceLost()
     }
 }
 
-void TextureCube::OnDeviceReset()
+void TextureCube::OnDeviceReset_OGL()
 {
     if (!object_.name_ || dataPending_)
     {
@@ -68,7 +68,7 @@ void TextureCube::OnDeviceReset()
 
         if (!object_.name_)
         {
-            Create();
+            Create_OGL();
             dataLost_ = true;
         }
     }
@@ -76,7 +76,7 @@ void TextureCube::OnDeviceReset()
     dataPending_ = false;
 }
 
-void TextureCube::Release()
+void TextureCube::Release_OGL()
 {
     if (object_.name_)
     {
@@ -107,7 +107,7 @@ void TextureCube::Release()
     levelsDirty_ = false;
 }
 
-bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int width, int height, const void* data)
+bool TextureCube::SetData_OGL(CubeMapFace face, unsigned level, int x, int y, int width, int height, const void* data)
 {
     URHO3D_PROFILE(SetTextureData);
 
@@ -136,7 +136,7 @@ bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int wi
         return true;
     }
 
-    if (IsCompressed())
+    if (IsCompressed_OGL())
     {
         x &= ~3u;
         y &= ~3u;
@@ -150,19 +150,19 @@ bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int wi
         return false;
     }
 
-    graphics_->SetTextureForUpdate(this);
+    graphics_->SetTextureForUpdate_OGL(this);
 
     bool wholeLevel = x == 0 && y == 0 && width == levelWidth && height == levelHeight;
-    unsigned format = GetSRGB() ? GetSRGBFormat(format_) : format_;
+    unsigned format = GetSRGB() ? GetSRGBFormat_OGL(format_) : format_;
 
-    if (!IsCompressed())
+    if (!IsCompressed_OGL())
     {
         if (wholeLevel)
-            glTexImage2D((GLenum)(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face), level, format, width, height, 0, GetExternalFormat(format_),
-                GetDataType(format_), data);
+            glTexImage2D((GLenum)(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face), level, format, width, height, 0, GetExternalFormat_OGL(format_),
+                GetDataType_OGL(format_), data);
         else
-            glTexSubImage2D((GLenum)(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face), level, x, y, width, height, GetExternalFormat(format_),
-                GetDataType(format_), data);
+            glTexSubImage2D((GLenum)(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face), level, x, y, width, height, GetExternalFormat_OGL(format_),
+                GetDataType_OGL(format_), data);
     }
     else
     {
@@ -178,16 +178,16 @@ bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int wi
     return true;
 }
 
-bool TextureCube::SetData(CubeMapFace face, Deserializer& source)
+bool TextureCube::SetData_OGL(CubeMapFace face, Deserializer& source)
 {
     SharedPtr<Image> image(new Image(context_));
     if (!image->Load(source))
         return false;
 
-    return SetData(face, image);
+    return SetData_OGL(face, image);
 }
 
-bool TextureCube::SetData(CubeMapFace face, Image* image, bool useAlpha)
+bool TextureCube::SetData_OGL(CubeMapFace face, Image* image, bool useAlpha)
 {
     if (!image)
     {
@@ -262,7 +262,7 @@ bool TextureCube::SetData(CubeMapFace face, Image* image, bool useAlpha)
         if (!face)
         {
             // If image was previously compressed, reset number of requested levels to avoid error if level count is too high for new size
-            if (IsCompressed() && requestedLevels_ > 1)
+            if (IsCompressed_OGL() && requestedLevels_ > 1)
                 requestedLevels_ = 0;
             SetSize(levelWidth, format);
         }
@@ -282,7 +282,7 @@ bool TextureCube::SetData(CubeMapFace face, Image* image, bool useAlpha)
 
         for (unsigned i = 0; i < levels_; ++i)
         {
-            SetData(face, i, 0, 0, levelWidth, levelHeight, levelData);
+            SetData_OGL(face, i, 0, 0, levelWidth, levelHeight, levelData);
             memoryUse += levelWidth * levelHeight * components;
 
             if (i < levels_ - 1)
@@ -347,14 +347,14 @@ bool TextureCube::SetData(CubeMapFace face, Image* image, bool useAlpha)
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
             if (!needDecompress)
             {
-                SetData(face, i, 0, 0, level.width_, level.height_, level.data_);
+                SetData_OGL(face, i, 0, 0, level.width_, level.height_, level.data_);
                 memoryUse += level.rows_ * level.rowSize_;
             }
             else
             {
                 auto* rgbaData = new unsigned char[level.width_ * level.height_ * 4];
                 level.Decompress(rgbaData);
-                SetData(face, i, 0, 0, level.width_, level.height_, rgbaData);
+                SetData_OGL(face, i, 0, 0, level.width_, level.height_, rgbaData);
                 memoryUse += level.width_ * level.height_ * 4;
                 delete[] rgbaData;
             }
@@ -369,7 +369,7 @@ bool TextureCube::SetData(CubeMapFace face, Image* image, bool useAlpha)
     return true;
 }
 
-bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
+bool TextureCube::GetData_OGL(CubeMapFace face, unsigned level, void* dest) const
 {
     if (!object_.name_ || !graphics_)
     {
@@ -405,10 +405,10 @@ bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
     if (resolveDirty_)
         graphics_->ResolveToTexture(const_cast<TextureCube*>(this));
 
-    graphics_->SetTextureForUpdate(const_cast<TextureCube*>(this));
+    graphics_->SetTextureForUpdate_OGL(const_cast<TextureCube*>(this));
 
-    if (!IsCompressed())
-        glGetTexImage((GLenum)(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face), level, GetExternalFormat(format_), GetDataType(format_), dest);
+    if (!IsCompressed_OGL())
+        glGetTexImage((GLenum)(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face), level, GetExternalFormat_OGL(format_), GetDataType_OGL(format_), dest);
     else
         glGetCompressedTexImage((GLenum)(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face), level, dest);
 
@@ -421,7 +421,7 @@ bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
         graphics_->SetRenderTarget(0, renderSurfaces_[face]);
         // Ensure the FBO is current; this viewport is actually never rendered to
         graphics_->SetViewport(IntRect(0, 0, width_, height_));
-        glReadPixels(0, 0, width_, height_, GetExternalFormat(format_), GetDataType(format_), dest);
+        glReadPixels(0, 0, width_, height_, GetExternalFormat_OGL(format_), GetDataType_OGL(format_), dest);
         return true;
     }
 
@@ -430,9 +430,9 @@ bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
 #endif
 }
 
-bool TextureCube::Create()
+bool TextureCube::Create_OGL()
 {
-    Release();
+    Release_OGL();
 
     if (!graphics_ || !width_ || !height_)
         return false;
@@ -455,12 +455,12 @@ bool TextureCube::Create()
     glGenTextures(1, &object_.name_);
 
     // Ensure that our texture is bound to OpenGL texture unit 0
-    graphics_->SetTextureForUpdate(this);
+    graphics_->SetTextureForUpdate_OGL(this);
 
     // If not compressed, create the initial level 0 texture with null data
-    unsigned format = GetSRGB() ? GetSRGBFormat(format_) : format_;
-    unsigned externalFormat = GetExternalFormat(format_);
-    unsigned dataType = GetDataType(format_);
+    unsigned format = GetSRGB() ? GetSRGBFormat_OGL(format_) : format_;
+    unsigned externalFormat = GetExternalFormat_OGL(format_);
+    unsigned dataType = GetDataType_OGL(format_);
 
     // If multisample, create renderbuffers for each face
     if (multiSample_ > 1)
@@ -470,7 +470,7 @@ bool TextureCube::Create()
     }
 
     bool success = true;
-    if (!IsCompressed())
+    if (!IsCompressed_OGL())
     {
         glGetError();
         for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
@@ -495,7 +495,7 @@ bool TextureCube::Create()
         if (requestedLevels_ != 1)
         {
             // Generate levels for the first time now
-            RegenerateLevels();
+            RegenerateLevels_OGL();
             // Determine max. levels automatically
             requestedLevels_ = 0;
         }

+ 24 - 24
Source/Urho3D/Graphics/OpenGL/OGLVertexBuffer.cpp

@@ -32,7 +32,7 @@
 namespace Urho3D
 {
 
-void VertexBuffer::OnDeviceLost()
+void VertexBuffer::OnDeviceLost_OGL()
 {
     if (object_.name_ && !graphics_->IsDeviceLost())
         glDeleteBuffers(1, &object_.name_);
@@ -40,22 +40,22 @@ void VertexBuffer::OnDeviceLost()
     GPUObject::OnDeviceLost();
 }
 
-void VertexBuffer::OnDeviceReset()
+void VertexBuffer::OnDeviceReset_OGL()
 {
     if (!object_.name_)
     {
-        Create();
-        dataLost_ = !UpdateToGPU();
+        Create_OGL();
+        dataLost_ = !UpdateToGPU_OGL();
     }
     else if (dataPending_)
-        dataLost_ = !UpdateToGPU();
+        dataLost_ = !UpdateToGPU_OGL();
 
     dataPending_ = false;
 }
 
-void VertexBuffer::Release()
+void VertexBuffer::Release_OGL()
 {
-    Unlock();
+    Unlock_OGL();
 
     if (object_.name_)
     {
@@ -70,7 +70,7 @@ void VertexBuffer::Release()
                     graphics_->SetVertexBuffer(nullptr);
             }
 
-            graphics_->SetVBO(0);
+            graphics_->SetVBO_OGL(0);
             glDeleteBuffers(1, &object_.name_);
         }
 
@@ -78,7 +78,7 @@ void VertexBuffer::Release()
     }
 }
 
-bool VertexBuffer::SetData(const void* data)
+bool VertexBuffer::SetData_OGL(const void* data)
 {
     if (!data)
     {
@@ -99,7 +99,7 @@ bool VertexBuffer::SetData(const void* data)
     {
         if (!graphics_->IsDeviceLost())
         {
-            graphics_->SetVBO(object_.name_);
+            graphics_->SetVBO_OGL(object_.name_);
             glBufferData(GL_ARRAY_BUFFER, vertexCount_ * (size_t)vertexSize_, data, dynamic_ ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
         }
         else
@@ -113,10 +113,10 @@ bool VertexBuffer::SetData(const void* data)
     return true;
 }
 
-bool VertexBuffer::SetDataRange(const void* data, unsigned start, unsigned count, bool discard)
+bool VertexBuffer::SetDataRange_OGL(const void* data, unsigned start, unsigned count, bool discard)
 {
     if (start == 0 && count == vertexCount_)
-        return SetData(data);
+        return SetData_OGL(data);
 
     if (!data)
     {
@@ -146,7 +146,7 @@ bool VertexBuffer::SetDataRange(const void* data, unsigned start, unsigned count
     {
         if (!graphics_->IsDeviceLost())
         {
-            graphics_->SetVBO(object_.name_);
+            graphics_->SetVBO_OGL(object_.name_);
             if (!discard || start != 0)
                 glBufferSubData(GL_ARRAY_BUFFER, start * (size_t)vertexSize_, count * vertexSize_, data);
             else
@@ -162,7 +162,7 @@ bool VertexBuffer::SetDataRange(const void* data, unsigned start, unsigned count
     return true;
 }
 
-void* VertexBuffer::Lock(unsigned start, unsigned count, bool discard)
+void* VertexBuffer::Lock_OGL(unsigned start, unsigned count, bool discard)
 {
     if (lockState_ != LOCK_NONE)
     {
@@ -204,17 +204,17 @@ void* VertexBuffer::Lock(unsigned start, unsigned count, bool discard)
         return nullptr;
 }
 
-void VertexBuffer::Unlock()
+void VertexBuffer::Unlock_OGL()
 {
     switch (lockState_)
     {
     case LOCK_SHADOW:
-        SetDataRange(shadowData_.Get() + lockStart_ * vertexSize_, lockStart_, lockCount_, discardLock_);
+        SetDataRange_OGL(shadowData_.Get() + lockStart_ * vertexSize_, lockStart_, lockCount_, discardLock_);
         lockState_ = LOCK_NONE;
         break;
 
     case LOCK_SCRATCH:
-        SetDataRange(lockScratchData_, lockStart_, lockCount_, discardLock_);
+        SetDataRange_OGL(lockScratchData_, lockStart_, lockCount_, discardLock_);
         if (graphics_)
             graphics_->FreeScratchBuffer(lockScratchData_);
         lockScratchData_ = nullptr;
@@ -226,11 +226,11 @@ void VertexBuffer::Unlock()
     }
 }
 
-bool VertexBuffer::Create()
+bool VertexBuffer::Create_OGL()
 {
     if (!vertexCount_ || !elementMask_)
     {
-        Release();
+        Release_OGL();
         return true;
     }
 
@@ -250,28 +250,28 @@ bool VertexBuffer::Create()
             return false;
         }
 
-        graphics_->SetVBO(object_.name_);
+        graphics_->SetVBO_OGL(object_.name_);
         glBufferData(GL_ARRAY_BUFFER, vertexCount_ * (size_t)vertexSize_, nullptr, dynamic_ ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
     }
 
     return true;
 }
 
-bool VertexBuffer::UpdateToGPU()
+bool VertexBuffer::UpdateToGPU_OGL()
 {
     if (object_.name_ && shadowData_)
-        return SetData(shadowData_.Get());
+        return SetData_OGL(shadowData_.Get());
     else
         return false;
 }
 
-void* VertexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
+void* VertexBuffer::MapBuffer_OGL(unsigned start, unsigned count, bool discard)
 {
     // Never called on OpenGL
     return nullptr;
 }
 
-void VertexBuffer::UnmapBuffer()
+void VertexBuffer::UnmapBuffer_OGL()
 {
     // Never called on OpenGL
 }

+ 89 - 0
Source/Urho3D/Graphics/RenderSurface.cpp

@@ -109,4 +109,93 @@ Viewport* RenderSurface::GetViewport(unsigned index) const
     return index < viewports_.Size() ? viewports_[index] : nullptr;
 }
 
+RenderSurface::RenderSurface(Texture* parentTexture)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+    {
+        Constructor_OGL(parentTexture);
+        return;
+    }
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+    {
+        Constructor_D3D9(parentTexture);
+        return;
+    }
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+    {
+        Constructor_D3D11(parentTexture);
+        return;
+    }
+#endif
+}
+
+bool RenderSurface::CreateRenderBuffer(unsigned width, unsigned height, unsigned format, int multiSample)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return CreateRenderBuffer_OGL(width, height, format, multiSample);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return CreateRenderBuffer_D3D9(width, height, format, multiSample);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return CreateRenderBuffer_D3D11(width, height, format, multiSample);
+#endif
+}
+
+void RenderSurface::OnDeviceLost()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return OnDeviceLost_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return OnDeviceLost_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return OnDeviceLost_D3D11();
+#endif
+}
+
+void RenderSurface::Release()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Release_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Release_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Release_D3D11();
+#endif
+}
+
 }

+ 21 - 0
Source/Urho3D/Graphics/RenderSurface.h

@@ -138,6 +138,27 @@ public:
     void SetResolveDirty(bool enable) { resolveDirty_ = enable; }
 
 private:
+#ifdef URHO3D_OPENGL
+    void Constructor_OGL(Texture* parentTexture);
+    bool CreateRenderBuffer_OGL(unsigned width, unsigned height, unsigned format, int multiSample);
+    void OnDeviceLost_OGL();
+    void Release_OGL();
+#endif // def URHO3D_OPENGL
+
+#ifdef URHO3D_D3D9
+    void Constructor_D3D9(Texture* parentTexture);
+    bool CreateRenderBuffer_D3D9(unsigned width, unsigned height, unsigned format, int multiSample);
+    void OnDeviceLost_D3D9();
+    void Release_D3D9();
+#endif // def URHO3D_D3D9
+
+#ifdef URHO3D_D3D11
+    void Constructor_D3D11(Texture* parentTexture);
+    bool CreateRenderBuffer_D3D11(unsigned width, unsigned height, unsigned format, int multiSample);
+    void OnDeviceLost_D3D11();
+    void Release_D3D11();
+#endif // def URHO3D_D3D11
+
     /// Parent texture.
     Texture* parentTexture_;
 

+ 42 - 30
Source/Urho3D/Graphics/Renderer.cpp

@@ -959,11 +959,14 @@ Texture2D* Renderer::GetShadowMap(Light* light, Camera* camera, unsigned viewWid
             newShadowMap->SetFilterMode(FILTER_BILINEAR);
             newShadowMap->SetShadowCompare(shadowMapUsage == TEXTURE_DEPTHSTENCIL);
 #endif
-#ifndef URHO3D_OPENGL
-            // Direct3D9: when shadow compare must be done manually, use nearest filtering so that the filtering of point lights
-            // and other shadowed lights matches
-            newShadowMap->SetFilterMode(graphics_->GetHardwareShadowSupport() ? FILTER_BILINEAR : FILTER_NEAREST);
-#endif
+
+            if (Graphics::GetGAPI() != GAPI_OPENGL)
+            {
+                // Direct3D9: when shadow compare must be done manually, use nearest filtering so that the filtering of point lights
+                // and other shadowed lights matches
+                newShadowMap->SetFilterMode(graphics_->GetHardwareShadowSupport() ? FILTER_BILINEAR : FILTER_NEAREST);
+            }
+
             // Create dummy color texture for the shadow map if necessary: Direct3D9, or OpenGL when working around an OS X +
             // Intel driver bug
             if (shadowMapUsage == TEXTURE_DEPTHSTENCIL && dummyColorFormat)
@@ -1048,7 +1051,7 @@ Texture* Renderer::GetScreenBuffer(int width, int height, unsigned format, int m
 #ifdef URHO3D_OPENGL
             // OpenGL hack: clear persistent floating point screen buffers to ensure the initial contents aren't illegal (NaN)?
             // Otherwise eg. the AutoExposure post process will not work correctly
-            if (persistentKey && Texture::GetDataType(format) == GL_FLOAT)
+            if (Graphics::GetGAPI() == GAPI_OPENGL && persistentKey && Texture::GetDataType_OGL(format) == GL_FLOAT)
             {
                 // Note: this loses current rendertarget assignment
                 graphics_->ResetRenderTargets();
@@ -1810,7 +1813,7 @@ void Renderer::CreateGeometries()
     pointLightGeometry_->SetIndexBuffer(plib);
     pointLightGeometry_->SetDrawRange(TRIANGLE_LIST, 0, plib->GetIndexCount());
 
-#if !defined(URHO3D_OPENGL) || !defined(GL_ES_VERSION_2_0)
+#if !defined(GL_ES_VERSION_2_0)
     if (graphics_->GetShadowMapFormat())
     {
         faceSelectCubeMap_ = new TextureCube(context_);
@@ -1854,17 +1857,20 @@ void Renderer::SetIndirectionTextureData()
         {
             for (unsigned x = 0; x < 256; ++x)
             {
-#ifdef URHO3D_OPENGL
-                dest[0] = (unsigned char)x;
-                dest[1] = (unsigned char)(255 - y);
-                dest[2] = faceX;
-                dest[3] = (unsigned char)(255 * 2 / 3 - faceY);
-#else
-                dest[0] = (unsigned char)x;
-                dest[1] = (unsigned char)y;
-                dest[2] = faceX;
-                dest[3] = faceY;
-#endif
+                if (Graphics::GetGAPI() == GAPI_OPENGL)
+                {
+                    dest[0] = (unsigned char)x;
+                    dest[1] = (unsigned char)(255 - y);
+                    dest[2] = faceX;
+                    dest[3] = (unsigned char)(255 * 2 / 3 - faceY);
+                }
+                else
+                {
+                    dest[0] = (unsigned char)x;
+                    dest[1] = (unsigned char)y;
+                    dest[2] = faceX;
+                    dest[3] = faceY;
+                }
                 dest += 4;
             }
         }
@@ -1914,25 +1920,31 @@ String Renderer::GetShadowVariations() const
     switch (shadowQuality_)
     {
         case SHADOWQUALITY_SIMPLE_16BIT:
-        #ifdef URHO3D_OPENGL
-            return "SIMPLE_SHADOW ";
-        #else
-            if (graphics_->GetHardwareShadowSupport())
+            if (Graphics::GetGAPI() == GAPI_OPENGL)
+            {
                 return "SIMPLE_SHADOW ";
+            }
             else
-                return "SIMPLE_SHADOW SHADOWCMP ";
-        #endif
+            {
+                if (graphics_->GetHardwareShadowSupport())
+                    return "SIMPLE_SHADOW ";
+                else
+                    return "SIMPLE_SHADOW SHADOWCMP ";
+            }
         case SHADOWQUALITY_SIMPLE_24BIT:
             return "SIMPLE_SHADOW ";
         case SHADOWQUALITY_PCF_16BIT:
-        #ifdef URHO3D_OPENGL
-            return "PCF_SHADOW ";
-        #else
-            if (graphics_->GetHardwareShadowSupport())
+            if (Graphics::GetGAPI() == GAPI_OPENGL)
+            {
                 return "PCF_SHADOW ";
+            }
             else
-                return "PCF_SHADOW SHADOWCMP ";
-        #endif
+            {
+                if (graphics_->GetHardwareShadowSupport())
+                    return "PCF_SHADOW ";
+                else
+                    return "PCF_SHADOW SHADOWCMP ";
+            }
         case SHADOWQUALITY_PCF_24BIT:
             return "PCF_SHADOW ";
         case SHADOWQUALITY_VSM:

+ 5 - 4
Source/Urho3D/Graphics/Shader.cpp

@@ -100,10 +100,11 @@ bool Shader::BeginLoad(Deserializer& source)
     CommentOutFunction(psSourceCode_, "void VS(");
 
     // OpenGL: rename either VS() or PS() to main()
-#ifdef URHO3D_OPENGL
-    vsSourceCode_.Replace("void VS(", "void main(");
-    psSourceCode_.Replace("void PS(", "void main(");
-#endif
+    if (Graphics::GetGAPI() == GAPI_OPENGL)
+    {
+        vsSourceCode_.Replace("void VS(", "void main(");
+        psSourceCode_.Replace("void PS(", "void main(");
+    }
 
     RefreshMemoryUse();
     return true;

+ 0 - 33
Source/Urho3D/Graphics/ShaderProgram.h

@@ -1,33 +0,0 @@
-//
-// Copyright (c) 2008-2022 the Urho3D project.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-//
-
-#pragma once
-
-// Note: ShaderProgram class is purposefully API-specific. It should not be used by Urho3D client applications.
-
-#if defined(URHO3D_OPENGL)
-#include "OpenGL/OGLShaderProgram.h"
-#elif defined(URHO3D_D3D11)
-#include "Direct3D11/D3D11ShaderProgram.h"
-#else
-#include "Direct3D9/D3D9ShaderProgram.h"
-#endif

+ 80 - 0
Source/Urho3D/Graphics/ShaderVariation.cpp

@@ -77,4 +77,84 @@ Shader* ShaderVariation::GetOwner() const
     return owner_;
 }
 
+void ShaderVariation::OnDeviceLost()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return OnDeviceLost_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return OnDeviceLost_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return OnDeviceLost_D3D11();
+#endif
+}
+
+void ShaderVariation::Release()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Release_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Release_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Release_D3D11();
+#endif
+}
+
+bool ShaderVariation::Create()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Create_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Create_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Create_D3D11();
+#endif
+}
+
+void ShaderVariation::SetDefines(const String& defines)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetDefines_OGL(defines);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetDefines_D3D9(defines);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetDefines_D3D11(defines);
+#endif
+}
+
 }

+ 55 - 6
Source/Urho3D/Graphics/ShaderVariation.h

@@ -137,20 +137,69 @@ public:
     /// Return defines with the CLIPPLANE define appended. Used internally on Direct3D11 only, will be empty on other APIs.
     const String& GetDefinesClipPlane() { return definesClipPlane_; }
 
+    /// OpenGL vertex semantic names. Used internally.
+    static const char* elementSemanticNames_OGL[];
+
     /// D3D11 vertex semantic names. Used internally.
-    static const char* elementSemanticNames[];
+    static const char* elementSemanticNames_D3D11[];
 
 private:
+
+    // Internal functions
+
+#ifdef URHO3D_D3D9
+    /// Load bytecode from a file. Return true if successful.
+    bool LoadByteCode_D3D9(const String& binaryShaderName);
+
+    /// Compile from source. Return true if successful.
+    bool Compile_D3D9();
+
+    /// Inspect the constant parameters and input layout (if applicable) from the shader bytecode.
+    void ParseParameters_D3D9(unsigned char* bufData, unsigned bufSize);
+
+    /// Save bytecode to a file.
+    void SaveByteCode_D3D9(const String& binaryShaderName);
+#endif // def URHO3D_D3D9
+
+#ifdef URHO3D_D3D11
     /// Load bytecode from a file. Return true if successful.
-    bool LoadByteCode(const String& binaryShaderName);
+    bool LoadByteCode_D3D11(const String& binaryShaderName);
+
     /// Compile from source. Return true if successful.
-    bool Compile();
+    bool Compile_D3D11();
+
     /// Inspect the constant parameters and input layout (if applicable) from the shader bytecode.
-    void ParseParameters(unsigned char* bufData, unsigned bufSize);
+    void ParseParameters_D3D11(unsigned char* bufData, unsigned bufSize);
+
     /// Save bytecode to a file.
-    void SaveByteCode(const String& binaryShaderName);
+    void SaveByteCode_D3D11(const String& binaryShaderName);
+    
     /// Calculate constant buffer sizes from parameters.
-    void CalculateConstantBufferSizes();
+    void CalculateConstantBufferSizes_D3D11();
+#endif // def URHO3D_D3D11
+
+    // For proxy functions
+
+#ifdef URHO3D_OPENGL
+    void OnDeviceLost_OGL();
+    void Release_OGL();
+    bool Create_OGL();
+    void SetDefines_OGL(const String& defines);
+#endif // def URHO3D_OPENGL
+
+#ifdef URHO3D_D3D9
+    void OnDeviceLost_D3D9();
+    void Release_D3D9();
+    bool Create_D3D9();
+    void SetDefines_D3D9(const String& defines);
+#endif // def URHO3D_D3D9
+
+#ifdef URHO3D_D3D11
+    void OnDeviceLost_D3D11();
+    void Release_D3D11();
+    bool Create_D3D11();
+    void SetDefines_D3D11(const String& defines);
+#endif // def URHO3D_D3D11
 
     /// Shader this variation belongs to.
     WeakPtr<Shader> owner_;

+ 120 - 0
Source/Urho3D/Graphics/Texture.cpp

@@ -284,4 +284,124 @@ void Texture::CheckTextureBudget(StringHash type)
         cache->ReleaseResources(Material::GetTypeStatic());
 }
 
+void Texture::SetSRGB(bool enable)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetSRGB_OGL(enable);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetSRGB_D3D9(enable);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetSRGB_D3D11(enable);
+#endif
+}
+
+void Texture::UpdateParameters()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return UpdateParameters_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return UpdateParameters_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return UpdateParameters_D3D11();
+#endif
+}
+
+bool Texture::GetParametersDirty() const
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetParametersDirty_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetParametersDirty_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetParametersDirty_D3D11();
+#endif
+}
+
+bool Texture::IsCompressed() const
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return IsCompressed_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return IsCompressed_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return IsCompressed_D3D11();
+#endif
+}
+
+unsigned Texture::GetRowDataSize(int width) const
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetRowDataSize_OGL(width);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetRowDataSize_D3D9(width);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetRowDataSize_D3D11(width);
+#endif
+}
+
+void Texture::RegenerateLevels()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return RegenerateLevels_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return RegenerateLevels_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return RegenerateLevels_D3D11();
+#endif
+}
+
 }

+ 52 - 15
Source/Urho3D/Graphics/Texture.h

@@ -192,10 +192,6 @@ public:
     /// Return texture's target. Only used on OpenGL.
     unsigned GetTarget() const { return target_; }
 
-    /// Convert format to sRGB. Not used on Direct3D9.
-    /// @nobind
-    unsigned GetSRGBFormat(unsigned format);
-
     /// Set or clear the need resolve flag. Called internally by Graphics.
     void SetResolveDirty(bool enable) { resolveDirty_ = enable; }
 
@@ -208,20 +204,61 @@ public:
     static unsigned CheckMaxLevels(int width, int height, unsigned requestedLevels);
     /// Check maximum allowed mip levels for a specific 3D texture size.
     static unsigned CheckMaxLevels(int width, int height, int depth, unsigned requestedLevels);
-    /// Return the shader resource view format corresponding to a texture format. Handles conversion of typeless depth texture formats. Only used on Direct3D11.
-    /// @nobind
-    static unsigned GetSRVFormat(unsigned format);
-    /// Return the depth-stencil view format corresponding to a texture format. Handles conversion of typeless depth texture formats. Only used on Direct3D11.
-    /// @nobind
-    static unsigned GetDSVFormat(unsigned format);
-    /// Return the non-internal texture format corresponding to an OpenGL internal format.
-    /// @nobind
-    static unsigned GetExternalFormat(unsigned format);
+
+#ifdef URHO3D_OPENGL
     /// Return the data type corresponding to an OpenGL internal format.
-    /// @nobind
-    static unsigned GetDataType(unsigned format);
+    static unsigned GetDataType_OGL(unsigned format);
+#endif
 
 protected:
+#ifdef URHO3D_OPENGL
+    /// Convert format to sRGB. Not used on Direct3D9.
+    unsigned GetSRGBFormat_OGL(unsigned format);
+
+    /// Return the non-internal texture format corresponding to an OpenGL internal format.
+    static unsigned GetExternalFormat_OGL(unsigned format);
+#endif // def URHO3D_OPENGL
+
+#ifdef URHO3D_D3D11
+    /// Convert format to sRGB. Not used on Direct3D9.
+    unsigned GetSRGBFormat_D3D11(unsigned format);
+
+    /// Return the shader resource view format corresponding to a texture format. Handles conversion of typeless depth texture formats. Only used on Direct3D11.
+    static unsigned GetSRVFormat_D3D11(unsigned format);
+
+    /// Return the depth-stencil view format corresponding to a texture format. Handles conversion of typeless depth texture formats. Only used on Direct3D11.
+    static unsigned GetDSVFormat_D3D11(unsigned format);
+#endif // def URHO3D_D3D11
+
+    // For proxy functions
+
+#ifdef URHO3D_OPENGL
+    void SetSRGB_OGL(bool enable);
+    void UpdateParameters_OGL();
+    bool GetParametersDirty_OGL() const;
+    bool IsCompressed_OGL() const;
+    unsigned GetRowDataSize_OGL(int width) const;
+    void RegenerateLevels_OGL();
+#endif // def URHO3D_OPENGL
+
+#ifdef URHO3D_D3D9
+    void SetSRGB_D3D9(bool enable);
+    void UpdateParameters_D3D9();
+    bool GetParametersDirty_D3D9() const;
+    bool IsCompressed_D3D9() const;
+    unsigned GetRowDataSize_D3D9(int width) const;
+    void RegenerateLevels_D3D9();
+#endif // def URHO3D_D3D9
+
+#ifdef URHO3D_D3D11
+    void SetSRGB_D3D11(bool enable);
+    void UpdateParameters_D3D11();
+    bool GetParametersDirty_D3D11() const;
+    bool IsCompressed_D3D11() const;
+    unsigned GetRowDataSize_D3D11(int width) const;
+    void RegenerateLevels_D3D11();
+#endif // def URHO3D_D3D11
+
     /// Check whether texture memory budget has been exceeded. Free unused materials in that case to release the texture references.
     void CheckTextureBudget(StringHash type);
     /// Create the GPU texture. Implemented in subclasses.

+ 142 - 1
Source/Urho3D/Graphics/Texture2D.cpp

@@ -43,7 +43,8 @@ Texture2D::Texture2D(Context* context) :
     Texture(context)
 {
 #ifdef URHO3D_OPENGL
-    target_ = GL_TEXTURE_2D;
+    if (Graphics::GetGAPI() == GAPI_OPENGL)
+        target_ = GL_TEXTURE_2D;
 #endif
 }
 
@@ -192,4 +193,144 @@ void Texture2D::HandleRenderSurfaceUpdate(StringHash eventType, VariantMap& even
     }
 }
 
+void Texture2D::OnDeviceLost()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return OnDeviceLost_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return OnDeviceLost_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return OnDeviceLost_D3D11();
+#endif
+}
+
+void Texture2D::OnDeviceReset()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return OnDeviceReset_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return OnDeviceReset_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return OnDeviceReset_D3D11();
+#endif
+}
+
+void Texture2D::Release()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Release_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Release_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Release_D3D11();
+#endif
+}
+
+bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, const void* data)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetData_OGL(level, x, y, width, height, data);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetData_D3D9(level, x, y, width, height, data);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetData_D3D11(level, x, y, width, height, data);
+#endif
+}
+
+bool Texture2D::SetData(Image* image, bool useAlpha)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetData_OGL(image, useAlpha);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetData_D3D9(image, useAlpha);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetData_D3D11(image, useAlpha);
+#endif
+}
+
+bool Texture2D::GetData(unsigned level, void* dest) const
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetData_OGL(level, dest);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetData_D3D9(level, dest);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetData_D3D11(level, dest);
+#endif
+}
+
+bool Texture2D::Create()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Create_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Create_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Create_D3D11();
+#endif
+}
+
 }

+ 30 - 0
Source/Urho3D/Graphics/Texture2D.h

@@ -83,6 +83,36 @@ protected:
     bool Create() override;
 
 private:
+#ifdef URHO3D_OPENGL
+    void OnDeviceLost_OGL();
+    void OnDeviceReset_OGL();
+    void Release_OGL();
+    bool SetData_OGL(unsigned level, int x, int y, int width, int height, const void* data);
+    bool SetData_OGL(Image* image, bool useAlpha);
+    bool GetData_OGL(unsigned level, void* dest) const;
+    bool Create_OGL();
+#endif // def URHO3D_OPENGL
+
+#ifdef URHO3D_D3D9
+    void OnDeviceLost_D3D9();
+    void OnDeviceReset_D3D9();
+    void Release_D3D9();
+    bool SetData_D3D9(unsigned level, int x, int y, int width, int height, const void* data);
+    bool SetData_D3D9(Image* image, bool useAlpha);
+    bool GetData_D3D9(unsigned level, void* dest) const;
+    bool Create_D3D9();
+#endif // def URHO3D_D3D9
+
+#ifdef URHO3D_D3D11
+    void OnDeviceLost_D3D11();
+    void OnDeviceReset_D3D11();
+    void Release_D3D11();
+    bool SetData_D3D11(unsigned level, int x, int y, int width, int height, const void* data);
+    bool SetData_D3D11(Image* image, bool useAlpha);
+    bool GetData_D3D11(unsigned level, void* dest) const;
+    bool Create_D3D11();
+#endif // def URHO3D_D3D11
+
     /// Handle render surface update event.
     void HandleRenderSurfaceUpdate(StringHash eventType, VariantMap& eventData);
 

+ 162 - 1
Source/Urho3D/Graphics/Texture2DArray.cpp

@@ -48,7 +48,8 @@ Texture2DArray::Texture2DArray(Context* context) :
 {
 #ifdef URHO3D_OPENGL
 #ifndef GL_ES_VERSION_2_0
-    target_ = GL_TEXTURE_2D_ARRAY;
+    if (Graphics::GetGAPI() == GAPI_OPENGL)
+        target_ = GL_TEXTURE_2D_ARRAY;
 #endif
 #endif
 }
@@ -206,4 +207,164 @@ void Texture2DArray::HandleRenderSurfaceUpdate(StringHash eventType, VariantMap&
     }
 }
 
+void Texture2DArray::OnDeviceLost()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return OnDeviceLost_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return OnDeviceLost_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return OnDeviceLost_D3D11();
+#endif
+}
+
+void Texture2DArray::OnDeviceReset()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return OnDeviceReset_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return OnDeviceReset_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return OnDeviceReset_D3D11();
+#endif
+}
+
+void Texture2DArray::Release()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Release_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Release_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Release_D3D11();
+#endif
+}
+
+bool Texture2DArray::SetData(unsigned layer, unsigned level, int x, int y, int width, int height, const void* data)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetData_OGL(layer, level, x, y, width, height, data);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetData_D3D9(layer, level, x, y, width, height, data);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetData_D3D11(layer, level, x, y, width, height, data);
+#endif
+}
+
+bool Texture2DArray::SetData(unsigned layer, Deserializer& source)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetData_OGL(layer, source);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetData_D3D9(layer, source);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetData_D3D11(layer, source);
+#endif
+}
+
+bool Texture2DArray::SetData(unsigned layer, Image* image, bool useAlpha)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetData_OGL(layer, image, useAlpha);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetData_D3D9(layer, image, useAlpha);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetData_D3D11(layer, image, useAlpha);
+#endif
+}
+
+bool Texture2DArray::GetData(unsigned layer, unsigned level, void* dest) const
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetData_OGL(layer, level, dest);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetData_D3D9(layer, level, dest);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetData_D3D11(layer, level, dest);
+#endif
+}
+
+bool Texture2DArray::Create()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Create_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Create_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Create_D3D11();
+#endif
+}
+
 }

+ 33 - 0
Source/Urho3D/Graphics/Texture2DArray.h

@@ -83,6 +83,39 @@ protected:
     bool Create() override;
 
 private:
+#ifdef URHO3D_OPENGL
+    void OnDeviceLost_OGL();
+    void OnDeviceReset_OGL();
+    void Release_OGL();
+    bool SetData_OGL(unsigned layer, unsigned level, int x, int y, int width, int height, const void* data);
+    bool SetData_OGL(unsigned layer, Deserializer& source);
+    bool SetData_OGL(unsigned layer, Image* image, bool useAlpha = false);
+    bool GetData_OGL(unsigned layer, unsigned level, void* dest) const;
+    bool Create_OGL();
+#endif // def URHO3D_OPENGL
+
+#ifdef URHO3D_D3D9
+    void OnDeviceLost_D3D9();
+    void OnDeviceReset_D3D9();
+    void Release_D3D9();
+    bool SetData_D3D9(unsigned layer, unsigned level, int x, int y, int width, int height, const void* data);
+    bool SetData_D3D9(unsigned layer, Deserializer& source);
+    bool SetData_D3D9(unsigned layer, Image* image, bool useAlpha = false);
+    bool GetData_D3D9(unsigned layer, unsigned level, void* dest) const;
+    bool Create_D3D9();
+#endif // def URHO3D_D3D9
+
+#ifdef URHO3D_D3D11
+    void OnDeviceLost_D3D11();
+    void OnDeviceReset_D3D11();
+    void Release_D3D11();
+    bool SetData_D3D11(unsigned layer, unsigned level, int x, int y, int width, int height, const void* data);
+    bool SetData_D3D11(unsigned layer, Deserializer& source);
+    bool SetData_D3D11(unsigned layer, Image* image, bool useAlpha = false);
+    bool GetData_D3D11(unsigned layer, unsigned level, void* dest) const;
+    bool Create_D3D11();
+#endif // def URHO3D_D3D11
+
     /// Handle render surface update event.
     void HandleRenderSurfaceUpdate(StringHash eventType, VariantMap& eventData);
 

+ 142 - 1
Source/Urho3D/Graphics/Texture3D.cpp

@@ -44,7 +44,8 @@ Texture3D::Texture3D(Context* context) :
 {
 #ifdef URHO3D_OPENGL
 #ifndef GL_ES_VERSION_2_0
-    target_ = GL_TEXTURE_3D;
+    if (Graphics::GetGAPI() == GAPI_OPENGL)
+        target_ = GL_TEXTURE_3D;
 #endif
 #endif
 }
@@ -179,4 +180,144 @@ bool Texture3D::SetSize(int width, int height, int depth, unsigned format, Textu
     return Create();
 }
 
+void Texture3D::OnDeviceLost()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return OnDeviceLost_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return OnDeviceLost_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return OnDeviceLost_D3D11();
+#endif
+}
+
+void Texture3D::OnDeviceReset()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return OnDeviceReset_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return OnDeviceReset_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return OnDeviceReset_D3D11();
+#endif
+}
+
+void Texture3D::Release()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Release_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Release_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Release_D3D11();
+#endif
+}
+
+bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int height, int depth, const void* data)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetData_OGL(level, x, y, z, width, height, depth, data);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetData_D3D9(level, x, y, z, width, height, depth, data);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetData_D3D11(level, x, y, z, width, height, depth, data);
+#endif
+}
+
+bool Texture3D::SetData(Image* image, bool useAlpha)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetData_OGL(image, useAlpha);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetData_D3D9(image, useAlpha);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetData_D3D11(image, useAlpha);
+#endif
+}
+
+bool Texture3D::GetData(unsigned level, void* dest) const
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetData_OGL(level, dest);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetData_D3D9(level, dest);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetData_D3D11(level, dest);
+#endif
+}
+
+bool Texture3D::Create()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Create_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Create_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Create_D3D11();
+#endif
+}
+
 }

+ 30 - 0
Source/Urho3D/Graphics/Texture3D.h

@@ -70,6 +70,36 @@ protected:
     bool Create() override;
 
 private:
+#ifdef URHO3D_OPENGL
+    void OnDeviceLost_OGL();
+    void OnDeviceReset_OGL();
+    void Release_OGL();
+    bool SetData_OGL(unsigned level, int x, int y, int z, int width, int height, int depth, const void* data);
+    bool SetData_OGL(Image* image, bool useAlpha);
+    bool GetData_OGL(unsigned level, void* dest) const;
+    bool Create_OGL();
+#endif // def URHO3D_OPENGL
+
+#ifdef URHO3D_D3D9
+    void OnDeviceLost_D3D9();
+    void OnDeviceReset_D3D9();
+    void Release_D3D9();
+    bool SetData_D3D9(unsigned level, int x, int y, int z, int width, int height, int depth, const void* data);
+    bool SetData_D3D9(Image* image, bool useAlpha);
+    bool GetData_D3D9(unsigned level, void* dest) const;
+    bool Create_D3D9();
+#endif // def URHO3D_D3D9
+
+#ifdef URHO3D_D3D11
+    void OnDeviceLost_D3D11();
+    void OnDeviceReset_D3D11();
+    void Release_D3D11();
+    bool SetData_D3D11(unsigned level, int x, int y, int z, int width, int height, int depth, const void* data);
+    bool SetData_D3D11(Image* image, bool useAlpha);
+    bool GetData_D3D11(unsigned level, void* dest) const;
+    bool Create_D3D11();
+#endif // def URHO3D_D3D11
+
     /// Image file acquired during BeginLoad.
     SharedPtr<Image> loadImage_;
     /// Parameter file acquired during BeginLoad.

+ 164 - 2
Source/Urho3D/Graphics/TextureCube.cpp

@@ -62,7 +62,8 @@ TextureCube::TextureCube(Context* context) :
     Texture(context)
 {
 #ifdef URHO3D_OPENGL
-    target_ = GL_TEXTURE_CUBE_MAP;
+    if (Graphics::GetGAPI() == GAPI_OPENGL)
+        target_ = GL_TEXTURE_CUBE_MAP;
 #endif
 
     // Default to clamp mode addressing
@@ -290,7 +291,8 @@ bool TextureCube::SetSize(int size, unsigned format, TextureUsage usage, int mul
         {
             renderSurfaces_[i] = new RenderSurface(this);
 #ifdef URHO3D_OPENGL
-            renderSurfaces_[i]->target_ = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i;
+            if (Graphics::GetGAPI() == GAPI_OPENGL)
+                renderSurfaces_[i]->target_ = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i;
 #endif
         }
 
@@ -348,4 +350,164 @@ void TextureCube::HandleRenderSurfaceUpdate(StringHash eventType, VariantMap& ev
     }
 }
 
+void TextureCube::OnDeviceLost()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return OnDeviceLost_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return OnDeviceLost_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return OnDeviceLost_D3D11();
+#endif
+}
+
+void TextureCube::OnDeviceReset()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return OnDeviceReset_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return OnDeviceReset_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return OnDeviceReset_D3D11();
+#endif
+}
+
+void TextureCube::Release()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Release_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Release_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Release_D3D11();
+#endif
+}
+
+bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int width, int height, const void* data)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetData_OGL(face, level, x, y, width, height, data);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetData_D3D9(face, level, x, y, width, height, data);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetData_D3D11(face, level, x, y, width, height, data);
+#endif
+}
+
+bool TextureCube::SetData(CubeMapFace face, Deserializer& source)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetData_OGL(face, source);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetData_D3D9(face, source);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetData_D3D11(face, source);
+#endif
+}
+
+bool TextureCube::SetData(CubeMapFace face, Image* image, bool useAlpha)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetData_OGL(face, image, useAlpha);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetData_D3D9(face, image, useAlpha);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetData_D3D11(face, image, useAlpha);
+#endif
+}
+
+bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return GetData_OGL(face, level, dest);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return GetData_D3D9(face, level, dest);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return GetData_D3D11(face, level, dest);
+#endif
+}
+
+bool TextureCube::Create()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Create_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Create_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Create_D3D11();
+#endif
+}
+
 }

+ 33 - 0
Source/Urho3D/Graphics/TextureCube.h

@@ -80,6 +80,39 @@ protected:
     bool Create() override;
 
 private:
+#ifdef URHO3D_OPENGL
+    void OnDeviceLost_OGL();
+    void OnDeviceReset_OGL();
+    void Release_OGL();
+    bool SetData_OGL(CubeMapFace face, unsigned level, int x, int y, int width, int height, const void* data);
+    bool SetData_OGL(CubeMapFace face, Deserializer& source);
+    bool SetData_OGL(CubeMapFace face, Image* image, bool useAlpha = false);
+    bool GetData_OGL(CubeMapFace face, unsigned level, void* dest) const;
+    bool Create_OGL();
+#endif // def URHO3D_OPENGL
+
+#ifdef URHO3D_D3D9
+    void OnDeviceLost_D3D9();
+    void OnDeviceReset_D3D9();
+    void Release_D3D9();
+    bool SetData_D3D9(CubeMapFace face, unsigned level, int x, int y, int width, int height, const void* data);
+    bool SetData_D3D9(CubeMapFace face, Deserializer& source);
+    bool SetData_D3D9(CubeMapFace face, Image* image, bool useAlpha = false);
+    bool GetData_D3D9(CubeMapFace face, unsigned level, void* dest) const;
+    bool Create_D3D9();
+#endif // def URHO3D_D3D9
+
+#ifdef URHO3D_D3D11
+    void OnDeviceLost_D3D11();
+    void OnDeviceReset_D3D11();
+    void Release_D3D11();
+    bool SetData_D3D11(CubeMapFace face, unsigned level, int x, int y, int width, int height, const void* data);
+    bool SetData_D3D11(CubeMapFace face, Deserializer& source);
+    bool SetData_D3D11(CubeMapFace face, Image* image, bool useAlpha = false);
+    bool GetData_D3D11(CubeMapFace face, unsigned level, void* dest) const;
+    bool Create_D3D11();
+#endif // def URHO3D_D3D11
+
     /// Handle render surface update event.
     void HandleRenderSurfaceUpdate(StringHash eventType, VariantMap& eventData);
 

+ 220 - 0
Source/Urho3D/Graphics/VertexBuffer.cpp

@@ -204,4 +204,224 @@ void VertexBuffer::UpdateOffsets(PODVector<VertexElement>& elements)
     }
 }
 
+void VertexBuffer::OnDeviceLost()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return OnDeviceLost_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return OnDeviceLost_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return OnDeviceLost_D3D11();
+#endif
+}
+
+void VertexBuffer::OnDeviceReset()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return OnDeviceReset_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return OnDeviceReset_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return OnDeviceReset_D3D11();
+#endif
+}
+
+void VertexBuffer::Release()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Release_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Release_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Release_D3D11();
+#endif
+}
+
+bool VertexBuffer::SetData(const void* data)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetData_OGL(data);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetData_D3D9(data);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetData_D3D11(data);
+#endif
+}
+
+bool VertexBuffer::SetDataRange(const void* data, unsigned start, unsigned count, bool discard)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return SetDataRange_OGL(data, start, count, discard);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return SetDataRange_D3D9(data, start, count, discard);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return SetDataRange_D3D11(data, start, count, discard);
+#endif
+}
+
+void* VertexBuffer::Lock(unsigned start, unsigned count, bool discard)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Lock_OGL(start, count, discard);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Lock_D3D9(start, count, discard);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Lock_D3D11(start, count, discard);
+#endif
+}
+
+void VertexBuffer::Unlock()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Unlock_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Unlock_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Unlock_D3D11();
+#endif
+}
+
+bool VertexBuffer::Create()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return Create_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return Create_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return Create_D3D11();
+#endif
+}
+
+bool VertexBuffer::UpdateToGPU()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return UpdateToGPU_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return UpdateToGPU_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return UpdateToGPU_D3D11();
+#endif
+}
+
+void* VertexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return MapBuffer_OGL(start, count, discard);
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return MapBuffer_D3D9(start, count, discard);
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return MapBuffer_D3D11(start, count, discard);
+#endif
+}
+
+void VertexBuffer::UnmapBuffer()
+{
+    GAPI gapi = Graphics::GetGAPI();
+
+#ifdef URHO3D_OPENGL
+    if (gapi == GAPI_OPENGL)
+        return UnmapBuffer_OGL();
+#endif
+
+#ifdef URHO3D_D3D9
+    if (gapi == GAPI_D3D9)
+        return UnmapBuffer_D3D9();
+#endif
+
+#ifdef URHO3D_D3D11
+    if (gapi == GAPI_D3D11)
+        return UnmapBuffer_D3D11();
+#endif
+}
+
 }

+ 42 - 0
Source/Urho3D/Graphics/VertexBuffer.h

@@ -151,6 +151,48 @@ private:
     /// Unmap the GPU buffer. Not used on OpenGL.
     void UnmapBuffer();
 
+#ifdef URHO3D_OPENGL
+    void OnDeviceLost_OGL();
+    void OnDeviceReset_OGL();
+    void Release_OGL();
+    bool SetData_OGL(const void* data);
+    bool SetDataRange_OGL(const void* data, unsigned start, unsigned count, bool discard = false);
+    void* Lock_OGL(unsigned start, unsigned count, bool discard);
+    void Unlock_OGL();
+    bool Create_OGL();
+    bool UpdateToGPU_OGL();
+    void* MapBuffer_OGL(unsigned start, unsigned count, bool discard);
+    void UnmapBuffer_OGL();
+#endif // def URHO3D_OPENGL
+
+#ifdef URHO3D_D3D9
+    void OnDeviceLost_D3D9();
+    void OnDeviceReset_D3D9();
+    void Release_D3D9();
+    bool SetData_D3D9(const void* data);
+    bool SetDataRange_D3D9(const void* data, unsigned start, unsigned count, bool discard = false);
+    void* Lock_D3D9(unsigned start, unsigned count, bool discard);
+    void Unlock_D3D9();
+    bool Create_D3D9();
+    bool UpdateToGPU_D3D9();
+    void* MapBuffer_D3D9(unsigned start, unsigned count, bool discard);
+    void UnmapBuffer_D3D9();
+#endif // def URHO3D_D3D9
+
+#ifdef URHO3D_D3D11
+    void OnDeviceLost_D3D11();
+    void OnDeviceReset_D3D11();
+    void Release_D3D11();
+    bool SetData_D3D11(const void* data);
+    bool SetDataRange_D3D11(const void* data, unsigned start, unsigned count, bool discard = false);
+    void* Lock_D3D11(unsigned start, unsigned count, bool discard);
+    void Unlock_D3D11();
+    bool Create_D3D11();
+    bool UpdateToGPU_D3D11();
+    void* MapBuffer_D3D11(unsigned start, unsigned count, bool discard);
+    void UnmapBuffer_D3D11();
+#endif // def URHO3D_D3D11
+
     /// Shadow data.
     SharedArrayPtr<unsigned char> shadowData_;
     /// Number of vertices.

+ 0 - 31
Source/Urho3D/Graphics/VertexDeclaration.h

@@ -1,31 +0,0 @@
-//
-// Copyright (c) 2008-2022 the Urho3D project.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-//
-
-#pragma once
-
-#if defined(URHO3D_OPENGL)
-//#error OpenGL Graphics API does not have VertexDeclaration class, remove this header file in your build to fix this error
-#elif defined(URHO3D_D3D11)
-#include "Direct3D11/D3D11VertexDeclaration.h"
-#else
-#include "Direct3D9/D3D9VertexDeclaration.h"
-#endif

+ 94 - 79
Source/Urho3D/Graphics/View.cpp

@@ -319,13 +319,11 @@ bool View::Define(RenderSurface* renderTarget, Viewport* viewport)
     rtSize_ = IntVector2(rtWidth, rtHeight);
 
     // On OpenGL flip the viewport if rendering to a texture for consistent UV addressing with Direct3D9
-#ifdef URHO3D_OPENGL
-    if (renderTarget_)
+    if (Graphics::GetGAPI() == GAPI_OPENGL && renderTarget_)
     {
         viewRect_.bottom_ = rtHeight - viewRect_.top_;
         viewRect_.top_ = viewRect_.bottom_ - viewSize_.y_;
     }
-#endif
 
     scene_ = viewport->GetScene();
     cullCamera_ = viewport->GetCullCamera();
@@ -375,27 +373,28 @@ bool View::Define(RenderSurface* renderTarget, Viewport* viewport)
     scenePasses_.Clear();
     geometriesUpdated_ = false;
 
-#ifdef URHO3D_OPENGL
+    if (Graphics::GetGAPI() == GAPI_OPENGL)
+    {
 #ifdef GL_ES_VERSION_2_0
-    // On OpenGL ES we assume a stencil is not available or would not give a good performance, and disable light stencil
-    // optimizations in any case
-    noStencil_ = true;
+        // On OpenGL ES we assume a stencil is not available or would not give a good performance, and disable light stencil
+        // optimizations in any case
+        noStencil_ = true;
 #else
-    for (unsigned i = 0; i < renderPath_->commands_.Size(); ++i)
-    {
-        const RenderPathCommand& command = renderPath_->commands_[i];
-        if (!command.enabled_)
-            continue;
-        if (command.depthStencilName_.Length())
+        for (unsigned i = 0; i < renderPath_->commands_.Size(); ++i)
         {
-            // Using a readable depth texture will disable light stencil optimizations on OpenGL, as for compatibility reasons
-            // we are using a depth format without stencil channel
-            noStencil_ = true;
-            break;
+            const RenderPathCommand& command = renderPath_->commands_[i];
+            if (!command.enabled_)
+                continue;
+            if (command.depthStencilName_.Length())
+            {
+                // Using a readable depth texture will disable light stencil optimizations on OpenGL, as for compatibility reasons
+                // we are using a depth format without stencil channel
+                noStencil_ = true;
+                break;
+            }
         }
-    }
-#endif
 #endif
+    }
 
     // Make sure that all necessary batch queues exist
     for (unsigned i = 0; i < renderPath_->commands_.Size(); ++i)
@@ -596,8 +595,7 @@ void View::Render()
     }
 #endif
 
-#ifdef URHO3D_OPENGL
-    if (renderTarget_)
+    if (Graphics::GetGAPI() == GAPI_OPENGL && renderTarget_)
     {
         // On OpenGL, flip the projection if rendering to a texture so that the texture can be addressed in the same way
         // as a render texture produced on Direct3D9
@@ -608,7 +606,6 @@ void View::Render()
         if (camera_)
             camera_->SetFlipVertical(!camera_->GetFlipVertical());
     }
-#endif
 
     // Render
     ExecuteRenderPathCommands();
@@ -654,14 +651,12 @@ void View::Render()
         }
     }
 
-#ifdef URHO3D_OPENGL
-    if (renderTarget_)
+    if (Graphics::GetGAPI() == GAPI_OPENGL && renderTarget_)
     {
         // Restores original setting of FlipVertical when flipped by code above.
         if (camera_)
             camera_->SetFlipVertical(!camera_->GetFlipVertical());
     }
-#endif
 
     // Run framebuffer blitting if necessary. If scene was resolved from backbuffer, do not touch depth
     // (backbuffer should contain proper depth already)
@@ -724,15 +719,20 @@ void View::SetCameraShaderParameters(Camera* camera)
     if (camera->IsOrthographic())
     {
         depthMode.x_ = 1.0f;
-#ifdef URHO3D_OPENGL
-        depthMode.z_ = 0.5f;
-        depthMode.w_ = 0.5f;
-#else
-        depthMode.z_ = 1.0f;
-#endif
+        if (Graphics::GetGAPI() == GAPI_OPENGL)
+        {
+            depthMode.z_ = 0.5f;
+            depthMode.w_ = 0.5f;
+        }
+        else
+        {
+            depthMode.z_ = 1.0f;
+        }
     }
     else
+    {
         depthMode.w_ = 1.0f / camera->GetFarClip();
+    }
 
     graphics_->SetShaderParameter(VSP_DEPTHMODE, depthMode);
 
@@ -746,12 +746,14 @@ void View::SetCameraShaderParameters(Camera* camera)
     graphics_->SetShaderParameter(VSP_FRUSTUMSIZE, farVector);
 
     Matrix4 projection = camera->GetGPUProjection();
-#ifdef URHO3D_OPENGL
-    // Add constant depth bias manually to the projection matrix due to glPolygonOffset() inconsistency
-    float constantBias = 2.0f * graphics_->GetDepthConstantBias();
-    projection.m22_ += projection.m32_ * constantBias;
-    projection.m23_ += projection.m33_ * constantBias;
-#endif
+
+    if (Graphics::GetGAPI() == GAPI_OPENGL)
+    {
+        // Add constant depth bias manually to the projection matrix due to glPolygonOffset() inconsistency
+        float constantBias = 2.0f * graphics_->GetDepthConstantBias();
+        projection.m22_ += projection.m32_ * constantBias;
+        projection.m23_ += projection.m33_ * constantBias;
+    }
 
     graphics_->SetShaderParameter(VSP_VIEWPROJ, projection * camera->GetView());
 
@@ -774,14 +776,20 @@ void View::SetGBufferShaderParameters(const IntVector2& texSize, const IntRect&
     float widthRange = 0.5f * viewRect.Width() / texWidth;
     float heightRange = 0.5f * viewRect.Height() / texHeight;
 
-#ifdef URHO3D_OPENGL
-    Vector4 bufferUVOffset(((float)viewRect.left_) / texWidth + widthRange,
-        1.0f - (((float)viewRect.top_) / texHeight + heightRange), widthRange, heightRange);
-#else
-    const Vector2& pixelUVOffset = Graphics::GetPixelUVOffset();
-    Vector4 bufferUVOffset((pixelUVOffset.x_ + (float)viewRect.left_) / texWidth + widthRange,
-        (pixelUVOffset.y_ + (float)viewRect.top_) / texHeight + heightRange, widthRange, heightRange);
-#endif
+    Vector4 bufferUVOffset;
+
+    if (Graphics::GetGAPI() == GAPI_OPENGL)
+    {
+        bufferUVOffset = Vector4(((float)viewRect.left_) / texWidth + widthRange,
+            1.0f - (((float)viewRect.top_) / texHeight + heightRange), widthRange, heightRange);
+    }
+    else
+    {
+        const Vector2& pixelUVOffset = Graphics::GetPixelUVOffset();
+        bufferUVOffset = Vector4((pixelUVOffset.x_ + (float)viewRect.left_) / texWidth + widthRange,
+            (pixelUVOffset.y_ + (float)viewRect.top_) / texHeight + heightRange, widthRange, heightRange);
+    }
+
     graphics_->SetShaderParameter(VSP_GBUFFEROFFSETS, bufferUVOffset);
 
     float invSizeX = 1.0f / texWidth;
@@ -1550,12 +1558,16 @@ void View::ExecuteRenderPathCommands()
                     // If the render path ends into a quad, it can be redirected to the final render target
                     // However, on OpenGL we can not reliably do this in case the final target is the backbuffer, and we want to
                     // render depth buffer sensitive debug geometry afterward (backbuffer and textures can not share depth)
-#ifndef URHO3D_OPENGL
-                    if (i == lastCommandIndex && command.type_ == CMD_QUAD)
-#else
-                    if (i == lastCommandIndex && command.type_ == CMD_QUAD && renderTarget_)
-#endif
-                        currentRenderTarget_ = renderTarget_;
+                    if (Graphics::GetGAPI() != GAPI_OPENGL)
+                    {
+                        if (i == lastCommandIndex && command.type_ == CMD_QUAD)
+                            currentRenderTarget_ = renderTarget_;
+                    }
+                    else
+                    {
+                        if (i == lastCommandIndex && command.type_ == CMD_QUAD && renderTarget_)
+                            currentRenderTarget_ = renderTarget_;
+                    }
                 }
                 else
                     currentRenderTarget_ = substituteRenderTarget_ ? substituteRenderTarget_ : renderTarget_;
@@ -1750,14 +1762,14 @@ void View::SetRenderTargets(RenderPathCommand& command)
             {
                 useColorWrite = false;
                 useCustomDepth = true;
-#if !defined(URHO3D_OPENGL) && !defined(URHO3D_D3D11)
+
                 // On D3D9 actual depth-only rendering is illegal, we need a color rendertarget
-                if (!depthOnlyDummyTexture_)
+                if (Graphics::GetGAPI() == GAPI_D3D9 && !depthOnlyDummyTexture_)
                 {
                     depthOnlyDummyTexture_ = renderer_->GetScreenBuffer(texture->GetWidth(), texture->GetHeight(),
                         graphics_->GetDummyColorFormat(), texture->GetMultiSample(), texture->GetAutoResolve(), false, false, false);
                 }
-#endif
+
                 graphics_->SetRenderTarget(0, GetRenderSurfaceFromTexture(depthOnlyDummyTexture_));
                 graphics_->SetDepthStencil(GetRenderSurfaceFromTexture(texture));
             }
@@ -1988,17 +2000,19 @@ void View::AllocateScreenBuffers()
         }
     }
 
-#ifdef URHO3D_OPENGL
-    // Due to FBO limitations, in OpenGL deferred modes need to render to texture first and then blit to the backbuffer
-    // Also, if rendering to a texture with full deferred rendering, it must be RGBA to comply with the rest of the buffers,
-    // unless using OpenGL 3
-    if (((deferred_ || hasScenePassToRTs) && !renderTarget_) || (!Graphics::GetGL3Support() && deferredAmbient_ && renderTarget_
-        && renderTarget_->GetParentTexture()->GetFormat() != Graphics::GetRGBAFormat()))
+    if (Graphics::GetGAPI() == GAPI_OPENGL)
+    {
+        // Due to FBO limitations, in OpenGL deferred modes need to render to texture first and then blit to the backbuffer
+        // Also, if rendering to a texture with full deferred rendering, it must be RGBA to comply with the rest of the buffers,
+        // unless using OpenGL 3
+        if (((deferred_ || hasScenePassToRTs) && !renderTarget_) || (!Graphics::GetGL3Support() && deferredAmbient_ && renderTarget_
+            && renderTarget_->GetParentTexture()->GetFormat() != Graphics::GetRGBAFormat()))
             needSubstitute = true;
-    // Also need substitute if rendering to backbuffer using a custom (readable) depth buffer
-    if (!renderTarget_ && hasCustomDepth)
-        needSubstitute = true;
-#endif
+        // Also need substitute if rendering to backbuffer using a custom (readable) depth buffer
+        if (!renderTarget_ && hasCustomDepth)
+            needSubstitute = true;
+    }
+
     // If backbuffer is antialiased when using deferred rendering, need to reserve a buffer
     if (deferred_ && !renderTarget_ && graphics_->GetMultiSample() > 1)
         needSubstitute = true;
@@ -2020,11 +2034,9 @@ void View::AllocateScreenBuffers()
         needSubstitute = true;
     }
 
-#ifdef URHO3D_OPENGL
     // On OpenGL 2 ensure that all MRT buffers are RGBA in deferred rendering
-    if (deferred_ && !renderer_->GetHDRRendering() && !Graphics::GetGL3Support())
+    if (deferred_ && !renderer_->GetHDRRendering() && Graphics::GetGAPI() == GAPI_OPENGL && !Graphics::GetGL3Support())
         format = Graphics::GetRGBAFormat();
-#endif
 
     if (hasViewportRead)
     {
@@ -2148,13 +2160,17 @@ void View::DrawFullscreenQuad(bool setIdentityProjection)
     {
         Matrix3x4 model = Matrix3x4::IDENTITY;
         Matrix4 projection = Matrix4::IDENTITY;
-#ifdef URHO3D_OPENGL
-        if (camera_ && camera_->GetFlipVertical())
-            projection.m11_ = -1.0f;
-        model.m23_ = 0.0f;
-#else
-        model.m23_ = 0.5f;
-#endif
+
+        if (Graphics::GetGAPI() == GAPI_OPENGL)
+        {
+            if (camera_ && camera_->GetFlipVertical())
+                projection.m11_ = -1.0f;
+            model.m23_ = 0.0f;
+        }
+        else
+        {
+            model.m23_ = 0.5f;
+        }
 
         graphics_->SetShaderParameter(VSP_MODEL, model);
         graphics_->SetShaderParameter(VSP_VIEWPROJ, projection);
@@ -2717,11 +2733,10 @@ void View::FinalizeShadowCamera(Camera* shadowCamera, Light* light, const IntRec
             shadowCamera->SetZoom(shadowCamera->GetZoom() * ((shadowMapWidth - 2.0f) / shadowMapWidth));
         else
         {
-#ifdef URHO3D_OPENGL
-            shadowCamera->SetZoom(shadowCamera->GetZoom() * ((shadowMapWidth - 3.0f) / shadowMapWidth));
-#else
-            shadowCamera->SetZoom(shadowCamera->GetZoom() * ((shadowMapWidth - 4.0f) / shadowMapWidth));
-#endif
+            if (Graphics::GetGAPI() == GAPI_OPENGL)
+                shadowCamera->SetZoom(shadowCamera->GetZoom() * ((shadowMapWidth - 3.0f) / shadowMapWidth));
+            else
+                shadowCamera->SetZoom(shadowCamera->GetZoom() * ((shadowMapWidth - 4.0f) / shadowMapWidth));
         }
     }
 }

+ 1 - 1
Source/Urho3D/Input/Input.cpp

@@ -2356,7 +2356,7 @@ void Input::HandleSDLEvent(void* sdlEvent)
 #if defined(IOS) || defined(TVOS) || defined (__ANDROID__)
                 // On iOS/tvOS we never lose the GL context, but may have done GPU object changes that could not be applied yet. Apply them now
                 // On Android the old GL context may be lost already, restore GPU objects to the new GL context
-                graphics_->Restore();
+                graphics_->Restore_OGL();
 #endif
                 minimized_ = false;
                 SendInputFocusEvent();

+ 5 - 9
Source/Urho3D/UI/UI.cpp

@@ -1005,14 +1005,12 @@ void UI::Render(VertexBuffer* buffer, const PODVector<UIBatch>& batches, unsigne
     Vector2 scale(2.0f * invScreenSize.x_, -2.0f * invScreenSize.y_);
     Vector2 offset(-1.0f, 1.0f);
 
-    if (surface)
+    if (Graphics::GetGAPI() == GAPI_OPENGL && surface)
     {
-#ifdef URHO3D_OPENGL
         // On OpenGL, flip the projection if rendering to a texture so that the texture can be addressed in the
         // same way as a render texture produced on Direct3D.
         offset.y_ = -offset.y_;
         scale.y_ = -scale.y_;
-#endif
     }
 
     Matrix4 projection(Matrix4::IDENTITY);
@@ -1026,13 +1024,13 @@ void UI::Render(VertexBuffer* buffer, const PODVector<UIBatch>& batches, unsigne
 
     graphics_->ClearParameterSources();
     graphics_->SetColorWrite(true);
-#ifdef URHO3D_OPENGL
+
     // Reverse winding if rendering to texture on OpenGL
-    if (surface)
+    if (Graphics::GetGAPI() == GAPI_OPENGL && surface)
         graphics_->SetCullMode(CULL_CW);
     else
-#endif
         graphics_->SetCullMode(CULL_CCW);
+    
     graphics_->SetDepthTest(CMP_ALWAYS);
     graphics_->SetDepthWrite(false);
     graphics_->SetFillMode(FILL_SOLID);
@@ -1115,15 +1113,13 @@ void UI::Render(VertexBuffer* buffer, const PODVector<UIBatch>& batches, unsigne
         scissor.bottom_ = (int)(scissor.bottom_ * uiScale_);
 
         // Flip scissor vertically if using OpenGL texture rendering
-#ifdef URHO3D_OPENGL
-        if (surface)
+        if (Graphics::GetGAPI() == GAPI_OPENGL && surface)
         {
             int top = scissor.top_;
             int bottom = scissor.bottom_;
             scissor.top_ = viewSize.y_ - bottom;
             scissor.bottom_ = viewSize.y_ - top;
         }
-#endif
 
         graphics_->SetBlendMode(batch.blendMode_);
         graphics_->SetScissorTest(true, scissor);

+ 12 - 9
cmake/Modules/FindDirectX.cmake

@@ -126,12 +126,13 @@ if (NOT MSVC_VERSION GREATER 1600 OR MINGW)     # MinGW reuses the logic below t
             string (REGEX REPLACE "^.*(d3dcompiler[_0-9]*).*$" \\1 D3DCOMPILER_LIB_NAME ${NAME})
             if (DirectX_FIND_REQUIRED_D3D11)
                 set (DIRECT3D_LIB_NAMES d3d11 dxgi dxguid)
-            else ()
-                set (DIRECT3D_LIB_NAMES d3d9)
-                if (NOT DirectX_FIND_REQUIRED_D3D AND NOT DirectX_FIND_REQUIRED_D3D9)
-                    # When using OpenGL we still want to reuse the logic below to find the DirectX library directory
-                    set (NO_DIRECT3D_COMPONENTS TRUE)
-                endif ()
+            endif ()
+            if (DirectX_FIND_REQUIRED_D3D OR DirectX_FIND_REQUIRED_D3D9)
+                list (APPEND DIRECT3D_LIB_NAMES d3d9)
+            endif ()
+            if (NOT DirectX_FIND_REQUIRED_D3D AND NOT DirectX_FIND_REQUIRED_D3D9 AND NOT DirectX_FIND_REQUIRED_D3D11)
+                # When using OpenGL we still want to reuse the logic below to find the DirectX library directory
+                set (NO_DIRECT3D_COMPONENTS TRUE)
             endif ()
             foreach (NAME ${D3DCOMPILER_LIB_NAME} ${DIRECT3D_LIB_NAMES})
                 string (REGEX REPLACE _[0-9]+$ "" BASE_NAME ${NAME})
@@ -155,7 +156,8 @@ if (NOT MSVC_VERSION GREATER 1600 OR MINGW)     # MinGW reuses the logic below t
                 set (HAVE_DIRECTX TRUE)
                 if (DirectX_FIND_REQUIRED_D3D11)
                     set (DirectX_D3D11_FOUND TRUE)
-                elseif (DirectX_FIND_REQUIRED_D3D OR DirectX_FIND_REQUIRED_D3D9)
+                endif ()
+                if (DirectX_FIND_REQUIRED_D3D OR DirectX_FIND_REQUIRED_D3D9)
                     set (DirectX_D3D9_FOUND TRUE)
                     set (DirectX_D3D_FOUND TRUE)
                 endif ()
@@ -194,8 +196,9 @@ if (MSVC_VERSION GREATER 1600 OR MINGW)     # MinGW reuses the logic below to fi
         if (DirectX_FIND_REQUIRED_D3D11)
             set (DIRECT3D_LIBRARIES d3dcompiler d3d11 dxgi dxguid)
             set (DirectX_D3D11_FOUND TRUE)
-        elseif (DirectX_FIND_REQUIRED_D3D OR DirectX_FIND_REQUIRED_D3D9)
-            set (DIRECT3D_LIBRARIES d3dcompiler d3d9)
+        endif ()
+        if (DirectX_FIND_REQUIRED_D3D OR DirectX_FIND_REQUIRED_D3D9)
+            list (APPEND DIRECT3D_LIBRARIES d3dcompiler d3d9)
             set (DirectX_D3D9_FOUND TRUE)
             set (DirectX_D3D_FOUND TRUE)
         endif ()

+ 1 - 1
cmake/Modules/FindUrho3D.cmake

@@ -54,7 +54,7 @@
 #  URHO3D_STATIC_RUNTIME
 #
 
-set (AUTO_DISCOVER_VARS URHO3D_OPENGL URHO3D_D3D11 URHO3D_SSE URHO3D_DATABASE_ODBC URHO3D_DATABASE_SQLITE URHO3D_LUAJIT URHO3D_TESTING URHO3D_STATIC_RUNTIME)
+set (AUTO_DISCOVER_VARS URHO3D_OPENGL URHO3D_D3D9 URHO3D_D3D11 URHO3D_SSE URHO3D_DATABASE_ODBC URHO3D_DATABASE_SQLITE URHO3D_LUAJIT URHO3D_TESTING URHO3D_STATIC_RUNTIME)
 set (PATH_SUFFIX Urho3D)
 if (CMAKE_PROJECT_NAME STREQUAL Urho3D AND TARGET Urho3D)
     # A special case where library location is already known to be in the build tree of Urho3D project

+ 19 - 13
cmake/Modules/UrhoCommon.cmake

@@ -177,10 +177,11 @@ if (CMAKE_PROJECT_NAME STREQUAL Urho3D)
     if (MINGW)
         set (DEFAULT_OPENGL TRUE)
     endif ()
-    cmake_dependent_option (URHO3D_OPENGL "Use OpenGL instead of Direct3D (Windows platform only)" "${DEFAULT_OPENGL}" WIN32 TRUE)
+    cmake_dependent_option (URHO3D_OPENGL "Use OpenGL (Windows platform only)" "${DEFAULT_OPENGL}" WIN32 TRUE)
     # On Windows platform Direct3D11 can be optionally chosen
     # Using Direct3D11 on non-MSVC compiler may require copying and renaming Microsoft official libraries (.lib to .a), else link failures or non-functioning graphics may result
-    cmake_dependent_option (URHO3D_D3D11 "Use Direct3D11 instead of Direct3D9 (Windows platform only); overrides URHO3D_OPENGL option" FALSE "WIN32" FALSE)
+    cmake_dependent_option (URHO3D_D3D9 "Use Direct3D9 (Windows platform only)" TRUE "WIN32" FALSE)
+    cmake_dependent_option (URHO3D_D3D11 "Use Direct3D11 (Windows platform only)" TRUE "WIN32" FALSE)
     if (X86 OR E2K OR WEB)
         # TODO: Rename URHO3D_SSE to URHO3D_SIMD
         if (MINGW AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.1)
@@ -372,10 +373,13 @@ if (RPI)
     set_property (CACHE RPI_ABI PROPERTY STRINGS ${RPI_SUPPORTED_ABIS})
 endif ()
 # Handle mutually exclusive options and implied options
-if (URHO3D_D3D11)
-    set (URHO3D_OPENGL 0)
-    unset (URHO3D_OPENGL CACHE)
-endif ()
+#if (URHO3D_D3D11)
+#    set (URHO3D_OPENGL 0)
+#    unset (URHO3D_OPENGL CACHE)
+#endif ()
+#if (NOT URHO3D_OPENGL AND NOT URHO3D_D3D11)
+#    set (URHO3D_D3D9 1) # TODO: Make option
+#endif ()
 if (URHO3D_DATABASE_ODBC)
     set (URHO3D_DATABASE_SQLITE 0)
     unset (URHO3D_DATABASE_SQLITE CACHE)
@@ -494,13 +498,14 @@ endforeach ()
 if (WIN32 AND NOT CMAKE_PROJECT_NAME MATCHES ^Urho3D-ExternalProject-)
     set (DIRECTX_REQUIRED_COMPONENTS)
     set (DIRECTX_OPTIONAL_COMPONENTS DInput DSound XInput)
-    if (NOT URHO3D_OPENGL)
-        if (URHO3D_D3D11)
-            list (APPEND DIRECTX_REQUIRED_COMPONENTS D3D11)
-        else ()
-            list (APPEND DIRECTX_REQUIRED_COMPONENTS D3D)
-        endif ()
+    if (URHO3D_D3D11)
+        list (APPEND DIRECTX_REQUIRED_COMPONENTS D3D11)
+    endif ()
+    
+    if (URHO3D_D3D9)
+        list (APPEND DIRECTX_REQUIRED_COMPONENTS D3D)
     endif ()
+    
     find_package (DirectX REQUIRED ${DIRECTX_REQUIRED_COMPONENTS} OPTIONAL_COMPONENTS ${DIRECTX_OPTIONAL_COMPONENTS})
     if (DIRECTX_FOUND)
         include_directories (SYSTEM ${DIRECTX_INCLUDE_DIRS})   # These variables may be empty when WinSDK or MinGW is being used
@@ -978,7 +983,8 @@ macro (define_dependency_libs TARGET)
             else ()
                 list (APPEND LIBS GL)
             endif ()
-        elseif (DIRECT3D_LIBRARIES)
+        endif ()
+        if (DIRECT3D_LIBRARIES)
             list (APPEND LIBS ${DIRECT3D_LIBRARIES})
         endif ()
 

+ 1 - 0
rakefile

@@ -40,6 +40,7 @@ task :cmake => [:init] do
     system 'cmake --version' or abort 'Failed to find CMake'
     if ENV['USE_CCACHE'] && ENV['GITHUB_EVENT_NAME'] != 'repository_dispatch' && /\[cache clear\]/ =~ `git log --format=%B -n1 2>/dev/null`
       system 'bash', '-c', 'rm -rf ~/.{ccache,gradle}' or abort 'Failed to clear the build cache'
+      puts "CMake cache has been cleared"
     end
   end
   next if ENV['PLATFORM'] == 'android' || (Dir.exists?(build_tree) and not ARGV.include?('cmake'))

Some files were not shown because too many files changed in this diff