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 { VertexStage, FragmentStage };
40  void prepareShader(Stage stage);
41  QByteArray compileShader(Stage stage, const QByteArray &source, const QByteArray &entryPoint);
42  ID3D11ShaderResourceView *initTexture(const void *p, int width, int height);
43 
44  ID3D11Device *m_device = nullptr;
45  ID3D11DeviceContext *m_context = nullptr;
46  QByteArray m_vert;
47  QByteArray m_vertEntryPoint;
48  QByteArray m_frag;
49  QByteArray m_fragEntryPoint;
50 
51  bool m_initialized = false;
52  ID3D11Buffer *m_vbuf = nullptr;
53  ID3D11Buffer *m_cbuf = nullptr;
54  ID3D11VertexShader *m_vs = nullptr;
55  ID3D11PixelShader *m_ps = nullptr;
56  ID3D11InputLayout *m_inputLayout = nullptr;
57  ID3D11RasterizerState *m_rastState = nullptr;
58  ID3D11DepthStencilState *m_dsState = nullptr;
59  ID3D11ShaderResourceView *m_texture[3] = {nullptr, nullptr, nullptr};
60 
61  struct ConstantBuffer
62  {
63  int32_t colorspace;
64  };
65 
66  ConstantBuffer m_constants;
67 };
68 
69 #endif // D3DVIDEOWIDGET_H