Skip to content

Commit

Permalink
Small Draw2D refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Aug 23, 2022
1 parent 5415da1 commit d1336fe
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
55 changes: 34 additions & 21 deletions GPU/Common/Draw2D.cpp
Expand Up @@ -155,7 +155,9 @@ void FramebufferManagerCommon::Ensure2DResources() {
}
}

Draw::Pipeline *FramebufferManagerCommon::Create2DPipeline(RasterChannel (*generate)(ShaderWriter &)) {
Draw::Pipeline *FramebufferManagerCommon::Create2DPipeline(std::function<RasterChannel (ShaderWriter &)> generate) {
Ensure2DResources();

using namespace Draw;
const ShaderLanguageDesc &shaderLanguageDesc = draw_->GetShaderLanguageDesc();

Expand Down Expand Up @@ -212,19 +214,42 @@ Draw::Pipeline *FramebufferManagerCommon::Create2DPipeline(RasterChannel (*gener
return pipeline;
}

void FramebufferManagerCommon::DrawStrip2D(Draw::Texture *tex, Draw2DVertex *verts, int vertexCount, bool linearFilter, Draw2DShader shader, float texW, float texH) {

void FramebufferManagerCommon::DrawStrip2D(Draw::Texture *tex, Draw2DVertex *verts, int vertexCount, bool linearFilter, Draw::Pipeline *pipeline, float texW, float texH) {
using namespace Draw;

Ensure2DResources();
Draw2DUB ub;
ub.texSizeX = tex ? tex->Width() : texW;
ub.texSizeY = tex ? tex->Height() : texH;
ub.scaleFactor = (float)renderScaleFactor_;

draw_->BindPipeline(pipeline);
draw_->UpdateDynamicUniformBuffer(&ub, sizeof(ub));

if (tex) {
draw_->BindTextures(TEX_SLOT_PSP_TEXTURE, 1, &tex);
}
draw_->BindSamplerStates(TEX_SLOT_PSP_TEXTURE, 1, linearFilter ? &draw2DSamplerLinear_ : &draw2DSamplerNearest_);
draw_->DrawUP(verts, vertexCount);

draw_->InvalidateCachedState();

gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE | DIRTY_VERTEXSHADER_STATE);
}

void FramebufferManagerCommon::DrawStrip2D(Draw::Texture *tex, Draw2DVertex *verts, int vertexCount, bool linearFilter, Draw2DShader shader, float texW, float texH) {
using namespace Draw;

const ShaderLanguageDesc &shaderLanguageDesc = draw_->GetShaderLanguageDesc();

Draw::Pipeline *pipeline = nullptr;

switch (shader) {
case DRAW2D_COPY_COLOR:
if (!draw2DPipelineColor_) {
draw2DPipelineColor_ = Create2DPipeline(&GenerateDraw2DFs);
}
draw_->BindPipeline(draw2DPipelineColor_);
pipeline = draw2DPipelineColor_;
break;

case DRAW2D_COPY_DEPTH:
Expand All @@ -236,7 +261,7 @@ void FramebufferManagerCommon::DrawStrip2D(Draw::Texture *tex, Draw2DVertex *ver
draw2DPipelineDepth_ = Create2DPipeline(&GenerateDraw2DDepthFs);
}
linearFilter = false;
draw_->BindPipeline(draw2DPipelineDepth_);
pipeline = draw2DPipelineDepth_;
break;

case DRAW2D_565_TO_DEPTH:
Expand All @@ -248,7 +273,7 @@ void FramebufferManagerCommon::DrawStrip2D(Draw::Texture *tex, Draw2DVertex *ver
draw2DPipeline565ToDepth_ = Create2DPipeline(&GenerateDraw2D565ToDepthFs);
}
linearFilter = false;
draw_->BindPipeline(draw2DPipeline565ToDepth_);
pipeline = draw2DPipeline565ToDepth_;
break;

case DRAW2D_565_TO_DEPTH_DESWIZZLE:
Expand All @@ -260,23 +285,11 @@ void FramebufferManagerCommon::DrawStrip2D(Draw::Texture *tex, Draw2DVertex *ver
draw2DPipeline565ToDepthDeswizzle_ = Create2DPipeline(&GenerateDraw2D565ToDepthDeswizzleFs);
}
linearFilter = false;
draw_->BindPipeline(draw2DPipeline565ToDepthDeswizzle_);
pipeline = draw2DPipeline565ToDepthDeswizzle_;
break;
}

Draw2DUB ub;
ub.texSizeX = tex ? tex->Width() : texW;
ub.texSizeY = tex ? tex->Height() : texH;
ub.scaleFactor = (float)renderScaleFactor_;
draw_->UpdateDynamicUniformBuffer(&ub, sizeof(ub));

if (tex) {
draw_->BindTextures(TEX_SLOT_PSP_TEXTURE, 1, &tex);
if (pipeline) {
DrawStrip2D(tex, verts, vertexCount, linearFilter, pipeline, texW, texH);
}
draw_->BindSamplerStates(TEX_SLOT_PSP_TEXTURE, 1, linearFilter ? &draw2DSamplerLinear_ : &draw2DSamplerNearest_);
draw_->DrawUP(verts, vertexCount);

draw_->InvalidateCachedState();

gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE | DIRTY_VERTEXSHADER_STATE);
}
4 changes: 3 additions & 1 deletion GPU/Common/FramebufferManagerCommon.h
Expand Up @@ -376,8 +376,10 @@ class FramebufferManagerCommon {
void DrawActiveTexture(float x, float y, float w, float h, float destW, float destH, float u0, float v0, float u1, float v1, int uvRotation, int flags);

void DrawStrip2D(Draw::Texture *tex, Draw2DVertex *verts, int vertexCount, bool linearFilter, Draw2DShader channel, float texW = 0.0f, float texH = 0.0f);
void DrawStrip2D(Draw::Texture *tex, Draw2DVertex *verts, int vertexCount, bool linearFilter, Draw::Pipeline *pipeline, float texW = 0.0f, float texH = 0.0f);

void Ensure2DResources();
Draw::Pipeline *Create2DPipeline(RasterChannel (*generate)(ShaderWriter &));
Draw::Pipeline *Create2DPipeline(std::function<RasterChannel(ShaderWriter &)> generate);

void CopyToColorFromOverlappingFramebuffers(VirtualFramebuffer *dest);
void CopyToDepthFromOverlappingFramebuffers(VirtualFramebuffer *dest);
Expand Down

0 comments on commit d1336fe

Please sign in to comment.