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
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
#include "VideoCommon/VertexLoader.h"
|
|
|
|
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "Common/Assert.h"
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
|
|
|
|
#include "VideoCommon/DataReader.h"
|
2015-06-01 17:58:27 +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
|
|
|
#include "VideoCommon/VertexLoader_Color.h"
|
|
|
|
#include "VideoCommon/VertexLoader_Normal.h"
|
|
|
|
#include "VideoCommon/VertexLoader_Position.h"
|
|
|
|
#include "VideoCommon/VertexLoader_TextCoord.h"
|
|
|
|
#include "VideoCommon/VideoCommon.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2014-12-09 07:30:38 +00:00
|
|
|
// This pointer is used as the source/dst for all fixed function loader calls
|
2014-11-27 22:53:11 +00:00
|
|
|
u8* g_video_buffer_read_ptr;
|
2014-12-09 07:30:38 +00:00
|
|
|
u8* g_vertex_manager_write_ptr;
|
2014-11-27 22:53:11 +00:00
|
|
|
|
2015-06-19 19:18:16 +00:00
|
|
|
static void PosMtx_ReadDirect_UByte(VertexLoader* loader)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2015-10-01 07:28:19 +00:00
|
|
|
u32 posmtx = DataRead<u8>() & 0x3f;
|
2015-06-01 17:58:27 +00:00
|
|
|
if (loader->m_counter < 3)
|
2016-05-07 07:35:40 +00:00
|
|
|
VertexLoaderManager::position_matrix_index[loader->m_counter + 1] = posmtx;
|
2015-01-15 00:46:23 +00:00
|
|
|
DataWrite<u32>(posmtx);
|
2020-11-14 03:33:26 +00:00
|
|
|
PRIM_LOG("posmtx: {}, ", posmtx);
|
2009-06-28 20:04:07 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 19:18:16 +00:00
|
|
|
static void TexMtx_ReadDirect_UByte(VertexLoader* loader)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2015-10-01 07:28:19 +00:00
|
|
|
loader->m_curtexmtx[loader->m_texmtxread] = DataRead<u8>() & 0x3f;
|
2014-09-14 16:52:51 +00:00
|
|
|
|
2020-11-14 03:33:26 +00:00
|
|
|
PRIM_LOG("texmtx{}: {}, ", loader->m_texmtxread, loader->m_curtexmtx[loader->m_texmtxread]);
|
2014-12-13 09:57:46 +00:00
|
|
|
loader->m_texmtxread++;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 19:18:16 +00:00
|
|
|
static void TexMtx_Write_Float(VertexLoader* loader)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2014-12-13 09:57:46 +00:00
|
|
|
DataWrite(float(loader->m_curtexmtx[loader->m_texmtxwrite++]));
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 19:18:16 +00:00
|
|
|
static void TexMtx_Write_Float2(VertexLoader* loader)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2013-02-22 08:19:59 +00:00
|
|
|
DataWrite(0.f);
|
2014-12-13 09:57:46 +00:00
|
|
|
DataWrite(float(loader->m_curtexmtx[loader->m_texmtxwrite++]));
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 19:18:16 +00:00
|
|
|
static void TexMtx_Write_Float3(VertexLoader* loader)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2013-02-22 08:19:59 +00:00
|
|
|
DataWrite(0.f);
|
|
|
|
DataWrite(0.f);
|
2014-12-13 09:57:46 +00:00
|
|
|
DataWrite(float(loader->m_curtexmtx[loader->m_texmtxwrite++]));
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 19:18:16 +00:00
|
|
|
static void SkipVertex(VertexLoader* loader)
|
2014-12-21 13:29:44 +00:00
|
|
|
{
|
|
|
|
if (loader->m_vertexSkip)
|
|
|
|
{
|
|
|
|
// reset the output buffer
|
|
|
|
g_vertex_manager_write_ptr -= loader->m_native_vtx_decl.stride;
|
|
|
|
|
|
|
|
loader->m_skippedVertices++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-29 05:23:17 +00:00
|
|
|
VertexLoader::VertexLoader(const TVtxDesc& vtx_desc, const VAT& vtx_attr)
|
2014-12-13 00:51:14 +00:00
|
|
|
: VertexLoaderBase(vtx_desc, vtx_attr)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2013-03-06 17:58:15 +00:00
|
|
|
CompileVertexTranslator();
|
2014-12-13 09:57:46 +00:00
|
|
|
|
|
|
|
// generate frac factors
|
2015-01-19 17:33:08 +00:00
|
|
|
m_posScale = 1.0f / (1U << m_VtxAttr.PosFrac);
|
2014-12-13 09:57:46 +00:00
|
|
|
for (int i = 0; i < 8; i++)
|
2015-01-19 17:33:08 +00:00
|
|
|
m_tcScale[i] = 1.0f / (1U << m_VtxAttr.texCoord[i].Frac);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VertexLoader::CompileVertexTranslator()
|
|
|
|
{
|
|
|
|
m_VertexSize = 0;
|
|
|
|
const TVtxAttr& vtx_attr = m_VtxAttr;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-02-23 14:14:27 +00:00
|
|
|
// Reset pipeline
|
|
|
|
m_numPipelineStages = 0;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-01-15 15:58:36 +00:00
|
|
|
u32 components = 0;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
// Position in pc vertex format.
|
|
|
|
int nat_offset = 0;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
// Position Matrix Index
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxDesc.low.PosMatIdx)
|
2013-04-24 13:21:54 +00:00
|
|
|
{
|
2008-12-08 05:25:12 +00:00
|
|
|
WriteCall(PosMtx_ReadDirect_UByte);
|
2014-01-15 15:58:36 +00:00
|
|
|
components |= VB_HAS_POSMTXIDX;
|
2015-01-15 00:46:23 +00:00
|
|
|
m_native_vtx_decl.posmtx.components = 4;
|
|
|
|
m_native_vtx_decl.posmtx.enable = true;
|
|
|
|
m_native_vtx_decl.posmtx.offset = nat_offset;
|
|
|
|
m_native_vtx_decl.posmtx.type = VAR_UNSIGNED_BYTE;
|
|
|
|
m_native_vtx_decl.posmtx.integer = true;
|
|
|
|
nat_offset += 4;
|
2008-12-08 05:25:12 +00:00
|
|
|
m_VertexSize += 1;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxDesc.low.Tex0MatIdx)
|
2015-02-15 19:43:31 +00:00
|
|
|
{
|
|
|
|
m_VertexSize += 1;
|
|
|
|
components |= VB_HAS_TEXMTXIDX0;
|
|
|
|
WriteCall(TexMtx_ReadDirect_UByte);
|
|
|
|
}
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxDesc.low.Tex1MatIdx)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2015-02-15 19:43:31 +00:00
|
|
|
m_VertexSize += 1;
|
|
|
|
components |= VB_HAS_TEXMTXIDX1;
|
|
|
|
WriteCall(TexMtx_ReadDirect_UByte);
|
|
|
|
}
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxDesc.low.Tex2MatIdx)
|
2015-02-15 19:43:31 +00:00
|
|
|
{
|
|
|
|
m_VertexSize += 1;
|
|
|
|
components |= VB_HAS_TEXMTXIDX2;
|
|
|
|
WriteCall(TexMtx_ReadDirect_UByte);
|
|
|
|
}
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxDesc.low.Tex3MatIdx)
|
2015-02-15 19:43:31 +00:00
|
|
|
{
|
|
|
|
m_VertexSize += 1;
|
|
|
|
components |= VB_HAS_TEXMTXIDX3;
|
|
|
|
WriteCall(TexMtx_ReadDirect_UByte);
|
|
|
|
}
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxDesc.low.Tex4MatIdx)
|
2015-02-15 19:43:31 +00:00
|
|
|
{
|
|
|
|
m_VertexSize += 1;
|
|
|
|
components |= VB_HAS_TEXMTXIDX4;
|
|
|
|
WriteCall(TexMtx_ReadDirect_UByte);
|
|
|
|
}
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxDesc.low.Tex5MatIdx)
|
2015-02-15 19:43:31 +00:00
|
|
|
{
|
|
|
|
m_VertexSize += 1;
|
|
|
|
components |= VB_HAS_TEXMTXIDX5;
|
|
|
|
WriteCall(TexMtx_ReadDirect_UByte);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxDesc.low.Tex6MatIdx)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2015-02-15 19:43:31 +00:00
|
|
|
m_VertexSize += 1;
|
|
|
|
components |= VB_HAS_TEXMTXIDX6;
|
2014-09-14 16:52:51 +00:00
|
|
|
WriteCall(TexMtx_ReadDirect_UByte);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxDesc.low.Tex7MatIdx)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2010-04-09 15:13:42 +00:00
|
|
|
m_VertexSize += 1;
|
2015-03-17 06:05:19 +00:00
|
|
|
components |= VB_HAS_TEXMTXIDX7;
|
2015-01-19 16:38:40 +00:00
|
|
|
WriteCall(TexMtx_ReadDirect_UByte);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
2014-07-25 23:10:44 +00:00
|
|
|
// Write vertex position loader
|
2021-02-08 23:22:10 +00:00
|
|
|
WriteCall(VertexLoader_Position::GetFunction(m_VtxDesc.low.Position, m_VtxAttr.PosFormat,
|
2015-03-17 06:05:19 +00:00
|
|
|
m_VtxAttr.PosElements));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
m_VertexSize += VertexLoader_Position::GetSize(m_VtxDesc.low.Position, m_VtxAttr.PosFormat,
|
2011-03-21 05:46:33 +00:00
|
|
|
m_VtxAttr.PosElements);
|
2021-02-08 23:22:10 +00:00
|
|
|
int pos_elements = m_VtxAttr.PosElements == CoordComponentCount::XY ? 2 : 3;
|
2011-03-21 05:46:33 +00:00
|
|
|
m_native_vtx_decl.position.components = pos_elements;
|
|
|
|
m_native_vtx_decl.position.enable = true;
|
2015-01-19 16:38:40 +00:00
|
|
|
m_native_vtx_decl.position.offset = nat_offset;
|
2014-07-25 23:10:44 +00:00
|
|
|
m_native_vtx_decl.position.type = VAR_FLOAT;
|
2011-03-21 05:46:33 +00:00
|
|
|
m_native_vtx_decl.position.integer = false;
|
2015-03-17 06:05:19 +00:00
|
|
|
nat_offset += pos_elements * sizeof(float);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2011-03-21 05:46:33 +00:00
|
|
|
// Normals
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxDesc.low.Normal != VertexComponentFormat::NotPresent)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
m_VertexSize += VertexLoader_Normal::GetSize(m_VtxDesc.low.Normal, m_VtxAttr.NormalFormat,
|
2011-03-21 05:46:33 +00:00
|
|
|
m_VtxAttr.NormalElements, m_VtxAttr.NormalIndex3);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
TPipelineFunction pFunc =
|
|
|
|
VertexLoader_Normal::GetFunction(m_VtxDesc.low.Normal, m_VtxAttr.NormalFormat,
|
|
|
|
m_VtxAttr.NormalElements, m_VtxAttr.NormalIndex3);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-03-09 20:14:26 +00:00
|
|
|
if (pFunc == nullptr)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2020-11-14 03:33:26 +00:00
|
|
|
PanicAlertFmt("VertexLoader_Normal::GetFunction({} {} {} {}) returned zero!",
|
2021-02-08 23:22:10 +00:00
|
|
|
m_VtxDesc.low.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements,
|
2020-11-14 03:33:26 +00:00
|
|
|
m_VtxAttr.NormalIndex3);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
WriteCall(pFunc);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
for (int i = 0; i < (vtx_attr.NormalElements == NormalComponentCount::NBT ? 3 : 1); i++)
|
2013-04-24 13:21:54 +00:00
|
|
|
{
|
2014-07-25 23:10:44 +00:00
|
|
|
m_native_vtx_decl.normals[i].components = 3;
|
|
|
|
m_native_vtx_decl.normals[i].enable = true;
|
|
|
|
m_native_vtx_decl.normals[i].offset = nat_offset;
|
|
|
|
m_native_vtx_decl.normals[i].type = VAR_FLOAT;
|
|
|
|
m_native_vtx_decl.normals[i].integer = false;
|
2011-01-19 13:57:15 +00:00
|
|
|
nat_offset += 12;
|
2013-03-20 01:51:12 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-01-15 15:58:36 +00:00
|
|
|
components |= VB_HAS_NRM0;
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxAttr.NormalElements == NormalComponentCount::NBT)
|
2014-01-15 15:58:36 +00:00
|
|
|
components |= VB_HAS_NRM1 | VB_HAS_NRM2;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
for (size_t i = 0; i < m_VtxDesc.low.Color.Size(); i++)
|
2013-04-24 13:21:54 +00:00
|
|
|
{
|
2014-07-25 23:10:44 +00:00
|
|
|
m_native_vtx_decl.colors[i].components = 4;
|
|
|
|
m_native_vtx_decl.colors[i].type = VAR_UNSIGNED_BYTE;
|
|
|
|
m_native_vtx_decl.colors[i].integer = false;
|
2021-02-08 23:22:10 +00:00
|
|
|
switch (m_VtxDesc.low.Color[i])
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
case VertexComponentFormat::NotPresent:
|
2008-12-08 05:25:12 +00:00
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case VertexComponentFormat::Direct:
|
2008-12-08 05:25:12 +00:00
|
|
|
switch (m_VtxAttr.color[i].Comp)
|
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGB565:
|
2014-02-17 04:51:41 +00:00
|
|
|
m_VertexSize += 2;
|
|
|
|
WriteCall(Color_ReadDirect_16b_565);
|
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGB888:
|
2014-02-17 04:51:41 +00:00
|
|
|
m_VertexSize += 3;
|
|
|
|
WriteCall(Color_ReadDirect_24b_888);
|
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGB888x:
|
2014-02-17 04:51:41 +00:00
|
|
|
m_VertexSize += 4;
|
|
|
|
WriteCall(Color_ReadDirect_32b_888x);
|
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGBA4444:
|
2014-02-17 04:51:41 +00:00
|
|
|
m_VertexSize += 2;
|
|
|
|
WriteCall(Color_ReadDirect_16b_4444);
|
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGBA6666:
|
2014-02-17 04:51:41 +00:00
|
|
|
m_VertexSize += 3;
|
|
|
|
WriteCall(Color_ReadDirect_24b_6666);
|
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGBA8888:
|
2014-02-17 04:51:41 +00:00
|
|
|
m_VertexSize += 4;
|
|
|
|
WriteCall(Color_ReadDirect_32b_8888);
|
2008-12-08 05:25:12 +00:00
|
|
|
break;
|
|
|
|
default:
|
2018-03-15 00:34:35 +00:00
|
|
|
ASSERT(0);
|
2016-06-24 08:43:46 +00:00
|
|
|
break;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case VertexComponentFormat::Index8:
|
2008-12-08 05:25:12 +00:00
|
|
|
m_VertexSize += 1;
|
|
|
|
switch (m_VtxAttr.color[i].Comp)
|
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGB565:
|
2014-02-17 04:51:41 +00:00
|
|
|
WriteCall(Color_ReadIndex8_16b_565);
|
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGB888:
|
2014-02-17 04:51:41 +00:00
|
|
|
WriteCall(Color_ReadIndex8_24b_888);
|
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGB888x:
|
2014-02-17 04:51:41 +00:00
|
|
|
WriteCall(Color_ReadIndex8_32b_888x);
|
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGBA4444:
|
2014-02-17 04:51:41 +00:00
|
|
|
WriteCall(Color_ReadIndex8_16b_4444);
|
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGBA6666:
|
2014-02-17 04:51:41 +00:00
|
|
|
WriteCall(Color_ReadIndex8_24b_6666);
|
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGBA8888:
|
2014-02-17 04:51:41 +00:00
|
|
|
WriteCall(Color_ReadIndex8_32b_8888);
|
2008-12-08 05:25:12 +00:00
|
|
|
break;
|
|
|
|
default:
|
2018-03-15 00:34:35 +00:00
|
|
|
ASSERT(0);
|
2008-12-08 05:25:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case VertexComponentFormat::Index16:
|
2014-07-25 23:10:44 +00:00
|
|
|
m_VertexSize += 2;
|
|
|
|
switch (m_VtxAttr.color[i].Comp)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGB565:
|
2008-12-08 05:25:12 +00:00
|
|
|
WriteCall(Color_ReadIndex16_16b_565);
|
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGB888:
|
2008-12-08 05:25:12 +00:00
|
|
|
WriteCall(Color_ReadIndex16_24b_888);
|
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGB888x:
|
2014-07-25 23:10:44 +00:00
|
|
|
WriteCall(Color_ReadIndex16_32b_888x);
|
2016-06-24 08:43:46 +00:00
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGBA4444:
|
2014-07-25 23:10:44 +00:00
|
|
|
WriteCall(Color_ReadIndex16_16b_4444);
|
2016-06-24 08:43:46 +00:00
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGBA6666:
|
2014-07-25 23:10:44 +00:00
|
|
|
WriteCall(Color_ReadIndex16_24b_6666);
|
2010-02-28 11:36:00 +00:00
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGBA8888:
|
2010-02-28 11:36:00 +00:00
|
|
|
WriteCall(Color_ReadIndex16_32b_8888);
|
2016-06-24 08:43:46 +00:00
|
|
|
break;
|
|
|
|
default:
|
2018-03-15 00:34:35 +00:00
|
|
|
ASSERT(0);
|
2016-06-24 08:43:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2010-02-28 11:36:00 +00:00
|
|
|
// Common for the three bottom cases
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxDesc.low.Color[i] != VertexComponentFormat::NotPresent)
|
2013-04-24 13:21:54 +00:00
|
|
|
{
|
2014-01-15 15:58:36 +00:00
|
|
|
components |= VB_HAS_COL0 << i;
|
2010-04-09 15:13:42 +00:00
|
|
|
m_native_vtx_decl.colors[i].offset = nat_offset;
|
2014-07-25 23:10:44 +00:00
|
|
|
m_native_vtx_decl.colors[i].enable = true;
|
2013-04-24 13:21:54 +00:00
|
|
|
nat_offset += 4;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
// Texture matrix indices (remove if corresponding texture coordinate isn't enabled)
|
2021-02-08 23:22:10 +00:00
|
|
|
for (size_t i = 0; i < m_VtxDesc.high.TexCoord.Size(); i++)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2008-12-08 05:25:12 +00:00
|
|
|
m_native_vtx_decl.texcoords[i].offset = nat_offset;
|
|
|
|
m_native_vtx_decl.texcoords[i].type = VAR_FLOAT;
|
2014-07-25 23:10:44 +00:00
|
|
|
m_native_vtx_decl.texcoords[i].integer = false;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
const auto tc = m_VtxDesc.high.TexCoord[i].Value();
|
|
|
|
const auto format = m_VtxAttr.texCoord[i].Format;
|
|
|
|
const auto elements = m_VtxAttr.texCoord[i].Elements;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
if (tc != VertexComponentFormat::NotPresent)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
ASSERT_MSG(VIDEO, VertexComponentFormat::Direct <= tc && tc <= VertexComponentFormat::Index16,
|
|
|
|
"Invalid texture coordinates!\n(tc = %d)", (u32)tc);
|
|
|
|
ASSERT_MSG(VIDEO, ComponentFormat::UByte <= format && format <= ComponentFormat::Float,
|
|
|
|
"Invalid texture coordinates format!\n(format = %d)", (u32)format);
|
|
|
|
ASSERT_MSG(VIDEO, elements == TexComponentCount::S || elements == TexComponentCount::ST,
|
|
|
|
"Invalid number of texture coordinates elements!\n(elements = %d)", (u32)elements);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-07-25 23:10:44 +00:00
|
|
|
components |= VB_HAS_UV0 << i;
|
2021-02-08 23:22:10 +00:00
|
|
|
WriteCall(VertexLoader_TextCoord::GetFunction(tc, format, elements));
|
|
|
|
m_VertexSize += VertexLoader_TextCoord::GetSize(tc, format, elements);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
if (components & (VB_HAS_TEXMTXIDX0 << i))
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2008-12-08 05:25:12 +00:00
|
|
|
m_native_vtx_decl.texcoords[i].enable = true;
|
2021-02-08 23:22:10 +00:00
|
|
|
if (tc != VertexComponentFormat::NotPresent)
|
2013-04-24 13:21:54 +00:00
|
|
|
{
|
2008-12-08 05:25:12 +00:00
|
|
|
// if texmtx is included, texcoord will always be 3 floats, z will be the texmtx index
|
2015-01-15 00:46:23 +00:00
|
|
|
m_native_vtx_decl.texcoords[i].components = 3;
|
|
|
|
nat_offset += 12;
|
2021-02-08 23:22:10 +00:00
|
|
|
WriteCall(m_VtxAttr.texCoord[i].Elements == TexComponentCount::ST ? TexMtx_Write_Float :
|
|
|
|
TexMtx_Write_Float2);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2013-04-24 13:21:54 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_native_vtx_decl.texcoords[i].components = 3;
|
|
|
|
nat_offset += 12;
|
|
|
|
WriteCall(TexMtx_Write_Float3);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2013-04-24 13:21:54 +00:00
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
if (tc != VertexComponentFormat::NotPresent)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2014-07-25 23:10:44 +00:00
|
|
|
m_native_vtx_decl.texcoords[i].enable = true;
|
2021-02-08 23:22:10 +00:00
|
|
|
m_native_vtx_decl.texcoords[i].components =
|
|
|
|
vtx_attr.texCoord[i].Elements == TexComponentCount::ST ? 2 : 1;
|
|
|
|
nat_offset += 4 * (vtx_attr.texCoord[i].Elements == TexComponentCount::ST ? 2 : 1);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
if (tc == VertexComponentFormat::NotPresent)
|
2013-04-24 13:21:54 +00:00
|
|
|
{
|
2013-10-29 05:23:17 +00:00
|
|
|
// if there's more tex coords later, have to write a dummy call
|
2021-02-08 23:22:10 +00:00
|
|
|
size_t j = i + 1;
|
|
|
|
for (; j < m_VtxDesc.high.TexCoord.Size(); ++j)
|
2013-04-24 13:21:54 +00:00
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxDesc.high.TexCoord[j] != VertexComponentFormat::NotPresent)
|
2013-04-24 13:21:54 +00:00
|
|
|
{
|
2010-04-09 15:13:42 +00:00
|
|
|
WriteCall(VertexLoader_TextCoord::GetDummyFunction()); // important to get indices right!
|
2008-12-08 05:25:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
// tricky!
|
2014-01-15 15:58:36 +00:00
|
|
|
if (j == 8 && !((components & VB_HAS_TEXMTXIDXALL) & (VB_HAS_TEXMTXIDXALL << (i + 1))))
|
2013-04-24 13:21:54 +00:00
|
|
|
{
|
2008-12-08 05:25:12 +00:00
|
|
|
// no more tex coords and tex matrices, so exit loop
|
|
|
|
break;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
// indexed position formats may skip the vertex
|
|
|
|
if (IsIndexed(m_VtxDesc.low.Position))
|
2014-12-21 13:29:44 +00:00
|
|
|
{
|
|
|
|
WriteCall(SkipVertex);
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-07-25 23:10:44 +00:00
|
|
|
m_native_components = components;
|
|
|
|
m_native_vtx_decl.stride = nat_offset;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VertexLoader::WriteCall(TPipelineFunction func)
|
|
|
|
{
|
|
|
|
m_PipelineStages[m_numPipelineStages++] = func;
|
2009-01-10 23:10:33 +00:00
|
|
|
}
|
|
|
|
|
2015-04-06 09:44:13 +00:00
|
|
|
int VertexLoader::RunVertices(DataReader src, DataReader dst, int count)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2015-01-06 16:49:27 +00:00
|
|
|
g_vertex_manager_write_ptr = dst.GetPointer();
|
|
|
|
g_video_buffer_read_ptr = src.GetPointer();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
m_numLoadedVertices += count;
|
2014-12-21 13:29:44 +00:00
|
|
|
m_skippedVertices = 0;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-06-01 17:58:27 +00:00
|
|
|
for (m_counter = count - 1; m_counter >= 0; m_counter--)
|
2013-02-21 10:36:10 +00:00
|
|
|
{
|
2014-12-13 09:57:46 +00:00
|
|
|
m_tcIndex = 0;
|
|
|
|
m_colIndex = 0;
|
|
|
|
m_texmtxwrite = m_texmtxread = 0;
|
2013-02-21 10:36:10 +00:00
|
|
|
for (int i = 0; i < m_numPipelineStages; i++)
|
2014-12-13 09:57:46 +00:00
|
|
|
m_PipelineStages[i](this);
|
2013-02-21 10:36:10 +00:00
|
|
|
PRIM_LOG("\n");
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-12-21 13:29:44 +00:00
|
|
|
return count - m_skippedVertices;
|
2014-01-30 13:48:23 +00:00
|
|
|
}
|