Convert TextureShaderApplier to a member function in DepalCache.
This commit is contained in:
parent
383adcb870
commit
58a6fd3395
3 changed files with 55 additions and 67 deletions
|
@ -243,3 +243,52 @@ std::string DepalShaderCache::DebugGetShaderString(std::string idstr, DebugShade
|
|||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Merge with DepalShaderCache?
|
||||
void DepalShaderCache::ApplyShader(DepalShader *shader, float bufferW, float bufferH, int renderW, int renderH, const KnownVertexBounds &bounds, u32 uoff, u32 voff) {
|
||||
Draw2DVertex verts[4] = {
|
||||
{-1, -1, 0, 0 },
|
||||
{ 1, -1, 1, 0 },
|
||||
{-1, 1, 0, 1 },
|
||||
{ 1, 1, 1, 1 },
|
||||
};
|
||||
|
||||
// If min is not < max, then we don't have values (wasn't set during decode.)
|
||||
if (bounds.minV < bounds.maxV) {
|
||||
const float invWidth = 1.0f / bufferW;
|
||||
const float invHeight = 1.0f / bufferH;
|
||||
// Inverse of half = double.
|
||||
const float invHalfWidth = invWidth * 2.0f;
|
||||
const float invHalfHeight = invHeight * 2.0f;
|
||||
|
||||
const int u1 = bounds.minU + uoff;
|
||||
const int v1 = bounds.minV + voff;
|
||||
const int u2 = bounds.maxU + uoff;
|
||||
const int v2 = bounds.maxV + voff;
|
||||
|
||||
const float left = u1 * invHalfWidth - 1.0f;
|
||||
const float right = u2 * invHalfWidth - 1.0f;
|
||||
const float top = v1 * invHalfHeight - 1.0f;
|
||||
const float bottom = v2 * invHalfHeight - 1.0f;
|
||||
|
||||
const float uvleft = u1 * invWidth;
|
||||
const float uvright = u2 * invWidth;
|
||||
const float uvtop = v1 * invHeight;
|
||||
const float uvbottom = v2 * invHeight;
|
||||
|
||||
// Points are: BL, BR, TR, TL.
|
||||
verts[0] = Draw2DVertex{ left, bottom, uvleft, uvbottom };
|
||||
verts[1] = Draw2DVertex{ right, bottom, uvright, uvbottom };
|
||||
verts[2] = Draw2DVertex{ left, top, uvleft, uvtop };
|
||||
verts[3] = Draw2DVertex{ right, top, uvright, uvtop };
|
||||
|
||||
// We need to reapply the texture next time since we cropped UV.
|
||||
gstate_c.Dirty(DIRTY_TEXTURE_PARAMS);
|
||||
}
|
||||
|
||||
Draw::Viewport vp{ 0.0f, 0.0f, (float)renderW, (float)renderH, 0.0f, 1.0f };
|
||||
draw_->BindPipeline(shader->pipeline);
|
||||
draw_->SetViewports(1, &vp);
|
||||
draw_->SetScissorRect(0, 0, renderW, renderH);
|
||||
draw_->DrawUP((const uint8_t *)verts, 4);
|
||||
}
|
||||
|
|
|
@ -54,6 +54,8 @@ public:
|
|||
|
||||
Draw::SamplerState *GetSampler();
|
||||
|
||||
void ApplyShader(DepalShader *shader, float bufferW, float bufferH, int renderW, int renderH, const KnownVertexBounds &bounds, u32 uoff, u32 voff);
|
||||
|
||||
void Clear();
|
||||
void Decimate();
|
||||
std::vector<std::string> DebugGetShaderIDs(DebugShaderType type);
|
||||
|
@ -79,67 +81,3 @@ private:
|
|||
std::map<u32, DepalShader *> cache_;
|
||||
std::map<u32, DepalTexture *> texCache_;
|
||||
};
|
||||
|
||||
// TODO: Merge with DepalShaderCache?
|
||||
class TextureShaderApplier {
|
||||
public:
|
||||
TextureShaderApplier(Draw::DrawContext *draw, DepalShader *shader, float bufferW, float bufferH, int renderW, int renderH)
|
||||
: draw_(draw), shader_(shader), bufferW_(bufferW), bufferH_(bufferH), renderW_(renderW), renderH_(renderH) {
|
||||
static const Draw2DVertex defaultVerts[4] = {
|
||||
{-1, -1, 0, 0 },
|
||||
{ 1, -1, 1, 0 },
|
||||
{-1, 1, 0, 1 },
|
||||
{ 1, 1, 1, 1 },
|
||||
};
|
||||
memcpy(verts_, defaultVerts, sizeof(defaultVerts));
|
||||
}
|
||||
|
||||
void Shade(const KnownVertexBounds &bounds, u32 uoff, u32 voff) {
|
||||
// If min is not < max, then we don't have values (wasn't set during decode.)
|
||||
if (bounds.minV < bounds.maxV) {
|
||||
const float invWidth = 1.0f / bufferW_;
|
||||
const float invHeight = 1.0f / bufferH_;
|
||||
// Inverse of half = double.
|
||||
const float invHalfWidth = invWidth * 2.0f;
|
||||
const float invHalfHeight = invHeight * 2.0f;
|
||||
|
||||
const int u1 = bounds.minU + uoff;
|
||||
const int v1 = bounds.minV + voff;
|
||||
const int u2 = bounds.maxU + uoff;
|
||||
const int v2 = bounds.maxV + voff;
|
||||
|
||||
const float left = u1 * invHalfWidth - 1.0f;
|
||||
const float right = u2 * invHalfWidth - 1.0f;
|
||||
const float top = v1 * invHalfHeight - 1.0f;
|
||||
const float bottom = v2 * invHalfHeight - 1.0f;
|
||||
|
||||
const float uvleft = u1 * invWidth;
|
||||
const float uvright = u2 * invWidth;
|
||||
const float uvtop = v1 * invHeight;
|
||||
const float uvbottom = v2 * invHeight;
|
||||
|
||||
// Points are: BL, BR, TR, TL.
|
||||
verts_[0] = Draw2DVertex{ left, bottom, uvleft, uvbottom };
|
||||
verts_[1] = Draw2DVertex{ right, bottom, uvright, uvbottom };
|
||||
verts_[2] = Draw2DVertex{ left, top, uvleft, uvtop };
|
||||
verts_[3] = Draw2DVertex{ right, top, uvright, uvtop };
|
||||
|
||||
// We need to reapply the texture next time since we cropped UV.
|
||||
gstate_c.Dirty(DIRTY_TEXTURE_PARAMS);
|
||||
}
|
||||
Draw::Viewport vp{ 0.0f, 0.0f, (float)renderW_, (float)renderH_, 0.0f, 1.0f };
|
||||
draw_->BindPipeline(shader_->pipeline);
|
||||
draw_->SetViewports(1, &vp);
|
||||
draw_->SetScissorRect(0, 0, renderW_, renderH_);
|
||||
draw_->DrawUP((const uint8_t *)verts_, 4);
|
||||
}
|
||||
|
||||
protected:
|
||||
Draw::DrawContext *draw_;
|
||||
DepalShader *shader_;
|
||||
Draw2DVertex verts_[4];
|
||||
float bufferW_;
|
||||
float bufferH_;
|
||||
int renderW_;
|
||||
int renderH_;
|
||||
};
|
||||
|
|
|
@ -1929,15 +1929,16 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer
|
|||
Draw::Viewport vp{ 0.0f, 0.0f, (float)framebuffer->renderWidth, (float)framebuffer->renderHeight, 0.0f, 1.0f };
|
||||
draw_->SetViewports(1, &vp);
|
||||
|
||||
TextureShaderApplier shaderApply(draw_, depalShader, framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight);
|
||||
|
||||
draw_->BindFramebufferAsTexture(framebuffer->fbo, 0, depth ? Draw::FB_DEPTH_BIT : Draw::FB_COLOR_BIT, 0);
|
||||
draw_->BindTexture(1, clutTexture);
|
||||
Draw::SamplerState *nearest = depalShaderCache_->GetSampler();
|
||||
draw_->BindSamplerStates(0, 1, &nearest);
|
||||
draw_->BindSamplerStates(1, 1, &nearest);
|
||||
|
||||
shaderApply.Shade(gstate_c.vertBounds, gstate_c.curTextureXOffset, gstate_c.curTextureYOffset);
|
||||
depalShaderCache_->ApplyShader(depalShader,
|
||||
framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight,
|
||||
gstate_c.vertBounds, gstate_c.curTextureXOffset, gstate_c.curTextureYOffset);
|
||||
|
||||
draw_->BindTexture(0, nullptr);
|
||||
framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue