summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/VertexLoaderBase.cpp
diff options
context:
space:
mode:
authordegasus <wickmarkus@web.de>2014-12-18 23:27:10 +0100
committerdegasus <wickmarkus@web.de>2014-12-21 14:13:04 +0100
commit7edf6ec4e4506be5bf575eee5f33287be19ae372 (patch)
treebfa930ec15c3bc210aa6dc2fc6cf352573dbb160 /Source/Core/VideoCommon/VertexLoaderBase.cpp
parent809117102e1c8007345c48aba5eabfec9cff26ee (diff)
VertexLoader: Add a test loader which compares two vertex loaders
Diffstat (limited to 'Source/Core/VideoCommon/VertexLoaderBase.cpp')
-rw-r--r--Source/Core/VideoCommon/VertexLoaderBase.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/Source/Core/VideoCommon/VertexLoaderBase.cpp b/Source/Core/VideoCommon/VertexLoaderBase.cpp
index 4372729506..ed56db0655 100644
--- a/Source/Core/VideoCommon/VertexLoaderBase.cpp
+++ b/Source/Core/VideoCommon/VertexLoaderBase.cpp
@@ -2,6 +2,8 @@
// Licensed under GPLv2
// Refer to the license.txt file included.
+#include <vector>
+
#include "Common/StringUtil.h"
#include "VideoCommon/VertexLoader.h"
@@ -124,10 +126,68 @@ void VertexLoaderBase::AppendToString(std::string *dest) const
dest->append(StringFromFormat(" - %i v\n", m_numLoadedVertices));
}
+// a hacky implementation to compare two vertex loaders
+class VertexLoaderTester : public VertexLoaderBase
+{
+public:
+ VertexLoaderTester(VertexLoaderBase* _a, VertexLoaderBase* _b, const TVtxDesc& vtx_desc, const VAT& vtx_attr)
+ : VertexLoaderBase(vtx_desc, vtx_attr)
+ {
+ a = _a;
+ b = _b;
+ m_initialized = a && b && a->IsInitialized() && b->IsInitialized();
+ m_initialized = m_initialized && (a->m_VertexSize == b->m_VertexSize);
+ m_initialized = m_initialized && (a->m_native_vtx_decl.stride == b->m_native_vtx_decl.stride);
+ }
+ ~VertexLoaderTester()
+ {
+ delete a;
+ delete b;
+ }
+
+ int RunVertices(int primitive, int count, DataReader src, DataReader dst) override
+ {
+ buffer_a.resize(count * a->m_native_vtx_decl.stride);
+ buffer_b.resize(count * b->m_native_vtx_decl.stride);
+
+ int count_a = a->RunVertices(primitive, count, src, DataReader(buffer_a.data(), buffer_a.data()+buffer_a.size()));
+ int count_b = b->RunVertices(primitive, count, src, DataReader(buffer_b.data(), buffer_b.data()+buffer_b.size()));
+
+ if (count_a != count_b)
+ ERROR_LOG(VIDEO, "Both vertexloaders have loaded a different amount of vertices.");
+
+ if (memcmp(buffer_a.data(), buffer_b.data(), std::min(count_a, count_b)))
+ ERROR_LOG(VIDEO, "Both vertexloaders have loaded different data.");
+
+ u8* dstptr;
+ dst.WritePointer(&dstptr);
+ memcpy(dstptr, buffer_a.data(), count_a);
+ return count_a;
+ }
+ std::string GetName() const override { return "CompareLoader"; }
+ bool IsInitialized() override { return m_initialized; }
+
+private:
+ VertexLoaderBase *a, *b;
+ bool m_initialized;
+ std::vector<u8> buffer_a, buffer_b;
+};
+
VertexLoaderBase* VertexLoaderBase::CreateVertexLoader(const TVtxDesc& vtx_desc, const VAT& vtx_attr)
{
VertexLoaderBase* loader;
+#if 0
+ // first try: Any new VertexLoader vs the old one
+ loader = new VertexLoaderTester(
+ new VertexLoader(vtx_desc, vtx_attr), // the software one
+ new VertexLoader(vtx_desc, vtx_attr), // the new one to compare
+ vtx_desc, vtx_attr);
+ if (loader->IsInitialized())
+ return loader;
+ delete loader;
+#endif
+
// last try: The old VertexLoader
loader = new VertexLoader(vtx_desc, vtx_attr);
if (loader->IsInitialized())