Project
Loading...
Searching...
No Matches
GPUDisplayBackendOpenGL.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 GPUDISPLAYBACKENDOPENGL_H
16#define GPUDISPLAYBACKENDOPENGL_H
17
18#include "GPUDisplayBackend.h"
19
20#include <vector>
21
22namespace o2::gpu
23{
24struct GLfb {
25 uint32_t fb_id = 0, fbCol_id = 0, fbDepth_id = 0;
26 bool tex = false;
27 bool msaa = false;
28 bool depth = false;
29 bool created = false;
30};
32{
33 public:
35 ~GPUDisplayBackendOpenGL() override = default;
36 int32_t ExtInit() override;
37 bool CoreProfile() override;
38 bool canLimitToVSync() const override; // Buffer swap blocks with VSync, if the frontend can set the swap interval
39 uint32_t DepthBits() override;
40
41 protected:
42 void createFB(GLfb& fb, bool tex, bool withDepth, bool msaa, uint32_t width, uint32_t height);
43 void deleteFB(GLfb& fb);
44
45 uint32_t drawVertices(const vboList& v, const drawType t) override;
46 uint32_t drawField() override;
47 void ActivateColor(std::array<float, 4>& color) override;
48 void setQuality() override;
49 void setDepthBuffer() override;
50 void setFrameBuffer(uint32_t newID = 0);
51 int32_t InitBackendA() override;
53 bool mMagneticFieldFailed = false; // Initialization of the field drawing failed, do not retry
54 void ExitBackendA() override;
56 static int32_t checkShaderStatus(uint32_t shader);
57 static int32_t checkProgramStatus(uint32_t program);
58 void clearScreen(bool alphaOnly = false);
59 void loadDataToGPU(size_t totalVertizes) override;
60 bool prepareDraw(const hmm_mat4& proj, const hmm_mat4& view, bool requestScreenshot, bool toMixBuffer, float includeMixImage) override;
61 void resizeScene(uint32_t width, uint32_t height) override;
62 void updateRenderer(bool withScreenshot);
64 void finishDraw(bool doScreenshot, bool toMixBuffer, float includeMixImage) override;
65 void finishFrame(bool doScreenshot, bool toMixBuffer, float includeMixImage) override;
66 void prepareText() override;
67 void finishText() override;
68 void mixImages(float mixSlaveImage);
69 void drawDownsample(uint32_t srcTexture, uint32_t dstFramebuffer, uint32_t width, uint32_t height, int32_t factor); // Exact box filter (fragmentDownsample.frag) for FSAA factors other than 2
70 void pointSizeFactor(float factor) override;
71 void lineWidthFactor(float factor) override;
72 size_t needMultiVBO() override { return 0x100000000ll; }
73 void readImageToPixels();
74 static uint32_t loadShader(uint32_t type, const char* spirv, size_t size); // Create shader from SPIR-V
75 static constexpr int32_t UNIFORM_LOCATION_MATRIX = 0; // Explicit uniform locations in the OpenGL variant of the shaders (shaders/*.vert, *.frag)
76 static constexpr int32_t UNIFORM_LOCATION_COLOR = 4; // color, textColor, alpha
77 static constexpr int32_t UNIFORM_LOCATION_POINT_SIZE = 5; // vertexSmoothPoint.vert
78 static constexpr int32_t UNIFORM_LOCATION_VIEWPORT = 6; // vertexSmoothLine.vert
79 static constexpr int32_t UNIFORM_LOCATION_LINE_WIDTH = 7; // vertexSmoothLine.vert
80
81 void addFontSymbol(int32_t symbol, int32_t sizex, int32_t sizey, int32_t offsetx, int32_t offsety, int32_t advance, void* data) override;
82 void initializeTextDrawing() override;
83 void clearFontSymbols() override;
84 void OpenGLPrint(const char* s, float x, float y, float* color, float scale) override;
85
86 struct FontSymbolOpenGL : public FontSymbol {
87 uint32_t texId;
88 };
89
90 uint32_t mVertexShader;
104 uint32_t mShaderProgramSmoothPoint; // Points with fragmentSmoothPoint.frag, for smoothPoints with the shader path (not rendererCompatSmoothing / GL_POINT_SMOOTH)
106 uint32_t mShaderProgramSmoothLine; // Lines with vertexSmoothLine.vert / fragmentSmoothLine.frag, for smoothLines with the shader path (not rendererCompatSmoothing / GL_LINE_SMOOTH)
112 uint32_t mVertexArray;
113
114 uint32_t mIndirectId;
115 std::vector<uint32_t> mVBOId;
116 std::vector<FontSymbolOpenGL> mFontSymbols;
117
124
126
128
130
133};
134} // namespace o2::gpu
135
136#endif
void lineWidthFactor(float factor) override
static constexpr int32_t UNIFORM_LOCATION_LINE_WIDTH
void resizeScene(uint32_t width, uint32_t height) override
void loadDataToGPU(size_t totalVertizes) override
bool prepareDraw(const hmm_mat4 &proj, const hmm_mat4 &view, bool requestScreenshot, bool toMixBuffer, float includeMixImage) override
static uint32_t loadShader(uint32_t type, const char *spirv, size_t size)
void OpenGLPrint(const char *s, float x, float y, float *color, float scale) override
void drawDownsample(uint32_t srcTexture, uint32_t dstFramebuffer, uint32_t width, uint32_t height, int32_t factor)
void finishDraw(bool doScreenshot, bool toMixBuffer, float includeMixImage) override
~GPUDisplayBackendOpenGL() override=default
uint32_t drawVertices(const vboList &v, const drawType t) override
static int32_t checkProgramStatus(uint32_t program)
void createFB(GLfb &fb, bool tex, bool withDepth, bool msaa, uint32_t width, uint32_t height)
void pointSizeFactor(float factor) override
static int32_t checkShaderStatus(uint32_t shader)
static constexpr int32_t UNIFORM_LOCATION_POINT_SIZE
static constexpr int32_t UNIFORM_LOCATION_VIEWPORT
static constexpr int32_t UNIFORM_LOCATION_COLOR
std::vector< FontSymbolOpenGL > mFontSymbols
void finishFrame(bool doScreenshot, bool toMixBuffer, float includeMixImage) override
void addFontSymbol(int32_t symbol, int32_t sizex, int32_t sizey, int32_t offsetx, int32_t offsety, int32_t advance, void *data) override
void ActivateColor(std::array< float, 4 > &color) override
static constexpr int32_t UNIFORM_LOCATION_MATRIX
std::tuple< uint32_t, uint32_t, int32_t > vboList
GLint GLenum GLint x
Definition glcorearb.h:403
GLsizeiptr size
Definition glcorearb.h:659
GLuint color
Definition glcorearb.h:1272
const GLdouble * v
Definition glcorearb.h:832
GLuint shader
Definition glcorearb.h:780
GLbitfield GLuint program
Definition glcorearb.h:1905
GLint GLsizei GLsizei height
Definition glcorearb.h:270
GLint GLsizei width
Definition glcorearb.h:270
GLint y
Definition glcorearb.h:270
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLboolean * data
Definition glcorearb.h:298
GLint GLint GLsizei GLsizei GLsizei depth
Definition glcorearb.h:470