mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-04 10:03:36 +00:00
New LLE render.
This commit is contained in:
parent
84e92d1240
commit
0bc6cf7a11
|
@ -292,12 +292,16 @@ public:
|
|||
"uniform mediump vec2 uCacheOffset[2]; \n"
|
||||
"uniform mediump vec2 uCacheShiftScale[2]; \n"
|
||||
"uniform lowp ivec2 uCacheFrameBuffer; \n"
|
||||
"OUT lowp vec4 vShadeColor; \n"
|
||||
"OUT highp vec2 vTexCoord0; \n"
|
||||
"OUT highp vec2 vTexCoord1; \n"
|
||||
"OUT mediump vec2 vLodTexCoord; \n"
|
||||
"OUT lowp float vNumLights; \n"
|
||||
|
||||
;
|
||||
if (!_glinfo.isGLESX || _glinfo.noPerspective)
|
||||
m_part += "noperspective OUT lowp vec4 vShadeColor; \n";
|
||||
else
|
||||
m_part += "OUT lowp vec4 vShadeColor; \n";
|
||||
m_part +=
|
||||
"mediump vec2 calcTexCoord(in vec2 texCoord, in int idx) \n"
|
||||
"{ \n"
|
||||
" vec2 texCoordOut = texCoord*uCacheShiftScale[idx]; \n"
|
||||
|
@ -361,8 +365,13 @@ public:
|
|||
"uniform mediump vec2 uFogScale; \n"
|
||||
"uniform mediump vec2 uScreenCoordsScale; \n"
|
||||
" \n"
|
||||
"OUT lowp vec4 vShadeColor; \n"
|
||||
"OUT lowp float vNumLights; \n"
|
||||
;
|
||||
if (!_glinfo.isGLESX || _glinfo.noPerspective)
|
||||
m_part += "noperspective OUT lowp vec4 vShadeColor; \n";
|
||||
else
|
||||
m_part += "OUT lowp vec4 vShadeColor; \n";
|
||||
m_part +=
|
||||
" \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
|
@ -406,9 +415,14 @@ public:
|
|||
"IN highp vec2 aTexCoord0; \n"
|
||||
"IN highp vec2 aTexCoord1; \n"
|
||||
" \n"
|
||||
"OUT lowp vec4 vShadeColor; \n"
|
||||
"OUT highp vec2 vTexCoord0; \n"
|
||||
"OUT highp vec2 vTexCoord1; \n"
|
||||
;
|
||||
if (!_glinfo.isGLESX || _glinfo.noPerspective)
|
||||
m_part += "noperspective OUT lowp vec4 vShadeColor; \n";
|
||||
else
|
||||
m_part += "OUT lowp vec4 vShadeColor; \n";
|
||||
m_part +=
|
||||
"uniform lowp vec4 uRectColor; \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
|
@ -428,7 +442,12 @@ public:
|
|||
m_part =
|
||||
"IN highp vec4 aRectPosition; \n"
|
||||
" \n"
|
||||
"OUT lowp vec4 vShadeColor; \n"
|
||||
;
|
||||
if (!_glinfo.isGLESX || _glinfo.noPerspective)
|
||||
m_part += "noperspective OUT lowp vec4 vShadeColor; \n";
|
||||
else
|
||||
m_part += "OUT lowp vec4 vShadeColor; \n";
|
||||
m_part +=
|
||||
"uniform lowp vec4 uRectColor; \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
|
@ -876,8 +895,12 @@ public:
|
|||
;
|
||||
}
|
||||
|
||||
if (!_glinfo.isGLESX || _glinfo.noPerspective)
|
||||
m_part += "noperspective IN lowp vec4 vShadeColor; \n";
|
||||
else
|
||||
m_part += "IN lowp vec4 vShadeColor; \n";
|
||||
|
||||
m_part +=
|
||||
"IN lowp vec4 vShadeColor; \n"
|
||||
"IN highp vec2 vTexCoord0;\n"
|
||||
"IN highp vec2 vTexCoord1;\n"
|
||||
"IN mediump vec2 vLodTexCoord;\n"
|
||||
|
@ -955,10 +978,12 @@ public:
|
|||
;
|
||||
}
|
||||
|
||||
m_part +=
|
||||
"IN lowp vec4 vShadeColor; \n"
|
||||
"IN lowp float vNumLights; \n"
|
||||
;
|
||||
if (!_glinfo.isGLESX || _glinfo.noPerspective)
|
||||
m_part += "noperspective IN lowp vec4 vShadeColor; \n";
|
||||
else
|
||||
m_part += "IN lowp vec4 vShadeColor; \n";
|
||||
|
||||
m_part += "IN lowp float vNumLights; \n";
|
||||
|
||||
if (config.frameBufferEmulation.N64DepthCompare == Config::dcFast && _glinfo.ext_fetch) {
|
||||
m_part +=
|
||||
|
|
|
@ -302,6 +302,10 @@ void GraphicsDrawer::_updateScreenCoordsViewport(const FrameBuffer * _pBuffer) c
|
|||
viewportScaleX = viewportScaleY = pCurrentBuffer->m_scale;
|
||||
X = roundup(f32(pCurrentBuffer->m_originX), viewportScaleX);
|
||||
Y = roundup(f32(pCurrentBuffer->m_originY), viewportScaleY);
|
||||
if (RSP.LLE) {
|
||||
gSP.viewport.width = f32(bufferWidth);
|
||||
gSP.viewport.height = f32(bufferHeight);
|
||||
}
|
||||
}
|
||||
s32 WIDTH = roundup(f32(bufferWidth), viewportScaleX);
|
||||
s32 HEIGHT = roundup(f32(bufferHeight), viewportScaleY);
|
||||
|
@ -801,12 +805,17 @@ void GraphicsDrawer::drawScreenSpaceTriangle(u32 _numVtx, graphics::DrawModePara
|
|||
SPVertex & vtx = m_dmaVertices[i];
|
||||
vtx.modify = MODIFY_ALL;
|
||||
maxY = std::max(maxY, vtx.y);
|
||||
|
||||
vtx.clip = 0;
|
||||
if (vtx.x > gSP.viewport.width) vtx.clip |= CLIP_POSX;
|
||||
if (vtx.x < 0) vtx.clip |= CLIP_NEGX;
|
||||
if (vtx.y > gSP.viewport.height) vtx.clip |= CLIP_POSY;
|
||||
if (vtx.y < 0) vtx.clip |= CLIP_NEGY;
|
||||
}
|
||||
m_modifyVertices = MODIFY_ALL;
|
||||
|
||||
gSP.changed &= ~CHANGED_GEOMETRYMODE; // Don't update cull mode
|
||||
_prepareDrawTriangle();
|
||||
gfxContext.enable(enable::CULL_FACE, false);
|
||||
|
||||
Context::DrawTriangleParameters triParams;
|
||||
triParams.mode = _mode;
|
||||
|
@ -818,7 +827,18 @@ void GraphicsDrawer::drawScreenSpaceTriangle(u32 _numVtx, graphics::DrawModePara
|
|||
g_debugger.addTriangles(triParams);
|
||||
m_dmaVerticesNum = 0;
|
||||
|
||||
#ifndef OLD_LLE
|
||||
if (config.frameBufferEmulation.enable != 0) {
|
||||
const f32 maxY = renderTriangles(m_dmaVertices.data(), nullptr, _numVtx);
|
||||
frameBufferList().setBufferChanged(maxY);
|
||||
if (config.frameBufferEmulation.copyDepthToRDRAM == Config::cdSoftwareRender &&
|
||||
gDP.otherMode.depthUpdate != 0) {
|
||||
FrameBuffer * pCurrentDepthBuffer = frameBufferList().findBuffer(gDP.depthImageAddress);
|
||||
if (pCurrentDepthBuffer != nullptr)
|
||||
pCurrentDepthBuffer->setDirty();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
gSP.changed |= CHANGED_GEOMETRYMODE;
|
||||
}
|
||||
|
||||
|
|
|
@ -546,6 +546,7 @@ void RDP_Half_1( u32 _c )
|
|||
w0 = RDP.cmd_data[RDP.cmd_cur+0];
|
||||
w1 = RDP.cmd_data[RDP.cmd_cur+1];
|
||||
LLEcmd[RSP.cmd](w0, w1);
|
||||
LLETriangle::get().flush(cmd);
|
||||
} else {
|
||||
DebugMsg(DEBUG_NORMAL | DEBUG_IGNORED, "gDPHalf_1()\n");
|
||||
}
|
||||
|
@ -605,6 +606,7 @@ void RDP_ProcessRDPList()
|
|||
RDP.w2 = RDP.cmd_data[RDP.cmd_cur + 2];
|
||||
RDP.w3 = RDP.cmd_data[RDP.cmd_cur + 3];
|
||||
RSP.cmd = cmd;
|
||||
LLETriangle::get().flush(cmd);
|
||||
LLEcmd[cmd](RDP.w0, RDP.w1);
|
||||
|
||||
RDP.cmd_cur = (RDP.cmd_cur + CmdLength[cmd] / 4) & maxCMDMask;
|
||||
|
@ -615,7 +617,6 @@ void RDP_ProcessRDPList()
|
|||
RDP.cmd_cur = 0;
|
||||
}
|
||||
|
||||
RSP.LLE = false;
|
||||
gDP.changed |= CHANGED_COLORBUFFER;
|
||||
gDP.changed &= ~CHANGED_CPU_FB_WRITE;
|
||||
|
||||
|
|
|
@ -109,6 +109,8 @@ void RSP_CheckDLCounter()
|
|||
|
||||
void RSP_ProcessDList()
|
||||
{
|
||||
RSP.LLE = false;
|
||||
|
||||
if (ConfigOpen || dwnd().isResizeWindow()) {
|
||||
*REG.MI_INTR |= MI_INTR_DP;
|
||||
CheckInterrupts();
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "DepthBufferRender/ClipPolygon.h"
|
||||
#include "DepthBufferRender/DepthBufferRender.h"
|
||||
#include "gSP.h"
|
||||
#include "RSP.h"
|
||||
#include "SoftwareRender.h"
|
||||
#include "DepthBuffer.h"
|
||||
#include "Config.h"
|
||||
|
@ -54,6 +55,8 @@ bool calcScreenCoordinates(SPVertex * _vsrc, vertexclip * _vclip, u32 _numVertex
|
|||
const float y2 = _vclip[2].y - _vclip[1].y;
|
||||
|
||||
_clockwise = (x1*y2 - y1*x2) >= 0.0f;
|
||||
if (RSP.LLE)
|
||||
return true;
|
||||
|
||||
const u32 cullMode = (gSP.geometryMode & G_CULL_BOTH);
|
||||
|
||||
|
|
479
src/gDP.cpp
479
src/gDP.cpp
|
@ -27,6 +27,9 @@ using namespace std;
|
|||
|
||||
gDPInfo gDP;
|
||||
|
||||
// angrylion's macro
|
||||
#define SIGN(x, numb) (((x) & ((1 << numb) - 1)) | -((x) & (1 << (numb - 1))))
|
||||
|
||||
bool isCurrentColorImageDepthImage()
|
||||
{
|
||||
return (gDP.colorImage.address == gDP.depthImageAddress) ||
|
||||
|
@ -811,9 +814,6 @@ void gDPFillRectangle( s32 ulx, s32 uly, s32 lrx, s32 lry )
|
|||
|
||||
void gDPSetConvert( s32 k0, s32 k1, s32 k2, s32 k3, s32 k4, s32 k5 )
|
||||
{
|
||||
// angrylion's macro
|
||||
#define SIGN(x, numb) (((x) & ((1 << numb) - 1)) | -((x) & (1 << (numb - 1))))
|
||||
|
||||
gDP.convert.k0 = (SIGN(k0, 9) << 1) + 1;
|
||||
gDP.convert.k1 = (SIGN(k1, 9) << 1) + 1;
|
||||
gDP.convert.k2 = (SIGN(k2, 9) << 1) + 1;
|
||||
|
@ -949,6 +949,8 @@ void gDPNoOp()
|
|||
* based on sources of ziggy's z64 *
|
||||
*******************************************/
|
||||
|
||||
#ifdef OLD_LLE
|
||||
|
||||
void gDPLLETriangle(u32 _w1, u32 _w2, int _shade, int _texture, int _zbuffer, u32 * _pRdpCmd)
|
||||
{
|
||||
gSP.texture.level = _SHIFTR(_w1, 19, 3);
|
||||
|
@ -1248,55 +1250,526 @@ void gDPLLETriangle(u32 _w1, u32 _w2, int _shade, int _texture, int _zbuffer, u3
|
|||
_w1, _w2, _shade, _texture, _zbuffer);
|
||||
}
|
||||
|
||||
#endif // OLD_LLE
|
||||
|
||||
LLETriangle::LLETriangle()
|
||||
{
|
||||
m_textureTileOrg[0] = m_textureTileOrg[1] = nullptr;
|
||||
m_textureScaleOrg[0] = m_textureScaleOrg[1] = 1.0f;
|
||||
}
|
||||
|
||||
LLETriangle& LLETriangle::get()
|
||||
{
|
||||
static LLETriangle lleTriangle;
|
||||
return lleTriangle;
|
||||
}
|
||||
|
||||
void LLETriangle::start(u32 _tile)
|
||||
{
|
||||
if (!m_flushed)
|
||||
return;
|
||||
m_textureTileOrg[0] = gSP.textureTile[0];
|
||||
m_textureTileOrg[1] = gSP.textureTile[1];
|
||||
m_textureScaleOrg[0] = gSP.texture.scales;
|
||||
m_textureScaleOrg[1] = gSP.texture.scalet;
|
||||
gSP.textureTile[0] = &gDP.tiles[_tile];
|
||||
gSP.textureTile[1] = needReplaceTex1ByTex0() ? &gDP.tiles[_tile] : &gDP.tiles[(_tile + 1) & 7];
|
||||
gSP.texture.scales = 1.0f;
|
||||
gSP.texture.scalet = 1.0f;
|
||||
}
|
||||
|
||||
void LLETriangle::flush(u32 _cmd)
|
||||
{
|
||||
#ifndef OLD_LLE
|
||||
if (_cmd >= 0x08 && _cmd <= 0x0f)
|
||||
return;
|
||||
|
||||
GraphicsDrawer & drawer = dwnd().getDrawer();
|
||||
if (drawer.getDMAVerticesCount() > 0) {
|
||||
drawer.drawScreenSpaceTriangle(drawer.getDMAVerticesCount(), graphics::drawmode::TRIANGLES);
|
||||
}
|
||||
gSP.textureTile[0] = m_textureTileOrg[0];
|
||||
gSP.textureTile[1] = m_textureTileOrg[1];
|
||||
gSP.texture.scales = m_textureScaleOrg[0];
|
||||
gSP.texture.scalet = m_textureScaleOrg[1];
|
||||
#endif
|
||||
}
|
||||
|
||||
void LLETriangle::draw(bool _shade, bool _texture, bool _zbuffer, s32 * _pData)
|
||||
{
|
||||
DebugMsg(DEBUG_NORMAL, "gDPLLETriangle shade: %d, texture: %d, zbuffer: %d\n",
|
||||
int(_shade), int(_texture), int(_zbuffer));
|
||||
|
||||
gSP.texture.level = _SHIFTR(_pData[0], 19, 3);
|
||||
const u32 tile = _SHIFTR(_pData[0], 16, 3);
|
||||
const int flip = (_pData[0] & 0x800000) >> 23;
|
||||
start(tile);
|
||||
|
||||
int yl = SIGN(_pData[0], 14);
|
||||
int ym = _pData[1] >> 16;
|
||||
ym = SIGN(ym, 14);
|
||||
int yh = SIGN(_pData[1], 14);
|
||||
|
||||
int xl = SIGN(_pData[2], 28);
|
||||
int xh = SIGN(_pData[4], 28);
|
||||
int xm = SIGN(_pData[6], 28);
|
||||
|
||||
const int dxldy = SIGN(_pData[3], 30);
|
||||
const int dxhdy = SIGN(_pData[5], 30);
|
||||
const int dxmdy = SIGN(_pData[7], 30);
|
||||
|
||||
yh &= ~3;
|
||||
|
||||
int r = 0xff, g = 0xff, b = 0xff, a = 0xff;
|
||||
int drdx = 0, dgdx = 0, dbdx = 0, dadx = 0;
|
||||
int drde = 0, dgde = 0, dbde = 0, dade = 0;
|
||||
|
||||
if (_shade) {
|
||||
r = (_pData[8] & 0xffff0000) | ((_pData[12] >> 16) & 0x0000ffff);
|
||||
g = ((_pData[8] << 16) & 0xffff0000) | (_pData[12] & 0x0000ffff);
|
||||
b = (_pData[9] & 0xffff0000) | ((_pData[13] >> 16) & 0x0000ffff);
|
||||
a = ((_pData[9] << 16) & 0xffff0000) | (_pData[13] & 0x0000ffff);
|
||||
drdx = (_pData[10] & 0xffff0000) | ((_pData[14] >> 16) & 0x0000ffff);
|
||||
dgdx = ((_pData[10] << 16) & 0xffff0000) | (_pData[14] & 0x0000ffff);
|
||||
dbdx = (_pData[11] & 0xffff0000) | ((_pData[15] >> 16) & 0x0000ffff);
|
||||
dadx = ((_pData[11] << 16) & 0xffff0000) | (_pData[15] & 0x0000ffff);
|
||||
drde = (_pData[16] & 0xffff0000) | ((_pData[20] >> 16) & 0x0000ffff);
|
||||
dgde = ((_pData[16] << 16) & 0xffff0000) | (_pData[20] & 0x0000ffff);
|
||||
dbde = (_pData[17] & 0xffff0000) | ((_pData[21] >> 16) & 0x0000ffff);
|
||||
dade = ((_pData[17] << 16) & 0xffff0000) | (_pData[21] & 0x0000ffff);
|
||||
}
|
||||
|
||||
int s = 0, t = 0, w = 0x30000;
|
||||
int dsdx = 0, dtdx = 0, dwdx = 0;
|
||||
int dsde = 0, dtde = 0, dwde = 0;
|
||||
if (_texture) {
|
||||
s = (_pData[24] & 0xffff0000) | ((_pData[28] >> 16) & 0x0000ffff);
|
||||
t = ((_pData[24] << 16) & 0xffff0000) | (_pData[28] & 0x0000ffff);
|
||||
w = (_pData[25] & 0xffff0000) | ((_pData[29] >> 16) & 0x0000ffff);
|
||||
dsdx = (_pData[26] & 0xffff0000) | ((_pData[30] >> 16) & 0x0000ffff);
|
||||
dtdx = ((_pData[26] << 16) & 0xffff0000) | (_pData[30] & 0x0000ffff);
|
||||
dwdx = (_pData[27] & 0xffff0000) | ((_pData[31] >> 16) & 0x0000ffff);
|
||||
dsde = (_pData[32] & 0xffff0000) | ((_pData[36] >> 16) & 0x0000ffff);
|
||||
dtde = ((_pData[32] << 16) & 0xffff0000) | (_pData[36] & 0x0000ffff);
|
||||
dwde = (_pData[33] & 0xffff0000) | ((_pData[37] >> 16) & 0x0000ffff);
|
||||
}
|
||||
|
||||
int z = 0xffff0000;
|
||||
int dzdx = 0, dzde = 0;
|
||||
if (_zbuffer) {
|
||||
z = _pData[40];
|
||||
dzdx = _pData[41];
|
||||
dzde = _pData[42];
|
||||
}
|
||||
|
||||
std::array<SPVertex, 8> vertices;
|
||||
|
||||
auto cscale = [](int c) {
|
||||
return _FIXED2FLOATCOLOR((((c) > 0x3ff0000 ? 0x3ff0000 : ((c) < 0 ? 0 : (c))) >> 18), 8);
|
||||
};
|
||||
|
||||
float rf = cscale(r << 2);
|
||||
float gf = cscale(g << 2);
|
||||
float bf = cscale(b << 2);
|
||||
float af = cscale(a << 2);
|
||||
double wf = double(w) / double(0xffff0000);
|
||||
double zf = double(z) / double(0xffff0000);
|
||||
double sf = double(s) / double(1 << 18);
|
||||
double tf = double(t) / double(1 << 18);
|
||||
|
||||
double drdef = _FIXED2FLOAT(((drde >> 2) & ~1), 16) / 255.0;
|
||||
double dgdef = _FIXED2FLOAT(((dgde >> 2) & ~1), 16) / 255.0;
|
||||
double dbdef = _FIXED2FLOAT(((dbde >> 2) & ~1), 16) / 255.0;
|
||||
double dadef = _FIXED2FLOAT(((dade >> 2) & ~1), 16) / 255.0;
|
||||
double dwdef = double(dwde >> 2) / double(0xffff0000);
|
||||
double dzdef = double(dzde >> 2) / double(0xffff0000);
|
||||
|
||||
double dsdef = double(dsde >> 2) / double(1 << 18);
|
||||
double dtdef = double(dtde >> 2) / double(1 << 18);
|
||||
|
||||
double drdxf = _FIXED2FLOAT(drdx, 16) / 255.0;
|
||||
double dgdxf = _FIXED2FLOAT(dgdx, 16) / 255.0;
|
||||
double dbdxf = _FIXED2FLOAT(dbdx, 16) / 255.0;
|
||||
double dadxf = _FIXED2FLOAT(dadx, 16) / 255.0;
|
||||
|
||||
double dwdxf = double(dwdx >> 2) / double(0xffff0000);
|
||||
double dzdxf = double(dzdx >> 2) / double(0xffff0000);
|
||||
|
||||
double dsdxf = _FIXED2FLOAT(((dsdx >> 2) & ~1), 16);
|
||||
double dtdxf = _FIXED2FLOAT(((dtdx >> 2) & ~1), 16);
|
||||
|
||||
double xhf = _FIXED2FLOAT((xh & ~0x1), 16);
|
||||
double xmf = _FIXED2FLOAT((xm & ~0x1), 16);
|
||||
|
||||
double yhf = double(yh);
|
||||
double ymf = double(ym);
|
||||
double ylf = double(yl);
|
||||
double hk = _FIXED2FLOAT(((dxhdy >> 2) & ~0x1), 16);
|
||||
double mk = _FIXED2FLOAT(((dxmdy >> 2) & ~0x1), 16);
|
||||
double hc = xhf - hk * yhf;
|
||||
double mc = xmf - mk * yhf;
|
||||
|
||||
auto updateVtx = [&](SPVertex * vtx, double diffY, double diffx)
|
||||
{
|
||||
if (_shade) {
|
||||
auto colorClamp = [](double c) -> float
|
||||
{
|
||||
float res;
|
||||
if (c < 0.0)
|
||||
res = 0.0f;
|
||||
else if (c > 1.0)
|
||||
res = 1.0f;
|
||||
else
|
||||
res = static_cast<float>(c);
|
||||
return res;
|
||||
};
|
||||
|
||||
vtx->r = colorClamp(rf + drdef * diffY + drdxf * diffx);
|
||||
vtx->g = colorClamp(gf + dgdef * diffY + dgdxf * diffx);
|
||||
vtx->b = colorClamp(bf + dbdef * diffY + dbdxf * diffx);
|
||||
vtx->a = colorClamp(af + dadef * diffY + dadxf * diffx);
|
||||
}
|
||||
|
||||
if (_zbuffer) {
|
||||
//((gDP.otherMode.depthSource == G_ZS_PRIM) ? gDP.primDepth.z : float(u32(z)) / 0xffff0000)
|
||||
vtx->z = (gDP.otherMode.depthSource == G_ZS_PRIM) ?
|
||||
float(gDP.primDepth.z) / float(0xffff0000) :
|
||||
static_cast<float>((zf + dzdef * diffY + dzdxf * diffx * 4.0)*2.0);
|
||||
//if (vtx->z < 0.0f)
|
||||
// vtx->z = 1.0f + vtx->z - ceil(vtx->z);
|
||||
} else
|
||||
vtx->z = 1.0f;
|
||||
|
||||
if (_texture) {
|
||||
if (gDP.otherMode.texturePersp != 0) {
|
||||
double vw = wf + dwdef * diffY + dwdxf * diffx * 4.0f;
|
||||
if (vw == 0)
|
||||
int t = 0;
|
||||
vtx->w = static_cast<float>(1.0 / (vw > 0.0 ? vw : (1.0 + vw - ceil(vw))));
|
||||
//vtx->w = static_cast<float>(1.0 / vw);
|
||||
if (vw <= 0.0) {
|
||||
// TODO fix with proper coords
|
||||
vtx->s = static_cast<float>(1 << gSP.textureTile[0]->masks);
|
||||
vtx->t = static_cast<float>(1 << gSP.textureTile[0]->maskt);
|
||||
} else {
|
||||
vtx->s = static_cast<float>((sf + dsdef * diffY + dsdxf*diffx) / vw * 0.0625);
|
||||
vtx->t = static_cast<float>((tf + dtdef * diffY + dtdxf*diffx) / vw * 0.0625);
|
||||
}
|
||||
} else {
|
||||
vtx->w = 1.0f;
|
||||
vtx->s = static_cast<float>((sf + dsdef * diffY + dsdxf*diffx) * 0.125);
|
||||
vtx->t = static_cast<float>((tf + dtdef * diffY + dtdxf*diffx) * 0.125);
|
||||
}
|
||||
} else
|
||||
vtx->w = 1.0f;
|
||||
//assert(!isnan(vtx->x));
|
||||
};
|
||||
|
||||
u32 vtxCount = 0;
|
||||
if (fabs(hk - mk) < 0.00000001) {
|
||||
SPVertex * vtx = &vertices[vtxCount++];
|
||||
vtx->x = static_cast<float>(hk * yhf + hc);
|
||||
vtx->y = static_cast<float>(yhf * 0.25f);
|
||||
updateVtx(vtx, 0.0, 0.0);
|
||||
|
||||
if (mc != hc) {
|
||||
vtx = &vertices[vtxCount++];
|
||||
vtx->x = static_cast<float>(mk * yhf + mc);
|
||||
vtx->y = static_cast<float>(yhf * 0.25);
|
||||
updateVtx(vtx, 0.0, (mc - hc));
|
||||
}
|
||||
|
||||
double diffym = (ymf - yhf);
|
||||
double xhym = (hk * ymf + hc);
|
||||
double xmym = (mk * ymf + mc);
|
||||
double diffxm = (xmym - xhym);
|
||||
|
||||
#if 1
|
||||
double vw = wf + dwdef * diffym + dwdxf * diffxm * 4.0;
|
||||
if (vw <= 0.0) {
|
||||
double xhyf, xmyf, diffyf, diffxf;
|
||||
double yf = ymf;
|
||||
do {
|
||||
yf -= 1.0;
|
||||
diffyf = (yf - yhf);
|
||||
xhyf = hk * yf + hc;
|
||||
xmyf = mk * yf + mc;
|
||||
diffxf = xmyf - xhyf;
|
||||
vw = wf + dwdef * diffyf + dwdxf * diffxf * 4.0;
|
||||
} while (vw <= 0.0 && yf > yhf);
|
||||
|
||||
SPVertex * vtx = &vertices[vtxCount++];
|
||||
vtx->x = static_cast<float>(xhyf);
|
||||
vtx->y = static_cast<float>(yf * 0.25);
|
||||
updateVtx(vtx, diffyf, 0.0);
|
||||
|
||||
vtx = &vertices[vtxCount++];
|
||||
vtx->x = static_cast<float>(xmyf);
|
||||
vtx->y = static_cast<float>(yf * 0.25);
|
||||
updateVtx(vtx, diffyf, diffxf);
|
||||
}
|
||||
#endif
|
||||
|
||||
vtx = &vertices[vtxCount++];
|
||||
vtx->x = static_cast<float>(xhym);
|
||||
vtx->y = static_cast<float>(ymf * 0.25);
|
||||
updateVtx(vtx, diffym, 0.0);
|
||||
|
||||
vtx = &vertices[vtxCount++];
|
||||
vtx->x = static_cast<float>(xmym);
|
||||
vtx->y = static_cast<float>(ymf * 0.25);
|
||||
updateVtx(vtx, diffym, diffxm);
|
||||
|
||||
if (dxldy != dxmdy && ym < yl) {
|
||||
double xlf = _FIXED2FLOAT((xl & ~1), 16);
|
||||
double lk = _FIXED2FLOAT(((dxldy >> 2) & ~1), 16);
|
||||
double lc = xlf - lk * ym;
|
||||
double y4f = (lc - hc) / (hk - lk);
|
||||
vtx = &vertices[vtxCount++];
|
||||
vtx->x = static_cast<float>(hk * y4f + hc);
|
||||
vtx->y = static_cast<float>(y4f * 0.25);
|
||||
updateVtx(vtx, (y4f - yhf), 0.0);
|
||||
}
|
||||
} else {
|
||||
double y0f = (mc - hc) / (hk - mk);
|
||||
|
||||
SPVertex * vtx = &vertices[vtxCount++];
|
||||
vtx->x = static_cast<float>(hk * y0f + hc);
|
||||
vtx->y = static_cast<float>(y0f * 0.25f);
|
||||
updateVtx(vtx, (y0f - yhf), 0.0);
|
||||
|
||||
double y1f = ymf;
|
||||
double xlf = _FIXED2FLOAT((xl & ~1), 16);
|
||||
double lk = _FIXED2FLOAT(((dxldy >> 2) & ~1), 16);
|
||||
double lc = xlf - lk * y1f;
|
||||
|
||||
//double lc = xt - lk * yf;
|
||||
//if ((dxldy >> 2) == (dxmdy >> 2))
|
||||
// y1f = (lc - hc) / (hk - lk);
|
||||
//else
|
||||
// y1f = (lc - mc) / (mk - lk);
|
||||
|
||||
//if (y1f < ymf)
|
||||
// y1f = ymf;
|
||||
|
||||
vtx = &vertices[vtxCount++];
|
||||
vtx->x = static_cast<float>(xlf);
|
||||
vtx->y = static_cast<float>(y1f * 0.25);
|
||||
|
||||
double x1f = hk * y1f + hc;
|
||||
double diffx1 = xlf - x1f;
|
||||
|
||||
#if 0
|
||||
if ((dxldy >> 2) == (dxmdy >> 2))
|
||||
y1f = (lc - hc) / (hk - lk);
|
||||
else
|
||||
y1f = (lc - mc) / (mk - lk);
|
||||
#endif
|
||||
|
||||
double diffy1 = (y1f - yhf);
|
||||
updateVtx(vtx, diffy1, diffx1);
|
||||
|
||||
#if 1
|
||||
double vw1 = wf + dwdef * diffy1 + dwdxf * diffx1 * 4.0;
|
||||
if (vw1 <= 0.0) {
|
||||
double y1_1f = y1f;
|
||||
double vw1_1 = vw1;
|
||||
double x1_1f = x1f;
|
||||
double x1_2f = xlf;
|
||||
double diffy1_1 = diffy1;
|
||||
double diffx1_1 = diffx1;
|
||||
do {
|
||||
y1_1f += 1.0;
|
||||
diffy1_1 = (y1_1f - yhf);
|
||||
x1_1f = hk * y1_1f + hc;
|
||||
x1_2f = lk * y1_1f + lc;
|
||||
diffx1_1 = x1_2f - x1_1f;
|
||||
vw1_1 = wf + dwdef * diffy1_1 + dwdxf * diffx1_1 * 4.0;
|
||||
} while (vw1_1 <= 0.0 && y1_1f < ylf);
|
||||
|
||||
vtx = &vertices[vtxCount++];
|
||||
vtx->x = static_cast<float>(x1_1f);
|
||||
vtx->y = static_cast<float>(y1_1f * 0.25);
|
||||
updateVtx(vtx, diffy1_1, 0.0);
|
||||
|
||||
vtx = &vertices[vtxCount++];
|
||||
vtx->x = static_cast<float>(x1_2f);
|
||||
vtx->y = static_cast<float>(y1_1f * 0.25);
|
||||
updateVtx(vtx, diffy1_1, diffx1_1);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
if (hk == lk) {
|
||||
double lrx = lk * ylf + lc;
|
||||
vtx = &vertices[vtxCount++];
|
||||
vtx->x = static_cast<float>(lrx);
|
||||
vtx->y = static_cast<float>(ylf * 0.25 - (vertices[1].y - vertices[0].y));
|
||||
double ydiff = (vtx->y*4.0 - yhf);
|
||||
updateVtx(vtx, ydiff, diffx1);
|
||||
|
||||
vtx = &vertices[vtxCount++];
|
||||
vtx->x = static_cast<float>(lrx);
|
||||
vtx->y = static_cast<float>(ylf*0.25);
|
||||
ydiff = (ylf - yhf);
|
||||
|
||||
double x2f = hk * ylf + hc;
|
||||
double diffx2 = vtx->x - x2f;
|
||||
updateVtx(vtx, ydiff, diffx2);
|
||||
}
|
||||
else if (mk == lk) {
|
||||
vtx = &vertices[vtxCount++];
|
||||
vtx->x = static_cast<float>(hk * ylf + hc);
|
||||
vtx->y = static_cast<float>(ylf * 0.25);
|
||||
updateVtx(vtx, (ylf - yhf), 0.0);
|
||||
}
|
||||
else {
|
||||
double y2f = ylf;
|
||||
|
||||
if (yl == ym) {
|
||||
y2f = (lc - mc) / (mk - lk);
|
||||
}
|
||||
else {
|
||||
y2f = (lc - hc) / (hk - lk);
|
||||
}
|
||||
|
||||
vtx = &vertices[vtxCount++];
|
||||
vtx->x = static_cast<float>(hk * y2f + hc);
|
||||
vtx->y = static_cast<float>(y2f * 0.25);
|
||||
updateVtx(vtx, (y2f - yhf), 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
if (_texture)
|
||||
gDP.changed |= CHANGED_TILE;
|
||||
if (_zbuffer)
|
||||
gSP.geometryMode |= G_ZBUFFER;
|
||||
|
||||
if (vtxCount < 3)
|
||||
return;
|
||||
|
||||
GraphicsDrawer & drawer = dwnd().getDrawer();
|
||||
|
||||
for (u32 i = 0; i < vtxCount - 2; ++i) {
|
||||
for (u32 j = 0; j < 3; ++j) {
|
||||
SPVertex & v = drawer.getCurrentDMAVertex();
|
||||
v = vertices[i + j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef OLD_LLE
|
||||
static void gDPTriangle(u32 _w1, u32 _w2, int shade, int texture, int zbuffer)
|
||||
{
|
||||
gDPLLETriangle(_w1, _w2, shade, texture, zbuffer, RDP.cmd_data + RDP.cmd_cur);
|
||||
}
|
||||
#endif
|
||||
|
||||
void gDPTriFill(u32 w0, u32 w1)
|
||||
{
|
||||
#ifndef OLD_LLE
|
||||
s32 ewdata[44];
|
||||
memcpy(&ewdata[0], RDP.cmd_data + RDP.cmd_cur, 8 * sizeof(s32));
|
||||
memset(&ewdata[8], 0, 36 * sizeof(s32));
|
||||
LLETriangle::get().draw(0, 0, 0, ewdata);
|
||||
#else
|
||||
gDPTriangle(w0, w1, 0, 0, 0);
|
||||
#endif
|
||||
DebugMsg( DEBUG_NORMAL, "trifill\n");
|
||||
}
|
||||
|
||||
void gDPTriShade(u32 w0, u32 w1)
|
||||
{
|
||||
#ifndef OLD_LLE
|
||||
s32 ewdata[44];
|
||||
memcpy(&ewdata[0], RDP.cmd_data + RDP.cmd_cur, 24 * sizeof(s32));
|
||||
memset(&ewdata[24], 0, 20 * sizeof(s32));
|
||||
LLETriangle::get().draw(1, 0, 0, ewdata);
|
||||
#else
|
||||
gDPTriangle(w0, w1, 1, 0, 0);
|
||||
#endif
|
||||
DebugMsg( DEBUG_NORMAL, "trishade\n");
|
||||
}
|
||||
|
||||
void gDPTriTxtr(u32 w0, u32 w1)
|
||||
{
|
||||
#ifndef OLD_LLE
|
||||
s32 ewdata[44];
|
||||
memcpy(&ewdata[0], RDP.cmd_data + RDP.cmd_cur, 8 * sizeof(s32));
|
||||
memset(&ewdata[8], 0, 16 * sizeof(s32));
|
||||
memcpy(&ewdata[24], RDP.cmd_data + RDP.cmd_cur + 8, 16 * sizeof(s32));
|
||||
memset(&ewdata[40], 0, 4 * sizeof(s32));
|
||||
LLETriangle::get().draw(0, 1, 0, ewdata);
|
||||
#else
|
||||
gDPTriangle(w0, w1, 0, 1, 0);
|
||||
#endif
|
||||
DebugMsg(DEBUG_NORMAL, "tritxtr\n");
|
||||
}
|
||||
|
||||
void gDPTriShadeTxtr(u32 w0, u32 w1)
|
||||
{
|
||||
#ifndef OLD_LLE
|
||||
s32 ewdata[44];
|
||||
memcpy(&ewdata[0], RDP.cmd_data + RDP.cmd_cur, 40 * sizeof(s32));
|
||||
memset(&ewdata[40], 0, 4 * sizeof(s32));
|
||||
LLETriangle::get().draw(1, 1, 0, ewdata);
|
||||
#else
|
||||
gDPTriangle(w0, w1, 1, 1, 0);
|
||||
#endif
|
||||
DebugMsg( DEBUG_NORMAL, "trishadetxtr\n");
|
||||
}
|
||||
|
||||
void gDPTriFillZ(u32 w0, u32 w1)
|
||||
{
|
||||
#ifndef OLD_LLE
|
||||
s32 ewdata[44];
|
||||
memcpy(&ewdata[0], RDP.cmd_data + RDP.cmd_cur, 8 * sizeof(s32));
|
||||
memset(&ewdata[8], 0, 32 * sizeof(s32));
|
||||
memcpy(&ewdata[40], RDP.cmd_data + RDP.cmd_cur + 8, 4 * sizeof(s32));
|
||||
LLETriangle::get().draw(0, 0, 1, ewdata);
|
||||
#else
|
||||
gDPTriangle(w0, w1, 0, 0, 1);
|
||||
#endif
|
||||
DebugMsg( DEBUG_NORMAL, "trifillz\n");
|
||||
}
|
||||
|
||||
void gDPTriShadeZ(u32 w0, u32 w1)
|
||||
{
|
||||
#ifndef OLD_LLE
|
||||
s32 ewdata[44];
|
||||
memcpy(&ewdata[0], RDP.cmd_data + RDP.cmd_cur, 24 * sizeof(s32));
|
||||
memset(&ewdata[24], 0, 16 * sizeof(s32));
|
||||
memcpy(&ewdata[40], RDP.cmd_data + RDP.cmd_cur + 24, 4 * sizeof(s32));
|
||||
LLETriangle::get().draw(1, 0, 1, ewdata);
|
||||
#else
|
||||
gDPTriangle(w0, w1, 1, 0, 1);
|
||||
#endif
|
||||
DebugMsg( DEBUG_NORMAL, "trishadez\n");
|
||||
}
|
||||
|
||||
void gDPTriTxtrZ(u32 w0, u32 w1)
|
||||
{
|
||||
#ifndef OLD_LLE
|
||||
s32 ewdata[44];
|
||||
memcpy(&ewdata[0], RDP.cmd_data + RDP.cmd_cur, 8 * sizeof(s32));
|
||||
memset(&ewdata[8], 0, 16 * sizeof(s32));
|
||||
memcpy(&ewdata[24], RDP.cmd_data + RDP.cmd_cur + 8, 16 * sizeof(s32));
|
||||
memcpy(&ewdata[40], RDP.cmd_data + RDP.cmd_cur + 24, 4 * sizeof(s32));
|
||||
LLETriangle::get().draw(0, 1, 1, ewdata);
|
||||
#else
|
||||
gDPTriangle(w0, w1, 0, 1, 1);
|
||||
#endif
|
||||
DebugMsg( DEBUG_NORMAL, "tritxtrz\n");
|
||||
}
|
||||
|
||||
void gDPTriShadeTxtrZ(u32 w0, u32 w1)
|
||||
{
|
||||
#ifndef OLD_LLE
|
||||
s32 ewdata[44];
|
||||
memcpy(&ewdata[0], RDP.cmd_data + RDP.cmd_cur, 44 * sizeof(s32));
|
||||
LLETriangle::get().draw(1, 1, 1, ewdata);
|
||||
#else
|
||||
gDPTriangle(w0, w1, 1, 1, 1);
|
||||
#endif
|
||||
DebugMsg( DEBUG_NORMAL, "trishadetxtrz\n");
|
||||
}
|
||||
|
|
19
src/gDP.h
19
src/gDP.h
|
@ -260,6 +260,25 @@ struct gDPInfo
|
|||
|
||||
extern gDPInfo gDP;
|
||||
|
||||
//#define OLD_LLE
|
||||
|
||||
class LLETriangle
|
||||
{
|
||||
public:
|
||||
void draw(bool _shade, bool _texture, bool _zbuffer, s32 * _pData);
|
||||
void flush(u32 _cmd);
|
||||
static LLETriangle& get();
|
||||
|
||||
private:
|
||||
LLETriangle();
|
||||
LLETriangle(LLETriangle&) = delete;
|
||||
void start(u32 _tile);
|
||||
|
||||
gDPTile *m_textureTileOrg[2];
|
||||
f32 m_textureScaleOrg[2];
|
||||
bool m_flushed{ true };
|
||||
};
|
||||
|
||||
void gDPSetOtherMode( u32 mode0, u32 mode1 );
|
||||
void gDPSetPrimDepth( u16 z, u16 dz );
|
||||
void gDPSetTexturePersp( u32 enable );
|
||||
|
|
Loading…
Reference in New Issue
Block a user