Project
Loading...
Searching...
No Matches
GPUDisplayBackend.h
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#ifndef GPUDISPLAYBACKEND_H
16#define GPUDISPLAYBACKEND_H
17
18#include "GPUCommonDef.h"
19#include "../utils/vecpod.h"
20#include <array>
21#include <cstddef>
22#include <memory>
23#include <vector>
24
25union hmm_mat4;
26
27namespace o2::gpu
28{
29class GPUDisplay;
30class GPUDisplayFrontend;
31class GPUDisplayMagneticField;
32struct GLfb;
34{
35 friend GPUDisplay;
36
37 public:
40
41 virtual int32_t ExtInit() { return 0; };
42 virtual bool CoreProfile() { return false; };
43 virtual uint32_t DepthBits() = 0;
44
45 typedef std::tuple<uint32_t, uint32_t, int32_t> vboList;
46
47 enum drawType {
48 POINTS = 0,
49 LINES = 1,
50 LINE_STRIP = 2
51 };
52
59
61 DrawArraysIndirectCommand(uint32_t a = 0, uint32_t b = 0, uint32_t c = 0, uint32_t d = 0) : count(a), instanceCount(b), first(c), baseInstance(d) {}
62 uint32_t count;
63 uint32_t instanceCount;
64
65 uint32_t first;
66 uint32_t baseInstance;
67 };
68
69 struct FontSymbol {
70 int32_t size[2];
71 int32_t offset[2];
72 int32_t advance;
73 };
74
75 virtual uint32_t drawVertices(const vboList& v, const drawType t) = 0;
76 virtual uint32_t drawField() { return 0; }
77 virtual void ActivateColor(std::array<float, 4>& color) = 0;
78 virtual void setQuality() {};
79 virtual void SetVSync(bool enable) {};
80 enum fpsLimitModes : int32_t { FPS_LIMIT_NONE = 0,
82 FPS_LIMIT_RATE = 2 }; // Values of GPUSettingsDisplayRenderer::fpsLimit
83 virtual bool canLimitToVSync() const { return false; } // Rendering is throttled to the refresh rate with VSync (blocking buffer swap / present wait)
84 int32_t fpsLimitMode() const; // Effective mode: VSync limit without VSync = none, VSync limit not supported by the backend = fpsRate
85 virtual bool backendNeedRedraw() { return true; }
86 virtual void setDepthBuffer() = 0;
87 virtual int32_t InitBackendA() = 0;
88 virtual void ExitBackendA() = 0;
89 int32_t InitBackend();
90 void updateFontScale(float scale); // Rasterize the font again if the display (HiDPI) scale changed
91 void ExitBackend();
92 virtual void loadDataToGPU(size_t totalVertizes) = 0;
93 virtual bool prepareDraw(const hmm_mat4& proj, const hmm_mat4& view, bool requestScreenshot = false, bool toMixBuffer = false, float includeMixImage = 0.f) = 0; // Returns false if the frame must be skipped (no swapchain image available)
94 virtual void finishDraw(bool doScreenshot, bool toMixBuffer = false, float includeMixImage = 0.f) = 0;
95 virtual void finishFrame(bool doScreenshot, bool toMixBuffer = false, float includeMixImage = 0.f) = 0;
96 virtual void prepareText() = 0;
97 virtual void finishText() = 0;
98 virtual void pointSizeFactor(float factor) = 0;
99 virtual void lineWidthFactor(float factor) = 0;
101 const char* backendName() const { return mBackendName; }
102 virtual void resizeScene(uint32_t width, uint32_t height) {}
103 virtual size_t needMultiVBO() { return 0; }
104 virtual void OpenGLPrint(const char* s, float x, float y, float* color, float scale) = 0;
105 static GPUDisplayBackend* getBackend(const char* type);
106 std::vector<char> getPixels();
107 virtual float getYFactor() const { return 1.0f; }
108 virtual int32_t getMaxMSAA() const { return 16; }
109
110 protected:
111 virtual void addFontSymbol(int32_t symbol, int32_t sizex, int32_t sizey, int32_t offsetx, int32_t offsety, int32_t advance, void* data) = 0;
112 virtual void initializeTextDrawing() = 0;
113 virtual void clearFontSymbols() {} // Release glyphs / font atlas before loading the font again
114 void loadFont();
115
116 float getDownsampleFactor(bool screenshot = false);
118 bool smoothFont();
119
121 std::vector<int32_t> mIndirectSectorOffset;
124 float mFontRasterScale = 1.f; // Display scale the font was rasterized for
126 std::vector<char> mScreenshotPixels;
127
128 static constexpr float SMOOTH_POINT_EXTRA_SIZE = 0.6f;
129 static constexpr float SMOOTH_LINE_EXTRA_WIDTH = 0.8f;
130 int32_t mDownsampleFactor = 1;
131
132 uint32_t mRenderWidth = 0;
133 uint32_t mRenderHeight = 0;
134 uint32_t mMaxRenderSize = UINT32_MAX; // Maximum width / height of render targets, set by the backend
135 uint32_t mScreenWidth = 0;
136 uint32_t mScreenHeight = 0;
137
139 const char* mBackendName = nullptr;
140
141 std::unique_ptr<GPUDisplayMagneticField> mMagneticFieldVisualization;
142};
143} // namespace o2::gpu
144
145#endif
uint32_t c
Definition RawData.h:2
virtual void addFontSymbol(int32_t symbol, int32_t sizex, int32_t sizey, int32_t offsetx, int32_t offsety, int32_t advance, void *data)=0
virtual float getYFactor() const
std::vector< char > getPixels()
virtual bool canLimitToVSync() const
virtual uint32_t drawVertices(const vboList &v, const drawType t)=0
virtual void finishFrame(bool doScreenshot, bool toMixBuffer=false, float includeMixImage=0.f)=0
vecpod< DrawArraysIndirectCommand > mCmdBuffer
virtual void prepareText()=0
const char * backendName() const
std::vector< int32_t > mIndirectSectorOffset
static constexpr float SMOOTH_LINE_EXTRA_WIDTH
virtual void SetVSync(bool enable)
virtual int32_t getMaxMSAA() const
virtual void lineWidthFactor(float factor)=0
static GPUDisplayBackend * getBackend(const char *type)
virtual void finishText()=0
virtual void ActivateColor(std::array< float, 4 > &color)=0
std::vector< char > mScreenshotPixels
static constexpr float SMOOTH_POINT_EXTRA_SIZE
virtual void resizeScene(uint32_t width, uint32_t height)
virtual void ExitBackendA()=0
virtual void initializeTextDrawing()=0
virtual void setDepthBuffer()=0
virtual int32_t InitBackendA()=0
backendTypes backendType() const
std::unique_ptr< GPUDisplayMagneticField > mMagneticFieldVisualization
virtual void finishDraw(bool doScreenshot, bool toMixBuffer=false, float includeMixImage=0.f)=0
virtual void loadDataToGPU(size_t totalVertizes)=0
float getDownsampleFactor(bool screenshot=false)
virtual bool prepareDraw(const hmm_mat4 &proj, const hmm_mat4 &view, bool requestScreenshot=false, bool toMixBuffer=false, float includeMixImage=0.f)=0
virtual void pointSizeFactor(float factor)=0
virtual uint32_t DepthBits()=0
std::tuple< uint32_t, uint32_t, int32_t > vboList
virtual void OpenGLPrint(const char *s, float x, float y, float *color, float scale)=0
GLint GLenum GLint x
Definition glcorearb.h:403
GLint GLsizei count
Definition glcorearb.h:399
GLsizeiptr size
Definition glcorearb.h:659
GLuint color
Definition glcorearb.h:1272
const GLdouble * v
Definition glcorearb.h:832
GLint GLsizei GLsizei height
Definition glcorearb.h:270
GLint first
Definition glcorearb.h:399
GLint GLsizei width
Definition glcorearb.h:270
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLint y
Definition glcorearb.h:270
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLboolean * data
Definition glcorearb.h:298
GLintptr offset
Definition glcorearb.h:660
GLboolean enable
Definition glcorearb.h:3991
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
DrawArraysIndirectCommand(uint32_t a=0, uint32_t b=0, uint32_t c=0, uint32_t d=0)
typename std::vector< T, vecpod_allocator< T > > vecpod
Definition vecpod.h:31