Use the gstate.getViewport* accessors.

This commit is contained in:
Henrik Rydgard 2015-08-26 13:35:27 +02:00
parent 6096ef30c5
commit 29fc9e81a4
6 changed files with 43 additions and 42 deletions

View File

@ -67,12 +67,12 @@ static void PlanesFromMatrix(float mtx[16], Plane planes[6]) {
static Vec3f ClipToScreen(const Vec4f& coords) {
// TODO: Check for invalid parameters (x2 < x1, etc)
float vpx1 = getFloat24(gstate.viewportx1);
float vpx2 = getFloat24(gstate.viewportx2);
float vpy1 = getFloat24(gstate.viewporty1);
float vpy2 = getFloat24(gstate.viewporty2);
float vpz1 = getFloat24(gstate.viewportz1);
float vpz2 = getFloat24(gstate.viewportz2);
float vpx1 = gstate.getViewportX1();
float vpx2 = gstate.getViewportX2();
float vpy1 = gstate.getViewportY1();
float vpy2 = gstate.getViewportY2();
float vpz1 = gstate.getViewportZ1();
float vpz2 = gstate.getViewportZ2();
float retx = coords.x * vpx1 / coords.w + vpx2;
float rety = coords.y * vpy1 / coords.w + vpy2;

View File

@ -309,11 +309,11 @@ void ShaderManagerDX9::VSUpdateUniforms(int dirtyUniforms) {
// In Phantasy Star Portable 2, depth range sometimes goes negative and is clamped by glDepthRange to 0,
// causing graphics clipping glitch (issue #1788). This hack modifies the projection matrix to work around it.
if (g_Config.bDepthRangeHack) {
float zScale = getFloat24(gstate.viewportz1) / 65535.0f;
float zOff = getFloat24(gstate.viewportz2) / 65535.0f;
float zScale = gstate.getViewportZ1() / 65535.0f;
float zCenter = gstate.getViewportZ2() / 65535.0f;
// if far depth range < 0
if (zOff + zScale < 0.0f) {
if (zCenter + zScale < 0.0f) {
// if perspective projection
if (flippedMatrix[11] < 0.0f) {
float depthMax = gstate.getDepthRangeMax() / 65535.0f;
@ -325,7 +325,7 @@ void ShaderManagerDX9::VSUpdateUniforms(int dirtyUniforms) {
float n = b / (a - 1.0f);
float f = b / (a + 1.0f);
f = (n * f) / (n + ((zOff + zScale) * (n - f) / (depthMax - depthMin)));
f = (n * f) / (n + ((zCenter + zScale) * (n - f) / (depthMax - depthMin)));
a = (n + f) / (n - f);
b = (2.0f * n * f) / (n - f);

View File

@ -718,10 +718,10 @@ void TransformDrawEngineDX9::ApplyDrawState(int prim) {
(regionY2 - regionY1) * renderHeightFactor,
0.f, 1.f);
} else {
float vpXScale = getFloat24(gstate.viewportx1);
float vpXCenter = getFloat24(gstate.viewportx2);
float vpYScale = getFloat24(gstate.viewporty1);
float vpYCenter = getFloat24(gstate.viewporty2);
float vpXScale = gstate.getViewportX1();
float vpXCenter = gstate.getViewportX2();
float vpYScale = gstate.getViewportY1();
float vpYCenter = gstate.getViewportY2();
// The viewport transform appears to go like this:
// Xscreen = -offsetX + vpXCenter + vpXScale * Xview
@ -742,11 +742,11 @@ void TransformDrawEngineDX9::ApplyDrawState(int prim) {
vpWidth *= renderWidthFactor;
vpHeight *= renderHeightFactor;
float zScale = getFloat24(gstate.viewportz1) / 65535.0f;
float zOff = getFloat24(gstate.viewportz2) / 65535.0f;
float zScale = gstate.getViewportZ1() / 65535.0f;
float zCenter = gstate.getViewportZ2() / 65535.0f;
float depthRangeMin = zOff - fabsf(zScale);
float depthRangeMax = zOff + fabsf(zScale);
float depthRangeMin = zCenter - fabsf(zScale);
float depthRangeMax = zCenter + fabsf(zScale);
gstate_c.vpDepth = zScale * 2;

View File

@ -406,11 +406,11 @@ void LinkedShader::UpdateUniforms(u32 vertType) {
// In Phantasy Star Portable 2, depth range sometimes goes negative and is clamped by glDepthRange to 0,
// causing graphics clipping glitch (issue #1788). This hack modifies the projection matrix to work around it.
if (g_Config.bDepthRangeHack) {
float zScale = getFloat24(gstate.viewportz1) / 65535.0f;
float zOff = getFloat24(gstate.viewportz2) / 65535.0f;
float zScale = gstate.getViewportZ1() / 65535.0f;
float zCenter = gstate.getViewportZ2() / 65535.0f;
// if far depth range < 0
if (zOff + zScale < 0.0f) {
if (zCenter + zScale < 0.0f) {
// if perspective projection
if (flippedMatrix[11] < 0.0f) {
float depthMax = gstate.getDepthRangeMax() / 65535.0f;
@ -422,7 +422,7 @@ void LinkedShader::UpdateUniforms(u32 vertType) {
float n = b / (a - 1.0f);
float f = b / (a + 1.0f);
f = (n * f) / (n + ((zOff + zScale) * (n - f) / (depthMax - depthMin)));
f = (n * f) / (n + ((zCenter + zScale) * (n - f) / (depthMax - depthMin)));
a = (n + f) / (n - f);
b = (2.0f * n * f) / (n - f);

View File

@ -792,10 +792,10 @@ void TransformDrawEngine::ApplyDrawState(int prim) {
glstate.depthRange.set(0.0f, 1.0f);
} else {
// These we can turn into a glViewport call, offset by offsetX and offsetY. Math after.
float vpXScale = getFloat24(gstate.viewportx1);
float vpXCenter = getFloat24(gstate.viewportx2);
float vpYScale = getFloat24(gstate.viewporty1);
float vpYCenter = getFloat24(gstate.viewporty2);
float vpXScale = gstate.getViewportX1();
float vpXCenter = gstate.getViewportX2();
float vpYScale = gstate.getViewportY1();
float vpYCenter = gstate.getViewportY2();
// The viewport transform appears to go like this:
// Xscreen = -offsetX + vpXCenter + vpXScale * Xview
@ -861,8 +861,7 @@ void TransformDrawEngine::ApplyDrawState(int prim) {
bool scaleChanged = gstate_c.vpWidthScale != wScale || gstate_c.vpHeightScale != hScale;
bool offsetChanged = gstate_c.vpXOffset != xOffset || gstate_c.vpYOffset != yOffset;
if (scaleChanged || offsetChanged)
{
if (scaleChanged || offsetChanged) {
gstate_c.vpWidthScale = wScale;
gstate_c.vpHeightScale = hScale;
gstate_c.vpXOffset = xOffset;
@ -872,10 +871,10 @@ void TransformDrawEngine::ApplyDrawState(int prim) {
glstate.viewport.set(left, bottom, right - left, top - bottom);
float zScale = getFloat24(gstate.viewportz1) * (1.0f / 65535.0f);
float zOff = getFloat24(gstate.viewportz2) * (1.0f / 65535.0f);
float depthRangeMin = zOff - zScale;
float depthRangeMax = zOff + zScale;
float zScale = gstate.getViewportZ1() * (1.0f / 65535.0f);
float zCenter = gstate.getViewportZ2() * (1.0f / 65535.0f);
float depthRangeMin = zCenter - zScale;
float depthRangeMax = zCenter + zScale;
glstate.depthRange.set(depthRangeMin, depthRangeMax);
#ifndef MOBILE_DEVICE

View File

@ -55,22 +55,24 @@ ClipCoords TransformUnit::ViewToClip(const ViewCoords& coords)
return ClipCoords(projection_matrix * coords4);
}
// TODO: This is ugly
static inline ScreenCoords ClipToScreenInternal(const ClipCoords& coords, bool *outside_range_flag)
{
static inline ScreenCoords ClipToScreenInternal(const ClipCoords& coords, bool *outside_range_flag) {
ScreenCoords ret;
// TODO: Check for invalid parameters (x2 < x1, etc)
float vpx1 = getFloat24(gstate.viewportx1);
float vpx2 = getFloat24(gstate.viewportx2);
float vpy1 = getFloat24(gstate.viewporty1);
float vpy2 = getFloat24(gstate.viewporty2);
float vpz1 = getFloat24(gstate.viewportz1);
float vpz2 = getFloat24(gstate.viewportz2);
// Parameters here can seem invalid, but the PSP is fine with negative viewport widths etc.
// The checking that OpenGL and D3D do is actually quite superflous as the calculations still "work"
// with some pretty crazy inputs, which PSP games are happy to do at times.
float vpx1 = gstate.getViewportX1();
float vpx2 = gstate.getViewportX2();
float vpy1 = gstate.getViewportY1();
float vpy2 = gstate.getViewportY2();
float vpz1 = gstate.getViewportZ1();
float vpz2 = gstate.getViewportZ2();
float retx = coords.x * vpx1 / coords.w + vpx2;
float rety = coords.y * vpy1 / coords.w + vpy2;
float retz = coords.z * vpz1 / coords.w + vpz2;
// Is this really right?
if (gstate.clipEnable & 0x1) {
if (retz < 0.f)
retz = 0.f;