2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:09:55 +00:00
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2011-01-23 15:29:57 +00:00
|
|
|
#include <cmath>
|
2014-11-11 09:48:38 +00:00
|
|
|
#include <type_traits>
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2015-08-28 19:13:28 +00:00
|
|
|
#include "Common/Common.h"
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "Common/CommonFuncs.h"
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "VideoCommon/DataReader.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/VertexLoader.h"
|
|
|
|
#include "VideoCommon/VertexLoader_Normal.h"
|
2015-05-29 12:42:45 +00:00
|
|
|
#include "VideoCommon/VertexLoaderManager.h"
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "VideoCommon/VertexLoaderUtils.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
|
2013-02-21 10:45:29 +00:00
|
|
|
// warning: mapping buffer should be disabled to use this
|
2014-12-09 07:30:38 +00:00
|
|
|
#define LOG_NORM() // PRIM_LOG("norm: %f %f %f, ", ((float*)g_vertex_manager_write_ptr)[-3], ((float*)g_vertex_manager_write_ptr)[-2], ((float*)g_vertex_manager_write_ptr)[-1]);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
VertexLoader_Normal::Set VertexLoader_Normal::m_Table[NUM_NRM_TYPE][NUM_NRM_INDICES][NUM_NRM_ELEMENTS][NUM_NRM_FORMAT];
|
|
|
|
|
2013-02-21 04:22:41 +00:00
|
|
|
namespace
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
|
|
|
|
2013-02-21 04:22:41 +00:00
|
|
|
template <typename T>
|
2013-02-21 19:25:35 +00:00
|
|
|
__forceinline float FracAdjust(T val)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2013-02-21 04:22:41 +00:00
|
|
|
//auto const S8FRAC = 1.f / (1u << 6);
|
|
|
|
//auto const U8FRAC = 1.f / (1u << 7);
|
|
|
|
//auto const S16FRAC = 1.f / (1u << 14);
|
|
|
|
//auto const U16FRAC = 1.f / (1u << 15);
|
2013-03-20 01:51:12 +00:00
|
|
|
|
2013-02-21 06:49:47 +00:00
|
|
|
// TODO: is this right?
|
2014-11-11 09:48:38 +00:00
|
|
|
return val / float(1u << (sizeof(T) * 8 - std::is_signed<T>::value - 1));
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2013-02-21 04:22:41 +00:00
|
|
|
template <>
|
2013-02-21 19:25:35 +00:00
|
|
|
__forceinline float FracAdjust(float val)
|
2013-04-24 13:21:54 +00:00
|
|
|
{
|
|
|
|
return val;
|
|
|
|
}
|
2009-09-13 21:18:04 +00:00
|
|
|
|
2013-02-21 04:22:41 +00:00
|
|
|
template <typename T, int N>
|
2013-02-21 19:25:35 +00:00
|
|
|
__forceinline void ReadIndirect(const T* data)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2013-02-21 04:22:41 +00:00
|
|
|
static_assert(3 == N || 9 == N, "N is only sane as 3 or 9!");
|
2014-12-09 07:30:38 +00:00
|
|
|
DataReader dst(g_vertex_manager_write_ptr, nullptr);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2013-02-21 04:22:41 +00:00
|
|
|
for (int i = 0; i != N; ++i)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2014-01-21 22:44:51 +00:00
|
|
|
dst.Write(FracAdjust(Common::FromBigEndian(data[i])));
|
2013-02-21 04:22:41 +00:00
|
|
|
}
|
2013-03-20 01:51:12 +00:00
|
|
|
|
2015-01-06 16:49:27 +00:00
|
|
|
g_vertex_manager_write_ptr = dst.GetPointer();
|
2013-02-21 12:45:48 +00:00
|
|
|
LOG_NORM();
|
2009-09-13 21:18:04 +00:00
|
|
|
}
|
|
|
|
|
2013-02-21 04:22:41 +00:00
|
|
|
template <typename T, int N>
|
2013-02-21 19:25:35 +00:00
|
|
|
struct Normal_Direct
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2015-06-19 19:18:16 +00:00
|
|
|
static void function(VertexLoader* loader)
|
2013-02-21 19:25:35 +00:00
|
|
|
{
|
|
|
|
auto const source = reinterpret_cast<const T*>(DataGetPosition());
|
|
|
|
ReadIndirect<T, N * 3>(source);
|
|
|
|
DataSkip<N * 3 * sizeof(T)>();
|
|
|
|
}
|
2013-03-20 01:51:12 +00:00
|
|
|
|
2013-02-21 19:25:35 +00:00
|
|
|
static const int size = sizeof(T) * N * 3;
|
|
|
|
};
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2013-02-21 04:22:41 +00:00
|
|
|
template <typename I, typename T, int N, int Offset>
|
2013-02-21 19:25:35 +00:00
|
|
|
__forceinline void Normal_Index_Offset()
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2014-11-11 09:48:38 +00:00
|
|
|
static_assert(std::is_unsigned<I>::value, "Only unsigned I is sane!");
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-21 04:22:41 +00:00
|
|
|
auto const index = DataRead<I>();
|
2015-05-29 12:42:45 +00:00
|
|
|
auto const data = reinterpret_cast<const T*>(VertexLoaderManager::cached_arraybases[ARRAY_NORMAL]
|
2014-11-11 09:48:38 +00:00
|
|
|
+ (index * g_main_cp_state.array_strides[ARRAY_NORMAL]) + sizeof(T) * 3 * Offset);
|
2013-02-21 04:22:41 +00:00
|
|
|
ReadIndirect<T, N * 3>(data);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2013-02-21 04:22:41 +00:00
|
|
|
template <typename I, typename T, int N>
|
2013-02-21 19:25:35 +00:00
|
|
|
struct Normal_Index
|
2009-09-13 21:18:04 +00:00
|
|
|
{
|
2015-06-19 19:18:16 +00:00
|
|
|
static void function(VertexLoader* loader)
|
2013-02-21 19:25:35 +00:00
|
|
|
{
|
|
|
|
Normal_Index_Offset<I, T, N, 0>();
|
|
|
|
}
|
2013-03-20 01:51:12 +00:00
|
|
|
|
2013-02-21 19:25:35 +00:00
|
|
|
static const int size = sizeof(I);
|
|
|
|
};
|
2009-09-13 21:18:04 +00:00
|
|
|
|
2013-02-21 04:22:41 +00:00
|
|
|
template <typename I, typename T>
|
2013-02-21 19:25:35 +00:00
|
|
|
struct Normal_Index_Indices3
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2015-06-19 19:18:16 +00:00
|
|
|
static void function(VertexLoader* loader)
|
2013-02-21 19:25:35 +00:00
|
|
|
{
|
|
|
|
Normal_Index_Offset<I, T, 1, 0>();
|
|
|
|
Normal_Index_Offset<I, T, 1, 1>();
|
|
|
|
Normal_Index_Offset<I, T, 1, 2>();
|
|
|
|
}
|
2013-03-20 01:51:12 +00:00
|
|
|
|
2013-02-21 19:25:35 +00:00
|
|
|
static const int size = sizeof(I) * 3;
|
|
|
|
};
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-08-30 16:41:21 +00:00
|
|
|
void VertexLoader_Normal::Init()
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2014-02-17 04:51:41 +00:00
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES1][NRM_NBT] [FORMAT_UBYTE] = Normal_Direct<u8, 1>();
|
2013-02-21 19:25:35 +00:00
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES1][NRM_NBT] [FORMAT_BYTE] = Normal_Direct<s8, 1>();
|
2014-02-17 04:51:41 +00:00
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES1][NRM_NBT] [FORMAT_USHORT] = Normal_Direct<u16, 1>();
|
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES1][NRM_NBT] [FORMAT_SHORT] = Normal_Direct<s16, 1>();
|
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES1][NRM_NBT] [FORMAT_FLOAT] = Normal_Direct<float, 1>();
|
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES1][NRM_NBT3][FORMAT_UBYTE] = Normal_Direct<u8, 3>();
|
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES1][NRM_NBT3][FORMAT_BYTE] = Normal_Direct<s8, 3>();
|
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES1][NRM_NBT3][FORMAT_USHORT] = Normal_Direct<u16, 3>();
|
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES1][NRM_NBT3][FORMAT_SHORT] = Normal_Direct<s16, 3>();
|
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES1][NRM_NBT3][FORMAT_FLOAT] = Normal_Direct<float, 3>();
|
2013-02-21 19:25:35 +00:00
|
|
|
|
|
|
|
// Same as above
|
2014-02-17 04:51:41 +00:00
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES3][NRM_NBT] [FORMAT_UBYTE] = Normal_Direct<u8, 1>();
|
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES3][NRM_NBT] [FORMAT_BYTE] = Normal_Direct<s8, 1>();
|
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES3][NRM_NBT] [FORMAT_USHORT] = Normal_Direct<u16, 1>();
|
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES3][NRM_NBT] [FORMAT_SHORT] = Normal_Direct<s16, 1>();
|
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES3][NRM_NBT] [FORMAT_FLOAT] = Normal_Direct<float, 1>();
|
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES3][NRM_NBT3][FORMAT_UBYTE] = Normal_Direct<u8, 3>();
|
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES3][NRM_NBT3][FORMAT_BYTE] = Normal_Direct<s8, 3>();
|
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES3][NRM_NBT3][FORMAT_USHORT] = Normal_Direct<u16, 3>();
|
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES3][NRM_NBT3][FORMAT_SHORT] = Normal_Direct<s16, 3>();
|
|
|
|
m_Table[NRM_DIRECT] [NRM_INDICES3][NRM_NBT3][FORMAT_FLOAT] = Normal_Direct<float, 3>();
|
|
|
|
|
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES1][NRM_NBT] [FORMAT_UBYTE] = Normal_Index<u8, u8, 1>();
|
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES1][NRM_NBT] [FORMAT_BYTE] = Normal_Index<u8, s8, 1>();
|
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES1][NRM_NBT] [FORMAT_USHORT] = Normal_Index<u8, u16, 1>();
|
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES1][NRM_NBT] [FORMAT_SHORT] = Normal_Index<u8, s16, 1>();
|
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES1][NRM_NBT] [FORMAT_FLOAT] = Normal_Index<u8, float, 1>();
|
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES1][NRM_NBT3][FORMAT_UBYTE] = Normal_Index<u8, u8, 3>();
|
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES1][NRM_NBT3][FORMAT_BYTE] = Normal_Index<u8, s8, 3>();
|
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES1][NRM_NBT3][FORMAT_USHORT] = Normal_Index<u8, u16, 3>();
|
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES1][NRM_NBT3][FORMAT_SHORT] = Normal_Index<u8, s16, 3>();
|
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES1][NRM_NBT3][FORMAT_FLOAT] = Normal_Index<u8, float, 3>();
|
2013-02-21 19:25:35 +00:00
|
|
|
|
|
|
|
// Same as above for NRM_NBT
|
2014-02-17 04:51:41 +00:00
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES3][NRM_NBT] [FORMAT_UBYTE] = Normal_Index<u8, u8, 1>();
|
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES3][NRM_NBT] [FORMAT_BYTE] = Normal_Index<u8, s8, 1>();
|
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES3][NRM_NBT] [FORMAT_USHORT] = Normal_Index<u8, u16, 1>();
|
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES3][NRM_NBT] [FORMAT_SHORT] = Normal_Index<u8, s16, 1>();
|
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES3][NRM_NBT] [FORMAT_FLOAT] = Normal_Index<u8, float, 1>();
|
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES3][NRM_NBT3][FORMAT_UBYTE] = Normal_Index_Indices3<u8, u8>();
|
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES3][NRM_NBT3][FORMAT_BYTE] = Normal_Index_Indices3<u8, s8>();
|
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES3][NRM_NBT3][FORMAT_USHORT] = Normal_Index_Indices3<u8, u16>();
|
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES3][NRM_NBT3][FORMAT_SHORT] = Normal_Index_Indices3<u8, s16>();
|
|
|
|
m_Table[NRM_INDEX8] [NRM_INDICES3][NRM_NBT3][FORMAT_FLOAT] = Normal_Index_Indices3<u8, float>();
|
|
|
|
|
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES1][NRM_NBT] [FORMAT_UBYTE] = Normal_Index<u16, u8, 1>();
|
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES1][NRM_NBT] [FORMAT_BYTE] = Normal_Index<u16, s8, 1>();
|
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES1][NRM_NBT] [FORMAT_USHORT] = Normal_Index<u16, u16, 1>();
|
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES1][NRM_NBT] [FORMAT_SHORT] = Normal_Index<u16, s16, 1>();
|
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES1][NRM_NBT] [FORMAT_FLOAT] = Normal_Index<u16, float, 1>();
|
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_UBYTE] = Normal_Index<u16, u8, 3>();
|
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_BYTE] = Normal_Index<u16, s8, 3>();
|
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_USHORT] = Normal_Index<u16, u16, 3>();
|
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_SHORT] = Normal_Index<u16, s16, 3>();
|
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_FLOAT] = Normal_Index<u16, float, 3>();
|
2013-02-21 19:25:35 +00:00
|
|
|
|
|
|
|
// Same as above for NRM_NBT
|
2014-02-17 04:51:41 +00:00
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES3][NRM_NBT] [FORMAT_UBYTE] = Normal_Index<u16, u8, 1>();
|
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES3][NRM_NBT] [FORMAT_BYTE] = Normal_Index<u16, s8, 1>();
|
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES3][NRM_NBT] [FORMAT_USHORT] = Normal_Index<u16, u16, 1>();
|
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES3][NRM_NBT] [FORMAT_SHORT] = Normal_Index<u16, s16, 1>();
|
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES3][NRM_NBT] [FORMAT_FLOAT] = Normal_Index<u16, float, 1>();
|
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_UBYTE] = Normal_Index_Indices3<u16, u8>();
|
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_BYTE] = Normal_Index_Indices3<u16, s8>();
|
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_USHORT] = Normal_Index_Indices3<u16, u16>();
|
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_SHORT] = Normal_Index_Indices3<u16, s16>();
|
|
|
|
m_Table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_FLOAT] = Normal_Index_Indices3<u16, float>();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2014-09-01 09:00:25 +00:00
|
|
|
unsigned int VertexLoader_Normal::GetSize(u64 _type,
|
2013-02-21 04:22:41 +00:00
|
|
|
unsigned int _format, unsigned int _elements, unsigned int _index3)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2013-02-21 04:22:41 +00:00
|
|
|
return m_Table[_type][_index3][_elements][_format].gc_size;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2014-09-01 09:00:25 +00:00
|
|
|
TPipelineFunction VertexLoader_Normal::GetFunction(u64 _type,
|
2013-02-21 04:22:41 +00:00
|
|
|
unsigned int _format, unsigned int _elements, unsigned int _index3)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2013-02-21 04:22:41 +00:00
|
|
|
TPipelineFunction pFunc = m_Table[_type][_index3][_elements][_format].function;
|
2013-04-24 13:21:54 +00:00
|
|
|
return pFunc;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|