mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-27 13:54:16 +01:00
[hud] Don't use vertex shader for scaling
Instead, do it on the CPU.
This commit is contained in:
parent
aa40decc23
commit
9c6ff95bb6
@ -47,6 +47,9 @@ namespace dxvk::hud {
|
|||||||
const std::string& text) {
|
const std::string& text) {
|
||||||
beginTextRendering();
|
beginTextRendering();
|
||||||
|
|
||||||
|
const float xscale = 1.0f / std::max(float(m_surfaceSize.width), 1.0f);
|
||||||
|
const float yscale = 1.0f / std::max(float(m_surfaceSize.height), 1.0f);
|
||||||
|
|
||||||
uint32_t vertexCount = 6 * text.size();
|
uint32_t vertexCount = 6 * text.size();
|
||||||
|
|
||||||
auto vertexSlice = allocVertexBuffer(vertexCount * sizeof(HudTextVertex));
|
auto vertexSlice = allocVertexBuffer(vertexCount * sizeof(HudTextVertex));
|
||||||
@ -57,30 +60,25 @@ namespace dxvk::hud {
|
|||||||
auto vertexData = reinterpret_cast<HudTextVertex*>(
|
auto vertexData = reinterpret_cast<HudTextVertex*>(
|
||||||
vertexSlice.getSliceHandle().mapPtr);
|
vertexSlice.getSliceHandle().mapPtr);
|
||||||
|
|
||||||
const float sizeFactor = size / static_cast<float>(g_hudFont.size);
|
const float sizeFactor = size / float(g_hudFont.size);
|
||||||
|
|
||||||
for (size_t i = 0; i < text.size(); i++) {
|
for (size_t i = 0; i < text.size(); i++) {
|
||||||
const HudGlyph& glyph = g_hudFont.glyphs[
|
const HudGlyph& glyph = g_hudFont.glyphs[
|
||||||
m_charMap[static_cast<uint8_t>(text[i])]];
|
m_charMap[uint8_t(text[i])]];
|
||||||
|
|
||||||
const HudPos size = {
|
HudPos size = {
|
||||||
sizeFactor * static_cast<float>(glyph.w),
|
sizeFactor * float(glyph.w),
|
||||||
sizeFactor * static_cast<float>(glyph.h) };
|
sizeFactor * float(glyph.h) };
|
||||||
|
|
||||||
const HudPos origin = {
|
HudPos origin = {
|
||||||
pos.x - sizeFactor * static_cast<float>(glyph.originX),
|
pos.x - sizeFactor * float(glyph.originX),
|
||||||
pos.y - sizeFactor * static_cast<float>(glyph.originY) };
|
pos.y - sizeFactor * float(glyph.originY) };
|
||||||
|
|
||||||
const HudPos posTl = { origin.x, origin.y };
|
HudPos posTl = { xscale * (origin.x), yscale * (origin.y) };
|
||||||
const HudPos posBr = { origin.x + size.x, origin.y + size.y };
|
HudPos posBr = { xscale * (origin.x + size.x), yscale * (origin.y + size.y) };
|
||||||
|
|
||||||
const HudTexCoord texTl = {
|
HudTexCoord texTl = { uint32_t(glyph.x), uint32_t(glyph.y) };
|
||||||
static_cast<uint32_t>(glyph.x),
|
HudTexCoord texBr = { uint32_t(glyph.x + glyph.w), uint32_t(glyph.y + glyph.h) };
|
||||||
static_cast<uint32_t>(glyph.y), };
|
|
||||||
|
|
||||||
const HudTexCoord texBr = {
|
|
||||||
static_cast<uint32_t>(glyph.x + glyph.w),
|
|
||||||
static_cast<uint32_t>(glyph.y + glyph.h) };
|
|
||||||
|
|
||||||
vertexData[6 * i + 0].position = { posTl.x, posTl.y };
|
vertexData[6 * i + 0].position = { posTl.x, posTl.y };
|
||||||
vertexData[6 * i + 0].texcoord = { texTl.u, texTl.v };
|
vertexData[6 * i + 0].texcoord = { texTl.u, texTl.v };
|
||||||
@ -110,6 +108,9 @@ namespace dxvk::hud {
|
|||||||
const HudLineVertex* vertexData) {
|
const HudLineVertex* vertexData) {
|
||||||
beginLineRendering();
|
beginLineRendering();
|
||||||
|
|
||||||
|
const float xscale = 1.0f / std::max(float(m_surfaceSize.width), 1.0f);
|
||||||
|
const float yscale = 1.0f / std::max(float(m_surfaceSize.height), 1.0f);
|
||||||
|
|
||||||
auto vertexSlice = allocVertexBuffer(vertexCount * sizeof(HudLineVertex));
|
auto vertexSlice = allocVertexBuffer(vertexCount * sizeof(HudLineVertex));
|
||||||
m_context->bindVertexBuffer(0, vertexSlice, sizeof(HudLineVertex));
|
m_context->bindVertexBuffer(0, vertexSlice, sizeof(HudLineVertex));
|
||||||
m_context->draw(vertexCount, 1, 0, 0);
|
m_context->draw(vertexCount, 1, 0, 0);
|
||||||
@ -117,8 +118,12 @@ namespace dxvk::hud {
|
|||||||
auto dstVertexData = reinterpret_cast<HudLineVertex*>(
|
auto dstVertexData = reinterpret_cast<HudLineVertex*>(
|
||||||
vertexSlice.getSliceHandle().mapPtr);
|
vertexSlice.getSliceHandle().mapPtr);
|
||||||
|
|
||||||
for (size_t i = 0; i < vertexCount; i++)
|
for (size_t i = 0; i < vertexCount; i++) {
|
||||||
dstVertexData[i] = vertexData[i];
|
dstVertexData[i].position = {
|
||||||
|
xscale * vertexData[i].position.x,
|
||||||
|
yscale * vertexData[i].position.y };
|
||||||
|
dstVertexData[i].color = vertexData[i].color;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
#version 450
|
#version 450
|
||||||
|
|
||||||
layout(set = 0, binding = 0, std140)
|
|
||||||
uniform u_hud {
|
|
||||||
uvec2 size;
|
|
||||||
} g_hud;
|
|
||||||
|
|
||||||
layout(location = 0) in vec2 v_position;
|
layout(location = 0) in vec2 v_position;
|
||||||
layout(location = 1) in vec4 v_color;
|
layout(location = 1) in vec4 v_color;
|
||||||
|
|
||||||
@ -13,6 +8,6 @@ layout(location = 0) out vec4 o_color;
|
|||||||
void main() {
|
void main() {
|
||||||
o_color = v_color;
|
o_color = v_color;
|
||||||
|
|
||||||
vec2 pos = 2.0f * (v_position / vec2(g_hud.size)) - 1.0f;
|
vec2 pos = 2.0f * v_position - 1.0f;
|
||||||
gl_Position = vec4(pos, 0.0f, 1.0f);
|
gl_Position = vec4(pos, 0.0f, 1.0f);
|
||||||
}
|
}
|
@ -1,10 +1,5 @@
|
|||||||
#version 450
|
#version 450
|
||||||
|
|
||||||
layout(set = 0, binding = 0, std140)
|
|
||||||
uniform u_hud {
|
|
||||||
uvec2 size;
|
|
||||||
} g_hud;
|
|
||||||
|
|
||||||
layout(location = 0) in vec2 v_position;
|
layout(location = 0) in vec2 v_position;
|
||||||
layout(location = 1) in uvec2 v_texcoord;
|
layout(location = 1) in uvec2 v_texcoord;
|
||||||
|
|
||||||
@ -13,6 +8,6 @@ layout(location = 0) out vec2 o_texcoord;
|
|||||||
void main() {
|
void main() {
|
||||||
o_texcoord = vec2(v_texcoord);
|
o_texcoord = vec2(v_texcoord);
|
||||||
|
|
||||||
vec2 pos = 2.0f * (v_position / vec2(g_hud.size)) - 1.0f;
|
vec2 pos = 2.0f * v_position - 1.0f;
|
||||||
gl_Position = vec4(pos, 0.0f, 1.0f);
|
gl_Position = vec4(pos, 0.0f, 1.0f);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user