瀏覽代碼

IndexBuffer: unsigned to signed

1vanK 3 年之前
父節點
當前提交
04fa35540d

+ 16 - 16
Source/Urho3D/AngelScript/Generated_Members.h

@@ -10619,27 +10619,27 @@ template <class T> void RegisterMembers_IndexBuffer(asIScriptEngine* engine, con
     RegisterMembers_Object<T>(engine, className);
     RegisterMembers_GPUObject<T>(engine, className);
 
-    // unsigned char* IndexBuffer::GetShadowData() const
-    // Error: type "unsigned char*" can not automatically bind
-    // SharedArrayPtr<unsigned char> IndexBuffer::GetShadowDataShared() const
-    // Error: type "SharedArrayPtr<unsigned char>" can not automatically bind
-    // void* IndexBuffer::Lock(unsigned start, unsigned count, bool discard = false)
+    // u8* IndexBuffer::GetShadowData() const
+    // Error: type "u8*" can not automatically bind
+    // SharedArrayPtr<u8> IndexBuffer::GetShadowDataShared() const
+    // Error: type "SharedArrayPtr<u8>" can not automatically bind
+    // void* IndexBuffer::Lock(i32 start, i32 count, bool discard = false)
     // Error: type "void*" can not automatically bind
     // bool IndexBuffer::SetData(const void* data)
     // Error: type "const void*" can not automatically bind
-    // bool IndexBuffer::SetDataRange(const void* data, unsigned start, unsigned count, bool discard = false)
+    // bool IndexBuffer::SetDataRange(const void* data, i32 start, i32 count, bool discard = false)
     // Error: type "const void*" can not automatically bind
 
-    // unsigned IndexBuffer::GetIndexCount() const
-    engine->RegisterObjectMethod(className, "uint GetIndexCount() const", AS_METHODPR(T, GetIndexCount, () const, unsigned), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "uint get_indexCount() const", AS_METHODPR(T, GetIndexCount, () const, unsigned), AS_CALL_THISCALL);
+    // i32 IndexBuffer::GetIndexCount() const
+    engine->RegisterObjectMethod(className, "int GetIndexCount() const", AS_METHODPR(T, GetIndexCount, () const, i32), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "int get_indexCount() const", AS_METHODPR(T, GetIndexCount, () const, i32), AS_CALL_THISCALL);
 
-    // unsigned IndexBuffer::GetIndexSize() const
-    engine->RegisterObjectMethod(className, "uint GetIndexSize() const", AS_METHODPR(T, GetIndexSize, () const, unsigned), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "uint get_indexSize() const", AS_METHODPR(T, GetIndexSize, () const, unsigned), AS_CALL_THISCALL);
+    // i32 IndexBuffer::GetIndexSize() const
+    engine->RegisterObjectMethod(className, "int GetIndexSize() const", AS_METHODPR(T, GetIndexSize, () const, i32), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "int get_indexSize() const", AS_METHODPR(T, GetIndexSize, () const, i32), AS_CALL_THISCALL);
 
-    // bool IndexBuffer::GetUsedVertexRange(unsigned start, unsigned count, unsigned& minVertex, unsigned& vertexCount)
-    engine->RegisterObjectMethod(className, "bool GetUsedVertexRange(uint, uint, uint&, uint&)", AS_METHODPR(T, GetUsedVertexRange, (unsigned, unsigned, unsigned&, unsigned&), bool), AS_CALL_THISCALL);
+    // bool IndexBuffer::GetUsedVertexRange(i32 start, i32 count, i32& minVertex, i32& vertexCount)
+    engine->RegisterObjectMethod(className, "bool GetUsedVertexRange(int, int, int&, int&)", AS_METHODPR(T, GetUsedVertexRange, (i32, i32, i32&, i32&), bool), AS_CALL_THISCALL);
 
     // bool IndexBuffer::IsDynamic() const
     engine->RegisterObjectMethod(className, "bool IsDynamic() const", AS_METHODPR(T, IsDynamic, () const, bool), AS_CALL_THISCALL);
@@ -10656,8 +10656,8 @@ template <class T> void RegisterMembers_IndexBuffer(asIScriptEngine* engine, con
     engine->RegisterObjectMethod(className, "void SetShadowed(bool)", AS_METHODPR(T, SetShadowed, (bool), void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_shadowed(bool)", AS_METHODPR(T, SetShadowed, (bool), void), AS_CALL_THISCALL);
 
-    // bool IndexBuffer::SetSize(unsigned indexCount, bool largeIndices, bool dynamic = false)
-    engine->RegisterObjectMethod(className, "bool SetSize(uint, bool, bool = false)", AS_METHODPR(T, SetSize, (unsigned, bool, bool), bool), AS_CALL_THISCALL);
+    // bool IndexBuffer::SetSize(i32 indexCount, bool largeIndices, bool dynamic = false)
+    engine->RegisterObjectMethod(className, "bool SetSize(int, bool, bool = false)", AS_METHODPR(T, SetSize, (i32, bool, bool), bool), AS_CALL_THISCALL);
 
     // void IndexBuffer::Unlock()
     engine->RegisterObjectMethod(className, "void Unlock()", AS_METHODPR(T, Unlock, (), void), AS_CALL_THISCALL);

+ 2 - 2
Source/Urho3D/Graphics/Geometry.h

@@ -118,9 +118,9 @@ private:
     /// Number of indices.
     unsigned indexCount_;
     /// First used vertex.
-    unsigned vertexStart_;
+    i32 vertexStart_;
     /// Number of used vertices.
-    unsigned vertexCount_;
+    i32 vertexCount_;
     /// LOD distance.
     float lodDistance_;
     /// Raw vertex data elements.

+ 21 - 15
Source/Urho3D/GraphicsAPI/Direct3D11/D3D11IndexBuffer.cpp

@@ -49,7 +49,7 @@ bool IndexBuffer::SetData_D3D11(const void* data)
     }
 
     if (shadowData_ && data != shadowData_.Get())
-        memcpy(shadowData_.Get(), data, indexCount_ * indexSize_);
+        memcpy(shadowData_.Get(), data, (size_t)indexCount_ * indexSize_);
 
     if (object_.ptr_)
     {
@@ -58,7 +58,7 @@ bool IndexBuffer::SetData_D3D11(const void* data)
             void* hwData = MapBuffer_D3D11(0, indexCount_, true);
             if (hwData)
             {
-                memcpy(hwData, data, indexCount_ * indexSize_);
+                memcpy(hwData, data, (size_t)indexCount_ * indexSize_);
                 UnmapBuffer();
             }
             else
@@ -68,7 +68,7 @@ bool IndexBuffer::SetData_D3D11(const void* data)
         {
             D3D11_BOX destBox;
             destBox.left = 0;
-            destBox.right = indexCount_ * indexSize_;
+            destBox.right = (UINT)indexCount_ * indexSize_;
             destBox.top = 0;
             destBox.bottom = 1;
             destBox.front = 0;
@@ -81,8 +81,10 @@ bool IndexBuffer::SetData_D3D11(const void* data)
     return true;
 }
 
-bool IndexBuffer::SetDataRange_D3D11(const void* data, unsigned start, unsigned count, bool discard)
+bool IndexBuffer::SetDataRange_D3D11(const void* data, i32 start, i32 count, bool discard)
 {
+    assert(start >= 0 && count >= 0);
+
     if (start == 0 && count == indexCount_)
         return SetData_D3D11(data);
 
@@ -107,8 +109,9 @@ bool IndexBuffer::SetDataRange_D3D11(const void* data, unsigned start, unsigned
     if (!count)
         return true;
 
-    if (shadowData_ && shadowData_.Get() + start * indexSize_ != data)
-        memcpy(shadowData_.Get() + start * indexSize_, data, count * indexSize_);
+    u8* dst = shadowData_.Get() + (intptr_t)start * indexSize_;
+    if (shadowData_ && dst != data)
+        memcpy(dst, data, (size_t)count * indexSize_);
 
     if (object_.ptr_)
     {
@@ -117,7 +120,7 @@ bool IndexBuffer::SetDataRange_D3D11(const void* data, unsigned start, unsigned
             void* hwData = MapBuffer_D3D11(start, count, discard);
             if (hwData)
             {
-                memcpy(hwData, data, count * indexSize_);
+                memcpy(hwData, data, (size_t)count * indexSize_);
                 UnmapBuffer();
             }
             else
@@ -126,8 +129,8 @@ bool IndexBuffer::SetDataRange_D3D11(const void* data, unsigned start, unsigned
         else
         {
             D3D11_BOX destBox;
-            destBox.left = start * indexSize_;
-            destBox.right = destBox.left + count * indexSize_;
+            destBox.left = (UINT)start * indexSize_;
+            destBox.right = destBox.left + (UINT)count * indexSize_;
             destBox.top = 0;
             destBox.bottom = 1;
             destBox.front = 0;
@@ -140,8 +143,10 @@ bool IndexBuffer::SetDataRange_D3D11(const void* data, unsigned start, unsigned
     return true;
 }
 
-void* IndexBuffer::Lock_D3D11(unsigned start, unsigned count, bool discard)
+void* IndexBuffer::Lock_D3D11(i32 start, i32 count, bool discard)
 {
+    assert(start >= 0 && count >= 0);
+
     if (lockState_ != LOCK_NONE)
     {
         URHO3D_LOGERROR("Index buffer already locked");
@@ -172,7 +177,7 @@ void* IndexBuffer::Lock_D3D11(unsigned start, unsigned count, bool discard)
     else if (shadowData_)
     {
         lockState_ = LOCK_SHADOW;
-        return shadowData_.Get() + start * indexSize_;
+        return shadowData_.Get() + (intptr_t)start * indexSize_;
     }
     else if (graphics_)
     {
@@ -193,7 +198,7 @@ void IndexBuffer::Unlock_D3D11()
         break;
 
     case LOCK_SHADOW:
-        SetDataRange_D3D11(shadowData_.Get() + lockStart_ * indexSize_, lockStart_, lockCount_);
+        SetDataRange_D3D11(shadowData_.Get() + (intptr_t)lockStart_ * indexSize_, lockStart_, lockCount_);
         lockState_ = LOCK_NONE;
         break;
 
@@ -223,7 +228,7 @@ bool IndexBuffer::Create_D3D11()
         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 = (UINT)(indexCount_ * indexSize_);
+        bufferDesc.ByteWidth = (UINT)indexCount_ * indexSize_;
 
         HRESULT hr = graphics_->GetImpl_D3D11()->GetDevice()->CreateBuffer(&bufferDesc, nullptr, (ID3D11Buffer**)&object_.ptr_);
         if (FAILED(hr))
@@ -245,8 +250,9 @@ bool IndexBuffer::UpdateToGPU_D3D11()
         return false;
 }
 
-void* IndexBuffer::MapBuffer_D3D11(unsigned start, unsigned count, bool discard)
+void* IndexBuffer::MapBuffer_D3D11(i32 start, i32 count, bool discard)
 {
+    assert(start >= 0 && count >= 0);
     void* hwData = nullptr;
 
     if (object_.ptr_)
@@ -277,4 +283,4 @@ void IndexBuffer::UnmapBuffer_D3D11()
     }
 }
 
-}
+} // namespace Urho3D

+ 23 - 17
Source/Urho3D/GraphicsAPI/Direct3D9/D3D9IndexBuffer.cpp

@@ -60,7 +60,7 @@ bool IndexBuffer::SetData_D3D9(const void* data)
     }
 
     if (shadowData_ && data != shadowData_.Get())
-        memcpy(shadowData_.Get(), data, indexCount_ * indexSize_);
+        memcpy(shadowData_.Get(), data, (size_t)indexCount_ * indexSize_);
 
     if (object_.ptr_)
     {
@@ -74,7 +74,7 @@ bool IndexBuffer::SetData_D3D9(const void* data)
         void* hwData = MapBuffer_D3D9(0, indexCount_, true);
         if (hwData)
         {
-            memcpy(hwData, data, indexCount_ * indexSize_);
+            memcpy(hwData, data, (size_t)indexCount_ * indexSize_);
             UnmapBuffer();
         }
         else
@@ -85,8 +85,10 @@ bool IndexBuffer::SetData_D3D9(const void* data)
     return true;
 }
 
-bool IndexBuffer::SetDataRange_D3D9(const void* data, unsigned start, unsigned count, bool discard)
+bool IndexBuffer::SetDataRange_D3D9(const void* data, i32 start, i32 count, bool discard)
 {
+    assert(start >= 0 && count >= 0);
+
     if (start == 0 && count == indexCount_)
         return SetData_D3D9(data);
 
@@ -111,8 +113,9 @@ bool IndexBuffer::SetDataRange_D3D9(const void* data, unsigned start, unsigned c
     if (!count)
         return true;
 
-    if (shadowData_ && shadowData_.Get() + start * indexSize_ != data)
-        memcpy(shadowData_.Get() + start * indexSize_, data, count * indexSize_);
+    u8* dst = shadowData_.Get() + (intptr_t)start * indexSize_;
+    if (shadowData_ && dst != data)
+        memcpy(dst, data, (size_t)count * indexSize_);
 
     if (object_.ptr_)
     {
@@ -126,7 +129,7 @@ bool IndexBuffer::SetDataRange_D3D9(const void* data, unsigned start, unsigned c
         void* hwData = MapBuffer_D3D9(start, count, discard);
         if (hwData)
         {
-            memcpy(hwData, data, count * indexSize_);
+            memcpy(hwData, data, (size_t)count * indexSize_);
             UnmapBuffer();
         }
         else
@@ -136,8 +139,10 @@ bool IndexBuffer::SetDataRange_D3D9(const void* data, unsigned start, unsigned c
     return true;
 }
 
-void* IndexBuffer::Lock_D3D9(unsigned start, unsigned count, bool discard)
+void* IndexBuffer::Lock_D3D9(i32 start, i32 count, bool discard)
 {
+    assert(start >= 0 && count >= 0);
+
     if (lockState_ != LOCK_NONE)
     {
         URHO3D_LOGERROR("Index buffer already locked");
@@ -168,7 +173,7 @@ void* IndexBuffer::Lock_D3D9(unsigned start, unsigned count, bool discard)
     else if (shadowData_)
     {
         lockState_ = LOCK_SHADOW;
-        return shadowData_.Get() + start * indexSize_;
+        return shadowData_.Get() + (intptr_t)start * indexSize_;
     }
     else if (graphics_)
     {
@@ -189,7 +194,7 @@ void IndexBuffer::Unlock_D3D9()
         break;
 
     case LOCK_SHADOW:
-        SetDataRange_D3D9(shadowData_.Get() + lockStart_ * indexSize_, lockStart_, lockCount_);
+        SetDataRange_D3D9(shadowData_.Get() + (intptr_t)lockStart_ * indexSize_, lockStart_, lockCount_);
         lockState_ = LOCK_NONE;
         break;
 
@@ -220,15 +225,15 @@ bool IndexBuffer::Create_D3D9()
             return true;
         }
 
-        unsigned pool = dynamic_ ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
-        unsigned d3dUsage = dynamic_ ? D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY : 0;
+        D3DPOOL pool = dynamic_ ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
+        DWORD d3dUsage = dynamic_ ? D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY : 0;
 
         IDirect3DDevice9* device = graphics_->GetImpl_D3D9()->GetDevice();
         HRESULT hr = device->CreateIndexBuffer(
-            indexCount_ * indexSize_,
+            (UINT)indexCount_ * indexSize_,
             d3dUsage,
-            indexSize_ == sizeof(unsigned) ? D3DFMT_INDEX32 : D3DFMT_INDEX16,
-            (D3DPOOL)pool,
+            indexSize_ == sizeof(u32) ? D3DFMT_INDEX32 : D3DFMT_INDEX16,
+            pool,
             (IDirect3DIndexBuffer9**)&object_,
             nullptr);
         if (FAILED(hr))
@@ -250,8 +255,9 @@ bool IndexBuffer::UpdateToGPU_D3D9()
         return false;
 }
 
-void* IndexBuffer::MapBuffer_D3D9(unsigned start, unsigned count, bool discard)
+void* IndexBuffer::MapBuffer_D3D9(i32 start, i32 count, bool discard)
 {
+    assert(start >= 0 && count >= 0);
     void* hwData = nullptr;
 
     if (object_.ptr_)
@@ -261,7 +267,7 @@ void* IndexBuffer::MapBuffer_D3D9(unsigned start, unsigned count, bool discard)
         if (discard && dynamic_)
             flags = D3DLOCK_DISCARD;
 
-        HRESULT hr = ((IDirect3DIndexBuffer9*)object_.ptr_)->Lock(start * indexSize_, count * indexSize_, &hwData, flags);
+        HRESULT hr = ((IDirect3DIndexBuffer9*)object_.ptr_)->Lock((UINT)start * indexSize_, (UINT)count * indexSize_, &hwData, flags);
         if (FAILED(hr))
             URHO3D_LOGD3DERROR("Could not lock index buffer", hr);
         else
@@ -280,4 +286,4 @@ void IndexBuffer::UnmapBuffer_D3D9()
     }
 }
 
-}
+} // namespace Urho3D

+ 35 - 23
Source/Urho3D/GraphicsAPI/IndexBuffer.cpp

@@ -46,7 +46,7 @@ void IndexBuffer::SetShadowed(bool enable)
     if (enable != shadowed_)
     {
         if (enable && indexCount_ && indexSize_)
-            shadowData_ = new unsigned char[indexCount_ * indexSize_];
+            shadowData_ = new u8[(size_t)indexCount_ * indexSize_];
         else
             shadowData_.Reset();
 
@@ -54,24 +54,27 @@ void IndexBuffer::SetShadowed(bool enable)
     }
 }
 
-bool IndexBuffer::SetSize(unsigned indexCount, bool largeIndices, bool dynamic)
+bool IndexBuffer::SetSize(i32 indexCount, bool largeIndices, bool dynamic)
 {
+    assert(indexCount >= 0);
     Unlock();
 
     indexCount_ = indexCount;
-    indexSize_ = (unsigned)(largeIndices ? sizeof(unsigned) : sizeof(unsigned short));
+    indexSize_ = (i32)(largeIndices ? sizeof(u32) : sizeof(u16));
     dynamic_ = dynamic;
 
     if (shadowed_ && indexCount_ && indexSize_)
-        shadowData_ = new unsigned char[indexCount_ * indexSize_];
+        shadowData_ = new u8[(size_t)indexCount_ * indexSize_];
     else
         shadowData_.Reset();
 
     return Create();
 }
 
-bool IndexBuffer::GetUsedVertexRange(unsigned start, unsigned count, unsigned& minVertex, unsigned& vertexCount)
+bool IndexBuffer::GetUsedVertexRange(i32 start, i32 count, i32& minVertex, i32& vertexCount)
 {
+    assert(start >= 0 && count >= 0);
+
     if (!shadowData_)
     {
         URHO3D_LOGERROR("Used vertex range can only be queried from an index buffer with shadow data");
@@ -84,31 +87,37 @@ bool IndexBuffer::GetUsedVertexRange(unsigned start, unsigned count, unsigned& m
         return false;
     }
 
-    minVertex = M_MAX_UNSIGNED;
-    unsigned maxVertex = 0;
+    minVertex = M_MAX_INT;
+    i32 maxVertex = 0;
 
-    if (indexSize_ == sizeof(unsigned))
+    if (indexSize_ == sizeof(u32))
     {
-        unsigned* indices = ((unsigned*)shadowData_.Get()) + start;
+        u32* indices = (u32*)shadowData_.Get() + start;
 
-        for (unsigned i = 0; i < count; ++i)
+        for (i32 i = 0; i < count; ++i)
         {
-            if (indices[i] < minVertex)
-                minVertex = indices[i];
-            if (indices[i] > maxVertex)
-                maxVertex = indices[i];
+            i32 index = (i32)indices[i];
+
+            if (index < minVertex)
+                minVertex = index;
+
+            if (index > maxVertex)
+                maxVertex = index;
         }
     }
     else
     {
-        unsigned short* indices = ((unsigned short*)shadowData_.Get()) + start;
+        u16* indices = (u16*)shadowData_.Get() + start;
 
-        for (unsigned i = 0; i < count; ++i)
+        for (i32 i = 0; i < count; ++i)
         {
-            if (indices[i] < minVertex)
-                minVertex = indices[i];
-            if (indices[i] > maxVertex)
-                maxVertex = indices[i];
+            i32 index = (i32)indices[i];
+
+            if (index < minVertex)
+                minVertex = index;
+
+            if (index > maxVertex)
+                maxVertex = index;
         }
     }
 
@@ -198,8 +207,9 @@ bool IndexBuffer::SetData(const void* data)
     return {}; // Prevent warning
 }
 
-bool IndexBuffer::SetDataRange(const void* data, unsigned start, unsigned count, bool discard)
+bool IndexBuffer::SetDataRange(const void* data, i32 start, i32 count, bool discard)
 {
+    assert(start >= 0 && count >= 0);
     GAPI gapi = Graphics::GetGAPI();
 
 #ifdef URHO3D_OPENGL
@@ -220,8 +230,9 @@ bool IndexBuffer::SetDataRange(const void* data, unsigned start, unsigned count,
     return {}; // Prevent warning
 }
 
-void* IndexBuffer::Lock(unsigned start, unsigned count, bool discard)
+void* IndexBuffer::Lock(i32 start, i32 count, bool discard)
 {
+    assert(start >= 0 && count >= 0);
     GAPI gapi = Graphics::GetGAPI();
 
 #ifdef URHO3D_OPENGL
@@ -306,8 +317,9 @@ bool IndexBuffer::UpdateToGPU()
     return {}; // Prevent warning
 }
 
-void* IndexBuffer::MapBuffer(unsigned start, unsigned count, bool discard)
+void* IndexBuffer::MapBuffer(i32 start, i32 count, bool discard)
 {
+    assert(start >= 0 && count >= 0);
     GAPI gapi = Graphics::GetGAPI();
 
 #ifdef URHO3D_OPENGL

+ 23 - 23
Source/Urho3D/GraphicsAPI/IndexBuffer.h

@@ -33,13 +33,13 @@ public:
     /// @property
     void SetShadowed(bool enable);
     /// Set size and vertex elements and dynamic mode. Previous data will be lost.
-    bool SetSize(unsigned indexCount, bool largeIndices, bool dynamic = false);
+    bool SetSize(i32 indexCount, bool largeIndices, bool dynamic = false);
     /// Set all data in the buffer.
     bool SetData(const void* data);
     /// Set a data range in the buffer. Optionally discard data outside the range.
-    bool SetDataRange(const void* data, unsigned start, unsigned count, bool discard = false);
+    bool SetDataRange(const void* data, i32 start, i32 count, bool discard = false);
     /// Lock the buffer for write-only editing. Return data pointer if successful. Optionally discard data outside the range.
-    void* Lock(unsigned start, unsigned count, bool discard = false);
+    void* Lock(i32 start, i32 count, bool discard = false);
     /// Unlock the buffer and apply changes to the GPU buffer.
     void Unlock();
 
@@ -56,20 +56,20 @@ public:
 
     /// Return number of indices.
     /// @property
-    unsigned GetIndexCount() const { return indexCount_; }
+    i32 GetIndexCount() const { return indexCount_; }
 
     /// Return index size in bytes.
     /// @property
-    unsigned GetIndexSize() const { return indexSize_; }
+    i32 GetIndexSize() const { return indexSize_; }
 
     /// Return used vertex range from index range.
-    bool GetUsedVertexRange(unsigned start, unsigned count, unsigned& minVertex, unsigned& vertexCount);
+    bool GetUsedVertexRange(i32 start, i32 count, i32& minVertex, i32& vertexCount);
 
     /// Return CPU memory shadow data.
-    unsigned char* GetShadowData() const { return shadowData_.Get(); }
+    u8* GetShadowData() const { return shadowData_.Get(); }
 
     /// Return shared array pointer to the CPU memory shadow data.
-    SharedArrayPtr<unsigned char> GetShadowDataShared() const { return shadowData_; }
+    SharedArrayPtr<u8> GetShadowDataShared() const { return shadowData_; }
 
 private:
     /// Create buffer.
@@ -77,7 +77,7 @@ private:
     /// Update the shadow data to the GPU buffer.
     bool UpdateToGPU();
     /// Map the GPU buffer into CPU memory. Not used on OpenGL.
-    void* MapBuffer(unsigned start, unsigned count, bool discard);
+    void* MapBuffer(i32 start, i32 count, bool discard);
     /// Unmap the GPU buffer. Not used on OpenGL.
     void UnmapBuffer();
 
@@ -86,12 +86,12 @@ private:
     void OnDeviceReset_OGL();
     void Release_OGL();
     bool SetData_OGL(const void* data);
-    bool SetDataRange_OGL(const void* data, unsigned start, unsigned count, bool discard = false);
-    void* Lock_OGL(unsigned start, unsigned count, bool discard);
+    bool SetDataRange_OGL(const void* data, i32 start, i32 count, bool discard = false);
+    void* Lock_OGL(i32 start, i32 count, bool discard);
     void Unlock_OGL();
     bool Create_OGL();
     bool UpdateToGPU_OGL();
-    void* MapBuffer_OGL(unsigned start, unsigned count, bool discard);
+    void* MapBuffer_OGL(i32 start, i32 count, bool discard);
     void UnmapBuffer_OGL();
 #endif // def URHO3D_OPENGL
 
@@ -100,12 +100,12 @@ private:
     void OnDeviceReset_D3D9();
     void Release_D3D9();
     bool SetData_D3D9(const void* data);
-    bool SetDataRange_D3D9(const void* data, unsigned start, unsigned count, bool discard = false);
-    void* Lock_D3D9(unsigned start, unsigned count, bool discard);
+    bool SetDataRange_D3D9(const void* data, i32 start, i32 count, bool discard = false);
+    void* Lock_D3D9(i32 start, i32 count, bool discard);
     void Unlock_D3D9();
     bool Create_D3D9();
     bool UpdateToGPU_D3D9();
-    void* MapBuffer_D3D9(unsigned start, unsigned count, bool discard);
+    void* MapBuffer_D3D9(i32 start, i32 count, bool discard);
     void UnmapBuffer_D3D9();
 #endif // def URHO3D_D3D9
 
@@ -114,27 +114,27 @@ private:
     void OnDeviceReset_D3D11();
     void Release_D3D11();
     bool SetData_D3D11(const void* data);
-    bool SetDataRange_D3D11(const void* data, unsigned start, unsigned count, bool discard = false);
-    void* Lock_D3D11(unsigned start, unsigned count, bool discard);
+    bool SetDataRange_D3D11(const void* data, i32 start, i32 count, bool discard = false);
+    void* Lock_D3D11(i32 start, i32 count, bool discard);
     void Unlock_D3D11();
     bool Create_D3D11();
     bool UpdateToGPU_D3D11();
-    void* MapBuffer_D3D11(unsigned start, unsigned count, bool discard);
+    void* MapBuffer_D3D11(i32 start, i32 count, bool discard);
     void UnmapBuffer_D3D11();
 #endif // def URHO3D_D3D11
 
     /// Shadow data.
-    SharedArrayPtr<unsigned char> shadowData_;
+    SharedArrayPtr<u8> shadowData_;
     /// Number of indices.
-    unsigned indexCount_;
+    i32 indexCount_;
     /// Index size.
-    unsigned indexSize_;
+    i32 indexSize_;
     /// Buffer locking state.
     LockState lockState_;
     /// Lock start vertex.
-    unsigned lockStart_;
+    i32 lockStart_;
     /// Lock number of vertices.
-    unsigned lockCount_;
+    i32 lockCount_;
     /// Scratch buffer for fallback locking.
     void* lockScratchData_;
     /// Dynamic flag.

+ 19 - 13
Source/Urho3D/GraphicsAPI/OpenGL/OGLIndexBuffer.cpp

@@ -71,14 +71,14 @@ bool IndexBuffer::SetData_OGL(const void* data)
     }
 
     if (shadowData_ && data != shadowData_.Get())
-        memcpy(shadowData_.Get(), data, indexCount_ * (size_t)indexSize_);
+        memcpy(shadowData_.Get(), data, (size_t)indexCount_ * indexSize_);
 
     if (object_.name_)
     {
         if (!graphics_->IsDeviceLost())
         {
             graphics_->SetIndexBuffer(this);
-            glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount_ * (size_t)indexSize_, data, dynamic_ ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
+            glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)indexCount_ * indexSize_, data, dynamic_ ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
         }
         else
         {
@@ -91,8 +91,10 @@ bool IndexBuffer::SetData_OGL(const void* data)
     return true;
 }
 
-bool IndexBuffer::SetDataRange_OGL(const void* data, unsigned start, unsigned count, bool discard)
+bool IndexBuffer::SetDataRange_OGL(const void* data, i32 start, i32 count, bool discard)
 {
+    assert(start >= 0 && count >= 0);
+
     if (start == 0 && count == indexCount_)
         return SetData_OGL(data);
 
@@ -117,8 +119,9 @@ bool IndexBuffer::SetDataRange_OGL(const void* data, unsigned start, unsigned co
     if (!count)
         return true;
 
-    if (shadowData_ && shadowData_.Get() + start * indexSize_ != data)
-        memcpy(shadowData_.Get() + start * indexSize_, data, count * (size_t)indexSize_);
+    u8* dst = shadowData_.Get() + (intptr_t)start * indexSize_;
+    if (shadowData_ && dst != data)
+        memcpy(dst, data, (size_t)count * indexSize_);
 
     if (object_.name_)
     {
@@ -126,9 +129,9 @@ bool IndexBuffer::SetDataRange_OGL(const void* data, unsigned start, unsigned co
         {
             graphics_->SetIndexBuffer(this);
             if (!discard || start != 0)
-                glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, start * (size_t)indexSize_, count * indexSize_, data);
+                glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, (GLintptr)start * indexSize_, (GLsizeiptr)count * indexSize_, data);
             else
-                glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * (size_t)indexSize_, data, dynamic_ ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
+                glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)count * indexSize_, data, dynamic_ ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
         }
         else
         {
@@ -140,8 +143,10 @@ bool IndexBuffer::SetDataRange_OGL(const void* data, unsigned start, unsigned co
     return true;
 }
 
-void* IndexBuffer::Lock_OGL(unsigned start, unsigned count, bool discard)
+void* IndexBuffer::Lock_OGL(i32 start, i32 count, bool discard)
 {
+    assert(start >= 0 && count >= 0);
+
     if (lockState_ != LOCK_NONE)
     {
         URHO3D_LOGERROR("Index buffer already locked");
@@ -170,7 +175,7 @@ void* IndexBuffer::Lock_OGL(unsigned start, unsigned count, bool discard)
     if (shadowData_)
     {
         lockState_ = LOCK_SHADOW;
-        return shadowData_.Get() + start * indexSize_;
+        return shadowData_.Get() + (intptr_t)start * indexSize_;
     }
     else if (graphics_)
     {
@@ -187,7 +192,7 @@ void IndexBuffer::Unlock_OGL()
     switch (lockState_)
     {
     case LOCK_SHADOW:
-        SetDataRange_OGL(shadowData_.Get() + lockStart_ * indexSize_, lockStart_, lockCount_, discardLock_);
+        SetDataRange_OGL(shadowData_.Get() + (intptr_t)lockStart_ * indexSize_, lockStart_, lockCount_, discardLock_);
         lockState_ = LOCK_NONE;
         break;
 
@@ -222,6 +227,7 @@ bool IndexBuffer::Create_OGL()
 
         if (!object_.name_)
             glGenBuffers(1, &object_.name_);
+
         if (!object_.name_)
         {
             URHO3D_LOGERROR("Failed to create index buffer");
@@ -229,7 +235,7 @@ bool IndexBuffer::Create_OGL()
         }
 
         graphics_->SetIndexBuffer(this);
-        glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount_ * (size_t)indexSize_, nullptr, dynamic_ ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
+        glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)indexCount_ * indexSize_, nullptr, dynamic_ ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
     }
 
     return true;
@@ -243,7 +249,7 @@ bool IndexBuffer::UpdateToGPU_OGL()
         return false;
 }
 
-void* IndexBuffer::MapBuffer_OGL(unsigned start, unsigned count, bool discard)
+void* IndexBuffer::MapBuffer_OGL(i32 start, i32 count, bool discard)
 {
     // Never called on OpenGL
     return nullptr;
@@ -254,4 +260,4 @@ void IndexBuffer::UnmapBuffer_OGL()
     // Never called on OpenGL
 }
 
-}
+} // namespace Urho3D