Respect the size of the current FBO when drawing. Some cleanup.

This commit is contained in:
Henrik Rydgard committed 2013-03-16 00:40:37 +01:00
1 parent 13c2905f05
commit b1108f3290
6 files changed
+55 -21

No files matched your search

+1 -1
View File
@@ -172,6 +172,7 @@ GLES_GPU::GLES_GPU()
transformDraw_.SetTextureCache(&textureCache_);
transformDraw_.SetFramebufferManager(&framebufferManager_);
framebufferManager_.SetTextureCache(&textureCache_);
framebufferManager_.SetShaderManager(shaderManager_);
// Sanity check gstate
if ((int *)&gstate.transferstart - (int *)&gstate != 0xEA) {
@@ -327,7 +328,6 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff) {
// when it's time to draw. As most PSP games set state redundantly ALL THE TIME, this is a huge optimization.
// This also make skipping drawing very effective.
framebufferManager_.SetRenderFrameBuffer();
if (gstate_c.skipDrawReason & (SKIPDRAW_SKIPFRAME | SKIPDRAW_NON_DISPLAYED_FB))
return;
+37 -17
View File
@@ -30,6 +30,7 @@
#include "GPU/GLES/Framebuffer.h"
#include "GPU/GLES/TextureCache.h"
#include "GPU/GLES/ShaderManager.h"
static const char tex_fs[] =
"#ifdef GL_ES\n"
@@ -258,11 +259,29 @@ VirtualFramebuffer *FramebufferManager::GetDisplayFBO() {
return 0;
}
void GetViewportDimensions(int *w, int *h) {
void GetViewportDimensions(int &w, int &h) {
float vpXa = getFloat24(gstate.viewportx1);
float vpYa = getFloat24(gstate.viewporty1);
*w = (int)fabsf(vpXa * 2);
*h = (int)fabsf(vpYa * 2);
w = (int)fabsf(vpXa * 2);
h = (int)fabsf(vpYa * 2);
}
// Heuristics to figure out the size of FBO to create.
void GuessDrawingSize(int &drawing_width, int &drawing_height) {
GetViewportDimensions(drawing_width, drawing_height);
// HACK for first frame where some games don't init things right
if (drawing_width <= 1 && drawing_height <= 1) {
drawing_width = 480;
drawing_height = 272;
}
// Now, cap using scissor. Hm, no, this doesn't work so well.
/*
if (drawing_width > gstate.getScissorX2() + 1)
drawing_width = gstate.getScissorX2() + 1;
if (drawing_height > gstate.getScissorY2() + 1)
drawing_height = gstate.getScissorY2() + 1;*/
}
void FramebufferManager::SetRenderFrameBuffer() {
@@ -280,18 +299,11 @@ void FramebufferManager::SetRenderFrameBuffer() {
// As there are no clear "framebuffer width" and "framebuffer height" registers,
// we need to infer the size of the current framebuffer somehow. Let's try the viewport.
int drawing_width, drawing_height;
GetViewportDimensions(&drawing_width, &drawing_height);
// HACK for first frame where some games don't init things right
if (drawing_width <= 1 && drawing_height <= 1) {
drawing_width = 480;
drawing_height = 272;
}
int fmt = gstate.framebufpixformat & 3;
int drawing_width, drawing_height;
GuessDrawingSize(drawing_width, drawing_height);
// Find a matching framebuffer
VirtualFramebuffer *vfb = 0;
for (auto iter = vfbs_.begin(); iter != vfbs_.end(); ++iter) {
@@ -369,7 +381,6 @@ void FramebufferManager::SetRenderFrameBuffer() {
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glEnable(GL_DITHER);
glstate.viewport.set(0, 0, vfb->renderWidth, vfb->renderHeight);
currentRenderVfb_ = vfb;
INFO_LOG(HLE, "Creating FBO for %08x : %i x %i x %i", vfb->fb_address, vfb->width, vfb->height, vfb->format);
@@ -416,8 +427,16 @@ void FramebufferManager::SetRenderFrameBuffer() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
}
#endif
glstate.viewport.set(0, 0, vfb->renderWidth, vfb->renderHeight);
currentRenderVfb_ = vfb;
} else {
vfb->last_frame_used = gpuStats.numFrames;
}
// ugly...
if (gstate_c.curRTWidth != vfb->width || gstate_c.curRTHeight != vfb->height) {
shaderManager_->DirtyUniform(DIRTY_PROJTHROUGHMATRIX);
gstate_c.curRTWidth = vfb->width;
gstate_c.curRTHeight = vfb->height;
}
}
@@ -537,8 +556,9 @@ void FramebufferManager::DecimateFBOs() {
++iter;
continue;
}
if ((*iter)->last_frame_used + FBO_OLD_AGE < gpuStats.numFrames) {
INFO_LOG(HLE, "Destroying FBO for %08x (%i x %i x %i)", vfb->fb_address, vfb->width, vfb->height, vfb->format)
int age = gpuStats.numFrames - (*iter)->last_frame_used;
if (age > FBO_OLD_AGE) {
INFO_LOG(HLE, "Decimating FBO for %08x (%i x %i x %i), age %i", vfb->fb_address, vfb->width, vfb->height, vfb->format)
if (vfb->fbo) {
textureCache_->NotifyFramebufferDestroyed(vfb->fb_address, vfb);
fbo_destroy(vfb->fbo);
+6
View File
@@ -71,6 +71,8 @@ struct VirtualFramebuffer {
void CenterRect(float *x, float *y, float *w, float *h,
float origW, float origH, float frameW, float frameH);
class ShaderManager;
class FramebufferManager {
public:
FramebufferManager();
@@ -79,6 +81,9 @@ public:
void SetTextureCache(TextureCache *tc) {
textureCache_ = tc;
}
void SetShaderManager(ShaderManager *sm) {
shaderManager_ = sm;
}
void DrawPixels(const u8 *framebuf, int pixelFormat, int linesize);
void DrawActiveTexture(float x, float y, float w, float h, bool flip = false);
@@ -126,6 +131,7 @@ private:
TextureCache *textureCache_;
ShaderManager *shaderManager_;
bool resized_;
};
+1 -1
View File
@@ -244,7 +244,7 @@ void LinkedShader::updateUniforms() {
if (u_proj_through != -1 && (dirtyUniforms & DIRTY_PROJTHROUGHMATRIX))
{
Matrix4x4 proj_through;
proj_through.setOrtho(0.0f, 480, 272, 0, 0, 1);
proj_through.setOrtho(0.0f, gstate_c.curRTWidth, gstate_c.curRTHeight, 0, 0, 1);
glUniformMatrix4fv(u_proj_through, 1, GL_FALSE, proj_through.getReadPtr());
}
if (u_texenv != -1 && (dirtyUniforms & DIRTY_TEXENV)) {
+2 -2
View File
@@ -279,8 +279,8 @@ void TransformDrawEngine::ApplyDrawState(int prim) {
*/
int regionX1 = 0;
int regionY1 = 0;
int regionX2 = 480;
int regionY2 = 272;
int regionX2 = gstate_c.curRTWidth;
int regionY2 = gstate_c.curRTHeight;
float offsetX = (float)(gstate.offsetx & 0xFFFF) / 16.0f;
float offsetY = (float)(gstate.offsety & 0xFFFF) / 16.0f;
+8
View File
@@ -218,6 +218,11 @@ struct GPUgstate
int getUVLS0() const { return texshade & 0x3; } // 2 bits
int getUVLS1() const { return (texshade >> 8) & 0x3; } // 2 bits
int getScissorX1() const { return scissor1 & 0x3FF; }
int getScissorY1() const { return (scissor1 >> 10) & 0x3FF; }
int getScissorX2() const { return scissor2 & 0x3FF; }
int getScissorY2() const { return (scissor2 >> 10) & 0x3FF; }
// Vertex type
bool isModeThrough() const { return (vertType & GE_VTYPE_THROUGH) != 0; }
int getNumBoneWeights() const {
@@ -264,6 +269,9 @@ struct GPUStateCache
float vpWidth;
float vpHeight;
u32 curRTWidth;
u32 curRTHeight;
u32 getRelativeAddress(u32 data) const;
};