summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/OGL/VertexManager.cpp
diff options
context:
space:
mode:
authorNanoByte011 <nanobyte011@hotmail.com>2014-12-25 00:34:22 -0700
committerScott Mansell <phiren@gmail.com>2015-01-23 03:31:54 +1300
commit937844b9e339d1f6b819e90eeb9bde65f45e833f (patch)
tree4226b4160379d52e030385ef0a811c5c7ce0c331 /Source/Core/VideoBackends/OGL/VertexManager.cpp
parent4984215971e0c03a16e40b0c1703840bfa2cdab8 (diff)
Initial port of zfreeze branch (3.5-1729)
Initial port of original zfreeze branch (3.5-1729) by neobrain into most recent build of Dolphin. Makes Rogue Squadron 2 very playable at full speed thanks to recent core speedups made to Dolphin. Works on DirectX Video plugin only for now. Enjoy! and Merry Xmas!!
Diffstat (limited to 'Source/Core/VideoBackends/OGL/VertexManager.cpp')
-rw-r--r--Source/Core/VideoBackends/OGL/VertexManager.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/Source/Core/VideoBackends/OGL/VertexManager.cpp b/Source/Core/VideoBackends/OGL/VertexManager.cpp
index 1a162b1cde..d3a8d91bca 100644
--- a/Source/Core/VideoBackends/OGL/VertexManager.cpp
+++ b/Source/Core/VideoBackends/OGL/VertexManager.cpp
@@ -42,6 +42,13 @@ static size_t s_index_offset;
VertexManager::VertexManager()
{
+ LocalVBuffer.resize(MAXVBUFFERSIZE);
+
+ s_pCurBufferPointer = s_pBaseBufferPointer = &LocalVBuffer[0];
+ s_pEndBufferPointer = s_pBaseBufferPointer + LocalVBuffer.size();
+
+ LocalIBuffer.resize(MAXIBUFFERSIZE);
+
CreateDeviceObjects();
}
@@ -131,6 +138,7 @@ void VertexManager::vFlush(bool useDstAlpha)
{
GLVertexFormat *nativeVertexFmt = (GLVertexFormat*)VertexLoaderManager::GetCurrentVertexFormat();
u32 stride = nativeVertexFmt->GetVertexStride();
+ u32 indices = IndexGenerator::GetIndexLen();
if (m_last_vao != nativeVertexFmt->VAO)
{
@@ -140,6 +148,47 @@ void VertexManager::vFlush(bool useDstAlpha)
PrepareDrawBuffers(stride);
+ if (!bpmem.genMode.zfreeze && indices >= 3)
+ {
+ float vtx[9];
+ float out[12];
+
+ // Lookup vertices of the last rendered triangle and software-transform them
+ // This allows us to determine the depth slope, which will be used if zfreeze
+ // is enabled in the following flush.
+ for (unsigned int i = 0; i < 3; ++i)
+ {
+ const int base_index = GetIndexBuffer()[indices - 3 + i];
+ u8* vtx_ptr = &((u8*)GetVertexBuffer())[base_index * stride];
+ vtx[0 + i * 3] = ((float*)vtx_ptr)[0];
+ vtx[1 + i * 3] = ((float*)vtx_ptr)[1];
+ vtx[2 + i * 3] = ((float*)vtx_ptr)[2];
+
+ VertexShaderManager::TransformToClipSpace(&vtx[i * 3], &out[i * 4]);
+
+ // viewport offset ignored because we only look at coordinate differences.
+ out[0 + i * 4] = out[0 + i * 4] / out[3 + i * 4] * xfmem.viewport.wd;
+ out[1 + i * 4] = out[1 + i * 4] / out[3 + i * 4] * xfmem.viewport.ht;
+ out[2 + i * 4] = out[2 + i * 4] / out[3 + i * 4] * xfmem.viewport.zRange + xfmem.viewport.farZ;
+ }
+ float dx31 = out[8] - out[0];
+ float dx12 = out[0] - out[4];
+ float dy12 = out[1] - out[5];
+ float dy31 = out[9] - out[1];
+
+ float DF31 = out[10] - out[2];
+ float DF21 = out[6] - out[2];
+ float a = DF31 * -dy12 - DF21 * dy31;
+ float b = dx31 * DF21 + dx12 * DF31;
+ float c = -dx12 * dy31 - dx31 * -dy12;
+
+ float slope_dfdx = -a / c;
+ float slope_dfdy = -b / c;
+ float slope_f0 = out[2];
+
+ PixelShaderManager::SetZSlopeChanged(slope_dfdx, slope_dfdy, slope_f0);
+ }
+
// Makes sure we can actually do Dual source blending
bool dualSourcePossible = g_ActiveConfig.backend_info.bSupportsDualSourceBlend;