|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef UTIL_H |
|
19 #define UTIL_H |
|
20 |
|
21 |
|
22 |
|
23 //#define ENABLE_TRACE |
|
24 #undef ENABLE_TRACE |
|
25 |
|
26 #if (defined ENABLE_TRACE) && (!defined __SYMBIAN32__) |
|
27 #include <iostream> |
|
28 #endif |
|
29 |
|
30 #if (defined ENABLE_TRACE) && (defined __SYMBIAN32__) |
|
31 #include <e32def.h> |
|
32 #include <e32debug.h> |
|
33 #endif |
|
34 |
|
35 #ifndef SG_ASSERT |
|
36 #include <assert.h> |
|
37 #define SG_ASSERT assert |
|
38 #endif |
|
39 |
|
40 namespace shadergen |
|
41 { |
|
42 |
|
43 #ifdef _DEBUG |
|
44 #define DEBUG |
|
45 #endif |
|
46 |
|
47 /* Compile-time assertion */ |
|
48 #define SG_CT_MAKE_NAME(f, l) sg_ct_assert_failure_##f##l |
|
49 #define SG_CT_UNIQUE_NAME SG_CT_MAKE_NAME(__FILE__, __LINE__) |
|
50 |
|
51 #define SG_CT_ASSERT(cond) typedef char SG_CT_UNIQUE_NAME[(cond) ? 1 : -1] |
|
52 |
|
53 #define SG_LENGTH_OF_ARRAY(arr) (sizeof(arr) / sizeof((arr)[0])) |
|
54 |
|
55 |
|
56 #if (defined ENABLE_TRACE) && (defined __SYMBIAN32__) |
|
57 |
|
58 #define MY_TRACE(str) RDebug::Print(_L(str)) |
|
59 #define RAW_TRACE(str) RDebug::Printf(str) |
|
60 #define TRACE_FUNC_ENTRY() (RAW_TRACE(__FUNCTION__)) |
|
61 #elif (defined ENABLE_TRACE) && (!defined __SYMBIAN32__) |
|
62 #define MY_TRACE(str) std::cout << (str) << '\n' |
|
63 #define RAW_TRACE(str) std::cout << (str) << '\n' |
|
64 #define TRACE_FUNC_ENTRY() (MY_TRACE(__FUNCTION__)) |
|
65 #elif !defined ENABLE_TRACE |
|
66 #define MY_TRACE(str) |
|
67 #define RAW_TRACE(str) |
|
68 #define TRACE_FUNC_ENTRY() |
|
69 #endif |
|
70 |
|
71 |
|
72 |
|
73 template<class T> inline bool SG_IN_RANGE (const T& x, const T& mn, const T& mx) |
|
74 { |
|
75 return x <= mx && x >= mn; |
|
76 } |
|
77 |
|
78 |
|
79 typedef struct _Vec4 |
|
80 { |
|
81 float x, y, z, w; |
|
82 } Vec4; |
|
83 |
|
84 SG_CT_ASSERT(sizeof(Vec4) == 4 * sizeof(float)); |
|
85 |
|
86 } /* namespace shadergen */ |
|
87 |
|
88 #endif /* UTIL_H */ |