2008-10-25 12:35:55 +00:00
|
|
|
// Copyright (C) 2003-2008 Dolphin Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2008-10-25 15:53:43 +00:00
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include "Statistics.h"
|
|
|
|
|
2008-10-25 12:35:55 +00:00
|
|
|
#include "VertexShaderManager.h"
|
|
|
|
#include "VertexLoader.h"
|
|
|
|
#include "VertexLoaderManager.h"
|
|
|
|
|
2008-10-25 15:53:43 +00:00
|
|
|
static int s_attr_dirty; // bitfield
|
2008-10-25 12:35:55 +00:00
|
|
|
|
2008-10-25 15:53:43 +00:00
|
|
|
static VertexLoader *g_VertexLoaders[8];
|
2008-10-25 12:35:55 +00:00
|
|
|
|
2008-10-25 13:27:28 +00:00
|
|
|
namespace VertexLoaderManager
|
|
|
|
{
|
2008-10-25 12:35:55 +00:00
|
|
|
|
2008-10-25 15:53:43 +00:00
|
|
|
typedef std::map<VertexLoaderUID, VertexLoader *> VertexLoaderMap;
|
|
|
|
static VertexLoaderMap g_VertexLoaderMap;
|
|
|
|
// TODO - change into array of pointers. Keep a map of all seen so far.
|
|
|
|
|
2008-10-25 13:27:28 +00:00
|
|
|
void Init()
|
|
|
|
{
|
2008-10-25 15:53:43 +00:00
|
|
|
MarkAllDirty();
|
2008-10-27 21:38:30 +00:00
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
g_VertexLoaders[i] = NULL;
|
2008-10-25 12:35:55 +00:00
|
|
|
}
|
|
|
|
|
2008-10-25 13:27:28 +00:00
|
|
|
void Shutdown()
|
|
|
|
{
|
2008-10-25 15:53:43 +00:00
|
|
|
for (VertexLoaderMap::iterator iter = g_VertexLoaderMap.begin(); iter != g_VertexLoaderMap.end(); ++iter)
|
|
|
|
{
|
|
|
|
delete iter->second;
|
|
|
|
}
|
|
|
|
g_VertexLoaderMap.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarkAllDirty()
|
|
|
|
{
|
|
|
|
s_attr_dirty = 0xff;
|
|
|
|
}
|
2008-10-25 12:35:55 +00:00
|
|
|
|
2008-10-27 21:38:30 +00:00
|
|
|
static void RefreshLoader(int vtx_attr_group)
|
2008-10-25 15:53:43 +00:00
|
|
|
{
|
2008-10-27 21:38:30 +00:00
|
|
|
if ((s_attr_dirty >> vtx_attr_group) & 1)
|
2008-10-25 15:53:43 +00:00
|
|
|
{
|
|
|
|
VertexLoaderUID uid;
|
|
|
|
uid.InitFromCurrentState(vtx_attr_group);
|
|
|
|
VertexLoaderMap::iterator iter = g_VertexLoaderMap.find(uid);
|
|
|
|
if (iter != g_VertexLoaderMap.end())
|
|
|
|
{
|
|
|
|
g_VertexLoaders[vtx_attr_group] = iter->second;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VertexLoader *loader = new VertexLoader(g_VtxDesc, g_VtxAttr[vtx_attr_group]);
|
|
|
|
g_VertexLoaderMap[uid] = loader;
|
|
|
|
g_VertexLoaders[vtx_attr_group] = loader;
|
|
|
|
INCSTAT(stats.numVertexLoaders);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s_attr_dirty &= ~(1 << vtx_attr_group);
|
2008-10-25 12:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RunVertices(int vtx_attr_group, int primitive, int count)
|
|
|
|
{
|
|
|
|
if (!count)
|
|
|
|
return;
|
2008-10-25 15:53:43 +00:00
|
|
|
RefreshLoader(vtx_attr_group);
|
|
|
|
g_VertexLoaders[vtx_attr_group]->RunVertices(vtx_attr_group, primitive, count);
|
2008-10-25 12:35:55 +00:00
|
|
|
}
|
|
|
|
|
2008-10-25 13:27:28 +00:00
|
|
|
int GetVertexSize(int vtx_attr_group)
|
|
|
|
{
|
2008-10-25 15:53:43 +00:00
|
|
|
RefreshLoader(vtx_attr_group);
|
|
|
|
return g_VertexLoaders[vtx_attr_group]->GetVertexSize();
|
2008-10-25 13:27:28 +00:00
|
|
|
}
|
2008-10-25 12:35:55 +00:00
|
|
|
|
2008-10-25 13:27:28 +00:00
|
|
|
} // namespace
|
2008-10-25 12:35:55 +00:00
|
|
|
|
|
|
|
void LoadCPReg(u32 sub_cmd, u32 value)
|
|
|
|
{
|
|
|
|
switch (sub_cmd & 0xF0)
|
|
|
|
{
|
|
|
|
case 0x30:
|
|
|
|
VertexShaderMngr::SetTexMatrixChangedA(value);
|
|
|
|
break;
|
2008-10-25 13:27:28 +00:00
|
|
|
|
2008-10-25 12:35:55 +00:00
|
|
|
case 0x40:
|
|
|
|
VertexShaderMngr::SetTexMatrixChangedB(value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x50:
|
2008-10-25 13:27:28 +00:00
|
|
|
g_VtxDesc.Hex &= ~0x1FFFF; // keep the Upper bits
|
|
|
|
g_VtxDesc.Hex |= value;
|
2008-10-25 15:53:43 +00:00
|
|
|
s_attr_dirty = 0xFF;
|
2008-10-25 12:35:55 +00:00
|
|
|
break;
|
2008-10-25 13:27:28 +00:00
|
|
|
|
2008-10-25 12:35:55 +00:00
|
|
|
case 0x60:
|
2008-10-25 13:27:28 +00:00
|
|
|
g_VtxDesc.Hex &= 0x1FFFF; // keep the lower 17Bits
|
|
|
|
g_VtxDesc.Hex |= (u64)value << 17;
|
2008-10-25 15:53:43 +00:00
|
|
|
s_attr_dirty = 0xFF;
|
2008-10-25 12:35:55 +00:00
|
|
|
break;
|
|
|
|
|
2008-10-25 13:27:28 +00:00
|
|
|
case 0x70:
|
|
|
|
_assert_((sub_cmd & 0x0F) < 8);
|
|
|
|
g_VtxAttr[sub_cmd & 7].g0.Hex = value;
|
2008-10-25 15:53:43 +00:00
|
|
|
s_attr_dirty |= 1 << (sub_cmd & 7);
|
2008-10-25 13:27:28 +00:00
|
|
|
break;
|
2008-10-25 12:35:55 +00:00
|
|
|
|
2008-10-25 13:27:28 +00:00
|
|
|
case 0x80:
|
|
|
|
_assert_((sub_cmd & 0x0F) < 8);
|
|
|
|
g_VtxAttr[sub_cmd & 7].g1.Hex = value;
|
2008-10-25 15:53:43 +00:00
|
|
|
s_attr_dirty |= 1 << (sub_cmd & 7);
|
2008-10-25 13:27:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x90:
|
|
|
|
_assert_((sub_cmd & 0x0F) < 8);
|
|
|
|
g_VtxAttr[sub_cmd & 7].g2.Hex = value;
|
2008-10-25 15:53:43 +00:00
|
|
|
s_attr_dirty |= 1 << (sub_cmd & 7);
|
2008-10-25 13:27:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Pointers to vertex arrays in GC RAM
|
|
|
|
case 0xA0:
|
|
|
|
arraybases[sub_cmd & 0xF] = value & 0xFFFFFFFF; // huh, why the mask?
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xB0:
|
|
|
|
arraystrides[sub_cmd & 0xF] = value & 0xFF;
|
|
|
|
break;
|
2008-10-25 12:35:55 +00:00
|
|
|
}
|
|
|
|
}
|