Browse Source

Batch: unsigned to signed

1vanK 3 years ago
parent
commit
298da67af3

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

@@ -338,8 +338,8 @@ template <class T> void RegisterMembers_Batch(asIScriptEngine* engine, const cha
     // bool Batch::isBase_
     // bool Batch::isBase_
     engine->RegisterObjectProperty(className, "bool isBase", offsetof(T, isBase_));
     engine->RegisterObjectProperty(className, "bool isBase", offsetof(T, isBase_));
 
 
-    // unsigned Batch::numWorldTransforms_
-    engine->RegisterObjectProperty(className, "uint numWorldTransforms", offsetof(T, numWorldTransforms_));
+    // i32 Batch::numWorldTransforms_
+    engine->RegisterObjectProperty(className, "int numWorldTransforms", offsetof(T, numWorldTransforms_));
 
 
     // GeometryType Batch::geometryType_
     // GeometryType Batch::geometryType_
     engine->RegisterObjectProperty(className, "GeometryType geometryType", offsetof(T, geometryType_));
     engine->RegisterObjectProperty(className, "GeometryType geometryType", offsetof(T, geometryType_));
@@ -383,7 +383,7 @@ template <class T> void RegisterMembers_BatchGroupKey(asIScriptEngine* engine, c
 // struct BatchQueue | File: ../Graphics/Batch.h
 // struct BatchQueue | File: ../Graphics/Batch.h
 template <class T> void RegisterMembers_BatchQueue(asIScriptEngine* engine, const char* className)
 template <class T> void RegisterMembers_BatchQueue(asIScriptEngine* engine, const char* className)
 {
 {
-    // void BatchQueue::SetInstancingData(void* lockedData, unsigned stride, unsigned& freeIndex)
+    // void BatchQueue::SetInstancingData(void* lockedData, i32 stride, i32& freeIndex)
     // Error: type "void*" can not automatically bind
     // Error: type "void*" can not automatically bind
     // void BatchQueue::SortFrontToBack2Pass(Vector<Batch*>& batches)
     // void BatchQueue::SortFrontToBack2Pass(Vector<Batch*>& batches)
     // Error: type "Vector<Batch*>&" can not automatically bind
     // Error: type "Vector<Batch*>&" can not automatically bind
@@ -394,8 +394,8 @@ template <class T> void RegisterMembers_BatchQueue(asIScriptEngine* engine, cons
     // void BatchQueue::Draw(View* view, Camera* camera, bool markToStencil, bool usingLightOptimization, bool allowDepthWrite) const
     // void BatchQueue::Draw(View* view, Camera* camera, bool markToStencil, bool usingLightOptimization, bool allowDepthWrite) const
     engine->RegisterObjectMethod(className, "void Draw(View@+, Camera@+, bool, bool, bool) const", AS_METHODPR(T, Draw, (View*, Camera*, bool, bool, bool) const, void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "void Draw(View@+, Camera@+, bool, bool, bool) const", AS_METHODPR(T, Draw, (View*, Camera*, bool, bool, bool) const, void), AS_CALL_THISCALL);
 
 
-    // unsigned BatchQueue::GetNumInstances() const
-    engine->RegisterObjectMethod(className, "uint GetNumInstances() const", AS_METHODPR(T, GetNumInstances, () const, unsigned), AS_CALL_THISCALL);
+    // i32 BatchQueue::GetNumInstances() const
+    engine->RegisterObjectMethod(className, "int GetNumInstances() const", AS_METHODPR(T, GetNumInstances, () const, i32), AS_CALL_THISCALL);
 
 
     // bool BatchQueue::IsEmpty() const
     // bool BatchQueue::IsEmpty() const
     engine->RegisterObjectMethod(className, "bool IsEmpty() const", AS_METHODPR(T, IsEmpty, () const, bool), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool IsEmpty() const", AS_METHODPR(T, IsEmpty, () const, bool), AS_CALL_THISCALL);
@@ -421,8 +421,8 @@ template <class T> void RegisterMembers_BatchQueue(asIScriptEngine* engine, cons
     // Vector<BatchGroup*> BatchQueue::sortedBatchGroups_
     // Vector<BatchGroup*> BatchQueue::sortedBatchGroups_
     // Error: type "Vector<BatchGroup*>" can not automatically bind
     // Error: type "Vector<BatchGroup*>" can not automatically bind
 
 
-    // unsigned BatchQueue::maxSortedInstances_
-    engine->RegisterObjectProperty(className, "uint maxSortedInstances", offsetof(T, maxSortedInstances_));
+    // i32 BatchQueue::maxSortedInstances_
+    engine->RegisterObjectProperty(className, "int maxSortedInstances", offsetof(T, maxSortedInstances_));
 
 
     // bool BatchQueue::hasExtraDefines_
     // bool BatchQueue::hasExtraDefines_
     engine->RegisterObjectProperty(className, "bool hasExtraDefines", offsetof(T, hasExtraDefines_));
     engine->RegisterObjectProperty(className, "bool hasExtraDefines", offsetof(T, hasExtraDefines_));
@@ -7786,7 +7786,7 @@ template <class T> void RegisterMembers_BatchGroup(asIScriptEngine* engine, cons
 {
 {
     RegisterMembers_Batch<T>(engine, className);
     RegisterMembers_Batch<T>(engine, className);
 
 
-    // void BatchGroup::SetInstancingData(void* lockedData, unsigned stride, unsigned& freeIndex)
+    // void BatchGroup::SetInstancingData(void* lockedData, i32 stride, i32& freeIndex)
     // Error: type "void*" can not automatically bind
     // Error: type "void*" can not automatically bind
 
 
     // void BatchGroup::AddTransforms(const Batch& batch)
     // void BatchGroup::AddTransforms(const Batch& batch)
@@ -7795,8 +7795,8 @@ template <class T> void RegisterMembers_BatchGroup(asIScriptEngine* engine, cons
     // Vector<InstanceData> BatchGroup::instances_
     // Vector<InstanceData> BatchGroup::instances_
     // Error: type "Vector<InstanceData>" can not automatically bind
     // Error: type "Vector<InstanceData>" can not automatically bind
 
 
-    // unsigned BatchGroup::startIndex_
-    engine->RegisterObjectProperty(className, "uint startIndex", offsetof(T, startIndex_));
+    // i32 BatchGroup::startIndex_
+    engine->RegisterObjectProperty(className, "int startIndex", offsetof(T, startIndex_));
 
 
     #ifdef REGISTER_MEMBERS_MANUAL_PART_BatchGroup
     #ifdef REGISTER_MEMBERS_MANUAL_PART_BatchGroup
         REGISTER_MEMBERS_MANUAL_PART_BatchGroup();
         REGISTER_MEMBERS_MANUAL_PART_BatchGroup();

+ 19 - 14
Source/Urho3D/Graphics/Batch.cpp

@@ -61,8 +61,10 @@ inline bool CompareBatchGroupOrder(BatchGroup* lhs, BatchGroup* rhs)
     return lhs->renderOrder_ < rhs->renderOrder_;
     return lhs->renderOrder_ < rhs->renderOrder_;
 }
 }
 
 
-void CalculateShadowMatrix(Matrix4& dest, LightBatchQueue* queue, unsigned split, Renderer* renderer)
+void CalculateShadowMatrix(Matrix4& dest, LightBatchQueue* queue, i32 split, Renderer* renderer)
 {
 {
+    assert(split >= 0);
+
     Camera* shadowCamera = queue->shadowSplits_[split].shadowCamera_;
     Camera* shadowCamera = queue->shadowSplits_[split].shadowCamera_;
     const IntRect& viewport = queue->shadowSplits_[split].shadowViewport_;
     const IntRect& viewport = queue->shadowSplits_[split].shadowViewport_;
 
 
@@ -213,10 +215,10 @@ void Batch::Prepare(View* view, Camera* camera, bool setModelTransform, bool all
         view->SetGlobalShaderParameters();
         view->SetGlobalShaderParameters();
 
 
     // Set camera & viewport shader parameters
     // Set camera & viewport shader parameters
-    auto cameraHash = (unsigned)(size_t)camera;
+    hash32 cameraHash = (hash32)(size_t)camera;
     IntRect viewport = graphics->GetViewport();
     IntRect viewport = graphics->GetViewport();
     IntVector2 viewSize = IntVector2(viewport.Width(), viewport.Height());
     IntVector2 viewSize = IntVector2(viewport.Width(), viewport.Height());
-    auto viewportHash = (unsigned)viewSize.x_ | (unsigned)viewSize.y_ << 16u;
+    hash32 viewportHash = (hash32)viewSize.x_ | (hash32)viewSize.y_ << 16u;
     if (graphics->NeedParameterUpdate(SP_CAMERA, reinterpret_cast<const void*>(cameraHash + viewportHash)))
     if (graphics->NeedParameterUpdate(SP_CAMERA, reinterpret_cast<const void*>(cameraHash + viewportHash)))
     {
     {
         view->SetCameraShaderParameters(camera);
         view->SetCameraShaderParameters(camera);
@@ -249,7 +251,7 @@ void Batch::Prepare(View* view, Camera* camera, bool setModelTransform, bool all
     BlendMode blend = graphics->GetBlendMode();
     BlendMode blend = graphics->GetBlendMode();
     // If the pass is additive, override fog color to black so that shaders do not need a separate additive path
     // If the pass is additive, override fog color to black so that shaders do not need a separate additive path
     bool overrideFogColorToBlack = blend == BLEND_ADD || blend == BLEND_ADDALPHA;
     bool overrideFogColorToBlack = blend == BLEND_ADD || blend == BLEND_ADDALPHA;
-    auto zoneHash = (unsigned)(size_t)zone_;
+    hash32 zoneHash = (hash32)(size_t)zone_;
     if (overrideFogColorToBlack)
     if (overrideFogColorToBlack)
         zoneHash += 0x80000000;
         zoneHash += 0x80000000;
     if (zone_ && graphics->NeedParameterUpdate(SP_ZONE, reinterpret_cast<const void*>(zoneHash)))
     if (zone_ && graphics->NeedParameterUpdate(SP_ZONE, reinterpret_cast<const void*>(zoneHash)))
@@ -310,9 +312,9 @@ void Batch::Prepare(View* view, Camera* camera, bool setModelTransform, bool all
                 case LIGHT_DIRECTIONAL:
                 case LIGHT_DIRECTIONAL:
                     {
                     {
                         Matrix4 shadowMatrices[MAX_CASCADE_SPLITS];
                         Matrix4 shadowMatrices[MAX_CASCADE_SPLITS];
-                        unsigned numSplits = Min(MAX_CASCADE_SPLITS, lightQueue_->shadowSplits_.Size());
+                        i32 numSplits = Min(MAX_CASCADE_SPLITS, lightQueue_->shadowSplits_.Size());
 
 
-                        for (unsigned i = 0; i < numSplits; ++i)
+                        for (i32 i = 0; i < numSplits; ++i)
                             CalculateShadowMatrix(shadowMatrices[i], lightQueue_, i, renderer);
                             CalculateShadowMatrix(shadowMatrices[i], lightQueue_, i, renderer);
 
 
                         graphics->SetShaderParameter(VSP_LIGHTMATRICES, shadowMatrices[0].Data(), 16 * numSplits);
                         graphics->SetShaderParameter(VSP_LIGHTMATRICES, shadowMatrices[0].Data(), 16 * numSplits);
@@ -369,9 +371,9 @@ void Batch::Prepare(View* view, Camera* camera, bool setModelTransform, bool all
                 case LIGHT_DIRECTIONAL:
                 case LIGHT_DIRECTIONAL:
                     {
                     {
                         Matrix4 shadowMatrices[MAX_CASCADE_SPLITS];
                         Matrix4 shadowMatrices[MAX_CASCADE_SPLITS];
-                        unsigned numSplits = Min(MAX_CASCADE_SPLITS, lightQueue_->shadowSplits_.Size());
+                        i32 numSplits = Min(MAX_CASCADE_SPLITS, lightQueue_->shadowSplits_.Size());
 
 
-                        for (unsigned i = 0; i < numSplits; ++i)
+                        for (i32 i = 0; i < numSplits; ++i)
                             CalculateShadowMatrix(shadowMatrices[i], lightQueue_, i, renderer);
                             CalculateShadowMatrix(shadowMatrices[i], lightQueue_, i, renderer);
 
 
                         graphics->SetShaderParameter(PSP_LIGHTMATRICES, shadowMatrices[0].Data(), 16 * numSplits);
                         graphics->SetShaderParameter(PSP_LIGHTMATRICES, shadowMatrices[0].Data(), 16 * numSplits);
@@ -631,8 +633,10 @@ void Batch::Draw(View* view, Camera* camera, bool allowDepthWrite) const
     }
     }
 }
 }
 
 
-void BatchGroup::SetInstancingData(void* lockedData, unsigned stride, unsigned& freeIndex)
+void BatchGroup::SetInstancingData(void* lockedData, i32 stride, i32& freeIndex)
 {
 {
+    assert(stride >= 0);
+
     // Do not use up buffer space if not going to draw as instanced
     // Do not use up buffer space if not going to draw as instanced
     if (geometryType_ != GEOM_INSTANCED)
     if (geometryType_ != GEOM_INSTANCED)
         return;
         return;
@@ -662,7 +666,7 @@ void BatchGroup::Draw(View* view, Camera* camera, bool allowDepthWrite) const
     {
     {
         // Draw as individual objects if instancing not supported or could not fill the instancing buffer
         // Draw as individual objects if instancing not supported or could not fill the instancing buffer
         VertexBuffer* instanceBuffer = renderer->GetInstancingBuffer();
         VertexBuffer* instanceBuffer = renderer->GetInstancingBuffer();
-        if (!instanceBuffer || geometryType_ != GEOM_INSTANCED || startIndex_ == M_MAX_UNSIGNED)
+        if (!instanceBuffer || geometryType_ != GEOM_INSTANCED || startIndex_ == NINDEX)
         {
         {
             Batch::Prepare(view, camera, false, allowDepthWrite);
             Batch::Prepare(view, camera, false, allowDepthWrite);
 
 
@@ -710,7 +714,7 @@ void BatchQueue::Clear(int maxSortedInstances)
     batches_.Clear();
     batches_.Clear();
     sortedBatches_.Clear();
     sortedBatches_.Clear();
     batchGroups_.Clear();
     batchGroups_.Clear();
-    maxSortedInstances_ = (unsigned)maxSortedInstances;
+    maxSortedInstances_ = maxSortedInstances;
 }
 }
 
 
 void BatchQueue::SortBackToFront()
 void BatchQueue::SortBackToFront()
@@ -827,8 +831,9 @@ void BatchQueue::SortFrontToBack2Pass(Vector<Batch*>& batches)
 #endif
 #endif
 }
 }
 
 
-void BatchQueue::SetInstancingData(void* lockedData, unsigned stride, unsigned& freeIndex)
+void BatchQueue::SetInstancingData(void* lockedData, i32 stride, i32& freeIndex)
 {
 {
+    assert(stride >= 0);
     for (HashMap<BatchGroupKey, BatchGroup>::Iterator i = batchGroups_.Begin(); i != batchGroups_.End(); ++i)
     for (HashMap<BatchGroupKey, BatchGroup>::Iterator i = batchGroups_.Begin(); i != batchGroups_.End(); ++i)
         i->second_.SetInstancingData(lockedData, stride, freeIndex);
         i->second_.SetInstancingData(lockedData, stride, freeIndex);
 }
 }
@@ -876,9 +881,9 @@ void BatchQueue::Draw(View* view, Camera* camera, bool markToStencil, bool using
     }
     }
 }
 }
 
 
-unsigned BatchQueue::GetNumInstances() const
+i32 BatchQueue::GetNumInstances() const
 {
 {
-    unsigned total = 0;
+    i32 total = 0;
 
 
     for (HashMap<BatchGroupKey, BatchGroup>::ConstIterator i = batchGroups_.Begin(); i != batchGroups_.End(); ++i)
     for (HashMap<BatchGroupKey, BatchGroup>::ConstIterator i = batchGroups_.Begin(); i != batchGroups_.End(); ++i)
     {
     {

+ 10 - 10
Source/Urho3D/Graphics/Batch.h

@@ -72,7 +72,7 @@ struct Batch
     /// World transform(s). For a skinned model, these are the bone transforms.
     /// World transform(s). For a skinned model, these are the bone transforms.
     const Matrix3x4* worldTransform_{};
     const Matrix3x4* worldTransform_{};
     /// Number of world transforms.
     /// Number of world transforms.
-    unsigned numWorldTransforms_{};
+    i32 numWorldTransforms_{};
     /// Per-instance data. If not null, must contain enough data to fill instancing buffer.
     /// Per-instance data. If not null, must contain enough data to fill instancing buffer.
     void* instancingData_{};
     void* instancingData_{};
     /// Zone.
     /// Zone.
@@ -116,14 +116,14 @@ struct BatchGroup : public Batch
 {
 {
     /// Construct with defaults.
     /// Construct with defaults.
     BatchGroup() :
     BatchGroup() :
-        startIndex_(M_MAX_UNSIGNED)
+        startIndex_(NINDEX)
     {
     {
     }
     }
 
 
     /// Construct from a batch.
     /// Construct from a batch.
     explicit BatchGroup(const Batch& batch) :
     explicit BatchGroup(const Batch& batch) :
         Batch(batch),
         Batch(batch),
-        startIndex_(M_MAX_UNSIGNED)
+        startIndex_(NINDEX)
     {
     {
     }
     }
 
 
@@ -137,7 +137,7 @@ struct BatchGroup : public Batch
         newInstance.distance_ = batch.distance_;
         newInstance.distance_ = batch.distance_;
         newInstance.instancingData_ = batch.instancingData_;
         newInstance.instancingData_ = batch.instancingData_;
 
 
-        for (unsigned i = 0; i < batch.numWorldTransforms_; ++i)
+        for (i32 i = 0; i < batch.numWorldTransforms_; ++i)
         {
         {
             newInstance.worldTransform_ = &batch.worldTransform_[i];
             newInstance.worldTransform_ = &batch.worldTransform_[i];
             instances_.Push(newInstance);
             instances_.Push(newInstance);
@@ -145,14 +145,14 @@ struct BatchGroup : public Batch
     }
     }
 
 
     /// Pre-set the instance data. Buffer must be big enough to hold all data.
     /// Pre-set the instance data. Buffer must be big enough to hold all data.
-    void SetInstancingData(void* lockedData, unsigned stride, unsigned& freeIndex);
+    void SetInstancingData(void* lockedData, i32 stride, i32& freeIndex);
     /// Prepare and draw.
     /// Prepare and draw.
     void Draw(View* view, Camera* camera, bool allowDepthWrite) const;
     void Draw(View* view, Camera* camera, bool allowDepthWrite) const;
 
 
     /// Instance data.
     /// Instance data.
     Vector<InstanceData> instances_;
     Vector<InstanceData> instances_;
-    /// Instance stream start index, or M_MAX_UNSIGNED if transforms not pre-set.
-    unsigned startIndex_;
+    /// Instance stream start index, or NINDEX if transforms not pre-set.
+    i32 startIndex_;
 };
 };
 
 
 /// Instanced draw call grouping key.
 /// Instanced draw call grouping key.
@@ -216,11 +216,11 @@ public:
     /// Sort batches front to back while also maintaining state sorting.
     /// Sort batches front to back while also maintaining state sorting.
     void SortFrontToBack2Pass(Vector<Batch*>& batches);
     void SortFrontToBack2Pass(Vector<Batch*>& batches);
     /// Pre-set instance data of all groups. The vertex buffer must be big enough to hold all data.
     /// Pre-set instance data of all groups. The vertex buffer must be big enough to hold all data.
-    void SetInstancingData(void* lockedData, unsigned stride, unsigned& freeIndex);
+    void SetInstancingData(void* lockedData, i32 stride, i32& freeIndex);
     /// Draw.
     /// Draw.
     void Draw(View* view, Camera* camera, bool markToStencil, bool usingLightOptimization, bool allowDepthWrite) const;
     void Draw(View* view, Camera* camera, bool markToStencil, bool usingLightOptimization, bool allowDepthWrite) const;
     /// Return the combined amount of instances.
     /// Return the combined amount of instances.
-    unsigned GetNumInstances() const;
+    i32 GetNumInstances() const;
 
 
     /// Return whether the batch group is empty.
     /// Return whether the batch group is empty.
     bool IsEmpty() const { return batches_.Empty() && batchGroups_.Empty(); }
     bool IsEmpty() const { return batches_.Empty() && batchGroups_.Empty(); }
@@ -241,7 +241,7 @@ public:
     /// Sorted instanced draw calls.
     /// Sorted instanced draw calls.
     Vector<BatchGroup*> sortedBatchGroups_;
     Vector<BatchGroup*> sortedBatchGroups_;
     /// Maximum sorted instances.
     /// Maximum sorted instances.
-    unsigned maxSortedInstances_;
+    i32 maxSortedInstances_;
     /// Whether the pass command contains extra shader defines.
     /// Whether the pass command contains extra shader defines.
     bool hasExtraDefines_;
     bool hasExtraDefines_;
     /// Vertex shader extra defines.
     /// Vertex shader extra defines.

+ 2 - 2
Source/Urho3D/Graphics/View.cpp

@@ -2957,12 +2957,12 @@ void View::PrepareInstancingBuffer()
         return;
         return;
 
 
     VertexBuffer* instancingBuffer = renderer_->GetInstancingBuffer();
     VertexBuffer* instancingBuffer = renderer_->GetInstancingBuffer();
-    unsigned freeIndex = 0;
+    i32 freeIndex = 0;
     void* dest = instancingBuffer->Lock(0, totalInstances, true);
     void* dest = instancingBuffer->Lock(0, totalInstances, true);
     if (!dest)
     if (!dest)
         return;
         return;
 
 
-    const unsigned stride = instancingBuffer->GetVertexSize();
+    const i32 stride = instancingBuffer->GetVertexSize();
     for (HashMap<unsigned, BatchQueue>::Iterator i = batchQueues_.Begin(); i != batchQueues_.End(); ++i)
     for (HashMap<unsigned, BatchQueue>::Iterator i = batchQueues_.Begin(); i != batchQueues_.End(); ++i)
         i->second_.SetInstancingData(dest, stride, freeIndex);
         i->second_.SetInstancingData(dest, stride, freeIndex);