mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
GFX: updated Dates, code formatting cleanup, code cleanup / organization, some unknown BPs uncovered, fixed OGL's config dialog bug, added another shader
DSPHLE: Some warning fixes and added some logging for unknown voice cases Please report if anything has broken. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3884 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
// Copyright (C) 2003-2009 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
|
||||
@ -72,14 +72,13 @@ void VertexShaderManager::Init()
|
||||
|
||||
void VertexShaderManager::Shutdown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// =======================================================================================
|
||||
// Syncs the shader constant buffers with xfmem
|
||||
// ----------------
|
||||
// TODO: A cleaner way to control the matricies without making a mess in the parameters field
|
||||
void VertexShaderManager::SetConstants(bool proj_hax_1,bool Hack_hack1 ,float Hack_value1 ,bool Hack_hack2 ,float Hack_value2 ,bool freeLook)
|
||||
{
|
||||
|
||||
// TODO: Is this still needed?
|
||||
//nTransformMatricesChanged[0] = 0; nTransformMatricesChanged[1] = 256;
|
||||
//nNormalMatricesChanged[0] = 0; nNormalMatricesChanged[1] = 96;
|
||||
//nPostTransformMatricesChanged[0] = 0; nPostTransformMatricesChanged[1] = 256;
|
||||
@ -87,55 +86,63 @@ void VertexShaderManager::SetConstants(bool proj_hax_1,bool Hack_hack1 ,float Ha
|
||||
//bPosNormalMatrixChanged = true;
|
||||
//bTexMatricesChanged[0] = bTexMatricesChanged[1] = true;
|
||||
//bProjectionChanged = true;
|
||||
// bPosNormalMatrixChanged = bTexMatricesChanged[0] = bTexMatricesChanged[1] = true;
|
||||
// nMaterialsChanged = 15;
|
||||
//bPosNormalMatrixChanged = bTexMatricesChanged[0] = bTexMatricesChanged[1] = true;
|
||||
//nMaterialsChanged = 15;
|
||||
|
||||
if (nTransformMatricesChanged[0] >= 0) {
|
||||
int startn = nTransformMatricesChanged[0]/4;
|
||||
int endn = (nTransformMatricesChanged[1]+3)/4;
|
||||
const float* pstart = (const float*)&xfmem[startn*4];
|
||||
if (nTransformMatricesChanged[0] >= 0)
|
||||
{
|
||||
int startn = nTransformMatricesChanged[0] / 4;
|
||||
int endn = (nTransformMatricesChanged[1] + 3) / 4;
|
||||
const float* pstart = (const float*)&xfmem[startn * 4];
|
||||
for(int i = startn; i < endn; ++i, pstart += 4)
|
||||
SetVSConstant4fv(C_TRANSFORMMATRICES+i, pstart);
|
||||
SetVSConstant4fv(C_TRANSFORMMATRICES + i, pstart);
|
||||
nTransformMatricesChanged[0] = nTransformMatricesChanged[1] = -1;
|
||||
}
|
||||
if (nNormalMatricesChanged[0] >= 0) {
|
||||
int startn = nNormalMatricesChanged[0]/3;
|
||||
int endn = (nNormalMatricesChanged[1]+2)/3;
|
||||
if (nNormalMatricesChanged[0] >= 0)
|
||||
{
|
||||
int startn = nNormalMatricesChanged[0] / 3;
|
||||
int endn = (nNormalMatricesChanged[1] + 2) / 3;
|
||||
const float* pnstart = (const float*)&xfmem[XFMEM_NORMALMATRICES+3*startn];
|
||||
|
||||
for(int i = startn; i < endn; ++i, pnstart += 3)
|
||||
SetVSConstant4fv(C_NORMALMATRICES+i, pnstart);
|
||||
SetVSConstant4fv(C_NORMALMATRICES + i, pnstart);
|
||||
|
||||
nNormalMatricesChanged[0] = nNormalMatricesChanged[1] = -1;
|
||||
}
|
||||
|
||||
if (nPostTransformMatricesChanged[0] >= 0) {
|
||||
int startn = nPostTransformMatricesChanged[0]/4;
|
||||
int endn = (nPostTransformMatricesChanged[1]+3)/4;
|
||||
const float* pstart = (const float*)&xfmem[XFMEM_POSTMATRICES + startn*4];
|
||||
if (nPostTransformMatricesChanged[0] >= 0)
|
||||
{
|
||||
int startn = nPostTransformMatricesChanged[0] / 4;
|
||||
int endn = (nPostTransformMatricesChanged[1] + 3 ) / 4;
|
||||
const float* pstart = (const float*)&xfmem[XFMEM_POSTMATRICES + startn * 4];
|
||||
for(int i = startn; i < endn; ++i, pstart += 4)
|
||||
SetVSConstant4fv(C_POSTTRANSFORMMATRICES + i, pstart);
|
||||
}
|
||||
|
||||
if (nLightsChanged[0] >= 0) {
|
||||
if (nLightsChanged[0] >= 0)
|
||||
{
|
||||
// lights don't have a 1 to 1 mapping, the color component needs to be converted to 4 floats
|
||||
int istart = nLightsChanged[0] / 0x10;
|
||||
int iend = (nLightsChanged[1] + 15) / 0x10;
|
||||
const float* xfmemptr = (const float*)&xfmem[0x10*istart + XFMEM_LIGHTS];
|
||||
const float* xfmemptr = (const float*)&xfmem[0x10 * istart + XFMEM_LIGHTS];
|
||||
|
||||
for (int i = istart; i < iend; ++i) {
|
||||
for (int i = istart; i < iend; ++i)
|
||||
{
|
||||
u32 color = *(const u32*)(xfmemptr + 3);
|
||||
SetVSConstant4f(C_LIGHTS + 5*i,
|
||||
((color >> 24) & 0xFF)/255.0f,
|
||||
((color >> 16) & 0xFF)/255.0f,
|
||||
((color >> 8) & 0xFF)/255.0f,
|
||||
((color) & 0xFF)/255.0f);
|
||||
SetVSConstant4f(C_LIGHTS + 5 * i,
|
||||
((color >> 24) & 0xFF) / 255.0f,
|
||||
((color >> 16) & 0xFF) / 255.0f,
|
||||
((color >> 8) & 0xFF) / 255.0f,
|
||||
((color) & 0xFF) / 255.0f);
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
@ -147,66 +154,78 @@ void VertexShaderManager::SetConstants(bool proj_hax_1,bool Hack_hack1 ,float Ha
|
||||
nLightsChanged[0] = nLightsChanged[1] = -1;
|
||||
}
|
||||
|
||||
if (nMaterialsChanged) {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
if (nMaterialsChanged)
|
||||
{
|
||||
for (int i = 0; i < 4; ++i)
|
||||
if (nMaterialsChanged & (1 << i))
|
||||
SetVSConstant4fv(C_MATERIALS + i, &s_fMaterials[4*i]);
|
||||
}
|
||||
SetVSConstant4fv(C_MATERIALS + i, &s_fMaterials[4 * i]);
|
||||
|
||||
nMaterialsChanged = 0;
|
||||
}
|
||||
|
||||
if (bPosNormalMatrixChanged) {
|
||||
if (bPosNormalMatrixChanged)
|
||||
{
|
||||
bPosNormalMatrixChanged = false;
|
||||
|
||||
float* pos = (float*)xfmem + MatrixIndexA.PosNormalMtxIdx * 4;
|
||||
float* norm = (float*)xfmem + XFMEM_NORMALMATRICES + 3 * (MatrixIndexA.PosNormalMtxIdx & 31);
|
||||
|
||||
SetVSConstant4fv(C_POSNORMALMATRIX, pos);
|
||||
SetVSConstant4fv(C_POSNORMALMATRIX+1, pos+4);
|
||||
SetVSConstant4fv(C_POSNORMALMATRIX+2, pos+8);
|
||||
SetVSConstant4fv(C_POSNORMALMATRIX+1, pos + 4);
|
||||
SetVSConstant4fv(C_POSNORMALMATRIX+2, pos + 8);
|
||||
SetVSConstant4fv(C_POSNORMALMATRIX+3, norm);
|
||||
SetVSConstant4fv(C_POSNORMALMATRIX+4, norm+3);
|
||||
SetVSConstant4fv(C_POSNORMALMATRIX+5, norm+6);
|
||||
SetVSConstant4fv(C_POSNORMALMATRIX+4, norm + 3);
|
||||
SetVSConstant4fv(C_POSNORMALMATRIX+5, norm + 6);
|
||||
}
|
||||
|
||||
if (bTexMatricesChanged[0]) {
|
||||
if (bTexMatricesChanged[0])
|
||||
{
|
||||
bTexMatricesChanged[0] = false;
|
||||
float* fptrs[] = {
|
||||
|
||||
float* fptrs[] =
|
||||
{
|
||||
(float*)xfmem + MatrixIndexA.Tex0MtxIdx * 4, (float*)xfmem + MatrixIndexA.Tex1MtxIdx * 4,
|
||||
(float*)xfmem + MatrixIndexA.Tex2MtxIdx * 4, (float*)xfmem + MatrixIndexA.Tex3MtxIdx * 4
|
||||
};
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
SetVSConstant4fv(C_TEXMATRICES+3*i, fptrs[i]);
|
||||
SetVSConstant4fv(C_TEXMATRICES+3*i+1, fptrs[i]+4);
|
||||
SetVSConstant4fv(C_TEXMATRICES+3*i+2, fptrs[i]+8);
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
SetVSConstant4fv(C_TEXMATRICES+3 * i, fptrs[i]);
|
||||
SetVSConstant4fv(C_TEXMATRICES+3 * i + 1, fptrs[i] + 4);
|
||||
SetVSConstant4fv(C_TEXMATRICES+3 * i + 2, fptrs[i] + 8);
|
||||
}
|
||||
}
|
||||
|
||||
if (bTexMatricesChanged[1]) {
|
||||
if (bTexMatricesChanged[1])
|
||||
{
|
||||
bTexMatricesChanged[1] = false;
|
||||
|
||||
float* fptrs[] = {(float*)xfmem + MatrixIndexB.Tex4MtxIdx * 4, (float*)xfmem + MatrixIndexB.Tex5MtxIdx * 4,
|
||||
(float*)xfmem + MatrixIndexB.Tex6MtxIdx * 4, (float*)xfmem + MatrixIndexB.Tex7MtxIdx * 4 };
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
SetVSConstant4fv(C_TEXMATRICES+3*i+12, fptrs[i]);
|
||||
SetVSConstant4fv(C_TEXMATRICES+3*i+12+1, fptrs[i]+4);
|
||||
SetVSConstant4fv(C_TEXMATRICES+3*i+12+2, fptrs[i]+8);
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
SetVSConstant4fv(C_TEXMATRICES+3 * i + 12, fptrs[i]);
|
||||
SetVSConstant4fv(C_TEXMATRICES+3 * i + 12 + 1, fptrs[i] + 4);
|
||||
SetVSConstant4fv(C_TEXMATRICES+3 * i + 12 + 2, fptrs[i] + 8);
|
||||
}
|
||||
}
|
||||
|
||||
if (bViewportChanged) {
|
||||
if (bViewportChanged)
|
||||
{
|
||||
bViewportChanged = false;
|
||||
|
||||
// This is so implementation-dependent that we can't have it here.
|
||||
UpdateViewport();
|
||||
}
|
||||
|
||||
if (bProjectionChanged) {
|
||||
if (bProjectionChanged)
|
||||
{
|
||||
bProjectionChanged = false;
|
||||
|
||||
if (xfregs.rawProjection[6] == 0) { // Perspective
|
||||
if (xfregs.rawProjection[6] == 0)
|
||||
{
|
||||
// Perspective
|
||||
g_fProjectionMatrix[0] = xfregs.rawProjection[0];
|
||||
g_fProjectionMatrix[1] = 0.0f;
|
||||
g_fProjectionMatrix[2] = xfregs.rawProjection[1];
|
||||
@ -247,7 +266,9 @@ void VertexShaderManager::SetConstants(bool proj_hax_1,bool Hack_hack1 ,float Ha
|
||||
SETSTAT_FT(stats.gproj_14, g_fProjectionMatrix[14]);
|
||||
SETSTAT_FT(stats.gproj_15, g_fProjectionMatrix[15]);
|
||||
}
|
||||
else { // Orthographic Projection
|
||||
else
|
||||
{
|
||||
// Orthographic Projection
|
||||
g_fProjectionMatrix[0] = xfregs.rawProjection[0];
|
||||
g_fProjectionMatrix[1] = 0.0f;
|
||||
g_fProjectionMatrix[2] = 0.0f;
|
||||
@ -295,7 +316,8 @@ void VertexShaderManager::SetConstants(bool proj_hax_1,bool Hack_hack1 ,float Ha
|
||||
|
||||
PRIM_LOG("Projection: %f %f %f %f %f %f\n", xfregs.rawProjection[0], xfregs.rawProjection[1], xfregs.rawProjection[2], xfregs.rawProjection[3], xfregs.rawProjection[4], xfregs.rawProjection[5]);
|
||||
|
||||
if (freeLook) {
|
||||
if (freeLook)
|
||||
{
|
||||
Matrix44 mtxA;
|
||||
Matrix44 mtxB;
|
||||
Matrix44 viewMtx;
|
||||
@ -311,7 +333,8 @@ void VertexShaderManager::SetConstants(bool proj_hax_1,bool Hack_hack1 ,float Ha
|
||||
SetVSConstant4fv(C_PROJECTION+2, &mtxA.data[8]);
|
||||
SetVSConstant4fv(C_PROJECTION+3, &mtxA.data[12]);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
SetVSConstant4fv(C_PROJECTION, &g_fProjectionMatrix[0]);
|
||||
SetVSConstant4fv(C_PROJECTION+1, &g_fProjectionMatrix[4]);
|
||||
SetVSConstant4fv(C_PROJECTION+2, &g_fProjectionMatrix[8]);
|
||||
@ -322,10 +345,10 @@ void VertexShaderManager::SetConstants(bool proj_hax_1,bool Hack_hack1 ,float Ha
|
||||
|
||||
void VertexShaderManager::InvalidateXFRange(int start, int end)
|
||||
{
|
||||
if (((u32)start >= (u32)MatrixIndexA.PosNormalMtxIdx*4 &&
|
||||
(u32)start < (u32)MatrixIndexA.PosNormalMtxIdx*4 + 12) ||
|
||||
((u32)start >= XFMEM_NORMALMATRICES + ((u32)MatrixIndexA.PosNormalMtxIdx & 31)*3 &&
|
||||
(u32)start < XFMEM_NORMALMATRICES + ((u32)MatrixIndexA.PosNormalMtxIdx & 31)*3 + 9)) {
|
||||
if (((u32)start >= (u32)MatrixIndexA.PosNormalMtxIdx * 4 &&
|
||||
(u32)start < (u32)MatrixIndexA.PosNormalMtxIdx * 4 + 12) ||
|
||||
((u32)start >= XFMEM_NORMALMATRICES + ((u32)MatrixIndexA.PosNormalMtxIdx & 31) * 3 &&
|
||||
(u32)start < XFMEM_NORMALMATRICES + ((u32)MatrixIndexA.PosNormalMtxIdx & 31) * 3 + 9)) {
|
||||
bPosNormalMatrixChanged = true;
|
||||
}
|
||||
|
||||
@ -343,54 +366,66 @@ void VertexShaderManager::InvalidateXFRange(int start, int end)
|
||||
bTexMatricesChanged[1] = true;
|
||||
}
|
||||
|
||||
if (start < XFMEM_POSMATRICES_END) {
|
||||
if (nTransformMatricesChanged[0] == -1) {
|
||||
if (start < XFMEM_POSMATRICES_END)
|
||||
{
|
||||
if (nTransformMatricesChanged[0] == -1)
|
||||
{
|
||||
nTransformMatricesChanged[0] = start;
|
||||
nTransformMatricesChanged[1] = end>XFMEM_POSMATRICES_END?XFMEM_POSMATRICES_END:end;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
if (nTransformMatricesChanged[0] > start) nTransformMatricesChanged[0] = start;
|
||||
if (nTransformMatricesChanged[1] < end) nTransformMatricesChanged[1] = end>XFMEM_POSMATRICES_END?XFMEM_POSMATRICES_END:end;
|
||||
}
|
||||
}
|
||||
|
||||
if (start < XFMEM_NORMALMATRICES_END && end > XFMEM_NORMALMATRICES) {
|
||||
if (start < XFMEM_NORMALMATRICES_END && end > XFMEM_NORMALMATRICES)
|
||||
{
|
||||
int _start = start < XFMEM_NORMALMATRICES ? 0 : start-XFMEM_NORMALMATRICES;
|
||||
int _end = end < XFMEM_NORMALMATRICES_END ? end-XFMEM_NORMALMATRICES : XFMEM_NORMALMATRICES_END-XFMEM_NORMALMATRICES;
|
||||
|
||||
if (nNormalMatricesChanged[0] == -1 ) {
|
||||
if (nNormalMatricesChanged[0] == -1)
|
||||
{
|
||||
nNormalMatricesChanged[0] = _start;
|
||||
nNormalMatricesChanged[1] = _end;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
if (nNormalMatricesChanged[0] > _start) nNormalMatricesChanged[0] = _start;
|
||||
if (nNormalMatricesChanged[1] < _end) nNormalMatricesChanged[1] = _end;
|
||||
}
|
||||
}
|
||||
|
||||
if (start < XFMEM_POSTMATRICES_END && end > XFMEM_POSTMATRICES) {
|
||||
if (start < XFMEM_POSTMATRICES_END && end > XFMEM_POSTMATRICES)
|
||||
{
|
||||
int _start = start < XFMEM_POSTMATRICES ? XFMEM_POSTMATRICES : start-XFMEM_POSTMATRICES;
|
||||
int _end = end < XFMEM_POSTMATRICES_END ? end-XFMEM_POSTMATRICES : XFMEM_POSTMATRICES_END-XFMEM_POSTMATRICES;
|
||||
|
||||
if (nPostTransformMatricesChanged[0] == -1 ) {
|
||||
if (nPostTransformMatricesChanged[0] == -1)
|
||||
{
|
||||
nPostTransformMatricesChanged[0] = _start;
|
||||
nPostTransformMatricesChanged[1] = _end;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
if (nPostTransformMatricesChanged[0] > _start) nPostTransformMatricesChanged[0] = _start;
|
||||
if (nPostTransformMatricesChanged[1] < _end) nPostTransformMatricesChanged[1] = _end;
|
||||
}
|
||||
}
|
||||
|
||||
if (start < XFMEM_LIGHTS_END && end > XFMEM_LIGHTS) {
|
||||
if (start < XFMEM_LIGHTS_END && end > XFMEM_LIGHTS)
|
||||
{
|
||||
int _start = start < XFMEM_LIGHTS ? XFMEM_LIGHTS : start-XFMEM_LIGHTS;
|
||||
int _end = end < XFMEM_LIGHTS_END ? end-XFMEM_LIGHTS : XFMEM_LIGHTS_END-XFMEM_LIGHTS;
|
||||
|
||||
if (nLightsChanged[0] == -1 ) {
|
||||
if (nLightsChanged[0] == -1 )
|
||||
{
|
||||
nLightsChanged[0] = _start;
|
||||
nLightsChanged[1] = _end;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
if (nLightsChanged[0] > _start) nLightsChanged[0] = _start;
|
||||
if (nLightsChanged[1] < _end) nLightsChanged[1] = _end;
|
||||
}
|
||||
@ -399,7 +434,8 @@ void VertexShaderManager::InvalidateXFRange(int start, int end)
|
||||
|
||||
void VertexShaderManager::SetTexMatrixChangedA(u32 Value)
|
||||
{
|
||||
if (MatrixIndexA.Hex != Value) {
|
||||
if (MatrixIndexA.Hex != Value)
|
||||
{
|
||||
VertexManager::Flush();
|
||||
if (MatrixIndexA.PosNormalMtxIdx != (Value&0x3f))
|
||||
bPosNormalMatrixChanged = true;
|
||||
@ -410,7 +446,8 @@ void VertexShaderManager::SetTexMatrixChangedA(u32 Value)
|
||||
|
||||
void VertexShaderManager::SetTexMatrixChangedB(u32 Value)
|
||||
{
|
||||
if (MatrixIndexB.Hex != Value) {
|
||||
if (MatrixIndexB.Hex != Value)
|
||||
{
|
||||
VertexManager::Flush();
|
||||
bTexMatricesChanged[1] = true;
|
||||
MatrixIndexB.Hex = Value;
|
||||
@ -420,7 +457,8 @@ void VertexShaderManager::SetTexMatrixChangedB(u32 Value)
|
||||
void VertexShaderManager::SetViewport(float* _Viewport)
|
||||
{
|
||||
// Workaround for paper mario, yep this is bizarre.
|
||||
for (size_t i = 0; i < ARRAYSIZE(xfregs.rawViewport); ++i) {
|
||||
for (size_t i = 0; i < ARRAYSIZE(xfregs.rawViewport); ++i)
|
||||
{
|
||||
if (*(u32*)(_Viewport + i) == 0x7f800000) // invalid fp number
|
||||
return;
|
||||
}
|
||||
@ -445,10 +483,10 @@ void VertexShaderManager::SetMaterialColor(int index, u32 data)
|
||||
|
||||
nMaterialsChanged |= (1 << index);
|
||||
|
||||
s_fMaterials[ind++] = ((data>>24)&0xFF)/255.0f;
|
||||
s_fMaterials[ind++] = ((data>>16)&0xFF)/255.0f;
|
||||
s_fMaterials[ind++] = ((data>>8)&0xFF)/255.0f;
|
||||
s_fMaterials[ind] = ((data)&0xFF)/255.0f;
|
||||
s_fMaterials[ind++] = ((data >> 24) & 0xFF) / 255.0f;
|
||||
s_fMaterials[ind++] = ((data >> 16) & 0xFF) / 255.0f;
|
||||
s_fMaterials[ind++] = ((data >> 8) & 0xFF) / 255.0f;
|
||||
s_fMaterials[ind] = ( data & 0xFF) / 255.0f;
|
||||
}
|
||||
|
||||
void VertexShaderManager::TranslateView(float x, float y)
|
||||
@ -458,9 +496,8 @@ void VertexShaderManager::TranslateView(float x, float y)
|
||||
|
||||
Matrix33::Multiply(s_viewInvRotationMatrix, vector, result);
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int i = 0; i < 3; i++)
|
||||
s_fViewTranslationVector[i] += result[i];
|
||||
}
|
||||
|
||||
bProjectionChanged = true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user