aboutsummaryrefslogtreecommitdiff
path: root/xbmc/guilib
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/guilib')
-rw-r--r--xbmc/guilib/GUIFontTTF.cpp42
-rw-r--r--xbmc/guilib/GUIFontTTFGLES.cpp102
-rw-r--r--xbmc/guilib/GUIFontTTFGLES.h1
3 files changed, 74 insertions, 71 deletions
diff --git a/xbmc/guilib/GUIFontTTF.cpp b/xbmc/guilib/GUIFontTTF.cpp
index d19c1f0a3f..ff11db14f8 100644
--- a/xbmc/guilib/GUIFontTTF.cpp
+++ b/xbmc/guilib/GUIFontTTF.cpp
@@ -382,7 +382,7 @@ void CGUIFontTTF::DrawTextInternal(CGraphicContext& context,
uint32_t rawAlignment = alignment;
bool dirtyCache(false);
-#if defined(HAS_GL)
+#if not defined(HAS_DX)
// round coordinates to the pixel grid. otherwise, we might sample at the wrong positions.
if (!scrolling)
x = std::round(x);
@@ -392,7 +392,7 @@ void CGUIFontTTF::DrawTextInternal(CGraphicContext& context,
y += dy;
#endif
-#if defined(HAS_GL)
+#if not defined(HAS_DX)
// GL can scissor and shader clip
const bool hardwareClipping = true;
#else
@@ -404,7 +404,7 @@ void CGUIFontTTF::DrawTextInternal(CGraphicContext& context,
CGUIFontCacheStaticPosition staticPos(x, y);
CGUIFontCacheDynamicPosition dynamicPos;
-#if defined(HAS_GL)
+#if not defined(HAS_DX)
// dummy positions for the time being
dynamicPos = CGUIFontCacheDynamicPosition(0.0f, 0.0f, 0.0f);
#else
@@ -452,7 +452,7 @@ void CGUIFontTTF::DrawTextInternal(CGraphicContext& context,
const std::vector<Glyph> glyphs = GetHarfBuzzShapedGlyphs(text);
// save the origin, which is scaled separately
-#if defined(HAS_GL)
+#if not defined(HAS_DX)
// the origin is now at [0,0], and not at "random" locations anymore. positioning is done in the vertex shader.
m_originX = 0;
m_originY = 0;
@@ -710,7 +710,7 @@ void CGUIFontTTF::DrawTextInternal(CGraphicContext& context,
scrolling, std::chrono::steady_clock::now(), dirtyCache);
CVertexBuffer newVertexBuffer = CreateVertexBuffer(*tempVertices);
vertexBuffer = newVertexBuffer;
-#if defined(HAS_GL)
+#if not defined(HAS_DX)
m_vertexTrans.emplace_back(x, y, 0.0f, &vertexBuffer, context.GetClipRegion(), dx, dy);
#else
m_vertexTrans.emplace_back(.0f, .0f, .0f, &vertexBuffer, context.GetClipRegion());
@@ -728,7 +728,7 @@ void CGUIFontTTF::DrawTextInternal(CGraphicContext& context,
else
{
if (hardwareClipping)
-#if defined(HAS_GL)
+#if not defined(HAS_DX)
m_vertexTrans.emplace_back(x, y, 0.0f, &vertexBuffer, context.GetClipRegion(), dx, dy);
#else
m_vertexTrans.emplace_back(dynamicPos.m_x, dynamicPos.m_y, dynamicPos.m_z, &vertexBuffer,
@@ -1139,7 +1139,7 @@ void CGUIFontTTF::RenderCharacter(CGraphicContext& context,
// posX and posY are relative to our origin, and the textcell is offset
// from our (posX, posY). Plus, these are unscaled quantities compared to the underlying GUI resolution
-#if defined(HAS_GL)
+#if not defined(HAS_DX)
CRect vertex((posX + ch->m_offsetX), (posY + ch->m_offsetY), (posX + ch->m_offsetX + width),
(posY + ch->m_offsetY + height));
#else
@@ -1151,7 +1151,7 @@ void CGUIFontTTF::RenderCharacter(CGraphicContext& context,
#endif
CRect texture(ch->m_left, ch->m_top, ch->m_right, ch->m_bottom);
-#if !defined(HAS_GL)
+#if defined(HAS_DX)
if (!m_renderSystem->ScissorsCanEffectClipping())
context.ClipRect(vertex, texture);
@@ -1262,7 +1262,7 @@ void CGUIFontTTF::RenderCharacter(CGraphicContext& context,
v[3].u = tl;
v[3].v = tb;
-#elif defined(HAS_GL)
+#else
// GL / GLES uses triangle strips, not quads, so have to rearrange the vertex order
// GL uses vertex shaders to manipulate text rotation/translation/scaling/clipping.
@@ -1296,30 +1296,6 @@ void CGUIFontTTF::RenderCharacter(CGraphicContext& context,
v[3].x = vertex.x2 - xOffset + 0.5f;
v[3].y = vertex.y2 - yOffset + 0.5f;
v[3].z = 0;
-#else
- v[0].u = tl;
- v[0].v = tt;
- v[0].x = x[0];
- v[0].y = y[0];
- v[0].z = z[0];
-
- v[1].u = tl;
- v[1].v = tb;
- v[1].x = x[3];
- v[1].y = y[3];
- v[1].z = z[3];
-
- v[2].u = tr;
- v[2].v = tt;
- v[2].x = x[1];
- v[2].y = y[1];
- v[2].z = z[1];
-
- v[3].u = tr;
- v[3].v = tb;
- v[3].x = x[2];
- v[3].y = y[2];
- v[3].z = z[2];
#endif
}
diff --git a/xbmc/guilib/GUIFontTTFGLES.cpp b/xbmc/guilib/GUIFontTTFGLES.cpp
index c00a601319..67cceae441 100644
--- a/xbmc/guilib/GUIFontTTFGLES.cpp
+++ b/xbmc/guilib/GUIFontTTFGLES.cpp
@@ -62,6 +62,17 @@ bool CGUIFontTTFGLES::FirstBegin()
GLenum pixformat = GL_ALPHA; // deprecated
GLenum internalFormat = GL_ALPHA;
+ if (renderSystem->ScissorsCanEffectClipping())
+ {
+ m_scissorClip = true;
+ }
+ else
+ {
+ m_scissorClip = false;
+ renderSystem->ResetScissors();
+ renderSystem->EnableGUIShader(ShaderMethodGLES::SM_FONTS_SHADER_CLIP);
+ }
+
if (m_textureStatus == TEXTURE_REALLOCATED)
{
if (glIsTexture(m_nTexture))
@@ -124,6 +135,9 @@ bool CGUIFontTTFGLES::FirstBegin()
void CGUIFontTTFGLES::LastEnd()
{
+ // static vertex arrays are not supported anymore
+ assert(m_vertex.empty());
+
CWinSystemBase* const winSystem = CServiceBroker::GetWinSystem();
if (!winSystem)
return;
@@ -134,7 +148,9 @@ void CGUIFontTTFGLES::LastEnd()
GLint posLoc = renderSystem->GUIShaderGetPos();
GLint colLoc = renderSystem->GUIShaderGetCol();
GLint tex0Loc = renderSystem->GUIShaderGetCoord0();
- GLint modelLoc = renderSystem->GUIShaderGetModel();
+ GLint clipUniformLoc = renderSystem->GUIShaderGetClip();
+ GLint coordStepUniformLoc = renderSystem->GUIShaderGetCoordStep();
+ GLint matrixUniformLoc = renderSystem->GUIShaderGetMatrix();
CreateStaticVertexBuffers();
@@ -143,35 +159,6 @@ void CGUIFontTTFGLES::LastEnd()
glEnableVertexAttribArray(colLoc);
glEnableVertexAttribArray(tex0Loc);
- if (!m_vertex.empty())
- {
- // Deal with vertices that had to use software clipping
- std::vector<SVertex> vecVertices(6 * (m_vertex.size() / 4));
- SVertex* vertices = &vecVertices[0];
-
- for (size_t i = 0; i < m_vertex.size(); i += 4)
- {
- *vertices++ = m_vertex[i];
- *vertices++ = m_vertex[i + 1];
- *vertices++ = m_vertex[i + 2];
-
- *vertices++ = m_vertex[i + 1];
- *vertices++ = m_vertex[i + 3];
- *vertices++ = m_vertex[i + 2];
- }
-
- vertices = &vecVertices[0];
-
- glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, sizeof(SVertex),
- reinterpret_cast<char*>(vertices) + offsetof(SVertex, x));
- glVertexAttribPointer(colLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(SVertex),
- reinterpret_cast<char*>(vertices) + offsetof(SVertex, r));
- glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, GL_FALSE, sizeof(SVertex),
- reinterpret_cast<char*>(vertices) + offsetof(SVertex, u));
-
- glDrawArrays(GL_TRIANGLES, 0, vecVertices.size());
- }
-
if (!m_vertexTrans.empty())
{
// Deal with the vertices that can be hardware clipped and therefore translated
@@ -198,14 +185,54 @@ void CGUIFontTTFGLES::LastEnd()
// skip empty clip
if (clip.IsEmpty())
continue;
+ }
+ if (m_scissorClip)
+ {
+ // clip using scissors
renderSystem->SetScissors(clip);
}
+ else
+ {
+ // clip using vertex shader
+ renderSystem->ResetScissors();
+
+ float x1 =
+ m_vertexTrans[i].m_clip.x1 - m_vertexTrans[i].m_translateX - m_vertexTrans[i].m_offsetX;
+ float y1 =
+ m_vertexTrans[i].m_clip.y1 - m_vertexTrans[i].m_translateY - m_vertexTrans[i].m_offsetY;
+ float x2 =
+ m_vertexTrans[i].m_clip.x2 - m_vertexTrans[i].m_translateX - m_vertexTrans[i].m_offsetX;
+ float y2 =
+ m_vertexTrans[i].m_clip.y2 - m_vertexTrans[i].m_translateY - m_vertexTrans[i].m_offsetY;
+
+ glUniform4f(clipUniformLoc, x1, y1, x2, y2);
+
+ // setup texture step
+ float stepX = context.GetGUIScaleX() / (static_cast<float>(m_textureWidth));
+ float stepY = context.GetGUIScaleY() / (static_cast<float>(m_textureHeight));
+ glUniform4f(coordStepUniformLoc, stepX, stepY, 1.0f, 1.0f);
+ }
- // Apply the translation to the currently active (top-of-stack) model view matrix
- glMatrixModview.Push();
- glMatrixModview.Get().Translatef(m_vertexTrans[i].m_translateX, m_vertexTrans[i].m_translateY,
- m_vertexTrans[i].m_translateZ);
- glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glMatrixModview.Get());
+ // calculate the fractional offset to the ideal position
+ float fractX =
+ context.ScaleFinalXCoord(m_vertexTrans[i].m_translateX, m_vertexTrans[i].m_translateY);
+ float fractY =
+ context.ScaleFinalYCoord(m_vertexTrans[i].m_translateX, m_vertexTrans[i].m_translateY);
+ fractX = -fractX + std::round(fractX);
+ fractY = -fractY + std::round(fractY);
+
+ // proj * model * gui * scroll * translation * scaling * correction factor
+ CMatrixGL matrix = glMatrixProject.Get();
+ matrix.MultMatrixf(glMatrixModview.Get());
+ matrix.MultMatrixf(CMatrixGL(context.GetGUIMatrix()));
+ matrix.Translatef(m_vertexTrans[i].m_offsetX, m_vertexTrans[i].m_offsetY, 0.0f);
+ matrix.Translatef(m_vertexTrans[i].m_translateX, m_vertexTrans[i].m_translateY, 0.0f);
+ // the gui matrix messes with the scale. correct it here for now.
+ matrix.Scalef(context.GetGUIScaleX(), context.GetGUIScaleY(), 1.0f);
+ // the gui matrix doesn't align to exact pixel coords atm. correct it here for now.
+ matrix.Translatef(fractX, fractY, 0.0f);
+
+ glUniformMatrix4fv(matrixUniformLoc, 1, GL_FALSE, matrix);
// Bind the buffer to the OpenGL context's GL_ARRAY_BUFFER binding point
glBindBuffer(GL_ARRAY_BUFFER, m_vertexTrans[i].m_vertexBuffer->bufferHandle);
@@ -236,9 +263,8 @@ void CGUIFontTTFGLES::LastEnd()
glMatrixModview.Pop();
}
// Restore the original scissor rectangle
- renderSystem->SetScissors(scissor);
- // Restore the original model view matrix
- glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glMatrixModview.Get());
+ if (m_scissorClip)
+ renderSystem->SetScissors(scissor);
// Unbind GL_ARRAY_BUFFER and GL_ELEMENT_ARRAY_BUFFER
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
diff --git a/xbmc/guilib/GUIFontTTFGLES.h b/xbmc/guilib/GUIFontTTFGLES.h
index ae03da74e6..264d1a7611 100644
--- a/xbmc/guilib/GUIFontTTFGLES.h
+++ b/xbmc/guilib/GUIFontTTFGLES.h
@@ -55,4 +55,5 @@ private:
TextureStatus m_textureStatus{TEXTURE_VOID};
static bool m_staticVertexBufferCreated;
+ bool m_scissorClip{false};
};