1 #ifndef __RIDEFS_H |
|
2 #define __RIDEFS_H |
|
3 |
|
4 /*------------------------------------------------------------------------ |
|
5 * |
|
6 * OpenVG 1.1 Reference Implementation |
|
7 * ----------------------------------- |
|
8 * |
|
9 * Copyright (c) 2007 The Khronos Group Inc. |
|
10 * Portions copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
11 * |
|
12 * Permission is hereby granted, free of charge, to any person obtaining a |
|
13 * copy of this software and /or associated documentation files |
|
14 * (the "Materials "), to deal in the Materials without restriction, |
|
15 * including without limitation the rights to use, copy, modify, merge, |
|
16 * publish, distribute, sublicense, and/or sell copies of the Materials, |
|
17 * and to permit persons to whom the Materials are furnished to do so, |
|
18 * subject to the following conditions: |
|
19 * |
|
20 * The above copyright notice and this permission notice shall be included |
|
21 * in all copies or substantial portions of the Materials. |
|
22 * |
|
23 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
26 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
|
27 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
|
28 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR |
|
29 * THE USE OR OTHER DEALINGS IN THE MATERIALS. |
|
30 * |
|
31 *//** |
|
32 * \file |
|
33 * \brief Platform- and compiler-dependent type and macro definitions. |
|
34 * \note |
|
35 *//*-------------------------------------------------------------------*/ |
|
36 |
|
37 #include <float.h> |
|
38 #include <math.h> |
|
39 #include <assert.h> |
|
40 #include <new> //for bad_alloc |
|
41 |
|
42 #if defined(_WIN32) && defined(_DEBUG) |
|
43 # define WIN32_LEAN_AND_MEAN |
|
44 # include <windows.h> |
|
45 #endif |
|
46 |
|
47 //make for-clause scope c++ standard compliant on msvc |
|
48 #if defined (_MSC_VER) |
|
49 # if !defined (for) |
|
50 __forceinline bool getFalse (void) { return false; } |
|
51 # define for if(getFalse()); else for |
|
52 # endif // for |
|
53 |
|
54 #pragma warning(disable:4710) //disable function not inlined warning |
|
55 #pragma warning(disable:4714) //disable function not __forceinlined warning |
|
56 #endif // _MSC_VER |
|
57 |
|
58 namespace OpenVGRI |
|
59 { |
|
60 |
|
61 //======================================================================= |
|
62 |
|
63 typedef long long RIint64; |
|
64 typedef unsigned long long RIuint64; |
|
65 typedef int RIint32; |
|
66 typedef unsigned int RIuint32; |
|
67 typedef short RIint16; |
|
68 typedef unsigned short RIuint16; |
|
69 typedef signed char RIint8; |
|
70 typedef unsigned char RIuint8; |
|
71 typedef float RIfloat32; |
|
72 //TODO add compile-time assertions to guarantee the sizes |
|
73 |
|
74 #if defined (_MSC_VER) // MSVC WIN32 |
|
75 # define RI_INLINE __forceinline |
|
76 #elif defined __APPLE__ || defined (__GNUC__) || defined (__GCC32__) |
|
77 # define RI_INLINE inline |
|
78 #endif |
|
79 |
|
80 /*!< Unsigned int that can hold a pointer to any type */ |
|
81 /*!< Signed int that can hold a pointer to any type */ |
|
82 #if defined (_MSC_VER) && (_MSC_VER >= 1300) |
|
83 typedef uintptr_t RIuintptr; |
|
84 typedef intptr_t RIintptr; |
|
85 #else |
|
86 typedef unsigned long RIuintptr; |
|
87 typedef signed long RIintptr; |
|
88 #endif |
|
89 |
|
90 #define RI_UINT32_MAX (0xffffffffu) |
|
91 #define RI_INT32_MAX (0x7fffffff) |
|
92 #define RI_INT32_MIN (-0x7fffffff-1) |
|
93 |
|
94 /* maximum mantissa is 23 */ |
|
95 #define RI_MANTISSA_BITS 23 |
|
96 |
|
97 /* maximum exponent is 8 */ |
|
98 #define RI_EXPONENT_BITS 8 |
|
99 |
|
100 typedef union |
|
101 { |
|
102 RIfloat32 f; |
|
103 RIuint32 i; |
|
104 } RIfloatInt; |
|
105 |
|
106 RI_INLINE float getFloatMax() |
|
107 { |
|
108 RIfloatInt v; |
|
109 v.i = (((1<<(RI_EXPONENT_BITS-1))-1+127) << 23) | (((1<<RI_MANTISSA_BITS)-1) << (23-RI_MANTISSA_BITS)); |
|
110 return v.f; |
|
111 } |
|
112 #define RI_FLOAT_MAX getFloatMax() |
|
113 |
|
114 #define RI_MAX_IMAGE_WIDTH 16384 |
|
115 #define RI_MAX_IMAGE_HEIGHT 16384 |
|
116 #define RI_MAX_IMAGE_PIXELS (RI_MAX_IMAGE_WIDTH*RI_MAX_IMAGE_HEIGHT) |
|
117 #define RI_MAX_IMAGE_BYTES (4*RI_MAX_IMAGE_WIDTH*RI_MAX_IMAGE_HEIGHT) |
|
118 #define RI_MAX_DASH_COUNT 256 |
|
119 #define RI_MAX_COLOR_RAMP_STOPS 256 |
|
120 #define RI_MAX_KERNEL_SIZE 256 |
|
121 #define RI_MAX_SEPARABLE_KERNEL_SIZE 256 |
|
122 #define RI_MAX_GAUSSIAN_STD_DEVIATION 16.0f |
|
123 #define RI_MAX_SCISSOR_RECTANGLES 256 |
|
124 #define RI_MAX_EDGES 262144 |
|
125 #define RI_MAX_SAMPLES 1 |
|
126 //#define RI_NUM_TESSELLATED_SEGMENTS_QUAD 256 |
|
127 //#define RI_NUM_TESSELLATED_SEGMENTS_CUBIC 256 |
|
128 //#define RI_NUM_TESSELLATED_SEGMENTS_ARC 256 |
|
129 #define RI_NUM_TESSELLATED_SEGMENTS_QUAD 8 |
|
130 #define RI_NUM_TESSELLATED_SEGMENTS_CUBIC 8 |
|
131 #define RI_NUM_TESSELLATED_SEGMENTS_ARC 8 |
|
132 |
|
133 #if !defined(_WIN32) && !defined(SF_PROFILE) |
|
134 # ifndef NDEBUG |
|
135 # define _DEBUG 1 |
|
136 # endif |
|
137 #endif |
|
138 |
|
139 #if _DEBUG |
|
140 #define RI_DEBUG |
|
141 #endif |
|
142 |
|
143 #ifdef RI_DEBUG |
|
144 # define RI_ASSERT(X) assert(X) |
|
145 #else |
|
146 # define RI_ASSERT(X) (void(0)) |
|
147 #endif |
|
148 |
|
149 #if defined(RI_DEBUG) |
|
150 # define RI_PRINTF(...) printf(__VA_ARGS__) |
|
151 #else |
|
152 # define RI_PRINTF(...) |
|
153 #endif |
|
154 |
|
155 #if defined(RI_DEBUG) |
|
156 # if defined(_WIN32) |
|
157 # define RI_TRACE(...) do { \ |
|
158 char buf[512]; \ |
|
159 snprintf(buf, sizeof(buf), __VA_ARGS__); \ |
|
160 OutputDebugString(buf); \ |
|
161 } while(false) |
|
162 # else |
|
163 # define RI_TRACE(...) printf(__VA_ARGS__) |
|
164 # endif |
|
165 #else |
|
166 # define RI_TRACE(...) |
|
167 #endif |
|
168 |
|
169 #define RI_UNREF(X) ((void)(X)) |
|
170 #if defined(_WIN32) |
|
171 # define RI_APIENTRY VG_API_ENTRY |
|
172 #else |
|
173 # define RI_APIENTRY |
|
174 #endif |
|
175 |
|
176 #if defined(_WIN32) |
|
177 # define snprintf sprintf_s |
|
178 #endif |
|
179 |
|
180 #define RI_API_CALL VG_API_CALL |
|
181 |
|
182 #define RI_NEW(TYPE, PARAMS) (new TYPE PARAMS) |
|
183 #define RI_NEW_ARRAY(TYPE, ITEMS) (new TYPE[ITEMS]) |
|
184 #define RI_DELETE(PARAMS) (delete (PARAMS)) |
|
185 #define RI_DELETE_ARRAY(PARAMS) (delete[] (PARAMS)) |
|
186 |
|
187 bool isValidImageFormat(int format); |
|
188 |
|
189 // \todo Move these to utility functions, etc. |
|
190 RI_INLINE void RI_MEM_ZERO(void *dst, size_t n) |
|
191 { |
|
192 RI_ASSERT(n > 0); |
|
193 RI_ASSERT((n & 0x3) == 0); |
|
194 |
|
195 RIuint32 *ptr = (RIuint32*)dst; |
|
196 for(size_t i = 0; i < (n>>2); i++) |
|
197 { |
|
198 *ptr++ = 0; |
|
199 } |
|
200 } |
|
201 |
|
202 //======================================================================= |
|
203 |
|
204 } //namespace OpenVGRI |
|
205 |
|
206 #endif /* __RIDEFS_H */ |
|