Skip to content

Commit

Permalink
Merge branch 'xd_dev' into linux-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY authored Oct 10, 2018
2 parents 6357979 + 523f754 commit a7f2240
Show file tree
Hide file tree
Showing 30 changed files with 351 additions and 256 deletions.
18 changes: 9 additions & 9 deletions src/Layers/xrRender/FVisual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ void Fvisual::Load(const char* N, IReader* data, u32 dwFlags)
p_rm_Indices->AddRef();
#endif
#endif
#if (RENDER == R_R2) || (RENDER == R_R3) || (RENDER == R_R4) || (RENDER == R_GL)
// check for fast-vertices
#if RENDER == R_R1
if (data->find_chunk(OGF_FASTPATH) && ps_r1_force_geomx)
#else
if (data->find_chunk(OGF_FASTPATH))
#endif
{
destructor<IReader> geomdef(data->open_chunk(OGF_FASTPATH));
destructor<IReader> def(geomdef().open_chunk(OGF_GCONTAINER));
Expand Down Expand Up @@ -97,7 +100,6 @@ void Fvisual::Load(const char* N, IReader* data, u32 dwFlags)
// geom
m_fast->rm_geom.create(fmt, m_fast->p_rm_Vertices, m_fast->p_rm_Indices);
}
#endif // (RENDER==R_R2) || (RENDER==R_R3) || (RENDER==R_R4) || (RENDER==R_GL)
}

// read vertices
Expand Down Expand Up @@ -222,8 +224,11 @@ void Fvisual::Load(const char* N, IReader* data, u32 dwFlags)

void Fvisual::Render(float)
{
#if (RENDER == R_R2) || (RENDER == R_R3) || (RENDER == R_R4) || (RENDER==R_GL)
if (m_fast && RImplementation.phase == CRender::PHASE_SMAP && !RCache.is_TessEnabled())
#if RENDER == R_R1
if (m_fast && ps_r1_force_geomx)
#else
if (m_fast && (ps_r1_force_geomx || RImplementation.phase == CRender::PHASE_SMAP && !RCache.is_TessEnabled()))
#endif
{
RCache.set_Geometry(m_fast->rm_geom);
RCache.Render(D3DPT_TRIANGLELIST, m_fast->vBase, 0, m_fast->vCount, m_fast->iBase, m_fast->dwPrimitives);
Expand All @@ -235,11 +240,6 @@ void Fvisual::Render(float)
RCache.Render(D3DPT_TRIANGLELIST, vBase, 0, vCount, iBase, dwPrimitives);
RCache.stat.r.s_static.add(vCount);
}
#else // (RENDER==R_R2) || (RENDER==R_R3) || (RENDER==R_R4) || (RENDER==R_GL)
RCache.set_Geometry(rm_geom);
RCache.Render(D3DPT_TRIANGLELIST, vBase, 0, vCount, iBase, dwPrimitives);
RCache.stat.r.s_static.add(vCount);
#endif // (RENDER==R_R2) || (RENDER==R_R3) || (RENDER==R_R4) || (RENDER==R_GL)
}

#define PCOPY(a) a = pFrom->a
Expand Down
71 changes: 24 additions & 47 deletions src/Layers/xrRender/HW.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,20 @@ class CHW
BOOL support(D3DFORMAT fmt, DWORD type, DWORD usage);
#endif // !USE_OGL

#ifdef DEBUG
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
void Validate(void){};
#else // USE_DX10
void Validate(void)
#if defined(DEBUG) && defined(USE_DX9)
void Validate()
{
VERIFY(pDevice);
VERIFY(pD3D);
};
#endif // USE_DX10
#else
void Validate(void){};
void Validate() {}
#endif

// Variables section
// Variables section
public:
CHWCaps Caps;

#if defined(USE_OGL)
CHW* pDevice;
CHW* pContext;
Expand All @@ -63,62 +62,40 @@ class CHW
GLuint pFB;
GLuint pCFB;

CHWCaps Caps;

SDL_Window* m_hWnd;
HDC m_hDC;
SDL_GLContext m_hRC;
#elif defined(USE_DX11)
public:
IDXGIFactory1* m_pFactory = nullptr;
IDXGIAdapter1* m_pAdapter = nullptr; // pD3D equivalent
ID3D11Device* pDevice = nullptr; // combine with DX9 pDevice via typedef
ID3D11DeviceContext* pContext = nullptr; // combine with DX9 pDevice via typedef
IDXGISwapChain* m_pSwapChain = nullptr;
ID3D11RenderTargetView* pBaseRT = nullptr; // combine with DX9 pBaseRT via typedef
ID3D11DepthStencilView* pBaseZB = nullptr;

CHWCaps Caps;
#else // General DirectX
ID3DDevice* pDevice = nullptr; // render device
ID3DRenderTargetView* pBaseRT = nullptr; // base render target
ID3DDepthStencilView* pBaseZB = nullptr; // base depth-stencil buffer

D3D_DRIVER_TYPE m_DriverType;
DXGI_SWAP_CHAIN_DESC m_ChainDesc; // DevPP equivalent
D3D_FEATURE_LEVEL FeatureLevel;
#elif defined(USE_DX10)
public:
#ifndef USE_DX9
IDXGIFactory1* m_pFactory = nullptr;
IDXGIAdapter1* m_pAdapter = nullptr; // pD3D equivalent
ID3D10Device1* pDevice1 = nullptr; // combine with DX9 pDevice via typedef
ID3D10Device* pDevice = nullptr; // combine with DX9 pDevice via typedef
ID3D10Device1* pContext1 = nullptr; // combine with DX9 pDevice via typedef
ID3D10Device* pContext = nullptr; // combine with DX9 pDevice via typedef
IDXGIAdapter1* m_pAdapter = nullptr; // pD3D equivalent
ID3DDeviceContext* pContext = nullptr;
IDXGISwapChain* m_pSwapChain = nullptr;
ID3D10RenderTargetView* pBaseRT = nullptr; // combine with DX9 pBaseRT via typedef
ID3D10DepthStencilView* pBaseZB = nullptr;

CHWCaps Caps;

D3D10_DRIVER_TYPE m_DriverType;
DXGI_SWAP_CHAIN_DESC m_ChainDesc; // DevPP equivalent
DXGI_SWAP_CHAIN_DESC m_ChainDesc; // DevPP equivalent
D3D_FEATURE_LEVEL FeatureLevel;
#else
private:
#if defined(USE_DX10)
ID3D10Device1* pDevice1 = nullptr;
ID3D10Device1* pContext1 = nullptr;
#endif
#else // USE_DX9
#ifdef DEBUG
IDirect3DStateBlock9* dwDebugSB = nullptr;
#endif
private:
XRay::Module hD3D = nullptr;

public:
IDirect3D9* pD3D = nullptr; // D3D
IDirect3DDevice9* pDevice = nullptr; // render device
IDirect3DSurface9* pBaseRT = nullptr;
IDirect3DSurface9* pBaseZB = nullptr;

CHWCaps Caps;

UINT DevAdapter;
D3DDEVTYPE m_DriverType;
D3DPRESENT_PARAMETERS DevPP;
#endif // USE_DX10
#endif // USE_DX9
#endif // USE_OGL

#if !defined(_MAYA_EXPORT) && !defined(USE_OGL)
stats_manager stats_manager;
Expand All @@ -128,7 +105,7 @@ class CHW
void UpdateViews();
#endif
#if defined(USE_DX10) || defined(USE_DX11)
bool CheckFormatSupport(DXGI_FORMAT format, D3D_FORMAT_SUPPORT feature) const;
bool CheckFormatSupport(DXGI_FORMAT format, UINT feature) const;
DXGI_FORMAT SelectFormat(D3D_FORMAT_SUPPORT feature, const DXGI_FORMAT formats[], size_t count) const;
virtual void OnAppActivate();
virtual void OnAppDeactivate();
Expand Down
7 changes: 2 additions & 5 deletions src/Layers/xrRender/LightTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,8 @@ void CROS_impl::update_smooth(IRenderable* O)

void CROS_impl::calc_sun_value(Fvector& position, IGameObject* _object)
{
#if RENDER == R_R1
light* sun = (light*)RImplementation.L_DB->sun._get();
#else
light* sun = (light*)RImplementation.Lights.sun._get();
#endif

if (MODE & IRender_ObjectSpecific::TRACE_SUN)
{
if (--result_sun < 0)
Expand Down Expand Up @@ -530,7 +527,7 @@ void CROS_impl::prepare_lights(Fvector& position, IRenderable* O)
}

#if RENDER == R_R1
light* sun = (light*)RImplementation.L_DB->sun._get();
light* sun = (light*)RImplementation.Lights.sun._get();

// Sun
float E = sun_smooth * sun->color.intensity();
Expand Down
4 changes: 2 additions & 2 deletions src/Layers/xrRender/ResourceManager_Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ void CResourceManager::DBG_VerifyGeoms()
*/
}

SGeometry* CResourceManager::CreateGeom(D3DVERTEXELEMENT9* decl, IDirect3DVertexBuffer9* vb, IDirect3DIndexBuffer9* ib)
SGeometry* CResourceManager::CreateGeom(D3DVERTEXELEMENT9* decl, ID3DVertexBuffer* vb, ID3DIndexBuffer* ib)
{
R_ASSERT(decl && vb);

Expand All @@ -310,7 +310,7 @@ SGeometry* CResourceManager::CreateGeom(D3DVERTEXELEMENT9* decl, IDirect3DVertex
v_geoms.push_back(Geom);
return Geom;
}
SGeometry* CResourceManager::CreateGeom(u32 FVF, IDirect3DVertexBuffer9* vb, IDirect3DIndexBuffer9* ib)
SGeometry* CResourceManager::CreateGeom(u32 FVF, ID3DVertexBuffer* vb, ID3DIndexBuffer* ib)
{
D3DVERTEXELEMENT9 dcl[MAX_FVF_DECL_SIZE];
CHK_DX(D3DXDeclaratorFromFVF(FVF, dcl));
Expand Down
42 changes: 24 additions & 18 deletions src/Layers/xrRender/r__sector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,47 @@ void CPortal::OnRender()
VERIFY(poly.size());
// draw rect
static xr_vector<FVF::L> V;
V.resize(poly.size() + 2);
Fvector C = {0, 0, 0};
for (u32 k = 0; k < poly.size(); k++)
V.resize(poly.size()*3);
Fvector vCenter = { 0.0f, 0.0f, 0.0f };
static u32 portalColor = 0x800000FF;
for (u32 k = 0; k < poly.size(); ++k)
{
C.add(poly[k]);
V[k + 1].set(poly[k], 0x800000FF);
vCenter.add(poly[k]);
V[k * 3 + 1].set(poly[k], portalColor);

if (k + 1 == poly.size())
V[k * 3 + 2].set(poly[0], portalColor);
else
V[k * 3 + 2].set(poly[k + 1], portalColor);
}
V.back().set(poly[0], 0x800000FF);
C.div((float)poly.size());
V[0].set(C, 0x800000FF);

vCenter.div((float)poly.size());

for (u32 k = 0; k < poly.size(); ++k)
V[k * 3].set(vCenter, portalColor);

RCache.set_xform_world(Fidentity);
// draw solid
RCache.set_Shader(RImplementation.m_SelectionShader);
RCache.dbg_Draw(D3DPT_TRIANGLEFAN, &*V.begin(), V.size() - 2);
RCache.dbg_Draw(D3DPT_TRIANGLELIST, &*V.begin(), V.size() / 3);

// draw wire
V.resize(poly.size()+1); // SkyLoader: change vertex array for wire
for (u32 k = 0; k < poly.size(); ++k)
V[k].set(poly[k], portalColor);
V.back().set(poly[0], portalColor);

if (bDebug)
{
RImplementation.rmNear();
}
else
{
Device.SetNearer(TRUE);
}

RCache.set_Shader(RImplementation.m_WireShader);
RCache.dbg_Draw(D3DPT_LINESTRIP, &*(V.begin() + 1), V.size() - 2);
RCache.dbg_Draw(D3DPT_LINESTRIP, &*V.begin(), V.size() - 1);
if (bDebug)
{
RImplementation.rmNormal();
}
else
{
Device.SetNearer(FALSE);
}
}
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/Layers/xrRender/xrD3DDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ typedef IDirect3DVertexShader9 ID3DVertexShader;
typedef IDirect3DPixelShader9 ID3DPixelShader;
typedef ID3DXBuffer ID3DBlob;
typedef D3DXMACRO D3D_SHADER_MACRO;
typedef D3DDEVTYPE D3D_DRIVER_TYPE;
typedef IDirect3DQuery9 ID3DQuery;
typedef D3DVIEWPORT9 D3D_VIEWPORT;
typedef ID3DXInclude ID3DInclude;
typedef IDirect3DTexture9 ID3DTexture2D;
typedef IDirect3DSurface9 ID3DRenderTargetView;
typedef IDirect3DSurface9 ID3DDepthStencilView;
typedef IDirect3DDevice9 ID3DDevice;
typedef IDirect3DBaseTexture9 ID3DBaseTexture;
typedef D3DSURFACE_DESC D3D_TEXTURE2D_DESC;
typedef IDirect3DVertexBuffer9 ID3DVertexBuffer;
Expand Down
2 changes: 2 additions & 0 deletions src/Layers/xrRender/xrRender_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ float ps_r1_lmodel_lerp = 0.1f;
float ps_r1_dlights_clip = 40.f;
float ps_r1_pps_u = 0.f;
float ps_r1_pps_v = 0.f;
int ps_r1_force_geomx = 0;

// R1-specific
int ps_r1_GlowsPerFrame = 16; // r1-only
Expand Down Expand Up @@ -752,6 +753,7 @@ void xrRender_initconsole()
CMD4(CCC_Float, "r1_dlights_clip", &ps_r1_dlights_clip, 10.f, 150.f);
CMD4(CCC_Float, "r1_pps_u", &ps_r1_pps_u, -1.f, +1.f);
CMD4(CCC_Float, "r1_pps_v", &ps_r1_pps_v, -1.f, +1.f);
CMD4(CCC_Integer, "r1_force_geomx", &ps_r1_force_geomx, 0, 1);

// R1-specific
CMD4(CCC_Integer, "r1_glows_per_frame", &ps_r1_GlowsPerFrame, 2, 32);
Expand Down
1 change: 1 addition & 0 deletions src/Layers/xrRender/xrRender_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ extern ECORE_API float ps_r1_lmodel_lerp;
extern ECORE_API float ps_r1_dlights_clip;
extern ECORE_API float ps_r1_pps_u;
extern ECORE_API float ps_r1_pps_v;
extern ECORE_API int ps_r1_force_geomx;

// R1-specific
extern ECORE_API int ps_r1_GlowsPerFrame; // r1-only
Expand Down
5 changes: 5 additions & 0 deletions src/Layers/xrRenderDX10/DXCommonTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ typedef ID3D11DeviceContext ID3DDeviceContext;
#define D3D_FILL_WIREFRAME D3D11_FILL_WIREFRAME

#define D3D_FORMAT_SUPPORT D3D11_FORMAT_SUPPORT
#define D3D_FORMAT_SUPPORT_TEXTURE2D D3D11_FORMAT_SUPPORT_TEXTURE2D
#define D3D_FORMAT_SUPPORT_RENDER_TARGET D3D11_FORMAT_SUPPORT_RENDER_TARGET
#define D3D_FORMAT_SUPPORT_DEPTH_STENCIL D3D11_FORMAT_SUPPORT_DEPTH_STENCIL
#define D3D_FORMAT_SUPPORT_DISPLAY D3D11_FORMAT_SUPPORT_DISPLAY

Expand Down Expand Up @@ -328,6 +330,7 @@ typedef ID3D10Resource ID3DResource;

#define D3D_STANDARD_MULTISAMPLE_PATTERN D3D10_STANDARD_MULTISAMPLE_PATTERN

#define D3D_DRIVER_TYPE D3D10_DRIVER_TYPE // There IS already type named D3D_DRIVER_TYPE!!! Fix it later if we would need it
#define D3D_DRIVER_TYPE_REFERENCE D3D10_DRIVER_TYPE_REFERENCE
#define D3D_DRIVER_TYPE_HARDWARE D3D10_DRIVER_TYPE_HARDWARE

Expand Down Expand Up @@ -410,6 +413,8 @@ typedef ID3D10Resource ID3DResource;
#define D3D_FILL_WIREFRAME D3D10_FILL_WIREFRAME

#define D3D_FORMAT_SUPPORT D3D10_FORMAT_SUPPORT
#define D3D_FORMAT_SUPPORT_TEXTURE2D D3D10_FORMAT_SUPPORT_TEXTURE2D
#define D3D_FORMAT_SUPPORT_RENDER_TARGET D3D10_FORMAT_SUPPORT_RENDER_TARGET
#define D3D_FORMAT_SUPPORT_DEPTH_STENCIL D3D10_FORMAT_SUPPORT_DEPTH_STENCIL
#define D3D_FORMAT_SUPPORT_DISPLAY D3D10_FORMAT_SUPPORT_DISPLAY

Expand Down
26 changes: 15 additions & 11 deletions src/Layers/xrRenderDX10/dx10HW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ void CHW::CreateDevice(SDL_Window* m_sdlWnd)
// TODO: DX10: implement dynamic format selection
constexpr DXGI_FORMAT formats[] =
{
//DXGI_FORMAT_R16G16B16A16_FLOAT,
//DXGI_FORMAT_R10G10B10A2_UNORM,
//DXGI_FORMAT_B8G8R8X8_UNORM,
//DXGI_FORMAT_R16G16B16A16_FLOAT, // Do we even need this?
//DXGI_FORMAT_R10G10B10A2_UNORM, // D3DX11SaveTextureToMemory fails on this format
DXGI_FORMAT_B8G8R8X8_UNORM,
DXGI_FORMAT_R8G8B8A8_UNORM,
};

Expand Down Expand Up @@ -260,11 +260,16 @@ void CHW::Reset()
UpdateViews();
}

bool CHW::CheckFormatSupport(const DXGI_FORMAT format, const D3D_FORMAT_SUPPORT feature) const
bool CHW::CheckFormatSupport(const DXGI_FORMAT format, const UINT feature) const
{
UINT feature_bit = feature;
if (SUCCEEDED(pDevice->CheckFormatSupport(format, &feature_bit)))
return true;
UINT supports;

if (SUCCEEDED(pDevice->CheckFormatSupport(format, &supports)))
{
if (supports & feature)
return true;
}

return false;
}

Expand Down Expand Up @@ -314,13 +319,12 @@ void CHW::UpdateViews()
descDepth.ArraySize = 1;

// Select depth-stencil format
// TODO: DX10: test and support other formats
constexpr DXGI_FORMAT formats[] =
{
//DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
DXGI_FORMAT_D24_UNORM_S8_UINT,
//DXGI_FORMAT_D32_FLOAT,
//DXGI_FORMAT_D16_UNORM
DXGI_FORMAT_D32_FLOAT,
DXGI_FORMAT_D16_UNORM
};
descDepth.Format = SelectFormat(D3D_FORMAT_SUPPORT_DEPTH_STENCIL, formats, std::size(formats));
Caps.fDepth = dx10TextureUtils::ConvertTextureFormat(descDepth.Format);
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRenderDX10/dx10R_Backend_Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ ICF void CBackend::set_Vertices(ID3DVertexBuffer* _vb, u32 _vb_stride)
vb_stride = _vb_stride;
// CHK_DX (HW.pDevice->SetStreamSource(0,vb,0,vb_stride));
// UINT StreamNumber,
// IDirect3DVertexBuffer9 * pStreamData,
// ID3DVertexBuffer * pStreamData,
// UINT OffsetInBytes,
// UINT Stride

Expand Down
Loading

0 comments on commit a7f2240

Please sign in to comment.