diff options
| author | 2014-12-21 02:59:08 +0100 | |
|---|---|---|
| committer | 2014-12-31 16:32:55 +0100 | |
| commit | e229ff8c836fa213f1bdd31cabe924457f5e7e0c (patch) | |
| tree | 9d1b157410b6c5e3ac3c4c6d0f270951e5db3db6 /src/video_core/rasterizer.cpp | |
| parent | Pica/Rasterizer: Further enhance Tev support. (diff) | |
| download | yuzu-e229ff8c836fa213f1bdd31cabe924457f5e7e0c.tar.gz yuzu-e229ff8c836fa213f1bdd31cabe924457f5e7e0c.tar.xz yuzu-e229ff8c836fa213f1bdd31cabe924457f5e7e0c.zip | |
Pica/Rasterizer: Implement depth testing.
Diffstat (limited to 'src/video_core/rasterizer.cpp')
| -rw-r--r-- | src/video_core/rasterizer.cpp | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/src/video_core/rasterizer.cpp b/src/video_core/rasterizer.cpp index 04ff68615..8dff2db27 100644 --- a/src/video_core/rasterizer.cpp +++ b/src/video_core/rasterizer.cpp | |||
| @@ -396,12 +396,39 @@ void ProcessTriangle(const VertexShader::OutputVertex& v0, | |||
| 396 | combiner_output = Math::MakeVec(color_output, alpha_output); | 396 | combiner_output = Math::MakeVec(color_output, alpha_output); |
| 397 | } | 397 | } |
| 398 | 398 | ||
| 399 | // TODO: Not sure if the multiplication by 65535 has already been taken care | 399 | // TODO: Does depth indeed only get written even if depth testing is enabled? |
| 400 | // of when transforming to screen coordinates or not. | 400 | if (registers.output_merger.depth_test_enable) { |
| 401 | u16 z = (u16)(((float)v0.screenpos[2].ToFloat32() * w0 + | 401 | u16 z = (u16)(-((float)v0.screenpos[2].ToFloat32() * w0 + |
| 402 | (float)v1.screenpos[2].ToFloat32() * w1 + | 402 | (float)v1.screenpos[2].ToFloat32() * w1 + |
| 403 | (float)v2.screenpos[2].ToFloat32() * w2) * 65535.f / wsum); | 403 | (float)v2.screenpos[2].ToFloat32() * w2) * 65535.f / wsum); |
| 404 | SetDepth(x >> 4, y >> 4, z); | 404 | u16 ref_z = GetDepth(x >> 4, y >> 4); |
| 405 | |||
| 406 | bool pass = false; | ||
| 407 | |||
| 408 | switch (registers.output_merger.depth_test_func) { | ||
| 409 | case registers.output_merger.Always: | ||
| 410 | pass = true; | ||
| 411 | break; | ||
| 412 | |||
| 413 | case registers.output_merger.LessThan: | ||
| 414 | pass = z < ref_z; | ||
| 415 | break; | ||
| 416 | |||
| 417 | case registers.output_merger.GreaterThan: | ||
| 418 | pass = z > ref_z; | ||
| 419 | break; | ||
| 420 | |||
| 421 | default: | ||
| 422 | LOG_ERROR(HW_GPU, "Unknown depth test function %x", registers.output_merger.depth_test_func.Value()); | ||
| 423 | break; | ||
| 424 | } | ||
| 425 | |||
| 426 | if (!pass) | ||
| 427 | continue; | ||
| 428 | |||
| 429 | if (registers.output_merger.depth_write_enable) | ||
| 430 | SetDepth(x >> 4, y >> 4, z); | ||
| 431 | } | ||
| 405 | 432 | ||
| 406 | DrawPixel(x >> 4, y >> 4, combiner_output); | 433 | DrawPixel(x >> 4, y >> 4, combiner_output); |
| 407 | } | 434 | } |