Browse Source

Reformat D3D9 and D3D11 source files.

Yao Wei Tjong 姚伟忠 10 years ago
parent
commit
1a5268f427
51 changed files with 1688 additions and 1385 deletions
  1. 1 2
      Source/Urho3D/Graphics/Direct3D11/D3D11ConstantBuffer.cpp
  2. 6 5
      Source/Urho3D/Graphics/Direct3D11/D3D11ConstantBuffer.h
  3. 0 2
      Source/Urho3D/Graphics/Direct3D11/D3D11GPUObject.cpp
  4. 9 6
      Source/Urho3D/Graphics/Direct3D11/D3D11GPUObject.h
  5. 150 149
      Source/Urho3D/Graphics/Direct3D11/D3D11Graphics.cpp
  6. 84 16
      Source/Urho3D/Graphics/Direct3D11/D3D11Graphics.h
  7. 0 1
      Source/Urho3D/Graphics/Direct3D11/D3D11GraphicsImpl.cpp
  8. 7 4
      Source/Urho3D/Graphics/Direct3D11/D3D11GraphicsImpl.h
  9. 40 38
      Source/Urho3D/Graphics/Direct3D11/D3D11IndexBuffer.cpp
  10. 15 8
      Source/Urho3D/Graphics/Direct3D11/D3D11IndexBuffer.h
  11. 7 9
      Source/Urho3D/Graphics/Direct3D11/D3D11RenderSurface.cpp
  12. 12 5
      Source/Urho3D/Graphics/Direct3D11/D3D11RenderSurface.h
  13. 53 56
      Source/Urho3D/Graphics/Direct3D11/D3D11ShaderVariation.cpp
  14. 19 8
      Source/Urho3D/Graphics/Direct3D11/D3D11ShaderVariation.h
  15. 29 31
      Source/Urho3D/Graphics/Direct3D11/D3D11Texture.cpp
  16. 22 5
      Source/Urho3D/Graphics/Direct3D11/D3D11Texture.h
  17. 58 56
      Source/Urho3D/Graphics/Direct3D11/D3D11Texture2D.cpp
  18. 8 7
      Source/Urho3D/Graphics/Direct3D11/D3D11Texture2D.h
  19. 67 64
      Source/Urho3D/Graphics/Direct3D11/D3D11Texture3D.cpp
  20. 8 7
      Source/Urho3D/Graphics/Direct3D11/D3D11Texture3D.h
  21. 76 72
      Source/Urho3D/Graphics/Direct3D11/D3D11TextureCube.cpp
  22. 8 7
      Source/Urho3D/Graphics/Direct3D11/D3D11TextureCube.h
  23. 43 41
      Source/Urho3D/Graphics/Direct3D11/D3D11VertexBuffer.cpp
  24. 18 9
      Source/Urho3D/Graphics/Direct3D11/D3D11VertexBuffer.h
  25. 4 4
      Source/Urho3D/Graphics/Direct3D11/D3D11VertexDeclaration.cpp
  26. 3 3
      Source/Urho3D/Graphics/Direct3D11/D3D11VertexDeclaration.h
  27. 0 1
      Source/Urho3D/Graphics/Direct3D9/D3D9GPUObject.cpp
  28. 12 7
      Source/Urho3D/Graphics/Direct3D9/D3D9GPUObject.h
  29. 168 166
      Source/Urho3D/Graphics/Direct3D9/D3D9Graphics.cpp
  30. 83 15
      Source/Urho3D/Graphics/Direct3D9/D3D9Graphics.h
  31. 2 14
      Source/Urho3D/Graphics/Direct3D9/D3D9GraphicsImpl.cpp
  32. 7 3
      Source/Urho3D/Graphics/Direct3D9/D3D9GraphicsImpl.h
  33. 46 44
      Source/Urho3D/Graphics/Direct3D9/D3D9IndexBuffer.cpp
  34. 15 8
      Source/Urho3D/Graphics/Direct3D9/D3D9IndexBuffer.h
  35. 7 9
      Source/Urho3D/Graphics/Direct3D9/D3D9RenderSurface.cpp
  36. 12 5
      Source/Urho3D/Graphics/Direct3D9/D3D9RenderSurface.h
  37. 2 2
      Source/Urho3D/Graphics/Direct3D9/D3D9ShaderProgram.h
  38. 55 57
      Source/Urho3D/Graphics/Direct3D9/D3D9ShaderVariation.cpp
  39. 17 9
      Source/Urho3D/Graphics/Direct3D9/D3D9ShaderVariation.h
  40. 31 33
      Source/Urho3D/Graphics/Direct3D9/D3D9Texture.cpp
  41. 20 6
      Source/Urho3D/Graphics/Direct3D9/D3D9Texture.h
  42. 101 84
      Source/Urho3D/Graphics/Direct3D9/D3D9Texture2D.cpp
  43. 8 7
      Source/Urho3D/Graphics/Direct3D9/D3D9Texture2D.h
  44. 115 94
      Source/Urho3D/Graphics/Direct3D9/D3D9Texture3D.cpp
  45. 8 7
      Source/Urho3D/Graphics/Direct3D9/D3D9Texture3D.h
  46. 126 107
      Source/Urho3D/Graphics/Direct3D9/D3D9TextureCube.cpp
  47. 8 7
      Source/Urho3D/Graphics/Direct3D9/D3D9TextureCube.h
  48. 49 47
      Source/Urho3D/Graphics/Direct3D9/D3D9VertexBuffer.cpp
  49. 19 10
      Source/Urho3D/Graphics/Direct3D9/D3D9VertexBuffer.h
  50. 26 24
      Source/Urho3D/Graphics/Direct3D9/D3D9VertexDeclaration.cpp
  51. 4 4
      Source/Urho3D/Graphics/Direct3D9/D3D9VertexDeclaration.h

+ 1 - 2
Source/Urho3D/Graphics/Direct3D11/D3D11ConstantBuffer.cpp

@@ -24,15 +24,14 @@
 
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsImpl.h"
-#include "../../IO/Log.h"
 #include "../../Graphics/ConstantBuffer.h"
+#include "../../IO/Log.h"
 
 #include "../../DebugNew.h"
 
 namespace Urho3D
 {
 
-
 ConstantBuffer::ConstantBuffer(Context* context) :
     Object(context),
     GPUObject(GetSubsystem<Graphics>())

+ 6 - 5
Source/Urho3D/Graphics/Direct3D11/D3D11ConstantBuffer.h

@@ -22,10 +22,10 @@
 
 #pragma once
 
-#include "../../Graphics/GPUObject.h"
-#include "../../Graphics/GraphicsDefs.h"
 #include "../../Container/ArrayPtr.h"
 #include "../../Core/Object.h"
+#include "../../Graphics/GPUObject.h"
+#include "../../Graphics/GraphicsDefs.h"
 
 namespace Urho3D
 {
@@ -34,16 +34,16 @@ namespace Urho3D
 class URHO3D_API ConstantBuffer : public Object, public GPUObject
 {
     OBJECT(ConstantBuffer);
-    
+
 public:
     /// Construct.
     ConstantBuffer(Context* context);
     /// Destruct.
     virtual ~ConstantBuffer();
-    
+
     /// Release buffer.
     virtual void Release();
-    
+
     /// Set size and create GPU-side buffer. Return true on success.
     bool SetSize(unsigned size);
     /// Set a generic parameter and mark buffer dirty.
@@ -55,6 +55,7 @@ public:
 
     /// Return size.
     unsigned GetSize() const { return size_; }
+
     /// Return whether has unapplied data.
     bool IsDirty() const { return dirty_; }
 

+ 0 - 2
Source/Urho3D/Graphics/Direct3D11/D3D11GPUObject.cpp

@@ -23,8 +23,6 @@
 #include "../../Precompiled.h"
 
 #include "../../Graphics/Graphics.h"
-#include "../../Graphics/GraphicsImpl.h"
-#include "../../Graphics/GPUObject.h"
 
 #include "../../DebugNew.h"
 

+ 9 - 6
Source/Urho3D/Graphics/Direct3D11/D3D11GPUObject.h

@@ -37,22 +37,25 @@ public:
     GPUObject(Graphics* graphics);
     /// Destruct. Remove from the graphics subsystem.
     virtual ~GPUObject();
-    
+
     /// Unconditionally release the GPU resource.
-    virtual void Release() {}
-    
+    virtual void Release() { }
+
     /// Clear the data lost flag. No-op on D3D11.
-    void ClearDataLost() {}
-    
+    void ClearDataLost() { }
+
     /// Return the graphics subsystem.
     Graphics* GetGraphics() const;
+
     /// Return Direct3D object.
     void* GetGPUObject() const { return object_; }
+
     /// Return whether data is lost due to device loss. Always false on D3D11.
     bool IsDataLost() const { return false; }
+
     /// Return whether has pending data assigned while device was lost. Always false on D3D11.
     bool HasPendingData() const { return false; }
-    
+
 protected:
     /// Graphics subsystem.
     WeakPtr<Graphics> graphics_;

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


+ 84 - 16
Source/Urho3D/Graphics/Direct3D11/D3D11Graphics.h

@@ -23,15 +23,15 @@
 #pragma once
 
 #include "../../Container/ArrayPtr.h"
-#include "../../Math/Color.h"
 #include "../../Container/HashSet.h"
-#include "../../Resource/Image.h"
 #include "../../Core/Mutex.h"
 #include "../../Core/Object.h"
-#include "../../Math/Plane.h"
-#include "../../Math/Rect.h"
 #include "../../Graphics/GraphicsDefs.h"
 #include "../../Graphics/ShaderVariation.h"
+#include "../../Math/Color.h"
+#include "../../Math/Plane.h"
+#include "../../Math/Rect.h"
+#include "../../Resource/Image.h"
 
 namespace Urho3D
 {
@@ -65,7 +65,7 @@ struct ScratchBuffer
         reserved_(false)
     {
     }
-    
+
     /// Buffer data.
     SharedArrayPtr<unsigned char> data_;
     /// Data size.
@@ -80,13 +80,13 @@ typedef HashMap<Pair<ShaderVariation*, ShaderVariation*>, SharedPtr<ShaderProgra
 class URHO3D_API Graphics : public Object
 {
     OBJECT(Graphics);
-    
+
 public:
     /// Construct.
     Graphics(Context* context);
     /// Destruct. Release the Direct3D11 device and close the window.
     virtual ~Graphics();
-    
+
     /// Set external window handle. Only effective before setting the initial screen mode.
     void SetExternalWindow(void* window);
     /// Set window title.
@@ -98,7 +98,8 @@ public:
     /// Set window position. Sets initial position if window is not created yet.
     void SetWindowPosition(int x, int y);
     /// Set screen mode. Return true if successful.
-    bool SetMode(int width, int height, bool fullscreen, bool borderless, bool resizable, bool vsync, bool tripleBuffer, int multiSample);
+    bool SetMode
+        (int width, int height, bool fullscreen, bool borderless, bool resizable, bool vsync, bool tripleBuffer, int multiSample);
     /// Set screen resolution only. Return true if successful.
     bool SetMode(int width, int height);
     /// Set whether the main window uses sRGB conversion on write.
@@ -126,13 +127,16 @@ public:
     /// Draw indexed geometry.
     void Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount);
     /// Draw indexed, instanced geometry. An instancing vertex buffer must be set.
-    void DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount, unsigned instanceCount);
+    void DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount,
+        unsigned instanceCount);
     /// Set vertex buffer.
     void SetVertexBuffer(VertexBuffer* buffer);
     /// Set multiple vertex buffers.
-    bool SetVertexBuffers(const PODVector<VertexBuffer*>& buffers, const PODVector<unsigned>& elementMasks, unsigned instanceOffset = 0);
+    bool SetVertexBuffers
+        (const PODVector<VertexBuffer*>& buffers, const PODVector<unsigned>& elementMasks, unsigned instanceOffset = 0);
     /// Set multiple vertex buffers.
-    bool SetVertexBuffers(const Vector<SharedPtr<VertexBuffer> >& buffers, const PODVector<unsigned>& elementMasks, unsigned instanceOffset = 0);
+    bool SetVertexBuffers
+        (const Vector<SharedPtr<VertexBuffer> >& buffers, const PODVector<unsigned>& elementMasks, unsigned instanceOffset = 0);
     /// Set index buffer.
     void SetIndexBuffer(IndexBuffer* buffer);
     /// Set shaders.
@@ -214,76 +218,109 @@ public:
     /// Set scissor test.
     void SetScissorTest(bool enable, const IntRect& rect);
     /// Set stencil test.
-    void SetStencilTest(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);
+    void SetStencilTest
+        (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);
     /// Set a custom clipping plane. The plane is specified in world space, but is dependent on the view and projection matrices.
-    void SetClipPlane(bool enable, const Plane& clipPlane = Plane::UP, const Matrix3x4& view = Matrix3x4::IDENTITY, const Matrix4& projection = Matrix4::IDENTITY);
+    void SetClipPlane(bool enable, const Plane& clipPlane = Plane::UP, const Matrix3x4& view = Matrix3x4::IDENTITY,
+        const Matrix4& projection = Matrix4::IDENTITY);
     /// Begin dumping shader variation names to an XML file for precaching.
     void BeginDumpShaders(const String& fileName);
     /// End dumping shader variations names.
     void EndDumpShaders();
     /// Precache shader variations from an XML file generated with BeginDumpShaders().
     void PrecacheShaders(Deserializer& source);
-    
+
     /// Return whether rendering initialized.
     bool IsInitialized() const;
+
     /// Return graphics implementation, which holds the actual API-specific resources.
     GraphicsImpl* GetImpl() const { return impl_; }
+
     /// Return OS-specific external window handle. Null if not in use.
     void* GetExternalWindow() const { return externalWindow_; }
+
     /// Return window title.
     const String& GetWindowTitle() const { return windowTitle_; }
+
     /// Return graphics API name.
     const String& GetApiName() const { return apiName_; }
+
     /// Return window position.
     IntVector2 GetWindowPosition() const;
+
     /// Return window width.
     int GetWidth() const { return width_; }
+
     /// Return window height.
     int GetHeight() const { return height_; }
+
     /// Return multisample mode (1 = no multisampling.)
     int GetMultiSample() const { return multiSample_; }
+
     /// Return whether window is fullscreen.
     bool GetFullscreen() const { return fullscreen_; }
+
     /// Return whether window is resizable.
     bool GetResizable() const { return resizable_; }
+
     /// Return whether window is borderless.
     bool GetBorderless() const { return borderless_; }
+
     /// Return whether vertical sync is on.
     bool GetVSync() const { return vsync_; }
+
     /// Return whether triple buffering is enabled.
     bool GetTripleBuffer() const { return tripleBuffer_; }
+
     /// Return whether the main window is using sRGB conversion on write.
     bool GetSRGB() const { return sRGB_; }
+
     /// Return whether the GPU command buffer is flushed each frame.
     bool GetFlushGPU() const { return flushGPU_; }
+
     /// Return allowed screen orientations.
     const String& GetOrientations() const { return orientations_; }
+
     /// Return whether Direct3D device is lost, and can not yet render. Always false on D3D11.
     bool IsDeviceLost() const { return false; }
+
     /// Return number of primitives drawn this frame.
     unsigned GetNumPrimitives() const { return numPrimitives_; }
+
     /// Return number of batches drawn this frame.
     unsigned GetNumBatches() const { return numBatches_; }
+
     /// Return dummy color texture format for shadow maps. Is "NULL" (consume no video memory) if supported.
     unsigned GetDummyColorFormat() const { return dummyColorFormat_; }
+
     /// Return shadow map depth texture format, or 0 if not supported.
     unsigned GetShadowMapFormat() const { return shadowMapFormat_; }
+
     /// Return 24-bit shadow map depth texture format, or 0 if not supported.
     unsigned GetHiresShadowMapFormat() const { return hiresShadowMapFormat_; }
+
     /// Return whether hardware instancing is supported..
     bool GetInstancingSupport() const { return instancingSupport_; }
+
     /// Return whether light pre-pass rendering is supported.
     bool GetLightPrepassSupport() const { return lightPrepassSupport_; }
+
     /// Return whether deferred rendering is supported.
     bool GetDeferredSupport() const { return deferredSupport_; }
+
     /// Return whether shadow map depth compare is done in hardware.
     bool GetHardwareShadowSupport() const { return hardwareShadowSupport_; }
+
     /// Return whether a readable hardware depth format is available.
     bool GetReadableDepthSupport() const { return GetReadableDepthFormat() != 0; }
+
     /// Return whether sRGB conversion on texture sampling is supported.
     bool GetSRGBSupport() const { return sRGBSupport_; }
+
     /// Return whether sRGB conversion on rendertarget writing is supported.
     bool GetSRGBWriteSupport() const { return sRGBWriteSupport_; }
+
     /// Return supported fullscreen resolutions.
     PODVector<IntVector2> GetResolutions() const;
     /// Return supported multisampling levels.
@@ -298,69 +335,98 @@ public:
     ShaderVariation* GetShader(ShaderType type, const char* name, const char* defines) const;
     /// Return current vertex buffer by index.
     VertexBuffer* GetVertexBuffer(unsigned index) const;
+
     /// Return current index buffer.
     IndexBuffer* GetIndexBuffer() const { return indexBuffer_; }
+
     /// Return current vertex shader.
     ShaderVariation* GetVertexShader() const { return vertexShader_; }
+
     /// Return current pixel shader.
     ShaderVariation* GetPixelShader() const { return pixelShader_; }
+
     /// Return texture unit index by name.
     TextureUnit GetTextureUnit(const String& name);
     /// Return texture unit name by index.
     const String& GetTextureUnitName(TextureUnit unit);
     /// Return current texture by texture unit index.
     Texture* GetTexture(unsigned index) const;
+
     /// Return default texture filtering mode.
     TextureFilterMode GetDefaultTextureFilterMode() const { return defaultTextureFilterMode_; }
+
     /// Return current rendertarget by index.
     RenderSurface* GetRenderTarget(unsigned index) const;
+
     /// Return current depth-stencil surface.
     RenderSurface* GetDepthStencil() const { return depthStencil_; }
+
     /// Return the viewport coordinates.
     IntRect GetViewport() const { return viewport_; }
+
     /// Return texture anisotropy.
     unsigned GetTextureAnisotropy() const { return textureAnisotropy_; }
+
     /// Return blending mode.
     BlendMode GetBlendMode() const { return blendMode_; }
+
     /// Return whether color write is enabled.
     bool GetColorWrite() const { return colorWrite_; }
+
     /// Return hardware culling mode.
     CullMode GetCullMode() const { return cullMode_; }
+
     /// Return depth constant bias.
     float GetDepthConstantBias() const { return constantDepthBias_; }
+
     /// Return depth slope scaled bias.
     float GetDepthSlopeScaledBias() const { return slopeScaledDepthBias_; }
+
     /// Return depth compare mode.
     CompareMode GetDepthTest() const { return depthTestMode_; }
+
     /// Return whether depth write is enabled.
     bool GetDepthWrite() const { return depthWrite_; }
+
     /// Return polygon fill mode.
     FillMode GetFillMode() const { return fillMode_; }
+
     /// Return whether stencil test is enabled.
     bool GetStencilTest() const { return stencilTest_; }
+
     /// Return whether scissor test is enabled.
     bool GetScissorTest() const { return scissorTest_; }
+
     /// Return scissor rectangle coordinates.
     const IntRect& GetScissorRect() const { return scissorRect_; }
+
     /// Return stencil compare mode.
     CompareMode GetStencilTestMode() const { return stencilTestMode_; }
+
     /// Return stencil operation to do if stencil test passes.
     StencilOp GetStencilPass() const { return stencilPass_; }
+
     /// Return stencil operation to do if stencil test fails.
     StencilOp GetStencilFail() const { return stencilFail_; }
+
     /// Return stencil operation to do if depth compare fails.
     StencilOp GetStencilZFail() const { return stencilZFail_; }
+
     /// Return stencil reference value.
     unsigned GetStencilRef() const { return stencilRef_; }
+
     /// Return stencil compare bitmask.
     unsigned GetStencilCompareMask() const { return stencilCompareMask_; }
+
     /// Return stencil write bitmask.
     unsigned GetStencilWriteMask() const { return stencilWriteMask_; }
+
     /// Return whether a custom clipping plane is in use.
     bool GetUseClipPlane() const { return useClipPlane_; }
+
     /// Return rendertarget width and height.
     IntVector2 GetRenderTargetDimensions() const;
-    
+
     /// Window was resized through user interaction. Called by Input subsystem.
     void WindowResized();
     /// Window was moved through user interaction. Called by Input subsystem.
@@ -418,8 +484,10 @@ public:
     static unsigned GetReadableDepthFormat();
     /// Return the API-specific texture format from a textual description, for example "rgb".
     static unsigned GetFormat(const String& formatName);
+
     /// Return UV offset required for pixel perfect rendering.
     static const Vector2& GetPixelUVOffset() { return pixelUVOffset; }
+
     /// Return maximum number of supported bones for skinning.
     static unsigned GetMaxBones() { return 128; }
 
@@ -442,7 +510,7 @@ private:
     void SetTextureUnitMappings();
     /// Process dirtied state before draw.
     void PrepareDraw();
-    
+
     /// Mutex for accessing the GPU objects vector from several threads.
     Mutex gpuObjectMutex_;
     /// Implementation.

+ 0 - 1
Source/Urho3D/Graphics/Direct3D11/D3D11GraphicsImpl.cpp

@@ -23,7 +23,6 @@
 #include "../../Precompiled.h"
 
 #include "../../Graphics/Graphics.h"
-#include "../../Graphics/GraphicsEvents.h"
 #include "../../Graphics/GraphicsImpl.h"
 
 #include "../../DebugNew.h"

+ 7 - 4
Source/Urho3D/Graphics/Direct3D11/D3D11GraphicsImpl.h

@@ -22,8 +22,8 @@
 
 #pragma once
 
-#include "../../Math/Color.h"
 #include "../../Graphics/GraphicsDefs.h"
+#include "../../Math/Color.h"
 
 #include <d3d11.h>
 #include <dxgi.h>
@@ -36,20 +36,23 @@ namespace Urho3D
 class URHO3D_API GraphicsImpl
 {
     friend class Graphics;
-    
+
 public:
     /// Construct.
     GraphicsImpl();
-    
+
     /// Return Direct3D device.
     ID3D11Device* GetDevice() const { return device_; }
+
     /// Return Direct3D immediate device context.
     ID3D11DeviceContext* GetDeviceContext() const { return deviceContext_; }
+
     /// Return swapchain.
     IDXGISwapChain* GetSwapChain() const { return swapChain_; }
+
     /// Return window.
     SDL_Window* GetWindow() const { return window_; }
-    
+
 private:
     /// SDL window.
     SDL_Window* window_;

+ 40 - 38
Source/Urho3D/Graphics/Direct3D11/D3D11IndexBuffer.cpp

@@ -58,15 +58,15 @@ IndexBuffer::~IndexBuffer()
 void IndexBuffer::Release()
 {
     Unlock();
-    
+
     if (object_)
     {
         if (!graphics_)
             return;
-        
+
         if (graphics_->GetIndexBuffer() == this)
             graphics_->SetIndexBuffer(0);
-        
+
         ((ID3D11Buffer*)object_)->Release();
         object_ = 0;
     }
@@ -77,14 +77,14 @@ void IndexBuffer::SetShadowed(bool enable)
     // If no graphics subsystem, can not disable shadowing
     if (!graphics_)
         enable = true;
-    
+
     if (enable != shadowed_)
     {
         if (enable && indexCount_ && indexSize_)
             shadowData_ = new unsigned char[indexCount_ * indexSize_];
         else
             shadowData_.Reset();
-        
+
         shadowed_ = enable;
     }
 }
@@ -92,16 +92,16 @@ void IndexBuffer::SetShadowed(bool enable)
 bool IndexBuffer::SetSize(unsigned indexCount, bool largeIndices, bool dynamic)
 {
     Unlock();
-    
+
     dynamic_ = dynamic;
     indexCount_ = indexCount;
-    indexSize_ = largeIndices ? sizeof(unsigned) : sizeof(unsigned short);
-    
+    indexSize_ = (unsigned)(largeIndices ? sizeof(unsigned) : sizeof(unsigned short));
+
     if (shadowed_ && indexCount_ && indexSize_)
         shadowData_ = new unsigned char[indexCount_ * indexSize_];
     else
         shadowData_.Reset();
-    
+
     return Create();
 }
 
@@ -112,16 +112,16 @@ bool IndexBuffer::SetData(const void* data)
         LOGERROR("Null pointer for index buffer data");
         return false;
     }
-    
+
     if (!indexSize_)
     {
         LOGERROR("Index size not defined, can not set index buffer data");
         return false;
     }
-    
+
     if (shadowData_ && data != shadowData_.Get())
         memcpy(shadowData_.Get(), data, indexCount_ * indexSize_);
-    
+
     if (object_)
     {
         if (dynamic_)
@@ -148,7 +148,7 @@ bool IndexBuffer::SetData(const void* data)
             graphics_->GetImpl()->GetDeviceContext()->UpdateSubresource((ID3D11Buffer*)object_, 0, &destBox, data, 0, 0);
         }
     }
-    
+
     return true;
 }
 
@@ -156,31 +156,31 @@ bool IndexBuffer::SetDataRange(const void* data, unsigned start, unsigned count,
 {
     if (start == 0 && count == indexCount_)
         return SetData(data);
-    
+
     if (!data)
     {
         LOGERROR("Null pointer for index buffer data");
         return false;
     }
-    
+
     if (!indexSize_)
     {
         LOGERROR("Index size not defined, can not set index buffer data");
         return false;
     }
-    
+
     if (start + count > indexCount_)
     {
         LOGERROR("Illegal range for setting new index buffer data");
         return false;
     }
-    
+
     if (!count)
         return true;
-    
+
     if (shadowData_ && shadowData_.Get() + start * indexSize_ != data)
         memcpy(shadowData_.Get() + start * indexSize_, data, count * indexSize_);
-    
+
     if (object_)
     {
         if (dynamic_)
@@ -218,25 +218,25 @@ void* IndexBuffer::Lock(unsigned start, unsigned count, bool discard)
         LOGERROR("Index buffer already locked");
         return 0;
     }
-    
+
     if (!indexSize_)
     {
         LOGERROR("Index size not defined, can not lock index buffer");
         return 0;
     }
-    
+
     if (start + count > indexCount_)
     {
         LOGERROR("Illegal range for locking index buffer");
         return 0;
     }
-    
+
     if (!count)
         return 0;
-    
+
     lockStart_ = start;
     lockCount_ = count;
-    
+
     // Because shadow data must be kept in sync, can only lock hardware buffer if not shadowed
     if (object_ && !shadowData_ && dynamic_)
         return MapBuffer(start, count, discard);
@@ -262,12 +262,12 @@ void IndexBuffer::Unlock()
     case LOCK_HARDWARE:
         UnmapBuffer();
         break;
-        
+
     case LOCK_SHADOW:
         SetDataRange(shadowData_.Get() + lockStart_ * indexSize_, lockStart_, lockCount_);
         lockState_ = LOCK_NONE;
         break;
-        
+
     case LOCK_SCRATCH:
         SetDataRange(lockScratchData_, lockStart_, lockCount_);
         if (graphics_)
@@ -275,6 +275,8 @@ void IndexBuffer::Unlock()
         lockScratchData_ = 0;
         lockState_ = LOCK_NONE;
         break;
+
+    default: break;
     }
 }
 
@@ -285,20 +287,20 @@ bool IndexBuffer::GetUsedVertexRange(unsigned start, unsigned count, unsigned& m
         LOGERROR("Used vertex range can only be queried from an index buffer with shadow data");
         return false;
     }
-    
+
     if (start + count > indexCount_)
     {
         LOGERROR("Illegal index range for querying used vertices");
         return false;
     }
-    
+
     minVertex = M_MAX_UNSIGNED;
     unsigned maxVertex = 0;
-    
+
     if (indexSize_ == sizeof(unsigned))
     {
         unsigned* indices = ((unsigned*)shadowData_.Get()) + start;
-        
+
         for (unsigned i = 0; i < count; ++i)
         {
             if (indices[i] < minVertex)
@@ -310,7 +312,7 @@ bool IndexBuffer::GetUsedVertexRange(unsigned start, unsigned count, unsigned& m
     else
     {
         unsigned short* indices = ((unsigned short*)shadowData_.Get()) + start;
-        
+
         for (unsigned i = 0; i < count; ++i)
         {
             if (indices[i] < minVertex)
@@ -319,7 +321,7 @@ bool IndexBuffer::GetUsedVertexRange(unsigned start, unsigned count, unsigned& m
                 maxVertex = indices[i];
         }
     }
-    
+
     vertexCount = maxVertex - minVertex + 1;
     return true;
 }
@@ -327,10 +329,10 @@ bool IndexBuffer::GetUsedVertexRange(unsigned start, unsigned count, unsigned& m
 bool IndexBuffer::Create()
 {
     Release();
-    
+
     if (!indexCount_)
         return true;
-    
+
     if (graphics_)
     {
         D3D11_BUFFER_DESC bufferDesc;
@@ -338,7 +340,7 @@ bool IndexBuffer::Create()
         bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
         bufferDesc.CPUAccessFlags = dynamic_ ? D3D11_CPU_ACCESS_WRITE : 0;
         bufferDesc.Usage = dynamic_ ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT;
-        bufferDesc.ByteWidth = (unsigned)(indexCount_ * indexSize_);
+        bufferDesc.ByteWidth = (UINT)(indexCount_ * indexSize_);
 
         graphics_->GetImpl()->GetDevice()->CreateBuffer(&bufferDesc, 0, (ID3D11Buffer**)&object_);
 
@@ -348,7 +350,7 @@ bool IndexBuffer::Create()
             return false;
         }
     }
-    
+
     return true;
 }
 
@@ -363,7 +365,7 @@ bool IndexBuffer::UpdateToGPU()
 void* IndexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
 {
     void* hwData = 0;
-    
+
     if (object_)
     {
         D3D11_MAPPED_SUBRESOURCE mappedData;
@@ -377,7 +379,7 @@ void* IndexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
         else
             lockState_ = LOCK_HARDWARE;
     }
-    
+
     return hwData;
 }
 

+ 15 - 8
Source/Urho3D/Graphics/Direct3D11/D3D11IndexBuffer.h

@@ -22,10 +22,10 @@
 
 #pragma once
 
-#include "../../Graphics/GPUObject.h"
 #include "../../Core/Object.h"
-#include "../../Graphics/GraphicsDefs.h"
 #include "../../Container/ArrayPtr.h"
+#include "../../Graphics/GPUObject.h"
+#include "../../Graphics/GraphicsDefs.h"
 
 namespace Urho3D
 {
@@ -34,16 +34,16 @@ namespace Urho3D
 class URHO3D_API IndexBuffer : public Object, public GPUObject
 {
     OBJECT(IndexBuffer);
-    
+
 public:
     /// Construct.
     IndexBuffer(Context* context);
     /// Destruct.
     virtual ~IndexBuffer();
-    
+
     /// Release buffer.
     virtual void Release();
-    
+
     /// Enable shadowing in CPU memory. Shadowing is forced on if the graphics subsystem does not exist.
     void SetShadowed(bool enable);
     /// Set size and vertex elements and dynamic mode. Previous data will be lost.
@@ -56,21 +56,28 @@ public:
     void* Lock(unsigned start, unsigned count, bool discard = false);
     /// Unlock the buffer and apply changes to the GPU buffer.
     void Unlock();
-    
+
     /// Return whether CPU memory shadowing is enabled.
     bool IsShadowed() const { return shadowed_; }
+
     /// Return whether is dynamic.
     bool IsDynamic() const { return dynamic_; }
+
     /// Return whether is currently locked.
     bool IsLocked() const { return lockState_ != LOCK_NONE; }
+
     /// Return number of indices.
-    unsigned GetIndexCount() const {return indexCount_; }
+    unsigned GetIndexCount() const { return indexCount_; }
+
     /// Return index size.
     unsigned GetIndexSize() const { return indexSize_; }
+
     /// Return used vertex range from index range.
     bool GetUsedVertexRange(unsigned start, unsigned count, unsigned& minVertex, unsigned& vertexCount);
+
     /// Return CPU memory shadow data.
     unsigned char* GetShadowData() const { return shadowData_.Get(); }
+
     /// Return shared array pointer to the CPU memory shadow data.
     SharedArrayPtr<unsigned char> GetShadowDataShared() const { return shadowData_; }
 
@@ -83,7 +90,7 @@ private:
     void* MapBuffer(unsigned start, unsigned count, bool discard);
     /// Unmap the GPU buffer.
     void UnmapBuffer();
-    
+
     /// Shadow data.
     SharedArrayPtr<unsigned char> shadowData_;
     /// Number of indices.

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

@@ -25,10 +25,8 @@
 #include "../../Graphics/Camera.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsImpl.h"
-#include "../../IO/Log.h"
 #include "../../Graphics/Renderer.h"
 #include "../../Graphics/RenderSurface.h"
-#include "../../Scene/Scene.h"
 #include "../../Graphics/Texture.h"
 
 #include "../../DebugNew.h"
@@ -58,7 +56,7 @@ void RenderSurface::SetViewport(unsigned index, Viewport* viewport)
 {
     if (index >= viewports_.Size())
         viewports_.Resize(index + 1);
-    
+
     viewports_[index] = viewport;
 }
 
@@ -84,7 +82,7 @@ void RenderSurface::QueueUpdate()
     if (!updateQueued_)
     {
         bool hasValidView = false;
-        
+
         // Verify that there is at least 1 non-null viewport, as otherwise Renderer will not accept the surface and the update flag
         // will be left on
         for (unsigned i = 0; i < viewports_.Size(); ++i)
@@ -95,13 +93,13 @@ void RenderSurface::QueueUpdate()
                 break;
             }
         }
-        
+
         if (hasValidView)
         {
             Renderer* renderer = parentTexture_->GetSubsystem<Renderer>();
             if (renderer)
                 renderer->QueueRenderSurface(this);
-            
+
             updateQueued_ = true;
         }
     }
@@ -112,7 +110,7 @@ void RenderSurface::Release()
     Graphics* graphics = parentTexture_->GetGraphics();
     if (!graphics)
         return;
-    
+
     if (renderTargetView_)
     {
         for (unsigned i = 0; i < MAX_RENDERTARGETS; ++i)
@@ -120,10 +118,10 @@ void RenderSurface::Release()
             if (graphics->GetRenderTarget(i) == this)
                 graphics->ResetRenderTarget(i);
         }
-        
+
         if (graphics->GetDepthStencil() == this)
             graphics->ResetDepthStencil();
-        
+
         ((ID3D11View*)renderTargetView_)->Release();
         renderTargetView_ = 0;
     }

+ 12 - 5
Source/Urho3D/Graphics/Direct3D11/D3D11RenderSurface.h

@@ -35,13 +35,13 @@ class URHO3D_API RenderSurface : public RefCounted
 {
     friend class Texture2D;
     friend class TextureCube;
-    
+
 public:
     /// Construct with parent texture.
     RenderSurface(Texture* parentTexture);
     /// Destruct.
     ~RenderSurface();
-    
+
     /// Set number of viewports.
     void SetNumViewports(unsigned num);
     /// Set viewport.
@@ -56,31 +56,38 @@ public:
     void QueueUpdate();
     /// Release surface.
     void Release();
-    
+
     /// Return parent texture.
     Texture* GetParentTexture() const { return parentTexture_; }
+
     /// Return Direct3D rendertarget or depth-stencil view.
     void* GetRenderTargetView() const { return renderTargetView_; }
+
     /// Return width.
     int GetWidth() const;
     /// Return height.
     int GetHeight() const;
     /// Return usage.
     TextureUsage GetUsage() const;
+
     /// Return number of viewports.
     unsigned GetNumViewports() const { return viewports_.Size(); }
+
     /// Return viewport by index.
     Viewport* GetViewport(unsigned index) const;
+
     /// Return viewport update mode.
     RenderSurfaceUpdateMode GetUpdateMode() const { return updateMode_; }
+
     /// Return linked color rendertarget.
     RenderSurface* GetLinkedRenderTarget() const { return linkedRenderTarget_; }
+
     /// Return linked depth-stencil surface.
     RenderSurface* GetLinkedDepthStencil() const { return linkedDepthStencil_; }
-    
+
     /// Clear update flag. Called by Renderer.
     void WasUpdated();
-    
+
 private:
     /// Parent texture.
     Texture* parentTexture_;

+ 53 - 56
Source/Urho3D/Graphics/Direct3D11/D3D11ShaderVariation.cpp

@@ -22,17 +22,15 @@
 
 #include "../../Precompiled.h"
 
-#include "../../IO/File.h"
-#include "../../IO/FileSystem.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsImpl.h"
-#include "../../IO/Log.h"
-#include "../../Resource/ResourceCache.h"
 #include "../../Graphics/Shader.h"
-#include "../../Graphics/ShaderVariation.h"
 #include "../../Graphics/VertexBuffer.h"
+#include "../../IO/File.h"
+#include "../../IO/FileSystem.h"
+#include "../../IO/Log.h"
+#include "../../Resource/ResourceCache.h"
 
-#include <windows.h>
 #include <d3dcompiler.h>
 
 #include "../../DebugNew.h"
@@ -60,10 +58,10 @@ ShaderVariation::~ShaderVariation()
 bool ShaderVariation::Create()
 {
     Release();
-    
+
     if (!graphics_)
         return false;
-    
+
     if (!owner_)
     {
         compilerOutput_ = "Owner shader has expired";
@@ -74,9 +72,9 @@ bool ShaderVariation::Create()
     String path, name, extension;
     SplitPath(owner_->GetName(), path, name, extension);
     extension = type_ == VS ? ".vs4" : ".ps4";
-    
+
     String binaryShaderName = path + "Cache/" + name + "_" + StringHash(defines_).ToString() + extension;
-    
+
     if (!LoadByteCode(binaryShaderName))
     {
         // Compile shader if don't have valid bytecode
@@ -86,7 +84,7 @@ bool ShaderVariation::Create()
         if (owner_->GetTimeStamp())
             SaveByteCode(binaryShaderName);
     }
-    
+
     // Then create shader from the bytecode
     ID3D11Device* device = graphics_->GetImpl()->GetDevice();
     if (type_ == VS)
@@ -113,29 +111,29 @@ void ShaderVariation::Release()
     {
         if (!graphics_)
             return;
-        
+
         graphics_->CleanUpShaderPrograms(this);
 
         if (type_ == VS)
         {
             if (graphics_->GetVertexShader() == this)
                 graphics_->SetShaders(0, 0);
-            
+
             ((ID3D11VertexShader*)object_)->Release();
         }
         else
         {
             if (graphics_->GetPixelShader() == this)
                 graphics_->SetShaders(0, 0);
-            
+
             ((ID3D11PixelShader*)object_)->Release();
         }
 
         object_ = 0;
     }
-    
+
     compilerOutput_.Clear();
-    
+
     for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
         useTextureUnit_[i] = false;
     for (unsigned i = 0; i < MAX_SHADER_PARAMETER_GROUPS; ++i)
@@ -165,27 +163,26 @@ bool ShaderVariation::LoadByteCode(const String& binaryShaderName)
     ResourceCache* cache = owner_->GetSubsystem<ResourceCache>();
     if (!cache->Exists(binaryShaderName))
         return false;
-    
+
     FileSystem* fileSystem = owner_->GetSubsystem<FileSystem>();
     unsigned sourceTimeStamp = owner_->GetTimeStamp();
     // If source code is loaded from a package, its timestamp will be zero. Else check that binary is not older
     // than source
-    if (sourceTimeStamp && fileSystem->GetLastModifiedTime(cache->GetResourceFileName(binaryShaderName)) <
-        sourceTimeStamp)
+    if (sourceTimeStamp && fileSystem->GetLastModifiedTime(cache->GetResourceFileName(binaryShaderName)) < sourceTimeStamp)
         return false;
-    
+
     SharedPtr<File> file = cache->GetFile(binaryShaderName);
     if (!file || file->ReadFileID() != "USHD")
     {
         LOGERROR(binaryShaderName + " is not a valid shader bytecode file");
         return false;
     }
-    
+
     /// \todo Check that shader type and model match
-    unsigned short shaderType = file->ReadUShort();
-    unsigned short shaderModel = file->ReadUShort();
+    /*unsigned short shaderType = */file->ReadUShort();
+    /*unsigned short shaderModel = */file->ReadUShort();
     elementMask_ = file->ReadUInt();
-    
+
     unsigned numParameters = file->ReadUInt();
     for (unsigned i = 0; i < numParameters; ++i)
     {
@@ -197,28 +194,28 @@ bool ShaderVariation::LoadByteCode(const String& binaryShaderName)
         ShaderParameter parameter(type_, name_, buffer, offset, size);
         parameters_[StringHash(name)] = parameter;
     }
-    
+
     unsigned numTextureUnits = file->ReadUInt();
     for (unsigned i = 0; i < numTextureUnits; ++i)
     {
-        String unitName = file->ReadString();
+        /*String unitName = */file->ReadString();
         unsigned reg = file->ReadUByte();
-        
+
         if (reg < MAX_TEXTURE_UNITS)
             useTextureUnit_[reg] = true;
     }
-    
+
     unsigned byteCodeSize = file->ReadUInt();
     if (byteCodeSize)
     {
         byteCode_.Resize(byteCodeSize);
         file->Read(&byteCode_[0], byteCodeSize);
-        
+
         if (type_ == VS)
             LOGDEBUG("Loaded cached vertex shader " + GetFullName());
         else
             LOGDEBUG("Loaded cached pixel shader " + GetFullName());
-        
+
         CalculateConstantBufferSizes();
         return true;
     }
@@ -233,12 +230,12 @@ bool ShaderVariation::Compile()
 {
     const String& sourceCode = owner_->GetSourceCode(type_);
     Vector<String> defines = defines_.Split(' ');
-    
+
     // Set the entrypoint, profile and flags according to the shader being compiled
     const char* entryPoint = 0;
     const char* profile = 0;
     unsigned flags = D3DCOMPILE_OPTIMIZATION_LEVEL3;
-    
+
     defines.Push("D3D11");
 
     if (type_ == VS)
@@ -256,11 +253,11 @@ bool ShaderVariation::Compile()
     }
 
     defines.Push("MAXBONES=" + String(Graphics::GetMaxBones()));
-    
+
     // Collect defines into macros
     Vector<String> defineValues;
     PODVector<D3D_SHADER_MACRO> macros;
-    
+
     for (unsigned i = 0; i < defines.Size(); ++i)
     {
         unsigned equalsPos = defines[i].Find('=');
@@ -280,42 +277,42 @@ bool ShaderVariation::Compile()
         macros.Push(macro);
 
         // In debug mode, check that all defines are referenced by the shader code
-        #ifdef _DEBUG
+#ifdef _DEBUG
         if (sourceCode.Find(defines[i]) == String::NPOS)
             LOGWARNING("Shader " + GetFullName() + " does not use the define " + defines[i]);
-        #endif
+#endif
     }
-    
+
     D3D_SHADER_MACRO endMacro;
     endMacro.Name = 0;
     endMacro.Definition = 0;
     macros.Push(endMacro);
-    
+
     // Compile using D3DCompile
     ID3DBlob* shaderCode = 0;
     ID3DBlob* errorMsgs = 0;
-    
+
     if (FAILED(D3DCompile(sourceCode.CString(), sourceCode.Length(), owner_->GetName().CString(), &macros.Front(), 0,
         entryPoint, profile, flags, 0, &shaderCode, &errorMsgs)))
-        compilerOutput_ = String((const char*)errorMsgs->GetBufferPointer(), errorMsgs->GetBufferSize());
+        compilerOutput_ = String((const char*)errorMsgs->GetBufferPointer(), (unsigned)errorMsgs->GetBufferSize());
     else
     {
         if (type_ == VS)
             LOGDEBUG("Compiled vertex shader " + GetFullName());
         else
             LOGDEBUG("Compiled pixel shader " + GetFullName());
-        
+
         unsigned char* bufData = (unsigned char*)shaderCode->GetBufferPointer();
-        unsigned bufSize = shaderCode->GetBufferSize();
+        unsigned bufSize = (unsigned)shaderCode->GetBufferSize();
         // Use the original bytecode to reflect the parameters
         ParseParameters(bufData, bufSize);
         CalculateConstantBufferSizes();
 
         // Then strip everything not necessary to use the shader
         ID3DBlob* strippedCode = 0;
-        D3DStripShader(bufData, bufSize, D3DCOMPILER_STRIP_REFLECTION_DATA | D3DCOMPILER_STRIP_DEBUG_INFO |
-            D3DCOMPILER_STRIP_TEST_BLOBS, &strippedCode);
-        byteCode_.Resize(strippedCode->GetBufferSize());
+        D3DStripShader(bufData, bufSize,
+            D3DCOMPILER_STRIP_REFLECTION_DATA | D3DCOMPILER_STRIP_DEBUG_INFO | D3DCOMPILER_STRIP_TEST_BLOBS, &strippedCode);
+        byteCode_.Resize((unsigned)strippedCode->GetBufferSize());
         memcpy(&byteCode_[0], strippedCode->GetBufferPointer(), byteCode_.Size());
         strippedCode->Release();
     }
@@ -324,7 +321,7 @@ bool ShaderVariation::Compile()
         shaderCode->Release();
     if (errorMsgs)
         errorMsgs->Release();
-    
+
     return !byteCode_.Empty();
 }
 
@@ -347,11 +344,11 @@ void ShaderVariation::ParseParameters(unsigned char* bufData, unsigned bufSize)
         for (unsigned i = 0; i < shaderDesc.InputParameters; ++i)
         {
             D3D11_SIGNATURE_PARAMETER_DESC paramDesc;
-            reflection->GetInputParameterDesc((unsigned)i, &paramDesc);
+            reflection->GetInputParameterDesc((UINT)i, &paramDesc);
             for (unsigned j = 0; j < MAX_VERTEX_ELEMENTS; ++j)
             {
-                if (!String::Compare(paramDesc.SemanticName, VertexBuffer::elementSemantics[j], true) && paramDesc.SemanticIndex ==
-                    VertexBuffer::elementSemanticIndices[j])
+                if (!String::Compare(paramDesc.SemanticName, VertexBuffer::elementSemantics[j], true) &&
+                    paramDesc.SemanticIndex == VertexBuffer::elementSemanticIndices[j])
                 {
                     elementMask_ |= (1 << j);
                     break;
@@ -401,16 +398,16 @@ void ShaderVariation::SaveByteCode(const String& binaryShaderName)
 {
     ResourceCache* cache = owner_->GetSubsystem<ResourceCache>();
     FileSystem* fileSystem = owner_->GetSubsystem<FileSystem>();
-    
+
     String path = GetPath(cache->GetResourceFileName(owner_->GetName())) + "Cache/";
     String fullName = path + GetFileNameAndExtension(binaryShaderName);
     if (!fileSystem->DirExists(path))
         fileSystem->CreateDir(path);
-    
+
     SharedPtr<File> file(new File(owner_->GetContext(), fullName, FILE_WRITE));
     if (!file->IsOpen())
         return;
-    
+
     file->WriteFileID("USHD");
     file->WriteShort((unsigned short)type_);
     file->WriteShort(4);
@@ -424,7 +421,7 @@ void ShaderVariation::SaveByteCode(const String& binaryShaderName)
         file->WriteUInt(i->second_.offset_);
         file->WriteUInt(i->second_.size_);
     }
-    
+
     unsigned usedTextureUnits = 0;
     for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
     {
@@ -437,10 +434,10 @@ void ShaderVariation::SaveByteCode(const String& binaryShaderName)
         if (useTextureUnit_[i])
         {
             file->WriteString(graphics_->GetTextureUnitName((TextureUnit)i));
-            file->WriteUByte(i);
+            file->WriteUByte((unsigned char)i);
         }
     }
-    
+
     file->WriteUInt(byteCode_.Size());
     if (byteCode_.Size())
         file->Write(&byteCode_[0], byteCode_.Size());
@@ -450,7 +447,7 @@ void ShaderVariation::CalculateConstantBufferSizes()
 {
     for (unsigned i = 0; i < MAX_SHADER_PARAMETER_GROUPS; ++i)
         constantBufferSizes_[i] = 0;
-    
+
     for (HashMap<StringHash, ShaderParameter>::ConstIterator i = parameters_.Begin(); i != parameters_.End(); ++i)
     {
         if (i->second_.buffer_ < MAX_SHADER_PARAMETER_GROUPS)

+ 19 - 8
Source/Urho3D/Graphics/Direct3D11/D3D11ShaderVariation.h

@@ -22,11 +22,11 @@
 
 #pragma once
 
-#include "../../Graphics/GPUObject.h"
-#include "../../Graphics/GraphicsDefs.h"
 #include "../../Container/HashSet.h"
 #include "../../Container/RefCounted.h"
 #include "../../Container/ArrayPtr.h"
+#include "../../Graphics/GPUObject.h"
+#include "../../Graphics/GraphicsDefs.h"
 
 namespace Urho3D
 {
@@ -46,7 +46,7 @@ struct ShaderParameter
         bufferPtr_(0)
     {
     }
-    
+
     /// Construct with parameters.
     ShaderParameter(ShaderType type, const String& name, unsigned buffer, unsigned offset, unsigned size, ConstantBuffer* ptr = 0) :
         type_(type),
@@ -57,7 +57,7 @@ struct ShaderParameter
         bufferPtr_(ptr)
     {
     }
-    
+
     /// %Shader type.
     ShaderType type_;
     /// Name of the parameter.
@@ -80,39 +80,50 @@ public:
     ShaderVariation(Shader* owner, ShaderType type);
     /// Destruct.
     virtual ~ShaderVariation();
-    
+
     /// Release the shader.
     virtual void Release();
-    
+
     /// Compile the shader. Return true if successful.
     bool Create();
     /// Set name.
     void SetName(const String& name);
     /// Set defines.
     void SetDefines(const String& defines);
-    
+
     /// Return the owner resource.
     Shader* GetOwner() const;
+
     /// Return shader type.
     ShaderType GetShaderType() const { return type_; }
+
     /// Return shader name.
     const String& GetName() const { return name_; }
+
     /// Return full shader name.
     String GetFullName() const { return name_ + "(" + defines_ + ")"; }
+
     /// Return whether uses a parameter.
     bool HasParameter(StringHash param) const { return parameters_.Contains(param); }
+
     /// Return whether uses a texture unit (only for pixel shaders.)
     bool HasTextureUnit(TextureUnit unit) const { return useTextureUnit_[unit]; }
+
     /// Return all parameter definitions.
     const HashMap<StringHash, ShaderParameter>& GetParameters() const { return parameters_; }
+
     /// Return vertex element mask.
     unsigned GetElementMask() const { return elementMask_; }
+
     /// Return shader bytecode.
     const PODVector<unsigned char>& GetByteCode() const { return byteCode_; }
+
     /// Return defines.
     const String& GetDefines() const { return defines_; }
+
     /// Return compile error/warning string.
     const String& GetCompilerOutput() const { return compilerOutput_; }
+
     /// Return constant buffer data sizes.
     const unsigned* GetConstantBufferSizes() const { return &constantBufferSizes_[0]; }
 
@@ -127,7 +138,7 @@ private:
     void SaveByteCode(const String& binaryShaderName);
     /// Calculate constant buffer sizes from parameters.
     void CalculateConstantBufferSizes();
-    
+
     /// Shader this variation belongs to.
     WeakPtr<Shader> owner_;
     /// Shader type.

+ 29 - 31
Source/Urho3D/Graphics/Direct3D11/D3D11Texture.cpp

@@ -22,15 +22,13 @@
 
 #include "../../Precompiled.h"
 
-#include "../../IO/FileSystem.h"
-#include "../../IO/Log.h"
+#include "../../Core/Profiler.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/Material.h"
-#include "../../Core/Profiler.h"
+#include "../../IO/FileSystem.h"
+#include "../../IO/Log.h"
 #include "../../Resource/ResourceCache.h"
-#include "../../Core/StringUtils.h"
-#include "../../Graphics/Texture.h"
 #include "../../Resource/XMLFile.h"
 
 #include "../../DebugNew.h"
@@ -69,7 +67,7 @@ static const D3D11_FILTER d3dFilterMode[] =
     D3D11_FILTER_COMPARISON_ANISOTROPIC
 };
 
-static const D3D11_TEXTURE_ADDRESS_MODE d3dAddressMode[] = 
+static const D3D11_TEXTURE_ADDRESS_MODE d3dAddressMode[] =
 {
     D3D11_TEXTURE_ADDRESS_WRAP,
     D3D11_TEXTURE_ADDRESS_MIRROR,
@@ -97,7 +95,7 @@ Texture::Texture(Context* context) :
     for (int i = 0; i < MAX_COORDS; ++i)
         addressMode_[i] = ADDRESS_WRAP;
     for (int i = 0; i < MAX_TEXTURE_QUALITY_LEVELS; ++i)
-        mipsToSkip_[i] = MAX_TEXTURE_QUALITY_LEVELS - 1 - i;
+        mipsToSkip_[i] = (unsigned)(MAX_TEXTURE_QUALITY_LEVELS - 1 - i);
 }
 
 Texture::~Texture()
@@ -140,7 +138,7 @@ void Texture::SetSRGB(bool enable)
 {
     if (graphics_)
         enable &= graphics_->GetSRGBSupport();
-    
+
     // Note: on D3D11 sRGB only affects the texture before creation
     sRGB_ = enable;
 }
@@ -154,8 +152,8 @@ void Texture::SetMipsToSkip(int quality, int mips)
 {
     if (quality >= QUALITY_LOW && quality < MAX_TEXTURE_QUALITY_LEVELS)
     {
-        mipsToSkip_[quality] = mips;
-        
+        mipsToSkip_[quality] = (unsigned)mips;
+
         // Make sure a higher quality level does not actually skip more mips
         for (int i = 1; i < MAX_TEXTURE_QUALITY_LEVELS; ++i)
         {
@@ -215,13 +213,13 @@ unsigned Texture::GetRowDataSize(int width) const
     {
     case DXGI_FORMAT_R8_UNORM:
     case DXGI_FORMAT_A8_UNORM:
-        return width;
-    
+        return (unsigned)width;
+
     case DXGI_FORMAT_R8G8_UNORM:
     case DXGI_FORMAT_R16_UNORM:
     case DXGI_FORMAT_R16_FLOAT:
     case DXGI_FORMAT_R16_TYPELESS:
-        return width * 2;
+        return (unsigned)(width * 2);
 
     case DXGI_FORMAT_R8G8B8A8_UNORM:
     case DXGI_FORMAT_R16G16_UNORM:
@@ -229,22 +227,22 @@ unsigned Texture::GetRowDataSize(int width) const
     case DXGI_FORMAT_R32_FLOAT:
     case DXGI_FORMAT_R24G8_TYPELESS:
     case DXGI_FORMAT_R32_TYPELESS:
-        return width * 4;
-        
+        return (unsigned)(width * 4);
+
     case DXGI_FORMAT_R16G16B16A16_UNORM:
     case DXGI_FORMAT_R16G16B16A16_FLOAT:
-        return width * 8;
-        
+        return (unsigned)(width * 8);
+
     case DXGI_FORMAT_R32G32B32A32_FLOAT:
-        return width * 16;
-        
+        return (unsigned)(width * 16);
+
     case DXGI_FORMAT_BC1_UNORM:
-        return ((width + 3) >> 2) * 8;
-        
+        return (unsigned)(((width + 3) >> 2) * 8);
+
     case DXGI_FORMAT_BC2_UNORM:
     case DXGI_FORMAT_BC3_UNORM:
-        return ((width + 3) >> 2) * 16;
-        
+        return (unsigned)(((width + 3) >> 2) * 16);
+
     default:
         return 0;
     }
@@ -262,7 +260,7 @@ void Texture::SetParameters(XMLFile* file)
 {
     if (!file)
         return;
-    
+
     XMLElement rootElem = file->GetRoot();
     SetParameters(rootElem);
 }
@@ -273,7 +271,7 @@ void Texture::SetParameters(const XMLElement& element)
     while (paramElem)
     {
         String name = paramElem.GetName();
-        
+
         if (name == "address")
         {
             String coord = paramElem.GetAttributeLower("coord");
@@ -284,19 +282,19 @@ void Texture::SetParameters(const XMLElement& element)
                 SetAddressMode(coordIndex, (TextureAddressMode)GetStringListIndex(mode.CString(), addressModeNames, ADDRESS_WRAP));
             }
         }
-        
+
         if (name == "border")
             SetBorderColor(paramElem.GetColor("color"));
-        
+
         if (name == "filter")
         {
             String mode = paramElem.GetAttributeLower("mode");
             SetFilterMode((TextureFilterMode)GetStringListIndex(mode.CString(), filterModeNames, FILTER_DEFAULT));
         }
-        
+
         if (name == "mipmap")
             SetNumLevels(paramElem.GetBool("enable") ? 0 : 1);
-        
+
         if (name == "quality")
         {
             if (paramElem.HasAttribute("low"))
@@ -311,7 +309,7 @@ void Texture::SetParameters(const XMLElement& element)
 
         if (name == "srgb")
             SetSRGB(paramElem.GetBool("enable"));
-        
+
         paramElem = paramElem.GetNext();
     }
 }
@@ -435,7 +433,7 @@ void Texture::CheckTextureBudget(StringHash type)
     unsigned textureUse = cache->GetMemoryUse(type);
     if (!textureBudget)
         return;
-    
+
     // If textures are over the budget, they likely can not be freed directly as materials still refer to them.
     // Therefore free unused materials first
     if (textureUse > textureBudget)

+ 22 - 5
Source/Urho3D/Graphics/Direct3D11/D3D11Texture.h

@@ -23,9 +23,9 @@
 #pragma once
 
 #include "../../Container/ArrayPtr.h"
-#include "../../Math/Color.h"
 #include "../../Graphics/GPUObject.h"
 #include "../../Graphics/GraphicsDefs.h"
+#include "../../Math/Color.h"
 #include "../../Resource/Resource.h"
 
 namespace Urho3D
@@ -44,7 +44,7 @@ public:
     Texture(Context* context);
     /// Destruct.
     virtual ~Texture();
-    
+
     /// Set number of requested mip levels. Needs to be called before setting size.
     void SetNumLevels(unsigned levels);
     /// Set filtering mode.
@@ -61,31 +61,43 @@ public:
     void SetBackupTexture(Texture* texture);
     /// Set mip levels to skip on a quality setting when loading. Ensures higher quality levels do not skip more.
     void SetMipsToSkip(int quality, int mips);
-    
+
     /// Return texture format.
     unsigned GetFormat() const { return format_; }
+
     /// Return whether the texture format is compressed.
     bool IsCompressed() const;
+
     /// Return number of mip levels.
     unsigned GetLevels() const { return levels_; }
+
     /// Return width.
     int GetWidth() const { return width_; }
+
     /// Return height.
     int GetHeight() const { return height_; }
+
     /// Return height.
     int GetDepth() const { return depth_; }
+
     /// Return filtering mode.
     TextureFilterMode GetFilterMode() const { return filterMode_; }
+
     /// Return addressing mode by texture coordinate.
     TextureAddressMode GetAddressMode(TextureCoordinate coord) const { return addressMode_[coord]; }
+
     /// Return whether shadow compare is enabled.
     bool GetShadowCompare() const { return shadowCompare_; }
+
     /// Return border color.
     const Color& GetBorderColor() const { return borderColor_; }
+
     /// Return whether is using sRGB sampling and writing.
     bool GetSRGB() const { return sRGB_; }
+
     /// Return backup texture.
     Texture* GetBackupTexture() const { return backupTexture_; }
+
     /// Return mip levels to skip on a quality setting when loading.
     int GetMipsToSkip(int quality) const;
     /// Return mip level width, or 0 if level does not exist.
@@ -94,8 +106,10 @@ public:
     int GetLevelHeight(unsigned level) const;
     /// Return mip level depth, or 0 if level does not exist.
     int GetLevelDepth(unsigned level) const;
+
     /// Return texture usage type.
     TextureUsage GetUsage() const { return usage_; }
+
     /// Return data size in bytes for a rectangular region.
     unsigned GetDataSize(int width, int height) const;
     /// Return data size in bytes for a volume region.
@@ -104,6 +118,7 @@ public:
     unsigned GetRowDataSize(int width) const;
     /// Return number of image components required to receive pixel data from GetData(), or 0 for compressed images.
     unsigned GetComponents() const;
+
     /// Return whether the parameters are dirty.
     bool GetParametersDirty() const { return parametersDirty_ || !sampler_; }
 
@@ -115,11 +130,13 @@ public:
     void SetParametersDirty();
     /// Create sampler state object after parameters have been changed. Called by Graphics when assigning the texture.
     void UpdateParameters();
+
     /// Return shader resource view.
     void* GetShaderResourceView() const { return shaderResourceView_; }
+
     /// Return sampler state object.
     void* GetSampler() const { return sampler_; }
-    
+
     /// Check maximum allowed mip levels for a specific texture size.
     static unsigned CheckMaxLevels(int width, int height, unsigned requestedLevels);
     /// Check maximum allowed mip levels for a specific 3D texture size.
@@ -134,7 +151,7 @@ public:
 protected:
     /// Check whether texture memory budget has been exceeded. Free unused materials in that case to release the texture references.
     void CheckTextureBudget(StringHash type);
-    
+
     /// Shader resource view.
     void* shaderResourceView_;
     /// Sampler state object.

+ 58 - 56
Source/Urho3D/Graphics/Direct3D11/D3D11Texture2D.cpp

@@ -23,15 +23,15 @@
 #include "../../Precompiled.h"
 
 #include "../../Core/Context.h"
-#include "../../IO/FileSystem.h"
+#include "../../Core/Profiler.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsEvents.h"
 #include "../../Graphics/GraphicsImpl.h"
-#include "../../IO/Log.h"
 #include "../../Graphics/Renderer.h"
-#include "../../Core/Profiler.h"
-#include "../../Resource/ResourceCache.h"
 #include "../../Graphics/Texture2D.h"
+#include "../../IO/FileSystem.h"
+#include "../../IO/Log.h"
+#include "../../Resource/ResourceCache.h"
 #include "../../Resource/XMLFile.h"
 
 #include "../../DebugNew.h"
@@ -59,7 +59,7 @@ bool Texture2D::BeginLoad(Deserializer& source)
     // In headless mode, do not actually load the texture, just return success
     if (!graphics_)
         return true;
-    
+
     // Load the image data for EndLoad()
     loadImage_ = new Image(context_);
     if (!loadImage_->Load(source))
@@ -71,12 +71,12 @@ bool Texture2D::BeginLoad(Deserializer& source)
     // Precalculate mip levels if async loading
     if (GetAsyncLoadState() == ASYNC_LOADING)
         loadImage_->PrecalculateLevels();
-    
+
     // Load the optional parameters file
     ResourceCache* cache = GetSubsystem<ResourceCache>();
     String xmlName = ReplaceExtension(GetName(), ".xml");
     loadParameters_ = cache->GetTempResource<XMLFile>(xmlName, false);
-    
+
     return true;
 }
 
@@ -85,16 +85,16 @@ bool Texture2D::EndLoad()
     // In headless mode, do not actually load the texture, just return success
     if (!graphics_)
         return true;
-    
+
     // If over the texture budget, see if materials can be freed to allow textures to be freed
     CheckTextureBudget(GetTypeStatic());
 
     SetParameters(loadParameters_);
     bool success = SetData(loadImage_);
-    
+
     loadImage_.Reset();
     loadParameters_.Reset();
-    
+
     return success;
 }
 
@@ -104,16 +104,16 @@ void Texture2D::Release()
     {
         if (!graphics_)
             return;
-        
+
         for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
         {
             if (graphics_->GetTexture(i) == this)
                 graphics_->SetTexture(i, 0);
         }
-        
+
         if (renderSurface_)
             renderSurface_->Release();
-        
+
         ((ID3D11Resource*)object_)->Release();
         object_ = 0;
 
@@ -141,7 +141,7 @@ bool Texture2D::SetSize(int width, int height, unsigned format, TextureUsage usa
     // Delete the old rendersurface if any
     renderSurface_.Reset();
     usage_ = usage;
-    
+
     if (usage_ == TEXTURE_RENDERTARGET || usage_ == TEXTURE_DEPTHSTENCIL)
     {
         renderSurface_ = new RenderSurface(this);
@@ -151,7 +151,7 @@ bool Texture2D::SetSize(int width, int height, unsigned format, TextureUsage usa
         filterMode_ = FILTER_NEAREST;
         requestedLevels_ = 1;
     }
-    
+
     if (usage_ == TEXTURE_RENDERTARGET)
         SubscribeToEvent(E_RENDERSURFACEUPDATE, HANDLER(Texture2D, HandleRenderSurfaceUpdate));
     else
@@ -160,32 +160,32 @@ bool Texture2D::SetSize(int width, int height, unsigned format, TextureUsage usa
     width_ = width;
     height_ = height;
     format_ = format;
-    
+
     return Create();
 }
 
 bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, const void* data)
 {
     PROFILE(SetTextureData);
-    
+
     if (!object_)
     {
         LOGERROR("No texture created, can not set data");
         return false;
     }
-    
+
     if (!data)
     {
         LOGERROR("Null source for setting data");
         return false;
     }
-    
+
     if (level >= levels_)
     {
         LOGERROR("Illegal mip level for setting data");
         return false;
     }
-    
+
     int levelWidth = GetLevelWidth(level);
     int levelHeight = GetLevelHeight(level);
     if (x < 0 || x + width > levelWidth || y < 0 || y + height > levelHeight || width <= 0 || height <= 0)
@@ -193,7 +193,7 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
         LOGERROR("Illegal dimensions for setting data");
         return false;
     }
-    
+
     // If compressed, align the update region on a block
     if (IsCompressed())
     {
@@ -238,10 +238,10 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
     else
     {
         D3D11_BOX destBox;
-        destBox.left = x;
-        destBox.right = x + width;
-        destBox.top = y;
-        destBox.bottom = y + height;
+        destBox.left = (UINT)x;
+        destBox.right = (UINT)(x + width);
+        destBox.top = (UINT)y;
+        destBox.bottom = (UINT)(y + height);
         destBox.front = 0;
         destBox.back = 1;
 
@@ -259,14 +259,14 @@ bool Texture2D::SetData(SharedPtr<Image> image, bool useAlpha)
         LOGERROR("Null image, can not load texture");
         return false;
     }
-    
+
     unsigned memoryUse = sizeof(Texture2D);
-    
+
     int quality = QUALITY_HIGH;
     Renderer* renderer = GetSubsystem<Renderer>();
     if (renderer)
         quality = renderer->GetTextureQuality();
-    
+
     if (!image->IsCompressed())
     {
         // Convert unsuitable formats to RGBA
@@ -283,7 +283,7 @@ bool Texture2D::SetData(SharedPtr<Image> image, bool useAlpha)
         int levelWidth = image->GetWidth();
         int levelHeight = image->GetHeight();
         unsigned format = 0;
-        
+
         // Discard unnecessary mip levels
         for (unsigned i = 0; i < mipsToSkip_[quality]; ++i)
         {
@@ -292,28 +292,30 @@ bool Texture2D::SetData(SharedPtr<Image> image, bool useAlpha)
             levelWidth = image->GetWidth();
             levelHeight = image->GetHeight();
         }
-        
+
         switch (components)
         {
         case 1:
             format = Graphics::GetAlphaFormat();
             break;
-            
+
         case 4:
             format = Graphics::GetRGBAFormat();
             break;
+
+        default: break;
         }
-        
+
         // 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)
             requestedLevels_ = 0;
         SetSize(levelWidth, levelHeight, format);
-        
+
         for (unsigned i = 0; i < levels_; ++i)
         {
             SetData(i, 0, 0, levelWidth, levelHeight, levelData);
             memoryUse += levelWidth * levelHeight * components;
-            
+
             if (i < levels_ - 1)
             {
                 image = image->GetNextLevel();
@@ -330,13 +332,13 @@ bool Texture2D::SetData(SharedPtr<Image> image, bool useAlpha)
         unsigned levels = image->GetNumCompressedLevels();
         unsigned format = graphics_->GetFormat(image->GetCompressedFormat());
         bool needDecompress = false;
-        
+
         if (!format)
         {
             format = Graphics::GetRGBAFormat();
             needDecompress = true;
         }
-        
+
         unsigned mipsToSkip = mipsToSkip_[quality];
         if (mipsToSkip >= levels)
             mipsToSkip = levels - 1;
@@ -344,10 +346,10 @@ bool Texture2D::SetData(SharedPtr<Image> image, bool useAlpha)
             --mipsToSkip;
         width /= (1 << mipsToSkip);
         height /= (1 << mipsToSkip);
-        
-        SetNumLevels(Max((int)(levels - mipsToSkip), 1));
+
+        SetNumLevels((unsigned)Max((int)(levels - mipsToSkip), 1));
         SetSize(width, height, format);
-        
+
         for (unsigned i = 0; i < levels_ && i < levels - mipsToSkip; ++i)
         {
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
@@ -366,7 +368,7 @@ bool Texture2D::SetData(SharedPtr<Image> image, bool useAlpha)
             }
         }
     }
-    
+
     SetMemoryUse(memoryUse);
     return true;
 }
@@ -378,26 +380,26 @@ bool Texture2D::GetData(unsigned level, void* dest) const
         LOGERROR("No texture created, can not get data");
         return false;
     }
-    
+
     if (!dest)
     {
         LOGERROR("Null destination for getting data");
         return false;
     }
-    
+
     if (level >= levels_)
     {
         LOGERROR("Illegal mip level for getting data");
         return false;
     }
-    
+
     int levelWidth = GetLevelWidth(level);
     int levelHeight = GetLevelHeight(level);
-    
+
     D3D11_TEXTURE2D_DESC textureDesc;
     memset(&textureDesc, 0, sizeof textureDesc);
-    textureDesc.Width = levelWidth;
-    textureDesc.Height = levelHeight;
+    textureDesc.Width = (UINT)levelWidth;
+    textureDesc.Height = (UINT)levelHeight;
     textureDesc.MipLevels = 1;
     textureDesc.ArraySize = 1;
     textureDesc.Format = (DXGI_FORMAT)format_;
@@ -417,18 +419,18 @@ bool Texture2D::GetData(unsigned level, void* dest) const
     unsigned srcSubResource = D3D11CalcSubresource(level, 0, levels_);
     D3D11_BOX srcBox;
     srcBox.left = 0;
-    srcBox.right = levelWidth;
+    srcBox.right = (UINT)levelWidth;
     srcBox.top = 0;
-    srcBox.bottom = levelHeight;
+    srcBox.bottom = (UINT)levelHeight;
     srcBox.front = 0;
     srcBox.back = 1;
     graphics_->GetImpl()->GetDeviceContext()->CopySubresourceRegion(stagingTexture, 0, 0, 0, 0, (ID3D11Resource*)object_,
         srcSubResource, &srcBox);
-    
+
     D3D11_MAPPED_SUBRESOURCE mappedData;
     mappedData.pData = 0;
     unsigned rowSize = GetRowDataSize(levelWidth);
-    unsigned numRows = IsCompressed() ? (levelHeight + 3) >> 2 : levelHeight;
+    unsigned numRows = (unsigned)(IsCompressed() ? (levelHeight + 3) >> 2 : levelHeight);
 
     graphics_->GetImpl()->GetDeviceContext()->Map((ID3D11Resource*)stagingTexture, 0, D3D11_MAP_READ, 0, &mappedData);
     if (mappedData.pData)
@@ -450,16 +452,16 @@ bool Texture2D::GetData(unsigned level, void* dest) const
 bool Texture2D::Create()
 {
     Release();
-    
+
     if (!graphics_ || !width_ || !height_)
         return false;
-    
+
     levels_ = CheckMaxLevels(width_, height_, requestedLevels_);
-    
+
     D3D11_TEXTURE2D_DESC textureDesc;
     memset(&textureDesc, 0, sizeof textureDesc);
-    textureDesc.Width = width_;
-    textureDesc.Height = height_;
+    textureDesc.Width = (UINT)width_;
+    textureDesc.Height = (UINT)height_;
     textureDesc.MipLevels = levels_;
     textureDesc.ArraySize = 1;
     textureDesc.Format = (DXGI_FORMAT)(sRGB_ ? GetSRGBFormat(format_) : format_);
@@ -484,7 +486,7 @@ bool Texture2D::Create()
     memset(&resourceViewDesc, 0, sizeof resourceViewDesc);
     resourceViewDesc.Format = (DXGI_FORMAT)GetSRVFormat(textureDesc.Format);
     resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
-    resourceViewDesc.Texture2D.MipLevels = (unsigned)levels_;
+    resourceViewDesc.Texture2D.MipLevels = (UINT)levels_;
 
     graphics_->GetImpl()->GetDevice()->CreateShaderResourceView((ID3D11Resource*)object_, &resourceViewDesc,
         (ID3D11ShaderResourceView**)&shaderResourceView_);

+ 8 - 7
Source/Urho3D/Graphics/Direct3D11/D3D11Texture2D.h

@@ -22,8 +22,8 @@
 
 #pragma once
 
-#include "../../Graphics/RenderSurface.h"
 #include "../../Container/Ptr.h"
+#include "../../Graphics/RenderSurface.h"
 #include "../../Graphics/Texture.h"
 
 namespace Urho3D
@@ -36,7 +36,7 @@ class XMLFile;
 class URHO3D_API Texture2D : public Texture
 {
     OBJECT(Texture2D);
-    
+
 public:
     /// Construct.
     Texture2D(Context* context);
@@ -44,32 +44,33 @@ public:
     virtual ~Texture2D();
     /// Register object factory.
     static void RegisterObject(Context* context);
-    
+
     /// Load resource from stream. May be called from a worker thread. Return true if successful.
     virtual bool BeginLoad(Deserializer& source);
     /// Finish resource loading. Always called from the main thread. Return true if successful.
     virtual bool EndLoad();
     /// Release texture.
     virtual void Release();
-    
+
     /// Set size, format and usage. Zero size will follow application window size. Return true if successful.
     bool SetSize(int width, int height, unsigned format, TextureUsage usage = TEXTURE_STATIC);
     /// Set data either partially or fully on a mip level. Return true if successful.
     bool SetData(unsigned level, int x, int y, int width, int height, const void* data);
     /// Set data from an image. Return true if successful. Optionally make a single channel image alpha-only.
     bool SetData(SharedPtr<Image> image, bool useAlpha = false);
-    
+
     /// Get data from a mip level. The destination buffer must be big enough. Return true if successful.
     bool GetData(unsigned level, void* dest) const;
+
     /// Return render surface.
     RenderSurface* GetRenderSurface() const { return renderSurface_; }
-    
+
 private:
     /// Create texture.
     bool Create();
     /// Handle render surface update event.
     void HandleRenderSurfaceUpdate(StringHash eventType, VariantMap& eventData);
-    
+
     /// Render surface.
     SharedPtr<RenderSurface> renderSurface_;
     /// Image file acquired during BeginLoad.

+ 67 - 64
Source/Urho3D/Graphics/Direct3D11/D3D11Texture3D.cpp

@@ -23,15 +23,15 @@
 #include "../../Precompiled.h"
 
 #include "../../Core/Context.h"
-#include "../../IO/FileSystem.h"
+#include "../../Core/Profiler.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsEvents.h"
 #include "../../Graphics/GraphicsImpl.h"
-#include "../../IO/Log.h"
 #include "../../Graphics/Renderer.h"
-#include "../../Core/Profiler.h"
-#include "../../Resource/ResourceCache.h"
 #include "../../Graphics/Texture3D.h"
+#include "../../IO/FileSystem.h"
+#include "../../IO/Log.h"
+#include "../../Resource/ResourceCache.h"
 #include "../../Resource/XMLFile.h"
 
 #include "../../DebugNew.h"
@@ -61,10 +61,10 @@ bool Texture3D::BeginLoad(Deserializer& source)
     // In headless mode, do not actually load the texture, just return success
     if (!graphics_)
         return true;
-    
+
     String texPath, texName, texExt;
     SplitPath(GetName(), texPath, texName, texExt);
-    
+
     cache->ResetDependencies(this);
 
     loadParameters_ = new XMLFile(context_);
@@ -73,7 +73,7 @@ bool Texture3D::BeginLoad(Deserializer& source)
         loadParameters_.Reset();
         return false;
     }
-    
+
     XMLElement textureElem = loadParameters_->GetRoot();
     XMLElement volumeElem = textureElem.GetChild("volume");
     XMLElement colorlutElem = textureElem.GetChild("colorlut");
@@ -81,7 +81,7 @@ bool Texture3D::BeginLoad(Deserializer& source)
     if (volumeElem)
     {
         String name = volumeElem.GetAttribute("name");
-        
+
         String volumeTexPath, volumeTexName, volumeTexExt;
         SplitPath(name, volumeTexPath, volumeTexName, volumeTexExt);
         // If path is empty, add the XML file path
@@ -98,7 +98,7 @@ bool Texture3D::BeginLoad(Deserializer& source)
     else if (colorlutElem)
     {
         String name = colorlutElem.GetAttribute("name");
-        
+
         String colorlutTexPath, colorlutTexName, colorlutTexExt;
         SplitPath(name, colorlutTexPath, colorlutTexName, colorlutTexExt);
         // If path is empty, add the XML file path
@@ -129,16 +129,16 @@ bool Texture3D::EndLoad()
     // In headless mode, do not actually load the texture, just return success
     if (!graphics_)
         return true;
-    
+
     // If over the texture budget, see if materials can be freed to allow textures to be freed
     CheckTextureBudget(GetTypeStatic());
 
     SetParameters(loadParameters_);
     bool success = SetData(loadImage_);
-    
+
     loadImage_.Reset();
     loadParameters_.Reset();
-    
+
     return success;
 }
 
@@ -148,16 +148,16 @@ void Texture3D::Release()
     {
         if (!graphics_)
             return;
-        
+
         for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
         {
             if (graphics_->GetTexture(i) == this)
                 graphics_->SetTexture(i, 0);
         }
-        
+
         if (renderSurface_)
             renderSurface_->Release();
-        
+
         ((ID3D11Resource*)object_)->Release();
         object_ = 0;
 
@@ -196,7 +196,7 @@ bool Texture3D::SetSize(int width, int height, int depth, unsigned format, Textu
         filterMode_ = FILTER_NEAREST;
         requestedLevels_ = 1;
     }
-    
+
     if (usage_ == TEXTURE_RENDERTARGET)
         SubscribeToEvent(E_RENDERSURFACEUPDATE, HANDLER(Texture3D, HandleRenderSurfaceUpdate));
     else
@@ -206,41 +206,42 @@ bool Texture3D::SetSize(int width, int height, int depth, unsigned format, Textu
     height_ = height;
     depth_ = depth;
     format_ = format;
-    
+
     return Create();
 }
 
 bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int height, int depth, const void* data)
 {
     PROFILE(SetTextureData);
-    
+
     if (!object_)
     {
         LOGERROR("No texture created, can not set data");
         return false;
     }
-    
+
     if (!data)
     {
         LOGERROR("Null source for setting data");
         return false;
     }
-    
+
     if (level >= levels_)
     {
         LOGERROR("Illegal mip level for setting data");
         return false;
     }
-    
+
     int levelWidth = GetLevelWidth(level);
     int levelHeight = GetLevelHeight(level);
     int levelDepth = GetLevelDepth(level);
-    if (x < 0 || x + width > levelWidth || y < 0 || y + height > levelHeight || z < 0 || z + depth > levelDepth || width <= 0 || height <= 0 || depth <= 0)
+    if (x < 0 || x + width > levelWidth || y < 0 || y + height > levelHeight || z < 0 || z + depth > levelDepth || width <= 0 ||
+        height <= 0 || depth <= 0)
     {
         LOGERROR("Illegal dimensions for setting data");
         return false;
     }
-    
+
     // If compressed, align the update region on a block
     if (IsCompressed())
     {
@@ -276,8 +277,8 @@ bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int heig
             {
                 for (int row = 0; row < height; ++row)
                 {
-                    memcpy((unsigned char*)mappedData.pData + (page + z) * mappedData.DepthPitch + (row + y) * mappedData.RowPitch
-                        + rowStart, src + row * rowSize, rowSize);
+                    memcpy((unsigned char*)mappedData.pData + (page + z) * mappedData.DepthPitch + (row + y) * mappedData.RowPitch +
+                           rowStart, src + row * rowSize, rowSize);
                 }
             }
 
@@ -295,12 +296,12 @@ bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int heig
             levelHeight = (levelHeight + 3) >> 2;
 
         D3D11_BOX destBox;
-        destBox.left = x;
-        destBox.right = x + width;
-        destBox.top = y;
-        destBox.bottom = y + height;
-        destBox.front = z;
-        destBox.back = z + depth;
+        destBox.left = (UINT)x;
+        destBox.right = (UINT)(x + width);
+        destBox.top = (UINT)y;
+        destBox.bottom = (UINT)(y + height);
+        destBox.front = (UINT)z;
+        destBox.back = (UINT)(z + depth);
 
         graphics_->GetImpl()->GetDeviceContext()->UpdateSubresource((ID3D11Resource*)object_, subResource, &destBox, data,
             rowSize, levelHeight * rowSize);
@@ -316,14 +317,14 @@ bool Texture3D::SetData(SharedPtr<Image> image, bool useAlpha)
         LOGERROR("Null image, can not load texture");
         return false;
     }
-    
+
     unsigned memoryUse = sizeof(Texture3D);
-    
+
     int quality = QUALITY_HIGH;
     Renderer* renderer = GetSubsystem<Renderer>();
     if (renderer)
         quality = renderer->GetTextureQuality();
-    
+
     if (!image->IsCompressed())
     {
         // Convert unsuitable formats to RGBA
@@ -341,7 +342,7 @@ bool Texture3D::SetData(SharedPtr<Image> image, bool useAlpha)
         int levelHeight = image->GetHeight();
         int levelDepth = image->GetDepth();
         unsigned format = 0;
-        
+
         // Discard unnecessary mip levels
         for (unsigned i = 0; i < mipsToSkip_[quality]; ++i)
         {
@@ -351,7 +352,7 @@ bool Texture3D::SetData(SharedPtr<Image> image, bool useAlpha)
             levelHeight = image->GetHeight();
             levelDepth = image->GetDepth();
         }
-        
+
         switch (components)
         {
         case 1:
@@ -361,18 +362,20 @@ bool Texture3D::SetData(SharedPtr<Image> image, bool useAlpha)
         case 4:
             format = Graphics::GetRGBAFormat();
             break;
+
+        default: break;
         }
-        
+
         // 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)
             requestedLevels_ = 0;
         SetSize(levelWidth, levelHeight, levelDepth, format);
-        
+
         for (unsigned i = 0; i < levels_; ++i)
         {
             SetData(i, 0, 0, 0, levelWidth, levelHeight, levelDepth, levelData);
             memoryUse += levelWidth * levelHeight * levelDepth * components;
-            
+
             if (i < levels_ - 1)
             {
                 image = image->GetNextLevel();
@@ -391,13 +394,13 @@ bool Texture3D::SetData(SharedPtr<Image> image, bool useAlpha)
         unsigned levels = image->GetNumCompressedLevels();
         unsigned format = graphics_->GetFormat(image->GetCompressedFormat());
         bool needDecompress = false;
-        
+
         if (!format)
         {
             format = Graphics::GetRGBAFormat();
             needDecompress = true;
         }
-        
+
         unsigned mipsToSkip = mipsToSkip_[quality];
         if (mipsToSkip >= levels)
             mipsToSkip = levels - 1;
@@ -406,10 +409,10 @@ bool Texture3D::SetData(SharedPtr<Image> image, bool useAlpha)
         width /= (1 << mipsToSkip);
         height /= (1 << mipsToSkip);
         depth /= (1 << mipsToSkip);
-        
-        SetNumLevels(Max((int)(levels - mipsToSkip), 1));
+
+        SetNumLevels((unsigned)Max((int)(levels - mipsToSkip), 1));
         SetSize(width, height, depth, format);
-        
+
         for (unsigned i = 0; i < levels_ && i < levels - mipsToSkip; ++i)
         {
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
@@ -428,7 +431,7 @@ bool Texture3D::SetData(SharedPtr<Image> image, bool useAlpha)
             }
         }
     }
-    
+
     SetMemoryUse(memoryUse);
     return true;
 }
@@ -440,28 +443,28 @@ bool Texture3D::GetData(unsigned level, void* dest) const
         LOGERROR("No texture created, can not get data");
         return false;
     }
-    
+
     if (!dest)
     {
         LOGERROR("Null destination for getting data");
         return false;
     }
-    
+
     if (level >= levels_)
     {
         LOGERROR("Illegal mip level for getting data");
         return false;
     }
-    
+
     int levelWidth = GetLevelWidth(level);
     int levelHeight = GetLevelHeight(level);
     int levelDepth = GetLevelDepth(level);
-    
+
     D3D11_TEXTURE3D_DESC textureDesc;
     memset(&textureDesc, 0, sizeof textureDesc);
-    textureDesc.Width = levelWidth;
-    textureDesc.Height = levelHeight;
-    textureDesc.Depth = levelDepth;
+    textureDesc.Width = (UINT)levelWidth;
+    textureDesc.Height = (UINT)levelHeight;
+    textureDesc.Depth = (UINT)levelDepth;
     textureDesc.MipLevels = 1;
     textureDesc.Format = (DXGI_FORMAT)format_;
     textureDesc.Usage = D3D11_USAGE_STAGING;
@@ -478,18 +481,18 @@ bool Texture3D::GetData(unsigned level, void* dest) const
     unsigned srcSubResource = D3D11CalcSubresource(level, 0, levels_);
     D3D11_BOX srcBox;
     srcBox.left = 0;
-    srcBox.right = levelWidth;
+    srcBox.right = (UINT)levelWidth;
     srcBox.top = 0;
-    srcBox.bottom = levelHeight;
+    srcBox.bottom = (UINT)levelHeight;
     srcBox.front = 0;
-    srcBox.back = levelDepth;
+    srcBox.back = (UINT)levelDepth;
     graphics_->GetImpl()->GetDeviceContext()->CopySubresourceRegion(stagingTexture, 0, 0, 0, 0, (ID3D11Resource*)object_,
         srcSubResource, &srcBox);
 
     D3D11_MAPPED_SUBRESOURCE mappedData;
     mappedData.pData = 0;
     unsigned rowSize = GetRowDataSize(levelWidth);
-    unsigned numRows = IsCompressed() ? (levelHeight + 3) >> 2 : levelHeight;
+    unsigned numRows = (unsigned)(IsCompressed() ? (levelHeight + 3) >> 2 : levelHeight);
 
     graphics_->GetImpl()->GetDeviceContext()->Map((ID3D11Resource*)stagingTexture, 0, D3D11_MAP_READ, 0, &mappedData);
     if (mappedData.pData)
@@ -498,8 +501,8 @@ bool Texture3D::GetData(unsigned level, void* dest) const
         {
             for (unsigned row = 0; row < numRows; ++row)
             {
-                memcpy((unsigned char*)dest + (page * numRows + row) * rowSize, (unsigned char*)mappedData.pData + page *
-                    mappedData.DepthPitch + row * mappedData.RowPitch, rowSize);
+                memcpy((unsigned char*)dest + (page * numRows + row) * rowSize,
+                    (unsigned char*)mappedData.pData + page * mappedData.DepthPitch + row * mappedData.RowPitch, rowSize);
             }
         }
         graphics_->GetImpl()->GetDeviceContext()->Unmap((ID3D11Resource*)stagingTexture, 0);
@@ -517,17 +520,17 @@ bool Texture3D::GetData(unsigned level, void* dest) const
 bool Texture3D::Create()
 {
     Release();
-    
+
     if (!graphics_ || !width_ || !height_ || !depth_)
         return false;
-    
+
     levels_ = CheckMaxLevels(width_, height_, depth_, requestedLevels_);
 
     D3D11_TEXTURE3D_DESC textureDesc;
     memset(&textureDesc, 0, sizeof textureDesc);
-    textureDesc.Width = width_;
-    textureDesc.Height = height_;
-    textureDesc.Depth = depth_;
+    textureDesc.Width = (UINT)width_;
+    textureDesc.Height = (UINT)height_;
+    textureDesc.Depth = (UINT)depth_;
     textureDesc.MipLevels = levels_;
     textureDesc.Format = (DXGI_FORMAT)(sRGB_ ? GetSRGBFormat(format_) : format_);
     textureDesc.Usage = usage_ == TEXTURE_DYNAMIC ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT;
@@ -545,7 +548,7 @@ bool Texture3D::Create()
     memset(&resourceViewDesc, 0, sizeof resourceViewDesc);
     resourceViewDesc.Format = (DXGI_FORMAT)GetSRVFormat(textureDesc.Format);
     resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
-    resourceViewDesc.Texture3D.MipLevels = (unsigned)levels_;
+    resourceViewDesc.Texture3D.MipLevels = (UINT)levels_;
 
     graphics_->GetImpl()->GetDevice()->CreateShaderResourceView((ID3D11Resource*)object_, &resourceViewDesc,
         (ID3D11ShaderResourceView**)&shaderResourceView_);

+ 8 - 7
Source/Urho3D/Graphics/Direct3D11/D3D11Texture3D.h

@@ -22,8 +22,8 @@
 
 #pragma once
 
-#include "../../Graphics/RenderSurface.h"
 #include "../../Container/Ptr.h"
+#include "../../Graphics/RenderSurface.h"
 #include "../../Graphics/Texture.h"
 
 namespace Urho3D
@@ -35,7 +35,7 @@ class Image;
 class URHO3D_API Texture3D : public Texture
 {
     OBJECT(Texture3D);
-    
+
 public:
     /// Construct.
     Texture3D(Context* context);
@@ -43,32 +43,33 @@ public:
     virtual ~Texture3D();
     /// Register object factory.
     static void RegisterObject(Context* context);
-    
+
     /// Load resource from stream. May be called from a worker thread. Return true if successful.
     virtual bool BeginLoad(Deserializer& source);
     /// Finish resource loading. Always called from the main thread. Return true if successful.
     virtual bool EndLoad();
     /// Release texture.
     virtual void Release();
-    
+
     /// Set size, format and usage. Zero size will follow application window size. Return true if successful.
     bool SetSize(int width, int height, int depth, unsigned format, TextureUsage usage = TEXTURE_STATIC);
     /// Set data either partially or fully on a mip level. Return true if successful.
     bool SetData(unsigned level, int x, int y, int z, int width, int height, int depth, const void* data);
     /// Set data from an image. Return true if successful. Optionally make a single channel image alpha-only.
     bool SetData(SharedPtr<Image> image, bool useAlpha = false);
-    
+
     /// Get data from a mip level. The destination buffer must be big enough. Return true if successful.
     bool GetData(unsigned level, void* dest) const;
+
     /// Return render surface.
     RenderSurface* GetRenderSurface() const { return renderSurface_; }
-    
+
 private:
     /// Create texture.
     bool Create();
     /// Handle render surface update event.
     void HandleRenderSurfaceUpdate(StringHash eventType, VariantMap& eventData);
-    
+
     /// Render surface.
     SharedPtr<RenderSurface> renderSurface_;
     /// Image file acquired during BeginLoad.

+ 76 - 72
Source/Urho3D/Graphics/Direct3D11/D3D11TextureCube.cpp

@@ -23,15 +23,15 @@
 #include "../../Precompiled.h"
 
 #include "../../Core/Context.h"
-#include "../../IO/FileSystem.h"
+#include "../../Core/Profiler.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsEvents.h"
 #include "../../Graphics/GraphicsImpl.h"
-#include "../../IO/Log.h"
-#include "../../Core/Profiler.h"
 #include "../../Graphics/Renderer.h"
-#include "../../Resource/ResourceCache.h"
 #include "../../Graphics/TextureCube.h"
+#include "../../IO/FileSystem.h"
+#include "../../IO/Log.h"
+#include "../../Resource/ResourceCache.h"
 #include "../../Resource/XMLFile.h"
 
 #include "../../DebugNew.h"
@@ -54,7 +54,8 @@ static const char* cubeMapLayoutNames[] = {
 
 static SharedPtr<Image> GetTileImage(Image* src, int tileX, int tileY, int tileWidth, int tileHeight)
 {
-    return SharedPtr<Image>(src->GetSubimage(IntRect(tileX * tileWidth, tileY * tileHeight, (tileX + 1) * tileWidth, (tileY + 1) * tileHeight)));
+    return SharedPtr<Image>(
+        src->GetSubimage(IntRect(tileX * tileWidth, tileY * tileHeight, (tileX + 1) * tileWidth, (tileY + 1) * tileHeight)));
 }
 
 TextureCube::TextureCube(Context* context) :
@@ -65,7 +66,7 @@ TextureCube::TextureCube(Context* context) :
     addressMode_[COORD_U] = ADDRESS_CLAMP;
     addressMode_[COORD_V] = ADDRESS_CLAMP;
     addressMode_[COORD_W] = ADDRESS_CLAMP;
-    
+
     for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
         faceMemoryUse_[i] = 0;
 }
@@ -83,23 +84,23 @@ void TextureCube::RegisterObject(Context* context)
 bool TextureCube::BeginLoad(Deserializer& source)
 {
     ResourceCache* cache = GetSubsystem<ResourceCache>();
-    
+
     // In headless mode, do not actually load the texture, just return success
     if (!graphics_)
         return true;
-    
+
     cache->ResetDependencies(this);
 
     String texPath, texName, texExt;
     SplitPath(GetName(), texPath, texName, texExt);
-    
+
     loadParameters_ = (new XMLFile(context_));
     if (!loadParameters_->Load(source))
     {
         loadParameters_.Reset();
         return false;
     }
-    
+
     loadImages_.Clear();
 
     XMLElement textureElem = loadParameters_->GetRoot();
@@ -111,15 +112,16 @@ bool TextureCube::BeginLoad(Deserializer& source)
         // If path is empty, add the XML file path
         if (GetPath(name).Empty())
             name = texPath + name;
-        
-        CubeMapLayout layout = (CubeMapLayout)GetStringListIndex(imageElem.GetAttribute("layout").CString(), cubeMapLayoutNames, CML_HORIZONTAL);
+
+        CubeMapLayout layout =
+            (CubeMapLayout)GetStringListIndex(imageElem.GetAttribute("layout").CString(), cubeMapLayoutNames, CML_HORIZONTAL);
         SharedPtr<Image> image = cache->GetTempResource<Image>(name);
         if (!image)
             return false;
-        
+
         int faceWidth, faceHeight;
         loadImages_.Resize(MAX_CUBEMAP_FACES);
-        
+
         switch (layout)
         {
         case CML_HORIZONTAL:
@@ -132,14 +134,14 @@ bool TextureCube::BeginLoad(Deserializer& source)
             loadImages_[FACE_POSITIVE_Y] = GetTileImage(image, 4, 0, faceWidth, faceHeight);
             loadImages_[FACE_NEGATIVE_Y] = GetTileImage(image, 5, 0, faceWidth, faceHeight);
             break;
-            
+
         case CML_HORIZONTALNVIDIA:
             faceWidth = image->GetWidth() / MAX_CUBEMAP_FACES;
             faceHeight = image->GetHeight();
             for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
                 loadImages_[i] = GetTileImage(image, i, 0, faceWidth, faceHeight);
             break;
-            
+
         case CML_HORIZONTALCROSS:
             faceWidth = image->GetWidth() / 4;
             faceHeight = image->GetHeight() / 3;
@@ -150,7 +152,7 @@ bool TextureCube::BeginLoad(Deserializer& source)
             loadImages_[FACE_NEGATIVE_Z] = GetTileImage(image, 3, 1, faceWidth, faceHeight);
             loadImages_[FACE_NEGATIVE_Y] = GetTileImage(image, 1, 2, faceWidth, faceHeight);
             break;
-            
+
         case CML_VERTICALCROSS:
             faceWidth = image->GetWidth() / 3;
             faceHeight = image->GetHeight() / 4;
@@ -166,7 +168,7 @@ bool TextureCube::BeginLoad(Deserializer& source)
                 loadImages_[FACE_NEGATIVE_Z]->FlipHorizontal();
             }
             break;
-            
+
         case CML_BLENDER:
             faceWidth = image->GetWidth() / 3;
             faceHeight = image->GetHeight() / 2;
@@ -186,14 +188,14 @@ bool TextureCube::BeginLoad(Deserializer& source)
         while (faceElem)
         {
             String name = faceElem.GetAttribute("name");
-            
+
             // If path is empty, add the XML file path
             if (GetPath(name).Empty())
                 name = texPath + name;
-            
+
             loadImages_.Push(cache->GetTempResource<Image>(name));
             cache->StoreResourceDependency(this, name);
-            
+
             faceElem = faceElem.GetNext("face");
         }
     }
@@ -216,18 +218,18 @@ bool TextureCube::EndLoad()
     // In headless mode, do not actually load the texture, just return success
     if (!graphics_)
         return true;
-    
+
     // If over the texture budget, see if materials can be freed to allow textures to be freed
     CheckTextureBudget(GetTypeStatic());
 
     SetParameters(loadParameters_);
-    
+
     for (unsigned i = 0; i < loadImages_.Size() && i < MAX_CUBEMAP_FACES; ++i)
         SetData((CubeMapFace)i, loadImages_[i]);
-    
+
     loadImages_.Clear();
     loadParameters_.Reset();
-    
+
     return true;
 }
 
@@ -237,19 +239,19 @@ void TextureCube::Release()
     {
         if (!graphics_)
             return;
-        
+
         for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
         {
             if (graphics_->GetTexture(i) == this)
                 graphics_->SetTexture(i, 0);
         }
-        
+
         for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
         {
             if (renderSurfaces_[i])
                 renderSurfaces_[i]->Release();
         }
-        
+
         ((ID3D11Resource*)object_)->Release();
         object_ = 0;
 
@@ -279,59 +281,59 @@ bool TextureCube::SetSize(int size, unsigned format, TextureUsage usage)
         LOGERROR("Depth-stencil usage not supported for cube maps");
         return false;
     }
-    
+
     // Delete the old rendersurfaces if any
     for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
     {
         renderSurfaces_[i].Reset();
         faceMemoryUse_[i] = 0;
     }
-    
+
     usage_ = usage;
     if (usage_ == TEXTURE_RENDERTARGET)
     {
         for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
             renderSurfaces_[i] = new RenderSurface(this);
-        
+
         // Nearest filtering and mipmaps disabled by default
         filterMode_ = FILTER_NEAREST;
         requestedLevels_ = 1;
     }
-    
+
     if (usage_ == TEXTURE_RENDERTARGET)
         SubscribeToEvent(E_RENDERSURFACEUPDATE, HANDLER(TextureCube, HandleRenderSurfaceUpdate));
     else
         UnsubscribeFromEvent(E_RENDERSURFACEUPDATE);
-    
+
     width_ = size;
     height_ = size;
     format_ = format;
-    
+
     return Create();
 }
 
 bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int width, int height, const void* data)
 {
     PROFILE(SetTextureData);
-    
+
     if (!object_)
     {
         LOGERROR("No texture created, can not set data");
         return false;
     }
-    
+
     if (!data)
     {
         LOGERROR("Null source for setting data");
         return false;
     }
-    
+
     if (level >= levels_)
     {
         LOGERROR("Illegal mip level for setting data");
         return false;
     }
-    
+
     int levelWidth = GetLevelWidth(level);
     int levelHeight = GetLevelHeight(level);
     if (x < 0 || x + width > levelWidth || y < 0 || y + height > levelHeight || width <= 0 || height <= 0)
@@ -384,10 +386,10 @@ bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int wi
     else
     {
         D3D11_BOX destBox;
-        destBox.left = x;
-        destBox.right = x + width;
-        destBox.top = y;
-        destBox.bottom = y + height;
+        destBox.left = (UINT)x;
+        destBox.right = (UINT)(x + width);
+        destBox.top = (UINT)y;
+        destBox.bottom = (UINT)(y + height);
         destBox.front = 0;
         destBox.back = 1;
 
@@ -403,7 +405,7 @@ bool TextureCube::SetData(CubeMapFace face, Deserializer& source)
     SharedPtr<Image> image(new Image(context_));
     if (!image->Load(source))
         return false;
-    
+
     return SetData(face, image);
 }
 
@@ -414,14 +416,14 @@ bool TextureCube::SetData(CubeMapFace face, SharedPtr<Image> image, bool useAlph
         LOGERROR("Null image, can not load texture");
         return false;
     }
-    
+
     unsigned memoryUse = 0;
-    
+
     int quality = QUALITY_HIGH;
     Renderer* renderer = GetSubsystem<Renderer>();
     if (renderer)
         quality = renderer->GetTextureQuality();
-    
+
     if (!image->IsCompressed())
     {
         // Convert unsuitable formats to RGBA
@@ -438,7 +440,7 @@ bool TextureCube::SetData(CubeMapFace face, SharedPtr<Image> image, bool useAlph
         int levelWidth = image->GetWidth();
         int levelHeight = image->GetHeight();
         unsigned format = 0;
-        
+
         if (levelWidth != levelHeight)
         {
             LOGERROR("Cube texture width not equal to height");
@@ -453,7 +455,7 @@ bool TextureCube::SetData(CubeMapFace face, SharedPtr<Image> image, bool useAlph
             levelWidth = image->GetWidth();
             levelHeight = image->GetHeight();
         }
-        
+
         switch (components)
         {
         case 1:
@@ -463,8 +465,10 @@ bool TextureCube::SetData(CubeMapFace face, SharedPtr<Image> image, bool useAlph
         case 4:
             format = Graphics::GetRGBAFormat();
             break;
+
+        default: break;
         }
-        
+
         // Create the texture when face 0 is being loaded, check that rest of the faces are same size & format
         if (!face)
         {
@@ -486,12 +490,12 @@ bool TextureCube::SetData(CubeMapFace face, SharedPtr<Image> image, bool useAlph
                 return false;
             }
         }
-        
+
         for (unsigned i = 0; i < levels_; ++i)
         {
             SetData(face, i, 0, 0, levelWidth, levelHeight, levelData);
             memoryUse += levelWidth * levelHeight * components;
-            
+
             if (i < levels_ - 1)
             {
                 image = image->GetNextLevel();
@@ -508,19 +512,19 @@ bool TextureCube::SetData(CubeMapFace face, SharedPtr<Image> image, bool useAlph
         unsigned levels = image->GetNumCompressedLevels();
         unsigned format = graphics_->GetFormat(image->GetCompressedFormat());
         bool needDecompress = false;
-        
+
         if (width != height)
         {
             LOGERROR("Cube texture width not equal to height");
             return false;
         }
-        
+
         if (!format)
         {
             format = Graphics::GetRGBAFormat();
             needDecompress = true;
         }
-        
+
         unsigned mipsToSkip = mipsToSkip_[quality];
         if (mipsToSkip >= levels)
             mipsToSkip = levels - 1;
@@ -528,11 +532,11 @@ bool TextureCube::SetData(CubeMapFace face, SharedPtr<Image> image, bool useAlph
             --mipsToSkip;
         width /= (1 << mipsToSkip);
         height /= (1 << mipsToSkip);
-        
+
         // Create the texture when face 0 is being loaded, assume rest of the faces are same size & format
         if (!face)
         {
-            SetNumLevels(Max((int)(levels - mipsToSkip), 1));
+            SetNumLevels((unsigned)Max((int)(levels - mipsToSkip), 1));
             SetSize(width, format);
         }
         else
@@ -548,7 +552,7 @@ bool TextureCube::SetData(CubeMapFace face, SharedPtr<Image> image, bool useAlph
                 return false;
             }
         }
-        
+
         for (unsigned i = 0; i < levels_ && i < levels - mipsToSkip; ++i)
         {
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
@@ -567,13 +571,13 @@ bool TextureCube::SetData(CubeMapFace face, SharedPtr<Image> image, bool useAlph
             }
         }
     }
-    
+
     faceMemoryUse_[face] = memoryUse;
     unsigned totalMemoryUse = sizeof(TextureCube);
     for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
         totalMemoryUse += faceMemoryUse_[i];
     SetMemoryUse(totalMemoryUse);
-    
+
     return true;
 }
 
@@ -584,26 +588,26 @@ bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
         LOGERROR("No texture created, can not get data");
         return false;
     }
-    
+
     if (!dest)
     {
         LOGERROR("Null destination for getting data");
         return false;
     }
-    
+
     if (level >= levels_)
     {
         LOGERROR("Illegal mip level for getting data");
         return false;
     }
-    
+
     int levelWidth = GetLevelWidth(level);
     int levelHeight = GetLevelHeight(level);
 
     D3D11_TEXTURE2D_DESC textureDesc;
     memset(&textureDesc, 0, sizeof textureDesc);
-    textureDesc.Width = levelWidth;
-    textureDesc.Height = levelHeight;
+    textureDesc.Width = (UINT)levelWidth;
+    textureDesc.Height = (UINT)levelHeight;
     textureDesc.MipLevels = 1;
     textureDesc.ArraySize = 1;
     textureDesc.Format = (DXGI_FORMAT)format_;
@@ -623,9 +627,9 @@ bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
     unsigned srcSubResource = D3D11CalcSubresource(level, face, levels_);
     D3D11_BOX srcBox;
     srcBox.left = 0;
-    srcBox.right = levelWidth;
+    srcBox.right = (UINT)levelWidth;
     srcBox.top = 0;
-    srcBox.bottom = levelHeight;
+    srcBox.bottom = (UINT)levelHeight;
     srcBox.front = 0;
     srcBox.back = 1;
     graphics_->GetImpl()->GetDeviceContext()->CopySubresourceRegion(stagingTexture, 0, 0, 0, 0, (ID3D11Resource*)object_,
@@ -634,7 +638,7 @@ bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
     D3D11_MAPPED_SUBRESOURCE mappedData;
     mappedData.pData = 0;
     unsigned rowSize = GetRowDataSize(levelWidth);
-    unsigned numRows = IsCompressed() ? (levelHeight + 3) >> 2 : levelHeight;
+    unsigned numRows = (unsigned)(IsCompressed() ? (levelHeight + 3) >> 2 : levelHeight);
 
     graphics_->GetImpl()->GetDeviceContext()->Map((ID3D11Resource*)stagingTexture, 0, D3D11_MAP_READ, 0, &mappedData);
     if (mappedData.pData)
@@ -656,16 +660,16 @@ bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
 bool TextureCube::Create()
 {
     Release();
-    
+
     if (!graphics_ || !width_ || !height_)
         return false;
-    
+
     levels_ = CheckMaxLevels(width_, height_, requestedLevels_);
 
     D3D11_TEXTURE2D_DESC textureDesc;
     memset(&textureDesc, 0, sizeof textureDesc);
-    textureDesc.Width = width_;
-    textureDesc.Height = height_;
+    textureDesc.Width = (UINT)width_;
+    textureDesc.Height = (UINT)height_;
     textureDesc.MipLevels = levels_;
     textureDesc.ArraySize = MAX_CUBEMAP_FACES;
     textureDesc.Format = (DXGI_FORMAT)(sRGB_ ? GetSRGBFormat(format_) : format_);
@@ -691,7 +695,7 @@ bool TextureCube::Create()
     memset(&resourceViewDesc, 0, sizeof resourceViewDesc);
     resourceViewDesc.Format = (DXGI_FORMAT)GetSRVFormat(textureDesc.Format);
     resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
-    resourceViewDesc.Texture2D.MipLevels = (unsigned)levels_;
+    resourceViewDesc.Texture2D.MipLevels = (UINT)levels_;
 
     graphics_->GetImpl()->GetDevice()->CreateShaderResourceView((ID3D11Resource*)object_, &resourceViewDesc,
         (ID3D11ShaderResourceView**)&shaderResourceView_);

+ 8 - 7
Source/Urho3D/Graphics/Direct3D11/D3D11TextureCube.h

@@ -22,8 +22,8 @@
 
 #pragma once
 
-#include "../../Graphics/RenderSurface.h"
 #include "../../Container/Ptr.h"
+#include "../../Graphics/RenderSurface.h"
 #include "../../Graphics/Texture.h"
 
 namespace Urho3D
@@ -36,7 +36,7 @@ class Image;
 class URHO3D_API TextureCube : public Texture
 {
     OBJECT(TextureCube);
-    
+
 public:
     /// Construct.
     TextureCube(Context* context);
@@ -44,14 +44,14 @@ public:
     virtual ~TextureCube();
     /// Register object factory.
     static void RegisterObject(Context* context);
-    
+
     /// Load resource from stream. May be called from a worker thread. Return true if successful.
     virtual bool BeginLoad(Deserializer& source);
     /// Finish resource loading. Always called from the main thread. Return true if successful.
     virtual bool EndLoad();
     /// Release texture.
     virtual void Release();
-    
+
     /// Set size, format and usage. Return true if successful.
     bool SetSize(int size, unsigned format, TextureUsage usage = TEXTURE_STATIC);
     /// Set data either partially or fully on a face's mip level. Return true if successful.
@@ -60,18 +60,19 @@ public:
     bool SetData(CubeMapFace face, Deserializer& source);
     /// Set data of one face from an image. Return true if successful. Optionally make a single channel image alpha-only.
     bool SetData(CubeMapFace face, SharedPtr<Image> image, bool useAlpha = false);
-    
+
     /// Get data from a face's mip level. The destination buffer must be big enough. Return true if successful.
     bool GetData(CubeMapFace face, unsigned level, void* dest) const;
+
     /// Return render surface for one face.
     RenderSurface* GetRenderSurface(CubeMapFace face) const { return renderSurfaces_[face]; }
-    
+
 private:
     /// Create texture.
     bool Create();
     /// Handle render surface update event.
     void HandleRenderSurfaceUpdate(StringHash eventType, VariantMap& eventData);
-    
+
     /// Render surfaces.
     SharedPtr<RenderSurface> renderSurfaces_[MAX_CUBEMAP_FACES];
     /// Memory use per face.

+ 43 - 41
Source/Urho3D/Graphics/Direct3D11/D3D11VertexBuffer.cpp

@@ -24,8 +24,8 @@
 
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsImpl.h"
-#include "../../IO/Log.h"
 #include "../../Graphics/VertexBuffer.h"
+#include "../../IO/Log.h"
 
 #include "../../DebugNew.h"
 
@@ -113,7 +113,7 @@ VertexBuffer::VertexBuffer(Context* context) :
     shadowed_(false)
 {
     UpdateOffsets();
-    
+
     // Force shadowing mode if graphics subsystem does not exist
     if (!graphics_)
         shadowed_ = true;
@@ -127,18 +127,18 @@ VertexBuffer::~VertexBuffer()
 void VertexBuffer::Release()
 {
     Unlock();
-    
+
     if (object_)
     {
         if (!graphics_)
             return;
-        
+
         for (unsigned i = 0; i < MAX_VERTEX_STREAMS; ++i)
         {
             if (graphics_->GetVertexBuffer(i) == this)
                 graphics_->SetVertexBuffer(0);
         }
-        
+
         ((ID3D11Buffer*)object_)->Release();
         object_ = 0;
     }
@@ -149,14 +149,14 @@ void VertexBuffer::SetShadowed(bool enable)
     // If no graphics subsystem, can not disable shadowing
     if (!graphics_)
         enable = true;
-    
+
     if (enable != shadowed_)
     {
         if (enable && vertexSize_ && vertexCount_)
             shadowData_ = new unsigned char[vertexCount_ * vertexSize_];
         else
             shadowData_.Reset();
-        
+
         shadowed_ = enable;
     }
 }
@@ -164,18 +164,18 @@ void VertexBuffer::SetShadowed(bool enable)
 bool VertexBuffer::SetSize(unsigned vertexCount, unsigned elementMask, bool dynamic)
 {
     Unlock();
-    
+
     dynamic_ = dynamic;
     vertexCount_ = vertexCount;
     elementMask_ = elementMask;
-    
+
     UpdateOffsets();
-    
+
     if (shadowed_ && vertexCount_ && vertexSize_)
         shadowData_ = new unsigned char[vertexCount_ * vertexSize_];
     else
         shadowData_.Reset();
-    
+
     return Create();
 }
 
@@ -186,16 +186,16 @@ bool VertexBuffer::SetData(const void* data)
         LOGERROR("Null pointer for vertex buffer data");
         return false;
     }
-    
+
     if (!vertexSize_)
     {
         LOGERROR("Vertex elements not defined, can not set vertex buffer data");
         return false;
     }
-    
+
     if (shadowData_ && data != shadowData_.Get())
         memcpy(shadowData_.Get(), data, vertexCount_ * vertexSize_);
-    
+
     if (object_)
     {
         if (dynamic_)
@@ -222,7 +222,7 @@ bool VertexBuffer::SetData(const void* data)
             graphics_->GetImpl()->GetDeviceContext()->UpdateSubresource((ID3D11Buffer*)object_, 0, &destBox, data, 0, 0);
         }
     }
-    
+
     return true;
 }
 
@@ -230,31 +230,31 @@ bool VertexBuffer::SetDataRange(const void* data, unsigned start, unsigned count
 {
     if (start == 0 && count == vertexCount_)
         return SetData(data);
-    
+
     if (!data)
     {
         LOGERROR("Null pointer for vertex buffer data");
         return false;
     }
-    
+
     if (!vertexSize_)
     {
         LOGERROR("Vertex elements not defined, can not set vertex buffer data");
         return false;
     }
-    
+
     if (start + count > vertexCount_)
     {
         LOGERROR("Illegal range for setting new vertex buffer data");
         return false;
     }
-    
+
     if (!count)
         return true;
-    
+
     if (shadowData_ && shadowData_.Get() + start * vertexSize_ != data)
         memcpy(shadowData_.Get() + start * vertexSize_, data, count * vertexSize_);
-    
+
     if (object_)
     {
         if (dynamic_)
@@ -292,25 +292,25 @@ void* VertexBuffer::Lock(unsigned start, unsigned count, bool discard)
         LOGERROR("Vertex buffer already locked");
         return 0;
     }
-    
+
     if (!vertexSize_)
     {
         LOGERROR("Vertex elements not defined, can not lock vertex buffer");
         return 0;
     }
-    
+
     if (start + count > vertexCount_)
     {
         LOGERROR("Illegal range for locking vertex buffer");
         return 0;
     }
-    
+
     if (!count)
         return 0;
-    
+
     lockStart_ = start;
     lockCount_ = count;
-    
+
     // Because shadow data must be kept in sync, can only lock hardware buffer if not shadowed
     if (object_ && !shadowData_ && dynamic_)
         return MapBuffer(start, count, discard);
@@ -336,12 +336,12 @@ void VertexBuffer::Unlock()
     case LOCK_HARDWARE:
         UnmapBuffer();
         break;
-        
+
     case LOCK_SHADOW:
         SetDataRange(shadowData_.Get() + lockStart_ * vertexSize_, lockStart_, lockCount_);
         lockState_ = LOCK_NONE;
         break;
-        
+
     case LOCK_SCRATCH:
         SetDataRange(lockScratchData_, lockStart_, lockCount_);
         if (graphics_)
@@ -349,6 +349,8 @@ void VertexBuffer::Unlock()
         lockScratchData_ = 0;
         lockState_ = LOCK_NONE;
         break;
+
+    default: break;
     }
 }
 
@@ -376,49 +378,49 @@ unsigned long long VertexBuffer::GetBufferHash(unsigned streamIndex, unsigned us
         maskHash = ((unsigned long long)elementMask_) * 0x100000000ULL;
     else
         maskHash = ((unsigned long long)useMask) * 0x100000000ULL;
-    
+
     bufferHash |= maskHash;
     bufferHash <<= streamIndex * MAX_VERTEX_ELEMENTS;
-    
+
     return bufferHash;
 }
 
 unsigned VertexBuffer::GetVertexSize(unsigned elementMask)
 {
     unsigned vertexSize = 0;
-    
+
     for (unsigned i = 0; i < MAX_VERTEX_ELEMENTS; ++i)
     {
         if (elementMask & (1 << i))
             vertexSize += elementSize[i];
     }
-    
+
     return vertexSize;
 }
 
 unsigned VertexBuffer::GetElementOffset(unsigned elementMask, VertexElement element)
 {
     unsigned offset = 0;
-    
+
     for (unsigned i = 0; i < MAX_VERTEX_ELEMENTS; ++i)
     {
         if (i == element)
             break;
-        
+
         if (elementMask & (1 << i))
             offset += elementSize[i];
     }
-    
+
     return offset;
 }
 
 bool VertexBuffer::Create()
 {
     Release();
-    
+
     if (!vertexCount_ || !elementMask_)
         return true;
-    
+
     if (graphics_)
     {
         D3D11_BUFFER_DESC bufferDesc;
@@ -426,7 +428,7 @@ bool VertexBuffer::Create()
         bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
         bufferDesc.CPUAccessFlags = dynamic_ ? D3D11_CPU_ACCESS_WRITE : 0;
         bufferDesc.Usage = dynamic_ ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT;
-        bufferDesc.ByteWidth = (unsigned)(vertexCount_ * vertexSize_);
+        bufferDesc.ByteWidth = (UINT)(vertexCount_ * vertexSize_);
 
         graphics_->GetImpl()->GetDevice()->CreateBuffer(&bufferDesc, 0, (ID3D11Buffer**)&object_);
 
@@ -436,7 +438,7 @@ bool VertexBuffer::Create()
             return false;
         }
     }
-    
+
     return true;
 }
 
@@ -451,7 +453,7 @@ bool VertexBuffer::UpdateToGPU()
 void* VertexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
 {
     void* hwData = 0;
-    
+
     if (object_)
     {
         D3D11_MAPPED_SUBRESOURCE mappedData;
@@ -465,7 +467,7 @@ void* VertexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
         else
             lockState_ = LOCK_HARDWARE;
     }
-    
+
     return hwData;
 }
 

+ 18 - 9
Source/Urho3D/Graphics/Direct3D11/D3D11VertexBuffer.h

@@ -22,9 +22,9 @@
 
 #pragma once
 
+#include "../../Container/ArrayPtr.h"
 #include "../../Graphics/GPUObject.h"
 #include "../../Graphics/GraphicsDefs.h"
-#include "../../Container/ArrayPtr.h"
 
 namespace Urho3D
 {
@@ -33,16 +33,16 @@ namespace Urho3D
 class URHO3D_API VertexBuffer : public Object, public GPUObject
 {
     OBJECT(VertexBuffer);
-    
+
 public:
     /// Construct.
     VertexBuffer(Context* context);
     /// Destruct.
     virtual ~VertexBuffer();
-    
+
     /// Release buffer.
     virtual void Release();
-    
+
     /// Enable shadowing in CPU memory. Shadowing is forced on if the graphics subsystem does not exist.
     void SetShadowed(bool enable);
     /// Set size and vertex elements and dynamic mode. Previous data will be lost.
@@ -55,25 +55,34 @@ public:
     void* Lock(unsigned start, unsigned count, bool discard = false);
     /// Unlock the buffer and apply changes to the GPU buffer.
     void Unlock();
-    
+
     /// Return whether CPU memory shadowing is enabled.
     bool IsShadowed() const { return shadowed_; }
+
     /// Return whether is dynamic.
     bool IsDynamic() const { return dynamic_; }
+
     /// Return whether is currently locked.
     bool IsLocked() const { return lockState_ != LOCK_NONE; }
+
     /// Return number of vertices.
-    unsigned GetVertexCount() const {return vertexCount_; }
+    unsigned GetVertexCount() const { return vertexCount_; }
+
     /// Return vertex size.
     unsigned GetVertexSize() const { return vertexSize_; }
+
     /// Return bitmask of vertex elements.
     unsigned GetElementMask() const { return elementMask_; }
+
     /// Return offset of a specified element within a vertex.
     unsigned GetElementOffset(VertexElement element) const { return elementOffset_[element]; }
+
     /// Return buffer hash for building vertex declarations.
     unsigned long long GetBufferHash(unsigned streamIndex, unsigned useMask);
+
     /// Return CPU memory shadow data.
     unsigned char* GetShadowData() const { return shadowData_.Get(); }
+
     /// Return shared array pointer to the CPU memory shadow data.
     SharedArrayPtr<unsigned char> GetShadowDataShared() const { return shadowData_; }
 
@@ -81,7 +90,7 @@ public:
     static unsigned GetVertexSize(unsigned elementMask);
     /// Return element offset from an element mask.
     static unsigned GetElementOffset(unsigned elementMask, VertexElement element);
-    
+
     /// Vertex element sizes.
     static const unsigned elementSize[];
     /// Vertex element semantic names.
@@ -102,7 +111,7 @@ private:
     void* MapBuffer(unsigned start, unsigned count, bool discard);
     /// Unmap the GPU buffer.
     void UnmapBuffer();
-    
+
     /// Shadow data.
     SharedArrayPtr<unsigned char> shadowData_;
     /// Number of vertices.
@@ -111,7 +120,7 @@ private:
     unsigned vertexSize_;
     /// Vertex element bitmask.
     unsigned elementMask_;
-   /// Vertex element offsets.
+    /// Vertex element offsets.
     unsigned elementOffset_[MAX_VERTEX_ELEMENTS];
     /// Buffer locking state.
     LockState lockState_;

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

@@ -24,7 +24,6 @@
 
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsImpl.h"
-#include "../../Graphics/ShaderVariation.h"
 #include "../../Graphics/VertexBuffer.h"
 #include "../../Graphics/VertexDeclaration.h"
 #include "../../IO/Log.h"
@@ -34,7 +33,8 @@
 namespace Urho3D
 {
 
-VertexDeclaration::VertexDeclaration(Graphics* graphics, ShaderVariation* vertexShader, VertexBuffer** vertexBuffers, unsigned* elementMasks) :
+VertexDeclaration::VertexDeclaration(Graphics* graphics, ShaderVariation* vertexShader, VertexBuffer** vertexBuffers,
+    unsigned* elementMasks) :
     inputLayout_(0)
 {
     PODVector<D3D11_INPUT_ELEMENT_DESC> elementDescs;
@@ -53,7 +53,7 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, ShaderVariation* vertex
                     newDesc.SemanticName = VertexBuffer::elementSemantics[j];
                     newDesc.SemanticIndex = VertexBuffer::elementSemanticIndices[j];
                     newDesc.Format = (DXGI_FORMAT)VertexBuffer::elementFormats[j];
-                    newDesc.InputSlot = (unsigned)i;
+                    newDesc.InputSlot = (UINT)i;
                     newDesc.AlignedByteOffset = vertexBuffers[i]->GetElementOffset((VertexElement)j);
                     newDesc.InputSlotClass = (j >= ELEMENT_INSTANCEMATRIX1 && j <= ELEMENT_INSTANCEMATRIX3) ?
                         D3D11_INPUT_PER_INSTANCE_DATA : D3D11_INPUT_PER_VERTEX_DATA;
@@ -71,7 +71,7 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, ShaderVariation* vertex
     ID3D11InputLayout* d3dInputLayout = 0;
     const PODVector<unsigned char>& byteCode = vertexShader->GetByteCode();
 
-    graphics->GetImpl()->GetDevice()->CreateInputLayout(&elementDescs[0], (unsigned)elementDescs.Size(), &byteCode[0],
+    graphics->GetImpl()->GetDevice()->CreateInputLayout(&elementDescs[0], (UINT)elementDescs.Size(), &byteCode[0],
         byteCode.Size(), &d3dInputLayout);
     if (d3dInputLayout)
         inputLayout_ = d3dInputLayout;

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

@@ -22,9 +22,9 @@
 
 #pragma once
 
-#include "../../Graphics/GraphicsDefs.h"
 #include "../../Container/RefCounted.h"
 #include "../../Container/Vector.h"
+#include "../../Graphics/GraphicsDefs.h"
 
 namespace Urho3D
 {
@@ -41,10 +41,10 @@ public:
     VertexDeclaration(Graphics* graphics, ShaderVariation* vertexShader, VertexBuffer** buffers, unsigned* elementMasks);
     /// Destruct.
     ~VertexDeclaration();
-    
+
     /// Return input layout object corresponding to the declaration.
     void* GetInputLayout() const { return inputLayout_; }
-    
+
 private:
     /// Input layout object.
     void* inputLayout_;

+ 0 - 1
Source/Urho3D/Graphics/Direct3D9/D3D9GPUObject.cpp

@@ -23,7 +23,6 @@
 #include "../../Precompiled.h"
 
 #include "../../Graphics/Graphics.h"
-#include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/GPUObject.h"
 
 #include "../../DebugNew.h"

+ 12 - 7
Source/Urho3D/Graphics/Direct3D9/D3D9GPUObject.h

@@ -37,26 +37,31 @@ public:
     GPUObject(Graphics* graphics);
     /// Destruct. Remove from the graphics subsystem.
     virtual ~GPUObject();
-    
+
     /// Release default pool resources.
-    virtual void OnDeviceLost() {}
+    virtual void OnDeviceLost() { }
+
     /// Recreate default pool resources.
-    virtual void OnDeviceReset() {}
+    virtual void OnDeviceReset() { }
+
     /// Unconditionally release the GPU resource.
-    virtual void Release() {}
-    
+    virtual void Release() { }
+
     /// Clear the data lost flag.
     void ClearDataLost();
-    
+
     /// Return the graphics subsystem.
     Graphics* GetGraphics() const;
+
     /// Return Direct3D object.
     void* GetGPUObject() const { return object_; }
+
     /// Return whether data is lost due to device loss.
     bool IsDataLost() const { return dataLost_; }
+
     /// Return whether has pending data assigned while device was lost.
     bool HasPendingData() const { return dataPending_; }
-    
+
 protected:
     /// Graphics subsystem.
     WeakPtr<Graphics> graphics_;

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


+ 83 - 15
Source/Urho3D/Graphics/Direct3D9/D3D9Graphics.h

@@ -23,14 +23,14 @@
 #pragma once
 
 #include "../../Container/ArrayPtr.h"
-#include "../../Math/Color.h"
 #include "../../Container/HashSet.h"
-#include "../../Resource/Image.h"
 #include "../../Core/Mutex.h"
 #include "../../Core/Object.h"
+#include "../../Graphics/GraphicsDefs.h"
+#include "../../Math/Color.h"
 #include "../../Math/Plane.h"
 #include "../../Math/Rect.h"
-#include "../../Graphics/GraphicsDefs.h"
+#include "../../Resource/Image.h"
 
 namespace Urho3D
 {
@@ -65,7 +65,7 @@ struct ScratchBuffer
         reserved_(false)
     {
     }
-    
+
     /// Buffer data.
     SharedArrayPtr<unsigned char> data_;
     /// Data size.
@@ -78,13 +78,13 @@ struct ScratchBuffer
 class URHO3D_API Graphics : public Object
 {
     OBJECT(Graphics);
-    
+
 public:
     /// Construct.
     Graphics(Context* context);
     /// Destruct. Release the Direct3D9 device and close the window.
     virtual ~Graphics();
-    
+
     /// Set external window handle. Only effective before setting the initial screen mode.
     void SetExternalWindow(void* window);
     /// Set window title.
@@ -96,7 +96,8 @@ public:
     /// Set window position. Sets initial position if window is not created yet.
     void SetWindowPosition(int x, int y);
     /// Set screen mode. Return true if successful.
-    bool SetMode(int width, int height, bool fullscreen, bool borderless, bool resizable, bool vsync, bool tripleBuffer, int multiSample);
+    bool SetMode
+        (int width, int height, bool fullscreen, bool borderless, bool resizable, bool vsync, bool tripleBuffer, int multiSample);
     /// Set screen resolution only. Return true if successful.
     bool SetMode(int width, int height);
     /// Set whether the main window uses sRGB conversion on write.
@@ -124,13 +125,16 @@ public:
     /// Draw indexed geometry.
     void Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount);
     /// Draw indexed, instanced geometry. An instancing vertex buffer must be set.
-    void DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount, unsigned instanceCount);
+    void DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount,
+        unsigned instanceCount);
     /// Set vertex buffer.
     void SetVertexBuffer(VertexBuffer* buffer);
     /// Set multiple vertex buffers.
-    bool SetVertexBuffers(const PODVector<VertexBuffer*>& buffers, const PODVector<unsigned>& elementMasks, unsigned instanceOffset = 0);
+    bool SetVertexBuffers
+        (const PODVector<VertexBuffer*>& buffers, const PODVector<unsigned>& elementMasks, unsigned instanceOffset = 0);
     /// Set multiple vertex buffers.
-    bool SetVertexBuffers(const Vector<SharedPtr<VertexBuffer> >& buffers, const PODVector<unsigned>& elementMasks, unsigned instanceOffset = 0);
+    bool SetVertexBuffers
+        (const Vector<SharedPtr<VertexBuffer> >& buffers, const PODVector<unsigned>& elementMasks, unsigned instanceOffset = 0);
     /// Set index buffer.
     void SetIndexBuffer(IndexBuffer* buffer);
     /// Set shaders.
@@ -210,76 +214,109 @@ public:
     /// Set scissor test.
     void SetScissorTest(bool enable, const IntRect& rect);
     /// Set stencil test.
-    void SetStencilTest(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);
+    void SetStencilTest
+        (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);
     /// Set a custom clipping plane. The plane is specified in world space, but is dependent on the view and projection matrices.
-    void SetClipPlane(bool enable, const Plane& clipPlane = Plane::UP, const Matrix3x4& view = Matrix3x4::IDENTITY, const Matrix4& projection = Matrix4::IDENTITY);
+    void SetClipPlane(bool enable, const Plane& clipPlane = Plane::UP, const Matrix3x4& view = Matrix3x4::IDENTITY,
+        const Matrix4& projection = Matrix4::IDENTITY);
     /// Begin dumping shader variation names to an XML file for precaching.
     void BeginDumpShaders(const String& fileName);
     /// End dumping shader variations names.
     void EndDumpShaders();
     /// Precache shader variations from an XML file generated with BeginDumpShaders().
     void PrecacheShaders(Deserializer& source);
-    
+
     /// Return whether rendering initialized.
     bool IsInitialized() const;
+
     /// Return graphics implementation, which holds the actual API-specific resources.
     GraphicsImpl* GetImpl() const { return impl_; }
+
     /// Return OS-specific external window handle. Null if not in use.
     void* GetExternalWindow() const { return externalWindow_; }
+
     /// Return window title.
     const String& GetWindowTitle() const { return windowTitle_; }
+
     /// Return graphics API name.
     const String& GetApiName() const { return apiName_; }
+
     /// Return window position.
     IntVector2 GetWindowPosition() const;
+
     /// Return window width.
     int GetWidth() const { return width_; }
+
     /// Return window height.
     int GetHeight() const { return height_; }
+
     /// Return multisample mode (1 = no multisampling.)
     int GetMultiSample() const { return multiSample_; }
+
     /// Return whether window is fullscreen.
     bool GetFullscreen() const { return fullscreen_; }
+
     /// Return whether window is resizable.
     bool GetResizable() const { return resizable_; }
+
     /// Return whether window is borderless.
     bool GetBorderless() const { return borderless_; }
+
     /// Return whether vertical sync is on.
     bool GetVSync() const { return vsync_; }
+
     /// Return whether triple buffering is enabled.
     bool GetTripleBuffer() const { return tripleBuffer_; }
+
     /// Return whether the main window is using sRGB conversion on write.
     bool GetSRGB() const { return sRGB_; }
+
     /// Return whether the GPU command buffer is flushed each frame.
     bool GetFlushGPU() const { return flushGPU_; }
+
     /// Return allowed screen orientations.
     const String& GetOrientations() const { return orientations_; }
+
     /// Return whether Direct3D device is lost, and can not yet render. This happens during fullscreen resolution switching.
     bool IsDeviceLost() const { return deviceLost_; }
+
     /// Return number of primitives drawn this frame.
     unsigned GetNumPrimitives() const { return numPrimitives_; }
+
     /// Return number of batches drawn this frame.
     unsigned GetNumBatches() const { return numBatches_; }
+
     /// Return dummy color texture format for shadow maps. Is "NULL" (consume no video memory) if supported.
     unsigned GetDummyColorFormat() const { return dummyColorFormat_; }
+
     /// Return shadow map depth texture format, or 0 if not supported.
     unsigned GetShadowMapFormat() const { return shadowMapFormat_; }
+
     /// Return 24-bit shadow map depth texture format, or 0 if not supported.
     unsigned GetHiresShadowMapFormat() const { return hiresShadowMapFormat_; }
+
     /// Return whether hardware instancing is supported..
     bool GetInstancingSupport() const { return instancingSupport_; }
+
     /// Return whether light pre-pass rendering is supported.
     bool GetLightPrepassSupport() const { return lightPrepassSupport_; }
+
     /// Return whether deferred rendering is supported.
     bool GetDeferredSupport() const { return deferredSupport_; }
+
     /// Return whether shadow map depth compare is done in hardware.
     bool GetHardwareShadowSupport() const { return hardwareShadowSupport_; }
+
     /// Return whether a readable hardware depth format is available.
     bool GetReadableDepthSupport() const { return GetReadableDepthFormat() != 0; }
+
     /// Return whether sRGB conversion on texture sampling is supported.
     bool GetSRGBSupport() const { return sRGBSupport_; }
+
     /// Return whether sRGB conversion on rendertarget writing is supported.
     bool GetSRGBWriteSupport() const { return sRGBWriteSupport_; }
+
     /// Return supported fullscreen resolutions.
     PODVector<IntVector2> GetResolutions() const;
     /// Return supported multisampling levels.
@@ -294,69 +331,98 @@ public:
     ShaderVariation* GetShader(ShaderType type, const char* name, const char* defines) const;
     /// Return current vertex buffer by index.
     VertexBuffer* GetVertexBuffer(unsigned index) const;
+
     /// Return current index buffer.
     IndexBuffer* GetIndexBuffer() const { return indexBuffer_; }
+
     /// Return current vertex shader.
     ShaderVariation* GetVertexShader() const { return vertexShader_; }
+
     /// Return current pixel shader.
     ShaderVariation* GetPixelShader() const { return pixelShader_; }
+
     /// Return texture unit index by name.
     TextureUnit GetTextureUnit(const String& name);
     /// Return texture unit name by index.
     const String& GetTextureUnitName(TextureUnit unit);
     /// Return current texture by texture unit index.
     Texture* GetTexture(unsigned index) const;
+
     /// Return default texture filtering mode.
     TextureFilterMode GetDefaultTextureFilterMode() const { return defaultTextureFilterMode_; }
+
     /// Return current rendertarget by index.
     RenderSurface* GetRenderTarget(unsigned index) const;
+
     /// Return current depth-stencil surface.
     RenderSurface* GetDepthStencil() const { return depthStencil_; }
+
     /// Return the viewport coordinates.
     IntRect GetViewport() const { return viewport_; }
+
     /// Return texture anisotropy.
     unsigned GetTextureAnisotropy() const { return textureAnisotropy_; }
+
     /// Return blending mode.
     BlendMode GetBlendMode() const { return blendMode_; }
+
     /// Return whether color write is enabled.
     bool GetColorWrite() const { return colorWrite_; }
+
     /// Return hardware culling mode.
     CullMode GetCullMode() const { return cullMode_; }
+
     /// Return depth constant bias.
     float GetDepthConstantBias() const { return constantDepthBias_; }
+
     /// Return depth slope scaled bias.
     float GetDepthSlopeScaledBias() const { return slopeScaledDepthBias_; }
+
     /// Return depth compare mode.
     CompareMode GetDepthTest() const { return depthTestMode_; }
+
     /// Return whether depth write is enabled.
     bool GetDepthWrite() const { return depthWrite_; }
+
     /// Return polygon fill mode.
     FillMode GetFillMode() const { return fillMode_; }
+
     /// Return whether stencil test is enabled.
     bool GetStencilTest() const { return stencilTest_; }
+
     /// Return whether scissor test is enabled.
     bool GetScissorTest() const { return scissorTest_; }
+
     /// Return scissor rectangle coordinates.
     const IntRect& GetScissorRect() const { return scissorRect_; }
+
     /// Return stencil compare mode.
     CompareMode GetStencilTestMode() const { return stencilTestMode_; }
+
     /// Return stencil operation to do if stencil test passes.
     StencilOp GetStencilPass() const { return stencilPass_; }
+
     /// Return stencil operation to do if stencil test fails.
     StencilOp GetStencilFail() const { return stencilFail_; }
+
     /// Return stencil operation to do if depth compare fails.
     StencilOp GetStencilZFail() const { return stencilZFail_; }
+
     /// Return stencil reference value.
     unsigned GetStencilRef() const { return stencilRef_; }
+
     /// Return stencil compare bitmask.
     unsigned GetStencilCompareMask() const { return stencilCompareMask_; }
+
     /// Return stencil write bitmask.
     unsigned GetStencilWriteMask() const { return stencilWriteMask_; }
+
     /// Return whether a custom clipping plane is in use.
     bool GetUseClipPlane() const { return useClipPlane_; }
+
     /// Return rendertarget width and height.
     IntVector2 GetRenderTargetDimensions() const;
-    
+
     /// Window was resized through user interaction. Called by Input subsystem.
     void WindowResized();
     /// Window was moved through user interaction. Called by Input subsystem.
@@ -412,8 +478,10 @@ public:
     static unsigned GetReadableDepthFormat();
     /// Return the API-specific texture format from a textual description, for example "rgb".
     static unsigned GetFormat(const String& formatName);
+
     /// Return UV offset required for pixel perfect rendering.
     static const Vector2& GetPixelUVOffset() { return pixelUVOffset; }
+
     /// Return maximum number of supported bones for skinning.
     static unsigned GetMaxBones() { return 64; }
 
@@ -444,7 +512,7 @@ private:
     void ResetCachedState();
     /// Initialize texture unit mappings.
     void SetTextureUnitMappings();
-    
+
     /// Mutex for accessing the GPU objects vector from several threads.
     Mutex gpuObjectMutex_;
     /// Implementation.

+ 2 - 14
Source/Urho3D/Graphics/Direct3D9/D3D9GraphicsImpl.cpp

@@ -23,7 +23,6 @@
 #include "../../Precompiled.h"
 
 #include "../../Graphics/Graphics.h"
-#include "../../Graphics/GraphicsEvents.h"
 #include "../../Graphics/GraphicsImpl.h"
 
 #include "../../DebugNew.h"
@@ -46,19 +45,8 @@ GraphicsImpl::GraphicsImpl() :
 
 bool GraphicsImpl::CheckFormatSupport(D3DFORMAT format, DWORD usage, D3DRESOURCETYPE type)
 {
-    if (!interface_)
-        return false;
-    
-    if (SUCCEEDED(interface_->CheckDeviceFormat(
-        adapter_,
-        deviceType_,
-        D3DFMT_X8R8G8B8,
-        usage,
-        type,
-        format)))
-        return true;
-    else
-        return false;
+    return interface_ ? SUCCEEDED(interface_->CheckDeviceFormat(adapter_, deviceType_, D3DFMT_X8R8G8B8, usage, type, format)) :
+        false;
 }
 
 }

+ 7 - 3
Source/Urho3D/Graphics/Direct3D9/D3D9GraphicsImpl.h

@@ -34,22 +34,26 @@ namespace Urho3D
 class URHO3D_API GraphicsImpl
 {
     friend class Graphics;
-    
+
 public:
     /// Construct.
     GraphicsImpl();
-    
+
     /// Return Direct3D device.
     IDirect3DDevice9* GetDevice() const { return device_; }
+
     /// Return device capabilities.
     const D3DCAPS9& GetDeviceCaps() const { return deviceCaps_; }
+
     /// Return window.
     SDL_Window* GetWindow() const { return window_; }
+
     /// Return adapter identifier.
     const D3DADAPTER_IDENTIFIER9& GetAdapterIdentifier() const { return adapterIdentifier_; }
+
     /// Return whether a texture format and usage is supported.
     bool CheckFormatSupport(D3DFORMAT format, DWORD usage, D3DRESOURCETYPE type);
-    
+
 private:
     /// SDL window.
     SDL_Window* window_;

+ 46 - 44
Source/Urho3D/Graphics/Direct3D9/D3D9IndexBuffer.cpp

@@ -71,22 +71,22 @@ void IndexBuffer::OnDeviceReset()
     }
     else if (dataPending_)
         dataLost_ = !UpdateToGPU();
-    
+
     dataPending_ = false;
 }
 
 void IndexBuffer::Release()
 {
     Unlock();
-    
+
     if (object_)
     {
         if (!graphics_)
             return;
-        
+
         if (graphics_->GetIndexBuffer() == this)
             graphics_->SetIndexBuffer(0);
-        
+
         ((IDirect3DIndexBuffer9*)object_)->Release();
         object_ = 0;
     }
@@ -97,14 +97,14 @@ void IndexBuffer::SetShadowed(bool enable)
     // If no graphics subsystem, can not disable shadowing
     if (!graphics_)
         enable = true;
-    
+
     if (enable != shadowed_)
     {
         if (enable && indexCount_ && indexSize_)
             shadowData_ = new unsigned char[indexCount_ * indexSize_];
         else
             shadowData_.Reset();
-        
+
         shadowed_ = enable;
     }
 }
@@ -112,7 +112,7 @@ void IndexBuffer::SetShadowed(bool enable)
 bool IndexBuffer::SetSize(unsigned indexCount, bool largeIndices, bool dynamic)
 {
     Unlock();
-    
+
     if (dynamic)
     {
         pool_ = D3DPOOL_DEFAULT;
@@ -123,15 +123,15 @@ bool IndexBuffer::SetSize(unsigned indexCount, bool largeIndices, bool dynamic)
         pool_ = D3DPOOL_MANAGED;
         usage_ = 0;
     }
-    
+
     indexCount_ = indexCount;
-    indexSize_ = largeIndices ? sizeof(unsigned) : sizeof(unsigned short);
-    
+    indexSize_ = (unsigned)(largeIndices ? sizeof(unsigned) : sizeof(unsigned short));
+
     if (shadowed_ && indexCount_ && indexSize_)
         shadowData_ = new unsigned char[indexCount_ * indexSize_];
     else
         shadowData_.Reset();
-    
+
     return Create();
 }
 
@@ -142,16 +142,16 @@ bool IndexBuffer::SetData(const void* data)
         LOGERROR("Null pointer for index buffer data");
         return false;
     }
-    
+
     if (!indexSize_)
     {
         LOGERROR("Index size not defined, can not set index buffer data");
         return false;
     }
-    
+
     if (shadowData_ && data != shadowData_.Get())
         memcpy(shadowData_.Get(), data, indexCount_ * indexSize_);
-    
+
     if (object_)
     {
         if (graphics_->IsDeviceLost())
@@ -160,7 +160,7 @@ bool IndexBuffer::SetData(const void* data)
             dataPending_ = true;
             return true;
         }
-        
+
         void* hwData = MapBuffer(0, indexCount_, true);
         if (hwData)
         {
@@ -170,7 +170,7 @@ bool IndexBuffer::SetData(const void* data)
         else
             return false;
     }
-    
+
     dataLost_ = false;
     return true;
 }
@@ -179,31 +179,31 @@ bool IndexBuffer::SetDataRange(const void* data, unsigned start, unsigned count,
 {
     if (start == 0 && count == indexCount_)
         return SetData(data);
-    
+
     if (!data)
     {
         LOGERROR("Null pointer for index buffer data");
         return false;
     }
-    
+
     if (!indexSize_)
     {
         LOGERROR("Index size not defined, can not set index buffer data");
         return false;
     }
-    
+
     if (start + count > indexCount_)
     {
         LOGERROR("Illegal range for setting new index buffer data");
         return false;
     }
-    
+
     if (!count)
         return true;
-    
+
     if (shadowData_ && shadowData_.Get() + start * indexSize_ != data)
         memcpy(shadowData_.Get() + start * indexSize_, data, count * indexSize_);
-    
+
     if (object_)
     {
         if (graphics_->IsDeviceLost())
@@ -212,7 +212,7 @@ bool IndexBuffer::SetDataRange(const void* data, unsigned start, unsigned count,
             dataPending_ = true;
             return true;
         }
-        
+
         void* hwData = MapBuffer(start, count, discard);
         if (hwData)
         {
@@ -233,25 +233,25 @@ void* IndexBuffer::Lock(unsigned start, unsigned count, bool discard)
         LOGERROR("Index buffer already locked");
         return 0;
     }
-    
+
     if (!indexSize_)
     {
         LOGERROR("Index size not defined, can not lock index buffer");
         return 0;
     }
-    
+
     if (start + count > indexCount_)
     {
         LOGERROR("Illegal range for locking index buffer");
         return 0;
     }
-    
+
     if (!count)
         return 0;
-    
+
     lockStart_ = start;
     lockCount_ = count;
-    
+
     // Because shadow data must be kept in sync, can only lock hardware buffer if not shadowed
     if (object_ && !shadowData_ && !graphics_->IsDeviceLost())
         return MapBuffer(start, count, discard);
@@ -277,12 +277,12 @@ void IndexBuffer::Unlock()
     case LOCK_HARDWARE:
         UnmapBuffer();
         break;
-        
+
     case LOCK_SHADOW:
         SetDataRange(shadowData_.Get() + lockStart_ * indexSize_, lockStart_, lockCount_);
         lockState_ = LOCK_NONE;
         break;
-        
+
     case LOCK_SCRATCH:
         SetDataRange(lockScratchData_, lockStart_, lockCount_);
         if (graphics_)
@@ -290,6 +290,8 @@ void IndexBuffer::Unlock()
         lockScratchData_ = 0;
         lockState_ = LOCK_NONE;
         break;
+
+    default: break;
     }
 }
 
@@ -305,20 +307,20 @@ bool IndexBuffer::GetUsedVertexRange(unsigned start, unsigned count, unsigned& m
         LOGERROR("Used vertex range can only be queried from an index buffer with shadow data");
         return false;
     }
-    
+
     if (start + count > indexCount_)
     {
         LOGERROR("Illegal index range for querying used vertices");
         return false;
     }
-    
+
     minVertex = M_MAX_UNSIGNED;
     unsigned maxVertex = 0;
-    
+
     if (indexSize_ == sizeof(unsigned))
     {
         unsigned* indices = ((unsigned*)shadowData_.Get()) + start;
-        
+
         for (unsigned i = 0; i < count; ++i)
         {
             if (indices[i] < minVertex)
@@ -330,7 +332,7 @@ bool IndexBuffer::GetUsedVertexRange(unsigned start, unsigned count, unsigned& m
     else
     {
         unsigned short* indices = ((unsigned short*)shadowData_.Get()) + start;
-        
+
         for (unsigned i = 0; i < count; ++i)
         {
             if (indices[i] < minVertex)
@@ -339,7 +341,7 @@ bool IndexBuffer::GetUsedVertexRange(unsigned start, unsigned count, unsigned& m
                 maxVertex = indices[i];
         }
     }
-    
+
     vertexCount = maxVertex - minVertex + 1;
     return true;
 }
@@ -347,10 +349,10 @@ bool IndexBuffer::GetUsedVertexRange(unsigned start, unsigned count, unsigned& m
 bool IndexBuffer::Create()
 {
     Release();
-    
+
     if (!indexCount_)
         return true;
-    
+
     if (graphics_)
     {
         if (graphics_->IsDeviceLost())
@@ -358,7 +360,7 @@ bool IndexBuffer::Create()
             LOGWARNING("Index buffer creation while device is lost");
             return true;
         }
-        
+
         IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
         if (!device || FAILED(device->CreateIndexBuffer(
             indexCount_ * indexSize_,
@@ -372,7 +374,7 @@ bool IndexBuffer::Create()
             return false;
         }
     }
-    
+
     return true;
 }
 
@@ -387,20 +389,20 @@ bool IndexBuffer::UpdateToGPU()
 void* IndexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
 {
     void* hwData = 0;
-    
+
     if (object_)
     {
         DWORD flags = 0;
-        
+
         if (discard && usage_ & D3DUSAGE_DYNAMIC)
             flags = D3DLOCK_DISCARD;
-        
+
         if (FAILED(((IDirect3DIndexBuffer9*)object_)->Lock(start * indexSize_, count * indexSize_, &hwData, flags)))
             LOGERROR("Could not lock index buffer");
         else
             lockState_ = LOCK_HARDWARE;
     }
-    
+
     return hwData;
 }
 

+ 15 - 8
Source/Urho3D/Graphics/Direct3D9/D3D9IndexBuffer.h

@@ -22,10 +22,10 @@
 
 #pragma once
 
-#include "../../Graphics/GPUObject.h"
 #include "../../Core/Object.h"
-#include "../../Graphics/GraphicsDefs.h"
 #include "../../Container/ArrayPtr.h"
+#include "../../Graphics/GPUObject.h"
+#include "../../Graphics/GraphicsDefs.h"
 
 namespace Urho3D
 {
@@ -34,20 +34,20 @@ namespace Urho3D
 class URHO3D_API IndexBuffer : public Object, public GPUObject
 {
     OBJECT(IndexBuffer);
-    
+
 public:
     /// Construct.
     IndexBuffer(Context* context);
     /// Destruct.
     virtual ~IndexBuffer();
-    
+
     /// Release default pool resources.
     virtual void OnDeviceLost();
     /// Recreate default pool resources.
     virtual void OnDeviceReset();
     /// Release buffer.
     virtual void Release();
-    
+
     /// Enable shadowing in CPU memory. Shadowing is forced on if the graphics subsystem does not exist.
     void SetShadowed(bool enable);
     /// Set size and vertex elements and dynamic mode. Previous data will be lost.
@@ -60,21 +60,28 @@ public:
     void* Lock(unsigned start, unsigned count, bool discard = false);
     /// Unlock the buffer and apply changes to the GPU buffer.
     void Unlock();
-    
+
     /// Return whether CPU memory shadowing is enabled.
     bool IsShadowed() const { return shadowed_; }
+
     /// Return whether is dynamic.
     bool IsDynamic() const;
+
     /// Return whether is currently locked.
     bool IsLocked() const { return lockState_ != LOCK_NONE; }
+
     /// Return number of indices.
-    unsigned GetIndexCount() const {return indexCount_; }
+    unsigned GetIndexCount() const { return indexCount_; }
+
     /// Return index size.
     unsigned GetIndexSize() const { return indexSize_; }
+
     /// Return used vertex range from index range.
     bool GetUsedVertexRange(unsigned start, unsigned count, unsigned& minVertex, unsigned& vertexCount);
+
     /// Return CPU memory shadow data.
     unsigned char* GetShadowData() const { return shadowData_.Get(); }
+
     /// Return shared array pointer to the CPU memory shadow data.
     SharedArrayPtr<unsigned char> GetShadowDataShared() const { return shadowData_; }
 
@@ -87,7 +94,7 @@ private:
     void* MapBuffer(unsigned start, unsigned count, bool discard);
     /// Unmap the GPU buffer.
     void UnmapBuffer();
-    
+
     /// Shadow data.
     SharedArrayPtr<unsigned char> shadowData_;
     /// Number of indices.

+ 7 - 9
Source/Urho3D/Graphics/Direct3D9/D3D9RenderSurface.cpp

@@ -25,10 +25,8 @@
 #include "../../Graphics/Camera.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsImpl.h"
-#include "../../IO/Log.h"
 #include "../../Graphics/Renderer.h"
 #include "../../Graphics/RenderSurface.h"
-#include "../../Scene/Scene.h"
 #include "../../Graphics/Texture.h"
 
 #include "../../DebugNew.h"
@@ -58,7 +56,7 @@ void RenderSurface::SetViewport(unsigned index, Viewport* viewport)
 {
     if (index >= viewports_.Size())
         viewports_.Resize(index + 1);
-    
+
     viewports_[index] = viewport;
 }
 
@@ -84,7 +82,7 @@ void RenderSurface::QueueUpdate()
     if (!updateQueued_)
     {
         bool hasValidView = false;
-        
+
         // Verify that there is at least 1 non-null viewport, as otherwise Renderer will not accept the surface and the update flag
         // will be left on
         for (unsigned i = 0; i < viewports_.Size(); ++i)
@@ -95,13 +93,13 @@ void RenderSurface::QueueUpdate()
                 break;
             }
         }
-        
+
         if (hasValidView)
         {
             Renderer* renderer = parentTexture_->GetSubsystem<Renderer>();
             if (renderer)
                 renderer->QueueRenderSurface(this);
-            
+
             updateQueued_ = true;
         }
     }
@@ -112,7 +110,7 @@ void RenderSurface::Release()
     Graphics* graphics = parentTexture_->GetGraphics();
     if (!graphics)
         return;
-    
+
     if (surface_)
     {
         for (unsigned i = 0; i < MAX_RENDERTARGETS; ++i)
@@ -120,10 +118,10 @@ void RenderSurface::Release()
             if (graphics->GetRenderTarget(i) == this)
                 graphics->ResetRenderTarget(i);
         }
-        
+
         if (graphics->GetDepthStencil() == this)
             graphics->ResetDepthStencil();
-        
+
         ((IDirect3DSurface9*)surface_)->Release();
         surface_ = 0;
     }

+ 12 - 5
Source/Urho3D/Graphics/Direct3D9/D3D9RenderSurface.h

@@ -35,13 +35,13 @@ class URHO3D_API RenderSurface : public RefCounted
 {
     friend class Texture2D;
     friend class TextureCube;
-    
+
 public:
     /// Construct with parent texture.
     RenderSurface(Texture* parentTexture);
     /// Destruct.
     ~RenderSurface();
-    
+
     /// Set number of viewports.
     void SetNumViewports(unsigned num);
     /// Set viewport.
@@ -56,31 +56,38 @@ public:
     void QueueUpdate();
     /// Release surface.
     void Release();
-    
+
     /// Return parent texture.
     Texture* GetParentTexture() const { return parentTexture_; }
+
     /// Return Direct3D surface.
     void* GetSurface() const { return surface_; }
+
     /// Return width.
     int GetWidth() const;
     /// Return height.
     int GetHeight() const;
     /// Return usage.
     TextureUsage GetUsage() const;
+
     /// Return number of viewports.
     unsigned GetNumViewports() const { return viewports_.Size(); }
+
     /// Return viewport by index.
     Viewport* GetViewport(unsigned index) const;
+
     /// Return viewport update mode.
     RenderSurfaceUpdateMode GetUpdateMode() const { return updateMode_; }
+
     /// Return linked color rendertarget.
     RenderSurface* GetLinkedRenderTarget() const { return linkedRenderTarget_; }
+
     /// Return linked depth-stencil surface.
     RenderSurface* GetLinkedDepthStencil() const { return linkedDepthStencil_; }
-    
+
     /// Clear update flag. Called by Renderer.
     void WasUpdated();
-    
+
 private:
     /// Parent texture.
     Texture* parentTexture_;

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

@@ -37,12 +37,12 @@ public:
     {
         const HashMap<StringHash, ShaderParameter>& vsParams = vertexShader->GetParameters();
         for (HashMap<StringHash, ShaderParameter>::ConstIterator i = vsParams.Begin(); i != vsParams.End(); ++i)
-        parameters_[i->first_] = i->second_;
+            parameters_[i->first_] = i->second_;
 
         const HashMap<StringHash, ShaderParameter>& psParams = pixelShader->GetParameters();
         for (HashMap<StringHash, ShaderParameter>::ConstIterator i = psParams.Begin(); i != psParams.End(); ++i)
             parameters_[i->first_] = i->second_;
-    
+
         // Optimize shader parameter lookup by rehashing to next power of two
         parameters_.Rehash(NextPowerOfTwo(parameters_.Size()));
     }

+ 55 - 57
Source/Urho3D/Graphics/Direct3D9/D3D9ShaderVariation.cpp

@@ -22,16 +22,15 @@
 
 #include "../../Precompiled.h"
 
-#include "../../IO/File.h"
-#include "../../IO/FileSystem.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsImpl.h"
-#include "../../IO/Log.h"
-#include "../../Resource/ResourceCache.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 <windows.h>
 #include <d3dcompiler.h>
 #include <MojoShader/mojoshader.h>
 
@@ -57,10 +56,10 @@ ShaderVariation::~ShaderVariation()
 bool ShaderVariation::Create()
 {
     Release();
-    
+
     if (!graphics_)
         return false;
-    
+
     if (!owner_)
     {
         compilerOutput_ = "Owner shader has expired";
@@ -71,10 +70,10 @@ bool ShaderVariation::Create()
     String path, name, extension;
     SplitPath(owner_->GetName(), path, name, extension);
     extension = type_ == VS ? ".vs3" : ".ps3";
-    
+
     String binaryShaderName = path + "Cache/" + name + "_" + StringHash(defines_).ToString() + extension;
     PODVector<unsigned> byteCode;
-    
+
     if (!LoadByteCode(byteCode, binaryShaderName))
     {
         // Compile shader if don't have valid bytecode
@@ -84,7 +83,7 @@ bool ShaderVariation::Create()
         if (owner_->GetTimeStamp())
             SaveByteCode(byteCode, binaryShaderName);
     }
-    
+
     // Then create shader from the bytecode
     IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
     if (type_ == VS)
@@ -101,7 +100,7 @@ bool ShaderVariation::Create()
             (IDirect3DPixelShader9**)&object_)))
             compilerOutput_ = "Could not create pixel shader";
     }
-    
+
     return object_ != 0;
 }
 
@@ -111,29 +110,29 @@ void ShaderVariation::Release()
     {
         if (!graphics_)
             return;
-        
+
         graphics_->CleanupShaderPrograms(this);
 
         if (type_ == VS)
         {
             if (graphics_->GetVertexShader() == this)
                 graphics_->SetShaders(0, 0);
-            
+
             ((IDirect3DVertexShader9*)object_)->Release();
         }
         else
         {
             if (graphics_->GetPixelShader() == this)
                 graphics_->SetShaders(0, 0);
-            
+
             ((IDirect3DPixelShader9*)object_)->Release();
         }
 
         object_ = 0;
     }
-    
+
     compilerOutput_.Clear();
-    
+
     for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
         useTextureUnit_[i] = false;
     parameters_.Clear();
@@ -159,26 +158,25 @@ bool ShaderVariation::LoadByteCode(PODVector<unsigned>& byteCode, const String&
     ResourceCache* cache = owner_->GetSubsystem<ResourceCache>();
     if (!cache->Exists(binaryShaderName))
         return false;
-    
+
     FileSystem* fileSystem = owner_->GetSubsystem<FileSystem>();
     unsigned sourceTimeStamp = owner_->GetTimeStamp();
     // If source code is loaded from a package, its timestamp will be zero. Else check that binary is not older
     // than source
-    if (sourceTimeStamp && fileSystem->GetLastModifiedTime(cache->GetResourceFileName(binaryShaderName)) <
-        sourceTimeStamp)
+    if (sourceTimeStamp && fileSystem->GetLastModifiedTime(cache->GetResourceFileName(binaryShaderName)) < sourceTimeStamp)
         return false;
-    
+
     SharedPtr<File> file = cache->GetFile(binaryShaderName);
     if (!file || file->ReadFileID() != "USHD")
     {
         LOGERROR(binaryShaderName + " is not a valid shader bytecode file");
         return false;
     }
-    
+
     /// \todo Check that shader type and model match
-    unsigned short shaderType = file->ReadUShort();
-    unsigned short shaderModel = file->ReadUShort();
-    
+    /*unsigned short shaderType = */file->ReadUShort();
+    /*unsigned short shaderModel = */file->ReadUShort();
+
     unsigned numParameters = file->ReadUInt();
     for (unsigned i = 0; i < numParameters; ++i)
     {
@@ -189,28 +187,28 @@ bool ShaderVariation::LoadByteCode(PODVector<unsigned>& byteCode, const String&
         ShaderParameter parameter(type_, name, reg, regCount);
         parameters_[StringHash(name)] = parameter;
     }
-    
+
     unsigned numTextureUnits = file->ReadUInt();
     for (unsigned i = 0; i < numTextureUnits; ++i)
     {
-        String unitName = file->ReadString();
+        /*String unitName = */file->ReadString();
         unsigned reg = file->ReadUByte();
-        
+
         if (reg < MAX_TEXTURE_UNITS)
             useTextureUnit_[reg] = true;
     }
-    
+
     unsigned byteCodeSize = file->ReadUInt();
     if (byteCodeSize)
     {
         byteCode.Resize(byteCodeSize >> 2);
         file->Read(&byteCode[0], byteCodeSize);
-        
+
         if (type_ == VS)
             LOGDEBUG("Loaded cached vertex shader " + GetFullName());
         else
             LOGDEBUG("Loaded cached pixel shader " + GetFullName());
-        
+
         return true;
     }
     else
@@ -224,12 +222,12 @@ bool ShaderVariation::Compile(PODVector<unsigned>& byteCode)
 {
     const String& sourceCode = owner_->GetSourceCode(type_);
     Vector<String> defines = defines_.Split(' ');
-    
+
     // Set the entrypoint, profile and flags according to the shader being compiled
     const char* entryPoint = 0;
     const char* profile = 0;
     unsigned flags = D3DCOMPILE_OPTIMIZATION_LEVEL3;
-    
+
     if (type_ == VS)
     {
         entryPoint = "VS";
@@ -245,11 +243,11 @@ bool ShaderVariation::Compile(PODVector<unsigned>& byteCode)
     }
 
     defines.Push("MAXBONES=" + String(Graphics::GetMaxBones()));
-    
+
     // Collect defines into macros
     Vector<String> defineValues;
     PODVector<D3D_SHADER_MACRO> macros;
-    
+
     for (unsigned i = 0; i < defines.Size(); ++i)
     {
         unsigned equalsPos = defines[i].Find('=');
@@ -269,35 +267,35 @@ bool ShaderVariation::Compile(PODVector<unsigned>& byteCode)
         macros.Push(macro);
 
         // In debug mode, check that all defines are referenced by the shader code
-        #ifdef _DEBUG
+#ifdef _DEBUG
         if (sourceCode.Find(defines[i]) == String::NPOS)
             LOGWARNING("Shader " + GetFullName() + " does not use the define " + defines[i]);
-        #endif
+#endif
     }
-    
+
     D3D_SHADER_MACRO endMacro;
     endMacro.Name = 0;
     endMacro.Definition = 0;
     macros.Push(endMacro);
-    
+
     // Compile using D3DCompile
 
     LPD3DBLOB shaderCode = 0;
     LPD3DBLOB errorMsgs = 0;
-    
+
     if (FAILED(D3DCompile(sourceCode.CString(), sourceCode.Length(), owner_->GetName().CString(), &macros.Front(), 0,
         entryPoint, profile, flags, 0, &shaderCode, &errorMsgs)))
-        compilerOutput_ = String((const char*)errorMsgs->GetBufferPointer(), errorMsgs->GetBufferSize());
+        compilerOutput_ = String((const char*)errorMsgs->GetBufferPointer(), (unsigned)errorMsgs->GetBufferSize());
     else
     {
         if (type_ == VS)
             LOGDEBUG("Compiled vertex shader " + GetFullName());
         else
             LOGDEBUG("Compiled pixel shader " + GetFullName());
-        
+
         // Inspect the produced bytecode using MojoShader, then strip and store it
         unsigned char* bufData = (unsigned char*)shaderCode->GetBufferPointer();
-        unsigned bufSize = shaderCode->GetBufferSize();
+        unsigned bufSize = (unsigned)shaderCode->GetBufferSize();
         ParseParameters(bufData, bufSize);
         CopyStrippedCode(byteCode, bufData, bufSize);
     }
@@ -306,13 +304,13 @@ bool ShaderVariation::Compile(PODVector<unsigned>& byteCode)
         shaderCode->Release();
     if (errorMsgs)
         errorMsgs->Release();
-    
+
     return !byteCode.Empty();
 }
 
 void ShaderVariation::ParseParameters(unsigned char* bufData, unsigned bufSize)
 {
-    MOJOSHADER_parseData const *parseData = MOJOSHADER_parse("bytecode", bufData, bufSize, 0, 0, 0, 0, 0, 0, 0);
+    MOJOSHADER_parseData const* parseData = MOJOSHADER_parse("bytecode", bufData, bufSize, 0, 0, 0, 0, 0, 0, 0);
 
     for (int i = 0; i < parseData->symbol_count; i++)
     {
@@ -325,7 +323,7 @@ void ShaderVariation::ParseParameters(unsigned char* bufData, unsigned bufSize)
         // Check if the parameter is a constant or a texture sampler
         bool isSampler = (name[0] == 's');
         name = name.Substring(1);
-        
+
         if (isSampler)
         {
             // Skip if it's a G-buffer sampler, which are aliases for the standard texture units
@@ -341,7 +339,7 @@ void ShaderVariation::ParseParameters(unsigned char* bufData, unsigned bufSize)
             parameters_[StringHash(name)] = newParam;
         }
     }
-    
+
     MOJOSHADER_freeParseData(parseData);
 }
 
@@ -350,13 +348,13 @@ void ShaderVariation::CopyStrippedCode(PODVector<unsigned>& byteCode, unsigned c
     unsigned const D3DSIO_COMMENT = 0xFFFE;
     unsigned* srcWords = (unsigned*)bufData;
     unsigned srcWordSize = bufSize >> 2;
-    
+
     for (unsigned i = 0; i < srcWordSize; ++i)
     {
         unsigned opcode = srcWords[i] & 0xffff;
-        unsigned paramLength = (srcWords[i] & 0x0f000000) >> 24;
+        // unsigned paramLength = (srcWords[i] & 0x0f000000) >> 24;
         unsigned commentLength = srcWords[i] >> 16;
-        
+
         // For now, skip comment only at fixed position to prevent false positives
         if (i == 1 && opcode == D3DSIO_COMMENT)
         {
@@ -375,16 +373,16 @@ void ShaderVariation::SaveByteCode(const PODVector<unsigned>& byteCode, const St
 {
     ResourceCache* cache = owner_->GetSubsystem<ResourceCache>();
     FileSystem* fileSystem = owner_->GetSubsystem<FileSystem>();
-    
+
     String path = GetPath(cache->GetResourceFileName(owner_->GetName())) + "Cache/";
     String fullName = path + GetFileNameAndExtension(binaryShaderName);
     if (!fileSystem->DirExists(path))
         fileSystem->CreateDir(path);
-    
+
     SharedPtr<File> file(new File(owner_->GetContext(), fullName, FILE_WRITE));
     if (!file->IsOpen())
         return;
-    
+
     file->WriteFileID("USHD");
     file->WriteShort((unsigned short)type_);
     file->WriteShort(3);
@@ -393,10 +391,10 @@ void ShaderVariation::SaveByteCode(const PODVector<unsigned>& byteCode, const St
     for (HashMap<StringHash, ShaderParameter>::ConstIterator i = parameters_.Begin(); i != parameters_.End(); ++i)
     {
         file->WriteString(i->second_.name_);
-        file->WriteUByte(i->second_.register_);
-        file->WriteUByte(i->second_.regCount_);
+        file->WriteUByte((unsigned char)i->second_.register_);
+        file->WriteUByte((unsigned char)i->second_.regCount_);
     }
-    
+
     unsigned usedTextureUnits = 0;
     for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
     {
@@ -409,10 +407,10 @@ void ShaderVariation::SaveByteCode(const PODVector<unsigned>& byteCode, const St
         if (useTextureUnit_[i])
         {
             file->WriteString(graphics_->GetTextureUnitName((TextureUnit)i));
-            file->WriteUByte(i);
+            file->WriteUByte((unsigned char)i);
         }
     }
-    
+
     unsigned dataSize = byteCode.Size() << 2;
     file->WriteUInt(dataSize);
     if (dataSize)

+ 17 - 9
Source/Urho3D/Graphics/Direct3D9/D3D9ShaderVariation.h

@@ -22,11 +22,11 @@
 
 #pragma once
 
-#include "../../Graphics/GPUObject.h"
-#include "../../Graphics/GraphicsDefs.h"
 #include "../../Container/HashSet.h"
 #include "../../Container/RefCounted.h"
 #include "../../Container/ArrayPtr.h"
+#include "../../Graphics/GPUObject.h"
+#include "../../Graphics/GraphicsDefs.h"
 
 namespace Urho3D
 {
@@ -43,7 +43,7 @@ struct ShaderParameter
         regCount_(0)
     {
     }
-    
+
     /// Construct with parameters.
     ShaderParameter(ShaderType type, const String& name, unsigned reg, unsigned regCount) :
         type_(type),
@@ -52,7 +52,7 @@ struct ShaderParameter
         regCount_(regCount)
     {
     }
-    
+
     /// %Shader type.
     ShaderType type_;
     /// Name of the parameter.
@@ -71,36 +71,44 @@ public:
     ShaderVariation(Shader* owner, ShaderType type);
     /// Destruct.
     virtual ~ShaderVariation();
-    
+
     /// Release the shader.
     virtual void Release();
-    
+
     /// Compile the shader. Return true if successful.
     bool Create();
     /// Set name.
     void SetName(const String& name);
     /// Set defines.
     void SetDefines(const String& defines);
-    
+
     /// Return the owner resource.
     Shader* GetOwner() const;
+
     /// Return shader type.
     ShaderType GetShaderType() const { return type_; }
+
     /// Return shader name.
     const String& GetName() const { return name_; }
+
     /// Return defines.
     const String& GetDefines() const { return defines_; }
+
     /// Return full shader name.
     String GetFullName() const { return name_ + "(" + defines_ + ")"; }
+
     /// Return compile error/warning string.
     const String& GetCompilerOutput() const { return compilerOutput_; }
+
     /// Return whether uses a parameter.
     bool HasParameter(StringHash param) const { return parameters_.Contains(param); }
+
     /// Return whether uses a texture unit (only for pixel shaders.)
     bool HasTextureUnit(TextureUnit unit) const { return useTextureUnit_[unit]; }
+
     /// Return all parameter definitions.
     const HashMap<StringHash, ShaderParameter>& GetParameters() const { return parameters_; }
-    
+
 private:
     /// Load bytecode from a file. Return true if successful.
     bool LoadByteCode(PODVector<unsigned>& byteCode, const String& binaryShaderName);
@@ -112,7 +120,7 @@ private:
     void CopyStrippedCode(PODVector<unsigned>& byteCode, unsigned char* bufData, unsigned bufSize);
     /// Save bytecode to a file.
     void SaveByteCode(const PODVector<unsigned>& byteCode, const String& binaryShaderName);
-    
+
     /// Shader this variation belongs to.
     WeakPtr<Shader> owner_;
     /// Shader type.

+ 31 - 33
Source/Urho3D/Graphics/Direct3D9/D3D9Texture.cpp

@@ -22,14 +22,12 @@
 
 #include "../../Precompiled.h"
 
-#include "../../IO/FileSystem.h"
+#include "../../Core/StringUtils.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsImpl.h"
 #include "../../Graphics/Material.h"
-#include "../../Core/Profiler.h"
+#include "../../IO/FileSystem.h"
 #include "../../Resource/ResourceCache.h"
-#include "../../Core/StringUtils.h"
-#include "../../Graphics/Texture.h"
 #include "../../Resource/XMLFile.h"
 
 #include "../../DebugNew.h"
@@ -73,7 +71,7 @@ Texture::Texture(Context* context) :
     for (int i = 0; i < MAX_COORDS; ++i)
         addressMode_[i] = ADDRESS_WRAP;
     for (int i = 0; i < MAX_TEXTURE_QUALITY_LEVELS; ++i)
-        mipsToSkip_[i] = MAX_TEXTURE_QUALITY_LEVELS - 1 - i;
+        mipsToSkip_[i] = (unsigned)(MAX_TEXTURE_QUALITY_LEVELS - 1 - i);
 }
 
 Texture::~Texture()
@@ -107,7 +105,7 @@ void Texture::SetSRGB(bool enable)
 {
     if (graphics_)
         enable &= graphics_->GetSRGBSupport();
-    
+
     sRGB_ = enable;
 }
 
@@ -120,8 +118,8 @@ void Texture::SetMipsToSkip(int quality, int mips)
 {
     if (quality >= QUALITY_LOW && quality < MAX_TEXTURE_QUALITY_LEVELS)
     {
-        mipsToSkip_[quality] = mips;
-        
+        mipsToSkip_[quality] = (unsigned)mips;
+
         // Make sure a higher quality level does not actually skip more mips
         for (int i = 1; i < MAX_TEXTURE_QUALITY_LEVELS; ++i)
         {
@@ -166,13 +164,13 @@ TextureUsage Texture::GetUsage() const
 {
     if (usage_ & D3DUSAGE_DEPTHSTENCIL)
         return TEXTURE_DEPTHSTENCIL;
-    
+
     if (usage_ & D3DUSAGE_RENDERTARGET)
         return TEXTURE_RENDERTARGET;
-    
+
     if (pool_ == D3DPOOL_DEFAULT)
         return TEXTURE_DYNAMIC;
-    
+
     return TEXTURE_STATIC;
 }
 
@@ -195,18 +193,18 @@ unsigned Texture::GetRowDataSize(int width) const
     {
     case D3DFMT_A8:
     case D3DFMT_L8:
-        return width;
-    
+        return (unsigned)width;
+
     case D3DFMT_D16:
     case D3DFMT_R5G6B5:
     case D3DFMT_A4R4G4B4:
     case D3DFMT_A8L8:
     case D3DFMT_R16F:
-        return width * 2;
+        return (unsigned)(width * 2);
 
     case D3DFMT_X8R8G8B8:
         // Note: here source and destination data size differ
-        return width * 3;
+        return (unsigned)(width * 3);
 
     case D3DFMT_A8R8G8B8:
     case D3DFMT_G16R16:
@@ -214,22 +212,22 @@ unsigned Texture::GetRowDataSize(int width) const
     case D3DFMT_G16R16F:
     case D3DFMT_D24S8:
     case D3DFMT_D32:
-        return width * 4;
-        
+        return (unsigned)(width * 4);
+
     case D3DFMT_A16B16G16R16:
     case D3DFMT_A16B16G16R16F:
-        return width * 8;
-        
+        return (unsigned)(width * 8);
+
     case D3DFMT_A32B32G32R32F:
-        return width * 16;
-        
+        return (unsigned)(width * 16);
+
     case D3DFMT_DXT1:
-        return ((width + 3) >> 2) * 8;
-        
+        return (unsigned)(((width + 3) >> 2) * 8);
+
     case D3DFMT_DXT3:
     case D3DFMT_DXT5:
-        return ((width + 3) >> 2) * 16;
-        
+        return (unsigned)(((width + 3) >> 2) * 16);
+
     default:
         return 0;
     }
@@ -247,7 +245,7 @@ void Texture::SetParameters(XMLFile* file)
 {
     if (!file)
         return;
-    
+
     XMLElement rootElem = file->GetRoot();
     SetParameters(rootElem);
 }
@@ -258,7 +256,7 @@ void Texture::SetParameters(const XMLElement& element)
     while (paramElem)
     {
         String name = paramElem.GetName();
-        
+
         if (name == "address")
         {
             String coord = paramElem.GetAttributeLower("coord");
@@ -269,19 +267,19 @@ void Texture::SetParameters(const XMLElement& element)
                 SetAddressMode(coordIndex, (TextureAddressMode)GetStringListIndex(mode.CString(), addressModeNames, ADDRESS_WRAP));
             }
         }
-        
+
         if (name == "border")
             SetBorderColor(paramElem.GetColor("color"));
-        
+
         if (name == "filter")
         {
             String mode = paramElem.GetAttributeLower("mode");
             SetFilterMode((TextureFilterMode)GetStringListIndex(mode.CString(), filterModeNames, FILTER_DEFAULT));
         }
-        
+
         if (name == "mipmap")
             SetNumLevels(paramElem.GetBool("enable") ? 0 : 1);
-        
+
         if (name == "quality")
         {
             if (paramElem.HasAttribute("low"))
@@ -296,7 +294,7 @@ void Texture::SetParameters(const XMLElement& element)
 
         if (name == "srgb")
             SetSRGB(paramElem.GetBool("enable"));
-        
+
         paramElem = paramElem.GetNext();
     }
 }
@@ -308,7 +306,7 @@ void Texture::CheckTextureBudget(StringHash type)
     unsigned textureUse = cache->GetMemoryUse(type);
     if (!textureBudget)
         return;
-    
+
     // If textures are over the budget, they likely can not be freed directly as materials still refer to them.
     // Therefore free unused materials first
     if (textureUse > textureBudget)

+ 20 - 6
Source/Urho3D/Graphics/Direct3D9/D3D9Texture.h

@@ -22,9 +22,9 @@
 
 #pragma once
 
-#include "../../Math/Color.h"
 #include "../../Graphics/GPUObject.h"
 #include "../../Graphics/GraphicsDefs.h"
+#include "../../Math/Color.h"
 #include "../../Resource/Resource.h"
 
 namespace Urho3D
@@ -43,15 +43,17 @@ public:
     Texture(Context* context);
     /// Destruct.
     virtual ~Texture();
-    
+
     /// Set number of requested mip levels. Needs to be called before setting size.
     void SetNumLevels(unsigned levels);
     /// Set filtering mode.
     void SetFilterMode(TextureFilterMode filter);
     /// Set addressing mode by texture coordinate.
     void SetAddressMode(TextureCoordinate coord, TextureAddressMode address);
+
     /// Set shadow compare mode. No-op on D3D9.
-    void SetShadowCompare(bool enable) {}
+    void SetShadowCompare(bool enable) { }
+
     /// Set border color for border addressing mode.
     void SetBorderColor(const Color& color);
     /// Set sRGB sampling and writing mode.
@@ -60,31 +62,43 @@ public:
     void SetBackupTexture(Texture* texture);
     /// Set mip levels to skip on a quality setting when loading. Ensures higher quality levels do not skip more.
     void SetMipsToSkip(int quality, int mips);
-    
+
     /// Return texture format.
     unsigned GetFormat() const { return format_; }
+
     /// Return whether the texture format is compressed.
     bool IsCompressed() const;
+
     /// Return number of mip levels.
     unsigned GetLevels() const { return levels_; }
+
     /// Return width.
     int GetWidth() const { return width_; }
+
     /// Return height.
     int GetHeight() const { return height_; }
+
     /// Return height.
     int GetDepth() const { return depth_; }
+
     /// Return filtering mode.
     TextureFilterMode GetFilterMode() const { return filterMode_; }
+
     /// Return addressing mode by texture coordinate.
     TextureAddressMode GetAddressMode(TextureCoordinate coord) const { return addressMode_[coord]; }
+
     /// Return whether shadow compare is enabled. Always false on D3D9.
     bool GetShadowCompare() const { return false; }
+
     /// Return border color.
     const Color& GetBorderColor() const { return borderColor_; }
+
     /// Return whether is using sRGB sampling and writing.
     bool GetSRGB() const { return sRGB_; }
+
     /// Return backup texture.
     Texture* GetBackupTexture() const { return backupTexture_; }
+
     /// Return mip levels to skip on a quality setting when loading.
     int GetMipsToSkip(int quality) const;
     /// Return mip level width, or 0 if level does not exist.
@@ -108,11 +122,11 @@ public:
     void SetParameters(XMLFile* xml);
     /// Set additional parameters from an XML element.
     void SetParameters(const XMLElement& element);
-    
+
 protected:
     /// Check whether texture memory budget has been exceeded. Free unused materials in that case to release the texture references.
     void CheckTextureBudget(StringHash type);
-    
+
     /// Texture format.
     unsigned format_;
     /// Memory pool.

+ 101 - 84
Source/Urho3D/Graphics/Direct3D9/D3D9Texture2D.cpp

@@ -23,15 +23,15 @@
 #include "../../Precompiled.h"
 
 #include "../../Core/Context.h"
-#include "../../IO/FileSystem.h"
+#include "../../Core/Profiler.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsEvents.h"
 #include "../../Graphics/GraphicsImpl.h"
-#include "../../IO/Log.h"
 #include "../../Graphics/Renderer.h"
-#include "../../Core/Profiler.h"
-#include "../../Resource/ResourceCache.h"
 #include "../../Graphics/Texture2D.h"
+#include "../../IO/Log.h"
+#include "../../IO/FileSystem.h"
+#include "../../Resource/ResourceCache.h"
 #include "../../Resource/XMLFile.h"
 
 #include "../../DebugNew.h"
@@ -59,7 +59,7 @@ bool Texture2D::BeginLoad(Deserializer& source)
     // In headless mode, do not actually load the texture, just return success
     if (!graphics_)
         return true;
-    
+
     // If device is lost, retry later
     if (graphics_->IsDeviceLost())
     {
@@ -67,7 +67,7 @@ bool Texture2D::BeginLoad(Deserializer& source)
         dataPending_ = true;
         return true;
     }
-    
+
     // Load the image data for EndLoad()
     loadImage_ = new Image(context_);
     if (!loadImage_->Load(source))
@@ -79,12 +79,12 @@ bool Texture2D::BeginLoad(Deserializer& source)
     // Precalculate mip levels if async loading
     if (GetAsyncLoadState() == ASYNC_LOADING)
         loadImage_->PrecalculateLevels();
-    
+
     // Load the optional parameters file
     ResourceCache* cache = GetSubsystem<ResourceCache>();
     String xmlName = ReplaceExtension(GetName(), ".xml");
     loadParameters_ = cache->GetTempResource<XMLFile>(xmlName, false);
-    
+
     return true;
 }
 
@@ -93,16 +93,16 @@ bool Texture2D::EndLoad()
     // In headless mode, do not actually load the texture, just return success
     if (!graphics_ || graphics_->IsDeviceLost())
         return true;
-    
+
     // If over the texture budget, see if materials can be freed to allow textures to be freed
     CheckTextureBudget(GetTypeStatic());
 
     SetParameters(loadParameters_);
     bool success = SetData(loadImage_);
-    
+
     loadImage_.Reset();
     loadParameters_.Reset();
-    
+
     return success;
 }
 
@@ -120,14 +120,14 @@ void Texture2D::OnDeviceReset()
         ResourceCache* cache = GetSubsystem<ResourceCache>();
         if (cache->Exists(GetName()))
             dataLost_ = !cache->ReloadResource(this);
-        
+
         if (!object_)
         {
             Create();
             dataLost_ = true;
         }
     }
-    
+
     dataPending_ = false;
 }
 
@@ -137,16 +137,16 @@ void Texture2D::Release()
     {
         if (!graphics_)
             return;
-        
+
         for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
         {
             if (graphics_->GetTexture(i) == this)
                 graphics_->SetTexture(i, 0);
         }
-        
+
         if (renderSurface_)
             renderSurface_->Release();
-        
+
         ((IDirect3DTexture9*)object_)->Release();
         object_ = 0;
     }
@@ -163,7 +163,7 @@ bool Texture2D::SetSize(int width, int height, unsigned format, TextureUsage usa
     renderSurface_.Reset();
     pool_ = D3DPOOL_MANAGED;
     usage_ = 0;
-    
+
     if (usage == TEXTURE_RENDERTARGET || usage == TEXTURE_DEPTHSTENCIL)
     {
         renderSurface_ = new RenderSurface(this);
@@ -172,7 +172,7 @@ bool Texture2D::SetSize(int width, int height, unsigned format, TextureUsage usa
         else
             usage_ |= D3DUSAGE_DEPTHSTENCIL;
         pool_ = D3DPOOL_DEFAULT;
-        
+
         // Clamp mode addressing by default, nearest filtering, and mipmaps disabled
         addressMode_[COORD_U] = ADDRESS_CLAMP;
         addressMode_[COORD_V] = ADDRESS_CLAMP;
@@ -184,7 +184,7 @@ bool Texture2D::SetSize(int width, int height, unsigned format, TextureUsage usa
         usage_ |= D3DUSAGE_DYNAMIC;
         pool_ = D3DPOOL_DEFAULT;
     }
-    
+
     if (usage == TEXTURE_RENDERTARGET)
         SubscribeToEvent(E_RENDERSURFACEUPDATE, HANDLER(Texture2D, HandleRenderSurfaceUpdate));
     else
@@ -193,45 +193,45 @@ bool Texture2D::SetSize(int width, int height, unsigned format, TextureUsage usa
     width_ = width;
     height_ = height;
     format_ = format;
-    
+
     return Create();
 }
 
 bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, const void* data)
 {
     PROFILE(SetTextureData);
-    
+
     if (!object_)
     {
         LOGERROR("No texture created, can not set data");
         return false;
     }
-    
+
     if (!data)
     {
         LOGERROR("Null source for setting data");
         return false;
     }
-    
+
     if (level >= levels_)
     {
         LOGERROR("Illegal mip level for setting data");
         return false;
     }
-    
+
     if (graphics_->IsDeviceLost())
     {
         LOGWARNING("Texture data assignment while device is lost");
         dataPending_ = true;
         return true;
     }
-    
+
     if (IsCompressed())
     {
         x &= ~3;
         y &= ~3;
     }
-    
+
     int levelWidth = GetLevelWidth(level);
     int levelHeight = GetLevelHeight(level);
     if (x < 0 || x + width > levelWidth || y < 0 || y + height > levelHeight || width <= 0 || height <= 0)
@@ -239,37 +239,37 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
         LOGERROR("Illegal dimensions for setting data");
         return false;
     }
-    
+
     D3DLOCKED_RECT d3dLockedRect;
     RECT d3dRect;
     d3dRect.left = x;
     d3dRect.top = y;
     d3dRect.right = x + width;
     d3dRect.bottom = y + height;
-    
+
     DWORD flags = 0;
     if (level == 0 && x == 0 && y == 0 && width == levelWidth && height == levelHeight && pool_ == D3DPOOL_DEFAULT)
         flags |= D3DLOCK_DISCARD;
-    
+
     if (FAILED(((IDirect3DTexture9*)object_)->LockRect(level, &d3dLockedRect, (flags & D3DLOCK_DISCARD) ? 0 : &d3dRect, flags)))
     {
         LOGERROR("Could not lock texture");
         return false;
     }
-    
+
     if (IsCompressed())
     {
         height = (height + 3) >> 2;
         y >>= 2;
     }
-    
+
     unsigned char* src = (unsigned char*)data;
     unsigned rowSize = GetRowDataSize(width);
-    
+
     // GetRowDataSize() returns CPU-side (source) data size, so need to convert for X8R8G8B8
     if (format_ == D3DFMT_X8R8G8B8)
         rowSize = rowSize / 3 * 4;
-    
+
     // Perform conversion from RGB / RGBA as necessary
     switch (format_)
     {
@@ -281,32 +281,38 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
             src += rowSize;
         }
         break;
-        
+
     case D3DFMT_X8R8G8B8:
         for (int i = 0; i < height; ++i)
         {
             unsigned char* dest = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
             for (int j = 0; j < width; ++j)
             {
-                *dest++  = src[2]; *dest++ = src[1]; *dest++ = src[0]; *dest++ = 255;
+                *dest++ = src[2];
+                *dest++ = src[1];
+                *dest++ = src[0];
+                *dest++ = 255;
                 src += 3;
-           }
+            }
         }
         break;
-        
+
     case D3DFMT_A8R8G8B8:
         for (int i = 0; i < height; ++i)
         {
             unsigned char* dest = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
             for (int j = 0; j < width; ++j)
             {
-                *dest++  = src[2]; *dest++ = src[1]; *dest++ = src[0]; *dest++ = src[3];
+                *dest++ = src[2];
+                *dest++ = src[1];
+                *dest++ = src[0];
+                *dest++ = src[3];
                 src += 4;
-           }
+            }
         }
         break;
     }
-    
+
     ((IDirect3DTexture9*)object_)->UnlockRect(level);
     return true;
 }
@@ -318,14 +324,14 @@ bool Texture2D::SetData(SharedPtr<Image> image, bool useAlpha)
         LOGERROR("Null image, can not load texture");
         return false;
     }
-    
+
     unsigned memoryUse = sizeof(Texture2D);
-    
+
     int quality = QUALITY_HIGH;
     Renderer* renderer = GetSubsystem<Renderer>();
     if (renderer)
         quality = renderer->GetTextureQuality();
-    
+
     if (!image->IsCompressed())
     {
         unsigned char* levelData = image->GetData();
@@ -333,7 +339,7 @@ bool Texture2D::SetData(SharedPtr<Image> image, bool useAlpha)
         int levelHeight = image->GetHeight();
         unsigned components = image->GetComponents();
         unsigned format = 0;
-        
+
         // Discard unnecessary mip levels
         for (unsigned i = 0; i < mipsToSkip_[quality]; ++i)
         {
@@ -342,36 +348,40 @@ bool Texture2D::SetData(SharedPtr<Image> image, bool useAlpha)
             levelWidth = image->GetWidth();
             levelHeight = image->GetHeight();
         }
-        
+
         switch (components)
         {
         case 1:
             format = useAlpha ? Graphics::GetAlphaFormat() : Graphics::GetLuminanceFormat();
             break;
-            
+
         case 2:
             format = Graphics::GetLuminanceAlphaFormat();
             break;
-            
+
         case 3:
             format = Graphics::GetRGBFormat();
             break;
-            
+
         case 4:
             format = Graphics::GetRGBAFormat();
             break;
+
+        default:
+            assert(false);  // Should never reach here
+            break;
         }
-        
+
         // 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)
             requestedLevels_ = 0;
         SetSize(levelWidth, levelHeight, format);
-        
+
         for (unsigned i = 0; i < levels_; ++i)
         {
             SetData(i, 0, 0, levelWidth, levelHeight, levelData);
             memoryUse += levelWidth * levelHeight * components;
-            
+
             if (i < levels_ - 1)
             {
                 image = image->GetNextLevel();
@@ -388,13 +398,13 @@ bool Texture2D::SetData(SharedPtr<Image> image, bool useAlpha)
         unsigned levels = image->GetNumCompressedLevels();
         unsigned format = graphics_->GetFormat(image->GetCompressedFormat());
         bool needDecompress = false;
-        
+
         if (!format)
         {
             format = Graphics::GetRGBAFormat();
             needDecompress = true;
         }
-        
+
         unsigned mipsToSkip = mipsToSkip_[quality];
         if (mipsToSkip >= levels)
             mipsToSkip = levels - 1;
@@ -402,10 +412,10 @@ bool Texture2D::SetData(SharedPtr<Image> image, bool useAlpha)
             --mipsToSkip;
         width /= (1 << mipsToSkip);
         height /= (1 << mipsToSkip);
-        
-        SetNumLevels(Max((int)(levels - mipsToSkip), 1));
+
+        SetNumLevels((unsigned)Max((int)(levels - mipsToSkip), 1));
         SetSize(width, height, format);
-        
+
         for (unsigned i = 0; i < levels_ && i < levels - mipsToSkip; ++i)
         {
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
@@ -424,7 +434,7 @@ bool Texture2D::SetData(SharedPtr<Image> image, bool useAlpha)
             }
         }
     }
-    
+
     SetMemoryUse(memoryUse);
     return true;
 }
@@ -436,35 +446,35 @@ bool Texture2D::GetData(unsigned level, void* dest) const
         LOGERROR("No texture created, can not get data");
         return false;
     }
-    
+
     if (!dest)
     {
         LOGERROR("Null destination for getting data");
         return false;
     }
-    
+
     if (level >= levels_)
     {
         LOGERROR("Illegal mip level for getting data");
         return false;
     }
-    
+
     if (graphics_->IsDeviceLost())
     {
         LOGWARNING("Getting texture data while device is lost");
         return false;
     }
-    
+
     int levelWidth = GetLevelWidth(level);
     int levelHeight = GetLevelHeight(level);
-    
+
     D3DLOCKED_RECT d3dLockedRect;
     RECT d3dRect;
     d3dRect.left = 0;
     d3dRect.top = 0;
     d3dRect.right = levelWidth;
     d3dRect.bottom = levelHeight;
-    
+
     IDirect3DSurface9* offscreenSurface = 0;
     // Need to use a offscreen surface & GetRenderTargetData() for rendertargets
     if (renderSurface_)
@@ -476,7 +486,8 @@ bool Texture2D::GetData(unsigned level, void* dest) const
         }
 
         IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
-        device->CreateOffscreenPlainSurface(width_, height_, (D3DFORMAT)format_, D3DPOOL_SYSTEMMEM, &offscreenSurface, 0);
+        device->CreateOffscreenPlainSurface((UINT)width_, (UINT)height_, (D3DFORMAT)format_,
+            D3DPOOL_SYSTEMMEM, &offscreenSurface, 0);
         if (!offscreenSurface)
         {
             LOGERROR("Could not create surface for getting rendertarget data");
@@ -502,13 +513,13 @@ bool Texture2D::GetData(unsigned level, void* dest) const
     int height = levelHeight;
     if (IsCompressed())
         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
     if (format_ == D3DFMT_X8R8G8B8)
         rowSize = rowSize / 3 * 4;
-    
+
     // Perform conversion to RGB / RGBA as necessary
     switch (format_)
     {
@@ -520,32 +531,38 @@ bool Texture2D::GetData(unsigned level, void* dest) const
             destPtr += rowSize;
         }
         break;
-    
+
     case D3DFMT_X8R8G8B8:
         for (int i = 0; i < height; ++i)
         {
             unsigned char* src = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
             for (int j = 0; j < levelWidth; ++j)
             {
-                destPtr[2] = *src++; destPtr[1] = *src++; destPtr[0] = *src++; ++src;
+                destPtr[2] = *src++;
+                destPtr[1] = *src++;
+                destPtr[0] = *src++;
+                ++src;
                 destPtr += 3;
-           }
+            }
         }
         break;
-        
+
     case D3DFMT_A8R8G8B8:
         for (int i = 0; i < height; ++i)
         {
             unsigned char* src = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
             for (int j = 0; j < levelWidth; ++j)
             {
-                destPtr[2] = *src++; destPtr[1] = *src++; destPtr[0] = *src++; destPtr[3] = *src++;
+                destPtr[2] = *src++;
+                destPtr[1] = *src++;
+                destPtr[0] = *src++;
+                destPtr[3] = *src++;
                 destPtr += 4;
-           }
+            }
         }
         break;
     }
-    
+
     if (offscreenSurface)
     {
         offscreenSurface->UnlockRect();
@@ -560,23 +577,23 @@ bool Texture2D::GetData(unsigned level, void* dest) const
 bool Texture2D::Create()
 {
     Release();
-    
+
     if (!graphics_ || !width_ || !height_)
         return false;
-    
+
     if (graphics_->IsDeviceLost())
     {
         LOGWARNING("Texture creation while device is lost");
         return true;
     }
-    
+
     IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
     // If creating a depth-stencil texture, and it is not supported, create a depth-stencil surface instead
     if (usage_ & D3DUSAGE_DEPTHSTENCIL && !graphics_->GetImpl()->CheckFormatSupport((D3DFORMAT)format_, usage_, D3DRTYPE_TEXTURE))
     {
         if (!device || FAILED(device->CreateDepthStencilSurface(
-            width_,
-            height_,
+            (UINT)width_,
+            (UINT)height_,
             (D3DFORMAT)format_,
             D3DMULTISAMPLE_NONE,
             0,
@@ -587,14 +604,14 @@ bool Texture2D::Create()
             LOGERROR("Could not create depth-stencil surface");
             return false;
         }
-        
+
         levels_ = 1;
     }
     else
     {
         if (!device || FAILED(graphics_->GetImpl()->GetDevice()->CreateTexture(
-            width_,
-            height_,
+            (UINT)width_,
+            (UINT)height_,
             requestedLevels_,
             usage_,
             (D3DFORMAT)format_,
@@ -605,13 +622,13 @@ bool Texture2D::Create()
             LOGERROR("Could not create texture");
             return false;
         }
-        
+
         levels_ = ((IDirect3DTexture9*)object_)->GetLevelCount();
-        
+
         if (usage_ & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL))
             ((IDirect3DTexture9*)object_)->GetSurfaceLevel(0, (IDirect3DSurface9**)&renderSurface_->surface_);
     }
-    
+
     return true;
 }
 

+ 8 - 7
Source/Urho3D/Graphics/Direct3D9/D3D9Texture2D.h

@@ -22,8 +22,8 @@
 
 #pragma once
 
-#include "../../Graphics/RenderSurface.h"
 #include "../../Container/Ptr.h"
+#include "../../Graphics/RenderSurface.h"
 #include "../../Graphics/Texture.h"
 
 namespace Urho3D
@@ -36,7 +36,7 @@ class XMLFile;
 class URHO3D_API Texture2D : public Texture
 {
     OBJECT(Texture2D);
-    
+
 public:
     /// Construct.
     Texture2D(Context* context);
@@ -44,7 +44,7 @@ public:
     virtual ~Texture2D();
     /// Register object factory.
     static void RegisterObject(Context* context);
-    
+
     /// Load resource from stream. May be called from a worker thread. Return true if successful.
     virtual bool BeginLoad(Deserializer& source);
     /// Finish resource loading. Always called from the main thread. Return true if successful.
@@ -55,25 +55,26 @@ public:
     virtual void OnDeviceReset();
     /// Release texture.
     virtual void Release();
-    
+
     /// Set size, format and usage. Zero size will follow application window size. Return true if successful.
     bool SetSize(int width, int height, unsigned format, TextureUsage usage = TEXTURE_STATIC);
     /// Set data either partially or fully on a mip level. Return true if successful.
     bool SetData(unsigned level, int x, int y, int width, int height, const void* data);
     /// Set data from an image. Return true if successful. Optionally make a single channel image alpha-only.
     bool SetData(SharedPtr<Image> image, bool useAlpha = false);
-    
+
     /// Get data from a mip level. The destination buffer must be big enough. Return true if successful.
     bool GetData(unsigned level, void* dest) const;
+
     /// Return render surface.
     RenderSurface* GetRenderSurface() const { return renderSurface_; }
-    
+
 private:
     /// Create texture.
     bool Create();
     /// Handle render surface update event.
     void HandleRenderSurfaceUpdate(StringHash eventType, VariantMap& eventData);
-    
+
     /// Render surface.
     SharedPtr<RenderSurface> renderSurface_;
     /// Image file acquired during BeginLoad.

+ 115 - 94
Source/Urho3D/Graphics/Direct3D9/D3D9Texture3D.cpp

@@ -23,15 +23,15 @@
 #include "../../Precompiled.h"
 
 #include "../../Core/Context.h"
-#include "../../IO/FileSystem.h"
+#include "../../Core/Profiler.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsEvents.h"
 #include "../../Graphics/GraphicsImpl.h"
-#include "../../IO/Log.h"
 #include "../../Graphics/Renderer.h"
-#include "../../Core/Profiler.h"
-#include "../../Resource/ResourceCache.h"
 #include "../../Graphics/Texture3D.h"
+#include "../../IO/FileSystem.h"
+#include "../../IO/Log.h"
+#include "../../Resource/ResourceCache.h"
 #include "../../Resource/XMLFile.h"
 
 #include "../../DebugNew.h"
@@ -61,7 +61,7 @@ bool Texture3D::BeginLoad(Deserializer& source)
     // In headless mode, do not actually load the texture, just return success
     if (!graphics_)
         return true;
-    
+
     // If device is lost, retry later
     if (graphics_->IsDeviceLost())
     {
@@ -69,10 +69,10 @@ bool Texture3D::BeginLoad(Deserializer& source)
         dataPending_ = true;
         return true;
     }
-    
+
     String texPath, texName, texExt;
     SplitPath(GetName(), texPath, texName, texExt);
-    
+
     cache->ResetDependencies(this);
 
     loadParameters_ = new XMLFile(context_);
@@ -81,7 +81,7 @@ bool Texture3D::BeginLoad(Deserializer& source)
         loadParameters_.Reset();
         return false;
     }
-    
+
     XMLElement textureElem = loadParameters_->GetRoot();
     XMLElement volumeElem = textureElem.GetChild("volume");
     XMLElement colorlutElem = textureElem.GetChild("colorlut");
@@ -89,7 +89,7 @@ bool Texture3D::BeginLoad(Deserializer& source)
     if (volumeElem)
     {
         String name = volumeElem.GetAttribute("name");
-        
+
         String volumeTexPath, volumeTexName, volumeTexExt;
         SplitPath(name, volumeTexPath, volumeTexName, volumeTexExt);
         // If path is empty, add the XML file path
@@ -106,7 +106,7 @@ bool Texture3D::BeginLoad(Deserializer& source)
     else if (colorlutElem)
     {
         String name = colorlutElem.GetAttribute("name");
-        
+
         String colorlutTexPath, colorlutTexName, colorlutTexExt;
         SplitPath(name, colorlutTexPath, colorlutTexName, colorlutTexExt);
         // If path is empty, add the XML file path
@@ -137,16 +137,16 @@ bool Texture3D::EndLoad()
     // In headless mode, do not actually load the texture, just return success
     if (!graphics_ || graphics_->IsDeviceLost())
         return true;
-    
+
     // If over the texture budget, see if materials can be freed to allow textures to be freed
     CheckTextureBudget(GetTypeStatic());
 
     SetParameters(loadParameters_);
     bool success = SetData(loadImage_);
-    
+
     loadImage_.Reset();
     loadParameters_.Reset();
-    
+
     return success;
 }
 
@@ -171,7 +171,7 @@ void Texture3D::OnDeviceReset()
             dataLost_ = true;
         }
     }
-    
+
     dataPending_ = false;
 }
 
@@ -181,16 +181,16 @@ void Texture3D::Release()
     {
         if (!graphics_)
             return;
-        
+
         for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
         {
             if (graphics_->GetTexture(i) == this)
                 graphics_->SetTexture(i, 0);
         }
-        
+
         if (renderSurface_)
             renderSurface_->Release();
-        
+
         ((IDirect3DVolumeTexture9*)object_)->Release();
         object_ = 0;
     }
@@ -207,13 +207,13 @@ bool Texture3D::SetSize(int width, int height, int depth, unsigned format, Textu
     renderSurface_.Reset();
     pool_ = D3DPOOL_MANAGED;
     usage_ = 0;
-    
+
     if (usage == TEXTURE_RENDERTARGET)
     {
         renderSurface_ = new RenderSurface(this);
         usage_ |= D3DUSAGE_RENDERTARGET;
         pool_ = D3DPOOL_DEFAULT;
-        
+
         // Clamp mode addressing by default, nearest filtering, and mipmaps disabled
         addressMode_[COORD_U] = ADDRESS_CLAMP;
         addressMode_[COORD_V] = ADDRESS_CLAMP;
@@ -225,7 +225,7 @@ bool Texture3D::SetSize(int width, int height, int depth, unsigned format, Textu
         usage_ |= D3DUSAGE_DYNAMIC;
         pool_ = D3DPOOL_DEFAULT;
     }
-    
+
     if (usage == TEXTURE_RENDERTARGET)
         SubscribeToEvent(E_RENDERSURFACEUPDATE, HANDLER(Texture3D, HandleRenderSurfaceUpdate));
     else
@@ -235,86 +235,88 @@ bool Texture3D::SetSize(int width, int height, int depth, unsigned format, Textu
     height_ = height;
     depth_ = depth;
     format_ = format;
-    
+
     return Create();
 }
 
 bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int height, int depth, const void* data)
 {
     PROFILE(SetTextureData);
-    
+
     if (!object_)
     {
         LOGERROR("No texture created, can not set data");
         return false;
     }
-    
+
     if (!data)
     {
         LOGERROR("Null source for setting data");
         return false;
     }
-    
+
     if (level >= levels_)
     {
         LOGERROR("Illegal mip level for setting data");
         return false;
     }
-    
+
     if (graphics_->IsDeviceLost())
     {
         LOGWARNING("Texture data assignment while device is lost");
         dataPending_ = true;
         return true;
     }
-    
+
     if (IsCompressed())
     {
         x &= ~3;
         y &= ~3;
     }
-    
+
     int levelWidth = GetLevelWidth(level);
     int levelHeight = GetLevelHeight(level);
     int levelDepth = GetLevelDepth(level);
-    if (x < 0 || x + width > levelWidth || y < 0 || y + height > levelHeight || z < 0 || z + depth > levelDepth || width <= 0 || height <= 0 || depth <= 0)
+    if (x < 0 || x + width > levelWidth || y < 0 || y + height > levelHeight || z < 0 || z + depth > levelDepth || width <= 0 ||
+        height <= 0 || depth <= 0)
     {
         LOGERROR("Illegal dimensions for setting data");
         return false;
     }
-    
+
     D3DLOCKED_BOX d3dLockedBox;
     D3DBOX d3dBox;
-    d3dBox.Left = x;
-    d3dBox.Top = y;
-    d3dBox.Front = z;
-    d3dBox.Right = x + width;
-    d3dBox.Bottom = y + height;
-    d3dBox.Back = z + depth;
-    
+    d3dBox.Left = (UINT)x;
+    d3dBox.Top = (UINT)y;
+    d3dBox.Front = (UINT)z;
+    d3dBox.Right = (UINT)(x + width);
+    d3dBox.Bottom = (UINT)(y + height);
+    d3dBox.Back = (UINT)(z + depth);
+
     DWORD flags = 0;
-    if (level == 0 && x == 0 && y == 0 && z == 0 && width == levelWidth && height == levelHeight && depth == levelDepth && pool_ == D3DPOOL_DEFAULT)
+    if (level == 0 && x == 0 && y == 0 && z == 0 && width == levelWidth && height == levelHeight && depth == levelDepth &&
+        pool_ == D3DPOOL_DEFAULT)
         flags |= D3DLOCK_DISCARD;
-    
+
     if (FAILED(((IDirect3DVolumeTexture9*)object_)->LockBox(level, &d3dLockedBox, (flags & D3DLOCK_DISCARD) ? 0 : &d3dBox, flags)))
     {
         LOGERROR("Could not lock texture");
         return false;
     }
-    
+
     if (IsCompressed())
     {
         height = (height + 3) >> 2;
         y >>= 2;
     }
-    
+
     unsigned char* src = (unsigned char*)data;
     unsigned rowSize = GetRowDataSize(width);
-    
+
     // GetRowDataSize() returns CPU-side (source) data size, so need to convert for X8R8G8B8
     if (format_ == D3DFMT_X8R8G8B8)
         rowSize = rowSize / 3 * 4;
-    
+
     // Perform conversion from RGB / RGBA as necessary
     switch (format_)
     {
@@ -323,44 +325,53 @@ bool Texture3D::SetData(unsigned level, int x, int y, int z, int width, int heig
         {
             for (int i = 0; i < height; ++i)
             {
-                unsigned char* dest = (unsigned char*)d3dLockedBox.pBits + (k * d3dLockedBox.SlicePitch) + i * d3dLockedBox.RowPitch;
+                unsigned char
+                    * dest = (unsigned char*)d3dLockedBox.pBits + (k * d3dLockedBox.SlicePitch) + i * d3dLockedBox.RowPitch;
                 memcpy(dest, src, rowSize);
                 src += rowSize;
             }
         }
         break;
-        
+
     case D3DFMT_X8R8G8B8:
         for (int k = 0; k < levelDepth; ++k)
         {
             for (int i = 0; i < height; ++i)
             {
-                unsigned char* dest = (unsigned char*)d3dLockedBox.pBits + (k * d3dLockedBox.SlicePitch) + i * d3dLockedBox.RowPitch;
+                unsigned char
+                    * dest = (unsigned char*)d3dLockedBox.pBits + (k * d3dLockedBox.SlicePitch) + i * d3dLockedBox.RowPitch;
                 for (int j = 0; j < width; ++j)
                 {
-                    *dest++  = src[2]; *dest++ = src[1]; *dest++ = src[0]; *dest++ = 255;
+                    *dest++ = src[2];
+                    *dest++ = src[1];
+                    *dest++ = src[0];
+                    *dest++ = 255;
                     src += 3;
                 }
             }
         }
         break;
-        
+
     case D3DFMT_A8R8G8B8:
         for (int k = 0; k < levelDepth; ++k)
         {
             for (int i = 0; i < height; ++i)
             {
-                unsigned char* dest = (unsigned char*)d3dLockedBox.pBits + (k * d3dLockedBox.SlicePitch) + i * d3dLockedBox.RowPitch;
+                unsigned char
+                    * dest = (unsigned char*)d3dLockedBox.pBits + (k * d3dLockedBox.SlicePitch) + i * d3dLockedBox.RowPitch;
                 for (int j = 0; j < width; ++j)
                 {
-                    *dest++  = src[2]; *dest++ = src[1]; *dest++ = src[0]; *dest++ = src[3];
+                    *dest++ = src[2];
+                    *dest++ = src[1];
+                    *dest++ = src[0];
+                    *dest++ = src[3];
                     src += 4;
                 }
             }
         }
         break;
     }
-    
+
     ((IDirect3DVolumeTexture9*)object_)->UnlockBox(level);
     return true;
 }
@@ -372,14 +383,14 @@ bool Texture3D::SetData(SharedPtr<Image> image, bool useAlpha)
         LOGERROR("Null image, can not load texture");
         return false;
     }
-    
+
     unsigned memoryUse = sizeof(Texture3D);
-    
+
     int quality = QUALITY_HIGH;
     Renderer* renderer = GetSubsystem<Renderer>();
     if (renderer)
         quality = renderer->GetTextureQuality();
-    
+
     if (!image->IsCompressed())
     {
         unsigned char* levelData = image->GetData();
@@ -388,7 +399,7 @@ bool Texture3D::SetData(SharedPtr<Image> image, bool useAlpha)
         int levelDepth = image->GetDepth();
         unsigned components = image->GetComponents();
         unsigned format = 0;
-        
+
         // Discard unnecessary mip levels
         for (unsigned i = 0; i < mipsToSkip_[quality]; ++i)
         {
@@ -398,36 +409,40 @@ bool Texture3D::SetData(SharedPtr<Image> image, bool useAlpha)
             levelHeight = image->GetHeight();
             levelDepth = image->GetDepth();
         }
-        
+
         switch (components)
         {
         case 1:
             format = useAlpha ? Graphics::GetAlphaFormat() : Graphics::GetLuminanceFormat();
             break;
-            
+
         case 2:
             format = Graphics::GetLuminanceAlphaFormat();
             break;
-            
+
         case 3:
             format = Graphics::GetRGBFormat();
             break;
-            
+
         case 4:
             format = Graphics::GetRGBAFormat();
             break;
+
+        default:
+            assert(false);  // Should never reach here
+            break;
         }
-        
+
         // 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)
             requestedLevels_ = 0;
         SetSize(levelWidth, levelHeight, levelDepth, format);
-        
+
         for (unsigned i = 0; i < levels_; ++i)
         {
             SetData(i, 0, 0, 0, levelWidth, levelHeight, levelDepth, levelData);
             memoryUse += levelWidth * levelHeight * levelDepth * components;
-            
+
             if (i < levels_ - 1)
             {
                 image = image->GetNextLevel();
@@ -446,13 +461,13 @@ bool Texture3D::SetData(SharedPtr<Image> image, bool useAlpha)
         unsigned levels = image->GetNumCompressedLevels();
         unsigned format = graphics_->GetFormat(image->GetCompressedFormat());
         bool needDecompress = false;
-        
+
         if (!format)
         {
             format = Graphics::GetRGBAFormat();
             needDecompress = true;
         }
-        
+
         unsigned mipsToSkip = mipsToSkip_[quality];
         if (mipsToSkip >= levels)
             mipsToSkip = levels - 1;
@@ -461,10 +476,10 @@ bool Texture3D::SetData(SharedPtr<Image> image, bool useAlpha)
         width /= (1 << mipsToSkip);
         height /= (1 << mipsToSkip);
         depth /= (1 << mipsToSkip);
-        
-        SetNumLevels(Max((int)(levels - mipsToSkip), 1));
+
+        SetNumLevels((unsigned)Max((int)(levels - mipsToSkip), 1));
         SetSize(width, height, depth, format);
-        
+
         for (unsigned i = 0; i < levels_ && i < levels - mipsToSkip; ++i)
         {
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
@@ -483,7 +498,7 @@ bool Texture3D::SetData(SharedPtr<Image> image, bool useAlpha)
             }
         }
     }
-    
+
     SetMemoryUse(memoryUse);
     return true;
 }
@@ -495,54 +510,54 @@ bool Texture3D::GetData(unsigned level, void* dest) const
         LOGERROR("No texture created, can not get data");
         return false;
     }
-    
+
     if (!dest)
     {
         LOGERROR("Null destination for getting data");
         return false;
     }
-    
+
     if (level >= levels_)
     {
         LOGERROR("Illegal mip level for getting data");
         return false;
     }
-    
+
     if (graphics_->IsDeviceLost())
     {
         LOGWARNING("Getting texture data while device is lost");
         return false;
     }
-    
+
     int levelWidth = GetLevelWidth(level);
     int levelHeight = GetLevelHeight(level);
     int levelDepth = GetLevelDepth(level);
-    
+
     D3DLOCKED_BOX d3dLockedBox;
     D3DBOX d3dBox;
     d3dBox.Left = 0;
     d3dBox.Top = 0;
     d3dBox.Front = 0;
-    d3dBox.Right = levelWidth;
-    d3dBox.Bottom = levelHeight;
-    d3dBox.Back = levelDepth;
-    
+    d3dBox.Right = (UINT)levelWidth;
+    d3dBox.Bottom = (UINT)levelHeight;
+    d3dBox.Back = (UINT)levelDepth;
+
     if (FAILED(((IDirect3DVolumeTexture9*)object_)->LockBox(level, &d3dLockedBox, &d3dBox, D3DLOCK_READONLY)))
     {
         LOGERROR("Could not lock texture");
         return false;
     }
-    
+
     int height = levelHeight;
     if (IsCompressed())
         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
     if (format_ == D3DFMT_X8R8G8B8)
         rowSize = rowSize / 3 * 4;
-    
+
     // Perform conversion to RGB / RGBA as necessary
     switch (format_)
     {
@@ -557,7 +572,7 @@ bool Texture3D::GetData(unsigned level, void* dest) const
             }
         }
         break;
-    
+
     case D3DFMT_X8R8G8B8:
         for (int k = 0; k < levelDepth; ++k)
         {
@@ -566,13 +581,16 @@ bool Texture3D::GetData(unsigned level, void* dest) const
                 unsigned char* src = (unsigned char*)d3dLockedBox.pBits + (k * d3dLockedBox.SlicePitch) + i * d3dLockedBox.RowPitch;
                 for (int j = 0; j < levelWidth; ++j)
                 {
-                    destPtr[2] = *src++; destPtr[1] = *src++; destPtr[0] = *src++; ++src;
+                    destPtr[2] = *src++;
+                    destPtr[1] = *src++;
+                    destPtr[0] = *src++;
+                    ++src;
                     destPtr += 3;
-               }
+                }
             }
         }
         break;
-        
+
     case D3DFMT_A8R8G8B8:
         for (int k = 0; k < levelDepth; ++k)
         {
@@ -581,14 +599,17 @@ bool Texture3D::GetData(unsigned level, void* dest) const
                 unsigned char* src = (unsigned char*)d3dLockedBox.pBits + (k * d3dLockedBox.SlicePitch) + i * d3dLockedBox.RowPitch;
                 for (int j = 0; j < levelWidth; ++j)
                 {
-                    destPtr[2] = *src++; destPtr[1] = *src++; destPtr[0] = *src++; destPtr[3] = *src++;
+                    destPtr[2] = *src++;
+                    destPtr[1] = *src++;
+                    destPtr[0] = *src++;
+                    destPtr[3] = *src++;
                     destPtr += 4;
-               }
+                }
             }
         }
         break;
     }
-    
+
     ((IDirect3DVolumeTexture9*)object_)->UnlockBox(level);
     return true;
 }
@@ -596,22 +617,22 @@ bool Texture3D::GetData(unsigned level, void* dest) const
 bool Texture3D::Create()
 {
     Release();
-    
+
     if (!graphics_ || !width_ || !height_)
         return false;
-    
+
     if (graphics_->IsDeviceLost())
     {
         LOGWARNING("Texture creation while device is lost");
         return true;
     }
-    
+
     IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
 
     if (!device || FAILED(graphics_->GetImpl()->GetDevice()->CreateVolumeTexture(
-        width_,
-        height_,
-        depth_,
+        (UINT)width_,
+        (UINT)height_,
+        (UINT)depth_,
         requestedLevels_,
         usage_,
         (D3DFORMAT)format_,
@@ -622,9 +643,9 @@ bool Texture3D::Create()
         LOGERROR("Could not create texture");
         return false;
     }
-    
+
     levels_ = ((IDirect3DVolumeTexture9*)object_)->GetLevelCount();
-    
+
     return true;
 }
 

+ 8 - 7
Source/Urho3D/Graphics/Direct3D9/D3D9Texture3D.h

@@ -22,8 +22,8 @@
 
 #pragma once
 
-#include "../../Graphics/RenderSurface.h"
 #include "../../Container/Ptr.h"
+#include "../../Graphics/RenderSurface.h"
 #include "../../Graphics/Texture.h"
 
 namespace Urho3D
@@ -35,7 +35,7 @@ class Image;
 class URHO3D_API Texture3D : public Texture
 {
     OBJECT(Texture3D);
-    
+
 public:
     /// Construct.
     Texture3D(Context* context);
@@ -43,7 +43,7 @@ public:
     virtual ~Texture3D();
     /// Register object factory.
     static void RegisterObject(Context* context);
-    
+
     /// Load resource from stream. May be called from a worker thread. Return true if successful.
     virtual bool BeginLoad(Deserializer& source);
     /// Finish resource loading. Always called from the main thread. Return true if successful.
@@ -54,25 +54,26 @@ public:
     virtual void OnDeviceReset();
     /// Release texture.
     virtual void Release();
-    
+
     /// Set size, format and usage. Zero size will follow application window size. Return true if successful.
     bool SetSize(int width, int height, int depth, unsigned format, TextureUsage usage = TEXTURE_STATIC);
     /// Set data either partially or fully on a mip level. Return true if successful.
     bool SetData(unsigned level, int x, int y, int z, int width, int height, int depth, const void* data);
     /// Set data from an image. Return true if successful. Optionally make a single channel image alpha-only.
     bool SetData(SharedPtr<Image> image, bool useAlpha = false);
-    
+
     /// Get data from a mip level. The destination buffer must be big enough. Return true if successful.
     bool GetData(unsigned level, void* dest) const;
+
     /// Return render surface.
     RenderSurface* GetRenderSurface() const { return renderSurface_; }
-    
+
 private:
     /// Create texture.
     bool Create();
     /// Handle render surface update event.
     void HandleRenderSurfaceUpdate(StringHash eventType, VariantMap& eventData);
-    
+
     /// Render surface.
     SharedPtr<RenderSurface> renderSurface_;
     /// Image file acquired during BeginLoad.

+ 126 - 107
Source/Urho3D/Graphics/Direct3D9/D3D9TextureCube.cpp

@@ -23,15 +23,15 @@
 #include "../../Precompiled.h"
 
 #include "../../Core/Context.h"
-#include "../../IO/FileSystem.h"
+#include "../../Core/Profiler.h"
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsEvents.h"
 #include "../../Graphics/GraphicsImpl.h"
-#include "../../IO/Log.h"
-#include "../../Core/Profiler.h"
 #include "../../Graphics/Renderer.h"
-#include "../../Resource/ResourceCache.h"
 #include "../../Graphics/TextureCube.h"
+#include "../../IO/FileSystem.h"
+#include "../../IO/Log.h"
+#include "../../Resource/ResourceCache.h"
 #include "../../Resource/XMLFile.h"
 
 #include "../../DebugNew.h"
@@ -54,7 +54,8 @@ static const char* cubeMapLayoutNames[] = {
 
 static SharedPtr<Image> GetTileImage(Image* src, int tileX, int tileY, int tileWidth, int tileHeight)
 {
-    return SharedPtr<Image>(src->GetSubimage(IntRect(tileX * tileWidth, tileY * tileHeight, (tileX + 1) * tileWidth, (tileY + 1) * tileHeight)));
+    return SharedPtr<Image>(
+        src->GetSubimage(IntRect(tileX * tileWidth, tileY * tileHeight, (tileX + 1) * tileWidth, (tileY + 1) * tileHeight)));
 }
 
 TextureCube::TextureCube(Context* context) :
@@ -65,7 +66,7 @@ TextureCube::TextureCube(Context* context) :
     addressMode_[COORD_U] = ADDRESS_CLAMP;
     addressMode_[COORD_V] = ADDRESS_CLAMP;
     addressMode_[COORD_W] = ADDRESS_CLAMP;
-    
+
     for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
         faceMemoryUse_[i] = 0;
 }
@@ -83,11 +84,11 @@ void TextureCube::RegisterObject(Context* context)
 bool TextureCube::BeginLoad(Deserializer& source)
 {
     ResourceCache* cache = GetSubsystem<ResourceCache>();
-    
+
     // In headless mode, do not actually load the texture, just return success
     if (!graphics_)
         return true;
-    
+
     // If device is lost, retry later
     if (graphics_->IsDeviceLost())
     {
@@ -95,19 +96,19 @@ bool TextureCube::BeginLoad(Deserializer& source)
         dataPending_ = true;
         return true;
     }
-    
+
     cache->ResetDependencies(this);
 
     String texPath, texName, texExt;
     SplitPath(GetName(), texPath, texName, texExt);
-    
+
     loadParameters_ = (new XMLFile(context_));
     if (!loadParameters_->Load(source))
     {
         loadParameters_.Reset();
         return false;
     }
-    
+
     loadImages_.Clear();
 
     XMLElement textureElem = loadParameters_->GetRoot();
@@ -119,15 +120,16 @@ bool TextureCube::BeginLoad(Deserializer& source)
         // If path is empty, add the XML file path
         if (GetPath(name).Empty())
             name = texPath + name;
-        
-        CubeMapLayout layout = (CubeMapLayout)GetStringListIndex(imageElem.GetAttribute("layout").CString(), cubeMapLayoutNames, CML_HORIZONTAL);
+
+        CubeMapLayout layout =
+            (CubeMapLayout)GetStringListIndex(imageElem.GetAttribute("layout").CString(), cubeMapLayoutNames, CML_HORIZONTAL);
         SharedPtr<Image> image = cache->GetTempResource<Image>(name);
         if (!image)
             return false;
-        
+
         int faceWidth, faceHeight;
         loadImages_.Resize(MAX_CUBEMAP_FACES);
-        
+
         switch (layout)
         {
         case CML_HORIZONTAL:
@@ -140,14 +142,14 @@ bool TextureCube::BeginLoad(Deserializer& source)
             loadImages_[FACE_POSITIVE_Y] = GetTileImage(image, 4, 0, faceWidth, faceHeight);
             loadImages_[FACE_NEGATIVE_Y] = GetTileImage(image, 5, 0, faceWidth, faceHeight);
             break;
-            
+
         case CML_HORIZONTALNVIDIA:
             faceWidth = image->GetWidth() / MAX_CUBEMAP_FACES;
             faceHeight = image->GetHeight();
             for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
                 loadImages_[i] = GetTileImage(image, i, 0, faceWidth, faceHeight);
             break;
-            
+
         case CML_HORIZONTALCROSS:
             faceWidth = image->GetWidth() / 4;
             faceHeight = image->GetHeight() / 3;
@@ -158,7 +160,7 @@ bool TextureCube::BeginLoad(Deserializer& source)
             loadImages_[FACE_NEGATIVE_Z] = GetTileImage(image, 3, 1, faceWidth, faceHeight);
             loadImages_[FACE_NEGATIVE_Y] = GetTileImage(image, 1, 2, faceWidth, faceHeight);
             break;
-            
+
         case CML_VERTICALCROSS:
             faceWidth = image->GetWidth() / 3;
             faceHeight = image->GetHeight() / 4;
@@ -174,7 +176,7 @@ bool TextureCube::BeginLoad(Deserializer& source)
                 loadImages_[FACE_NEGATIVE_Z]->FlipHorizontal();
             }
             break;
-            
+
         case CML_BLENDER:
             faceWidth = image->GetWidth() / 3;
             faceHeight = image->GetHeight() / 2;
@@ -194,14 +196,14 @@ bool TextureCube::BeginLoad(Deserializer& source)
         while (faceElem)
         {
             String name = faceElem.GetAttribute("name");
-            
+
             // If path is empty, add the XML file path
             if (GetPath(name).Empty())
                 name = texPath + name;
-            
+
             loadImages_.Push(cache->GetTempResource<Image>(name));
             cache->StoreResourceDependency(this, name);
-            
+
             faceElem = faceElem.GetNext("face");
         }
     }
@@ -224,18 +226,18 @@ bool TextureCube::EndLoad()
     // In headless mode, do not actually load the texture, just return success
     if (!graphics_ || graphics_->IsDeviceLost())
         return true;
-    
+
     // If over the texture budget, see if materials can be freed to allow textures to be freed
     CheckTextureBudget(GetTypeStatic());
 
     SetParameters(loadParameters_);
-    
+
     for (unsigned i = 0; i < loadImages_.Size() && i < MAX_CUBEMAP_FACES; ++i)
         SetData((CubeMapFace)i, loadImages_[i]);
-    
+
     loadImages_.Clear();
     loadParameters_.Reset();
-    
+
     return true;
 }
 
@@ -260,7 +262,7 @@ void TextureCube::OnDeviceReset()
             dataLost_ = true;
         }
     }
-    
+
     dataPending_ = false;
 }
 
@@ -270,19 +272,19 @@ void TextureCube::Release()
     {
         if (!graphics_)
             return;
-        
+
         for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
         {
             if (graphics_->GetTexture(i) == this)
                 graphics_->SetTexture(i, 0);
         }
-        
+
         for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
         {
             if (renderSurfaces_[i])
                 renderSurfaces_[i]->Release();
         }
-        
+
         ((IDirect3DCubeTexture9*)object_)->Release();
         object_ = 0;
     }
@@ -300,25 +302,25 @@ bool TextureCube::SetSize(int size, unsigned format, TextureUsage usage)
         LOGERROR("Depth-stencil usage not supported for cube maps");
         return false;
     }
-    
+
     // Delete the old rendersurfaces if any
     for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
     {
         renderSurfaces_[i].Reset();
         faceMemoryUse_[i] = 0;
     }
-    
+
     pool_ = D3DPOOL_MANAGED;
     usage_ = 0;
-    
+
     if (usage == TEXTURE_RENDERTARGET)
     {
         for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
             renderSurfaces_[i] = new RenderSurface(this);
-        
+
         usage_ |= D3DUSAGE_RENDERTARGET;
         pool_ = D3DPOOL_DEFAULT;
-        
+
         // Nearest filtering and mipmaps disabled by default
         filterMode_ = FILTER_NEAREST;
         requestedLevels_ = 1;
@@ -328,54 +330,54 @@ bool TextureCube::SetSize(int size, unsigned format, TextureUsage usage)
         usage_ |= D3DUSAGE_DYNAMIC;
         pool_ = D3DPOOL_DEFAULT;
     }
-    
+
     if (usage == TEXTURE_RENDERTARGET)
         SubscribeToEvent(E_RENDERSURFACEUPDATE, HANDLER(TextureCube, HandleRenderSurfaceUpdate));
     else
         UnsubscribeFromEvent(E_RENDERSURFACEUPDATE);
-    
+
     width_ = size;
     height_ = size;
     format_ = format;
-    
+
     return Create();
 }
 
 bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int width, int height, const void* data)
 {
     PROFILE(SetTextureData);
-    
+
     if (!object_)
     {
         LOGERROR("No texture created, can not set data");
         return false;
     }
-    
+
     if (!data)
     {
         LOGERROR("Null source for setting data");
         return false;
     }
-    
+
     if (level >= levels_)
     {
         LOGERROR("Illegal mip level for setting data");
         return false;
     }
-    
+
     if (graphics_->IsDeviceLost())
     {
         LOGWARNING("Texture data assignment while device is lost");
         dataPending_ = true;
         return true;
     }
-    
+
     if (IsCompressed())
     {
         x &= ~3;
         y &= ~3;
     }
-    
+
     int levelWidth = GetLevelWidth(level);
     int levelHeight = GetLevelHeight(level);
     if (x < 0 || x + width > levelWidth || y < 0 || y + height > levelHeight || width <= 0 || height <= 0)
@@ -383,38 +385,38 @@ bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int wi
         LOGERROR("Illegal dimensions for setting data");
         return false;
     }
-    
+
     D3DLOCKED_RECT d3dLockedRect;
     RECT d3dRect;
     d3dRect.left = x;
     d3dRect.top = y;
     d3dRect.right = x + width;
     d3dRect.bottom = y + height;
-    
+
     DWORD flags = 0;
     if (level == 0 && x == 0 && y == 0 && width == levelWidth && height == levelHeight && pool_ == D3DPOOL_DEFAULT)
         flags |= D3DLOCK_DISCARD;
-    
-    if (FAILED(((IDirect3DCubeTexture9*)object_)->LockRect((D3DCUBEMAP_FACES)face, level, &d3dLockedRect, (flags &
-        D3DLOCK_DISCARD) ? 0 : &d3dRect, flags)))
+
+    if (FAILED(((IDirect3DCubeTexture9*)object_)->LockRect((D3DCUBEMAP_FACES)face, level, &d3dLockedRect,
+        (flags & D3DLOCK_DISCARD) ? 0 : &d3dRect, flags)))
     {
         LOGERROR("Could not lock texture");
         return false;
     }
-    
+
     if (IsCompressed())
     {
         height = (height + 3) >> 2;
         y >>= 2;
     }
-    
+
     unsigned char* src = (unsigned char*)data;
     unsigned rowSize = GetRowDataSize(width);
-    
+
     // GetRowDataSize() returns CPU-side (source) data size, so need to convert for X8R8G8B8
     if (format_ == D3DFMT_X8R8G8B8)
         rowSize = rowSize / 3 * 4;
-    
+
     // Perform conversion from RGB / RGBA as necessary
     switch (format_)
     {
@@ -426,32 +428,38 @@ bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int wi
             src += rowSize;
         }
         break;
-    
+
     case D3DFMT_X8R8G8B8:
         for (int i = 0; i < height; ++i)
         {
             unsigned char* dest = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
             for (int j = 0; j < width; ++j)
             {
-                *dest++  = src[2]; *dest++ = src[1]; *dest++ = src[0]; *dest++ = 255;
+                *dest++ = src[2];
+                *dest++ = src[1];
+                *dest++ = src[0];
+                *dest++ = 255;
                 src += 3;
-           }
+            }
         }
         break;
-        
+
     case D3DFMT_A8R8G8B8:
         for (int i = 0; i < height; ++i)
         {
             unsigned char* dest = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
             for (int j = 0; j < width; ++j)
             {
-                *dest++  = src[2]; *dest++ = src[1]; *dest++ = src[0]; *dest++ = src[3];
+                *dest++ = src[2];
+                *dest++ = src[1];
+                *dest++ = src[0];
+                *dest++ = src[3];
                 src += 4;
-           }
+            }
         }
         break;
     }
-    
+
     ((IDirect3DCubeTexture9*)object_)->UnlockRect((D3DCUBEMAP_FACES)face, level);
     return true;
 }
@@ -461,7 +469,7 @@ bool TextureCube::SetData(CubeMapFace face, Deserializer& source)
     SharedPtr<Image> image(new Image(context_));
     if (!image->Load(source))
         return false;
-    
+
     return SetData(face, image);
 }
 
@@ -472,14 +480,14 @@ bool TextureCube::SetData(CubeMapFace face, SharedPtr<Image> image, bool useAlph
         LOGERROR("Null image, can not load texture");
         return false;
     }
-    
+
     unsigned memoryUse = 0;
-    
+
     int quality = QUALITY_HIGH;
     Renderer* renderer = GetSubsystem<Renderer>();
     if (renderer)
         quality = renderer->GetTextureQuality();
-    
+
     if (!image->IsCompressed())
     {
         unsigned char* levelData = image->GetData();
@@ -487,13 +495,13 @@ bool TextureCube::SetData(CubeMapFace face, SharedPtr<Image> image, bool useAlph
         int levelHeight = image->GetHeight();
         unsigned components = image->GetComponents();
         unsigned format = 0;
-        
+
         if (levelWidth != levelHeight)
         {
             LOGERROR("Cube texture width not equal to height");
             return false;
         }
-        
+
         // Discard unnecessary mip levels
         for (unsigned i = 0; i < mipsToSkip_[quality]; ++i)
         {
@@ -502,26 +510,30 @@ bool TextureCube::SetData(CubeMapFace face, SharedPtr<Image> image, bool useAlph
             levelWidth = image->GetWidth();
             levelHeight = image->GetHeight();
         }
-        
+
         switch (components)
         {
         case 1:
             format = useAlpha ? Graphics::GetAlphaFormat() : Graphics::GetLuminanceFormat();
             break;
-            
+
         case 2:
             format = Graphics::GetLuminanceAlphaFormat();
             break;
-            
+
         case 3:
             format = Graphics::GetRGBFormat();
             break;
-            
+
         case 4:
             format = Graphics::GetRGBAFormat();
             break;
+
+        default:
+            assert(false);  // Should never reach here
+            break;
         }
-        
+
         // Create the texture when face 0 is being loaded, check that rest of the faces are same size & format
         if (!face)
         {
@@ -543,12 +555,12 @@ bool TextureCube::SetData(CubeMapFace face, SharedPtr<Image> image, bool useAlph
                 return false;
             }
         }
-        
+
         for (unsigned i = 0; i < levels_; ++i)
         {
             SetData(face, i, 0, 0, levelWidth, levelHeight, levelData);
             memoryUse += levelWidth * levelHeight * components;
-            
+
             if (i < levels_ - 1)
             {
                 image = image->GetNextLevel();
@@ -565,19 +577,19 @@ bool TextureCube::SetData(CubeMapFace face, SharedPtr<Image> image, bool useAlph
         unsigned levels = image->GetNumCompressedLevels();
         unsigned format = graphics_->GetFormat(image->GetCompressedFormat());
         bool needDecompress = false;
-        
+
         if (width != height)
         {
             LOGERROR("Cube texture width not equal to height");
             return false;
         }
-        
+
         if (!format)
         {
             format = Graphics::GetRGBAFormat();
             needDecompress = true;
         }
-        
+
         unsigned mipsToSkip = mipsToSkip_[quality];
         if (mipsToSkip >= levels)
             mipsToSkip = levels - 1;
@@ -585,11 +597,11 @@ bool TextureCube::SetData(CubeMapFace face, SharedPtr<Image> image, bool useAlph
             --mipsToSkip;
         width /= (1 << mipsToSkip);
         height /= (1 << mipsToSkip);
-        
+
         // Create the texture when face 0 is being loaded, assume rest of the faces are same size & format
         if (!face)
         {
-            SetNumLevels(Max((int)(levels - mipsToSkip), 1));
+            SetNumLevels((unsigned)Max((int)(levels - mipsToSkip), 1));
             SetSize(width, format);
         }
         else
@@ -605,7 +617,7 @@ bool TextureCube::SetData(CubeMapFace face, SharedPtr<Image> image, bool useAlph
                 return false;
             }
         }
-        
+
         for (unsigned i = 0; i < levels_ && i < levels - mipsToSkip; ++i)
         {
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
@@ -624,13 +636,13 @@ bool TextureCube::SetData(CubeMapFace face, SharedPtr<Image> image, bool useAlph
             }
         }
     }
-    
+
     faceMemoryUse_[face] = memoryUse;
     unsigned totalMemoryUse = sizeof(TextureCube);
     for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
         totalMemoryUse += faceMemoryUse_[i];
     SetMemoryUse(totalMemoryUse);
-    
+
     return true;
 }
 
@@ -641,35 +653,35 @@ bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
         LOGERROR("No texture created, can not get data");
         return false;
     }
-    
+
     if (!dest)
     {
         LOGERROR("Null destination for getting data");
         return false;
     }
-    
+
     if (level >= levels_)
     {
         LOGERROR("Illegal mip level for getting data");
         return false;
     }
-    
+
     if (graphics_->IsDeviceLost())
     {
         LOGWARNING("Getting texture data while device is lost");
         return false;
     }
-    
+
     int levelWidth = GetLevelWidth(level);
     int levelHeight = GetLevelHeight(level);
-    
+
     D3DLOCKED_RECT d3dLockedRect;
     RECT d3dRect;
     d3dRect.left = 0;
     d3dRect.top = 0;
     d3dRect.right = levelWidth;
     d3dRect.bottom = levelHeight;
-    
+
     IDirect3DSurface9* offscreenSurface = 0;
     // Need to use a offscreen surface & GetRenderTargetData() for rendertargets
     if (renderSurfaces_[face])
@@ -681,7 +693,7 @@ bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
         }
 
         IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
-        device->CreateOffscreenPlainSurface(width_, height_, (D3DFORMAT)format_, D3DPOOL_SYSTEMMEM, &offscreenSurface, 0);
+        device->CreateOffscreenPlainSurface((UINT)width_, (UINT)height_, (D3DFORMAT)format_, D3DPOOL_SYSTEMMEM, &offscreenSurface, 0);
         if (!offscreenSurface)
         {
             LOGERROR("Could not create surface for getting rendertarget data");
@@ -697,23 +709,24 @@ bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
     }
     else
     {
-        if (FAILED(((IDirect3DCubeTexture9*)object_)->LockRect((D3DCUBEMAP_FACES)face, level, &d3dLockedRect, &d3dRect, D3DLOCK_READONLY)))
+        if (FAILED(
+            ((IDirect3DCubeTexture9*)object_)->LockRect((D3DCUBEMAP_FACES)face, level, &d3dLockedRect, &d3dRect, D3DLOCK_READONLY)))
         {
             LOGERROR("Could not lock texture");
             return false;
         }
     }
-    
+
     int height = levelHeight;
     if (IsCompressed())
         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
     if (format_ == D3DFMT_X8R8G8B8)
         rowSize = rowSize / 3 * 4;
-    
+
     // Perform conversion to RGB / RGBA as necessary
     switch (format_)
     {
@@ -725,32 +738,38 @@ bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
             destPtr += rowSize;
         }
         break;
-        
+
     case D3DFMT_X8R8G8B8:
         for (int i = 0; i < height; ++i)
         {
             unsigned char* src = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
             for (int j = 0; j < levelWidth; ++j)
             {
-                destPtr[2] = *src++; destPtr[1] = *src++; destPtr[0] = *src++; ++src;
+                destPtr[2] = *src++;
+                destPtr[1] = *src++;
+                destPtr[0] = *src++;
+                ++src;
                 destPtr += 3;
-           }
+            }
         }
         break;
-        
+
     case D3DFMT_A8R8G8B8:
         for (int i = 0; i < height; ++i)
         {
             unsigned char* src = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
             for (int j = 0; j < levelWidth; ++j)
             {
-                destPtr[2] = *src++; destPtr[1] = *src++; destPtr[0] = *src++; destPtr[3] = *src++;
+                destPtr[2] = *src++;
+                destPtr[1] = *src++;
+                destPtr[0] = *src++;
+                destPtr[3] = *src++;
                 destPtr += 4;
-           }
+            }
         }
         break;
     }
-    
+
     if (offscreenSurface)
     {
         offscreenSurface->UnlockRect();
@@ -758,26 +777,26 @@ bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
     }
     else
         ((IDirect3DCubeTexture9*)object_)->UnlockRect((D3DCUBEMAP_FACES)face, level);
-    
+
     return true;
 }
 
 bool TextureCube::Create()
 {
     Release();
-    
+
     if (!graphics_ || !width_ || !height_)
         return false;
-    
+
     if (graphics_->IsDeviceLost())
     {
         LOGWARNING("Texture creation while device is lost");
         return true;
     }
-    
+
     IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
     if (!device || FAILED(device->CreateCubeTexture(
-        width_,
+        (UINT)width_,
         requestedLevels_,
         usage_,
         (D3DFORMAT)format_,
@@ -788,9 +807,9 @@ bool TextureCube::Create()
         LOGERROR("Could not create cube texture");
         return false;
     }
-    
+
     levels_ = ((IDirect3DCubeTexture9*)object_)->GetLevelCount();
-    
+
     if (usage_ & D3DUSAGE_RENDERTARGET)
     {
         for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
@@ -799,7 +818,7 @@ bool TextureCube::Create()
                 (IDirect3DSurface9**)&renderSurfaces_[i]->surface_);
         }
     }
-    
+
     return true;
 }
 

+ 8 - 7
Source/Urho3D/Graphics/Direct3D9/D3D9TextureCube.h

@@ -22,8 +22,8 @@
 
 #pragma once
 
-#include "../../Graphics/RenderSurface.h"
 #include "../../Container/Ptr.h"
+#include "../../Graphics/RenderSurface.h"
 #include "../../Graphics/Texture.h"
 
 namespace Urho3D
@@ -36,7 +36,7 @@ class Image;
 class URHO3D_API TextureCube : public Texture
 {
     OBJECT(TextureCube);
-    
+
 public:
     /// Construct.
     TextureCube(Context* context);
@@ -44,7 +44,7 @@ public:
     virtual ~TextureCube();
     /// Register object factory.
     static void RegisterObject(Context* context);
-    
+
     /// Load resource from stream. May be called from a worker thread. Return true if successful.
     virtual bool BeginLoad(Deserializer& source);
     /// Finish resource loading. Always called from the main thread. Return true if successful.
@@ -55,7 +55,7 @@ public:
     virtual void OnDeviceReset();
     /// Release texture.
     virtual void Release();
-    
+
     /// Set size, format and usage. Return true if successful.
     bool SetSize(int size, unsigned format, TextureUsage usage = TEXTURE_STATIC);
     /// Set data either partially or fully on a face's mip level. Return true if successful.
@@ -64,18 +64,19 @@ public:
     bool SetData(CubeMapFace face, Deserializer& source);
     /// Set data of one face from an image. Return true if successful. Optionally make a single channel image alpha-only.
     bool SetData(CubeMapFace face, SharedPtr<Image> image, bool useAlpha = false);
-    
+
     /// Get data from a face's mip level. The destination buffer must be big enough. Return true if successful.
     bool GetData(CubeMapFace face, unsigned level, void* dest) const;
+
     /// Return render surface for one face.
     RenderSurface* GetRenderSurface(CubeMapFace face) const { return renderSurfaces_[face]; }
-    
+
 private:
     /// Create texture.
     bool Create();
     /// Handle render surface update event.
     void HandleRenderSurfaceUpdate(StringHash eventType, VariantMap& eventData);
-    
+
     /// Render surfaces.
     SharedPtr<RenderSurface> renderSurfaces_[MAX_CUBEMAP_FACES];
     /// Memory use per face.

+ 49 - 47
Source/Urho3D/Graphics/Direct3D9/D3D9VertexBuffer.cpp

@@ -24,8 +24,8 @@
 
 #include "../../Graphics/Graphics.h"
 #include "../../Graphics/GraphicsImpl.h"
-#include "../../IO/Log.h"
 #include "../../Graphics/VertexBuffer.h"
+#include "../../IO/Log.h"
 
 #include "../../DebugNew.h"
 
@@ -63,7 +63,7 @@ VertexBuffer::VertexBuffer(Context* context) :
     shadowed_(false)
 {
     UpdateOffsets();
-    
+
     // Force shadowing mode if graphics subsystem does not exist
     if (!graphics_)
         shadowed_ = true;
@@ -89,25 +89,25 @@ void VertexBuffer::OnDeviceReset()
     }
     else if (dataPending_)
         dataLost_ = !UpdateToGPU();
-    
+
     dataPending_ = false;
 }
 
 void VertexBuffer::Release()
 {
     Unlock();
-    
+
     if (object_)
     {
         if (!graphics_)
             return;
-        
+
         for (unsigned i = 0; i < MAX_VERTEX_STREAMS; ++i)
         {
             if (graphics_->GetVertexBuffer(i) == this)
                 graphics_->SetVertexBuffer(0);
         }
-        
+
         ((IDirect3DVertexBuffer9*)object_)->Release();
         object_ = 0;
     }
@@ -118,14 +118,14 @@ void VertexBuffer::SetShadowed(bool enable)
     // If no graphics subsystem, can not disable shadowing
     if (!graphics_)
         enable = true;
-    
+
     if (enable != shadowed_)
     {
         if (enable && vertexSize_ && vertexCount_)
             shadowData_ = new unsigned char[vertexCount_ * vertexSize_];
         else
             shadowData_.Reset();
-        
+
         shadowed_ = enable;
     }
 }
@@ -133,7 +133,7 @@ void VertexBuffer::SetShadowed(bool enable)
 bool VertexBuffer::SetSize(unsigned vertexCount, unsigned elementMask, bool dynamic)
 {
     Unlock();
-    
+
     if (dynamic)
     {
         pool_ = D3DPOOL_DEFAULT;
@@ -144,17 +144,17 @@ bool VertexBuffer::SetSize(unsigned vertexCount, unsigned elementMask, bool dyna
         pool_ = D3DPOOL_MANAGED;
         usage_ = 0;
     }
-    
+
     vertexCount_ = vertexCount;
     elementMask_ = elementMask;
-    
+
     UpdateOffsets();
-    
+
     if (shadowed_ && vertexCount_ && vertexSize_)
         shadowData_ = new unsigned char[vertexCount_ * vertexSize_];
     else
         shadowData_.Reset();
-    
+
     return Create();
 }
 
@@ -165,16 +165,16 @@ bool VertexBuffer::SetData(const void* data)
         LOGERROR("Null pointer for vertex buffer data");
         return false;
     }
-    
+
     if (!vertexSize_)
     {
         LOGERROR("Vertex elements not defined, can not set vertex buffer data");
         return false;
     }
-    
+
     if (shadowData_ && data != shadowData_.Get())
         memcpy(shadowData_.Get(), data, vertexCount_ * vertexSize_);
-    
+
     if (object_)
     {
         if (graphics_->IsDeviceLost())
@@ -183,7 +183,7 @@ bool VertexBuffer::SetData(const void* data)
             dataPending_ = true;
             return true;
         }
-        
+
         void* hwData = MapBuffer(0, vertexCount_, true);
         if (hwData)
         {
@@ -193,7 +193,7 @@ bool VertexBuffer::SetData(const void* data)
         else
             return false;
     }
-    
+
     dataLost_ = false;
     return true;
 }
@@ -202,31 +202,31 @@ bool VertexBuffer::SetDataRange(const void* data, unsigned start, unsigned count
 {
     if (start == 0 && count == vertexCount_)
         return SetData(data);
-    
+
     if (!data)
     {
         LOGERROR("Null pointer for vertex buffer data");
         return false;
     }
-    
+
     if (!vertexSize_)
     {
         LOGERROR("Vertex elements not defined, can not set vertex buffer data");
         return false;
     }
-    
+
     if (start + count > vertexCount_)
     {
         LOGERROR("Illegal range for setting new vertex buffer data");
         return false;
     }
-    
+
     if (!count)
         return true;
-    
+
     if (shadowData_ && shadowData_.Get() + start * vertexSize_ != data)
         memcpy(shadowData_.Get() + start * vertexSize_, data, count * vertexSize_);
-    
+
     if (object_)
     {
         if (graphics_->IsDeviceLost())
@@ -235,7 +235,7 @@ bool VertexBuffer::SetDataRange(const void* data, unsigned start, unsigned count
             dataPending_ = true;
             return true;
         }
-        
+
         void* hwData = MapBuffer(start, count, discard);
         if (hwData)
         {
@@ -256,25 +256,25 @@ void* VertexBuffer::Lock(unsigned start, unsigned count, bool discard)
         LOGERROR("Vertex buffer already locked");
         return 0;
     }
-    
+
     if (!vertexSize_)
     {
         LOGERROR("Vertex elements not defined, can not lock vertex buffer");
         return 0;
     }
-    
+
     if (start + count > vertexCount_)
     {
         LOGERROR("Illegal range for locking vertex buffer");
         return 0;
     }
-    
+
     if (!count)
         return 0;
-    
+
     lockStart_ = start;
     lockCount_ = count;
-    
+
     // Because shadow data must be kept in sync, can only lock hardware buffer if not shadowed
     if (object_ && !shadowData_ && !graphics_->IsDeviceLost())
         return MapBuffer(start, count, discard);
@@ -300,12 +300,12 @@ void VertexBuffer::Unlock()
     case LOCK_HARDWARE:
         UnmapBuffer();
         break;
-        
+
     case LOCK_SHADOW:
         SetDataRange(shadowData_.Get() + lockStart_ * vertexSize_, lockStart_, lockCount_);
         lockState_ = LOCK_NONE;
         break;
-        
+
     case LOCK_SCRATCH:
         SetDataRange(lockScratchData_, lockStart_, lockCount_);
         if (graphics_)
@@ -313,6 +313,8 @@ void VertexBuffer::Unlock()
         lockScratchData_ = 0;
         lockState_ = LOCK_NONE;
         break;
+
+    default: break;
     }
 }
 
@@ -345,49 +347,49 @@ unsigned long long VertexBuffer::GetBufferHash(unsigned streamIndex, unsigned us
         maskHash = ((unsigned long long)elementMask_) * 0x100000000ULL;
     else
         maskHash = ((unsigned long long)useMask) * 0x100000000ULL;
-    
+
     bufferHash |= maskHash;
     bufferHash <<= streamIndex * MAX_VERTEX_ELEMENTS;
-    
+
     return bufferHash;
 }
 
 unsigned VertexBuffer::GetVertexSize(unsigned elementMask)
 {
     unsigned vertexSize = 0;
-    
+
     for (unsigned i = 0; i < MAX_VERTEX_ELEMENTS; ++i)
     {
         if (elementMask & (1 << i))
             vertexSize += elementSize[i];
     }
-    
+
     return vertexSize;
 }
 
 unsigned VertexBuffer::GetElementOffset(unsigned elementMask, VertexElement element)
 {
     unsigned offset = 0;
-    
+
     for (unsigned i = 0; i < MAX_VERTEX_ELEMENTS; ++i)
     {
         if (i == element)
             break;
-        
+
         if (elementMask & (1 << i))
             offset += elementSize[i];
     }
-    
+
     return offset;
 }
 
 bool VertexBuffer::Create()
 {
     Release();
-    
+
     if (!vertexCount_ || !elementMask_)
         return true;
-    
+
     if (graphics_)
     {
         if (graphics_->IsDeviceLost())
@@ -395,7 +397,7 @@ bool VertexBuffer::Create()
             LOGWARNING("Vertex buffer creation while device is lost");
             return true;
         }
-        
+
         IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
         if (!device || FAILED(device->CreateVertexBuffer(
             vertexCount_ * vertexSize_,
@@ -409,7 +411,7 @@ bool VertexBuffer::Create()
             return false;
         }
     }
-    
+
     return true;
 }
 
@@ -424,20 +426,20 @@ bool VertexBuffer::UpdateToGPU()
 void* VertexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
 {
     void* hwData = 0;
-    
+
     if (object_)
     {
         DWORD flags = 0;
-        
+
         if (discard && usage_ & D3DUSAGE_DYNAMIC)
             flags = D3DLOCK_DISCARD;
-        
+
         if (FAILED(((IDirect3DVertexBuffer9*)object_)->Lock(start * vertexSize_, count * vertexSize_, &hwData, flags)))
             LOGERROR("Could not lock vertex buffer");
         else
             lockState_ = LOCK_HARDWARE;
     }
-    
+
     return hwData;
 }
 

+ 19 - 10
Source/Urho3D/Graphics/Direct3D9/D3D9VertexBuffer.h

@@ -22,9 +22,9 @@
 
 #pragma once
 
+#include "../../Container/ArrayPtr.h"
 #include "../../Graphics/GPUObject.h"
 #include "../../Graphics/GraphicsDefs.h"
-#include "../../Container/ArrayPtr.h"
 
 namespace Urho3D
 {
@@ -33,20 +33,20 @@ namespace Urho3D
 class URHO3D_API VertexBuffer : public Object, public GPUObject
 {
     OBJECT(VertexBuffer);
-    
+
 public:
     /// Construct.
     VertexBuffer(Context* context);
     /// Destruct.
     virtual ~VertexBuffer();
-    
+
     /// Release default pool resources.
     virtual void OnDeviceLost();
     /// ReCreate default pool resources.
     virtual void OnDeviceReset();
     /// Release buffer.
     virtual void Release();
-    
+
     /// Enable shadowing in CPU memory. Shadowing is forced on if the graphics subsystem does not exist.
     void SetShadowed(bool enable);
     /// Set size and vertex elements and dynamic mode. Previous data will be lost.
@@ -59,25 +59,34 @@ public:
     void* Lock(unsigned start, unsigned count, bool discard = false);
     /// Unlock the buffer and apply changes to the GPU buffer.
     void Unlock();
-    
+
     /// Return whether CPU memory shadowing is enabled.
     bool IsShadowed() const { return shadowed_; }
+
     /// Return whether is dynamic.
     bool IsDynamic() const;
+
     /// Return whether is currently locked.
     bool IsLocked() const { return lockState_ != LOCK_NONE; }
+
     /// Return number of vertices.
-    unsigned GetVertexCount() const {return vertexCount_; }
+    unsigned GetVertexCount() const { return vertexCount_; }
+
     /// Return vertex size.
     unsigned GetVertexSize() const { return vertexSize_; }
+
     /// Return bitmask of vertex elements.
     unsigned GetElementMask() const { return elementMask_; }
+
     /// Return offset of a specified element within a vertex.
     unsigned GetElementOffset(VertexElement element) const { return elementOffset_[element]; }
+
     /// Return buffer hash for building vertex declarations.
     unsigned long long GetBufferHash(unsigned streamIndex, unsigned useMask);
+
     /// Return CPU memory shadow data.
     unsigned char* GetShadowData() const { return shadowData_.Get(); }
+
     /// Return shared array pointer to the CPU memory shadow data.
     SharedArrayPtr<unsigned char> GetShadowDataShared() const { return shadowData_; }
 
@@ -85,10 +94,10 @@ public:
     static unsigned GetVertexSize(unsigned elementMask);
     /// Return element offset from an element mask.
     static unsigned GetElementOffset(unsigned elementMask, VertexElement element);
-    
+
     /// Vertex element sizes.
     static const unsigned elementSize[];
-    
+
 private:
     /// Update offsets of vertex elements.
     void UpdateOffsets();
@@ -100,7 +109,7 @@ private:
     void* MapBuffer(unsigned start, unsigned count, bool discard);
     /// Unmap the GPU buffer.
     void UnmapBuffer();
-    
+
     /// Shadow data.
     SharedArrayPtr<unsigned char> shadowData_;
     /// Number of vertices.
@@ -109,7 +118,7 @@ private:
     unsigned vertexSize_;
     /// Vertex element bitmask.
     unsigned elementMask_;
-   /// Vertex element offsets.
+    /// Vertex element offsets.
     unsigned elementOffset_[MAX_VERTEX_ELEMENTS];
     /// Memory pool.
     unsigned pool_;

+ 26 - 24
Source/Urho3D/Graphics/Direct3D9/D3D9VertexDeclaration.cpp

@@ -88,11 +88,11 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, unsigned elementMask) :
 {
     PODVector<VertexDeclarationElement> elements;
     unsigned offset = 0;
-    
+
     for (unsigned i = 0; i < MAX_VERTEX_ELEMENTS; ++i)
     {
         VertexElement element = (VertexElement)i;
-        
+
         if (elementMask & (1 << i))
         {
             VertexDeclarationElement newElement;
@@ -100,26 +100,27 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, unsigned elementMask) :
             newElement.element_ = element;
             newElement.offset_ = offset;
             offset += VertexBuffer::elementSize[i];
-            
+
             elements.Push(newElement);
         }
     }
-    
+
     Create(graphics, elements);
 }
 
-VertexDeclaration::VertexDeclaration(Graphics* graphics, const PODVector<VertexBuffer*>& buffers, const PODVector<unsigned>& elementMasks) :
+VertexDeclaration::VertexDeclaration(Graphics* graphics, const PODVector<VertexBuffer*>& buffers,
+    const PODVector<unsigned>& elementMasks) :
     declaration_(0)
 {
     unsigned usedElementMask = 0;
     PODVector<VertexDeclarationElement> elements;
-    
+
     for (unsigned i = 0; i < buffers.Size(); ++i)
     {
         if (buffers[i])
         {
             unsigned elementMask = elementMasks[i];
-            
+
             if (elementMask == MASK_DEFAULT)
                 elementMask = buffers[i]->GetElementMask();
             else
@@ -127,11 +128,11 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, const PODVector<VertexB
                 if ((buffers[i]->GetElementMask() & elementMask) != elementMask)
                     return;
             }
-            
+
             for (unsigned j = 0; j < MAX_VERTEX_ELEMENTS; ++j)
             {
                 VertexElement element = (VertexElement)j;
-                
+
                 if (elementMask & (1 << j) && !(usedElementMask & (1 << j)))
                 {
                     VertexDeclarationElement newElement;
@@ -139,28 +140,29 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, const PODVector<VertexB
                     newElement.element_ = element;
                     newElement.offset_ = buffers[i]->GetElementOffset(element);
                     usedElementMask |= 1 << j;
-                    
+
                     elements.Push(newElement);
                 }
             }
         }
     }
-    
+
     Create(graphics, elements);
 }
 
-VertexDeclaration::VertexDeclaration(Graphics* graphics, const Vector<SharedPtr<VertexBuffer> >& buffers, const PODVector<unsigned>& elementMasks) :
+VertexDeclaration::VertexDeclaration(Graphics* graphics, const Vector<SharedPtr<VertexBuffer> >& buffers,
+    const PODVector<unsigned>& elementMasks) :
     declaration_(0)
 {
     unsigned usedElementMask = 0;
     PODVector<VertexDeclarationElement> elements;
-    
+
     for (unsigned i = 0; i < buffers.Size(); ++i)
     {
         if (buffers[i])
         {
             unsigned elementMask = elementMasks[i];
-            
+
             if (elementMask == MASK_DEFAULT)
                 elementMask = buffers[i]->GetElementMask();
             else
@@ -168,11 +170,11 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, const Vector<SharedPtr<
                 if ((buffers[i]->GetElementMask() & elementMask) != elementMask)
                     return;
             }
-            
+
             for (unsigned j = 0; j < MAX_VERTEX_ELEMENTS; ++j)
             {
                 VertexElement element = (VertexElement)j;
-                
+
                 if (elementMask & (1 << j) && !(usedElementMask & (1 << j)))
                 {
                     VertexDeclarationElement newElement;
@@ -180,13 +182,13 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, const Vector<SharedPtr<
                     newElement.element_ = element;
                     newElement.offset_ = buffers[i]->GetElementOffset(element);
                     usedElementMask |= 1 << j;
-                    
+
                     elements.Push(newElement);
                 }
             }
         }
     }
-    
+
     Create(graphics, elements);
 }
 
@@ -198,30 +200,30 @@ VertexDeclaration::~VertexDeclaration()
 void VertexDeclaration::Create(Graphics* graphics, const PODVector<VertexDeclarationElement>& elements)
 {
     SharedArrayPtr<D3DVERTEXELEMENT9> elementArray(new D3DVERTEXELEMENT9[elements.Size() + 1]);
-    
+
     D3DVERTEXELEMENT9* dest = elementArray;
     for (Vector<VertexDeclarationElement>::ConstIterator i = elements.Begin(); i != elements.End(); ++i)
     {
-        dest->Stream = i->stream_;
-        dest->Offset = i->offset_;
+        dest->Stream = (WORD)i->stream_;
+        dest->Offset = (WORD)i->offset_;
         dest->Type = d3dElementType[i->element_];
         dest->Method = D3DDECLMETHOD_DEFAULT;
         dest->Usage = d3dElementUsage[i->element_];
         dest->UsageIndex = d3dElementUsageIndex[i->element_];
         dest++;
     }
-    
+
     dest->Stream = 0xff;
     dest->Offset = 0;
     dest->Type = D3DDECLTYPE_UNUSED;
     dest->Method = 0;
     dest->Usage = 0;
     dest->UsageIndex = 0;
-    
+
     IDirect3DDevice9* device = graphics->GetImpl()->GetDevice();
     if (!device)
         return;
-    
+
     device->CreateVertexDeclaration(elementArray, &declaration_);
 }
 

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

@@ -22,9 +22,9 @@
 
 #pragma once
 
-#include "../../Graphics/GraphicsDefs.h"
 #include "../../Container/RefCounted.h"
 #include "../../Container/Vector.h"
+#include "../../Graphics/GraphicsDefs.h"
 
 #include <d3d9.h>
 
@@ -57,16 +57,16 @@ public:
     VertexDeclaration(Graphics* graphics, const Vector<SharedPtr<VertexBuffer> >& buffers, const PODVector<unsigned>& elementMasks);
     /// Destruct.
     ~VertexDeclaration();
-    
+
     /// Return Direct3D vertex declaration.
     IDirect3DVertexDeclaration9* GetDeclaration() const { return declaration_; }
-    
+
 private:
     /// Create declaration.
     void Create(Graphics* graphics, const PODVector<VertexDeclarationElement>& elements);
     /// Release declaration.
     void Release();
-    
+
     /// Direct3D vertex declaration.
     IDirect3DVertexDeclaration9* declaration_;
 };

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