]> git.mxchange.org Git - simgear.git/blob - simgear/canvas/ShivaVG/src/shDefs.h
Update for OpenSceneGraph 3.3.2 API changes.
[simgear.git] / simgear / canvas / ShivaVG / src / shDefs.h
1 /*
2  * Copyright (c) 2007 Ivan Leben
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  * 
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  * 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library in the file COPYING;
16  * if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18  *
19  */
20
21 #ifndef __SHDEFS_H
22 #define __SHDEFS_H
23
24 /* Standard headers */
25
26 #include "shConfig.h"
27
28 #ifdef VG_API_WINDOWS
29 #  include <windows.h>
30 #endif
31
32 #include <stdlib.h>
33 #include <assert.h>
34 #include <math.h>
35 #include <float.h>
36
37 #if !defined(VG_API_MACOSX) && !defined(__FreeBSD__)
38 #  include <malloc.h>
39 #endif
40
41 /* Disable VGHandle-pointer conversion warnings since we
42    do deal with it by defining VGHandle properly */
43
44 #if defined(_MSC_VER)
45 #  pragma warning(disable:4311)
46 #  pragma warning(disable:4312)
47 #endif
48
49 /* Type definitions */
50
51 #if HAVE_INTTYPES_H
52
53     #include <inttypes.h>
54
55 #else
56
57     #define int8_t    char
58     #define uint8_t   unsigned char
59     #define int16_t   short
60     #define uint16_t  unsigned short
61     #define int32_t   int
62     #define uint32_t  unsigned int
63     #define int64_t   long long
64     #define uint64_t  unsigned long long
65
66 #endif
67
68 typedef int8_t      SHint8;
69 typedef uint8_t     SHuint8;
70 typedef int16_t     SHint16;
71 typedef uint16_t    SHuint16;
72 typedef int32_t     SHint32;
73 typedef uint32_t    SHuint32;
74 typedef float       SHfloat32;
75
76 #define SHint   SHint32
77 #define SHuint  SHuint32
78 #define SHfloat SHfloat32
79
80 /* Maximum / minimum values */
81
82 #define SH_MAX_INT  (0x7fffffff)
83 #define SH_MIN_INT (-0x7fffffff-1)
84
85 #define SH_MANTISSA_BITS   23
86 #define SH_EXPONENT_BITS   8
87
88 /* all 1s in exponent yields NaN in IEEE 754 so we take
89    1 less then maximum representable with exponent bits */
90 #define SH_MAX_EXPONENT ((1 << SH_EXPONENT_BITS) - 2)
91 /* maximum representable with mantissa bits */
92 #define SH_MAX_MANTISSA ((1 << SH_MANTISSA_BITS) - 1)
93 /* compose into IEEE754 floating point bit value */
94 #define SH_MAX_FLOAT_BITS (SH_MAX_EXPONENT << SH_MANTISSA_BITS) | SH_MAX_MANTISSA
95
96 typedef union {
97   float f;
98   unsigned int i;
99 } SHfloatint;
100
101 SHfloat getMaxFloat();
102
103 /* Portable function definitions */
104
105 #define SH_SQRT   (float)sqrt
106 #define SH_COS    (float)cos
107 #define SH_SIN    (float)sin
108 #define SH_ACOS   (float)acos
109 #define SH_ASIN   (float)asin
110 #define SH_ATAN   (float)atan
111 #define SH_FLOOR  (float)floor
112 #define SH_CEIL   (float)ceil
113 #define SH_ASSERT assert
114
115 #if defined(__isnan) || (defined(__APPLE__) && (__GNUC__ == 3))
116 #  define SH_ISNAN __isnan
117 #elif defined(_isnan) || defined(WIN32)
118 #  define SH_ISNAN _isnan
119 #else
120 #  define SH_ISNAN isnan
121 #endif
122
123
124 /* Helper macros */
125
126 #define PI 3.141592654f
127 #define SH_DEG2RAD(a) (a * PI / 180.0f)
128 #define SH_RAD2DEG(a) (a * 180.0f / PI)
129 #define SH_ABS(a) ((a < 0.0f) ? -a : a)
130 #define SH_MAX(a,b) ((a > b) ? a : b)
131 #define SH_MIN(a,b) ((a < b) ? a : b)
132 #define SH_NEARZERO(a) (a >= -0.0001 && a < 0.0001)
133 #define SH_SWAP(a,b) {SHfloat t=a; a=b; b=t;}
134 #define SH_CLAMP(a,min,max) {if (a<min) a=min; if (a>max) a=max; }
135
136 #define SH_NEWOBJ(type,obj) { obj = (type*)malloc(sizeof(type)); if(obj) type ## _ctor(obj); }
137 #define SH_INITOBJ(type,obj){ type ## _ctor(&obj); }
138 #define SH_DEINITOBJ(type,obj) { type ## _dtor(&obj); }
139 #define SH_DELETEOBJ(type,obj) { if(obj) type ## _dtor(obj); free(obj); }
140
141 /* Implementation limits */
142
143 #define SH_MAX_SCISSOR_RECTS             1
144 #define SH_MAX_DASH_COUNT                VG_MAXINT
145 #define SH_MAX_IMAGE_WIDTH               VG_MAXINT
146 #define SH_MAX_IMAGE_HEIGHT              VG_MAXINT
147 #define SH_MAX_IMAGE_PIXELS              VG_MAXINT
148 #define SH_MAX_IMAGE_BYTES               VG_MAXINT
149 #define SH_MAX_COLOR_RAMP_STOPS          256
150
151 #define SH_MAX_VERTICES 999999999
152 #define SH_MAX_RECURSE_DEPTH 16
153
154 #define SH_GRADIENT_TEX_SIZE       1024
155 #define SH_GRADIENT_TEX_COORDSIZE   4096 /* 1024 * RGBA */
156
157 /* OpenGL headers */
158
159 #if defined(VG_API_LINUX)
160     #include <GL/gl.h>
161     #include <GL/glx.h>
162 #elif defined(VG_API_MACOSX)
163     #include <OpenGL/gl.h>
164 #elif defined(VG_API_WINDOWS)
165     #include <GL/gl.h>
166 #else
167     #define GL_GLEXT_LEGACY /* don't include glext.h */
168     #include <GL/gl.h>
169     #include <GL/glx.h>
170 #endif
171
172 #include "shExtensions.h"
173
174
175 #endif /* __SHDEFS_H */