Subversion Repository Public Repository

Divide-Dependencies

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// TAGRELEASE: PUBLIC
#include <assert.h>

// Direct3D9 includes
#include <d3d9.h>

// Direct3D11 includes
#include <d3dcommon.h>
#include <dxgi.h>
#include <d3d11.h>
#include <d3dcompiler.h>

// XInput includes
#include <xinput.h>

#ifndef V
#define V(x)           { hr = (x); }
#endif
#ifndef V_RETURN
#define V_RETURN(x)    { hr = (x); if( FAILED(hr) ) { return hr; } }
#endif

#ifndef SAFE_DELETE
#define SAFE_DELETE(p)       { if (p) { delete (p);     (p)=NULL; } }
#endif
#ifndef SAFE_DELETE_ARRAY
#define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p);   (p)=NULL; } }
#endif
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(p)      { if (p) { (p)->Release(); (p)=NULL; } }
#endif


#include "strsafe.h"
#include <string>

#include "NvSimpleRawMesh.h"
#include "NvSimpleMesh.h"
#include "NvSimpleMeshLoader.h"

NvSimpleMesh::NvSimpleMesh() :
    iNumVertices(0),
    iNumIndices(0),
    IndexFormat(DXGI_FORMAT_R16_UINT),
    VertexStride(0),
    pVB(NULL),
    pIB(NULL),
    pDiffuseTexture(NULL),
    pDiffuseSRV(NULL),
    pNormalsTexture(NULL),
    pNormalsSRV(NULL),
    pInputLayout(NULL)
{
    memset(szName,0,260);
}

inline ID3D11ShaderResourceView * UtilCreateTexture2DSRV(ID3D11Device *pd3dDevice,ID3D11Texture2D *pTex)
{
    HRESULT hr;
    ID3D11ShaderResourceView *pSRV = NULL;

    D3D11_TEXTURE2D_DESC TexDesc;
    ((ID3D11Texture2D*)pTex)->GetDesc(&TexDesc);

    D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc;
    ::ZeroMemory(&SRVDesc,sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC));
    SRVDesc.Texture2D.MipLevels = TexDesc.MipLevels;
    SRVDesc.Texture2D.MostDetailedMip = 0;
    SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
    SRVDesc.Format = TexDesc.Format;

    hr = pd3dDevice->CreateShaderResourceView(pTex,&SRVDesc,&pSRV);

    return pSRV;
}

HRESULT NvSimpleMesh::Initialize(ID3D11Device *pd3dDevice,NvSimpleRawMesh *pRawMesh)
{
    HRESULT hr = S_OK;
    
    if(pRawMesh)
    {
        memcpy(&Extents,pRawMesh->GetExtents(),3*sizeof(float));
        memcpy(&Center,pRawMesh->GetCenter(),3*sizeof(float));

        // Copy out d3d buffers and data for rendering and add references input mesh can be cleaned.
        pVB = pRawMesh->CreateD3D11VertexBufferFor(pd3dDevice);
        pIB = pRawMesh->CreateD3D11IndexBufferFor(pd3dDevice);
        IndexFormat = pRawMesh->GetIndexSize()==2?DXGI_FORMAT_R16_UINT:DXGI_FORMAT_R32_UINT;
        iNumIndices = pRawMesh->GetNumIndices();
        iNumVertices = pRawMesh->GetNumVertices();
        VertexStride = pRawMesh->GetVertexStride();

        // Make a texture object and SRV for it.
        pDiffuseTexture = pRawMesh->CreateD3D11DiffuseTextureFor(pd3dDevice);
        if(pDiffuseTexture)
            pDiffuseSRV = UtilCreateTexture2DSRV(pd3dDevice,pDiffuseTexture);
        pNormalsTexture = pRawMesh->CreateD3D11NormalsTextureFor(pd3dDevice);
        if(pNormalsTexture)
            pNormalsSRV = UtilCreateTexture2DSRV(pd3dDevice,pNormalsTexture);
    }

    return hr;
}

HRESULT NvSimpleMesh::InitializeWithInputLayout(ID3D11Device *pd3dDevice,NvSimpleRawMesh *pRawMesh,BYTE*pIAsig, SIZE_T pIAsigSize)
{
    HRESULT hr = S_OK;
    V_RETURN(CreateInputLayout(pd3dDevice,pIAsig,pIAsigSize));
    V_RETURN(Initialize(pd3dDevice,pRawMesh));
    return hr;
}

HRESULT NvSimpleMesh::CreateInputLayout(ID3D11Device *pd3dDevice,BYTE*pIAsig, SIZE_T pIAsigSize)
{
    HRESULT hr = S_OK;
    SAFE_RELEASE(pInputLayout);
    V_RETURN( pd3dDevice->CreateInputLayout( NvSimpleRawMesh::D3D11InputElements, NvSimpleRawMesh::D3D11ElementsSize, pIAsig, pIAsigSize, &pInputLayout ) );
    return hr;
}

void NvSimpleMesh::Release()
{
    SAFE_RELEASE(pVB);
    SAFE_RELEASE(pIB);
    SAFE_RELEASE(pDiffuseTexture);
    SAFE_RELEASE(pDiffuseSRV);
    SAFE_RELEASE(pNormalsTexture);
    SAFE_RELEASE(pNormalsSRV);
    SAFE_RELEASE(pInputLayout);
}

void NvSimpleMesh::SetupDraw(ID3D11DeviceContext *pd3dContext, int iDiffuseTexSlot, int iNormalsTexSlot)
{
    if(iDiffuseTexSlot >= 0)
        pd3dContext->PSSetShaderResources(iDiffuseTexSlot,1,&pDiffuseSRV);
    if(iNormalsTexSlot >= 0)
        pd3dContext->PSSetShaderResources(iNormalsTexSlot,1,&pNormalsSRV);

    D3D11_PRIMITIVE_TOPOLOGY topology = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;

    UINT Offsets[1];
    UINT Strides[1];
    ID3D11Buffer *ppVB[1];
    Offsets[0] = 0;
    Strides[0] = VertexStride;
    ppVB[0] = pVB;

    if(pInputLayout)    // optionally set an input layout if we have one
        pd3dContext->IASetInputLayout(pInputLayout);
    pd3dContext->IASetVertexBuffers(0,1,ppVB,Strides,Offsets);
    pd3dContext->IASetIndexBuffer( pIB,IndexFormat, 0 );
    pd3dContext->IASetPrimitiveTopology(topology);
}

void NvSimpleMesh::Draw(ID3D11DeviceContext *pd3dContext)
{
    if(!pVB) 
    {
        return;
    }

    pd3dContext->DrawIndexed(iNumIndices,0,0);
}


void NvSimpleMesh::DrawInstanced(ID3D11DeviceContext *pd3dContext, int iNumInstances)
{
    pd3dContext->DrawIndexedInstanced(iNumIndices,iNumInstances,0,0,0);
}

NvAggregateSimpleMesh::NvAggregateSimpleMesh()
{
    pSimpleMeshes = NULL;
    NumSimpleMeshes = 0;
}

NvAggregateSimpleMesh::~NvAggregateSimpleMesh()
{
    SAFE_DELETE_ARRAY(pSimpleMeshes);
}

HRESULT NvAggregateSimpleMesh::Initialize(ID3D11Device *pd3dDevice,NvSimpleMeshLoader *pMeshLoader)
{
    HRESULT hr = S_OK;
    if(pMeshLoader->pMeshes == NULL) return E_FAIL;
    NumSimpleMeshes = pMeshLoader->NumMeshes;
    pSimpleMeshes = new NvSimpleMesh[NumSimpleMeshes];
    for(int iMesh=0;iMesh<NumSimpleMeshes;iMesh++)
    {
        V_RETURN(pSimpleMeshes[iMesh].Initialize(pd3dDevice,&pMeshLoader->pMeshes[iMesh]));
    }
    return hr;
}
HRESULT NvAggregateSimpleMesh::InitializeWithInputLayout(ID3D11Device *pd3dDevice,NvSimpleMeshLoader *pMeshLoader,BYTE*pIAsig, SIZE_T pIAsigSize)
{
    HRESULT hr = S_OK;
    if(pMeshLoader->pMeshes == NULL) return E_FAIL;
    NumSimpleMeshes = pMeshLoader->NumMeshes;
    pSimpleMeshes = new NvSimpleMesh[NumSimpleMeshes];
    for(int iMesh=0;iMesh<NumSimpleMeshes;iMesh++)
    {
        V_RETURN(pSimpleMeshes[iMesh].InitializeWithInputLayout(pd3dDevice,&pMeshLoader->pMeshes[iMesh],pIAsig,pIAsigSize));
    }
    return hr;
}

void NvAggregateSimpleMesh::Release()
{
    if(pSimpleMeshes == NULL) return;
    for(int iMesh=0;iMesh<NumSimpleMeshes;iMesh++)
    {
        pSimpleMeshes[iMesh].Release();
    }
}

void NvAggregateSimpleMesh::Draw(ID3D11DeviceContext *pd3dContext, int iDiffuseTexSlot, int iNormalsTexSlot)
{
    if(pSimpleMeshes == NULL) return;
    for(int iMesh=0;iMesh<NumSimpleMeshes;iMesh++)
    {
        pSimpleMeshes[iMesh].SetupDraw(pd3dContext,iDiffuseTexSlot,iNormalsTexSlot);
        pSimpleMeshes[iMesh].Draw(pd3dContext);
    }
}

Commits for Divide-Dependencies/physx/APEX_1.4/externals/extensions/src/nvsimplemesh/NvSimpleMesh.cpp

Diff revisions: vs.
Revision Author Commited Message
105 IonutCava picture IonutCava Tue 16 Apr, 2019 19:55:41 +0000

Forgot to actually add physx