Skip to content

Commit

Permalink
Postproc: Scale pixel deltas and round off screen position. Fixes #8016
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Nov 2, 2015
1 parent 728d9e5 commit b411fc0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
30 changes: 15 additions & 15 deletions GPU/Common/FramebufferCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,26 @@ void CenterDisplayOutputRect(float *x, float *y, float *w, float *h, float origW
float smallDisplayW = origW * customZoom;
float smallDisplayH = origH * customZoom;
if (!rotated) {
*x = ((frameW - smallDisplayW) / 2.0f) + offsetX;
*y = ((frameH - smallDisplayH) / 2.0f) + offsetY;
*w = smallDisplayW;
*h = smallDisplayH;
*x = floorf(((frameW - smallDisplayW) / 2.0f) + offsetX);
*y = floorf(((frameH - smallDisplayH) / 2.0f) + offsetY);
*w = floorf(smallDisplayW);
*h = floorf(smallDisplayH);
return;
} else {
*x = ((frameW - smallDisplayH) / 2.0f) + offsetX;
*y = ((frameH - smallDisplayW) / 2.0f) + offsetY;
*w = smallDisplayH;
*h = smallDisplayW;
*x = floorf(((frameW - smallDisplayH) / 2.0f) + offsetX);
*y = floorf(((frameH - smallDisplayW) / 2.0f) + offsetY);
*w = floorf(smallDisplayH);
*h = floorf(smallDisplayW);
return;
}
} else {
float pixelCrop = frameH / 270.0f;
float resCommonWidescreen = pixelCrop - floor(pixelCrop);
if (!rotated && resCommonWidescreen == 0.0f) {
*x = 0;
*y = -pixelCrop;
*w = frameW;
*h = pixelCrop * 272.0f;
*y = floorf(-pixelCrop);
*w = floorf(frameW);
*h = floorf(pixelCrop * 272.0f);
return;
}
}
Expand All @@ -102,10 +102,10 @@ void CenterDisplayOutputRect(float *x, float *y, float *w, float *h, float origW
}
}

*x = (frameW - outW) / 2.0f;
*y = (frameH - outH) / 2.0f;
*w = outW;
*h = outH;
*x = floorf((frameW - outW) / 2.0f);
*y = floorf((frameH - outH) / 2.0f);
*w = floorf(outW);
*h = floorf(outH);
}


Expand Down
14 changes: 6 additions & 8 deletions GPU/GLES/Framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ void FramebufferManager::CompileDraw2DProgram() {
deltaLoc_ = glsl_uniform_loc(postShaderProgram_, "u_texelDelta");
pixelDeltaLoc_ = glsl_uniform_loc(postShaderProgram_, "u_pixelDelta");
timeLoc_ = glsl_uniform_loc(postShaderProgram_, "u_time");

UpdatePostShaderUniforms(renderWidth_, renderHeight_);
usePostShader_ = true;
}
} else {
Expand All @@ -223,16 +221,16 @@ void FramebufferManager::CompileDraw2DProgram() {
}
}

void FramebufferManager::UpdatePostShaderUniforms(int renderWidth, int renderHeight) {
void FramebufferManager::UpdatePostShaderUniforms(int bufferWidth, int bufferHeight, int renderWidth, int renderHeight) {
float u_delta = 1.0f / renderWidth;
float v_delta = 1.0f / renderHeight;
float u_pixel_delta = u_delta;
float v_pixel_delta = v_delta;
if (postShaderAtOutputResolution_) {
float x, y, w, h;
CenterDisplayOutputRect(&x, &y, &w, &h, 480.0f, 272.0f, (float)pixelWidth_, (float)pixelHeight_, ROTATION_LOCKED_HORIZONTAL, false);
u_pixel_delta = 1.0f / w;
v_pixel_delta = 1.0f / h;
u_pixel_delta = (1.0f / w) * (480.0f / bufferWidth);
v_pixel_delta = (1.0f / h) * (272.0f / bufferHeight);
}

if (deltaLoc_ != -1)
Expand Down Expand Up @@ -427,7 +425,7 @@ void FramebufferManager::DrawFramebufferToOutput(const u8 *srcPixels, GEBufferFo
CenterDisplayOutputRect(&x, &y, &w, &h, 480.0f, 272.0f, (float)pixelWidth_, (float)pixelHeight_, uvRotation, true);
if (applyPostShader) {
glsl_bind(postShaderProgram_);
UpdatePostShaderUniforms(renderWidth_, renderHeight_);
UpdatePostShaderUniforms(480, 272, renderWidth_, renderHeight_);
}
float u0 = 0.0f, u1 = 480.0f / 512.0f;
float v0 = 0.0f, v1 = 1.0f;
Expand Down Expand Up @@ -1089,7 +1087,7 @@ void FramebufferManager::CopyDisplayToOutput() {
glstate.viewport.set(0, 0, fbo_w, fbo_h);
shaderManager_->DirtyLastShader(); // dirty lastShader_
glsl_bind(postShaderProgram_);
UpdatePostShaderUniforms(renderWidth_, renderHeight_);
UpdatePostShaderUniforms(vfb->bufferWidth, vfb->bufferHeight, renderWidth_, renderHeight_);
DrawActiveTexture(colorTexture, 0, 0, fbo_w, fbo_h, fbo_w, fbo_h, 0.0f, 0.0f, 1.0f, 1.0f, postShaderProgram_, ROTATION_LOCKED_HORIZONTAL);

fbo_unbind();
Expand Down Expand Up @@ -1132,7 +1130,7 @@ void FramebufferManager::CopyDisplayToOutput() {

shaderManager_->DirtyLastShader(); // dirty lastShader_
glsl_bind(postShaderProgram_);
UpdatePostShaderUniforms(vfb->renderWidth, vfb->renderHeight);
UpdatePostShaderUniforms(vfb->bufferWidth, vfb->bufferHeight, vfb->renderWidth, vfb->renderHeight);
if (g_Config.bEnableCardboard) {
// Left Eye Image
glstate.viewport.set(cardboardSettings.leftEyeXPosition, cardboardSettings.screenYPosition, cardboardSettings.screenWidth, cardboardSettings.screenHeight);
Expand Down
2 changes: 1 addition & 1 deletion GPU/GLES/Framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class FramebufferManager : public FramebufferManagerCommon {
virtual void NotifyRenderFramebufferUpdated(VirtualFramebuffer *vfb, bool vfbFormatChanged) override;

private:
void UpdatePostShaderUniforms(int renderWidth, int renderHeight);
void UpdatePostShaderUniforms(int bufferWidth, int bufferHeight, int renderWidth, int renderHeight);
void CompileDraw2DProgram();
void DestroyDraw2DProgram();

Expand Down

0 comments on commit b411fc0

Please sign in to comment.