Commit MetaInfo

Revision34ff09c1e781608b06f77d2cc4c6ecd421c392d1 (tree)
Time2019-11-06 03:02:28
Author <Kuddel@c0f5...>

Log Message

Merged revision(s) 1198-1200 from trunk:
- made max. number of vertices to use for one chunk at star-drawing dynamic

(removed D3DMAXNUMVERTICES define).

- 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.

Change Summary

Incremental Difference

diff -r ad6a3a7570cb -r 34ff09c1e781 Orbitersdk/D3D9Client/CelSphere.cpp
--- a/Orbitersdk/D3D9Client/CelSphere.cpp Tue Nov 05 14:34:43 2019 +0000
+++ b/Orbitersdk/D3D9Client/CelSphere.cpp Tue Nov 05 18:02:28 2019 +0000
@@ -25,9 +25,10 @@
2525 // ==============================================================
2626
2727 CelestialSphere::CelestialSphere(D3D9Client *_gc)
28+ : gc(_gc)
29+ , pDevice(_gc->GetDevice())
30+ , maxNumVertices(_gc->GetHardwareCaps()->MaxPrimitiveCount)
2831 {
29- gc = _gc;
30- pDevice = _gc->GetDevice();
3132 sphere_r = 1e6f; // the actual render distance for the celestial sphere
3233 // is irrelevant, since it is rendered without z-buffer,
3334 // but it must be within the frustum limits - check this
@@ -76,14 +77,13 @@
7677 float c;
7778 int lvl, plvl = 256;
7879 DWORD i, j, k, nv, idx = 0;
79- DWORD buflen = D3DMAXNUMVERTICES;
8080 DWORD bufsize = 16;
8181 nsbuf = nsvtx = 0;
8282 svtx = new LPDIRECT3DVERTEXBUFFER9[bufsize];
8383
8484 struct StarRec {
8585 float lng, lat, mag;
86- } *data = new StarRec[buflen];
86+ } *data = new StarRec[maxNumVertices];
8787
8888 if (prm->mag_lo <= prm->mag_hi) { delete []data; return; }
8989
@@ -91,7 +91,7 @@
9191 FILE *f;
9292 fopen_s(&f, "Star.bin", "rb");
9393 if (!f) { delete []data; return; }
94- while (nv = fread (data, sizeof(StarRec), buflen, f)) {
94+ while (nv = fread (data, sizeof(StarRec), maxNumVertices, f)) {
9595 // limit number of stars to predefined magnitude - SHOULD BE BINARY SEARCH
9696 for (i = 0; i < nv; i++)
9797 if (data[i].mag > prm->mag_lo) { nv = i; break; }
@@ -129,7 +129,7 @@
129129 nsvtx += nv;
130130 nsbuf++;
131131 }
132- if (nv < buflen) break;
132+ if (nv < maxNumVertices) break;
133133 }
134134 fclose (f);
135135
@@ -233,10 +233,10 @@
233233 HR(pDevice->SetVertexDeclaration(pPosColorDecl));
234234 HR(FX->Begin(&numPasses, D3DXFX_DONOTSAVESTATE));
235235 HR(FX->BeginPass(0));
236- for (i = j = 0; i < nmax; i += D3DMAXNUMVERTICES, j++)
236+ for (i = j = 0; i < nmax; i += maxNumVertices, j++)
237237 {
238238 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)));
240240 }
241241 HR(FX->EndPass());
242242 HR(FX->End());
@@ -288,4 +288,4 @@
288288 for (i = 0; i < 12; i++) HR(pDevice->DrawPrimitive(D3DPT_LINESTRIP, i * (NSEG+1), NSEG));
289289 HR(FX->EndPass());
290290 HR(FX->End());
291-}
\ No newline at end of file
291+}
diff -r ad6a3a7570cb -r 34ff09c1e781 Orbitersdk/D3D9Client/CelSphere.h
--- a/Orbitersdk/D3D9Client/CelSphere.h Tue Nov 05 14:34:43 2019 +0000
+++ b/Orbitersdk/D3D9Client/CelSphere.h Tue Nov 05 18:02:28 2019 +0000
@@ -11,8 +11,6 @@
1111 #include "D3D9Client.h"
1212 #include "D3D9Util.h"
1313
14-#define D3DMAXNUMVERTICES 32767 // This should be dynamic
15-
1614
1715 // ==============================================================
1816 // Class CelestialSphere (interface)
@@ -110,6 +108,7 @@
110108 float sphere_r; ///< render radius for celestial sphere
111109 DWORD nsbuf; ///< number of vertex buffers for star positions
112110 // DWORD nstar; ///< total number of stars across all buffers
111+ UINT maxNumVertices; ///< number of vertices to use for one chunk at star-drawing
113112 DWORD nsvtx; ///< total number of vertices over all buffers
114113 LPDIRECT3DVERTEXBUFFER9 *svtx; ///< star vertex buffers
115114 int lvlid[256]; ///< star brightness hash table
@@ -120,4 +119,4 @@
120119 LPDIRECT3DDEVICE9 pDevice; ///< DirectX9 device
121120 };
122121
123-#endif // !__CELSPHERE_H
\ No newline at end of file
122+#endif // !__CELSPHERE_H
diff -r ad6a3a7570cb -r 34ff09c1e781 Orbitersdk/D3D9Client/D3D9Client.cpp
--- a/Orbitersdk/D3D9Client/D3D9Client.cpp Tue Nov 05 14:34:43 2019 +0000
+++ b/Orbitersdk/D3D9Client/D3D9Client.cpp Tue Nov 05 18:02:28 2019 +0000
@@ -268,7 +268,7 @@
268268 hLblFont1 (NULL),
269269 hLblFont2 (NULL),
270270 hMainThread (NULL),
271- caps (),
271+ pCaps (NULL),
272272 parser (),
273273 hRenderWnd(),
274274 scene (),
@@ -452,7 +452,7 @@
452452 ReleaseDC(hRenderWnd, hWnd);
453453 ValidateRect(hRenderWnd, NULL); // avoids white flash after splash screen
454454
455- caps = pFramework->caps;
455+ pCaps = pFramework->GetCaps();
456456
457457 WriteLog("[3DDevice Initialized]");
458458
diff -r ad6a3a7570cb -r 34ff09c1e781 Orbitersdk/D3D9Client/D3D9Client.h
--- a/Orbitersdk/D3D9Client/D3D9Client.h Tue Nov 05 14:34:43 2019 +0000
+++ b/Orbitersdk/D3D9Client/D3D9Client.h Tue Nov 05 18:02:28 2019 +0000
@@ -22,10 +22,10 @@
2222 #include <d3dx9.h>
2323 #include "D3D9Catalog.h"
2424 #include "GraphicsAPI.h"
25-#include "D3D9util.h"
25+#include "D3D9Util.h"
2626 #include <stdio.h>
2727 #include <assert.h>
28-#include <OrbiterAPI.h>
28+#include "OrbiterAPI.h"
2929 #include "D3D9Frame.h"
3030 #include "nvapi.h"
3131 #include "gcConst.h"
@@ -1001,15 +1001,15 @@
10011001 LPDIRECT3DTEXTURE9 GetNoiseTex() const { return pNoiseTex; }
10021002 void EmergencyShutdown();
10031003 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)); }
10061006 const LPD3DXMATRIX GetIdentity() const { return (const LPD3DXMATRIX)&ident; }
10071007 HWND GetWindow();
1008- bool HasVertexTextureSupport() { return bVertexTex; }
1009- D3DCAPS9 * GetHardwareCaps() { return &caps; }
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; }
10131013 const void * GetConfigParam (DWORD paramtype) const;
10141014 bool RegisterRenderProc(__gcRenderProc proc, DWORD id, void *pParam = NULL);
10151015 bool RegisterGenericProc(__gcGenericProc proc, DWORD id, void *pParam = NULL);
@@ -1255,9 +1255,9 @@
12551255 LPDIRECT3DSURFACE9 pTextScreen;
12561256 LPDIRECT3DSURFACE9 pBackBuffer;
12571257 LPDIRECT3DSURFACE9 pDepthStencil;
1258- CD3DFramework9* pFramework;
1259- D3DCAPS9 caps;
1260- FileParser * parser;
1258+ CD3DFramework9 * pFramework;
1259+ const D3DCAPS9 * pCaps;
1260+ FileParser * parser;
12611261 std::string scenarioName;
12621262 HANDLE hMainThread;
12631263
diff -r ad6a3a7570cb -r 34ff09c1e781 Orbitersdk/D3D9Client/D3D9Frame.h
--- a/Orbitersdk/D3D9Client/D3D9Frame.h Tue Nov 05 14:34:43 2019 +0000
+++ b/Orbitersdk/D3D9Client/D3D9Frame.h Tue Nov 05 18:02:28 2019 +0000
@@ -43,33 +43,34 @@
4343 private:
4444
4545 // 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
7374
7475 // Internal functions for the framework class
7576
@@ -79,19 +80,14 @@
7980
8081 public:
8182
82- D3DPRESENT_PARAMETERS d3dPP;
83- D3DCAPS9 caps;
84-
8583 // Access functions for DirectX objects
8684 inline HWND GetRenderWindow() const { return hWnd; }
8785 inline LPDIRECT3D9 GetDirect3D() const { return pD3D; }
8886 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
9187 inline DWORD GetZBufferBitDepth() const { return dwZBufferBitDepth; }
9288 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
9591 inline const RECT GetScreenRect() const { return rcScreenRect; }
9692 inline LPDIRECT3DSURFACE9 GetBackBuffer() const { return pRenderTarget; }
9793 inline SURFHANDLE GetBackBufferHandle() const { return pBackBuffer; }
diff -r ad6a3a7570cb -r 34ff09c1e781 Orbitersdk/D3D9Client/D3D9Surface.cpp
--- a/Orbitersdk/D3D9Client/D3D9Surface.cpp Tue Nov 05 14:34:43 2019 +0000
+++ b/Orbitersdk/D3D9Client/D3D9Surface.cpp Tue Nov 05 18:02:28 2019 +0000
@@ -203,10 +203,10 @@
203203
204204 // -----------------------------------------------------------------------------------------------
205205 //
206-D3D9ClientSurface::D3D9ClientSurface(LPDIRECT3DDEVICE9 pDev, const char* name/*="???"*/)
206+D3D9ClientSurface::D3D9ClientSurface(LPDIRECT3DDEVICE9 pDev, const char* name_ /* = NULL */)
207207 {
208208 Clear();
209- strcpy_s(this->name, 64, (name ? name : "???"));
209+ strcpy_s(this->name, ARRAYSIZE(this->name), (name_ ? name_ : "???"));
210210 pDevice = pDev;
211211 SurfaceCatalog->Add(this);
212212 }
@@ -2079,4 +2079,4 @@
20792079 z+=4;
20802080 x+=6;
20812081 }
2082-}
\ No newline at end of file
2082+}
diff -r ad6a3a7570cb -r 34ff09c1e781 Orbitersdk/D3D9Client/D3D9Surface.h
--- a/Orbitersdk/D3D9Client/D3D9Surface.h Tue Nov 05 14:34:43 2019 +0000
+++ b/Orbitersdk/D3D9Client/D3D9Surface.h Tue Nov 05 18:02:28 2019 +0000
@@ -43,7 +43,7 @@
4343 static void GlobalExit();
4444
4545 // 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);
4747
4848 // Destroy the class and release the texture (pTex) if exists. Value of Reference counter doesn't matter.
4949 ~D3D9ClientSurface();
diff -r ad6a3a7570cb -r 34ff09c1e781 Orbitersdk/D3D9Client/Mesh.cpp
--- a/Orbitersdk/D3D9Client/Mesh.cpp Tue Nov 05 14:34:43 2019 +0000
+++ b/Orbitersdk/D3D9Client/Mesh.cpp Tue Nov 05 18:02:28 2019 +0000
@@ -152,7 +152,7 @@
152152 // Mesh Implementation
153153 // ======================================================================================
154154 //
155-void D3D9Mesh::Null()
155+void D3D9Mesh::Null(const char *meshName /* = NULL */)
156156 {
157157 nGrp = 0;
158158 Grp = NULL;
@@ -182,15 +182,15 @@
182182
183183 memset(Locals, 0, sizeof(LightStruct) * Config->MaxLights());
184184 memset(LightList, 0, sizeof(LightList));
185- strcpy_s(name, 128, "???");
185+ strcpy_s(this->name, ARRAYSIZE(this->name), meshName ? meshName : "???");
186186 }
187187
188188 // ===========================================================================================
189189 //
190-D3D9Mesh::D3D9Mesh(const char *name) : D3D9Effect()
190+D3D9Mesh::D3D9Mesh(const char *fname) : D3D9Effect()
191191 {
192- Null();
193- MESHHANDLE hMesh = oapiLoadMesh(name);
192+ Null(fname);
193+ MESHHANDLE hMesh = oapiLoadMesh(fname);
194194
195195 if (hMesh) {
196196 LoadMeshFromHandle(hMesh);
@@ -203,9 +203,9 @@
203203
204204 // ===========================================================================================
205205 //
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()
207207 {
208- Null();
208+ Null(meshName);
209209 LoadMeshFromHandle(hMesh, reorig, scale);
210210 bIsTemplate = asTemplate;
211211 MeshCatalog->Add(this);
@@ -303,7 +303,7 @@
303303
304304 if (nGrp == 0) return;
305305
306- strcpy_s(name, 128, hTemp.name);
306+ strcpy_s(name, ARRAYSIZE(name), hTemp.name);
307307
308308 // Use Template's Vertex Data directly, no need for a local copy unless locally modified.
309309 pBuf = hTemp.pBuf;
@@ -476,9 +476,9 @@
476476
477477 // ===========================================================================================
478478 //
479-void D3D9Mesh::SetName(const char *fname)
479+void D3D9Mesh::SetName(const char *name_)
480480 {
481- if (fname) strcpy_s(name,128,fname);
481+ if (name_) strcpy_s(this->name, ARRAYSIZE(this->name), name_);
482482 }
483483
484484 // ===========================================================================================
diff -r ad6a3a7570cb -r 34ff09c1e781 Orbitersdk/D3D9Client/Mesh.h
--- a/Orbitersdk/D3D9Client/Mesh.h Tue Nov 05 14:34:43 2019 +0000
+++ b/Orbitersdk/D3D9Client/Mesh.h Tue Nov 05 18:02:28 2019 +0000
@@ -73,7 +73,7 @@
7373 ~MeshBuffer();
7474
7575 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); }
7777 void MustRemap(DWORD mode);
7878
7979 LPDIRECT3DVERTEXBUFFER9 pVB;
@@ -144,10 +144,10 @@
144144 };
145145
146146
147- D3D9Mesh(const char *name);
147+ D3D9Mesh(const char *fname);
148148 D3D9Mesh(DWORD nGrp, const MESHGROUPEX **hGroup, const SURFHANDLE *hSurf);
149149 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);
151151 D3D9Mesh(MESHHANDLE hMesh, const D3D9Mesh &hTemp);
152152 ~D3D9Mesh();
153153
@@ -279,7 +279,7 @@
279279 void ProcessInherit();
280280 bool CopyVertices(GROUPREC *grp, const MESHGROUPEX *mg, D3DXVECTOR3 *reorig = NULL, float *scale = NULL);
281281 void SetGroupRec(DWORD i, const MESHGROUPEX *mg);
282- void Null();
282+ void Null(const char *meshName = NULL);
283283
284284
285285 DWORD MaxVert;
diff -r ad6a3a7570cb -r 34ff09c1e781 Orbitersdk/D3D9Client/RingMgr.cpp
--- a/Orbitersdk/D3D9Client/RingMgr.cpp Tue Nov 05 14:34:43 2019 +0000
+++ b/Orbitersdk/D3D9Client/RingMgr.cpp Tue Nov 05 18:02:28 2019 +0000
@@ -72,7 +72,7 @@
7272
7373 LPDIRECT3DDEVICE9 pDev = gc->GetDevice();
7474
75- D3DCAPS9 *caps = gc->GetHardwareCaps();
75+ const D3DCAPS9 *caps = gc->GetHardwareCaps();
7676
7777 int size = max(min(caps->MaxTextureWidth, 8192), 2048);
7878
diff -r ad6a3a7570cb -r 34ff09c1e781 Orbitersdk/D3D9Client/VPlanet.cpp
--- a/Orbitersdk/D3D9Client/VPlanet.cpp Tue Nov 05 14:34:43 2019 +0000
+++ b/Orbitersdk/D3D9Client/VPlanet.cpp Tue Nov 05 18:02:28 2019 +0000
@@ -175,7 +175,7 @@
175175 if (hMesh) {
176176 LogAlw("Loading mesh [%s] for planetary body '%s'", cbuf, name);
177177 float fSize = float(size);
178- mesh = new D3D9Mesh(hMesh, false, NULL, &fSize);
178+ mesh = new D3D9Mesh(hMesh, false, NULL, &fSize, cbuf);
179179 oapiDeleteMesh (hMesh);
180180 }
181181 }
Show on old repository browser