1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org/ |
---|
6 | |
---|
7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | This program is free software; you can redistribute it and/or modify it under |
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
13 | version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
23 | |
---|
24 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | #ifndef __PlatformInformation_H__ |
---|
30 | #define __PlatformInformation_H__ |
---|
31 | |
---|
32 | #include "OgrePrerequisites.h" |
---|
33 | |
---|
34 | namespace Ogre { |
---|
35 | // |
---|
36 | // TODO: Puts following macros into OgrePlatform.h? |
---|
37 | // |
---|
38 | |
---|
39 | /* Initial CPU stuff to set. |
---|
40 | */ |
---|
41 | #define OGRE_CPU_UNKNOWN 0 |
---|
42 | #define OGRE_CPU_X86 1 |
---|
43 | #define OGRE_CPU_PPC 2 |
---|
44 | |
---|
45 | /* Find CPU type |
---|
46 | */ |
---|
47 | #if (defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))) || \ |
---|
48 | (defined(__GNUC__) && (defined(__i386__) /*|| defined(__x86_64__)*/)) |
---|
49 | # define OGRE_CPU OGRE_CPU_X86 |
---|
50 | |
---|
51 | #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE && defined(__BIG_ENDIAN__) |
---|
52 | # define OGRE_CPU OGRE_CPU_PPC |
---|
53 | #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
54 | # define OGRE_CPU OGRE_CPU_X86 |
---|
55 | |
---|
56 | #else |
---|
57 | # define OGRE_CPU OGRE_CPU_UNKNOWN |
---|
58 | #endif |
---|
59 | |
---|
60 | /* Find how to declare aligned variable. |
---|
61 | */ |
---|
62 | #if OGRE_COMPILER == OGRE_COMPILER_MSVC |
---|
63 | # define OGRE_ALIGNED_DECL(type, var, alignment) __declspec(align(alignment)) type var |
---|
64 | |
---|
65 | #elif OGRE_COMPILER == OGRE_COMPILER_GNUC |
---|
66 | # define OGRE_ALIGNED_DECL(type, var, alignment) type var __attribute__((__aligned__(alignment))) |
---|
67 | |
---|
68 | #else |
---|
69 | # define OGRE_ALIGNED_DECL(type, var, alignment) type var |
---|
70 | #endif |
---|
71 | |
---|
72 | /** Find perfect alignment (should supports SIMD alignment if SIMD available) |
---|
73 | */ |
---|
74 | #if OGRE_CPU == OGRE_CPU_X86 |
---|
75 | # define OGRE_SIMD_ALIGNMENT 16 |
---|
76 | |
---|
77 | #else |
---|
78 | # define OGRE_SIMD_ALIGNMENT 16 |
---|
79 | #endif |
---|
80 | |
---|
81 | /* Declare variable aligned to SIMD alignment. |
---|
82 | */ |
---|
83 | #define OGRE_SIMD_ALIGNED_DECL(type, var) OGRE_ALIGNED_DECL(type, var, OGRE_SIMD_ALIGNMENT) |
---|
84 | |
---|
85 | /* Define whether or not Ogre compiled with SSE supports. |
---|
86 | */ |
---|
87 | #if OGRE_DOUBLE_PRECISION == 0 && OGRE_CPU == OGRE_CPU_X86 && OGRE_COMPILER == OGRE_COMPILER_MSVC |
---|
88 | # define __OGRE_HAVE_SSE 1 |
---|
89 | #elif OGRE_DOUBLE_PRECISION == 0 && OGRE_CPU == OGRE_CPU_X86 && OGRE_COMPILER == OGRE_COMPILER_GNUC |
---|
90 | # define __OGRE_HAVE_SSE 1 |
---|
91 | #endif |
---|
92 | |
---|
93 | |
---|
94 | #ifndef __OGRE_HAVE_SSE |
---|
95 | # define __OGRE_HAVE_SSE 0 |
---|
96 | #endif |
---|
97 | |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | /** Class which provides the run-time platform information Ogre runs on. |
---|
102 | @remarks |
---|
103 | Ogre is designed to be platform-independent, but there some platform |
---|
104 | and run-time environment specific optimised functions are built-in |
---|
105 | for maximise performance, and those special optimised routines are |
---|
106 | need to determine run-time environment for select variant executing |
---|
107 | path. |
---|
108 | @par |
---|
109 | This class manages that provides a couple of functions to determine |
---|
110 | platform information of the run-time environment. |
---|
111 | @note |
---|
112 | This class is supposed to use by advanced user only. |
---|
113 | */ |
---|
114 | class _OgreExport PlatformInformation |
---|
115 | { |
---|
116 | public: |
---|
117 | |
---|
118 | /// Enum describing the different CPU features we want to check for, platform-dependent |
---|
119 | enum CpuFeatures |
---|
120 | { |
---|
121 | #if OGRE_CPU == OGRE_CPU_X86 |
---|
122 | CPU_FEATURE_SSE = 1 << 0, |
---|
123 | CPU_FEATURE_SSE2 = 1 << 1, |
---|
124 | CPU_FEATURE_SSE3 = 1 << 2, |
---|
125 | CPU_FEATURE_MMX = 1 << 3, |
---|
126 | CPU_FEATURE_MMXEXT = 1 << 4, |
---|
127 | CPU_FEATURE_3DNOW = 1 << 5, |
---|
128 | CPU_FEATURE_3DNOWEXT = 1 << 6, |
---|
129 | CPU_FEATURE_CMOV = 1 << 7, |
---|
130 | CPU_FEATURE_TSC = 1 << 8, |
---|
131 | CPU_FEATURE_FPU = 1 << 9, |
---|
132 | CPU_FEATURE_PRO = 1 << 10, |
---|
133 | CPU_FEATURE_HTT = 1 << 11, |
---|
134 | #endif |
---|
135 | |
---|
136 | CPU_FEATURE_NONE = 0 |
---|
137 | }; |
---|
138 | |
---|
139 | /** Gets a string of the CPU identifier. |
---|
140 | @note |
---|
141 | Actual detecting are performs in the first time call to this function, |
---|
142 | and then all future calls with return internal cached value. |
---|
143 | */ |
---|
144 | static const String& getCpuIdentifier(void); |
---|
145 | |
---|
146 | /** Gets a or-masked of enum CpuFeatures that are supported by the CPU. |
---|
147 | @note |
---|
148 | Actual detecting are performs in the first time call to this function, |
---|
149 | and then all future calls with return internal cached value. |
---|
150 | */ |
---|
151 | static uint getCpuFeatures(void); |
---|
152 | |
---|
153 | /** Gets whether a specific feature is supported by the CPU. |
---|
154 | @note |
---|
155 | Actual detecting are performs in the first time call to this function, |
---|
156 | and then all future calls with return internal cached value. |
---|
157 | */ |
---|
158 | static bool hasCpuFeature(CpuFeatures feature); |
---|
159 | |
---|
160 | |
---|
161 | /** Write the CPU information to the passed in Log */ |
---|
162 | static void log(Log* pLog); |
---|
163 | |
---|
164 | }; |
---|
165 | |
---|
166 | } |
---|
167 | |
---|
168 | #endif // __PlatformInformation_H__ |
---|