Skip to content

Commit

Permalink
Stop stretching things to the FBO size.
Browse files Browse the repository at this point in the history
Instead, draw in the top corner.  This way, even if framebuffers get
smaller things stay consistent.
  • Loading branch information
unknownbrackets committed Jun 2, 2014
1 parent cfb2170 commit c2ccfd5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
25 changes: 10 additions & 15 deletions GPU/GLES/Framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ void FramebufferManager::MakePixelTexture(const u8 *srcPixels, GEBufferFormat sr
void FramebufferManager::DrawPixels(VirtualFramebuffer *vfb, int dstX, int dstY, const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height) {
MakePixelTexture(srcPixels, srcPixelFormat, srcStride, width, height);
DisableState();
DrawActiveTexture(0, dstX, dstY, width, height, vfb->width, vfb->height, false, 0.0f, 0.0f, 1.0f, 1.0f);
DrawActiveTexture(0, dstX, dstY, width, height, vfb->bufferWidth, vfb->bufferHeight, false, 0.0f, 0.0f, 1.0f, 1.0f);
}

void FramebufferManager::DrawFramebuffer(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, bool applyPostShader) {
Expand Down Expand Up @@ -773,12 +773,8 @@ void FramebufferManager::DoSetRenderFrameBuffer() {
// Update fb stride in case it changed
vfb->fb_stride = fb_stride;
v->format = fmt;
if (v->width < drawing_width) {
v->width = drawing_width;
}
if (v->height < drawing_height) {
v->height = drawing_height;
}
v->width = drawing_width;
v->height = drawing_height;
break;
}
}
Expand Down Expand Up @@ -1101,7 +1097,6 @@ void FramebufferManager::BindFramebufferColor(VirtualFramebuffer *framebuffer, b

fbo_bind_as_render_target(currentRenderVfb_->fbo);
fbo_bind_color_as_texture(renderCopy, 0);
glstate.viewport.restore();
} else {
fbo_bind_color_as_texture(framebuffer->fbo, 0);
}
Expand Down Expand Up @@ -1174,7 +1169,7 @@ void FramebufferManager::CopyDisplayToOutput() {
if (!usePostShader_) {
glstate.viewport.set(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight);
// These are in the output display coordinates
DrawActiveTexture(colorTexture, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, true, 0.0f, 0.0f, 480.0f / (float)vfb->width, 272.0f / (float)vfb->height);
DrawActiveTexture(colorTexture, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, true, 0.0f, 0.0f, 480.0f / (float)vfb->bufferWidth, 272.0f / (float)vfb->bufferHeight);
} else if (usePostShader_ && extraFBOs_.size() == 1 && !postShaderAtOutputResolution_) {
// An additional pass, post-processing shader to the extra FBO.
fbo_bind_as_render_target(extraFBOs_[0]);
Expand All @@ -1194,12 +1189,12 @@ void FramebufferManager::CopyDisplayToOutput() {
colorTexture = fbo_get_color_texture(extraFBOs_[0]);
glstate.viewport.set(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight);
// These are in the output display coordinates
DrawActiveTexture(colorTexture, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, true, 0.0f, 0.0f, 480.0f / (float)vfb->width, 272.0f / (float)vfb->height);
DrawActiveTexture(colorTexture, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, true, 0.0f, 0.0f, 480.0f / (float)vfb->bufferWidth, 272.0f / (float)vfb->bufferHeight);
} else {
// Use post-shader, but run shader at output resolution.
glstate.viewport.set(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight);
// These are in the output display coordinates
DrawActiveTexture(colorTexture, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, true, 0.0f, 0.0f, 480.0f / (float)vfb->width, 272.0f / (float)vfb->height, postShaderProgram_);
DrawActiveTexture(colorTexture, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, true, 0.0f, 0.0f, 480.0f / (float)vfb->bufferWidth, 272.0f / (float)vfb->bufferHeight, postShaderProgram_);
}

glBindTexture(GL_TEXTURE_2D, 0);
Expand Down Expand Up @@ -1422,14 +1417,14 @@ void FramebufferManager::BlitFramebuffer_(VirtualFramebuffer *dst, int dstX, int
// Make sure our 2D drawing program is ready. Compiles only if not already compiled.
CompileDraw2DProgram();

glViewport(0, 0, dst->width, dst->height);
glViewport(0, 0, dst->renderWidth, dst->renderHeight);
DisableState();

// The first four coordinates are relative to the 6th and 7th arguments of DrawActiveTexture.
// Should maybe revamp that interface.
float srcW = src->width;
float srcH = src->height;
DrawActiveTexture(0, dstX, dstY, w, h, dst->width, dst->height, false, srcX / srcW, srcY / srcH, (srcX + w) / srcW, (srcY + h) / srcH, draw2dprogram_);
float srcW = src->bufferWidth;
float srcH = src->bufferHeight;
DrawActiveTexture(0, dstX, dstY, w, h, dst->bufferWidth, dst->bufferHeight, !flip, srcX / srcW, srcY / srcH, (srcX + w) / srcW, (srcY + h) / srcH, draw2dprogram_);
glBindTexture(GL_TEXTURE_2D, 0);
textureCache_->ForgetLastTexture();
}
Expand Down
2 changes: 2 additions & 0 deletions GPU/GLES/Framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ class FramebufferManager {
int GetRenderHeight() const { return currentRenderVfb_ ? currentRenderVfb_->renderHeight : 272; }
int GetTargetWidth() const { return currentRenderVfb_ ? currentRenderVfb_->width : 480; }
int GetTargetHeight() const { return currentRenderVfb_ ? currentRenderVfb_->height : 272; }
int GetTargetBufferWidth() const { return currentRenderVfb_ ? currentRenderVfb_->bufferWidth : 480; }
int GetTargetBufferHeight() const { return currentRenderVfb_ ? currentRenderVfb_->bufferHeight : 272; }

u32 PrevDisplayFramebufAddr() {
return prevDisplayFramebuf_ ? (0x04000000 | prevDisplayFramebuf_->fb_address) : 0;
Expand Down
11 changes: 7 additions & 4 deletions GPU/GLES/StateMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ void TransformDrawEngine::ApplyDrawState(int prim) {
}
}

bool throughmode = gstate.isModeThrough();

float renderWidthFactor, renderHeightFactor;
float renderWidth, renderHeight;
float renderX, renderY;
Expand All @@ -470,8 +472,8 @@ void TransformDrawEngine::ApplyDrawState(int prim) {
renderY = 0.0f;
renderWidth = framebufferManager_->GetRenderWidth();
renderHeight = framebufferManager_->GetRenderHeight();
renderWidthFactor = (float)renderWidth / framebufferManager_->GetTargetWidth();
renderHeightFactor = (float)renderHeight / framebufferManager_->GetTargetHeight();
renderWidthFactor = (float)renderWidth / framebufferManager_->GetTargetBufferWidth();
renderHeightFactor = (float)renderHeight / framebufferManager_->GetTargetBufferHeight();
} else {
// TODO: Aspect-ratio aware and centered
float pixelW = PSP_CoreParameter().pixelWidth;
Expand All @@ -481,8 +483,6 @@ void TransformDrawEngine::ApplyDrawState(int prim) {
renderHeightFactor = renderHeight / 272.0f;
}

bool throughmode = gstate.isModeThrough();

// Scissor
int scissorX1 = gstate.getScissorX1();
int scissorY1 = gstate.getScissorY1();
Expand Down Expand Up @@ -518,6 +518,9 @@ void TransformDrawEngine::ApplyDrawState(int prim) {
float offsetY = gstate.getOffsetY();

if (throughmode) {
// If the buffer is too large, offset the viewport to the top.
renderY += renderHeight - framebufferManager_->GetTargetHeight() * renderHeightFactor;

// No viewport transform here. Let's experiment with using region.
glstate.viewport.set(
renderX + (0 + regionX1) * renderWidthFactor,
Expand Down
4 changes: 2 additions & 2 deletions GPU/GLES/TextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -959,8 +959,8 @@ void TextureCache::SetTextureFramebuffer(TexCacheEntry *entry) {
entry->framebuffer->last_frame_used = gpuStats.numFlips;

// We need to force it, since we may have set it on a texture before attaching.
gstate_c.curTextureWidth = entry->framebuffer->width;
gstate_c.curTextureHeight = entry->framebuffer->height;
gstate_c.curTextureWidth = entry->framebuffer->bufferWidth;
gstate_c.curTextureHeight = entry->framebuffer->bufferHeight;
gstate_c.flipTexture = true;
gstate_c.textureFullAlpha = entry->framebuffer->format == GE_FORMAT_565;
gstate_c.textureSimpleAlpha = gstate_c.textureFullAlpha;
Expand Down

0 comments on commit c2ccfd5

Please sign in to comment.