CuteLogger
Fast and simple logging solution for Qt based applications
d3dvideowidget.h
1 /*
2  * Copyright (c) 2023 Meltytech, LLC
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 3 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, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef D3DVIDEOWIDGET_H
19 #define D3DVIDEOWIDGET_H
20 
21 #include "videowidget.h"
22 
23 #include <d3d11.h>
24 #include <directxmath.h>
25 
26 class D3DVideoWidget : public Mlt::VideoWidget
27 {
28  Q_OBJECT
29 public:
30  explicit D3DVideoWidget(QObject *parent = nullptr);
31  virtual ~D3DVideoWidget();
32 
33 public slots:
34  virtual void initialize();
35  virtual void beforeRendering();
36  virtual void renderVideo();
37 
38 private:
39  enum Stage {
40  VertexStage,
41  FragmentStage
42  };
43  void prepareShader(Stage stage);
44  QByteArray compileShader(Stage stage,
45  const QByteArray &source,
46  const QByteArray &entryPoint);
47  ID3D11ShaderResourceView *initTexture(const void *p, int width, int height);
48 
49  ID3D11Device *m_device = nullptr;
50  ID3D11DeviceContext *m_context = nullptr;
51  QByteArray m_vert;
52  QByteArray m_vertEntryPoint;
53  QByteArray m_frag;
54  QByteArray m_fragEntryPoint;
55 
56  bool m_initialized = false;
57  ID3D11Buffer *m_vbuf = nullptr;
58  ID3D11Buffer *m_cbuf = nullptr;
59  ID3D11VertexShader *m_vs = nullptr;
60  ID3D11PixelShader *m_ps = nullptr;
61  ID3D11InputLayout *m_inputLayout = nullptr;
62  ID3D11RasterizerState *m_rastState = nullptr;
63  ID3D11DepthStencilState *m_dsState = nullptr;
64  ID3D11ShaderResourceView *m_texture[3] = {nullptr, nullptr, nullptr};
65 
66  struct ConstantBuffer {
67  int32_t colorspace;
68  };
69 
70  ConstantBuffer m_constants;
71 };
72 
73 #endif // D3DVIDEOWIDGET_H