[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / src / Bullet3OpenCL / NarrowphaseCollision / b3StridingMeshInterface.h
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
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 B3_STRIDING_MESHINTERFACE_H
17 #define B3_STRIDING_MESHINTERFACE_H
18
19 #include "Bullet3Common/b3Vector3.h"
20 #include "b3TriangleCallback.h"
21 //#include "b3ConcaveShape.h"
22
23 enum PHY_ScalarType
24 {
25         PHY_FLOAT,
26         PHY_DOUBLE,
27         PHY_INTEGER,
28         PHY_SHORT,
29         PHY_FIXEDPOINT88,
30         PHY_UCHAR
31 };
32
33 ///     The b3StridingMeshInterface is the interface class for high performance generic access to triangle meshes, used in combination with b3BvhTriangleMeshShape and some other collision shapes.
34 /// Using index striding of 3*sizeof(integer) it can use triangle arrays, using index striding of 1*sizeof(integer) it can handle triangle strips.
35 /// It allows for sharing graphics and collision meshes. Also it provides locking/unlocking of graphics meshes that are in gpu memory.
36 B3_ATTRIBUTE_ALIGNED16(class)
37 b3StridingMeshInterface
38 {
39 protected:
40         b3Vector3 m_scaling;
41
42 public:
43         B3_DECLARE_ALIGNED_ALLOCATOR();
44
45         b3StridingMeshInterface() : m_scaling(b3MakeVector3(b3Scalar(1.), b3Scalar(1.), b3Scalar(1.)))
46         {
47         }
48
49         virtual ~b3StridingMeshInterface();
50
51         virtual void InternalProcessAllTriangles(b3InternalTriangleIndexCallback * callback, const b3Vector3& aabbMin, const b3Vector3& aabbMax) const;
52
53         ///brute force method to calculate aabb
54         void calculateAabbBruteForce(b3Vector3 & aabbMin, b3Vector3 & aabbMax);
55
56         /// get read and write access to a subpart of a triangle mesh
57         /// this subpart has a continuous array of vertices and indices
58         /// in this way the mesh can be handled as chunks of memory with striding
59         /// very similar to OpenGL vertexarray support
60         /// make a call to unLockVertexBase when the read and write access is finished
61         virtual void getLockedVertexIndexBase(unsigned char** vertexbase, int& numverts, PHY_ScalarType& type, int& stride, unsigned char** indexbase, int& indexstride, int& numfaces, PHY_ScalarType& indicestype, int subpart = 0) = 0;
62
63         virtual void getLockedReadOnlyVertexIndexBase(const unsigned char** vertexbase, int& numverts, PHY_ScalarType& type, int& stride, const unsigned char** indexbase, int& indexstride, int& numfaces, PHY_ScalarType& indicestype, int subpart = 0) const = 0;
64
65         /// unLockVertexBase finishes the access to a subpart of the triangle mesh
66         /// make a call to unLockVertexBase when the read and write access (using getLockedVertexIndexBase) is finished
67         virtual void unLockVertexBase(int subpart) = 0;
68
69         virtual void unLockReadOnlyVertexBase(int subpart) const = 0;
70
71         /// getNumSubParts returns the number of separate subparts
72         /// each subpart has a continuous array of vertices and indices
73         virtual int getNumSubParts() const = 0;
74
75         virtual void preallocateVertices(int numverts) = 0;
76         virtual void preallocateIndices(int numindices) = 0;
77
78         virtual bool hasPremadeAabb() const { return false; }
79         virtual void setPremadeAabb(const b3Vector3& aabbMin, const b3Vector3& aabbMax) const
80         {
81                 (void)aabbMin;
82                 (void)aabbMax;
83         }
84         virtual void getPremadeAabb(b3Vector3 * aabbMin, b3Vector3 * aabbMax) const
85         {
86                 (void)aabbMin;
87                 (void)aabbMax;
88         }
89
90         const b3Vector3& getScaling() const
91         {
92                 return m_scaling;
93         }
94         void setScaling(const b3Vector3& scaling)
95         {
96                 m_scaling = scaling;
97         }
98
99         virtual int calculateSerializeBufferSize() const;
100
101         ///fills the dataBuffer and returns the struct name (and 0 on failure)
102         //virtual       const char*     serialize(void* dataBuffer, b3Serializer* serializer) const;
103 };
104
105 struct b3IntIndexData
106 {
107         int m_value;
108 };
109
110 struct b3ShortIntIndexData
111 {
112         short m_value;
113         char m_pad[2];
114 };
115
116 struct b3ShortIntIndexTripletData
117 {
118         short m_values[3];
119         char m_pad[2];
120 };
121
122 struct b3CharIndexTripletData
123 {
124         unsigned char m_values[3];
125         char m_pad;
126 };
127
128 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
129 struct b3MeshPartData
130 {
131         b3Vector3FloatData* m_vertices3f;
132         b3Vector3DoubleData* m_vertices3d;
133
134         b3IntIndexData* m_indices32;
135         b3ShortIntIndexTripletData* m_3indices16;
136         b3CharIndexTripletData* m_3indices8;
137
138         b3ShortIntIndexData* m_indices16;  //backwards compatibility
139
140         int m_numTriangles;  //length of m_indices = m_numTriangles
141         int m_numVertices;
142 };
143
144 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
145 struct b3StridingMeshInterfaceData
146 {
147         b3MeshPartData* m_meshPartsPtr;
148         b3Vector3FloatData m_scaling;
149         int m_numMeshParts;
150         char m_padding[4];
151 };
152
153 B3_FORCE_INLINE int b3StridingMeshInterface::calculateSerializeBufferSize() const
154 {
155         return sizeof(b3StridingMeshInterfaceData);
156 }
157
158 #endif  //B3_STRIDING_MESHINTERFACE_H