mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-02-22 23:22:25 +00:00
Move the TextureShaderApplier out to DepalettizeCommon
This commit is contained in:
parent
ab560d9224
commit
7800bfdf72
@ -23,6 +23,7 @@
|
||||
#include "Common/GPU/Shader.h"
|
||||
#include "Common/GPU/thin3d.h"
|
||||
#include "GPU/ge_constants.h"
|
||||
#include "GPU/Common/Draw2D.h"
|
||||
#include "GPU/Common/ShaderCommon.h"
|
||||
#include "GPU/Common/DepalettizeShaderCommon.h"
|
||||
|
||||
@ -71,3 +72,103 @@ private:
|
||||
std::map<u32, DepalTexture *> texCache_;
|
||||
};
|
||||
|
||||
// TODO: Merge with DepalShaderCache?
|
||||
class TextureShaderApplier {
|
||||
public:
|
||||
struct Pos {
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
struct UV {
|
||||
float u;
|
||||
float v;
|
||||
};
|
||||
|
||||
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 Pos pos[4] = {
|
||||
{-1, -1 },
|
||||
{ 1, -1 },
|
||||
{-1, 1 },
|
||||
{ 1, 1 },
|
||||
};
|
||||
memcpy(pos_, pos, sizeof(pos_));
|
||||
|
||||
static const UV uv[4] = {
|
||||
{ 0, 0 },
|
||||
{ 1, 0 },
|
||||
{ 0, 1 },
|
||||
{ 1, 1 },
|
||||
};
|
||||
memcpy(uv_, uv, sizeof(uv_));
|
||||
}
|
||||
|
||||
void ApplyBounds(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;
|
||||
// Points are: BL, BR, TR, TL.
|
||||
pos_[0] = Pos{ left, bottom };
|
||||
pos_[1] = Pos{ right, bottom };
|
||||
pos_[2] = Pos{ left, top };
|
||||
pos_[3] = Pos{ right, top };
|
||||
|
||||
// And also the UVs, same order.
|
||||
const float uvleft = u1 * invWidth;
|
||||
const float uvright = u2 * invWidth;
|
||||
const float uvtop = v1 * invHeight;
|
||||
const float uvbottom = v2 * invHeight;
|
||||
uv_[0] = UV{ uvleft, uvbottom };
|
||||
uv_[1] = UV{ uvright, uvbottom };
|
||||
uv_[2] = UV{ uvleft, uvtop };
|
||||
uv_[3] = UV{ uvright, uvtop };
|
||||
|
||||
// We need to reapply the texture next time since we cropped UV.
|
||||
gstate_c.Dirty(DIRTY_TEXTURE_PARAMS);
|
||||
}
|
||||
}
|
||||
|
||||
void Use() {
|
||||
draw_->BindPipeline(shader_->pipeline);
|
||||
struct SimpleVertex {
|
||||
float pos[2];
|
||||
float uv[2];
|
||||
};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
memcpy(&verts_[i].x, &pos_[i], sizeof(Pos));
|
||||
memcpy(&verts_[i].u, &uv_[i], sizeof(UV));
|
||||
}
|
||||
}
|
||||
|
||||
void Shade() {
|
||||
Draw::Viewport vp{ 0.0f, 0.0f, (float)renderW_, (float)renderH_, 0.0f, 1.0f };
|
||||
draw_->SetViewports(1, &vp);
|
||||
draw_->SetScissorRect(0, 0, renderW_, renderH_);
|
||||
draw_->DrawUP((const uint8_t *)verts_, 4);
|
||||
}
|
||||
|
||||
protected:
|
||||
Draw::DrawContext *draw_;
|
||||
DepalShader *shader_;
|
||||
Pos pos_[4];
|
||||
UV uv_[4];
|
||||
Draw2DVertex verts_[4];
|
||||
float bufferW_;
|
||||
float bufferH_;
|
||||
int renderW_;
|
||||
int renderH_;
|
||||
};
|
||||
|
@ -231,107 +231,6 @@ void TextureCacheGLES::Unbind() {
|
||||
InvalidateLastTexture();
|
||||
}
|
||||
|
||||
// TODO: Move this thing directly into Depal.
|
||||
class TextureShaderApplier {
|
||||
public:
|
||||
struct Pos {
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
struct UV {
|
||||
float u;
|
||||
float v;
|
||||
};
|
||||
|
||||
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 Pos pos[4] = {
|
||||
{-1, -1 },
|
||||
{ 1, -1 },
|
||||
{-1, 1 },
|
||||
{ 1, 1 },
|
||||
};
|
||||
memcpy(pos_, pos, sizeof(pos_));
|
||||
|
||||
static const UV uv[4] = {
|
||||
{ 0, 0 },
|
||||
{ 1, 0 },
|
||||
{ 0, 1 },
|
||||
{ 1, 1 },
|
||||
};
|
||||
memcpy(uv_, uv, sizeof(uv_));
|
||||
}
|
||||
|
||||
void ApplyBounds(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;
|
||||
// Points are: BL, BR, TR, TL.
|
||||
pos_[0] = Pos{ left, bottom };
|
||||
pos_[1] = Pos{ right, bottom };
|
||||
pos_[2] = Pos{ left, top };
|
||||
pos_[3] = Pos{ right, top };
|
||||
|
||||
// And also the UVs, same order.
|
||||
const float uvleft = u1 * invWidth;
|
||||
const float uvright = u2 * invWidth;
|
||||
const float uvtop = v1 * invHeight;
|
||||
const float uvbottom = v2 * invHeight;
|
||||
uv_[0] = UV{ uvleft, uvbottom };
|
||||
uv_[1] = UV{ uvright, uvbottom };
|
||||
uv_[2] = UV{ uvleft, uvtop };
|
||||
uv_[3] = UV{ uvright, uvtop };
|
||||
|
||||
// We need to reapply the texture next time since we cropped UV.
|
||||
gstate_c.Dirty(DIRTY_TEXTURE_PARAMS);
|
||||
}
|
||||
}
|
||||
|
||||
void Use(DrawEngineGLES *transformDraw) {
|
||||
draw_->BindPipeline(shader_->pipeline);
|
||||
struct SimpleVertex {
|
||||
float pos[2];
|
||||
float uv[2];
|
||||
};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
memcpy(&verts_[i].x, &pos_[i], sizeof(Pos));
|
||||
memcpy(&verts_[i].u, &uv_[i], sizeof(UV));
|
||||
}
|
||||
}
|
||||
|
||||
void Shade() {
|
||||
Draw::Viewport vp{ 0.0f, 0.0f, (float)renderW_, (float)renderH_, 0.0f, 1.0f };
|
||||
draw_->SetViewports(1, &vp);
|
||||
draw_->SetScissorRect(0, 0, renderW_, renderH_);
|
||||
draw_->DrawUP((const uint8_t *)verts_, 4);
|
||||
}
|
||||
|
||||
protected:
|
||||
Draw::DrawContext *draw_;
|
||||
DepalShader *shader_;
|
||||
Pos pos_[4];
|
||||
UV uv_[4];
|
||||
Draw2DVertex verts_[4];
|
||||
float bufferW_;
|
||||
float bufferH_;
|
||||
int renderW_;
|
||||
int renderH_;
|
||||
};
|
||||
|
||||
void TextureCacheGLES::BindAsClutTexture(Draw::Texture *tex) {
|
||||
GLRTexture *glrTex = (GLRTexture *)draw_->GetNativeObject(Draw::NativeObject::TEXTURE, tex);
|
||||
render_->BindTexture(TEX_SLOT_CLUT, glrTex);
|
||||
@ -395,7 +294,7 @@ void TextureCacheGLES::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer,
|
||||
|
||||
TextureShaderApplier shaderApply(draw_, depalShader, framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight);
|
||||
shaderApply.ApplyBounds(gstate_c.vertBounds, gstate_c.curTextureXOffset, gstate_c.curTextureYOffset);
|
||||
shaderApply.Use(drawEngine_);
|
||||
shaderApply.Use();
|
||||
|
||||
draw_->BindFramebufferAsTexture(framebuffer->fbo, 0, depth ? Draw::FB_DEPTH_BIT : Draw::FB_COLOR_BIT, 0);
|
||||
Draw::SamplerState *nearest = depalShaderCache_->GetSampler();
|
||||
|
Loading…
x
Reference in New Issue
Block a user