mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-02 09:03:37 +00:00
Rewrite viewport for polygons with screen coords.
This commit is contained in:
parent
5f4d03fe21
commit
811dea1d77
|
@ -196,11 +196,6 @@ u32 _cutHeight(u32 _address, u32 _height, u32 _stride)
|
|||
return _height;
|
||||
}
|
||||
|
||||
u32 cutHeight(u32 _address, u32 _height, u32 _stride)
|
||||
{
|
||||
return _cutHeight(_address, _height, _stride);
|
||||
}
|
||||
|
||||
void FrameBuffer::setBufferClearParams(u32 _fillcolor, s32 _ulx, s32 _uly, s32 _lrx, s32 _lry)
|
||||
{
|
||||
m_cleared = true;
|
||||
|
@ -1273,3 +1268,16 @@ void FrameBuffer_AddAddress(u32 address, u32 _size)
|
|||
{
|
||||
RDRAMtoColorBuffer::get().addAddress(address, _size);
|
||||
}
|
||||
|
||||
u32 cutHeight(u32 _address, u32 _height, u32 _stride)
|
||||
{
|
||||
return _cutHeight(_address, _height, _stride);
|
||||
}
|
||||
|
||||
void calcCoordsScales(const FrameBuffer * _pBuffer, f32 & _scaleX, f32 & _scaleY)
|
||||
{
|
||||
const u32 bufferWidth = _pBuffer != nullptr ? _pBuffer->m_width : VI.width;
|
||||
const u32 bufferHeight = VI_GetMaxBufferHeight(bufferWidth);
|
||||
_scaleX = 1.0f / f32(bufferWidth);
|
||||
_scaleY = 1.0f / f32(bufferHeight);
|
||||
}
|
||||
|
|
|
@ -125,6 +125,7 @@ FrameBufferList & frameBufferList()
|
|||
}
|
||||
|
||||
u32 cutHeight(u32 _address, u32 _height, u32 _stride);
|
||||
void calcCoordsScales(const FrameBuffer * _pBuffer, f32 & _scaleX, f32 & _scaleY);
|
||||
|
||||
void FrameBuffer_Init();
|
||||
void FrameBuffer_Destroy();
|
||||
|
|
|
@ -588,9 +588,8 @@ public:
|
|||
|
||||
void update(bool _force) override
|
||||
{
|
||||
FrameBuffer * pCurrentBuffer = frameBufferList().getCurrent();
|
||||
const float scaleX = pCurrentBuffer != nullptr ? 1.0f / pCurrentBuffer->m_width : VI.rwidth;
|
||||
const float scaleY = pCurrentBuffer != nullptr ? 1.0f / pCurrentBuffer->m_height : VI.rheight;
|
||||
f32 scaleX, scaleY;
|
||||
calcCoordsScales(frameBufferList().getCurrent(), scaleX, scaleY);
|
||||
uScreenCoordsScale.set(2.0f*scaleX, -2.0f*scaleY, _force);
|
||||
}
|
||||
|
||||
|
|
|
@ -213,7 +213,6 @@ void GraphicsDrawer::_updateViewport() const
|
|||
if (_needAdjustCoordinate(wnd))
|
||||
Xf = _adjustViewportX(Xf);
|
||||
const s32 X = (s32)(Xf * scaleX);
|
||||
// const s32 Y = gSP.viewport.vscale[1] < 0 ? (s32)((gSP.viewport.y + gSP.viewport.vscale[1] * 2.0f) * scaleY) : (s32)((VI.height - (gSP.viewport.y + gSP.viewport.height)) * scaleY);
|
||||
const s32 Y = (s32)(gSP.viewport.y * scaleY);
|
||||
gfxContext.setViewport(X, Y,
|
||||
std::max((s32)(gSP.viewport.width * scaleX), 0), std::max((s32)(gSP.viewport.height * scaleY), 0));
|
||||
|
@ -224,7 +223,6 @@ void GraphicsDrawer::_updateViewport() const
|
|||
if (_needAdjustCoordinate(wnd))
|
||||
Xf = _adjustViewportX(Xf);
|
||||
const s32 X = (s32)(Xf * scaleX);
|
||||
// const s32 Y = gSP.viewport.vscale[1] < 0 ? (s32)((gSP.viewport.y + gSP.viewport.vscale[1] * 2.0f) * scaleY) : (s32)((pCurrentBuffer->m_height - (gSP.viewport.y + gSP.viewport.height)) * scaleY);
|
||||
const s32 Y = (s32)(gSP.viewport.y * scaleY);
|
||||
gfxContext.setViewport(X, Y,
|
||||
std::max((s32)(gSP.viewport.width * scaleX), 0), std::max((s32)(gSP.viewport.height * scaleY), 0));
|
||||
|
@ -236,10 +234,18 @@ void GraphicsDrawer::_updateScreenCoordsViewport() const
|
|||
{
|
||||
DisplayWindow & wnd = DisplayWindow::get();
|
||||
FrameBuffer * pCurrentBuffer = frameBufferList().getCurrent();
|
||||
if (pCurrentBuffer == nullptr)
|
||||
gfxContext.setViewport(0, 0, wnd.getScreenWidth(), wnd.getScreenHeight());
|
||||
else
|
||||
gfxContext.setViewport(0, 0, s32(pCurrentBuffer->m_width*pCurrentBuffer->m_scaleX), s32(pCurrentBuffer->m_height*pCurrentBuffer->m_scaleY));
|
||||
|
||||
u32 bufferWidth;
|
||||
f32 viewportScale;
|
||||
if (pCurrentBuffer == nullptr) {
|
||||
bufferWidth = VI.width;
|
||||
viewportScale = wnd.getScaleX();
|
||||
} else {
|
||||
bufferWidth = pCurrentBuffer->m_width;
|
||||
viewportScale = pCurrentBuffer->m_scaleX;
|
||||
}
|
||||
const u32 bufferHeight = VI_GetMaxBufferHeight(bufferWidth);
|
||||
gfxContext.setViewport(0, 0, (s32)(bufferWidth * viewportScale), (s32)(bufferHeight * viewportScale));
|
||||
gSP.changed |= CHANGED_VIEWPORT;
|
||||
}
|
||||
|
||||
|
@ -849,17 +855,12 @@ void GraphicsDrawer::drawRect(int _ulx, int _uly, int _lrx, int _lry)
|
|||
|
||||
m_drawingState = DrawingState::Rect;
|
||||
|
||||
FrameBuffer * pCurrentBuffer = frameBufferList().getCurrent();
|
||||
DisplayWindow & wnd = dwnd();
|
||||
if (pCurrentBuffer == nullptr)
|
||||
gfxContext.setViewport(0, 0, wnd.getScreenWidth(), wnd.getScreenHeight());
|
||||
else
|
||||
gfxContext.setViewport(0, 0, pCurrentBuffer->m_width*pCurrentBuffer->m_scaleX, pCurrentBuffer->m_height*pCurrentBuffer->m_scaleY);
|
||||
_updateScreenCoordsViewport();
|
||||
|
||||
gfxContext.enable(enable::CULL_FACE, false);
|
||||
|
||||
const float scaleX = pCurrentBuffer != nullptr ? 1.0f / pCurrentBuffer->m_width : VI.rwidth;
|
||||
const float scaleY = pCurrentBuffer != nullptr ? 1.0f / pCurrentBuffer->m_height : VI.rheight;
|
||||
f32 scaleX, scaleY;
|
||||
calcCoordsScales(frameBufferList().getCurrent(), scaleX, scaleY);
|
||||
const float Z = (gDP.otherMode.depthSource == G_ZS_PRIM) ? gDP.primDepth.z : 0.0f;
|
||||
const float W = 1.0f;
|
||||
m_rect[0].x = (float)_ulx * (2.0f * scaleX) - 1.0;
|
||||
|
@ -879,6 +880,7 @@ void GraphicsDrawer::drawRect(int _ulx, int _uly, int _lrx, int _lry)
|
|||
m_rect[3].z = Z;
|
||||
m_rect[3].w = W;
|
||||
|
||||
DisplayWindow & wnd = dwnd();
|
||||
if (wnd.isAdjustScreen() && (gDP.colorImage.width > VI.width * 98 / 100) && (_lrx - _ulx < VI.width * 9 / 10)) {
|
||||
const float scale = wnd.getAdjustScale();
|
||||
for (u32 i = 0; i < 4; ++i)
|
||||
|
@ -1092,8 +1094,8 @@ void GraphicsDrawer::drawTexturedRect(const TexturedRectParams & _params)
|
|||
&& ((cache.current[0]->frameBufferTexture == CachedTexture::fbNone && !cache.current[0]->bHDTexture))
|
||||
&& (cache.current[1] == nullptr || (cache.current[1]->frameBufferTexture == CachedTexture::fbNone && !cache.current[1]->bHDTexture));
|
||||
|
||||
const float scaleX = pCurrentBuffer != nullptr ? 1.0f / pCurrentBuffer->m_width : VI.rwidth;
|
||||
const float scaleY = pCurrentBuffer != nullptr ? 1.0f / pCurrentBuffer->m_height : VI.rheight;
|
||||
f32 scaleX, scaleY;
|
||||
calcCoordsScales(pCurrentBuffer, scaleX, scaleY);
|
||||
const float Z = (gDP.otherMode.depthSource == G_ZS_PRIM) ? gDP.primDepth.z : 0.0f;
|
||||
const float W = 1.0f;
|
||||
f32 uly, lry;
|
||||
|
@ -1241,10 +1243,7 @@ void GraphicsDrawer::drawTexturedRect(const TexturedRectParams & _params)
|
|||
if (bUseTexrectDrawer)
|
||||
m_texrectDrawer.add();
|
||||
else {
|
||||
if (pCurrentBuffer == nullptr)
|
||||
gfxContext.setViewport(0, 0, wnd.getScreenWidth(), wnd.getScreenHeight());
|
||||
else
|
||||
gfxContext.setViewport(0, 0, pCurrentBuffer->m_width*pCurrentBuffer->m_scaleX, pCurrentBuffer->m_height*pCurrentBuffer->m_scaleY);
|
||||
_updateScreenCoordsViewport();
|
||||
|
||||
Context::DrawRectParameters rectParams;
|
||||
rectParams.mode = drawmode::TRIANGLE_STRIP;
|
||||
|
|
|
@ -97,6 +97,12 @@ void TexrectDrawer::destroy()
|
|||
m_programClear.reset();
|
||||
}
|
||||
|
||||
void TexrectDrawer::_setViewport() const
|
||||
{
|
||||
const u32 bufferWidth = m_pBuffer == nullptr ? VI.width : m_pBuffer->m_width;
|
||||
gfxContext.setViewport(0, 0, bufferWidth, VI_GetMaxBufferHeight(bufferWidth));
|
||||
}
|
||||
|
||||
void TexrectDrawer::add()
|
||||
{
|
||||
DisplayWindow & wnd = dwnd();
|
||||
|
@ -150,10 +156,7 @@ void TexrectDrawer::add()
|
|||
gfxContext.enable(enable::DEPTH_TEST, false);
|
||||
gfxContext.enable(enable::BLEND, false);
|
||||
|
||||
if (m_pBuffer == nullptr)
|
||||
gfxContext.setViewport(0, 0, VI.width, VI.height);
|
||||
else
|
||||
gfxContext.setViewport(0, 0, m_pBuffer->m_width, m_pBuffer->m_height);
|
||||
_setViewport();
|
||||
|
||||
gfxContext.setScissor((s32)gDP.scissor.ulx, (s32)gDP.scissor.uly, (s32)(gDP.scissor.lrx - gDP.scissor.ulx), (s32)(gDP.scissor.lry - gDP.scissor.uly));
|
||||
|
||||
|
@ -227,8 +230,10 @@ bool TexrectDrawer::draw()
|
|||
|
||||
RectVertex * rect = drawer.m_rect;
|
||||
|
||||
const float scaleX = (m_pBuffer != nullptr ? 1.0f / m_pBuffer->m_width : VI.rwidth) * 2.0f;
|
||||
const float scaleY = (m_pBuffer != nullptr ? 1.0f / m_pBuffer->m_height : VI.rheight) * 2.0f;
|
||||
f32 scaleX, scaleY;
|
||||
calcCoordsScales(m_pBuffer, scaleX, scaleY);
|
||||
scaleX *= 2.0f;
|
||||
scaleY *= 2.0f;
|
||||
|
||||
const float s0 = (m_ulx + 1.0f) / scaleX / (float)m_pTexture->realWidth;
|
||||
const float t1 = (m_uly + 1.0f) / scaleY / (float)m_pTexture->realHeight;
|
||||
|
@ -236,10 +241,7 @@ bool TexrectDrawer::draw()
|
|||
const float t0 = (m_lry + 1.0f) / scaleY / (float)m_pTexture->realHeight;
|
||||
const float W = 1.0f;
|
||||
|
||||
if (m_pBuffer == nullptr)
|
||||
gfxContext.setViewport(0, wnd.getHeightOffset(), wnd.getScreenWidth(), wnd.getScreenHeight());
|
||||
else
|
||||
gfxContext.setViewport(0, 0, m_pBuffer->m_width*m_pBuffer->m_scaleX, m_pBuffer->m_height*m_pBuffer->m_scaleY);
|
||||
drawer._updateScreenCoordsViewport();
|
||||
|
||||
textureCache().activateTexture(0, m_pTexture);
|
||||
// Disable filtering to avoid black outlines
|
||||
|
@ -299,10 +301,7 @@ bool TexrectDrawer::draw()
|
|||
rect[2].y = -m_lry;
|
||||
rect[3].y = -m_lry;
|
||||
|
||||
if (m_pBuffer == nullptr)
|
||||
gfxContext.setViewport(0, 0, VI.width, VI.height);
|
||||
else
|
||||
gfxContext.setViewport(0, 0, m_pBuffer->m_width, m_pBuffer->m_height);
|
||||
_setViewport();
|
||||
|
||||
gfxContext.enable(enable::BLEND, false);
|
||||
gfxContext.enable(enable::SCISSOR_TEST, false);
|
||||
|
|
|
@ -21,6 +21,8 @@ public:
|
|||
bool draw();
|
||||
bool isEmpty();
|
||||
private:
|
||||
void _setViewport() const;
|
||||
|
||||
u32 m_numRects;
|
||||
u64 m_otherMode;
|
||||
u64 m_mux;
|
||||
|
|
Loading…
Reference in New Issue
Block a user