Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/Common/Draw2D.h
3186 views
1
#pragma once
2
3
#include "Data/Collections/Slice.h"
4
#include "GPU/GPU.h"
5
#include "Common/GPU/Shader.h"
6
#include "GPU/thin3d.h"
7
8
// For framebuffer copies and similar things that just require passthrough.
9
struct Draw2DVertex {
10
float x;
11
float y;
12
float u;
13
float v;
14
};
15
16
enum Draw2DShader {
17
DRAW2D_COPY_COLOR,
18
DRAW2D_COPY_DEPTH,
19
DRAW2D_ENCODE_R16_TO_DEPTH,
20
DRAW2D_565_TO_DEPTH,
21
DRAW2D_565_TO_DEPTH_DESWIZZLE,
22
DRAW2D_COPY_COLOR_RECT2LIN,
23
};
24
25
inline RasterChannel Draw2DSourceChannel(Draw2DShader shader) {
26
switch (shader) {
27
case DRAW2D_COPY_DEPTH:
28
return RASTER_DEPTH;
29
case DRAW2D_COPY_COLOR:
30
case DRAW2D_ENCODE_R16_TO_DEPTH:
31
case DRAW2D_565_TO_DEPTH:
32
case DRAW2D_565_TO_DEPTH_DESWIZZLE:
33
default:
34
return RASTER_COLOR;
35
}
36
}
37
38
struct Draw2DPipelineInfo {
39
const char *tag;
40
RasterChannel readChannel;
41
RasterChannel writeChannel;
42
Slice<SamplerDef> samplers;
43
};
44
45
extern const UniformDef g_draw2Duniforms[5];
46
47
struct Draw2DPipeline {
48
Draw::Pipeline *pipeline;
49
Draw2DPipelineInfo info;
50
char *code;
51
void Release() {
52
pipeline->Release();
53
delete[] code;
54
delete this;
55
}
56
};
57
58
class ShaderWriter;
59
60
class Draw2D {
61
public:
62
Draw2D(Draw::DrawContext *draw) : draw_(draw) {}
63
void DeviceLost();
64
void DeviceRestore(Draw::DrawContext *draw);
65
66
Draw2DPipeline *Create2DPipeline(std::function<Draw2DPipelineInfo(ShaderWriter &)> generate);
67
68
void DrawStrip2D(Draw::Texture *tex, const Draw2DVertex *verts, int vertexCount, bool linearFilter, Draw2DPipeline *pipeline, float texW = 0.0f, float texH = 0.0f, int scaleFactor = 0);
69
70
void Blit(Draw2DPipeline *pipeline, float srcX1, float srcY1, float srcX2, float srcY2, float dstX1, float dstY1, float dstX2, float dstY2, float srcWidth, float srcHeight, float dstWidth, float dstHeight, bool linear, int scaleFactor);
71
void Ensure2DResources();
72
73
private:
74
Draw::DrawContext *draw_;
75
76
Draw::SamplerState *draw2DSamplerLinear_ = nullptr;
77
Draw::SamplerState *draw2DSamplerNearest_ = nullptr;
78
Draw::ShaderModule *draw2DVs_ = nullptr;
79
};
80
81