Browse Source

Separate ConstantBuffer to API-independent and -specific implementations, and unify the header. Add dummy D3D9 constant buffer implementation (that only logs error if used) so that user will not get link errors if attempting to use.

Lasse Öörni 9 years ago
parent
commit
9b51baa445

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

@@ -0,0 +1,73 @@
+//
+// Copyright (c) 2008-2016 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#include "../Precompiled.h"
+
+#include "../Graphics/Graphics.h"
+#include "../Graphics/ConstantBuffer.h"
+#include "../IO/Log.h"
+
+#include "../DebugNew.h"
+
+namespace Urho3D
+{
+
+ConstantBuffer::ConstantBuffer(Context* context) :
+    Object(context),
+    GPUObject(GetSubsystem<Graphics>())
+{
+}
+
+ConstantBuffer::~ConstantBuffer()
+{
+    Release();
+}
+
+void ConstantBuffer::SetParameter(unsigned offset, unsigned size, const void* data)
+{
+    if (offset + size > size_)
+        return; // Would overflow the buffer
+
+    memcpy(&shadowData_[offset], data, size);
+    dirty_ = true;
+}
+
+void ConstantBuffer::SetVector3ArrayParameter(unsigned offset, unsigned rows, const void* data)
+{
+    if (offset + rows * 4 * sizeof(float) > size_)
+        return; // Would overflow the buffer
+
+    float* dest = (float*)&shadowData_[offset];
+    const float* src = (const float*)data;
+
+    while (rows--)
+    {
+        *dest++ = *src++;
+        *dest++ = *src++;
+        *dest++ = *src++;
+        ++dest; // Skip over the w coordinate
+    }
+
+    dirty_ = true;
+}
+
+}

+ 49 - 5
Source/Urho3D/Graphics/ConstantBuffer.h

@@ -22,8 +22,52 @@
 
 #pragma once
 
-#if defined(URHO3D_OPENGL)
-#include "OpenGL/OGLConstantBuffer.h"
-#elif defined(URHO3D_D3D11)
-#include "Direct3D11/D3D11ConstantBuffer.h"
-#endif
+#include "../Container/ArrayPtr.h"
+#include "../Core/Object.h"
+#include "../Graphics/GPUObject.h"
+#include "../Graphics/GraphicsDefs.h"
+
+namespace Urho3D
+{
+
+/// Hardware constant buffer.
+class URHO3D_API ConstantBuffer : public Object, public GPUObject
+{
+    URHO3D_OBJECT(ConstantBuffer, Object);
+
+public:
+    /// Construct.
+    ConstantBuffer(Context* context);
+    /// Destruct.
+    virtual ~ConstantBuffer();
+
+    /// Recreate the GPU resource and restore data if applicable.
+    virtual void OnDeviceReset();
+    /// Release the 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.
+    void SetParameter(unsigned offset, unsigned size, const void* data);
+    /// Set a Vector3 array parameter and mark buffer dirty.
+    void SetVector3ArrayParameter(unsigned offset, unsigned rows, const void* data);
+    /// Apply to GPU.
+    void Apply();
+
+    /// Return size.
+    unsigned GetSize() const { return size_; }
+
+    /// Return whether has unapplied data.
+    bool IsDirty() const { return dirty_; }
+
+private:
+    /// Shadow data.
+    SharedArrayPtr<unsigned char> shadowData_;
+    /// Buffer byte size.
+    unsigned size_;
+    /// Dirty flag.
+    bool dirty_;
+};
+
+}

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

@@ -32,15 +32,9 @@
 namespace Urho3D
 {
 
-ConstantBuffer::ConstantBuffer(Context* context) :
-    Object(context),
-    GPUObject(GetSubsystem<Graphics>())
+void ConstantBuffer::OnDeviceReset()
 {
-}
-
-ConstantBuffer::~ConstantBuffer()
-{
-    Release();
+    // No-op on Direct3D11
 }
 
 void ConstantBuffer::Release()
@@ -92,34 +86,6 @@ bool ConstantBuffer::SetSize(unsigned size)
     return true;
 }
 
-void ConstantBuffer::SetParameter(unsigned offset, unsigned size, const void* data)
-{
-    if (offset + size > size_)
-        return; // Would overflow the buffer
-
-    memcpy(&shadowData_[offset], data, size);
-    dirty_ = true;
-}
-
-void ConstantBuffer::SetVector3ArrayParameter(unsigned offset, unsigned rows, const void* data)
-{
-    if (offset + rows * 4 * sizeof(float) > size_)
-        return; // Would overflow the buffer
-
-    float* dest = (float*)&shadowData_[offset];
-    const float* src = (const float*)data;
-
-    while (rows--)
-    {
-        *dest++ = *src++;
-        *dest++ = *src++;
-        *dest++ = *src++;
-        ++dest; // Skip over the w coordinate
-    }
-
-    dirty_ = true;
-}
-
 void ConstantBuffer::Apply()
 {
     if (dirty_ && object_.ptr_)

+ 0 - 71
Source/Urho3D/Graphics/Direct3D11/D3D11ConstantBuffer.h

@@ -1,71 +0,0 @@
-//
-// Copyright (c) 2008-2016 the Urho3D project.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-//
-
-#pragma once
-
-#include "../../Container/ArrayPtr.h"
-#include "../../Core/Object.h"
-#include "../../Graphics/GPUObject.h"
-#include "../../Graphics/GraphicsDefs.h"
-
-namespace Urho3D
-{
-
-/// Hardware constant buffer.
-class URHO3D_API ConstantBuffer : public Object, public GPUObject
-{
-    URHO3D_OBJECT(ConstantBuffer, Object);
-
-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.
-    void SetParameter(unsigned offset, unsigned size, const void* data);
-    /// Set a Vector3 array parameter and mark buffer dirty.
-    void SetVector3ArrayParameter(unsigned offset, unsigned rows, const void* data);
-    /// Apply to GPU.
-    void Apply();
-
-    /// Return size.
-    unsigned GetSize() const { return size_; }
-
-    /// Return whether has unapplied data.
-    bool IsDirty() const { return dirty_; }
-
-private:
-    /// Shadow data.
-    SharedArrayPtr<unsigned char> shadowData_;
-    /// Buffer byte size.
-    unsigned size_;
-    /// Dirty flag.
-    bool dirty_;
-};
-
-}

+ 52 - 0
Source/Urho3D/Graphics/Direct3D9/D3D9ConstantBuffer.cpp

@@ -0,0 +1,52 @@
+//
+// Copyright (c) 2008-2016 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#include "../../Precompiled.h"
+
+#include "../../Graphics/Graphics.h"
+#include "../../Graphics/ConstantBuffer.h"
+#include "../../IO/Log.h"
+
+#include "../../DebugNew.h"
+
+namespace Urho3D
+{
+
+void ConstantBuffer::OnDeviceReset()
+{
+}
+
+void ConstantBuffer::Release()
+{
+}
+
+bool ConstantBuffer::SetSize(unsigned size)
+{
+    URHO3D_LOGERROR("Constant buffers are not supported on Direct3D9");
+    return false;
+}
+
+void ConstantBuffer::Apply()
+{
+}
+
+}

+ 1 - 7
Source/Urho3D/Graphics/GPUObject.h

@@ -49,28 +49,22 @@ public:
 
     /// Mark the GPU resource destroyed on graphics context destruction.
     virtual void OnDeviceLost();
-
     /// Recreate the GPU resource and restore data if applicable.
     virtual void OnDeviceReset();
-
     /// Unconditionally release the GPU resource.
     virtual void Release();
 
     /// Clear the data lost flag.
     void ClearDataLost();
 
-    /// Return the graphics subsystem.
+    /// Return the graphics subsystem associated with this GPU object.
     Graphics* GetGraphics() const;
-
     /// Return the object pointer. Applicable only on Direct3D.
     void* GetGPUObject() const { return object_.ptr_; }
-    
     /// Return the object name. Applicable only on OpenGL.
     unsigned GetGPUObjectName() const { return object_.name_; }
-
     /// Return whether data is lost due to context loss.
     bool IsDataLost() const { return dataLost_; }
-
     /// Return whether has pending data assigned while graphics context was lost.
     bool HasPendingData() const { return dataPending_; }
 

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

@@ -43,10 +43,8 @@ public:
 
     /// Mark the buffer destroyed on graphics context destruction. May be a no-op depending on the API.
     virtual void OnDeviceLost();
-
     /// Recreate the buffer and restore data if applicable. May be a no-op depending on the API.
     virtual void OnDeviceReset();
-
     /// Release buffer.
     virtual void Release();
 

+ 0 - 39
Source/Urho3D/Graphics/OpenGL/OGLConstantBuffer.cpp

@@ -32,17 +32,6 @@
 namespace Urho3D
 {
 
-ConstantBuffer::ConstantBuffer(Context* context) :
-    Object(context),
-    GPUObject(GetSubsystem<Graphics>())
-{
-}
-
-ConstantBuffer::~ConstantBuffer()
-{
-    Release();
-}
-
 void ConstantBuffer::Release()
 {
     if (object_.name_)
@@ -97,34 +86,6 @@ bool ConstantBuffer::SetSize(unsigned size)
     return true;
 }
 
-void ConstantBuffer::SetParameter(unsigned offset, unsigned size, const void* data)
-{
-    if (offset + size > size_)
-        return; // Would overflow the buffer
-
-    memcpy(&shadowData_[offset], data, size);
-    dirty_ = true;
-}
-
-void ConstantBuffer::SetVector3ArrayParameter(unsigned offset, unsigned rows, const void* data)
-{
-    if (offset + rows * 4 * sizeof(float) > size_)
-        return; // Would overflow the buffer
-
-    float* dest = (float*)&shadowData_[offset];
-    const float* src = (const float*)data;
-
-    while (rows--)
-    {
-        *dest++ = *src++;
-        *dest++ = *src++;
-        *dest++ = *src++;
-        ++dest; // Skip over the w coordinate
-    }
-
-    dirty_ = true;
-}
-
 void ConstantBuffer::Apply()
 {
     if (dirty_ && object_.name_)

+ 0 - 73
Source/Urho3D/Graphics/OpenGL/OGLConstantBuffer.h

@@ -1,73 +0,0 @@
-//
-// Copyright (c) 2008-2016 the Urho3D project.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-//
-
-#pragma once
-
-#include "../../Container/ArrayPtr.h"
-#include "../../Core/Object.h"
-#include "../../Graphics/GPUObject.h"
-#include "../../Graphics/GraphicsDefs.h"
-
-namespace Urho3D
-{
-
-/// Hardware constant buffer.
-class URHO3D_API ConstantBuffer : public Object, public GPUObject
-{
-    URHO3D_OBJECT(ConstantBuffer, Object);
-
-public:
-    /// Construct.
-    ConstantBuffer(Context* context);
-    /// Destruct.
-    virtual ~ConstantBuffer();
-
-    /// Recreate the GPU resource and restore data if applicable.
-    virtual void OnDeviceReset();
-    /// Release the 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.
-    void SetParameter(unsigned offset, unsigned size, const void* data);
-    /// Set a Vector3 array parameter and mark buffer dirty.
-    void SetVector3ArrayParameter(unsigned offset, unsigned rows, const void* data);
-    /// Apply to GPU.
-    void Apply();
-
-    /// Return size.
-    unsigned GetSize() const { return size_; }
-
-    /// Return whether has unapplied data.
-    bool IsDirty() const { return dirty_; }
-
-private:
-    /// Shadow data.
-    SharedArrayPtr<unsigned char> shadowData_;
-    /// Buffer byte size.
-    unsigned size_;
-    /// Dirty flag.
-    bool dirty_;
-};
-
-}

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

@@ -43,10 +43,8 @@ public:
 
     /// Mark the buffer destroyed on graphics context destruction. May be a no-op depending on the API.
     virtual void OnDeviceLost();
-
     /// Recreate the buffer and restore data if applicable. May be a no-op depending on the API.
     virtual void OnDeviceReset();
-
     /// Release buffer.
     virtual void Release();