1 /*  smplayer, GUI front-end for mplayer.
2     Copyright (C) 2006-2021 Ricardo Villalba <ricardo@smplayer.info>
3 
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 */
18 
19 #ifndef OPENGLRENDERER_H
20 #define OPENGLRENDERER_H
21 
22 #include "connectionbase.h"
23 
24 #include <QOpenGLBuffer>
25 #include <QOpenGLFunctions>
26 #include <QOpenGLShader>
27 #include <QOpenGLShaderProgram>
28 #include <QOpenGLTexture>
29 
30 class OpenGLRenderer : public QObject, protected QOpenGLFunctions
31 {
32 	Q_OBJECT
33 
34 public:
35 	enum PackedPattern { UYVY = 1, YUYV = 3 };
36 	enum ColorSp { BT601 = 1, BT709 = 2 };
37 
38 	OpenGLRenderer(QObject * parent = 0);
39 	~OpenGLRenderer();
40 
41 	void setFormat(ConnectionBase::Format format);
format()42 	int format() { return current_format; };
43 
setColorConversion(ColorSp c)44 	void setColorConversion(ColorSp c) { color_conversion = c; }
colorConversion()45 	int colorConversion() { return color_conversion; }
46 
47 	virtual void initializeGL(int window_width, int window_height);
48 	virtual void paintGL(int window_width, int window_height, int image_width, int image_height, uint32_t image_format, unsigned char * image_buffer);
49 	virtual void resizeGL(int w, int h);
50 
51 protected:
52 	void configureTexture(QOpenGLTexture &texture);
53 	void createFragmentShader();
54 
55 	QString rgbShader();
56 	QString yuv420Shader();
57 	QString packedShader(PackedPattern p = YUYV);
58 	QString colorConversionMat();
59 
60 	QOpenGLBuffer vertex_buffer;
61 
62 	QOpenGLTexture * textures[3];
63 
64 	QOpenGLShader * vertex_shader;
65 	QOpenGLShader * fragment_shader;
66 	QOpenGLShaderProgram program;
67 
68 	GLuint textureUniformU;
69 	GLuint textureUniformV;
70 	GLuint textureUniformY;
71 	GLuint textureUniformStepX;
72 
73 	int current_format;
74 	int color_conversion;
75 };
76 
77 #endif
78 
79