mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-10-07 19:03:29 +00:00
Draw2D
This commit is contained in:
parent
4e4ccbd819
commit
59b3df0643
@ -1529,6 +1529,8 @@ endif()
|
|||||||
set(GPU_SOURCES
|
set(GPU_SOURCES
|
||||||
${GPU_IMPLS}
|
${GPU_IMPLS}
|
||||||
${GPU_NEON}
|
${GPU_NEON}
|
||||||
|
GPU/Common/Draw2D.cpp
|
||||||
|
GPU/Common/Draw2D.h
|
||||||
GPU/Common/DepalettizeShaderCommon.cpp
|
GPU/Common/DepalettizeShaderCommon.cpp
|
||||||
GPU/Common/DepalettizeShaderCommon.h
|
GPU/Common/DepalettizeShaderCommon.h
|
||||||
GPU/Common/FragmentShaderGenerator.cpp
|
GPU/Common/FragmentShaderGenerator.cpp
|
||||||
|
123
GPU/Common/Draw2D.cpp
Normal file
123
GPU/Common/Draw2D.cpp
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
// Copyright (c) 2014- PPSSPP Project.
|
||||||
|
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, version 2.0 or later versions.
|
||||||
|
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License 2.0 for more details.
|
||||||
|
|
||||||
|
// A copy of the GPL 2.0 should have been included with the program.
|
||||||
|
// If not, see http://www.gnu.org/licenses/
|
||||||
|
|
||||||
|
// Official git repository and contact information can be found at
|
||||||
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||||
|
|
||||||
|
#include "Common/GPU/Shader.h"
|
||||||
|
#include "Common/GPU/ShaderWriter.h"
|
||||||
|
#include "Common/GPU/thin3d.h"
|
||||||
|
#include "Core/Config.h"
|
||||||
|
#include "Core/ConfigValues.h"
|
||||||
|
#include "Core/Reporting.h"
|
||||||
|
#include "GPU/Common/Draw2D.h"
|
||||||
|
#include "GPU/Common/DrawEngineCommon.h"
|
||||||
|
#include "GPU/Common/FramebufferManagerCommon.h"
|
||||||
|
#include "GPU/Common/TextureCacheCommon.h"
|
||||||
|
|
||||||
|
static const InputDef inputs[2] = {
|
||||||
|
{ "vec2", "a_position", "POSITION" },
|
||||||
|
{ "vec2", "a_texcoord", "TEXCOORD0" },
|
||||||
|
};
|
||||||
|
|
||||||
|
static const VaryingDef varyings[1] = {
|
||||||
|
{ "vec2", "v_texcoord", "TEXCOORD0", 0, "highp" },
|
||||||
|
};
|
||||||
|
|
||||||
|
void GenerateDraw2DFs(char *buffer, const ShaderLanguageDesc &lang, const Draw::Bugs &bugs) {
|
||||||
|
ShaderWriter writer(buffer, lang, ShaderStage::Fragment, nullptr, 0);
|
||||||
|
writer.DeclareSampler2D("samp", 0);
|
||||||
|
writer.DeclareTexture2D("tex", 0);
|
||||||
|
writer.BeginFSMain(Slice<UniformDef>::empty(), varyings);
|
||||||
|
writer.C(" vec4 outColor = ").SampleTexture2D("tex", "samp", "v_texcoord.xy").C(";\n");
|
||||||
|
writer.EndFSMain("outColor");
|
||||||
|
}
|
||||||
|
|
||||||
|
void GenerateDraw2DVS(char *buffer, const ShaderLanguageDesc &lang) {
|
||||||
|
ShaderWriter writer(buffer, lang, ShaderStage::Vertex, nullptr, 0);
|
||||||
|
|
||||||
|
writer.BeginVSMain(inputs, Slice<UniformDef>::empty(), varyings);
|
||||||
|
|
||||||
|
writer.C(" v_texcoord = a_texcoord;\n"); // yes, this should be right. Should be 2.0 in the far corners.
|
||||||
|
writer.C(" gl_Position = a_position;\n");
|
||||||
|
writer.F(" gl_Position.y *= %s1.0;\n", lang.viewportYSign);
|
||||||
|
|
||||||
|
writer.EndVSMain(varyings);
|
||||||
|
}
|
||||||
|
|
||||||
|
// verts have positions in clip coordinates.
|
||||||
|
void FramebufferManagerCommon::Draw2D(Draw::Texture *tex, Draw2DVertex *verts, int vertexCount, float viewportWidth, float viewportHeight) {
|
||||||
|
using namespace Draw;
|
||||||
|
|
||||||
|
if (!draw2DPipelineLinear_) {
|
||||||
|
const ShaderLanguageDesc &shaderLanguageDesc = draw_->GetShaderLanguageDesc();
|
||||||
|
|
||||||
|
char *fsCode = new char[4000];
|
||||||
|
char *vsCode = new char[4000];
|
||||||
|
GenerateDraw2DFs(fsCode, shaderLanguageDesc, draw_->GetBugs());
|
||||||
|
GenerateDraw2DVS(vsCode, shaderLanguageDesc);
|
||||||
|
|
||||||
|
draw2DFs_ = draw_->CreateShaderModule(ShaderStage::Fragment, shaderLanguageDesc.shaderLanguage, (const uint8_t *)fsCode, strlen(fsCode), "draw2d_fs");
|
||||||
|
draw2DVs_ = draw_->CreateShaderModule(ShaderStage::Vertex, shaderLanguageDesc.shaderLanguage, (const uint8_t *)vsCode, strlen(vsCode), "draw2d_vs");
|
||||||
|
|
||||||
|
_assert_(stencilUploadFs_ && stencilUploadVs_);
|
||||||
|
|
||||||
|
InputLayoutDesc desc = {
|
||||||
|
{
|
||||||
|
{ 16, false },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{ 0, SEM_POSITION, DataFormat::R32G32_FLOAT, 0 },
|
||||||
|
{ 16, SEM_TEXCOORD0, DataFormat::R32G32_FLOAT, 8 },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
InputLayout *inputLayout = draw_->CreateInputLayout(desc);
|
||||||
|
|
||||||
|
BlendState *blendOff = draw_->CreateBlendState({ false, 0xF });
|
||||||
|
DepthStencilStateDesc dsDesc{};
|
||||||
|
DepthStencilState *noDepthStencil = draw_->CreateDepthStencilState(dsDesc);
|
||||||
|
RasterState *rasterNoCull = draw_->CreateRasterState({});
|
||||||
|
|
||||||
|
PipelineDesc stencilWriteDesc{
|
||||||
|
Primitive::TRIANGLE_STRIP,
|
||||||
|
{ draw2DVs_, draw2DFs_ },
|
||||||
|
inputLayout, noDepthStencil, blendOff, rasterNoCull, nullptr,
|
||||||
|
};
|
||||||
|
draw2DPipelineLinear_ = draw_->CreateGraphicsPipeline(stencilWriteDesc);
|
||||||
|
_assert_(draw2DPipelineLinear_);
|
||||||
|
|
||||||
|
delete[] fsCode;
|
||||||
|
delete[] vsCode;
|
||||||
|
|
||||||
|
rasterNoCull->Release();
|
||||||
|
blendOff->Release();
|
||||||
|
noDepthStencil->Release();
|
||||||
|
inputLayout->Release();
|
||||||
|
|
||||||
|
SamplerStateDesc descLinear{};
|
||||||
|
descLinear.magFilter = TextureFilter::LINEAR;
|
||||||
|
descLinear.minFilter = TextureFilter::LINEAR;
|
||||||
|
descLinear.mipFilter = TextureFilter::LINEAR;
|
||||||
|
descLinear.wrapU = TextureAddressMode::CLAMP_TO_EDGE;
|
||||||
|
descLinear.wrapV = TextureAddressMode::CLAMP_TO_EDGE;
|
||||||
|
draw2DSamplerLinear_= draw_->CreateSamplerState(descLinear);
|
||||||
|
}
|
||||||
|
|
||||||
|
draw_->BindPipeline(draw2DPipelineLinear_);
|
||||||
|
draw_->BindTextures(TEX_SLOT_PSP_TEXTURE, 1, &tex);
|
||||||
|
draw_->BindSamplerStates(TEX_SLOT_PSP_TEXTURE, 1, &draw2DSamplerLinear_);
|
||||||
|
draw_->DrawUP(verts, vertexCount);
|
||||||
|
|
||||||
|
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_RASTER_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_TEXTURE_IMAGE | DIRTY_TEXTURE_PARAMS | DIRTY_VERTEXSHADER_STATE | DIRTY_FRAGMENTSHADER_STATE);
|
||||||
|
}
|
9
GPU/Common/Draw2D.h
Normal file
9
GPU/Common/Draw2D.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// For framebuffer copies and similar things that just require passthrough.
|
||||||
|
struct Draw2DVertex {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float u;
|
||||||
|
float v;
|
||||||
|
};
|
@ -2492,6 +2492,10 @@ void FramebufferManagerCommon::DeviceLost() {
|
|||||||
DoRelease(stencilUploadVs_);
|
DoRelease(stencilUploadVs_);
|
||||||
DoRelease(stencilUploadSampler_);
|
DoRelease(stencilUploadSampler_);
|
||||||
DoRelease(stencilUploadPipeline_);
|
DoRelease(stencilUploadPipeline_);
|
||||||
|
DoRelease(draw2DPipelineLinear_);
|
||||||
|
DoRelease(draw2DSamplerLinear_);
|
||||||
|
DoRelease(draw2DVs_);
|
||||||
|
DoRelease(draw2DFs_);
|
||||||
presentation_->DeviceLost();
|
presentation_->DeviceLost();
|
||||||
draw_ = nullptr;
|
draw_ = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -29,11 +29,11 @@
|
|||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/Log.h"
|
#include "Common/Log.h"
|
||||||
#include "Core/MemMap.h"
|
#include "Common/GPU/thin3d.h"
|
||||||
#include "GPU/GPU.h"
|
#include "GPU/GPU.h"
|
||||||
#include "GPU/ge_constants.h"
|
#include "GPU/ge_constants.h"
|
||||||
#include "GPU/GPUInterface.h"
|
#include "GPU/GPUInterface.h"
|
||||||
#include "Common/GPU/thin3d.h"
|
#include "GPU/Common/Draw2D.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
FB_USAGE_DISPLAYED_FRAMEBUFFER = 1,
|
FB_USAGE_DISPLAYED_FRAMEBUFFER = 1,
|
||||||
@ -357,6 +357,8 @@ protected:
|
|||||||
virtual 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) = 0;
|
virtual 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) = 0;
|
||||||
virtual void Bind2DShader() = 0;
|
virtual void Bind2DShader() = 0;
|
||||||
|
|
||||||
|
void Draw2D(Draw::Texture *tex, Draw2DVertex *verts, int vertexCount, float viewportWidth, float viewportHeight);
|
||||||
|
|
||||||
bool UpdateSize();
|
bool UpdateSize();
|
||||||
|
|
||||||
void FlushBeforeCopy();
|
void FlushBeforeCopy();
|
||||||
@ -473,4 +475,10 @@ protected:
|
|||||||
Draw::ShaderModule *stencilUploadVs_ = nullptr;
|
Draw::ShaderModule *stencilUploadVs_ = nullptr;
|
||||||
Draw::ShaderModule *stencilUploadFs_ = nullptr;
|
Draw::ShaderModule *stencilUploadFs_ = nullptr;
|
||||||
Draw::SamplerState *stencilUploadSampler_ = nullptr;
|
Draw::SamplerState *stencilUploadSampler_ = nullptr;
|
||||||
|
|
||||||
|
// Draw2D pipelines
|
||||||
|
Draw::Pipeline *draw2DPipelineLinear_ = nullptr;
|
||||||
|
Draw::SamplerState *draw2DSamplerLinear_ = nullptr;
|
||||||
|
Draw::ShaderModule *draw2DVs_ = nullptr;
|
||||||
|
Draw::ShaderModule *draw2DFs_ = nullptr;
|
||||||
};
|
};
|
||||||
|
@ -338,6 +338,7 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\ext\xbrz\xbrz.h" />
|
<ClInclude Include="..\ext\xbrz\xbrz.h" />
|
||||||
|
<ClInclude Include="Common\Draw2D.h" />
|
||||||
<ClInclude Include="Common\ReinterpretFramebuffer.h" />
|
<ClInclude Include="Common\ReinterpretFramebuffer.h" />
|
||||||
<ClInclude Include="Common\DepalettizeShaderCommon.h" />
|
<ClInclude Include="Common\DepalettizeShaderCommon.h" />
|
||||||
<ClInclude Include="Common\DrawEngineCommon.h" />
|
<ClInclude Include="Common\DrawEngineCommon.h" />
|
||||||
@ -459,6 +460,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\ext\xbrz\xbrz.cpp" />
|
<ClCompile Include="..\ext\xbrz\xbrz.cpp" />
|
||||||
|
<ClCompile Include="Common\Draw2D.cpp" />
|
||||||
<ClCompile Include="Common\ReinterpretFramebuffer.cpp" />
|
<ClCompile Include="Common\ReinterpretFramebuffer.cpp" />
|
||||||
<ClCompile Include="Common\DepalettizeShaderCommon.cpp" />
|
<ClCompile Include="Common\DepalettizeShaderCommon.cpp" />
|
||||||
<ClCompile Include="Common\DrawEngineCommon.cpp" />
|
<ClCompile Include="Common\DrawEngineCommon.cpp" />
|
||||||
@ -666,4 +668,4 @@
|
|||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
</Project>
|
</Project>
|
@ -264,6 +264,9 @@
|
|||||||
<ClInclude Include="Software\BinManager.h">
|
<ClInclude Include="Software\BinManager.h">
|
||||||
<Filter>Software</Filter>
|
<Filter>Software</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Common\Draw2D.h">
|
||||||
|
<Filter>Common</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Math3D.cpp">
|
<ClCompile Include="Math3D.cpp">
|
||||||
@ -518,6 +521,9 @@
|
|||||||
<ClCompile Include="Software\BinManager.cpp">
|
<ClCompile Include="Software\BinManager.cpp">
|
||||||
<Filter>Software</Filter>
|
<Filter>Software</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="Common\Draw2D.cpp">
|
||||||
|
<Filter>Common</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<FxCompile Include="..\assets\shaders\tex_4xbrz.csh">
|
<FxCompile Include="..\assets\shaders\tex_4xbrz.csh">
|
||||||
@ -535,4 +541,4 @@
|
|||||||
<Filter>Shaders</Filter>
|
<Filter>Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -319,6 +319,7 @@ EXEC_AND_LIB_FILES := \
|
|||||||
$(SRC)/GPU/GPUState.cpp \
|
$(SRC)/GPU/GPUState.cpp \
|
||||||
$(SRC)/GPU/GeConstants.cpp \
|
$(SRC)/GPU/GeConstants.cpp \
|
||||||
$(SRC)/GPU/GeDisasm.cpp \
|
$(SRC)/GPU/GeDisasm.cpp \
|
||||||
|
$(SRC)/GPU/Common/Draw2D.cpp \
|
||||||
$(SRC)/GPU/Common/DepalettizeShaderCommon.cpp \
|
$(SRC)/GPU/Common/DepalettizeShaderCommon.cpp \
|
||||||
$(SRC)/GPU/Common/FragmentShaderGenerator.cpp \
|
$(SRC)/GPU/Common/FragmentShaderGenerator.cpp \
|
||||||
$(SRC)/GPU/Common/FramebufferManagerCommon.cpp \
|
$(SRC)/GPU/Common/FramebufferManagerCommon.cpp \
|
||||||
|
@ -315,6 +315,7 @@ SOURCES_C +=\
|
|||||||
$(COMMONDIR)/GPU/OpenGL/gl3stub.c
|
$(COMMONDIR)/GPU/OpenGL/gl3stub.c
|
||||||
|
|
||||||
SOURCES_CXX += \
|
SOURCES_CXX += \
|
||||||
|
$(GPUCOMMONDIR)/Draw2D.cpp \
|
||||||
$(GPUCOMMONDIR)/VertexDecoderCommon.cpp \
|
$(GPUCOMMONDIR)/VertexDecoderCommon.cpp \
|
||||||
$(GPUCOMMONDIR)/GPUStateUtils.cpp \
|
$(GPUCOMMONDIR)/GPUStateUtils.cpp \
|
||||||
$(GPUCOMMONDIR)/DrawEngineCommon.cpp \
|
$(GPUCOMMONDIR)/DrawEngineCommon.cpp \
|
||||||
|
Loading…
Reference in New Issue
Block a user