~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/bullet/src/BulletMultiThreaded/GpuSoftBodySolvers/DX11/btSoftBodySolver_DX11.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Bullet Continuous Collision Detection and Physics Library
 
3
Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
 
4
 
 
5
This software is provided 'as-is', without any express or implied warranty.
 
6
In no event will the authors be held liable for any damages arising from the use of this software.
 
7
Permission is granted to anyone to use this software for any purpose, 
 
8
including commercial applications, and to alter it and redistribute it freely, 
 
9
subject to the following restrictions:
 
10
 
 
11
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
 
12
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
 
13
3. This notice may not be removed or altered from any source distribution.
 
14
*/
 
15
 
 
16
#ifndef BT_ACCELERATED_SOFT_BODY_DX11_SOLVER_H
 
17
#define BT_ACCELERATED_SOFT_BODY_DX11_SOLVER_H
 
18
 
 
19
 
 
20
#include "vectormath/vmInclude.h"
 
21
#include "BulletSoftBody/btSoftBodySolvers.h"
 
22
#include "btSoftBodySolverVertexBuffer_DX11.h"
 
23
#include "btSoftBodySolverLinkData_DX11.h"
 
24
#include "btSoftBodySolverVertexData_DX11.h"
 
25
#include "btSoftBodySolverTriangleData_DX11.h"
 
26
 
 
27
 
 
28
 
 
29
class DXFunctions
 
30
{
 
31
public:
 
32
        
 
33
        typedef HRESULT (WINAPI * CompileFromMemoryFunc)(LPCSTR,SIZE_T,LPCSTR,const D3D10_SHADER_MACRO*,LPD3D10INCLUDE,LPCSTR,LPCSTR,UINT,UINT,ID3DX11ThreadPump*,ID3D10Blob**,ID3D10Blob**,HRESULT*);
 
34
 
 
35
        ID3D11Device *           m_dx11Device;
 
36
        ID3D11DeviceContext* m_dx11Context;
 
37
        CompileFromMemoryFunc m_dx11CompileFromMemory;
 
38
 
 
39
        DXFunctions(ID3D11Device *dx11Device, ID3D11DeviceContext* dx11Context, CompileFromMemoryFunc dx11CompileFromMemory) :
 
40
                m_dx11Device( dx11Device ),
 
41
                m_dx11Context( dx11Context ),
 
42
                m_dx11CompileFromMemory( dx11CompileFromMemory )
 
43
        {
 
44
 
 
45
        }
 
46
 
 
47
        class KernelDesc
 
48
        {
 
49
        protected:
 
50
                
 
51
 
 
52
        public:
 
53
                ID3D11ComputeShader* kernel;
 
54
                ID3D11Buffer* constBuffer;
 
55
 
 
56
                KernelDesc()
 
57
                {
 
58
                        kernel = 0;
 
59
                        constBuffer = 0;
 
60
                }
 
61
 
 
62
                virtual ~KernelDesc()
 
63
                {
 
64
                        // TODO: this should probably destroy its kernel but we need to be careful
 
65
                        // in case KernelDescs are copied
 
66
                }
 
67
        }; 
 
68
 
 
69
        /**
 
70
         * Compile a compute shader kernel from a string and return the appropriate KernelDesc object.
 
71
         */
 
72
        KernelDesc compileComputeShaderFromString( const char* shaderString, const char* shaderName, int constBufferSize, D3D10_SHADER_MACRO *compileMacros = 0 );
 
73
 
 
74
};
 
75
 
 
76
class btDX11SoftBodySolver : public btSoftBodySolver
 
77
{
 
78
protected:
 
79
        /**
 
80
         * Entry in the collision shape array.
 
81
         * Specifies the shape type, the transform matrix and the necessary details of the collisionShape.
 
82
         */
 
83
        struct CollisionShapeDescription
 
84
        {
 
85
                Vectormath::Aos::Transform3 shapeTransform;
 
86
                Vectormath::Aos::Vector3 linearVelocity;
 
87
                Vectormath::Aos::Vector3 angularVelocity;
 
88
 
 
89
                int softBodyIdentifier;
 
90
                int collisionShapeType;
 
91
        
 
92
                // Both needed for capsule
 
93
                float radius;
 
94
                float halfHeight;
 
95
                
 
96
                float margin;
 
97
                float friction;
 
98
 
 
99
                CollisionShapeDescription()
 
100
                {
 
101
                        collisionShapeType = 0;
 
102
                        margin = 0;
 
103
                        friction = 0;
 
104
                }
 
105
        };
 
106
 
 
107
        struct UIntVector3
 
108
        {
 
109
                UIntVector3()
 
110
                {
 
111
                        x = 0;
 
112
                        y = 0;
 
113
                        z = 0;
 
114
                        _padding = 0;
 
115
                }
 
116
                
 
117
                UIntVector3( unsigned int x_, unsigned int y_, unsigned int z_ )
 
118
                {
 
119
                        x = x_;
 
120
                        y = y_;
 
121
                        z = z_;
 
122
                        _padding = 0;
 
123
                }
 
124
                        
 
125
                unsigned int x;
 
126
                unsigned int y;
 
127
                unsigned int z;
 
128
                unsigned int _padding;
 
129
        };
 
130
 
 
131
 
 
132
 
 
133
public:
 
134
        /**
 
135
         * SoftBody class to maintain information about a soft body instance
 
136
         * within a solver.
 
137
         * This data addresses the main solver arrays.
 
138
         */
 
139
        class btAcceleratedSoftBodyInterface
 
140
        {
 
141
        protected:
 
142
                /** Current number of vertices that are part of this cloth */
 
143
                int m_numVertices;
 
144
                /** Maximum number of vertices allocated to be part of this cloth */
 
145
                int m_maxVertices;
 
146
                /** Current number of triangles that are part of this cloth */
 
147
                int m_numTriangles;
 
148
                /** Maximum number of triangles allocated to be part of this cloth */
 
149
                int m_maxTriangles;
 
150
                /** Index of first vertex in the world allocated to this cloth */
 
151
                int m_firstVertex;
 
152
                /** Index of first triangle in the world allocated to this cloth */
 
153
                int m_firstTriangle;
 
154
                /** Index of first link in the world allocated to this cloth */
 
155
                int m_firstLink;
 
156
                /** Maximum number of links allocated to this cloth */
 
157
                int m_maxLinks;
 
158
                /** Current number of links allocated to this cloth */
 
159
                int m_numLinks;
 
160
 
 
161
                /** The actual soft body this data represents */
 
162
                btSoftBody *m_softBody;
 
163
 
 
164
 
 
165
        public:
 
166
                btAcceleratedSoftBodyInterface( btSoftBody *softBody ) :
 
167
                  m_softBody( softBody )
 
168
                {
 
169
                        m_numVertices = 0;
 
170
                        m_maxVertices = 0;
 
171
                        m_numTriangles = 0;
 
172
                        m_maxTriangles = 0;
 
173
                        m_firstVertex = 0;
 
174
                        m_firstTriangle = 0;
 
175
                        m_firstLink = 0;
 
176
                        m_maxLinks = 0;
 
177
                        m_numLinks = 0;
 
178
                }
 
179
                int getNumVertices() const
 
180
                {
 
181
                        return m_numVertices;
 
182
                }
 
183
 
 
184
                int getNumTriangles() const
 
185
                {
 
186
                        return m_numTriangles;
 
187
                }
 
188
 
 
189
                int getMaxVertices() const
 
190
                {
 
191
                        return m_maxVertices;
 
192
                }
 
193
 
 
194
                int getMaxTriangles() const
 
195
                {
 
196
                        return m_maxTriangles;
 
197
                }
 
198
 
 
199
                int getFirstVertex() const
 
200
                {
 
201
                        return m_firstVertex;
 
202
                }
 
203
 
 
204
                int getFirstTriangle() const
 
205
                {
 
206
                        return m_firstTriangle;
 
207
                }
 
208
 
 
209
 
 
210
                /**
 
211
                 * Update the bounds in the btSoftBody object
 
212
                 */
 
213
                void updateBounds( const btVector3 &lowerBound, const btVector3 &upperBound );
 
214
 
 
215
                // TODO: All of these set functions will have to do checks and
 
216
                // update the world because restructuring of the arrays will be necessary
 
217
                // Reasonable use of "friend"?
 
218
                void setNumVertices( int numVertices )
 
219
                {
 
220
                        m_numVertices = numVertices;
 
221
                }       
 
222
        
 
223
                void setNumTriangles( int numTriangles )
 
224
                {
 
225
                        m_numTriangles = numTriangles;
 
226
                }
 
227
 
 
228
                void setMaxVertices( int maxVertices )
 
229
                {
 
230
                        m_maxVertices = maxVertices;
 
231
                }
 
232
 
 
233
                void setMaxTriangles( int maxTriangles )
 
234
                {
 
235
                        m_maxTriangles = maxTriangles;
 
236
                }
 
237
 
 
238
                void setFirstVertex( int firstVertex )
 
239
                {
 
240
                        m_firstVertex = firstVertex;
 
241
                }
 
242
 
 
243
                void setFirstTriangle( int firstTriangle )
 
244
                {
 
245
                        m_firstTriangle = firstTriangle;
 
246
                }
 
247
 
 
248
                void setMaxLinks( int maxLinks )
 
249
                {
 
250
                        m_maxLinks = maxLinks;
 
251
                }
 
252
 
 
253
                void setNumLinks( int numLinks )
 
254
                {
 
255
                        m_numLinks = numLinks;
 
256
                }
 
257
 
 
258
                void setFirstLink( int firstLink )
 
259
                {
 
260
                        m_firstLink = firstLink;
 
261
                }
 
262
 
 
263
                int getMaxLinks()
 
264
                {
 
265
                        return m_maxLinks;
 
266
                }
 
267
 
 
268
                int getNumLinks()
 
269
                {
 
270
                        return m_numLinks;
 
271
                }
 
272
 
 
273
                int getFirstLink()
 
274
                {
 
275
                        return m_firstLink;
 
276
                }
 
277
 
 
278
                btSoftBody* getSoftBody()
 
279
                {
 
280
                        return m_softBody;
 
281
                }
 
282
 
 
283
        };
 
284
 
 
285
        
 
286
        struct CollisionObjectIndices
 
287
        {
 
288
                CollisionObjectIndices( int f, int e )
 
289
                {
 
290
                        firstObject = f;
 
291
                        endObject = e;
 
292
                }
 
293
 
 
294
                int firstObject;
 
295
                int endObject;
 
296
        };
 
297
 
 
298
 
 
299
 
 
300
 
 
301
 
 
302
        struct PrepareLinksCB
 
303
        {               
 
304
                int numLinks;
 
305
                int padding0;
 
306
                int padding1;
 
307
                int padding2;
 
308
        };
 
309
 
 
310
        struct SolvePositionsFromLinksKernelCB
 
311
        {               
 
312
                int startLink;
 
313
                int numLinks;
 
314
                float kst;
 
315
                float ti;
 
316
        };
 
317
 
 
318
        struct IntegrateCB
 
319
        {
 
320
                int numNodes;
 
321
                float solverdt;
 
322
                int padding1;
 
323
                int padding2;
 
324
        };
 
325
 
 
326
        struct UpdatePositionsFromVelocitiesCB
 
327
        {
 
328
                int numNodes;
 
329
                float solverSDT;
 
330
                int padding1;
 
331
                int padding2;
 
332
        };
 
333
 
 
334
        struct UpdateVelocitiesFromPositionsWithoutVelocitiesCB
 
335
        {
 
336
                int numNodes;
 
337
                float isolverdt;
 
338
                int padding1;
 
339
                int padding2;
 
340
        };
 
341
 
 
342
        struct UpdateVelocitiesFromPositionsWithVelocitiesCB
 
343
        {
 
344
                int numNodes;
 
345
                float isolverdt;
 
346
                int padding1;
 
347
                int padding2;
 
348
        };
 
349
 
 
350
        struct UpdateSoftBodiesCB
 
351
        {
 
352
                int numNodes;
 
353
                int startFace;
 
354
                int numFaces;
 
355
                float epsilon;
 
356
        };
 
357
 
 
358
 
 
359
        struct ApplyForcesCB
 
360
        {
 
361
                unsigned int numNodes;
 
362
                float solverdt;
 
363
                float epsilon;
 
364
                int padding3;
 
365
        };
 
366
 
 
367
        struct AddVelocityCB
 
368
        {
 
369
                int startNode;
 
370
                int lastNode;
 
371
                float velocityX;
 
372
                float velocityY;
 
373
                float velocityZ;
 
374
                int padding1;
 
375
                int padding2;
 
376
                int padding3;
 
377
        };
 
378
 
 
379
        struct VSolveLinksCB
 
380
        {
 
381
                int startLink;
 
382
                int numLinks;
 
383
                float kst;
 
384
                int padding;
 
385
        };
 
386
 
 
387
        struct ComputeBoundsCB
 
388
        {
 
389
                int numNodes;
 
390
                int numSoftBodies;
 
391
                int padding1;
 
392
                int padding2;
 
393
        };
 
394
 
 
395
        struct SolveCollisionsAndUpdateVelocitiesCB
 
396
        {
 
397
                unsigned int numNodes;
 
398
                float isolverdt;
 
399
                int padding0;
 
400
                int padding1;
 
401
        };
 
402
 
 
403
        
 
404
 
 
405
 
 
406
protected:
 
407
        ID3D11Device *           m_dx11Device;
 
408
        ID3D11DeviceContext* m_dx11Context;
 
409
        
 
410
        DXFunctions dxFunctions;
 
411
public:
 
412
        /** Link data for all cloths. Note that this will be sorted batch-wise for efficient computation and m_linkAddresses will maintain the addressing. */
 
413
        btSoftBodyLinkDataDX11 m_linkData;
 
414
        btSoftBodyVertexDataDX11 m_vertexData;
 
415
        btSoftBodyTriangleDataDX11 m_triangleData;
 
416
 
 
417
protected:
 
418
 
 
419
        /** Variable to define whether we need to update solver constants on the next iteration */
 
420
        bool m_updateSolverConstants;
 
421
 
 
422
        bool m_shadersInitialized;
 
423
 
 
424
        /** 
 
425
         * Cloths owned by this solver.
 
426
         * Only our cloths are in this array.
 
427
         */
 
428
        btAlignedObjectArray< btAcceleratedSoftBodyInterface * > m_softBodySet;
 
429
 
 
430
        /** Acceleration value to be applied to all non-static vertices in the solver. 
 
431
         * Index n is cloth n, array sized by number of cloths in the world not the solver. 
 
432
         */
 
433
        btAlignedObjectArray< Vectormath::Aos::Vector3 >        m_perClothAcceleration;
 
434
        btDX11Buffer<Vectormath::Aos::Vector3>                          m_dx11PerClothAcceleration;
 
435
 
 
436
        /** Wind velocity to be applied normal to all non-static vertices in the solver. 
 
437
         * Index n is cloth n, array sized by number of cloths in the world not the solver. 
 
438
         */
 
439
        btAlignedObjectArray< Vectormath::Aos::Vector3 >        m_perClothWindVelocity;
 
440
        btDX11Buffer<Vectormath::Aos::Vector3>                          m_dx11PerClothWindVelocity;
 
441
 
 
442
        /** Velocity damping factor */
 
443
        btAlignedObjectArray< float >                                           m_perClothDampingFactor;
 
444
        btDX11Buffer<float>                                                                     m_dx11PerClothDampingFactor;
 
445
 
 
446
        /** Velocity correction coefficient */
 
447
        btAlignedObjectArray< float >                                           m_perClothVelocityCorrectionCoefficient;
 
448
        btDX11Buffer<float>                                                                     m_dx11PerClothVelocityCorrectionCoefficient;
 
449
 
 
450
        /** Lift parameter for wind effect on cloth. */
 
451
        btAlignedObjectArray< float >                                           m_perClothLiftFactor;
 
452
        btDX11Buffer<float>                                                                     m_dx11PerClothLiftFactor;
 
453
        
 
454
        /** Drag parameter for wind effect on cloth. */
 
455
        btAlignedObjectArray< float >                                           m_perClothDragFactor;
 
456
        btDX11Buffer<float>                                                                     m_dx11PerClothDragFactor;
 
457
 
 
458
        /** Density of the medium in which each cloth sits */
 
459
        btAlignedObjectArray< float >                                           m_perClothMediumDensity;
 
460
        btDX11Buffer<float>                                                                     m_dx11PerClothMediumDensity;
 
461
 
 
462
        
 
463
        /** 
 
464
         * Collision shape details: pair of index of first collision shape for the cloth and number of collision objects.
 
465
         */
 
466
        btAlignedObjectArray< CollisionObjectIndices >          m_perClothCollisionObjects;
 
467
        btDX11Buffer<CollisionObjectIndices>                            m_dx11PerClothCollisionObjects;
 
468
 
 
469
        /** 
 
470
         * Collision shapes being passed across to the cloths in this solver.
 
471
         */
 
472
        btAlignedObjectArray< CollisionShapeDescription >       m_collisionObjectDetails;
 
473
        btDX11Buffer< CollisionShapeDescription >                       m_dx11CollisionObjectDetails;
 
474
 
 
475
        /** 
 
476
         * Minimum bounds for each cloth.
 
477
         * Updated by GPU and returned for use by broad phase.
 
478
         * These are int vectors as a reminder that they store the int representation of a float, not a float.
 
479
         * Bit 31 is inverted - is floats are stored with int-sortable values.
 
480
         */
 
481
        btAlignedObjectArray< UIntVector3 >     m_perClothMinBounds;
 
482
        btDX11Buffer< UIntVector3 >                     m_dx11PerClothMinBounds;
 
483
 
 
484
        /** 
 
485
         * Maximum bounds for each cloth.
 
486
         * Updated by GPU and returned for use by broad phase.
 
487
         * These are int vectors as a reminder that they store the int representation of a float, not a float.
 
488
         * Bit 31 is inverted - is floats are stored with int-sortable values.
 
489
         */
 
490
        btAlignedObjectArray< UIntVector3 >     m_perClothMaxBounds;
 
491
        btDX11Buffer< UIntVector3 >                     m_dx11PerClothMaxBounds;
 
492
 
 
493
        
 
494
        /** 
 
495
         * Friction coefficient for each cloth
 
496
         */
 
497
        btAlignedObjectArray< float >   m_perClothFriction;
 
498
        btDX11Buffer< float >                   m_dx11PerClothFriction;
 
499
 
 
500
        DXFunctions::KernelDesc         prepareLinksKernel;
 
501
        DXFunctions::KernelDesc         solvePositionsFromLinksKernel;
 
502
        DXFunctions::KernelDesc         vSolveLinksKernel;
 
503
        DXFunctions::KernelDesc         integrateKernel;
 
504
        DXFunctions::KernelDesc         addVelocityKernel;
 
505
        DXFunctions::KernelDesc         updatePositionsFromVelocitiesKernel;
 
506
        DXFunctions::KernelDesc         updateVelocitiesFromPositionsWithoutVelocitiesKernel;
 
507
        DXFunctions::KernelDesc         updateVelocitiesFromPositionsWithVelocitiesKernel;
 
508
        DXFunctions::KernelDesc         solveCollisionsAndUpdateVelocitiesKernel;
 
509
        DXFunctions::KernelDesc         resetNormalsAndAreasKernel;
 
510
        DXFunctions::KernelDesc         normalizeNormalsAndAreasKernel;
 
511
        DXFunctions::KernelDesc         computeBoundsKernel;
 
512
        DXFunctions::KernelDesc         updateSoftBodiesKernel;
 
513
 
 
514
        DXFunctions::KernelDesc         applyForcesKernel;
 
515
 
 
516
 
 
517
        /**
 
518
         * Integrate motion on the solver.
 
519
         */
 
520
        virtual void integrate( float solverdt );
 
521
        float computeTriangleArea( 
 
522
                const Vectormath::Aos::Point3 &vertex0,
 
523
                const Vectormath::Aos::Point3 &vertex1,
 
524
                const Vectormath::Aos::Point3 &vertex2 );
 
525
 
 
526
 
 
527
        virtual bool buildShaders();
 
528
 
 
529
        void resetNormalsAndAreas( int numVertices );
 
530
 
 
531
        void normalizeNormalsAndAreas( int numVertices );
 
532
 
 
533
        void executeUpdateSoftBodies( int firstTriangle, int numTriangles );
 
534
 
 
535
        void prepareCollisionConstraints();
 
536
 
 
537
        Vectormath::Aos::Vector3 ProjectOnAxis( const Vectormath::Aos::Vector3 &v, const Vectormath::Aos::Vector3 &a );
 
538
 
 
539
        void ApplyClampedForce( float solverdt, const Vectormath::Aos::Vector3 &force, const Vectormath::Aos::Vector3 &vertexVelocity, float inverseMass, Vectormath::Aos::Vector3 &vertexForce );
 
540
 
 
541
        virtual void applyForces( float solverdt );
 
542
        
 
543
        virtual void updateConstants( float timeStep );
 
544
        int findSoftBodyIndex( const btSoftBody* const softBody );
 
545
 
 
546
        //////////////////////////////////////
 
547
        // Kernel dispatches
 
548
        virtual void prepareLinks();
 
549
 
 
550
        void updatePositionsFromVelocities( float solverdt );
 
551
        void solveLinksForPosition( int startLink, int numLinks, float kst, float ti );
 
552
        void solveLinksForVelocity( int startLink, int numLinks, float kst );
 
553
        
 
554
        void updateVelocitiesFromPositionsWithVelocities( float isolverdt );
 
555
        void updateVelocitiesFromPositionsWithoutVelocities( float isolverdt );
 
556
        void computeBounds( );
 
557
        void solveCollisionsAndUpdateVelocities( float isolverdt );
 
558
 
 
559
        // End kernel dispatches
 
560
        /////////////////////////////////////
 
561
 
 
562
        void updateBounds();
 
563
 
 
564
        
 
565
        void releaseKernels();
 
566
 
 
567
public:
 
568
        btDX11SoftBodySolver(ID3D11Device * dx11Device, ID3D11DeviceContext* dx11Context, DXFunctions::CompileFromMemoryFunc dx11CompileFromMemory = &D3DX11CompileFromMemory);
 
569
 
 
570
        virtual ~btDX11SoftBodySolver();
 
571
        
 
572
        
 
573
        virtual SolverTypes getSolverType() const
 
574
        {
 
575
                return DX_SOLVER;
 
576
        }
 
577
 
 
578
 
 
579
        virtual btSoftBodyLinkData &getLinkData();
 
580
 
 
581
        virtual btSoftBodyVertexData &getVertexData();
 
582
 
 
583
        virtual btSoftBodyTriangleData &getTriangleData();
 
584
 
 
585
 
 
586
 
 
587
        
 
588
 
 
589
        btAcceleratedSoftBodyInterface *findSoftBodyInterface( const btSoftBody* const softBody );
 
590
        const btAcceleratedSoftBodyInterface * const findSoftBodyInterface( const btSoftBody* const softBody ) const;
 
591
 
 
592
        virtual bool checkInitialized();
 
593
 
 
594
        virtual void updateSoftBodies( );
 
595
 
 
596
        virtual void optimize( btAlignedObjectArray< btSoftBody * > &softBodies , bool forceUpdate=false);
 
597
 
 
598
        virtual void copyBackToSoftBodies();
 
599
 
 
600
        virtual void solveConstraints( float solverdt );
 
601
 
 
602
        virtual void predictMotion( float solverdt );
 
603
 
 
604
        
 
605
        virtual void processCollision( btSoftBody *, btCollisionObject* );
 
606
 
 
607
        virtual void processCollision( btSoftBody*, btSoftBody* );
 
608
 
 
609
};
 
610
 
 
611
 
 
612
 
 
613
/** 
 
614
 * Class to manage movement of data from a solver to a given target.
 
615
 * This version is the DX to CPU version.
 
616
 */
 
617
class btSoftBodySolverOutputDXtoCPU : public btSoftBodySolverOutput
 
618
{
 
619
protected:
 
620
 
 
621
public:
 
622
        btSoftBodySolverOutputDXtoCPU()
 
623
        {
 
624
        }
 
625
 
 
626
        /** Output current computed vertex data to the vertex buffers for all cloths in the solver. */
 
627
        virtual void copySoftBodyToVertexBuffer( const btSoftBody * const softBody, btVertexBufferDescriptor *vertexBuffer );
 
628
};
 
629
 
 
630
/** 
 
631
 * Class to manage movement of data from a solver to a given target.
 
632
 * This version is the DX to DX version and subclasses DX to CPU so that it works for that too.
 
633
 */
 
634
class btSoftBodySolverOutputDXtoDX : public btSoftBodySolverOutputDXtoCPU
 
635
{
 
636
protected:
 
637
        struct OutputToVertexArrayCB
 
638
        {
 
639
                int startNode;
 
640
                int numNodes;
 
641
                int positionOffset;
 
642
                int positionStride;
 
643
                
 
644
                int normalOffset;       
 
645
                int normalStride;
 
646
                int padding1;
 
647
                int padding2;
 
648
        };
 
649
        
 
650
        DXFunctions dxFunctions;
 
651
        DXFunctions::KernelDesc outputToVertexArrayWithNormalsKernel;
 
652
        DXFunctions::KernelDesc outputToVertexArrayWithoutNormalsKernel;
 
653
 
 
654
        
 
655
        bool m_shadersInitialized;
 
656
 
 
657
        bool checkInitialized();
 
658
        bool buildShaders();
 
659
        void releaseKernels();
 
660
 
 
661
public:
 
662
        btSoftBodySolverOutputDXtoDX(ID3D11Device *dx11Device, ID3D11DeviceContext* dx11Context, DXFunctions::CompileFromMemoryFunc dx11CompileFromMemory = &D3DX11CompileFromMemory) :
 
663
          dxFunctions( dx11Device, dx11Context, dx11CompileFromMemory )
 
664
        {
 
665
                m_shadersInitialized = false;
 
666
        }
 
667
 
 
668
        ~btSoftBodySolverOutputDXtoDX()
 
669
        {
 
670
                releaseKernels();
 
671
        }
 
672
 
 
673
        /** Output current computed vertex data to the vertex buffers for all cloths in the solver. */
 
674
        virtual void copySoftBodyToVertexBuffer( const btSoftBody * const softBody, btVertexBufferDescriptor *vertexBuffer );
 
675
};
 
676
 
 
677
#endif // #ifndef BT_ACCELERATED_SOFT_BODY_DX11_SOLVER_H
 
678
 
 
679