Revision | 34ff09c1e781608b06f77d2cc4c6ecd421c392d1 (tree) |
---|---|
Time | 2019-11-06 03:02:28 |
Author | <Kuddel@c0f5...> |
Merged revision(s) 1198-1200 from trunk:
- made max. number of vertices to use for one chunk at star-drawing dynamic
- D3DCAPS9 rework (mainly 'const' qualifiers, some private-isation and removal of redundant methods).
- Mesh- 'name' overhaul (results in some more named meshes).
- Surface- 'name' overhaul.
@@ -25,9 +25,10 @@ | ||
25 | 25 | // ============================================================== |
26 | 26 | |
27 | 27 | CelestialSphere::CelestialSphere(D3D9Client *_gc) |
28 | + : gc(_gc) | |
29 | + , pDevice(_gc->GetDevice()) | |
30 | + , maxNumVertices(_gc->GetHardwareCaps()->MaxPrimitiveCount) | |
28 | 31 | { |
29 | - gc = _gc; | |
30 | - pDevice = _gc->GetDevice(); | |
31 | 32 | sphere_r = 1e6f; // the actual render distance for the celestial sphere |
32 | 33 | // is irrelevant, since it is rendered without z-buffer, |
33 | 34 | // but it must be within the frustum limits - check this |
@@ -76,14 +77,13 @@ | ||
76 | 77 | float c; |
77 | 78 | int lvl, plvl = 256; |
78 | 79 | DWORD i, j, k, nv, idx = 0; |
79 | - DWORD buflen = D3DMAXNUMVERTICES; | |
80 | 80 | DWORD bufsize = 16; |
81 | 81 | nsbuf = nsvtx = 0; |
82 | 82 | svtx = new LPDIRECT3DVERTEXBUFFER9[bufsize]; |
83 | 83 | |
84 | 84 | struct StarRec { |
85 | 85 | float lng, lat, mag; |
86 | - } *data = new StarRec[buflen]; | |
86 | + } *data = new StarRec[maxNumVertices]; | |
87 | 87 | |
88 | 88 | if (prm->mag_lo <= prm->mag_hi) { delete []data; return; } |
89 | 89 |
@@ -91,7 +91,7 @@ | ||
91 | 91 | FILE *f; |
92 | 92 | fopen_s(&f, "Star.bin", "rb"); |
93 | 93 | if (!f) { delete []data; return; } |
94 | - while (nv = fread (data, sizeof(StarRec), buflen, f)) { | |
94 | + while (nv = fread (data, sizeof(StarRec), maxNumVertices, f)) { | |
95 | 95 | // limit number of stars to predefined magnitude - SHOULD BE BINARY SEARCH |
96 | 96 | for (i = 0; i < nv; i++) |
97 | 97 | if (data[i].mag > prm->mag_lo) { nv = i; break; } |
@@ -129,7 +129,7 @@ | ||
129 | 129 | nsvtx += nv; |
130 | 130 | nsbuf++; |
131 | 131 | } |
132 | - if (nv < buflen) break; | |
132 | + if (nv < maxNumVertices) break; | |
133 | 133 | } |
134 | 134 | fclose (f); |
135 | 135 |
@@ -233,10 +233,10 @@ | ||
233 | 233 | HR(pDevice->SetVertexDeclaration(pPosColorDecl)); |
234 | 234 | HR(FX->Begin(&numPasses, D3DXFX_DONOTSAVESTATE)); |
235 | 235 | HR(FX->BeginPass(0)); |
236 | - for (i = j = 0; i < nmax; i += D3DMAXNUMVERTICES, j++) | |
236 | + for (i = j = 0; i < nmax; i += maxNumVertices, j++) | |
237 | 237 | { |
238 | 238 | HR(pDevice->SetStreamSource(0, svtx[j], 0, sizeof(VERTEX_XYZC))); |
239 | - HR(pDevice->DrawPrimitive(D3DPT_POINTLIST, 0, min (nmax-i, D3DMAXNUMVERTICES))); | |
239 | + HR(pDevice->DrawPrimitive(D3DPT_POINTLIST, 0, min (nmax-i, maxNumVertices))); | |
240 | 240 | } |
241 | 241 | HR(FX->EndPass()); |
242 | 242 | HR(FX->End()); |
@@ -288,4 +288,4 @@ | ||
288 | 288 | for (i = 0; i < 12; i++) HR(pDevice->DrawPrimitive(D3DPT_LINESTRIP, i * (NSEG+1), NSEG)); |
289 | 289 | HR(FX->EndPass()); |
290 | 290 | HR(FX->End()); |
291 | -} | |
\ No newline at end of file | ||
291 | +} |
@@ -11,8 +11,6 @@ | ||
11 | 11 | #include "D3D9Client.h" |
12 | 12 | #include "D3D9Util.h" |
13 | 13 | |
14 | -#define D3DMAXNUMVERTICES 32767 // This should be dynamic | |
15 | - | |
16 | 14 | |
17 | 15 | // ============================================================== |
18 | 16 | // Class CelestialSphere (interface) |
@@ -110,6 +108,7 @@ | ||
110 | 108 | float sphere_r; ///< render radius for celestial sphere |
111 | 109 | DWORD nsbuf; ///< number of vertex buffers for star positions |
112 | 110 | // DWORD nstar; ///< total number of stars across all buffers |
111 | + UINT maxNumVertices; ///< number of vertices to use for one chunk at star-drawing | |
113 | 112 | DWORD nsvtx; ///< total number of vertices over all buffers |
114 | 113 | LPDIRECT3DVERTEXBUFFER9 *svtx; ///< star vertex buffers |
115 | 114 | int lvlid[256]; ///< star brightness hash table |
@@ -120,4 +119,4 @@ | ||
120 | 119 | LPDIRECT3DDEVICE9 pDevice; ///< DirectX9 device |
121 | 120 | }; |
122 | 121 | |
123 | -#endif // !__CELSPHERE_H | |
\ No newline at end of file | ||
122 | +#endif // !__CELSPHERE_H |
@@ -268,7 +268,7 @@ | ||
268 | 268 | hLblFont1 (NULL), |
269 | 269 | hLblFont2 (NULL), |
270 | 270 | hMainThread (NULL), |
271 | - caps (), | |
271 | + pCaps (NULL), | |
272 | 272 | parser (), |
273 | 273 | hRenderWnd(), |
274 | 274 | scene (), |
@@ -452,7 +452,7 @@ | ||
452 | 452 | ReleaseDC(hRenderWnd, hWnd); |
453 | 453 | ValidateRect(hRenderWnd, NULL); // avoids white flash after splash screen |
454 | 454 | |
455 | - caps = pFramework->caps; | |
455 | + pCaps = pFramework->GetCaps(); | |
456 | 456 | |
457 | 457 | WriteLog("[3DDevice Initialized]"); |
458 | 458 |
@@ -22,10 +22,10 @@ | ||
22 | 22 | #include <d3dx9.h> |
23 | 23 | #include "D3D9Catalog.h" |
24 | 24 | #include "GraphicsAPI.h" |
25 | -#include "D3D9util.h" | |
25 | +#include "D3D9Util.h" | |
26 | 26 | #include <stdio.h> |
27 | 27 | #include <assert.h> |
28 | -#include <OrbiterAPI.h> | |
28 | +#include "OrbiterAPI.h" | |
29 | 29 | #include "D3D9Frame.h" |
30 | 30 | #include "nvapi.h" |
31 | 31 | #include "gcConst.h" |
@@ -1001,15 +1001,15 @@ | ||
1001 | 1001 | LPDIRECT3DTEXTURE9 GetNoiseTex() const { return pNoiseTex; } |
1002 | 1002 | void EmergencyShutdown(); |
1003 | 1003 | void SplashScreen(); |
1004 | - inline bool IsRunning() { return bRunning; } | |
1005 | - inline bool IsLimited() { return ((caps.TextureCaps&D3DPTEXTURECAPS_POW2) && (caps.TextureCaps&D3DPTEXTURECAPS_NONPOW2CONDITIONAL)); } | |
1004 | + inline bool IsRunning() const { return bRunning; } | |
1005 | + inline bool IsLimited() const { return ((pCaps->TextureCaps&D3DPTEXTURECAPS_POW2) && (pCaps->TextureCaps&D3DPTEXTURECAPS_NONPOW2CONDITIONAL)); } | |
1006 | 1006 | const LPD3DXMATRIX GetIdentity() const { return (const LPD3DXMATRIX)&ident; } |
1007 | 1007 | HWND GetWindow(); |
1008 | - bool HasVertexTextureSupport() { return bVertexTex; } | |
1009 | - D3DCAPS9 * GetHardwareCaps() { return ∩︀ } | |
1010 | - FileParser * GetFileParser() { return parser; } | |
1011 | - LPDIRECT3DSURFACE9 GetBackBuffer() { return pBackBuffer; } | |
1012 | - LPDIRECT3DSURFACE9 GetDepthStencil() { return pDepthStencil; } | |
1008 | + bool HasVertexTextureSupport() const { return bVertexTex; } | |
1009 | + const D3DCAPS9 * GetHardwareCaps() const { return pCaps; } | |
1010 | + FileParser * GetFileParser() const { return parser; } | |
1011 | + LPDIRECT3DSURFACE9 GetBackBuffer() const { return pBackBuffer; } | |
1012 | + LPDIRECT3DSURFACE9 GetDepthStencil() const { return pDepthStencil; } | |
1013 | 1013 | const void * GetConfigParam (DWORD paramtype) const; |
1014 | 1014 | bool RegisterRenderProc(__gcRenderProc proc, DWORD id, void *pParam = NULL); |
1015 | 1015 | bool RegisterGenericProc(__gcGenericProc proc, DWORD id, void *pParam = NULL); |
@@ -1255,9 +1255,9 @@ | ||
1255 | 1255 | LPDIRECT3DSURFACE9 pTextScreen; |
1256 | 1256 | LPDIRECT3DSURFACE9 pBackBuffer; |
1257 | 1257 | LPDIRECT3DSURFACE9 pDepthStencil; |
1258 | - CD3DFramework9* pFramework; | |
1259 | - D3DCAPS9 caps; | |
1260 | - FileParser * parser; | |
1258 | + CD3DFramework9 * pFramework; | |
1259 | + const D3DCAPS9 * pCaps; | |
1260 | + FileParser * parser; | |
1261 | 1261 | std::string scenarioName; |
1262 | 1262 | HANDLE hMainThread; |
1263 | 1263 |
@@ -43,33 +43,34 @@ | ||
43 | 43 | private: |
44 | 44 | |
45 | 45 | // Internal variables for the framework class |
46 | - HWND hWnd; // The window object | |
47 | - BOOL bIsFullscreen; // Fullscreen vs. windowed | |
48 | - BOOL bVertexTexture; | |
49 | - BOOL bAAEnabled; | |
50 | - BOOL bNoVSync; // don't use vertical sync in fullscreen | |
51 | - BOOL Alpha; | |
52 | - BOOL SWVert; | |
53 | - BOOL Pure; | |
54 | - BOOL DDM; | |
55 | - BOOL bGDIBB; | |
56 | - BOOL nvPerfHud; | |
57 | - DWORD dwRenderWidth; // Dimensions of the render target | |
58 | - DWORD dwRenderHeight; | |
59 | - DWORD dwFSMode; | |
60 | - LPDIRECT3D9 pD3D; // The Direct3D object | |
61 | - LPDIRECT3DDEVICE9 pDevice; // The D3D device | |
62 | - LPD3DXFONT pLargeFont; | |
63 | - LPD3DXFONT pSmallFont; | |
64 | - DWORD dwZBufferBitDepth; // Bit depth of z-buffer | |
65 | - DWORD dwStencilBitDepth; // Bit depth of stencil buffer (0 if none) | |
66 | - DWORD Adapter; | |
67 | - DWORD Mode; | |
68 | - DWORD MultiSample; | |
69 | - LPDIRECT3DSURFACE9 pRenderTarget; | |
70 | - D3D9ClientSurface * pBackBuffer; | |
71 | - | |
72 | - RECT rcScreenRect; // Screen rect for window | |
46 | + HWND hWnd; // The window object | |
47 | + BOOL bIsFullscreen; // Fullscreen vs. windowed | |
48 | + BOOL bVertexTexture; | |
49 | + BOOL bAAEnabled; | |
50 | + BOOL bNoVSync; // don't use vertical sync in fullscreen | |
51 | + BOOL Alpha; | |
52 | + BOOL SWVert; | |
53 | + BOOL Pure; | |
54 | + BOOL DDM; | |
55 | + BOOL bGDIBB; | |
56 | + BOOL nvPerfHud; | |
57 | + DWORD dwRenderWidth; // Dimensions of the render target | |
58 | + DWORD dwRenderHeight; // Dimensions of the render target | |
59 | + DWORD dwFSMode; | |
60 | + LPDIRECT3D9 pD3D; // The Direct3D object | |
61 | + LPDIRECT3DDEVICE9 pDevice; // The D3D device | |
62 | + LPD3DXFONT pLargeFont; | |
63 | + LPD3DXFONT pSmallFont; | |
64 | + DWORD dwZBufferBitDepth; // Bit depth of z-buffer | |
65 | + DWORD dwStencilBitDepth; // Bit depth of stencil buffer (0 if none) | |
66 | + DWORD Adapter; | |
67 | + DWORD Mode; | |
68 | + DWORD MultiSample; | |
69 | + LPDIRECT3DSURFACE9 pRenderTarget; | |
70 | + D3D9ClientSurface * pBackBuffer; | |
71 | + D3DPRESENT_PARAMETERS d3dPP; | |
72 | + D3DCAPS9 caps; | |
73 | + RECT rcScreenRect; // Screen rect for window | |
73 | 74 | |
74 | 75 | // Internal functions for the framework class |
75 | 76 |
@@ -79,19 +80,14 @@ | ||
79 | 80 | |
80 | 81 | public: |
81 | 82 | |
82 | - D3DPRESENT_PARAMETERS d3dPP; | |
83 | - D3DCAPS9 caps; | |
84 | - | |
85 | 83 | // Access functions for DirectX objects |
86 | 84 | inline HWND GetRenderWindow() const { return hWnd; } |
87 | 85 | inline LPDIRECT3D9 GetDirect3D() const { return pD3D; } |
88 | 86 | inline LPDIRECT3DDEVICE9 GetD3DDevice() const { return pDevice; } |
89 | - inline DWORD GetRenderWidth() const { return dwRenderWidth; } // Dimensions of the render target | |
90 | - inline DWORD GetRenderHeight() const { return dwRenderHeight; } // Dimensions of the render target | |
91 | 87 | inline DWORD GetZBufferBitDepth() const { return dwZBufferBitDepth; } |
92 | 88 | inline DWORD GetStencilBitDepth() const { return dwStencilBitDepth; } |
93 | - inline DWORD GetWidth() const { return dwRenderWidth; } | |
94 | - inline DWORD GetHeight() const { return dwRenderHeight; } | |
89 | + inline DWORD GetWidth() const { return dwRenderWidth; } // Dimensions of the render target | |
90 | + inline DWORD GetHeight() const { return dwRenderHeight; } // Dimensions of the render target | |
95 | 91 | inline const RECT GetScreenRect() const { return rcScreenRect; } |
96 | 92 | inline LPDIRECT3DSURFACE9 GetBackBuffer() const { return pRenderTarget; } |
97 | 93 | inline SURFHANDLE GetBackBufferHandle() const { return pBackBuffer; } |
@@ -203,10 +203,10 @@ | ||
203 | 203 | |
204 | 204 | // ----------------------------------------------------------------------------------------------- |
205 | 205 | // |
206 | -D3D9ClientSurface::D3D9ClientSurface(LPDIRECT3DDEVICE9 pDev, const char* name/*="???"*/) | |
206 | +D3D9ClientSurface::D3D9ClientSurface(LPDIRECT3DDEVICE9 pDev, const char* name_ /* = NULL */) | |
207 | 207 | { |
208 | 208 | Clear(); |
209 | - strcpy_s(this->name, 64, (name ? name : "???")); | |
209 | + strcpy_s(this->name, ARRAYSIZE(this->name), (name_ ? name_ : "???")); | |
210 | 210 | pDevice = pDev; |
211 | 211 | SurfaceCatalog->Add(this); |
212 | 212 | } |
@@ -2079,4 +2079,4 @@ | ||
2079 | 2079 | z+=4; |
2080 | 2080 | x+=6; |
2081 | 2081 | } |
2082 | -} | |
\ No newline at end of file | ||
2082 | +} |
@@ -43,7 +43,7 @@ | ||
43 | 43 | static void GlobalExit(); |
44 | 44 | |
45 | 45 | // Create empty surface. Must use Create methods to make a valid surface |
46 | - D3D9ClientSurface(LPDIRECT3DDEVICE9 pDevice, const char* name = "???"); | |
46 | + D3D9ClientSurface(LPDIRECT3DDEVICE9 pDevice, const char* name = NULL); | |
47 | 47 | |
48 | 48 | // Destroy the class and release the texture (pTex) if exists. Value of Reference counter doesn't matter. |
49 | 49 | ~D3D9ClientSurface(); |
@@ -152,7 +152,7 @@ | ||
152 | 152 | // Mesh Implementation |
153 | 153 | // ====================================================================================== |
154 | 154 | // |
155 | -void D3D9Mesh::Null() | |
155 | +void D3D9Mesh::Null(const char *meshName /* = NULL */) | |
156 | 156 | { |
157 | 157 | nGrp = 0; |
158 | 158 | Grp = NULL; |
@@ -182,15 +182,15 @@ | ||
182 | 182 | |
183 | 183 | memset(Locals, 0, sizeof(LightStruct) * Config->MaxLights()); |
184 | 184 | memset(LightList, 0, sizeof(LightList)); |
185 | - strcpy_s(name, 128, "???"); | |
185 | + strcpy_s(this->name, ARRAYSIZE(this->name), meshName ? meshName : "???"); | |
186 | 186 | } |
187 | 187 | |
188 | 188 | // =========================================================================================== |
189 | 189 | // |
190 | -D3D9Mesh::D3D9Mesh(const char *name) : D3D9Effect() | |
190 | +D3D9Mesh::D3D9Mesh(const char *fname) : D3D9Effect() | |
191 | 191 | { |
192 | - Null(); | |
193 | - MESHHANDLE hMesh = oapiLoadMesh(name); | |
192 | + Null(fname); | |
193 | + MESHHANDLE hMesh = oapiLoadMesh(fname); | |
194 | 194 | |
195 | 195 | if (hMesh) { |
196 | 196 | LoadMeshFromHandle(hMesh); |
@@ -203,9 +203,9 @@ | ||
203 | 203 | |
204 | 204 | // =========================================================================================== |
205 | 205 | // |
206 | -D3D9Mesh::D3D9Mesh(MESHHANDLE hMesh, bool asTemplate, D3DXVECTOR3 *reorig, float *scale) : D3D9Effect() | |
206 | +D3D9Mesh::D3D9Mesh(MESHHANDLE hMesh, bool asTemplate, D3DXVECTOR3 *reorig, float *scale, const char *meshName) : D3D9Effect() | |
207 | 207 | { |
208 | - Null(); | |
208 | + Null(meshName); | |
209 | 209 | LoadMeshFromHandle(hMesh, reorig, scale); |
210 | 210 | bIsTemplate = asTemplate; |
211 | 211 | MeshCatalog->Add(this); |
@@ -303,7 +303,7 @@ | ||
303 | 303 | |
304 | 304 | if (nGrp == 0) return; |
305 | 305 | |
306 | - strcpy_s(name, 128, hTemp.name); | |
306 | + strcpy_s(name, ARRAYSIZE(name), hTemp.name); | |
307 | 307 | |
308 | 308 | // Use Template's Vertex Data directly, no need for a local copy unless locally modified. |
309 | 309 | pBuf = hTemp.pBuf; |
@@ -476,9 +476,9 @@ | ||
476 | 476 | |
477 | 477 | // =========================================================================================== |
478 | 478 | // |
479 | -void D3D9Mesh::SetName(const char *fname) | |
479 | +void D3D9Mesh::SetName(const char *name_) | |
480 | 480 | { |
481 | - if (fname) strcpy_s(name,128,fname); | |
481 | + if (name_) strcpy_s(this->name, ARRAYSIZE(this->name), name_); | |
482 | 482 | } |
483 | 483 | |
484 | 484 | // =========================================================================================== |
@@ -73,7 +73,7 @@ | ||
73 | 73 | ~MeshBuffer(); |
74 | 74 | |
75 | 75 | void Map(LPDIRECT3DDEVICE9 pDev); |
76 | - bool IsLocalTo(const class D3D9Mesh *_pRoot) { return (_pRoot == pRoot); } | |
76 | + bool IsLocalTo(const class D3D9Mesh *_pRoot) const { return (_pRoot == pRoot); } | |
77 | 77 | void MustRemap(DWORD mode); |
78 | 78 | |
79 | 79 | LPDIRECT3DVERTEXBUFFER9 pVB; |
@@ -144,10 +144,10 @@ | ||
144 | 144 | }; |
145 | 145 | |
146 | 146 | |
147 | - D3D9Mesh(const char *name); | |
147 | + D3D9Mesh(const char *fname); | |
148 | 148 | D3D9Mesh(DWORD nGrp, const MESHGROUPEX **hGroup, const SURFHANDLE *hSurf); |
149 | 149 | D3D9Mesh(const MESHGROUPEX *pGroup, const MATERIAL *pMat, D3D9ClientSurface *pTex); |
150 | - D3D9Mesh(MESHHANDLE hMesh, bool asTemplate = false, D3DXVECTOR3 *reorig = NULL, float *scale = NULL); | |
150 | + D3D9Mesh(MESHHANDLE hMesh, bool asTemplate = false, D3DXVECTOR3 *reorig = NULL, float *scale = NULL, const char *meshName = NULL); | |
151 | 151 | D3D9Mesh(MESHHANDLE hMesh, const D3D9Mesh &hTemp); |
152 | 152 | ~D3D9Mesh(); |
153 | 153 |
@@ -279,7 +279,7 @@ | ||
279 | 279 | void ProcessInherit(); |
280 | 280 | bool CopyVertices(GROUPREC *grp, const MESHGROUPEX *mg, D3DXVECTOR3 *reorig = NULL, float *scale = NULL); |
281 | 281 | void SetGroupRec(DWORD i, const MESHGROUPEX *mg); |
282 | - void Null(); | |
282 | + void Null(const char *meshName = NULL); | |
283 | 283 | |
284 | 284 | |
285 | 285 | DWORD MaxVert; |
@@ -72,7 +72,7 @@ | ||
72 | 72 | |
73 | 73 | LPDIRECT3DDEVICE9 pDev = gc->GetDevice(); |
74 | 74 | |
75 | - D3DCAPS9 *caps = gc->GetHardwareCaps(); | |
75 | + const D3DCAPS9 *caps = gc->GetHardwareCaps(); | |
76 | 76 | |
77 | 77 | int size = max(min(caps->MaxTextureWidth, 8192), 2048); |
78 | 78 |
@@ -175,7 +175,7 @@ | ||
175 | 175 | if (hMesh) { |
176 | 176 | LogAlw("Loading mesh [%s] for planetary body '%s'", cbuf, name); |
177 | 177 | float fSize = float(size); |
178 | - mesh = new D3D9Mesh(hMesh, false, NULL, &fSize); | |
178 | + mesh = new D3D9Mesh(hMesh, false, NULL, &fSize, cbuf); | |
179 | 179 | oapiDeleteMesh (hMesh); |
180 | 180 | } |
181 | 181 | } |