mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Readability, comments, tiny typo bugfix in gl gfx plugin (fix is on line 322 in pixelshadermanager)
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@930 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -161,7 +161,7 @@ void BPWritten(int addr, int changes, int newval)
|
|||||||
|
|
||||||
case BPMEM_LINEPTWIDTH:
|
case BPMEM_LINEPTWIDTH:
|
||||||
{
|
{
|
||||||
float fratio = VertexShaderMngr::rawViewport[0] != 0 ? (float)Renderer::GetTargetWidth() / 640.0f : 1.0f;
|
float fratio = VertexShaderMngr::GetPixelAspectRatio();
|
||||||
if (bpmem.lineptwidth.linesize > 0)
|
if (bpmem.lineptwidth.linesize > 0)
|
||||||
glLineWidth((float)bpmem.lineptwidth.linesize * fratio / 6.0f); // scale by ratio of widths
|
glLineWidth((float)bpmem.lineptwidth.linesize * fratio / 6.0f); // scale by ratio of widths
|
||||||
if (bpmem.lineptwidth.pointsize > 0)
|
if (bpmem.lineptwidth.pointsize > 0)
|
||||||
|
@ -133,7 +133,6 @@ FRAGMENTSHADER* PixelShaderMngr::GetShader()
|
|||||||
}
|
}
|
||||||
|
|
||||||
PSCacheEntry& newentry = pshaders[uid];
|
PSCacheEntry& newentry = pshaders[uid];
|
||||||
|
|
||||||
char *code = GeneratePixelShader(s_texturemask,
|
char *code = GeneratePixelShader(s_texturemask,
|
||||||
Renderer::GetZBufferTarget() != 0,
|
Renderer::GetZBufferTarget() != 0,
|
||||||
Renderer::GetRenderMode() != Renderer::RM_Normal);
|
Renderer::GetRenderMode() != Renderer::RM_Normal);
|
||||||
@ -184,9 +183,6 @@ void PixelShaderMngr::Cleanup()
|
|||||||
|
|
||||||
bool PixelShaderMngr::CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
|
bool PixelShaderMngr::CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
|
||||||
{
|
{
|
||||||
// todo: Should error be checked?
|
|
||||||
// CGerror cgerr = cgGetError();
|
|
||||||
|
|
||||||
char stropt[64];
|
char stropt[64];
|
||||||
sprintf(stropt, "MaxLocalParams=32,NumInstructionSlots=%d", s_nMaxPixelInstructions);
|
sprintf(stropt, "MaxLocalParams=32,NumInstructionSlots=%d", s_nMaxPixelInstructions);
|
||||||
const char* opts[] = {"-profileopts", stropt, "-O2", "-q", NULL};
|
const char* opts[] = {"-profileopts", stropt, "-O2", "-q", NULL};
|
||||||
@ -207,6 +203,7 @@ bool PixelShaderMngr::CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrpro
|
|||||||
|
|
||||||
if (Renderer::IsUsingATIDrawBuffers()) {
|
if (Renderer::IsUsingATIDrawBuffers()) {
|
||||||
// sometimes compilation can use ARB_draw_buffers, which would fail for ATI cards
|
// sometimes compilation can use ARB_draw_buffers, which would fail for ATI cards
|
||||||
|
// replace the three characters ARB with ATI. TODO - check whether this is fixed in modern ATI drivers.
|
||||||
char* poptions = strstr(pcompiledprog, "ARB_draw_buffers");
|
char* poptions = strstr(pcompiledprog, "ARB_draw_buffers");
|
||||||
if (poptions != NULL) {
|
if (poptions != NULL) {
|
||||||
poptions[0] = 'A';
|
poptions[0] = 'A';
|
||||||
@ -313,6 +310,7 @@ void PixelShaderMngr::SetConstants(FRAGMENTSHADER& ps)
|
|||||||
|
|
||||||
// indirect incoming texture scales, update all!
|
// indirect incoming texture scales, update all!
|
||||||
if (s_bIndTexScaleChanged) {
|
if (s_bIndTexScaleChanged) {
|
||||||
|
// set as two sets of vec4s, each containing S and T of two ind stages.
|
||||||
float f[8];
|
float f[8];
|
||||||
|
|
||||||
for (u32 i = 0; i < bpmem.genMode.numindstages; ++i) {
|
for (u32 i = 0; i < bpmem.genMode.numindstages; ++i) {
|
||||||
@ -321,7 +319,7 @@ void PixelShaderMngr::SetConstants(FRAGMENTSHADER& ps)
|
|||||||
TCoordInfo& tc = bpmem.texcoords[texcoord];
|
TCoordInfo& tc = bpmem.texcoords[texcoord];
|
||||||
|
|
||||||
f[2*i] = bpmem.texscale[i/2].getScaleS(i&1) * (float)(tc.s.scale_minus_1+1) / (float)(lastTexDims[srctexmap] & 0xffff);
|
f[2*i] = bpmem.texscale[i/2].getScaleS(i&1) * (float)(tc.s.scale_minus_1+1) / (float)(lastTexDims[srctexmap] & 0xffff);
|
||||||
f[2*i+1] = bpmem.texscale[i/2].getScaleT(i&1) * (float)(tc.t.scale_minus_1+1) / (float)((lastTexDims[srctexmap]>>16)&0xfff);
|
f[2*i+1] = bpmem.texscale[i/2].getScaleT(i&1) * (float)(tc.t.scale_minus_1+1) / (float)((lastTexDims[srctexmap] >> 16) & 0xffff);
|
||||||
|
|
||||||
PRIM_LOG("tex indscale%d: %f %f\n", i, f[2*i], f[2*i+1]);
|
PRIM_LOG("tex indscale%d: %f %f\n", i, f[2*i], f[2*i+1]);
|
||||||
}
|
}
|
||||||
@ -361,7 +359,6 @@ void PixelShaderMngr::SetConstants(FRAGMENTSHADER& ps)
|
|||||||
void PixelShaderMngr::SetPSTextureDims(int texid)
|
void PixelShaderMngr::SetPSTextureDims(int texid)
|
||||||
{
|
{
|
||||||
float fdims[4];
|
float fdims[4];
|
||||||
|
|
||||||
if (s_texturemask & (1<<texid)) {
|
if (s_texturemask & (1<<texid)) {
|
||||||
if (maptocoord[texid] >= 0) {
|
if (maptocoord[texid] >= 0) {
|
||||||
TCoordInfo& tc = bpmem.texcoords[maptocoord[texid]];
|
TCoordInfo& tc = bpmem.texcoords[maptocoord[texid]];
|
||||||
@ -392,7 +389,6 @@ void PixelShaderMngr::SetPSTextureDims(int texid)
|
|||||||
fdims[3] = 1.0f/(float)((lastTexDims[texid]>>16)&0xfff);
|
fdims[3] = 1.0f/(float)((lastTexDims[texid]>>16)&0xfff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PRIM_LOG("texdims%d: %f %f %f %f\n", texid, fdims[0], fdims[1], fdims[2], fdims[3]);
|
PRIM_LOG("texdims%d: %f %f %f %f\n", texid, fdims[0], fdims[1], fdims[2], fdims[3]);
|
||||||
SetPSConstant4fv(C_TEXDIMS + texid, fdims);
|
SetPSConstant4fv(C_TEXDIMS + texid, fdims);
|
||||||
}
|
}
|
||||||
@ -517,6 +513,8 @@ GLuint PixelShaderMngr::GetColorMatrixProgram()
|
|||||||
return s_ColorMatrixProgram;
|
return s_ColorMatrixProgram;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mash together all the inputs that contribute to the code of a generated pixel shader into
|
||||||
|
// a unique identifier, basically containing all the bits. Yup, it's a lot ....
|
||||||
void PixelShaderMngr::GetPixelShaderId(PixelShaderMngr::PIXELSHADERUID& uid)
|
void PixelShaderMngr::GetPixelShaderId(PixelShaderMngr::PIXELSHADERUID& uid)
|
||||||
{
|
{
|
||||||
u32 projtexcoords = 0;
|
u32 projtexcoords = 0;
|
||||||
@ -527,22 +525,25 @@ void PixelShaderMngr::GetPixelShaderId(PixelShaderMngr::PIXELSHADERUID& uid)
|
|||||||
projtexcoords |= 1 << texcoord;
|
projtexcoords |= 1 << texcoord;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 zbufrender = (Renderer::GetZBufferTarget() && bpmem.zmode.updateenable) ? 1 : 0;
|
u32 zbufrender = (Renderer::GetZBufferTarget() && bpmem.zmode.updateenable) ? 1 : 0;
|
||||||
u32 zBufRenderToCol0 = Renderer::GetRenderMode() != Renderer::RM_Normal;
|
u32 zBufRenderToCol0 = Renderer::GetRenderMode() != Renderer::RM_Normal;
|
||||||
uid.values[0] = (u32)bpmem.genMode.numtevstages|((u32)bpmem.genMode.numindstages<<4)|((u32)bpmem.genMode.numtexgens<<7)
|
uid.values[0] = (u32)bpmem.genMode.numtevstages |
|
||||||
|((u32)bpmem.dstalpha.enable<<11)|((u32)((bpmem.alphaFunc.hex>>16)&0xff)<<12)|(projtexcoords<<20)|((u32)bpmem.ztex2.op<<28)
|
((u32)bpmem.genMode.numindstages << 4) |
|
||||||
|(zbufrender<<30)|(zBufRenderToCol0<<31);
|
((u32)bpmem.genMode.numtexgens << 7) |
|
||||||
|
((u32)bpmem.dstalpha.enable << 11) |
|
||||||
|
((u32)((bpmem.alphaFunc.hex >> 16) & 0xff) << 12) |
|
||||||
|
(projtexcoords << 20) |
|
||||||
|
((u32)bpmem.ztex2.op << 28) |
|
||||||
|
(zbufrender << 30) |
|
||||||
|
(zBufRenderToCol0 << 31);
|
||||||
|
|
||||||
s_curuid.values[0] = (s_curuid.values[0] & ~0x0ff00000) | (projtexcoords << 20);
|
s_curuid.values[0] = (s_curuid.values[0] & ~0x0ff00000) | (projtexcoords << 20);
|
||||||
|
|
||||||
// swap table
|
// swap table
|
||||||
for (int i = 0; i < 8; i += 2)
|
for (int i = 0; i < 8; i += 2)
|
||||||
((u8*)&uid.values[1])[i/2] = (bpmem.tevksel[i].hex & 0xf) | ((bpmem.tevksel[i + 1].hex & 0xf)<<4);
|
((u8*)&uid.values[1])[i/2] = (bpmem.tevksel[i].hex & 0xf) | ((bpmem.tevksel[i + 1].hex & 0xf)<<4);
|
||||||
|
|
||||||
uid.values[2] = s_texturemask;
|
uid.values[2] = s_texturemask;
|
||||||
int hdr = 3;
|
int hdr = 3;
|
||||||
|
|
||||||
u32* pcurvalue = &uid.values[hdr];
|
u32* pcurvalue = &uid.values[hdr];
|
||||||
for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages+1; ++i) {
|
for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages+1; ++i) {
|
||||||
TevStageCombiner::ColorCombiner &cc = bpmem.combiners[i].colorC;
|
TevStageCombiner::ColorCombiner &cc = bpmem.combiners[i].colorC;
|
||||||
@ -552,7 +553,6 @@ void PixelShaderMngr::GetPixelShaderId(PixelShaderMngr::PIXELSHADERUID& uid)
|
|||||||
u32 val1 = ac.hex&0xffffff;
|
u32 val1 = ac.hex&0xffffff;
|
||||||
val0 |= bpmem.tevksel[i/2].getKC(i&1)<<24;
|
val0 |= bpmem.tevksel[i/2].getKC(i&1)<<24;
|
||||||
val1 |= bpmem.tevksel[i/2].getKA(i&1)<<24;
|
val1 |= bpmem.tevksel[i/2].getKA(i&1)<<24;
|
||||||
|
|
||||||
pcurvalue[0] = val0;
|
pcurvalue[0] = val0;
|
||||||
pcurvalue[1] = val1;
|
pcurvalue[1] = val1;
|
||||||
pcurvalue += 2;
|
pcurvalue += 2;
|
||||||
@ -560,10 +560,14 @@ void PixelShaderMngr::GetPixelShaderId(PixelShaderMngr::PIXELSHADERUID& uid)
|
|||||||
|
|
||||||
for (u32 i = 0; i < ((u32)bpmem.genMode.numtevstages+1)/2; ++i) {
|
for (u32 i = 0; i < ((u32)bpmem.genMode.numtevstages+1)/2; ++i) {
|
||||||
u32 val0, val1;
|
u32 val0, val1;
|
||||||
if (bpmem.tevorders[i].hex&0x40 ) val0 = bpmem.tevorders[i].hex&0x3ff;
|
if (bpmem.tevorders[i].hex & 0x40)
|
||||||
else val0 = bpmem.tevorders[i].hex&0x380;
|
val0 = bpmem.tevorders[i].hex & 0x3ff;
|
||||||
if (bpmem.tevorders[i].hex&0x40000 ) val1 = (bpmem.tevorders[i].hex&0x3ff000)>>12;
|
else
|
||||||
else val1 = (bpmem.tevorders[i].hex&0x380000)>>12;
|
val0 = bpmem.tevorders[i].hex & 0x380;
|
||||||
|
if (bpmem.tevorders[i].hex & 0x40000)
|
||||||
|
val1 = (bpmem.tevorders[i].hex & 0x3ff000) >> 12;
|
||||||
|
else
|
||||||
|
val1 = (bpmem.tevorders[i].hex & 0x380000) >> 12;
|
||||||
|
|
||||||
switch (i % 3) {
|
switch (i % 3) {
|
||||||
case 0: pcurvalue[0] = val0|(val1<<10); break;
|
case 0: pcurvalue[0] = val0|(val1<<10); break;
|
||||||
@ -574,13 +578,15 @@ void PixelShaderMngr::GetPixelShaderId(PixelShaderMngr::PIXELSHADERUID& uid)
|
|||||||
|
|
||||||
if ((bpmem.genMode.numtevstages + 1) & 1) { // odd
|
if ((bpmem.genMode.numtevstages + 1) & 1) { // odd
|
||||||
u32 val0;
|
u32 val0;
|
||||||
if (bpmem.tevorders[bpmem.genMode.numtevstages/2].hex&0x40 ) val0 = bpmem.tevorders[bpmem.genMode.numtevstages/2].hex&0x3ff;
|
if (bpmem.tevorders[bpmem.genMode.numtevstages/2].hex & 0x40)
|
||||||
else val0 = bpmem.tevorders[bpmem.genMode.numtevstages/2].hex&0x380;
|
val0 = bpmem.tevorders[bpmem.genMode.numtevstages/2].hex&0x3ff;
|
||||||
|
else
|
||||||
|
val0 = bpmem.tevorders[bpmem.genMode.numtevstages/2].hex & 0x380;
|
||||||
|
|
||||||
switch (bpmem.genMode.numtevstages % 3) {
|
switch (bpmem.genMode.numtevstages % 3) {
|
||||||
case 0: pcurvalue[0] = val0; break;
|
case 0: pcurvalue[0] = val0; break;
|
||||||
case 1: pcurvalue[0] |= val0 << 20; break;
|
case 1: pcurvalue[0] |= val0 << 20; break;
|
||||||
case 2: pcurvalue[1] |= (val0<<10); pcurvalue++; break;
|
case 2: pcurvalue[1] |= val0 << 10; pcurvalue++; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -598,5 +604,6 @@ void PixelShaderMngr::GetPixelShaderId(PixelShaderMngr::PIXELSHADERUID& uid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// yeah, well ....
|
||||||
uid.indstages = (u32)(pcurvalue - &uid.values[0] - 2 - uid.tevstages);
|
uid.indstages = (u32)(pcurvalue - &uid.values[0] - 2 - uid.tevstages);
|
||||||
}
|
}
|
||||||
|
@ -137,13 +137,15 @@ VertexLoader::~VertexLoader()
|
|||||||
int VertexLoader::ComputeVertexSize()
|
int VertexLoader::ComputeVertexSize()
|
||||||
{
|
{
|
||||||
if (!m_AttrDirty) {
|
if (!m_AttrDirty) {
|
||||||
if (m_VtxDesc.Hex0 == VertexManager::GetVtxDesc().Hex0 && (m_VtxDesc.Hex1&1)==(VertexManager::GetVtxDesc().Hex1&1))
|
// Compare the 33 desc bits.
|
||||||
|
if (m_VtxDesc.Hex0 == VertexManager::GetVtxDesc().Hex0 &&
|
||||||
|
(m_VtxDesc.Hex1 & 1) == (VertexManager::GetVtxDesc().Hex1 & 1))
|
||||||
return m_VertexSize;
|
return m_VertexSize;
|
||||||
|
|
||||||
m_VtxDesc.Hex = VertexManager::GetVtxDesc().Hex;
|
m_VtxDesc.Hex = VertexManager::GetVtxDesc().Hex;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// set anyway
|
// Attributes are dirty so we have to recompute everything anyway.
|
||||||
m_VtxDesc.Hex = VertexManager::GetVtxDesc().Hex;
|
m_VtxDesc.Hex = VertexManager::GetVtxDesc().Hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,14 +159,14 @@ int VertexLoader::ComputeVertexSize()
|
|||||||
m_VertexSize += 1;
|
m_VertexSize += 1;
|
||||||
|
|
||||||
// Texture matrix indices
|
// Texture matrix indices
|
||||||
if (m_VtxDesc.Tex0MatIdx) {m_VertexSize+=1; }
|
if (m_VtxDesc.Tex0MatIdx) m_VertexSize += 1;
|
||||||
if (m_VtxDesc.Tex1MatIdx) {m_VertexSize+=1; }
|
if (m_VtxDesc.Tex1MatIdx) m_VertexSize += 1;
|
||||||
if (m_VtxDesc.Tex2MatIdx) {m_VertexSize+=1; }
|
if (m_VtxDesc.Tex2MatIdx) m_VertexSize += 1;
|
||||||
if (m_VtxDesc.Tex3MatIdx) {m_VertexSize+=1; }
|
if (m_VtxDesc.Tex3MatIdx) m_VertexSize += 1;
|
||||||
if (m_VtxDesc.Tex4MatIdx) {m_VertexSize+=1; }
|
if (m_VtxDesc.Tex4MatIdx) m_VertexSize += 1;
|
||||||
if (m_VtxDesc.Tex5MatIdx) {m_VertexSize+=1; }
|
if (m_VtxDesc.Tex5MatIdx) m_VertexSize += 1;
|
||||||
if (m_VtxDesc.Tex6MatIdx) {m_VertexSize+=1; }
|
if (m_VtxDesc.Tex6MatIdx) m_VertexSize += 1;
|
||||||
if (m_VtxDesc.Tex7MatIdx) {m_VertexSize+=1; }
|
if (m_VtxDesc.Tex7MatIdx) m_VertexSize += 1;
|
||||||
|
|
||||||
switch (m_VtxDesc.Position) {
|
switch (m_VtxDesc.Position) {
|
||||||
case NOT_PRESENT: {_assert_("Vertex descriptor without position!");} break;
|
case NOT_PRESENT: {_assert_("Vertex descriptor without position!");} break;
|
||||||
@ -396,7 +398,6 @@ void VertexLoader::ProcessFormat()
|
|||||||
// Texture matrix indices (remove if corresponding texture coordinate isn't enabled)
|
// Texture matrix indices (remove if corresponding texture coordinate isn't enabled)
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
SetupTexCoord(i, tc[i], m_VtxAttr.texCoord[i].Format, m_VtxAttr.texCoord[i].Elements, m_VtxAttr.texCoord[i].Frac);
|
SetupTexCoord(i, tc[i], m_VtxAttr.texCoord[i].Format, m_VtxAttr.texCoord[i].Elements, m_VtxAttr.texCoord[i].Frac);
|
||||||
|
|
||||||
if (m_components & (VB_HAS_TEXMTXIDX0 << i)) {
|
if (m_components & (VB_HAS_TEXMTXIDX0 << i)) {
|
||||||
if (tc[i] != NOT_PRESENT) {
|
if (tc[i] != NOT_PRESENT) {
|
||||||
// if texmtx is included, texcoord will always be 3 floats, z will be the texmtx index
|
// if texmtx is included, texcoord will always be 3 floats, z will be the texmtx index
|
||||||
@ -719,6 +720,7 @@ void VertexLoader::RunVertices(int primitive, int count)
|
|||||||
if ((v % granularity) == 0)
|
if ((v % granularity) == 0)
|
||||||
{
|
{
|
||||||
if (VertexManager::GetRemainingSize() < granularity*m_VBVertexStride) {
|
if (VertexManager::GetRemainingSize() < granularity*m_VBVertexStride) {
|
||||||
|
// This buffer full - break current primitive and flush, to switch to the next buffer.
|
||||||
u8* plastptr = VertexManager::s_pCurBufferPointer;
|
u8* plastptr = VertexManager::s_pCurBufferPointer;
|
||||||
if (v - startv > 0)
|
if (v - startv > 0)
|
||||||
VertexManager::AddVertices(primitive, v - startv + extraverts);
|
VertexManager::AddVertices(primitive, v - startv + extraverts);
|
||||||
|
@ -24,7 +24,7 @@ static u32 s_prevcomponents; // previous state set
|
|||||||
|
|
||||||
u8* VertexManager::s_pCurBufferPointer = NULL;
|
u8* VertexManager::s_pCurBufferPointer = NULL;
|
||||||
|
|
||||||
const GLenum c_primitiveType[8] =
|
static const GLenum c_primitiveType[8] =
|
||||||
{
|
{
|
||||||
GL_QUADS,
|
GL_QUADS,
|
||||||
0, //nothing
|
0, //nothing
|
||||||
@ -57,6 +57,7 @@ bool VertexManager::Init()
|
|||||||
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
fnSetupVertexPointers = NULL;
|
fnSetupVertexPointers = NULL;
|
||||||
|
s_vStoredPrimitives.reserve(1000);
|
||||||
GL_REPORT_ERRORD();
|
GL_REPORT_ERRORD();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -245,6 +246,9 @@ void VertexManager::Flush()
|
|||||||
PixelShaderMngr::SetConstants(*ps);
|
PixelShaderMngr::SetConstants(*ps);
|
||||||
|
|
||||||
// finally bind
|
// finally bind
|
||||||
|
|
||||||
|
// TODO - cache progid, check if same as before. Maybe GL does this internally, though.
|
||||||
|
// This is the really annoying problem with GL - you never know whether it's worth caching stuff yourself.
|
||||||
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vs->glprogid);
|
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vs->glprogid);
|
||||||
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ps->glprogid);
|
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ps->glprogid);
|
||||||
|
|
||||||
@ -253,7 +257,8 @@ void VertexManager::Flush()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
for (vector< pair<int, int> >::const_iterator it = s_vStoredPrimitives.begin(); it != s_vStoredPrimitives.end(); ++it) {
|
for (vector< pair<int, int> >::const_iterator it = s_vStoredPrimitives.begin(); it != s_vStoredPrimitives.end(); ++it)
|
||||||
|
{
|
||||||
glDrawArrays(it->first, offset, it->second);
|
glDrawArrays(it->first, offset, it->second);
|
||||||
offset += it->second;
|
offset += it->second;
|
||||||
}
|
}
|
||||||
|
@ -36,24 +36,23 @@
|
|||||||
|
|
||||||
VertexShaderMngr::VSCache VertexShaderMngr::vshaders;
|
VertexShaderMngr::VSCache VertexShaderMngr::vshaders;
|
||||||
VERTEXSHADER* VertexShaderMngr::pShaderLast = NULL;
|
VERTEXSHADER* VertexShaderMngr::pShaderLast = NULL;
|
||||||
float VertexShaderMngr::rawViewport[6] = {0};
|
|
||||||
float VertexShaderMngr::rawProjection[7] = {0};
|
|
||||||
float GC_ALIGNED16(g_fProjectionMatrix[16]);
|
float GC_ALIGNED16(g_fProjectionMatrix[16]);
|
||||||
|
|
||||||
static int s_nMaxVertexInstructions;
|
|
||||||
extern int A, B;
|
extern int A, B;
|
||||||
extern float AR;
|
extern float AR;
|
||||||
extern int nBackbufferWidth, nBackbufferHeight;
|
extern int nBackbufferWidth, nBackbufferHeight;
|
||||||
|
|
||||||
////////////////////////
|
// Internal Variables
|
||||||
// Internal Variables //
|
static int s_nMaxVertexInstructions;
|
||||||
////////////////////////
|
|
||||||
static float s_fMaterials[16];
|
|
||||||
|
|
||||||
|
static float s_fMaterials[16];
|
||||||
|
static float rawViewport[6] = {0};
|
||||||
|
static float rawProjection[7] = {0};
|
||||||
|
|
||||||
// track changes
|
// track changes
|
||||||
static bool bTexMatricesChanged[2], bPosNormalMatrixChanged, bProjectionChanged, bViewportChanged;
|
static bool bTexMatricesChanged[2], bPosNormalMatrixChanged, bProjectionChanged, bViewportChanged;
|
||||||
int nMaterialsChanged;
|
static int nMaterialsChanged;
|
||||||
static int nTransformMatricesChanged[2]; // min,max
|
static int nTransformMatricesChanged[2]; // min,max
|
||||||
static int nNormalMatricesChanged[2]; // min,max
|
static int nNormalMatricesChanged[2]; // min,max
|
||||||
static int nPostTransformMatricesChanged[2]; // min,max
|
static int nPostTransformMatricesChanged[2]; // min,max
|
||||||
@ -85,12 +84,15 @@ void VertexShaderMngr::Init()
|
|||||||
|
|
||||||
void VertexShaderMngr::Shutdown()
|
void VertexShaderMngr::Shutdown()
|
||||||
{
|
{
|
||||||
VSCache::iterator iter = vshaders.begin();
|
for (VSCache::iterator iter = vshaders.begin(); iter != vshaders.end(); iter++)
|
||||||
for (;iter!=vshaders.end();iter++)
|
|
||||||
iter->second.Destroy();
|
iter->second.Destroy();
|
||||||
vshaders.clear();
|
vshaders.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float VertexShaderMngr::GetPixelAspectRatio() {
|
||||||
|
return rawViewport[0] != 0 ? (float)Renderer::GetTargetWidth() / 640.0f : 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
VERTEXSHADER* VertexShaderMngr::GetShader(u32 components)
|
VERTEXSHADER* VertexShaderMngr::GetShader(u32 components)
|
||||||
{
|
{
|
||||||
DVSTARTPROFILE();
|
DVSTARTPROFILE();
|
||||||
@ -268,11 +270,17 @@ void VertexShaderMngr::SetConstants(VERTEXSHADER& vs)
|
|||||||
for (int i = istart; i < iend; ++i) {
|
for (int i = istart; i < iend; ++i) {
|
||||||
u32 color = *(const u32*)(xfmemptr + 3);
|
u32 color = *(const u32*)(xfmemptr + 3);
|
||||||
SetVSConstant4f(C_LIGHTS + 5*i,
|
SetVSConstant4f(C_LIGHTS + 5*i,
|
||||||
((color>>24)&0xFF)/255.0f, ((color>>16)&0xFF)/255.0f, ((color>>8)&0xFF)/255.0f, ((color)&0xFF)/255.0f);
|
((color >> 24) & 0xFF)/255.0f,
|
||||||
|
((color >> 16) & 0xFF)/255.0f,
|
||||||
|
((color >> 8) & 0xFF)/255.0f,
|
||||||
|
((color) & 0xFF)/255.0f);
|
||||||
xfmemptr += 4;
|
xfmemptr += 4;
|
||||||
for (int j = 0; j < 4; ++j, xfmemptr += 3) {
|
for (int j = 0; j < 4; ++j, xfmemptr += 3) {
|
||||||
if( j == 1 && fabs(xfmemptr[0]) < 0.00001f && fabs(xfmemptr[1]) < 0.00001f && fabs(xfmemptr[2]) < 0.00001f) {
|
if (j == 1 &&
|
||||||
// dist atten, make sure not equal to 0!!!
|
fabs(xfmemptr[0]) < 0.00001f &&
|
||||||
|
fabs(xfmemptr[1]) < 0.00001f &&
|
||||||
|
fabs(xfmemptr[2]) < 0.00001f) {
|
||||||
|
// dist attenuation, make sure not equal to 0!!!
|
||||||
SetVSConstant4f(C_LIGHTS+5*i+j+1, 0.00001f, xfmemptr[1], xfmemptr[2], 0);
|
SetVSConstant4f(C_LIGHTS+5*i+j+1, 0.00001f, xfmemptr[1], xfmemptr[2], 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -307,9 +315,10 @@ void VertexShaderMngr::SetConstants(VERTEXSHADER& vs)
|
|||||||
|
|
||||||
if (bTexMatricesChanged[0]) {
|
if (bTexMatricesChanged[0]) {
|
||||||
bTexMatricesChanged[0] = false;
|
bTexMatricesChanged[0] = false;
|
||||||
|
float* fptrs[] = {
|
||||||
float* fptrs[] = {(float*)xfmem + MatrixIndexA.Tex0MtxIdx * 4, (float*)xfmem + MatrixIndexA.Tex1MtxIdx * 4,
|
(float*)xfmem + MatrixIndexA.Tex0MtxIdx * 4, (float*)xfmem + MatrixIndexA.Tex1MtxIdx * 4,
|
||||||
(float*)xfmem + MatrixIndexA.Tex2MtxIdx * 4, (float*)xfmem + MatrixIndexA.Tex3MtxIdx * 4 };
|
(float*)xfmem + MatrixIndexA.Tex2MtxIdx * 4, (float*)xfmem + MatrixIndexA.Tex3MtxIdx * 4
|
||||||
|
};
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
SetVSConstant4fv(C_TEXMATRICES+3*i, fptrs[i]);
|
SetVSConstant4fv(C_TEXMATRICES+3*i, fptrs[i]);
|
||||||
@ -352,8 +361,10 @@ void VertexShaderMngr::SetConstants(VERTEXSHADER& vs)
|
|||||||
int scissorYOff = bpmem.scissorOffset.y * 2 - 342;
|
int scissorYOff = bpmem.scissorOffset.y * 2 - 342;
|
||||||
float fourThree = 4.0f / 3.0f;
|
float fourThree = 4.0f / 3.0f;
|
||||||
float ratio = AR / fourThree;
|
float ratio = AR / fourThree;
|
||||||
float hAdj; float wAdj; float actualRatiow; float actualRatioh;
|
float wAdj, hAdj;
|
||||||
int overfl; int xoffs = 0; int yoffs = 0;
|
float actualRatiow, actualRatioh;
|
||||||
|
int overfl;
|
||||||
|
int xoffs = 0, yoffs = 0;
|
||||||
int wid, hei, actualWid, actualHei;
|
int wid, hei, actualWid, actualHei;
|
||||||
int winw = nBackbufferWidth; int winh = nBackbufferHeight;
|
int winw = nBackbufferWidth; int winh = nBackbufferHeight;
|
||||||
if (g_Config.bKeepAR)
|
if (g_Config.bKeepAR)
|
||||||
@ -420,17 +431,17 @@ void VertexShaderMngr::SetConstants(VERTEXSHADER& vs)
|
|||||||
g_fProjectionMatrix[0] = rawProjection[0];
|
g_fProjectionMatrix[0] = rawProjection[0];
|
||||||
g_fProjectionMatrix[1] = 0.0f;
|
g_fProjectionMatrix[1] = 0.0f;
|
||||||
g_fProjectionMatrix[2] = rawProjection[1];
|
g_fProjectionMatrix[2] = rawProjection[1];
|
||||||
g_fProjectionMatrix[3] = 0;//-0.5f/Renderer::GetTargetWidth();
|
g_fProjectionMatrix[3] = 0;
|
||||||
|
|
||||||
g_fProjectionMatrix[4] = 0.0f;
|
g_fProjectionMatrix[4] = 0.0f;
|
||||||
g_fProjectionMatrix[5] = rawProjection[2];
|
g_fProjectionMatrix[5] = rawProjection[2];
|
||||||
g_fProjectionMatrix[6] = rawProjection[3];
|
g_fProjectionMatrix[6] = rawProjection[3];
|
||||||
g_fProjectionMatrix[7] = 0;//+0.5f/Renderer::GetTargetHeight();
|
g_fProjectionMatrix[7] = 0;
|
||||||
|
|
||||||
g_fProjectionMatrix[8] = 0.0f;
|
g_fProjectionMatrix[8] = 0.0f;
|
||||||
g_fProjectionMatrix[9] = 0.0f;
|
g_fProjectionMatrix[9] = 0.0f;
|
||||||
g_fProjectionMatrix[10] = rawProjection[4];
|
g_fProjectionMatrix[10] = rawProjection[4];
|
||||||
g_fProjectionMatrix[11] = -(0.0f - rawProjection[5]);
|
g_fProjectionMatrix[11] = -(0.0f - rawProjection[5]); // Yes, it's important that it's done this way.
|
||||||
|
|
||||||
g_fProjectionMatrix[12] = 0.0f;
|
g_fProjectionMatrix[12] = 0.0f;
|
||||||
g_fProjectionMatrix[13] = 0.0f;
|
g_fProjectionMatrix[13] = 0.0f;
|
||||||
@ -451,7 +462,7 @@ void VertexShaderMngr::SetConstants(VERTEXSHADER& vs)
|
|||||||
g_fProjectionMatrix[8] = 0.0f;
|
g_fProjectionMatrix[8] = 0.0f;
|
||||||
g_fProjectionMatrix[9] = 0.0f;
|
g_fProjectionMatrix[9] = 0.0f;
|
||||||
g_fProjectionMatrix[10] = rawProjection[4];
|
g_fProjectionMatrix[10] = rawProjection[4];
|
||||||
g_fProjectionMatrix[11] = -(0.0f - rawProjection[5]);
|
g_fProjectionMatrix[11] = -(0.0f - rawProjection[5]); // Yes, it's important that it's done this way.
|
||||||
|
|
||||||
g_fProjectionMatrix[12] = 0;
|
g_fProjectionMatrix[12] = 0;
|
||||||
g_fProjectionMatrix[13] = 0;
|
g_fProjectionMatrix[13] = 0;
|
||||||
@ -564,10 +575,10 @@ void VertexShaderMngr::SetTexMatrixChangedB(u32 Value)
|
|||||||
|
|
||||||
void VertexShaderMngr::SetViewport(float* _Viewport)
|
void VertexShaderMngr::SetViewport(float* _Viewport)
|
||||||
{
|
{
|
||||||
// check for paper mario
|
// Workaround for paper mario, yep this is bizarre.
|
||||||
for (size_t i = 0; i < ARRAYSIZE(rawViewport); ++i) {
|
for (size_t i = 0; i < ARRAYSIZE(rawViewport); ++i) {
|
||||||
if( *(u32*)(_Viewport + i) == 0x7f800000 )
|
if (*(u32*)(_Viewport + i) == 0x7f800000) // invalid fp number
|
||||||
return; // invalid number
|
return;
|
||||||
}
|
}
|
||||||
memcpy(rawViewport, _Viewport, sizeof(rawViewport));
|
memcpy(rawViewport, _Viewport, sizeof(rawViewport));
|
||||||
bViewportChanged = true;
|
bViewportChanged = true;
|
||||||
@ -723,16 +734,16 @@ void VertexShaderMngr::LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData)
|
|||||||
break;
|
break;
|
||||||
case 0x1018:
|
case 0x1018:
|
||||||
//_assert_msg_(GX_XF, 0, "XF matrixindex0");
|
//_assert_msg_(GX_XF, 0, "XF matrixindex0");
|
||||||
VertexShaderMngr::SetTexMatrixChangedA(data); //?
|
SetTexMatrixChangedA(data); //?
|
||||||
break;
|
break;
|
||||||
case 0x1019:
|
case 0x1019:
|
||||||
//_assert_msg_(GX_XF, 0, "XF matrixindex1");
|
//_assert_msg_(GX_XF, 0, "XF matrixindex1");
|
||||||
VertexShaderMngr::SetTexMatrixChangedB(data); //?
|
SetTexMatrixChangedB(data); //?
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x101a:
|
case 0x101a:
|
||||||
VertexManager::Flush();
|
VertexManager::Flush();
|
||||||
VertexShaderMngr::SetViewport((float*)&pData[i]);
|
SetViewport((float*)&pData[i]);
|
||||||
i += 6;
|
i += 6;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -795,7 +806,7 @@ void VertexShaderMngr::LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check docs for this sucker...
|
// TODO - verify that it is correct. Seems to work, though.
|
||||||
void VertexShaderMngr::LoadIndexedXF(u32 val, int array)
|
void VertexShaderMngr::LoadIndexedXF(u32 val, int array)
|
||||||
{
|
{
|
||||||
int index = val >> 16;
|
int index = val >> 16;
|
||||||
@ -816,21 +827,31 @@ float* VertexShaderMngr::GetPosNormalMat()
|
|||||||
return (float*)xfmem + MatrixIndexA.PosNormalMtxIdx * 4;
|
return (float*)xfmem + MatrixIndexA.PosNormalMtxIdx * 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mash together all the inputs that contribute to the code of a generated vertex shader into
|
||||||
|
// a unique identifier, basically containing all the bits. Yup, it's a lot ....
|
||||||
void VertexShaderMngr::GetVertexShaderId(VERTEXSHADERUID& id, u32 components)
|
void VertexShaderMngr::GetVertexShaderId(VERTEXSHADERUID& id, u32 components)
|
||||||
{
|
{
|
||||||
u32 zbufrender = (bpmem.ztex2.op == ZTEXTURE_ADD) || Renderer::GetZBufferTarget() != 0;
|
u32 zbufrender = (bpmem.ztex2.op == ZTEXTURE_ADD) || Renderer::GetZBufferTarget() != 0;
|
||||||
id.values[0] = components|(xfregs.numTexGens<<23)|(xfregs.nNumChans<<27)|((u32)xfregs.bEnableDualTexTransform<<29)|(zbufrender<<30);
|
id.values[0] = components |
|
||||||
|
(xfregs.numTexGens << 23) |
|
||||||
|
(xfregs.nNumChans << 27) |
|
||||||
|
((u32)xfregs.bEnableDualTexTransform << 29) |
|
||||||
|
(zbufrender << 30);
|
||||||
|
|
||||||
for (int i = 0; i < 2; ++i) {
|
for (int i = 0; i < 2; ++i) {
|
||||||
id.values[1+i] = xfregs.colChans[i].color.enablelighting?(u32)xfregs.colChans[i].color.hex:(u32)xfregs.colChans[i].color.matsource;
|
id.values[1+i] = xfregs.colChans[i].color.enablelighting ?
|
||||||
id.values[1+i] |= (xfregs.colChans[i].alpha.enablelighting?(u32)xfregs.colChans[i].alpha.hex:(u32)xfregs.colChans[i].alpha.matsource)<<15;
|
(u32)xfregs.colChans[i].color.hex :
|
||||||
|
(u32)xfregs.colChans[i].color.matsource;
|
||||||
|
id.values[1+i] |= (xfregs.colChans[i].alpha.enablelighting ?
|
||||||
|
(u32)xfregs.colChans[i].alpha.hex :
|
||||||
|
(u32)xfregs.colChans[i].alpha.matsource) << 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fog
|
// fog
|
||||||
id.values[1] |= (((u32)bpmem.fog.c_proj_fsel.fsel & 3) << 30);
|
id.values[1] |= (((u32)bpmem.fog.c_proj_fsel.fsel & 3) << 30);
|
||||||
id.values[2] |= (((u32)bpmem.fog.c_proj_fsel.fsel >> 2) << 30);
|
id.values[2] |= (((u32)bpmem.fog.c_proj_fsel.fsel >> 2) << 30);
|
||||||
|
|
||||||
u32* pcurvalue = &id.values[3];
|
u32* pcurvalue = &id.values[3];
|
||||||
|
|
||||||
for (int i = 0; i < xfregs.numTexGens; ++i) {
|
for (int i = 0; i < xfregs.numTexGens; ++i) {
|
||||||
TexMtxInfo tinfo = xfregs.texcoords[i].texmtxinfo;
|
TexMtxInfo tinfo = xfregs.texcoords[i].texmtxinfo;
|
||||||
if (tinfo.texgentype != XF_TEXGEN_EMBOSS_MAP)
|
if (tinfo.texgentype != XF_TEXGEN_EMBOSS_MAP)
|
||||||
|
@ -123,9 +123,7 @@ public:
|
|||||||
static void LoadIndexedXF(u32 val, int array);
|
static void LoadIndexedXF(u32 val, int array);
|
||||||
|
|
||||||
static float* GetPosNormalMat();
|
static float* GetPosNormalMat();
|
||||||
|
static float GetPixelAspectRatio();
|
||||||
static float rawViewport[6];
|
|
||||||
static float rawProjection[7];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user