PowerVR Software Development Kit |
00001 /*!*************************************************************************** 00002 @File PVRTFixedPoint.h 00003 00004 @Brief Fixed point module of the PowerVR Tools library. 00005 00006 @Author PowerVR 00007 00008 @Date 26 January 2005 00009 00010 @Copyright Copyright 2003-2004 by Imagination Technologies Limited. 00011 All rights reserved. No part of this software, either 00012 material or conceptual may be copied or distributed, 00013 transmitted, transcribed, stored in a retrieval system 00014 or translated into any human or computer language in any 00015 form by any means, electronic, mechanical, manual or 00016 other-wise, or disclosed to third parties without the 00017 express written permission of Imagination Technologies 00018 Limited, Unit 8, HomePark Industrial Estate, 00019 King's Langley, Hertfordshire, WD4 8LZ, U.K. 00020 00021 @Platform Independant 00022 00023 @Description Set of macros and functions to make fixed-point 00024 easier to program. 00025 *****************************************************************************/ 00026 #ifndef _PVRTFIXEDPOINT_H_ 00027 #define _PVRTFIXEDPOINT_H_ 00028 00029 #if defined(BUILD_OGLES) || defined(BUILD_D3DM) 00030 #include "PVRTFixedPointAPI.h" 00031 #else 00032 #define VERTTYPE float 00033 #ifdef PVRTFIXEDPOINTENABLE 00034 #error Build option not supported: PVRTFIXEDPOINTENABLE 00035 #endif 00036 #endif 00037 00038 /* Define a 64-bit type for various platforms */ 00039 #if defined(__int64) || defined(WIN32) 00040 #define PVR64BIT __int64 00041 #elif defined(TInt64) 00042 #define PVR64BIT TInt64 00043 #else 00044 #define PVR64BIT long long 00045 #endif 00046 00047 /* Fixed-point macros */ 00048 #define PVRTF2X(f) ( (int) ( (f)*(65536) ) ) 00049 #define PVRTX2F(x) ((float)(x)/65536.0f) 00050 #define PVRTXMUL(a,b) ( (int)( ((PVR64BIT)(a)*(b)) / 65536 ) ) 00051 #define PVRTXDIV(a,b) ( (int)( (((PVR64BIT)(a))<<16)/(b) ) ) 00052 #define PVRTABS(a) ((a) <= 0 ? -(a) : (a) ) 00053 00054 /* Define trig table macros */ 00055 #include "PVRTMathTable.h" 00056 00057 /* Useful values */ 00058 #define PVRTPIOVERTWOf (3.1415926535f / 2.0f) 00059 #define PVRTPIf (3.1415926535f) 00060 #define PVRTTWOPIf (3.1415926535f * 2.0f) 00061 #define PVRTONEf (1.0f) 00062 00063 #define PVRTPIOVERTWOx PVRTF2X(PVRTPIOVERTWOf) 00064 #define PVRTPIx PVRTF2X(PVRTPIf) 00065 #define PVRTTWOPIx PVRTF2X(PVRTTWOPIf) 00066 #define PVRTONEx PVRTF2X(PVRTONEf) 00067 00068 /* Fixed-point trig function lookups */ 00069 #define PVRTXCOS(x) (cos_val[(PVRTXMUL(((PVRTXDIV((x)<0? -(x):(x), PVRTTWOPIx)) & 0x0000FFFF), (NUM_ENTRIES-1)))]) 00070 #define PVRTXSIN(x) (sin_val[(PVRTXMUL(((PVRTXDIV((x)<0 ? PVRTPIx-(x):(x), PVRTTWOPIx)) & 0x0000FFFF), (NUM_ENTRIES-1)))]) 00071 #define PVRTXTAN(x) ( (x)<0 ? -tan_val[(PVRTXMUL(((PVRTXDIV(-(x), PVRTTWOPIx)) & 0x0000FFFF), (NUM_ENTRIES-1)))] : tan_val[(PVRTXMUL(((PVRTXDIV(x, PVRTTWOPIx)) & 0x0000FFFF), (NUM_ENTRIES-1)))] ) 00072 #define PVRTXACOS(x) (acos_val[PVRTXMUL(((((x) + PVRTF2X(1.0f))>>1) & 0x0000FFFF), (NUM_ENTRIES-1))]) 00073 00074 /* Floating-point trig functions lookups (needed by some tools chains that have problems with real math functions) */ 00075 #ifdef USETRIGONOMETRICLOOKUPTABLES 00076 00077 /* If trig tables are forced ON in non-fixed-point builds then convert fixed-point trig tables results to float */ 00078 #define PVRTFCOS(x) PVRTX2F(PVRTXCOS(PVRTF2X(x))) 00079 #define PVRTFSIN(x) PVRTX2F(PVRTXSIN(PVRTF2X(x))) 00080 #define PVRTFTAN(x) PVRTX2F(PVRTXTAN(PVRTF2X(x))) 00081 #define PVRTFACOS(x) PVRTX2F(PVRTXACOS(PVRTF2X(x))) 00082 00083 #else 00084 00085 /* Trig abstraction macros default to normal math trig functions for full float mode */ 00086 #define PVRTFCOS(x) ((float)cos(x)) 00087 #define PVRTFSIN(x) ((float)sin(x)) 00088 #define PVRTFTAN(x) ((float)tan(x)) 00089 #define PVRTFACOS(x) ((float)acos(x)) 00090 00091 #endif 00092 00093 00094 /* Fixed/float macro abstraction */ 00095 #ifdef PVRTFIXEDPOINTENABLE 00096 00097 /* Fixed-point operations, including trig tables */ 00098 #define VERTTYPEMUL(a,b) PVRTXMUL(a,b) 00099 #define VERTTYPEDIV(a,b) PVRTXDIV(a,b) 00100 #define VERTTYPEABS(a) PVRTABS(a) 00101 00102 #define f2vt(f) PVRTF2X(f) 00103 #define vt2f(x) PVRTX2F(x) 00104 00105 #define PVRTPIOVERTWO PVRTPIOVERTWOx 00106 #define PVRTPI PVRTPIx 00107 #define PVRTTWOPI PVRTTWOPIx 00108 #define PVRTONE PVRTONEx 00109 00110 #define PVRTCOS(x) PVRTXCOS(x) 00111 #define PVRTSIN(x) PVRTXSIN(x) 00112 #define PVRTTAN(x) PVRTXTAN(x) 00113 #define PVRTACOS(x) PVRTXACOS(x) 00114 00115 #else 00116 00117 /* Floating-point operations */ 00118 #define VERTTYPEMUL(a,b) ( (VERTTYPE)((a)*(b)) ) 00119 #define VERTTYPEDIV(a,b) ( (VERTTYPE)((a)/(b)) ) 00120 #define VERTTYPEABS(a) ( (VERTTYPE)(fabs(a)) ) 00121 00122 #define f2vt(x) (x) 00123 #define vt2f(x) (x) 00124 00125 #define PVRTPIOVERTWO PVRTPIOVERTWOf 00126 #define PVRTPI PVRTPIf 00127 #define PVRTTWOPI PVRTTWOPIf 00128 #define PVRTONE PVRTONEf 00129 00130 /* If trig tables are forced ON in non-fixed-point builds then convert fixed-point trig tables results to float */ 00131 #define PVRTCOS(x) PVRTFCOS(x) 00132 #define PVRTSIN(x) PVRTFSIN(x) 00133 #define PVRTTAN(x) PVRTFTAN(x) 00134 #define PVRTACOS(x) PVRTFACOS(x) 00135 00136 #endif 00137 00138 00139 // Structure Definitions 00140 00141 /*!*************************************************************************** 00142 Defines the format of a header-object as exported by the MAX 00143 plugin. 00144 *****************************************************************************/ 00145 00146 typedef struct { 00147 unsigned int nNumVertex; 00148 unsigned int nNumFaces; 00149 unsigned int nNumStrips; 00150 unsigned int nFlags; 00151 unsigned int nMaterial; 00152 float fCenter[3]; 00153 float *pVertex; 00154 float *pUV; 00155 float *pNormals; 00156 float *pPackedVertex; 00157 unsigned int *pVertexColor; 00158 unsigned int *pVertexMaterial; 00159 unsigned short *pFaces; 00160 unsigned short *pStrips; 00161 unsigned short *pStripLength; 00162 struct 00163 { 00164 unsigned int nType; 00165 unsigned int nNumPatches; 00166 unsigned int nNumVertices; 00167 unsigned int nNumSubdivisions; 00168 float *pControlPoints; 00169 float *pUVs; 00170 } Patch; 00171 } HeaderStruct_Mesh; 00172 00173 00174 #ifdef PVRTFIXEDPOINTENABLE 00175 00176 /*!*************************************************************************** 00177 Defines the format of a header-object as when converted to 00178 fixed point. 00179 *****************************************************************************/ 00180 00181 typedef struct { 00182 unsigned int nNumVertex; 00183 unsigned int nNumFaces; 00184 unsigned int nNumStrips; 00185 unsigned int nFlags; 00186 unsigned int nMaterial; 00187 VERTTYPE fCenter[3]; 00188 VERTTYPE *pVertex; 00189 VERTTYPE *pUV; 00190 VERTTYPE *pNormals; 00191 VERTTYPE *pPackedVertex; 00192 unsigned int *pVertexColor; 00193 unsigned int *pVertexMaterial; 00194 unsigned short *pFaces; 00195 unsigned short *pStrips; 00196 unsigned short *pStripLength; 00197 struct 00198 { 00199 unsigned int nType; // for the moment, these are left as floats 00200 unsigned int nNumPatches; 00201 unsigned int nNumVertices; 00202 unsigned int nNumSubdivisions; 00203 float *pControlPoints; 00204 float *pUVs; 00205 } Patch; 00206 } HeaderStruct_Fixed_Mesh; 00207 00208 typedef HeaderStruct_Fixed_Mesh HeaderStruct_Mesh_Type; 00209 #else 00210 typedef HeaderStruct_Mesh HeaderStruct_Mesh_Type; 00211 #endif 00212 00213 // Function prototypes 00214 00215 /*!*************************************************************************** 00216 @Function PVRTLoadHeaderObject 00217 @Input headerObj Pointer to object structure in the header file 00218 @Return directly usable geometry in fixed or float format as appropriate 00219 @Description Converts the data exported by MAX to fixed point when used in OpenGL 00220 ES common-lite profile. 00221 *****************************************************************************/ 00222 HeaderStruct_Mesh_Type* PVRTLoadHeaderObject(const void *headerObj); 00223 00224 /*!*************************************************************************** 00225 @Function PVRTUnloadHeaderObject 00226 @Input headerObj Pointer returned by LoadHeaderObject 00227 @Description Releases memory allocated by LoadHeaderObject when geometry no longer 00228 needed. 00229 *****************************************************************************/ 00230 void PVRTUnloadHeaderObject(HeaderStruct_Mesh_Type* headerObj); 00231 00232 00233 #endif /* _PVRTFIXEDPOINT_H_ */ 00234 00235 /***************************************************************************** 00236 End of file (PVRTFixedPoint.h) 00237 *****************************************************************************/
Copyright © 1999-2006, PowerVR Technologies and partners. PowerVR Technologies is a division of Imagination Technologies Ltd.