| 
									
										
										
										
											2014-12-13 01:51:14 +01:00
										 |  |  | // Copyright 2014 Dolphin Emulator Project
 | 
					
						
							| 
									
										
										
										
											2015-05-18 01:08:10 +02:00
										 |  |  | // Licensed under GPLv2+
 | 
					
						
							| 
									
										
										
										
											2014-12-13 01:51:14 +01:00
										 |  |  | // Refer to the license.txt file included.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <array>
 | 
					
						
							| 
									
										
										
										
											2015-12-22 19:59:32 -05:00
										 |  |  | #include <memory>
 | 
					
						
							| 
									
										
										
										
											2014-12-13 01:51:14 +01:00
										 |  |  | #include <string>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Common/CommonTypes.h"
 | 
					
						
							|  |  |  | #include "VideoCommon/CPMemory.h"
 | 
					
						
							|  |  |  | #include "VideoCommon/NativeVertexFormat.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-31 14:51:55 -05:00
										 |  |  | class DataReader; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-13 01:51:14 +01:00
										 |  |  | class VertexLoaderUID | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   std::array<u32, 5> vid; | 
					
						
							|  |  |  |   size_t hash; | 
					
						
							| 
									
										
										
										
											2014-12-13 01:51:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | public: | 
					
						
							|  |  |  |   VertexLoaderUID() {} | 
					
						
							|  |  |  |   VertexLoaderUID(const TVtxDesc& vtx_desc, const VAT& vat) | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     vid[0] = vtx_desc.Hex & 0xFFFFFFFF; | 
					
						
							|  |  |  |     vid[1] = vtx_desc.Hex >> 32; | 
					
						
							|  |  |  |     vid[2] = vat.g0.Hex; | 
					
						
							|  |  |  |     vid[3] = vat.g1.Hex; | 
					
						
							|  |  |  |     vid[4] = vat.g2.Hex; | 
					
						
							|  |  |  |     hash = CalculateHash(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   bool operator==(const VertexLoaderUID& rh) const { return vid == rh.vid; } | 
					
						
							|  |  |  |   size_t GetHash() const { return hash; } | 
					
						
							| 
									
										
										
										
											2014-12-13 01:51:14 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   size_t CalculateHash() const | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     size_t h = -1; | 
					
						
							| 
									
										
										
										
											2014-12-13 01:51:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |     for (auto word : vid) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       h = h * 137 + word; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-12-13 01:51:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |     return h; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-13 01:51:14 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace std | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | template <> | 
					
						
							|  |  |  | struct hash<VertexLoaderUID> | 
					
						
							| 
									
										
										
										
											2014-12-13 01:51:14 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   size_t operator()(const VertexLoaderUID& uid) const { return uid.GetHash(); } | 
					
						
							| 
									
										
										
										
											2014-12-13 01:51:14 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class VertexLoaderBase | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   static std::unique_ptr<VertexLoaderBase> CreateVertexLoader(const TVtxDesc& vtx_desc, | 
					
						
							|  |  |  |                                                               const VAT& vtx_attr); | 
					
						
							|  |  |  |   virtual ~VertexLoaderBase() {} | 
					
						
							|  |  |  |   virtual int RunVertices(DataReader src, DataReader dst, int count) = 0; | 
					
						
							| 
									
										
										
										
											2014-12-13 01:51:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   virtual bool IsInitialized() = 0; | 
					
						
							| 
									
										
										
										
											2014-12-13 01:51:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   // For debugging / profiling
 | 
					
						
							|  |  |  |   void AppendToString(std::string* dest) const; | 
					
						
							| 
									
										
										
										
											2014-12-13 01:51:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   virtual std::string GetName() const = 0; | 
					
						
							| 
									
										
										
										
											2014-12-13 01:51:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   // per loader public state
 | 
					
						
							|  |  |  |   int m_VertexSize;  // number of bytes of a raw GC vertex
 | 
					
						
							|  |  |  |   PortableVertexDeclaration m_native_vtx_decl; | 
					
						
							|  |  |  |   u32 m_native_components; | 
					
						
							| 
									
										
										
										
											2014-12-13 01:51:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   // used by VertexLoaderManager
 | 
					
						
							|  |  |  |   NativeVertexFormat* m_native_vertex_format; | 
					
						
							|  |  |  |   int m_numLoadedVertices; | 
					
						
							| 
									
										
										
										
											2014-12-13 01:51:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   VertexLoaderBase(const TVtxDesc& vtx_desc, const VAT& vtx_attr); | 
					
						
							|  |  |  |   void SetVAT(const VAT& vat); | 
					
						
							| 
									
										
										
										
											2014-12-13 01:51:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   // GC vertex format
 | 
					
						
							|  |  |  |   TVtxAttr m_VtxAttr;  // VAT decoded into easy format
 | 
					
						
							|  |  |  |   TVtxDesc m_VtxDesc;  // Not really used currently - or well it is, but could be easily avoided.
 | 
					
						
							|  |  |  |   VAT m_vat; | 
					
						
							| 
									
										
										
										
											2014-12-13 01:51:14 +01:00
										 |  |  | }; |