1 | /* $Id: d3dhlp.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Gallium D3D testcase. Various D3D helpers.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2017-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef GA_INCLUDED_SRC_WINNT_Graphics_Video_disp_wddm_gallium_test_d3dhlp_h
|
---|
29 | #define GA_INCLUDED_SRC_WINNT_Graphics_Video_disp_wddm_gallium_test_d3dhlp_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #ifdef VBOX
|
---|
35 | #include <iprt/win/d3d9.h>
|
---|
36 | #else
|
---|
37 | #include <d3d9.h>
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | #define D3D_RELEASE(ptr) do { \
|
---|
41 | if (ptr) \
|
---|
42 | { \
|
---|
43 | (ptr)->Release(); \
|
---|
44 | (ptr) = 0; \
|
---|
45 | } \
|
---|
46 | } while (0)
|
---|
47 |
|
---|
48 | #define GA_W_OFFSET_OF(_Type, _Member) ( (WORD)(uintptr_t) &( ((_Type *)0)->_Member ) )
|
---|
49 |
|
---|
50 | #ifdef D3DTEST_STANDALONE
|
---|
51 | inline void D3DTestShowError(HRESULT hr, const char *pszString)
|
---|
52 | {
|
---|
53 | (void)hr;
|
---|
54 | MessageBoxA(0, pszString, 0, 0);
|
---|
55 | }
|
---|
56 | #else
|
---|
57 | #define D3DTestShowError(_hr, _s) do { } while(0)
|
---|
58 | #endif
|
---|
59 |
|
---|
60 | /* Expand __LINE__ number to string. */
|
---|
61 | #define D3DTEST_S(n) #n
|
---|
62 | #define D3DTEST_N2S(n) D3DTEST_S(n)
|
---|
63 |
|
---|
64 | #define GaAssertHR(_hr) do { if (FAILED(_hr)) D3DTestShowError((_hr), __FILE__ "@" D3DTEST_N2S(__LINE__)); } while(0)
|
---|
65 |
|
---|
66 | #define HTEST(a) do { \
|
---|
67 | hr = a; \
|
---|
68 | GaAssertHR(hr); \
|
---|
69 | } while (0)
|
---|
70 |
|
---|
71 | /*
|
---|
72 | * D3D vector and matrix math helpers.
|
---|
73 | */
|
---|
74 | void d3dMatrixTranspose(D3DMATRIX *pM);
|
---|
75 | void d3dMatrixIdentity(D3DMATRIX *pM);
|
---|
76 | void d3dMatrixScaleTranslation(D3DMATRIX *pM, const float s, const float dx, const float dy, const float dz);
|
---|
77 | void d3dMatrixRotationAxis(D3DMATRIX *pM, const D3DVECTOR *pV, float angle);
|
---|
78 | void d3dMatrixView(D3DMATRIX *pM, const D3DVECTOR *pR, const D3DVECTOR *pU, const D3DVECTOR *pL, const D3DVECTOR *pP);
|
---|
79 | void d3dMatrixPerspectiveProjection(D3DMATRIX *pM, float verticalFoV, float aspectRatio, float zNear, float zFar);
|
---|
80 | void d3dMatrixMultiply(D3DMATRIX *pM, const D3DMATRIX *pM1, const D3DMATRIX *pM2);
|
---|
81 | void d3dVectorMatrixMultiply(D3DVECTOR *pR, const D3DVECTOR *pV, float w, const D3DMATRIX *pM);
|
---|
82 | void d3dVectorNormalize(D3DVECTOR *pV);
|
---|
83 | void d3dVectorCross(D3DVECTOR *pC, const D3DVECTOR *pV1, const D3DVECTOR *pV2);
|
---|
84 | float d3dVectorDot(const D3DVECTOR *pV1, const D3DVECTOR *pV2);
|
---|
85 | void d3dVectorInit(D3DVECTOR *pV, float x, float y, float z);
|
---|
86 |
|
---|
87 | /*
|
---|
88 | * Helper to compute view and projection matrices for a camera.
|
---|
89 | */
|
---|
90 | class D3DCamera
|
---|
91 | {
|
---|
92 | public:
|
---|
93 | D3DCamera();
|
---|
94 |
|
---|
95 | const D3DMATRIX *ViewProjection(void);
|
---|
96 |
|
---|
97 | void SetupAt(const D3DVECTOR *pPos, const D3DVECTOR *pAt, const D3DVECTOR *pUp);
|
---|
98 | void SetProjection(float verticalFoV, float aspectRatio, float zNear, float zFar);
|
---|
99 |
|
---|
100 | void TimeAdvance(float dt);
|
---|
101 |
|
---|
102 | private:
|
---|
103 | void computeView(void);
|
---|
104 |
|
---|
105 | /* Camera location in the world space. */
|
---|
106 | D3DVECTOR mPosition;
|
---|
107 | D3DVECTOR mRight;
|
---|
108 | D3DVECTOR mUp;
|
---|
109 | D3DVECTOR mLook;
|
---|
110 |
|
---|
111 | D3DMATRIX mView;
|
---|
112 | D3DMATRIX mProjection;
|
---|
113 | D3DMATRIX mViewProjection;
|
---|
114 |
|
---|
115 | float mTime;
|
---|
116 | };
|
---|
117 |
|
---|
118 | HRESULT d3dCreateCubeTexture(IDirect3DDevice9 *pDevice, IDirect3DCubeTexture9 **ppCubeTexture);
|
---|
119 | HRESULT d3dCreateCubeVertexBuffer(IDirect3DDevice9 *pDevice, float EdgeLength, IDirect3DVertexBuffer9 **ppVertexBuffer);
|
---|
120 |
|
---|
121 | #endif /* !GA_INCLUDED_SRC_WINNT_Graphics_Video_disp_wddm_gallium_test_d3dhlp_h */
|
---|