Skip to content

Commit

Permalink
Merge pull request xbmc#22819 from lrusak/guifontgl-split
Browse files Browse the repository at this point in the history
CGUIFontGL: split out GLES paths into CGUIFontGLES
  • Loading branch information
lrusak committed Mar 4, 2023
2 parents 1087c29 + 4a12708 commit 56b88b2
Show file tree
Hide file tree
Showing 5 changed files with 496 additions and 77 deletions.
18 changes: 10 additions & 8 deletions xbmc/guilib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,23 @@ set(HEADERS DDSImage.h
XBTFReader.h)

if(OPENGL_FOUND OR OPENGLES_FOUND)
list(APPEND SOURCES GUIFontTTFGL.cpp
Shader.cpp
list(APPEND SOURCES Shader.cpp
TextureGL.cpp)
list(APPEND HEADERS GUIFontTTFGL.h
Shader.h
list(APPEND HEADERS Shader.h
TextureGL.h)

if(OPENGL_FOUND)
list(APPEND SOURCES GUITextureGL.cpp)
list(APPEND HEADERS GUITextureGL.h)
list(APPEND SOURCES GUIFontTTFGL.cpp
GUITextureGL.cpp)
list(APPEND HEADERS GUIFontTTFGL.h
GUITextureGL.h)
endif()

if(OPENGLES_FOUND)
list(APPEND SOURCES GUITextureGLES.cpp)
list(APPEND HEADERS GUITextureGLES.h)
list(APPEND SOURCES GUIFontTTFGLES.cpp
GUITextureGLES.cpp)
list(APPEND HEADERS GUIFontTTFGLES.h
GUITextureGLES.h)
endif()

endif()
Expand Down
11 changes: 9 additions & 2 deletions xbmc/guilib/GUIFontManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
#include "windowing/GraphicContext.h"

#include <mutex>
#if defined(HAS_GLES) || defined(HAS_GL)
#if defined(HAS_GL)
#include "GUIFontTTFGL.h"
#endif
#if defined(HAS_GLES)
#include "GUIFontTTFGLES.h"
#endif
#include "FileItem.h"
#include "GUIControlFactory.h"
#include "GUIFont.h"
Expand Down Expand Up @@ -408,9 +411,13 @@ void GUIFontManager::Clear()
m_vecFontFiles.clear();
m_vecFontInfo.clear();

#if defined(HAS_GLES) || defined(HAS_GL)
#if defined(HAS_GL)
CGUIFontTTFGL::DestroyStaticVertexBuffers();
#endif

#if defined(HAS_GLES)
CGUIFontTTFGLES::DestroyStaticVertexBuffers();
#endif
}

void GUIFontManager::LoadFonts(const std::string& fontSet)
Expand Down
69 changes: 2 additions & 67 deletions xbmc/guilib/GUIFontTTFGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@
#include "Texture.h"
#include "TextureManager.h"
#include "gui3d.h"
#include "rendering/MatrixGL.h"
#include "rendering/gl/RenderSystemGL.h"
#include "utils/GLUtils.h"
#include "utils/log.h"
#include "windowing/GraphicContext.h"
#ifdef HAS_GL
#include "rendering/gl/RenderSystemGL.h"
#elif HAS_GLES
#include "rendering/gles/RenderSystemGLES.h"
#endif
#include "rendering/MatrixGL.h"

#include <cassert>
#include <memory>
Expand Down Expand Up @@ -58,7 +54,6 @@ CGUIFontTTFGL::~CGUIFontTTFGL(void)

bool CGUIFontTTFGL::FirstBegin()
{
#if defined(HAS_GL)
GLenum pixformat = GL_RED;
GLenum internalFormat;
unsigned int major, minor;
Expand All @@ -69,13 +64,6 @@ bool CGUIFontTTFGL::FirstBegin()
else
internalFormat = GL_LUMINANCE;
renderSystem->EnableShader(ShaderMethodGL::SM_FONTS);
#else
CRenderSystemGLES* renderSystem =
dynamic_cast<CRenderSystemGLES*>(CServiceBroker::GetRenderSystem());
renderSystem->EnableGUIShader(ShaderMethodGLES::SM_FONTS);
GLenum pixformat = GL_ALPHA; // deprecated
GLenum internalFormat = GL_ALPHA;
#endif

if (m_textureStatus == TEXTURE_REALLOCATED)
{
Expand Down Expand Up @@ -133,7 +121,6 @@ void CGUIFontTTFGL::LastEnd()
if (!winSystem)
return;

#ifdef HAS_GL
CRenderSystemGL* renderSystem = dynamic_cast<CRenderSystemGL*>(CServiceBroker::GetRenderSystem());

GLint posLoc = renderSystem->ShaderGetPos();
Expand Down Expand Up @@ -186,54 +173,6 @@ void CGUIFontTTFGL::LastEnd()
glDeleteBuffers(1, &VertexVBO);
}

#else
// GLES 2.0 version.
CRenderSystemGLES* renderSystem =
dynamic_cast<CRenderSystemGLES*>(CServiceBroker::GetRenderSystem());

GLint posLoc = renderSystem->GUIShaderGetPos();
GLint colLoc = renderSystem->GUIShaderGetCol();
GLint tex0Loc = renderSystem->GUIShaderGetCoord0();
GLint modelLoc = renderSystem->GUIShaderGetModel();


CreateStaticVertexBuffers();

// Enable the attributes used by this shader
glEnableVertexAttribArray(posLoc);
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());
}
#endif

if (!m_vertexTrans.empty())
{
// Deal with the vertices that can be hardware clipped and therefore translated
Expand Down Expand Up @@ -311,11 +250,7 @@ void CGUIFontTTFGL::LastEnd()
glDisableVertexAttribArray(colLoc);
glDisableVertexAttribArray(tex0Loc);

#ifdef HAS_GL
renderSystem->DisableShader();
#else
renderSystem->DisableGUIShader();
#endif
}

CVertexBuffer CGUIFontTTFGL::CreateVertexBuffer(const std::vector<SVertex>& vertices) const
Expand Down
Loading

0 comments on commit 56b88b2

Please sign in to comment.