Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/include/OgreOptimisedUtil.h @ 1

Last change on this file since 1 was 1, checked in by landauf, 17 years ago
File size: 9.9 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#ifndef __OptimisedUtil_H__
30#define __OptimisedUtil_H__
31
32#include "OgrePrerequisites.h"
33#include "OgreEdgeListBuilder.h"
34
35namespace Ogre {
36
37    /** Utility class for provides optimised functions.
38    @note
39        This class are supposed used by internal engine only.
40    */
41    class _OgreExport OptimisedUtil
42    {
43    private:
44        /// Privated copy constructor, to prevent misuse
45        OptimisedUtil(const OptimisedUtil& rhs); /* do nothing, should not use */
46        /// Privated operator=, to prevent misuse
47        OptimisedUtil& operator=(const OptimisedUtil& rhs); /* do not use */
48
49    protected:
50        /// Store a pointer to the implementation
51        static OptimisedUtil* msImplementation;
52
53        /// Detect best implementation based on run-time environment
54        static OptimisedUtil* _detectImplementation(void);
55
56    public:
57        // Default constructor
58        OptimisedUtil(void) {}
59        // Destructor
60        virtual ~OptimisedUtil() {}
61
62        /** Gets the implementation of this class.
63        @note
64            Don't cache the pointer returned by this function, it'll change due
65            run-time environment detection to pick up the best implementation.
66        */
67        static OptimisedUtil* getImplementation(void) { return msImplementation; }
68
69        /** Performs software vertex skinning.
70        @param srcPosPtr Pointer to source position buffer.
71        @param destPosPtr Pointer to destination position buffer.
72        @param srcNormPtr Pointer to source normal buffer, if NULL,
73            means blend position only.
74        @param destNormPtr Pointer to destination normal buffer, it's
75            ignored if srcNormPtr is NULL.
76        @param blendWeightPtr Pointer to blend weight buffer.
77        @param blendIndexPtr Pointer to blend index buffer.
78        @param blendMatrices An array of pointer of blend matrix, the matrix
79            must be aligned to SIMD alignment, but not necessary for the array
80            itself.
81        @param srcPosStride The stride of source position in bytes.
82        @param destPosStride The stride of destination position in bytes.
83        @param srcNormStride The stride of source normal in bytes,
84            it's ignored if srcNormPtr is NULL.
85        @param destNormStride The stride of destination normal in bytes,
86            it's ignored if srcNormPtr is NULL.
87        @param blendWeightStride The stride of blend weight buffer in bytes.
88        @param blendIndexStride The stride of blend index buffer in bytes.
89        @param numWeightsPerVertex Number of blend weights per-vertex, as well
90            as for blend indices.
91        @param numVertices Number of vertices to blend.
92        */
93        virtual void softwareVertexSkinning(
94            const float *srcPosPtr, float *destPosPtr,
95            const float *srcNormPtr, float *destNormPtr,
96            const float *blendWeightPtr, const unsigned char* blendIndexPtr,
97            const Matrix4* const* blendMatrices,
98            size_t srcPosStride, size_t destPosStride,
99            size_t srcNormStride, size_t destNormStride,
100            size_t blendWeightStride, size_t blendIndexStride,
101            size_t numWeightsPerVertex,
102            size_t numVertices) = 0;
103
104        /** Performs a software vertex morph, of the kind used for
105            morph animation although it can be used for other purposes.
106        @remarks
107            This function will linearly interpolate positions between two
108            source buffers, into a third buffer.
109        @param t Parametric distance between the start and end positions
110        @param srcPos1 Pointer to buffer for the start positions
111        @param srcPos2 Pointer to buffer for the end positions
112        @param dstPos Pointer to buffer for the destination positions
113        @param numVertices Number of vertices to morph, which agree with
114            the number in start, end and destination buffer. Bear in mind
115            three floating-point values per vertex
116        */
117        virtual void softwareVertexMorph(
118            Real t,
119            const float *srcPos1, const float *srcPos2,
120            float *dstPos,
121            size_t numVertices) = 0;
122
123        /** Concatenate an affine matrix to an array of affine matrices.
124        @note
125            An affine matrix is a 4x4 matrix with row 3 equal to (0, 0, 0, 1),
126            e.g. no projective coefficients.
127        @param baseMatrix The matrix used as first operand.
128        @param srcMatrices An array of matrix used as second operand.
129        @param dstMatrices An array of matrix to store matrix concatenate results.
130        @param numMatrices Number of matrices in the array.
131        */
132        virtual void concatenateAffineMatrices(
133            const Matrix4& baseMatrix,
134            const Matrix4* srcMatrices,
135            Matrix4* dstMatrices,
136            size_t numMatrices) = 0;
137
138        /** Calculate the face normals for the triangles based on position
139            information.
140        @param positions Pointer to position information, which packed in
141            (x, y, z) format, indexing by vertex index in the triangle. No
142            alignment requests.
143        @param triangles The triangles need to calculate face normal, the vertex
144            positions is indexed by vertex index to position information.
145        @param faceNormals The array of Vector4 used to store triangles face normal,
146            Must be aligned to SIMD alignment.
147        @param numTriangles Number of triangles to calculate face normal.
148        */
149        virtual void calculateFaceNormals(
150            const float *positions,
151            const EdgeData::Triangle *triangles,
152            Vector4 *faceNormals,
153            size_t numTriangles) = 0;
154
155        /** Calculate the light facing state of the triangle's face normals
156        @remarks
157            This is normally the first stage of calculating a silhouette, ie
158            establishing which tris are facing the light and which are facing
159            away.
160        @param lightPos 4D position of the light in object space, note that
161            for directional lights (which have no position), the w component
162            is 0 and the x/y/z position are the direction.
163        @param faceNormals An array of face normals for the triangles, the face
164            normal are unit vector othogonal to the triangles, plus distance
165            from origin. This array must be aligned to SIMD alignment.
166        @param lightFacings An array of flags for store light facing state
167            results, the result flag is true if corresponding face normal facing
168            the light, false otherwise. This array no alignment requires.
169        @param numFaces Number of face normals to calculate.
170        */
171        virtual void calculateLightFacing(
172            const Vector4& lightPos,
173            const Vector4* faceNormals,
174            char* lightFacings,
175            size_t numFaces) = 0;
176
177        /** Extruding vertices by a fixed distance based on light position.
178        @param lightPos 4D light position, when w=0.0f this represents a
179            directional light, otherwise, w must be equal to 1.0f, which
180            represents a point light.
181        @param extrudeDist The distance to extrude.
182        @param srcPositions Pointer to source vertex's position buffer, which
183            the position is a 3D vector packed in xyz format. No SIMD alignment
184            requirement but loss performance for unaligned data.
185        @param destPositions Pointer to destination vertex's position buffer,
186            which the position is a 3D vector packed in xyz format. No SIMD
187            alignment requirement but loss performance for unaligned data.
188        @param numVertices Number of vertices need to extruding, which agree
189            with source and destination buffers.
190        */
191        virtual void extrudeVertices(
192            const Vector4& lightPos,
193            Real extrudeDist,
194            const float* srcPositions,
195            float* destPositions,
196            size_t numVertices) = 0;
197    };
198
199    /** Returns raw offseted of the given pointer.
200    @note
201        The offset are in bytes, no matter what type of the pointer.
202    */
203    template <class T>
204    static FORCEINLINE T* rawOffsetPointer(T* ptr, ptrdiff_t offset)
205    {
206        return (T*)((char*)(ptr) + offset);
207    }
208
209    /** Advance the pointer with raw offset.
210    @note
211        The offset are in bytes, no matter what type of the pointer.
212    */
213    template <class T>
214    static FORCEINLINE void advanceRawPointer(T*& ptr, ptrdiff_t offset)
215    {
216        ptr = rawOffsetPointer(ptr, offset);
217    }
218
219}
220
221#endif  // __OptimisedUtil_H__
Note: See TracBrowser for help on using the repository browser.