2020-05-24 14:51:37 +00:00
|
|
|
// See comment in header for the purpose of the code in this file.
|
2019-10-28 08:33:30 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cmath>
|
|
|
|
|
2021-05-01 14:15:04 +00:00
|
|
|
#include "Common/Data/Convert/ColorConv.h"
|
2020-10-04 08:04:01 +00:00
|
|
|
#include "Common/Profiler/Profiler.h"
|
2022-01-02 00:25:34 +00:00
|
|
|
#include "Common/StringUtils.h"
|
2021-11-14 17:29:58 +00:00
|
|
|
#include "Common/Thread/ParallelLoop.h"
|
2019-10-28 08:33:30 +00:00
|
|
|
|
|
|
|
#include "Core/Config.h"
|
2022-01-02 00:25:34 +00:00
|
|
|
#include "Core/Debugger/MemBlockInfo.h"
|
2019-10-28 08:33:30 +00:00
|
|
|
#include "Core/MemMap.h"
|
|
|
|
#include "Core/Reporting.h"
|
2021-05-01 14:15:04 +00:00
|
|
|
#include "Core/System.h"
|
2019-10-28 08:33:30 +00:00
|
|
|
#include "GPU/GPUState.h"
|
|
|
|
|
|
|
|
#include "GPU/Common/TextureCacheCommon.h"
|
2021-11-21 15:20:19 +00:00
|
|
|
#include "GPU/Software/DrawPixel.h"
|
2019-10-28 08:33:30 +00:00
|
|
|
#include "GPU/Software/Rasterizer.h"
|
|
|
|
#include "GPU/Software/Sampler.h"
|
2021-11-21 15:20:19 +00:00
|
|
|
#include "GPU/Software/SoftGpu.h"
|
2019-10-28 08:33:30 +00:00
|
|
|
|
|
|
|
#if defined(_M_SSE)
|
|
|
|
#include <emmintrin.h>
|
|
|
|
#endif
|
|
|
|
|
2020-05-24 14:51:37 +00:00
|
|
|
extern DSStretch g_DarkStalkerStretch;
|
2019-10-28 08:33:30 +00:00
|
|
|
// For Darkstalkers hack. Ugh.
|
|
|
|
extern bool currentDialogActive;
|
|
|
|
|
|
|
|
namespace Rasterizer {
|
|
|
|
|
|
|
|
// Through mode, with the specific Darkstalker settings.
|
2021-11-20 22:22:55 +00:00
|
|
|
inline void DrawSinglePixel5551(u16 *pixel, const u32 color_in, const PixelFuncID &pixelID) {
|
2019-10-28 08:33:30 +00:00
|
|
|
u32 new_color;
|
2020-08-31 23:43:54 +00:00
|
|
|
if ((color_in >> 24) == 255) {
|
|
|
|
new_color = color_in & 0xFFFFFF;
|
2019-10-28 08:33:30 +00:00
|
|
|
} else {
|
|
|
|
const u32 old_color = RGBA5551ToRGBA8888(*pixel);
|
|
|
|
const Vec4<int> dst = Vec4<int>::FromRGBA(old_color);
|
2021-11-20 22:22:55 +00:00
|
|
|
Vec3<int> blended = AlphaBlendingResult(pixelID, Vec4<int>::FromRGBA(color_in), dst);
|
2019-10-28 08:33:30 +00:00
|
|
|
// ToRGB() always automatically clamps.
|
|
|
|
new_color = blended.ToRGB();
|
|
|
|
}
|
|
|
|
new_color |= (*pixel & 0x8000) ? 0xff000000 : 0x00000000;
|
|
|
|
*pixel = RGBA8888ToRGBA5551(new_color);
|
|
|
|
}
|
|
|
|
|
2022-01-11 05:43:41 +00:00
|
|
|
static inline Vec4IntResult SOFTRAST_CALL ModulateRGBA(Vec4IntArg prim_in, Vec4IntArg texcolor_in, const SamplerID &samplerID) {
|
2021-12-05 21:10:18 +00:00
|
|
|
Vec4<int> out;
|
|
|
|
Vec4<int> prim_color = prim_in;
|
|
|
|
Vec4<int> texcolor = texcolor_in;
|
2019-10-28 08:33:30 +00:00
|
|
|
|
|
|
|
#if defined(_M_SSE)
|
2021-12-05 21:10:18 +00:00
|
|
|
// Modulate weights slightly on the tex color, by adding one to prim and dividing by 256.
|
|
|
|
const __m128i p = _mm_slli_epi16(_mm_packs_epi32(prim_color.ivec, prim_color.ivec), 4);
|
|
|
|
const __m128i pboost = _mm_add_epi16(p, _mm_set1_epi16(1 << 4));
|
|
|
|
__m128i t = _mm_slli_epi16(_mm_packs_epi32(texcolor.ivec, texcolor.ivec), 4);
|
2022-01-11 05:43:41 +00:00
|
|
|
if (samplerID.useColorDoubling) {
|
2021-12-05 21:10:18 +00:00
|
|
|
const __m128i amask = _mm_set_epi16(-1, 0, 0, 0, -1, 0, 0, 0);
|
|
|
|
const __m128i a = _mm_and_si128(t, amask);
|
|
|
|
const __m128i rgb = _mm_andnot_si128(amask, t);
|
|
|
|
t = _mm_or_si128(_mm_slli_epi16(rgb, 1), a);
|
2019-10-28 08:33:30 +00:00
|
|
|
}
|
2021-12-05 21:10:18 +00:00
|
|
|
const __m128i b = _mm_mulhi_epi16(pboost, t);
|
|
|
|
out.ivec = _mm_unpacklo_epi16(b, _mm_setzero_si128());
|
2019-10-28 08:33:30 +00:00
|
|
|
#else
|
2022-01-11 05:43:41 +00:00
|
|
|
if (samplerID.useColorDoubling) {
|
2021-12-05 21:10:18 +00:00
|
|
|
Vec4<int> tex = texcolor * Vec4<int>(2, 2, 2, 1);
|
|
|
|
out = ((prim_color + Vec4<int>::AssignToAll(1)) * tex) / 256;
|
2019-10-28 08:33:30 +00:00
|
|
|
} else {
|
2021-12-05 21:10:18 +00:00
|
|
|
out = (prim_color + Vec4<int>::AssignToAll(1)) * texcolor / 256;
|
2019-10-28 08:33:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-12-05 21:10:18 +00:00
|
|
|
return ToVec4IntResult(out);
|
2019-10-28 08:33:30 +00:00
|
|
|
}
|
|
|
|
|
2022-01-11 05:43:41 +00:00
|
|
|
void DrawSprite(const VertexData &v0, const VertexData &v1, const RasterizerState &state) {
|
2022-01-11 08:00:03 +00:00
|
|
|
const u8 *texptr = state.texptr[0];
|
2019-10-28 08:33:30 +00:00
|
|
|
|
2022-01-11 05:43:41 +00:00
|
|
|
GETextureFormat texfmt = state.samplerID.TexFmt();
|
2022-01-11 08:00:03 +00:00
|
|
|
int texbufw = state.texbufw[0];
|
2019-10-28 08:33:30 +00:00
|
|
|
|
|
|
|
ScreenCoords pprime(v0.screenpos.x, v0.screenpos.y, 0);
|
2022-01-11 05:43:41 +00:00
|
|
|
Sampler::FetchFunc fetchFunc = Sampler::GetFetchFunc(state.samplerID);
|
|
|
|
auto &pixelID = state.pixelID;
|
|
|
|
auto &samplerID = state.samplerID;
|
2019-10-28 08:33:30 +00:00
|
|
|
|
|
|
|
DrawingCoords pos0 = TransformUnit::ScreenToDrawing(v0.screenpos);
|
2021-09-07 05:05:39 +00:00
|
|
|
// Include the ending pixel based on its center, not start.
|
|
|
|
DrawingCoords pos1 = TransformUnit::ScreenToDrawing(v1.screenpos + ScreenCoords(7, 7, 0));
|
2019-10-28 08:33:30 +00:00
|
|
|
|
|
|
|
DrawingCoords scissorTL(gstate.getScissorX1(), gstate.getScissorY1(), 0);
|
|
|
|
DrawingCoords scissorBR(gstate.getScissorX2(), gstate.getScissorY2(), 0);
|
|
|
|
|
|
|
|
int z = pos0.z;
|
2021-11-21 15:20:19 +00:00
|
|
|
int fog = 255;
|
2019-10-28 08:33:30 +00:00
|
|
|
|
2021-01-17 04:13:16 +00:00
|
|
|
bool isWhite = v1.color0 == Vec4<int>(255, 255, 255, 255);
|
2019-10-28 08:33:30 +00:00
|
|
|
|
2021-11-15 02:44:30 +00:00
|
|
|
constexpr int MIN_LINES_PER_THREAD = 32;
|
2021-11-14 17:29:58 +00:00
|
|
|
|
2022-01-12 03:42:40 +00:00
|
|
|
if (state.enableTextures) {
|
2019-10-28 08:33:30 +00:00
|
|
|
// 1:1 (but with mirror support) texture mapping!
|
|
|
|
int s_start = v0.texturecoords.x;
|
|
|
|
int t_start = v0.texturecoords.y;
|
|
|
|
int ds = v1.texturecoords.x > v0.texturecoords.x ? 1 : -1;
|
|
|
|
int dt = v1.texturecoords.y > v0.texturecoords.y ? 1 : -1;
|
|
|
|
|
|
|
|
if (ds < 0) {
|
|
|
|
s_start += ds;
|
|
|
|
}
|
|
|
|
if (dt < 0) {
|
|
|
|
t_start += dt;
|
|
|
|
}
|
|
|
|
|
|
|
|
// First clip the right and bottom sides, since we don't need to adjust the deltas.
|
|
|
|
if (pos1.x > scissorBR.x) pos1.x = scissorBR.x + 1;
|
|
|
|
if (pos1.y > scissorBR.y) pos1.y = scissorBR.y + 1;
|
|
|
|
// Now clip the other sides.
|
|
|
|
if (pos0.x < scissorTL.x) {
|
|
|
|
s_start += (scissorTL.x - pos0.x) * ds;
|
|
|
|
pos0.x = scissorTL.x;
|
|
|
|
}
|
|
|
|
if (pos0.y < scissorTL.y) {
|
|
|
|
t_start += (scissorTL.y - pos0.y) * dt;
|
|
|
|
pos0.y = scissorTL.y;
|
|
|
|
}
|
|
|
|
|
2021-11-20 22:45:38 +00:00
|
|
|
if (!pixelID.stencilTest &&
|
2021-11-21 17:39:14 +00:00
|
|
|
pixelID.DepthTestFunc() == GE_COMP_ALWAYS &&
|
2021-11-20 22:45:38 +00:00
|
|
|
!pixelID.applyLogicOp &&
|
|
|
|
!pixelID.colorTest &&
|
|
|
|
!pixelID.dithering &&
|
|
|
|
// TODO: Safe?
|
2021-11-21 17:39:14 +00:00
|
|
|
pixelID.AlphaTestFunc() != GE_COMP_ALWAYS &&
|
2021-11-20 22:45:38 +00:00
|
|
|
pixelID.alphaTestRef == 0 &&
|
|
|
|
!pixelID.hasAlphaTestMask &&
|
|
|
|
pixelID.alphaBlend &&
|
2022-01-10 07:31:12 +00:00
|
|
|
samplerID.useTextureAlpha &&
|
|
|
|
samplerID.TexFunc() == GE_TEXFUNC_MODULATE &&
|
2021-11-20 22:45:38 +00:00
|
|
|
!pixelID.applyColorWriteMask &&
|
2021-11-21 17:39:14 +00:00
|
|
|
pixelID.FBFormat() == GE_FORMAT_5551) {
|
2021-11-14 17:29:58 +00:00
|
|
|
if (isWhite) {
|
|
|
|
ParallelRangeLoop(&g_threadManager, [=](int y1, int y2) {
|
|
|
|
int t = t_start + (y1 - pos0.y) * dt;
|
|
|
|
for (int y = y1; y < y2; y++) {
|
|
|
|
int s = s_start;
|
|
|
|
u16 *pixel = fb.Get16Ptr(pos0.x, y, gstate.FrameBufStride());
|
|
|
|
for (int x = pos0.x; x < pos1.x; x++) {
|
2021-12-31 18:35:26 +00:00
|
|
|
u32 tex_color = Vec4<int>(fetchFunc(s, t, texptr, texbufw, 0)).ToRGBA();
|
2021-11-14 17:29:58 +00:00
|
|
|
if (tex_color & 0xFF000000) {
|
2021-11-20 22:22:55 +00:00
|
|
|
DrawSinglePixel5551(pixel, tex_color, pixelID);
|
2021-11-14 17:29:58 +00:00
|
|
|
}
|
|
|
|
s += ds;
|
|
|
|
pixel++;
|
2019-10-28 08:33:30 +00:00
|
|
|
}
|
2021-11-14 17:29:58 +00:00
|
|
|
t += dt;
|
|
|
|
}
|
|
|
|
}, pos0.y, pos1.y, MIN_LINES_PER_THREAD);
|
|
|
|
} else {
|
|
|
|
ParallelRangeLoop(&g_threadManager, [=](int y1, int y2) {
|
|
|
|
int t = t_start + (y1 - pos0.y) * dt;
|
|
|
|
for (int y = y1; y < y2; y++) {
|
|
|
|
int s = s_start;
|
|
|
|
u16 *pixel = fb.Get16Ptr(pos0.x, y, gstate.FrameBufStride());
|
|
|
|
for (int x = pos0.x; x < pos1.x; x++) {
|
|
|
|
Vec4<int> prim_color = v1.color0;
|
2021-12-31 18:35:26 +00:00
|
|
|
Vec4<int> tex_color = fetchFunc(s, t, texptr, texbufw, 0);
|
2022-01-11 05:43:41 +00:00
|
|
|
prim_color = Vec4<int>(ModulateRGBA(ToVec4IntArg(prim_color), ToVec4IntArg(tex_color), state.samplerID));
|
2021-11-14 17:29:58 +00:00
|
|
|
if (prim_color.a() > 0) {
|
2021-11-20 22:22:55 +00:00
|
|
|
DrawSinglePixel5551(pixel, prim_color.ToRGBA(), pixelID);
|
2021-11-14 17:29:58 +00:00
|
|
|
}
|
|
|
|
s += ds;
|
|
|
|
pixel++;
|
|
|
|
}
|
|
|
|
t += dt;
|
2019-10-28 08:33:30 +00:00
|
|
|
}
|
2021-11-14 17:29:58 +00:00
|
|
|
}, pos0.y, pos1.y, MIN_LINES_PER_THREAD);
|
|
|
|
}
|
|
|
|
} else {
|
2022-01-02 05:19:55 +00:00
|
|
|
int xoff = ((v0.screenpos.x & 15) + 1) / 2;
|
|
|
|
int yoff = ((v0.screenpos.y & 15) + 1) / 2;
|
|
|
|
|
2022-01-12 03:42:40 +00:00
|
|
|
float dsf = ds * (1.0f / (float)(1 << state.samplerID.width0Shift));
|
|
|
|
float dtf = dt * (1.0f / (float)(1 << state.samplerID.height0Shift));
|
|
|
|
float sf_start = s_start * (1.0f / (float)(1 << state.samplerID.width0Shift));
|
|
|
|
float tf_start = t_start * (1.0f / (float)(1 << state.samplerID.height0Shift));
|
2022-01-02 05:19:55 +00:00
|
|
|
|
2021-11-14 17:29:58 +00:00
|
|
|
ParallelRangeLoop(&g_threadManager, [=](int y1, int y2) {
|
2022-01-02 05:19:55 +00:00
|
|
|
float t = tf_start + (y1 - pos0.y) * dtf;
|
2021-11-14 17:29:58 +00:00
|
|
|
for (int y = y1; y < y2; y++) {
|
2022-01-02 05:19:55 +00:00
|
|
|
float s = sf_start;
|
2021-11-14 17:29:58 +00:00
|
|
|
// Not really that fast but faster than triangle.
|
2019-10-28 08:33:30 +00:00
|
|
|
for (int x = pos0.x; x < pos1.x; x++) {
|
2022-01-11 05:43:41 +00:00
|
|
|
Vec4<int> prim_color = state.nearest(s, t, xoff, yoff, ToVec4IntArg(v1.color0), &texptr, &texbufw, 0, 0);
|
|
|
|
state.drawPixel(x, y, z, 255, ToVec4IntArg(prim_color), pixelID);
|
2022-01-02 05:19:55 +00:00
|
|
|
s += dsf;
|
2019-10-28 08:33:30 +00:00
|
|
|
}
|
2022-01-02 05:19:55 +00:00
|
|
|
t += dtf;
|
2019-10-28 08:33:30 +00:00
|
|
|
}
|
2021-11-14 17:29:58 +00:00
|
|
|
}, pos0.y, pos1.y, MIN_LINES_PER_THREAD);
|
2019-10-28 08:33:30 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-03-10 01:57:55 +00:00
|
|
|
if (pos1.x > scissorBR.x) pos1.x = scissorBR.x + 1;
|
|
|
|
if (pos1.y > scissorBR.y) pos1.y = scissorBR.y + 1;
|
2019-10-28 08:33:30 +00:00
|
|
|
if (pos0.x < scissorTL.x) pos0.x = scissorTL.x;
|
|
|
|
if (pos0.y < scissorTL.y) pos0.y = scissorTL.y;
|
2021-11-20 22:45:38 +00:00
|
|
|
if (!pixelID.stencilTest &&
|
2021-11-21 17:39:14 +00:00
|
|
|
pixelID.DepthTestFunc() == GE_COMP_ALWAYS &&
|
2021-11-20 22:45:38 +00:00
|
|
|
!pixelID.applyLogicOp &&
|
|
|
|
!pixelID.colorTest &&
|
|
|
|
!pixelID.dithering &&
|
|
|
|
// TODO: Safe?
|
2021-11-21 17:39:14 +00:00
|
|
|
pixelID.AlphaTestFunc() != GE_COMP_ALWAYS &&
|
2021-11-20 22:45:38 +00:00
|
|
|
pixelID.alphaTestRef == 0 &&
|
|
|
|
!pixelID.hasAlphaTestMask &&
|
|
|
|
pixelID.alphaBlend &&
|
2022-01-10 07:31:12 +00:00
|
|
|
samplerID.useTextureAlpha &&
|
|
|
|
samplerID.TexFunc() == GE_TEXFUNC_MODULATE &&
|
2021-11-20 22:45:38 +00:00
|
|
|
!pixelID.applyColorWriteMask &&
|
2021-11-21 17:39:14 +00:00
|
|
|
pixelID.FBFormat() == GE_FORMAT_5551) {
|
2021-01-17 04:13:16 +00:00
|
|
|
if (v1.color0.a() == 0)
|
2019-10-28 08:33:30 +00:00
|
|
|
return;
|
|
|
|
|
2021-11-14 17:29:58 +00:00
|
|
|
ParallelRangeLoop(&g_threadManager, [=](int y1, int y2) {
|
|
|
|
for (int y = y1; y < y2; y++) {
|
|
|
|
u16 *pixel = fb.Get16Ptr(pos0.x, y, gstate.FrameBufStride());
|
|
|
|
for (int x = pos0.x; x < pos1.x; x++) {
|
|
|
|
Vec4<int> prim_color = v1.color0;
|
2021-11-20 22:22:55 +00:00
|
|
|
DrawSinglePixel5551(pixel, prim_color.ToRGBA(), pixelID);
|
2021-11-14 17:29:58 +00:00
|
|
|
pixel++;
|
|
|
|
}
|
2019-10-28 08:33:30 +00:00
|
|
|
}
|
2021-11-14 17:29:58 +00:00
|
|
|
}, pos0.y, pos1.y, MIN_LINES_PER_THREAD);
|
2019-10-28 08:33:30 +00:00
|
|
|
} else {
|
2021-11-14 17:29:58 +00:00
|
|
|
ParallelRangeLoop(&g_threadManager, [=](int y1, int y2) {
|
|
|
|
for (int y = y1; y < y2; y++) {
|
|
|
|
for (int x = pos0.x; x < pos1.x; x++) {
|
|
|
|
Vec4<int> prim_color = v1.color0;
|
2022-01-11 05:43:41 +00:00
|
|
|
state.drawPixel(x, y, z, fog, ToVec4IntArg(prim_color), pixelID);
|
2021-11-14 17:29:58 +00:00
|
|
|
}
|
2019-10-28 08:33:30 +00:00
|
|
|
}
|
2021-11-14 17:29:58 +00:00
|
|
|
}, pos0.y, pos1.y, MIN_LINES_PER_THREAD);
|
2019-10-28 08:33:30 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-02 00:25:34 +00:00
|
|
|
|
|
|
|
#if defined(SOFTGPU_MEMORY_TAGGING_BASIC) || defined(SOFTGPU_MEMORY_TAGGING_DETAILED)
|
|
|
|
uint32_t bpp = pixelID.FBFormat() == GE_FORMAT_8888 ? 4 : 2;
|
2022-01-12 05:23:29 +00:00
|
|
|
std::string tag = StringFromFormat("DisplayListR_%08x", state.listPC);
|
|
|
|
std::string ztag = StringFromFormat("DisplayListRZ_%08x", state.listPC);
|
2022-01-02 00:25:34 +00:00
|
|
|
|
|
|
|
for (int y = pos0.y; y < pos1.y; y++) {
|
|
|
|
uint32_t row = gstate.getFrameBufAddress() + y * gstate.FrameBufStride() * bpp;
|
|
|
|
NotifyMemInfo(MemBlockFlags::WRITE, row + pos0.x * bpp, (pos1.x - pos0.x) * bpp, tag.c_str(), tag.size());
|
|
|
|
|
|
|
|
if (pixelID.depthWrite) {
|
|
|
|
uint32_t row = gstate.getDepthBufAddress() + y * gstate.DepthBufStride() * 2;
|
|
|
|
NotifyMemInfo(MemBlockFlags::WRITE, row + pos0.x * 2, (pos1.x - pos0.x) * 2, ztag.c_str(), ztag.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2019-10-28 08:33:30 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 14:51:37 +00:00
|
|
|
bool g_needsClearAfterDialog = false;
|
2019-10-28 08:33:30 +00:00
|
|
|
|
2021-09-30 02:19:21 +00:00
|
|
|
static inline bool NoClampOrWrap(const Vec2f &tc) {
|
|
|
|
if (tc.x < 0 || tc.y < 0)
|
|
|
|
return false;
|
2021-09-30 13:33:25 +00:00
|
|
|
return tc.x <= gstate.getTextureWidth(0) && tc.y <= gstate.getTextureHeight(0);
|
2021-09-30 02:19:21 +00:00
|
|
|
}
|
|
|
|
|
2019-10-28 08:33:30 +00:00
|
|
|
// Returns true if the normal path should be skipped.
|
2022-01-11 05:43:41 +00:00
|
|
|
bool RectangleFastPath(const VertexData &v0, const VertexData &v1, const RasterizerState &state) {
|
2020-05-24 14:51:37 +00:00
|
|
|
g_DarkStalkerStretch = DSStretch::Off;
|
2019-10-28 08:33:30 +00:00
|
|
|
// Check for 1:1 texture mapping. In that case we can call DrawSprite.
|
|
|
|
int xdiff = v1.screenpos.x - v0.screenpos.x;
|
|
|
|
int ydiff = v1.screenpos.y - v0.screenpos.y;
|
|
|
|
int udiff = (v1.texturecoords.x - v0.texturecoords.x) * 16.0f;
|
|
|
|
int vdiff = (v1.texturecoords.y - v0.texturecoords.y) * 16.0f;
|
|
|
|
bool coord_check =
|
|
|
|
(xdiff == udiff || xdiff == -udiff) &&
|
|
|
|
(ydiff == vdiff || ydiff == -vdiff);
|
2020-09-08 23:16:41 +00:00
|
|
|
// Currently only works for TL/BR, which is the most common but not required.
|
|
|
|
bool orient_check = xdiff >= 0 && ydiff >= 0;
|
2021-09-30 02:19:21 +00:00
|
|
|
// We already have a fast path for clear in ClearRectangle.
|
2022-01-11 05:43:41 +00:00
|
|
|
bool state_check = !state.pixelID.clearMode && NoClampOrWrap(v0.texturecoords) && NoClampOrWrap(v1.texturecoords);
|
2022-01-02 05:19:55 +00:00
|
|
|
// TODO: No mipmap levels? Might be a font at level 1...
|
2022-01-12 03:42:40 +00:00
|
|
|
if ((coord_check || !state.enableTextures) && orient_check && state_check) {
|
2022-01-11 05:43:41 +00:00
|
|
|
Rasterizer::DrawSprite(v0, v1, state);
|
2019-10-28 08:33:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Eliminate the stretch blit in DarkStalkers.
|
|
|
|
// We compensate for that when blitting the framebuffer in SoftGpu.cpp.
|
|
|
|
if (PSP_CoreParameter().compat.flags().DarkStalkersPresentHack && v0.texturecoords.x == 64.0f && v0.texturecoords.y == 16.0f && v1.texturecoords.x == 448.0f && v1.texturecoords.y == 240.0f) {
|
2020-05-24 14:51:37 +00:00
|
|
|
// check for save/load dialog.
|
|
|
|
if (!currentDialogActive) {
|
|
|
|
if (v0.screenpos.x == 0x7100 && v0.screenpos.y == 0x7780 && v1.screenpos.x == 0x8f00 && v1.screenpos.y == 0x8880) {
|
|
|
|
g_DarkStalkerStretch = DSStretch::Wide;
|
|
|
|
} else if (v0.screenpos.x == 0x7400 && v0.screenpos.y == 0x7780 && v1.screenpos.x == 0x8C00 && v1.screenpos.y == 0x8880) {
|
|
|
|
g_DarkStalkerStretch = DSStretch::Normal;
|
2019-10-28 08:33:30 +00:00
|
|
|
} else {
|
2020-05-24 14:51:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (g_needsClearAfterDialog) {
|
|
|
|
g_needsClearAfterDialog = false;
|
|
|
|
// Afterwards, we also need to clear the actual destination. Can do a fast rectfill.
|
|
|
|
gstate.textureMapEnable &= ~1;
|
2021-01-17 04:13:16 +00:00
|
|
|
VertexData newV1 = v1;
|
|
|
|
newV1.color0 = Vec4<int>(0, 0, 0, 255);
|
2022-01-11 05:43:41 +00:00
|
|
|
Rasterizer::DrawSprite(v0, newV1, state);
|
2020-05-24 14:51:37 +00:00
|
|
|
gstate.textureMapEnable |= 1;
|
2019-10-28 08:33:30 +00:00
|
|
|
}
|
2020-05-24 14:51:37 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
g_needsClearAfterDialog = true;
|
|
|
|
}
|
2019-10-28 08:33:30 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DetectRectangleFromThroughModeStrip(const VertexData data[4]) {
|
2021-11-14 17:00:07 +00:00
|
|
|
// We'll only do this when the color is flat.
|
|
|
|
if (!(data[0].color0 == data[1].color0))
|
|
|
|
return false;
|
|
|
|
if (!(data[1].color0 == data[2].color0))
|
|
|
|
return false;
|
|
|
|
if (!(data[2].color0 == data[3].color0))
|
|
|
|
return false;
|
|
|
|
|
2021-11-14 17:10:12 +00:00
|
|
|
// And the depth must also be flat.
|
|
|
|
if (!(data[0].screenpos.z == data[1].screenpos.z))
|
|
|
|
return false;
|
|
|
|
if (!(data[1].screenpos.z == data[2].screenpos.z))
|
|
|
|
return false;
|
|
|
|
if (!(data[2].screenpos.z == data[3].screenpos.z))
|
|
|
|
return false;
|
|
|
|
|
2019-10-28 08:33:30 +00:00
|
|
|
// OK, now let's look at data to detect rectangles. There are a few possibilities
|
|
|
|
// but we focus on Darkstalkers for now.
|
|
|
|
if (data[0].screenpos.x == data[1].screenpos.x &&
|
|
|
|
data[0].screenpos.y == data[2].screenpos.y &&
|
|
|
|
data[2].screenpos.x == data[3].screenpos.x &&
|
|
|
|
data[1].screenpos.y == data[3].screenpos.y &&
|
2021-11-14 17:00:07 +00:00
|
|
|
data[1].screenpos.y > data[0].screenpos.y &&
|
|
|
|
data[2].screenpos.x > data[0].screenpos.x) {
|
|
|
|
// Okay, this is in the shape of a triangle, but what about rotation/texture?
|
|
|
|
if (!gstate.isTextureMapEnabled())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (data[0].texturecoords.x == data[1].texturecoords.x &&
|
|
|
|
data[0].texturecoords.y == data[2].texturecoords.y &&
|
|
|
|
data[2].texturecoords.x == data[3].texturecoords.x &&
|
|
|
|
data[1].texturecoords.y == data[3].texturecoords.y &&
|
|
|
|
data[1].texturecoords.y > data[0].texturecoords.y &&
|
|
|
|
data[2].texturecoords.x > data[0].texturecoords.x) {
|
|
|
|
// It's a rectangle!
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2019-10-28 08:33:30 +00:00
|
|
|
}
|
|
|
|
// There's the other vertex order too...
|
|
|
|
if (data[0].screenpos.x == data[2].screenpos.x &&
|
|
|
|
data[0].screenpos.y == data[1].screenpos.y &&
|
|
|
|
data[1].screenpos.x == data[3].screenpos.x &&
|
|
|
|
data[2].screenpos.y == data[3].screenpos.y &&
|
2021-11-14 17:00:07 +00:00
|
|
|
data[2].screenpos.y > data[0].screenpos.y &&
|
|
|
|
data[1].screenpos.x > data[0].screenpos.x) {
|
|
|
|
// Okay, this is in the shape of a triangle, but what about rotation/texture?
|
|
|
|
if (!gstate.isTextureMapEnabled())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (data[0].texturecoords.x == data[2].texturecoords.x &&
|
|
|
|
data[0].texturecoords.y == data[1].texturecoords.y &&
|
|
|
|
data[1].texturecoords.x == data[3].texturecoords.x &&
|
|
|
|
data[2].texturecoords.y == data[3].texturecoords.y &&
|
|
|
|
data[2].texturecoords.y > data[0].texturecoords.y &&
|
|
|
|
data[1].texturecoords.x > data[0].texturecoords.x) {
|
|
|
|
// It's a rectangle!
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2019-10-28 08:33:30 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-11-14 18:24:54 +00:00
|
|
|
bool DetectRectangleFromThroughModeFan(const VertexData *data, int c, int *tlIndex, int *brIndex) {
|
|
|
|
// Color and Z must be flat.
|
|
|
|
for (int i = 1; i < c; ++i) {
|
|
|
|
if (!(data[i].color0 == data[0].color0))
|
|
|
|
return false;
|
|
|
|
if (!(data[i].screenpos.z == data[0].screenpos.z))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for the common case: a single TL-TR-BR-BL.
|
|
|
|
if (c == 4) {
|
|
|
|
const auto &tl = data[0].screenpos, &tr = data[1].screenpos;
|
|
|
|
const auto &bl = data[3].screenpos, &br = data[2].screenpos;
|
|
|
|
if (tl.x == bl.x && tr.x == br.x && tl.y == tr.y && bl.y == br.y) {
|
|
|
|
// Looking like yes. Set TL/BR based on y order first...
|
|
|
|
*tlIndex = tl.y > bl.y ? 2 : 0;
|
|
|
|
*brIndex = tl.y > bl.y ? 0 : 2;
|
|
|
|
// And if it's horizontally flipped, trade to the actual TL/BR.
|
|
|
|
if (tl.x > tr.x) {
|
|
|
|
*tlIndex ^= 1;
|
|
|
|
*brIndex ^= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do we need to think about rotation?
|
|
|
|
if (!gstate.isTextureMapEnabled())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
const auto &textl = data[*tlIndex].texturecoords, &textr = data[*tlIndex ^ 1].texturecoords;
|
|
|
|
const auto &texbl = data[*brIndex ^ 1].texturecoords, &texbr = data[*brIndex].texturecoords;
|
|
|
|
|
|
|
|
if (textl.x == texbl.x && textr.x == texbr.x && textl.y == textr.y && texbl.y == texbr.y) {
|
|
|
|
// Okay, the texture is also good, but let's avoid rotation issues.
|
|
|
|
return textl.y < texbr.y && textl.x < texbr.x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2019-10-28 08:33:30 +00:00
|
|
|
|
2021-11-14 20:17:41 +00:00
|
|
|
bool DetectRectangleSlices(const VertexData data[4]) {
|
|
|
|
// Color and Z must be flat.
|
|
|
|
for (int i = 1; i < 4; ++i) {
|
|
|
|
if (!(data[i].color0 == data[0].color0))
|
|
|
|
return false;
|
|
|
|
if (!(data[i].screenpos.z == data[0].screenpos.z))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Games very commonly use vertical strips of rectangles. Detect and combine.
|
|
|
|
const auto &tl1 = data[0].screenpos, &br1 = data[1].screenpos;
|
|
|
|
const auto &tl2 = data[2].screenpos, &br2 = data[3].screenpos;
|
|
|
|
if (tl1.y == tl2.y && br1.y == br2.y && br1.y > tl1.y) {
|
|
|
|
if (br1.x == tl2.x && tl1.x < br1.x && tl2.x < br2.x) {
|
|
|
|
if (!gstate.isTextureMapEnabled() || gstate.isModeClear())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
const auto &textl1 = data[0].texturecoords, &texbr1 = data[1].texturecoords;
|
|
|
|
const auto &textl2 = data[2].texturecoords, &texbr2 = data[3].texturecoords;
|
|
|
|
if (textl1.y != textl2.y || texbr1.y != texbr2.y || textl1.y > texbr1.y)
|
|
|
|
return false;
|
|
|
|
if (texbr1.x != textl2.x || textl1.x > texbr1.x || textl2.x > texbr2.x)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// We might be able to compare ratios, but let's expect 1:1.
|
|
|
|
int texdiff1 = (texbr1.x - textl1.x) * 16.0f;
|
|
|
|
int texdiff2 = (texbr2.x - textl2.x) * 16.0f;
|
|
|
|
int posdiff1 = br1.x - tl1.x;
|
|
|
|
int posdiff2 = br2.x - tl2.x;
|
|
|
|
return texdiff1 == posdiff1 && texdiff2 == posdiff2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-28 08:33:30 +00:00
|
|
|
} // namespace Rasterizer
|
|
|
|
|