Merge pull request #6191 from lioncash/file-static

D3DUtil: Make file-scope variables internally linked where applicable
This commit is contained in:
Leo Lam 2017-11-19 18:36:32 +01:00 committed by GitHub
commit 01794126ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 48 deletions

View file

@ -97,8 +97,33 @@ private:
std::list<bool*> observers; std::list<bool*> observers;
}; };
CD3DFont font; class CD3DFont
UtilVertexBuffer* util_vbuf = nullptr; {
public:
CD3DFont();
// 2D text drawing function
// Initializing and destroying device-dependent objects
int Init();
int Shutdown();
int DrawTextScaled(float x, float y, float size, float spacing, u32 dwColor,
const std::string& text);
private:
ID3D11ShaderResourceView* m_pTexture;
ID3D11Buffer* m_pVB;
ID3D11InputLayout* m_InputLayout;
ID3D11PixelShader* m_pshader;
ID3D11VertexShader* m_vshader;
ID3D11BlendState* m_blendstate;
ID3D11RasterizerState* m_raststate;
const int m_dwTexWidth;
const int m_dwTexHeight;
unsigned int m_LineHeight;
float m_fTexCoords[128 - 32][4];
};
static CD3DFont font;
static UtilVertexBuffer* util_vbuf = nullptr;
#define MAX_NUM_VERTICES 50 * 6 #define MAX_NUM_VERTICES 50 * 6
struct FONT2DVERTEX struct FONT2DVERTEX
@ -458,8 +483,8 @@ int CD3DFont::DrawTextScaled(float x, float y, float size, float spacing, u32 dw
return S_OK; return S_OK;
} }
ID3D11SamplerState* linear_copy_sampler = nullptr; static ID3D11SamplerState* linear_copy_sampler = nullptr;
ID3D11SamplerState* point_copy_sampler = nullptr; static ID3D11SamplerState* point_copy_sampler = nullptr;
struct STQVertex struct STQVertex
{ {
@ -480,28 +505,31 @@ struct ColVertex
u32 col; u32 col;
}; };
struct struct TexQuadData
{ {
float u1, v1, u2, v2, S, G; float u1, v1, u2, v2, S, G;
} tex_quad_data; };
static TexQuadData tex_quad_data;
struct struct DrawQuadData
{ {
float x1, y1, x2, y2, z; float x1, y1, x2, y2, z;
u32 col; u32 col;
} draw_quad_data; };
static DrawQuadData draw_quad_data;
struct struct ClearQuadData
{ {
u32 col; u32 col;
float z; float z;
} clear_quad_data; };
static ClearQuadData clear_quad_data;
// ring buffer offsets // ring buffer offsets
int stq_offset, cq_offset, clearq_offset; static int stq_offset, cq_offset, clearq_offset;
// observer variables for ring buffer wraps // observer variables for ring buffer wraps
bool stq_observer, cq_observer, clearq_observer; static bool stq_observer, cq_observer, clearq_observer;
void InitUtils() void InitUtils()
{ {
@ -764,6 +792,10 @@ void DrawEFBPokeQuads(EFBAccessType type, const EfbPokeData* points, size_t num_
stateman->SetGeometryShader(GeometryShaderCache::GetClearGeometryShader()); stateman->SetGeometryShader(GeometryShaderCache::GetClearGeometryShader());
} }
void DrawTextScaled(float x, float y, float size, float spacing, u32 color, const std::string& text)
{
font.DrawTextScaled(x, y, size, spacing, color, text);
}
} // namespace D3D } // namespace D3D
} // namespace DX11 } // namespace DX11

View file

@ -14,39 +14,6 @@ namespace DX11
{ {
namespace D3D namespace D3D
{ {
// Font creation flags
#define D3DFONT_BOLD 0x0001
#define D3DFONT_ITALIC 0x0002
// Font rendering flags
#define D3DFONT_CENTERED 0x0001
class CD3DFont
{
ID3D11ShaderResourceView* m_pTexture;
ID3D11Buffer* m_pVB;
ID3D11InputLayout* m_InputLayout;
ID3D11PixelShader* m_pshader;
ID3D11VertexShader* m_vshader;
ID3D11BlendState* m_blendstate;
ID3D11RasterizerState* m_raststate;
const int m_dwTexWidth;
const int m_dwTexHeight;
unsigned int m_LineHeight;
float m_fTexCoords[128 - 32][4];
public:
CD3DFont();
// 2D text drawing function
// Initializing and destroying device-dependent objects
int Init();
int Shutdown();
int DrawTextScaled(float x, float y, float size, float spacing, u32 dwColor,
const std::string& text);
};
extern CD3DFont font;
void InitUtils(); void InitUtils();
void ShutdownUtils(); void ShutdownUtils();
@ -61,5 +28,7 @@ void drawClearQuad(u32 Color, float z);
void drawColorQuad(u32 Color, float z, float x1, float y1, float x2, float y2); void drawColorQuad(u32 Color, float z, float x1, float y1, float x2, float y2);
void DrawEFBPokeQuads(EFBAccessType type, const EfbPokeData* points, size_t num_points); void DrawEFBPokeQuads(EFBAccessType type, const EfbPokeData* points, size_t num_points);
void DrawTextScaled(float x, float y, float size, float spacing, u32 color,
const std::string& text);
} }
} }

View file

@ -243,9 +243,9 @@ Renderer::~Renderer()
void Renderer::RenderText(const std::string& text, int left, int top, u32 color) void Renderer::RenderText(const std::string& text, int left, int top, u32 color)
{ {
D3D::font.DrawTextScaled((float)(left + 1), (float)(top + 1), 20.f, 0.0f, color & 0xFF000000, D3D::DrawTextScaled(static_cast<float>(left + 1), static_cast<float>(top + 1), 20.f, 0.0f,
text); color & 0xFF000000, text);
D3D::font.DrawTextScaled((float)left, (float)top, 20.f, 0.0f, color, text); D3D::DrawTextScaled(static_cast<float>(left), static_cast<float>(top), 20.f, 0.0f, color, text);
} }
TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc) TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)