Project
Loading...
Searching...
No Matches
GPUDisplayBackend.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#include "GPUDisplayBackend.h"
17
19
20#ifdef GPUCA_BUILD_EVENT_DISPLAY_VULKAN
22#endif
23
24#ifdef GPUCA_BUILD_EVENT_DISPLAY_FREETYPE
25#include <ft2build.h>
26#include FT_FREETYPE_H
27#ifdef GPUCA_BUILD_EVENT_DISPLAY_FONTCONFIG
28#if !__has_include(<fontconfig/fontconfig.h>)
29#undef GPUCA_BUILD_EVENT_DISPLAY_FONTCONFIG
30#else
31#include <fontconfig/fontconfig.h>
32#endif
33#endif
34#endif
35
36#include "GPUDisplay.h"
37#include "GPULogging.h"
38#include <string>
39
40using namespace o2::gpu;
41
44
46{
47#ifdef GPUCA_BUILD_EVENT_DISPLAY_VULKAN
48 if (strcmp(type, "vulkan") == 0 || strcmp(type, "auto") == 0) {
49 return new GPUDisplayBackendVulkan;
50 } else
51#endif
52 if (strcmp(type, "opengl") == 0 || strcmp(type, "auto") == 0) {
53 return new GPUDisplayBackendOpenGL;
54 } else {
55 GPUError("Requested renderer not available");
56 }
57 return nullptr;
58}
59
61{
62 int32_t retVal = InitBackendA();
63 if (retVal) {
64 return retVal;
65 }
66 if (mDisplay->cfg().noFreetype) {
67 return retVal;
68 }
69 std::string fontName = mDisplay->cfg().font;
70#ifdef GPUCA_BUILD_EVENT_DISPLAY_FONTCONFIG
71 FcInit();
72 FcConfig* config = FcInitLoadConfigAndFonts();
73 FcPattern* pat = FcNameParse((const FcChar8*)fontName.c_str());
74 FcConfigSubstitute(config, pat, FcMatchPattern);
75 FcDefaultSubstitute(pat);
76 FcResult result;
77 FcPattern* font = FcFontMatch(config, pat, &result);
78 if (font && result == 0) {
79 FcChar8* file = nullptr;
80 if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
81 fontName = (char*)file;
82 }
83 } else {
84 GPUError("Coult not find font for pattern %s", fontName.c_str());
85 }
86 FcPatternDestroy(font);
87 FcPatternDestroy(pat);
88 FcConfigDestroy(config);
89 FcFini();
90#endif // GPUCA_BUILD_EVENT_DISPLAY_FONTCONFIG
91
92#ifdef GPUCA_BUILD_EVENT_DISPLAY_FREETYPE
93 FT_Library ft;
94 FT_Face face;
95 if (FT_Init_FreeType(&ft)) {
96 GPUError("Error initializing freetype");
97 return 0;
98 }
99 if (FT_New_Face(ft, fontName.c_str(), 0, &face)) {
100 GPUError("Error loading freetypoe font");
101 return 0;
102 }
103
104 int32_t fontSize = mDisplay->cfg().fontSize;
106 if (smoothFont()) {
107 fontSize *= 4; // Font size scaled by 4, can be downsampled
108 }
109 FT_Set_Pixel_Sizes(face, 0, fontSize);
110
111 for (uint32_t i = 0; i < 128; i++) {
112 if (FT_Load_Char(face, i, FT_LOAD_RENDER)) {
113 GPUError("Error loading freetype symbol");
114 return 0;
115 }
116 const auto& glyph = face->glyph;
117 addFontSymbol(i, glyph->bitmap.width, glyph->bitmap.rows, glyph->bitmap_left, glyph->bitmap_top, glyph->advance.x, glyph->bitmap.buffer);
118 }
120 FT_Done_Face(face);
121 FT_Done_FreeType(ft);
123#endif // GPUCA_BUILD_EVENT_DISPLAY_FREETYPE
124 return retVal;
125}
126
131
133{
134 auto retVal = std::move(mScreenshotPixels);
135 mScreenshotPixels = std::vector<char>();
136 return retVal;
137}
138
140{
141 mCmdBuffer.clear();
143 // TODO: Check if this can be parallelized
144 for (int32_t iSector = 0; iSector < GPUCA_NSECTORS; iSector++) {
145 mIndirectSectorOffset[iSector] = mCmdBuffer.size();
146 for (uint32_t k = 0; k < mDisplay->vertexBufferStart()[iSector].size(); k++) {
147 mCmdBuffer.emplace_back(mDisplay->vertexBufferCount()[iSector][k], 1, mDisplay->vertexBufferStart()[iSector][k], 0);
148 }
149 }
150}
151
153{
154 float factor = 1.0f;
155 int32_t fsaa = mDisplay->cfgR().drawQualityDownsampleFSAA;
156 int32_t screenshotScale = mDisplay->cfgR().screenshotScaleFactor;
157 if (fsaa) {
158 factor *= fsaa;
159 }
160 if (screenshotScale && screenshot) {
161 factor *= screenshotScale;
162 }
163 return factor;
164}
165
167{
168 return mDisplay->cfg().smoothFont < 0 ? (mDisplay->cfg().fontSize > 12) : mDisplay->cfg().smoothFont;
169}
int32_t i
int32_t retVal
#define GPUCA_NSECTORS
virtual void addFontSymbol(int32_t symbol, int32_t sizex, int32_t sizey, int32_t offsetx, int32_t offsety, int32_t advance, void *data)=0
std::vector< char > getPixels()
vecpod< DrawArraysIndirectCommand > mCmdBuffer
std::vector< int32_t > mIndirectSectorOffset
static GPUDisplayBackend * getBackend(const char *type)
std::vector< char > mScreenshotPixels
virtual void ExitBackendA()=0
virtual void initializeTextDrawing()=0
virtual int32_t InitBackendA()=0
float getDownsampleFactor(bool screenshot=false)
const GPUSettingsDisplayRenderer & cfgR() const
Definition GPUDisplay.h:58
int32_t & drawTextFontSize()
Definition GPUDisplay.h:76
const vecpod< uint32_t > * vertexBufferCount() const
Definition GPUDisplay.h:67
const GPUSettingsDisplay & cfg() const
Definition GPUDisplay.h:61
vecpod< int32_t > * vertexBufferStart()
Definition GPUDisplay.h:66
GLuint64EXT * result
Definition glcorearb.h:5662
GLsizeiptr size
Definition glcorearb.h:659
GLenum GLuint GLint GLenum face
Definition glcorearb.h:3184
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLenum GLsizeiptr fontSize
Definition glcorearb.h:5519
GLenum const void * fontName
Definition glcorearb.h:5473