sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description: Global definitions
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
#ifndef __M3G_DEFS_H__
|
sl@0
|
19 |
#define __M3G_DEFS_H__
|
sl@0
|
20 |
|
sl@0
|
21 |
/*!
|
sl@0
|
22 |
* \internal
|
sl@0
|
23 |
* \file
|
sl@0
|
24 |
* \brief Global definitions for the Nokia M3G API implementation
|
sl@0
|
25 |
*/
|
sl@0
|
26 |
|
sl@0
|
27 |
/* Include public API */
|
sl@0
|
28 |
#include "M3G/m3g_core.h"
|
sl@0
|
29 |
|
sl@0
|
30 |
#if defined(__cplusplus)
|
sl@0
|
31 |
extern "C" {
|
sl@0
|
32 |
#endif
|
sl@0
|
33 |
|
sl@0
|
34 |
/* Try to recognize debug builds */
|
sl@0
|
35 |
#if defined(_DEBUG) || defined(DEBUG)
|
sl@0
|
36 |
#undef M3G_DEBUG
|
sl@0
|
37 |
#define M3G_DEBUG
|
sl@0
|
38 |
#endif
|
sl@0
|
39 |
|
sl@0
|
40 |
/*----------------------------------------------------------------------
|
sl@0
|
41 |
* Platform dependent definitions
|
sl@0
|
42 |
*--------------------------------------------------------------------*/
|
sl@0
|
43 |
|
sl@0
|
44 |
/* Define constants for use in m3g_config.h */
|
sl@0
|
45 |
|
sl@0
|
46 |
#define M3G_LOG_FATAL_ERRORS 0x0001
|
sl@0
|
47 |
#define M3G_LOG_USER_ERRORS 0x0002
|
sl@0
|
48 |
#define M3G_LOG_WARNINGS 0x0003
|
sl@0
|
49 |
#define M3G_LOG_PROFILE 0x0004
|
sl@0
|
50 |
#define M3G_LOG_INTERFACE 0x0010
|
sl@0
|
51 |
#define M3G_LOG_OBJECTS 0x0020
|
sl@0
|
52 |
#define M3G_LOG_STAGES 0x0040
|
sl@0
|
53 |
#define M3G_LOG_REFCOUNT 0x0080
|
sl@0
|
54 |
#define M3G_LOG_MEMORY_USAGE 0x0100
|
sl@0
|
55 |
#define M3G_LOG_MEMORY_BLOCKS 0x0200
|
sl@0
|
56 |
#define M3G_LOG_MEMORY_MAPPING 0x0400
|
sl@0
|
57 |
#define M3G_LOG_MEMORY_ALL 0x0F00
|
sl@0
|
58 |
#define M3G_LOG_RENDERING 0x1000
|
sl@0
|
59 |
#define M3G_LOG_IMAGES 0x2000
|
sl@0
|
60 |
#define M3G_LOG_ALL 0xFFFF
|
sl@0
|
61 |
|
sl@0
|
62 |
/* Include the platform configuration file; the possible configuration
|
sl@0
|
63 |
* options are documented and their default values set below */
|
sl@0
|
64 |
|
sl@0
|
65 |
#include "m3g_config.h"
|
sl@0
|
66 |
|
sl@0
|
67 |
/*!
|
sl@0
|
68 |
* \internal
|
sl@0
|
69 |
* \def M3G_TARGET_GENERIC
|
sl@0
|
70 |
* \brief Enables a generic C build
|
sl@0
|
71 |
*/
|
sl@0
|
72 |
/*!
|
sl@0
|
73 |
* \internal
|
sl@0
|
74 |
* \def M3G_TARGET_ISA
|
sl@0
|
75 |
* \brief Enables building for ISA
|
sl@0
|
76 |
*/
|
sl@0
|
77 |
/*!
|
sl@0
|
78 |
* \internal
|
sl@0
|
79 |
* \def M3G_TARGET_SYMBIAN
|
sl@0
|
80 |
* \brief Enables building for Symbian
|
sl@0
|
81 |
*/
|
sl@0
|
82 |
/*!
|
sl@0
|
83 |
* \internal
|
sl@0
|
84 |
* \def M3G_TARGET_WIN32
|
sl@0
|
85 |
* \brief Enables building for Win32
|
sl@0
|
86 |
*/
|
sl@0
|
87 |
#if defined(M3G_TARGET_GENERIC)
|
sl@0
|
88 |
#elif defined(M3G_TARGET_ISA)
|
sl@0
|
89 |
#elif defined(M3G_TARGET_SYMBIAN)
|
sl@0
|
90 |
#elif defined(M3G_TARGET_WIN32)
|
sl@0
|
91 |
#elif defined(S_SPLINT_S) /* auto-recognize Splint as a special case */
|
sl@0
|
92 |
# define M3G_TARGET_GENERIC
|
sl@0
|
93 |
#else
|
sl@0
|
94 |
# error Build target undefined! Supply one of the M3G_TARGET_* definitions.
|
sl@0
|
95 |
#endif
|
sl@0
|
96 |
|
sl@0
|
97 |
/*!
|
sl@0
|
98 |
* \internal
|
sl@0
|
99 |
* \def M3G_USE_NGL_API
|
sl@0
|
100 |
* \brief Enable the legacy "NGL" OpenGL context management interface
|
sl@0
|
101 |
*/
|
sl@0
|
102 |
#if defined(M3G_USE_NGL_API)
|
sl@0
|
103 |
# define M3G_NGL_CONTEXT_API
|
sl@0
|
104 |
# define M3G_NGL_TEXTURE_API
|
sl@0
|
105 |
#endif
|
sl@0
|
106 |
|
sl@0
|
107 |
#if defined(M3G_TARGET_ISA)
|
sl@0
|
108 |
# if !defined(M3G_NGL_CONTEXT_API)
|
sl@0
|
109 |
# error ISA builds must define M3G_USE_NGL_API
|
sl@0
|
110 |
# endif
|
sl@0
|
111 |
#endif
|
sl@0
|
112 |
#if defined(M3G_TARGET_SYMBIAN)
|
sl@0
|
113 |
# if defined(M3G_NGL_TEXTURE_API) || defined(M3G_NGL_CONTEXT_API)
|
sl@0
|
114 |
# error Legacy NGL API not supported in Symbian builds
|
sl@0
|
115 |
# endif
|
sl@0
|
116 |
#endif
|
sl@0
|
117 |
|
sl@0
|
118 |
/*!
|
sl@0
|
119 |
* \internal
|
sl@0
|
120 |
* \def M3G_ALIGNMENT
|
sl@0
|
121 |
* \brief Alignment, in bytes, mandated for internal data structures
|
sl@0
|
122 |
*
|
sl@0
|
123 |
* This must meet or exceed the alignment requirement of the
|
sl@0
|
124 |
* underlying hardware. The default is 4 bytes.
|
sl@0
|
125 |
*/
|
sl@0
|
126 |
#if !defined(M3G_ALIGNMENT)
|
sl@0
|
127 |
# define M3G_ALIGNMENT 4
|
sl@0
|
128 |
#endif
|
sl@0
|
129 |
|
sl@0
|
130 |
/*!
|
sl@0
|
131 |
* \internal
|
sl@0
|
132 |
* \def M3G_MAX_GL_CONTEXTS
|
sl@0
|
133 |
* \brief Maximum number of GL contexts to cache at once
|
sl@0
|
134 |
*
|
sl@0
|
135 |
* \note This only applies to builds using the EGL API.
|
sl@0
|
136 |
*/
|
sl@0
|
137 |
#if !defined(M3G_MAX_GL_CONTEXTS)
|
sl@0
|
138 |
# define M3G_MAX_GL_CONTEXTS 3
|
sl@0
|
139 |
#endif
|
sl@0
|
140 |
|
sl@0
|
141 |
/*!
|
sl@0
|
142 |
* \internal
|
sl@0
|
143 |
* \def M3G_MAX_GL_SURFACES
|
sl@0
|
144 |
* \brief Maximum number of GL surfaces to cache at once
|
sl@0
|
145 |
*
|
sl@0
|
146 |
* \note This only applies to builds using the EGL API.
|
sl@0
|
147 |
*/
|
sl@0
|
148 |
#if !defined(M3G_MAX_GL_SURFACES)
|
sl@0
|
149 |
# define M3G_MAX_GL_SURFACES 4
|
sl@0
|
150 |
#endif
|
sl@0
|
151 |
|
sl@0
|
152 |
/*!
|
sl@0
|
153 |
* \internal
|
sl@0
|
154 |
* \def M3G_MAX_LIGHTS
|
sl@0
|
155 |
* \brief Maximum number of lights in use simultaneously
|
sl@0
|
156 |
*
|
sl@0
|
157 |
* This is a rendering quality / performance trade-off; less lights
|
sl@0
|
158 |
* will be (slightly) faster, but reduce the quality of lighting.
|
sl@0
|
159 |
*
|
sl@0
|
160 |
* \note The value set here must not exceed the limits of the
|
sl@0
|
161 |
* underlying OpenGL implementation; this is not automatically
|
sl@0
|
162 |
* verified, but the default should be safe for all compliant OpenGL
|
sl@0
|
163 |
* ES implementation
|
sl@0
|
164 |
*/
|
sl@0
|
165 |
#if !defined(M3G_MAX_LIGHTS)
|
sl@0
|
166 |
# define M3G_MAX_LIGHTS 8
|
sl@0
|
167 |
#endif
|
sl@0
|
168 |
|
sl@0
|
169 |
/*!
|
sl@0
|
170 |
* \internal
|
sl@0
|
171 |
* \def M3G_MAX_TEXTURE_DIMENSION
|
sl@0
|
172 |
* \brief Maximum supported texture dimension
|
sl@0
|
173 |
*
|
sl@0
|
174 |
* \note The value set here must not exceed the limits of the
|
sl@0
|
175 |
* underlying OpenGL implementation; this is not automatically
|
sl@0
|
176 |
* verified, but the default should be safe for all compliant OpenGL
|
sl@0
|
177 |
* ES implementation
|
sl@0
|
178 |
*/
|
sl@0
|
179 |
#if !defined(M3G_MAX_TEXTURE_DIMENSION)
|
sl@0
|
180 |
# define M3G_MAX_TEXTURE_DIMENSION 256
|
sl@0
|
181 |
#endif
|
sl@0
|
182 |
|
sl@0
|
183 |
/*!
|
sl@0
|
184 |
* \internal
|
sl@0
|
185 |
* \def M3G_MAX_VERTEX_TRANSFORMS
|
sl@0
|
186 |
* \brief Maximum number of transforms per vertex
|
sl@0
|
187 |
*
|
sl@0
|
188 |
* \note The value set here must not exceed the limits of the
|
sl@0
|
189 |
* underlying OpenGL implementation; this is not automatically
|
sl@0
|
190 |
* verified
|
sl@0
|
191 |
*/
|
sl@0
|
192 |
#if !defined(M3G_MAX_VERTEX_TRANSFORMS)
|
sl@0
|
193 |
# define M3G_MAX_VERTEX_TRANSFORMS 4
|
sl@0
|
194 |
#endif
|
sl@0
|
195 |
|
sl@0
|
196 |
/*!
|
sl@0
|
197 |
* \internal
|
sl@0
|
198 |
* \def M3G_MAX_VIEWPORT_DIMENSION
|
sl@0
|
199 |
* \brief Maximum supported viewport dimension
|
sl@0
|
200 |
*
|
sl@0
|
201 |
* \note The value set here must not exceed the limits of the
|
sl@0
|
202 |
* underlying OpenGL implementation; this is not automatically
|
sl@0
|
203 |
* verified, but the default should be safe for all compliant OpenGL
|
sl@0
|
204 |
* ES implementation
|
sl@0
|
205 |
*/
|
sl@0
|
206 |
#if !defined(M3G_MAX_VIEWPORT_DIMENSION)
|
sl@0
|
207 |
# define M3G_MAX_VIEWPORT_DIMENSION 1024
|
sl@0
|
208 |
#endif
|
sl@0
|
209 |
|
sl@0
|
210 |
/*!
|
sl@0
|
211 |
* \internal
|
sl@0
|
212 |
* \def M3G_MAX_VIEWPORT_WIDTH
|
sl@0
|
213 |
* \brief Maximum supported viewport width
|
sl@0
|
214 |
*
|
sl@0
|
215 |
* \note The value set here must not exceed the limits of the
|
sl@0
|
216 |
* underlying OpenGL implementation; this is not automatically
|
sl@0
|
217 |
* verified, but the default should be safe for all compliant OpenGL
|
sl@0
|
218 |
* ES implementation
|
sl@0
|
219 |
*/
|
sl@0
|
220 |
#if !defined(M3G_MAX_VIEWPORT_WIDTH)
|
sl@0
|
221 |
# define M3G_MAX_VIEWPORT_WIDTH 1024
|
sl@0
|
222 |
#endif
|
sl@0
|
223 |
|
sl@0
|
224 |
/*!
|
sl@0
|
225 |
* \internal
|
sl@0
|
226 |
* \def M3G_MAX_VIEWPORT_HEIGHT
|
sl@0
|
227 |
* \brief Maximum supported viewport height
|
sl@0
|
228 |
*
|
sl@0
|
229 |
* \note The value set here must not exceed the limits of the
|
sl@0
|
230 |
* underlying OpenGL implementation; this is not automatically
|
sl@0
|
231 |
* verified, but the default should be safe for all compliant OpenGL
|
sl@0
|
232 |
* ES implementation
|
sl@0
|
233 |
*/
|
sl@0
|
234 |
#if !defined(M3G_MAX_VIEWPORT_HEIGHT)
|
sl@0
|
235 |
# define M3G_MAX_VIEWPORT_HEIGHT 1024
|
sl@0
|
236 |
#endif
|
sl@0
|
237 |
|
sl@0
|
238 |
/*!
|
sl@0
|
239 |
* \internal
|
sl@0
|
240 |
* \def M3G_NATIVE_LOADER
|
sl@0
|
241 |
* \brief Include a native loader implementation
|
sl@0
|
242 |
*
|
sl@0
|
243 |
* This is always enabled in current builds.
|
sl@0
|
244 |
*/
|
sl@0
|
245 |
#undef M3G_NATIVE_LOADER
|
sl@0
|
246 |
#define M3G_NATIVE_LOADER
|
sl@0
|
247 |
|
sl@0
|
248 |
/*!
|
sl@0
|
249 |
* \internal
|
sl@0
|
250 |
* \def M3G_NUM_TEXTURE_UNITS
|
sl@0
|
251 |
* \brief Number of texture units to support
|
sl@0
|
252 |
*
|
sl@0
|
253 |
* \note The value set here must not exceed the limits of the
|
sl@0
|
254 |
* underlying OpenGL implementation; this is not automatically
|
sl@0
|
255 |
* verified, but the default should be safe for all compliant OpenGL
|
sl@0
|
256 |
* ES implementation
|
sl@0
|
257 |
*/
|
sl@0
|
258 |
#if !defined(M3G_NUM_TEXTURE_UNITS)
|
sl@0
|
259 |
# define M3G_NUM_TEXTURE_UNITS 2
|
sl@0
|
260 |
#endif
|
sl@0
|
261 |
|
sl@0
|
262 |
/*!
|
sl@0
|
263 |
* \internal
|
sl@0
|
264 |
* \def M3G_SUPPORT_ANTIALIASING
|
sl@0
|
265 |
* \brief Enable or disable support for antialiasing
|
sl@0
|
266 |
*
|
sl@0
|
267 |
* \note This is currently only supported for Symbian.
|
sl@0
|
268 |
*/
|
sl@0
|
269 |
#if !defined(M3G_SUPPORT_ANTIALIASING)
|
sl@0
|
270 |
# if defined(M3G_NGL_CONTEXT_API)
|
sl@0
|
271 |
# define M3G_SUPPORT_ANTIALIASING M3G_FALSE
|
sl@0
|
272 |
# else
|
sl@0
|
273 |
# define M3G_SUPPORT_ANTIALIASING M3G_TRUE
|
sl@0
|
274 |
# endif
|
sl@0
|
275 |
#endif
|
sl@0
|
276 |
|
sl@0
|
277 |
/*!
|
sl@0
|
278 |
* \internal
|
sl@0
|
279 |
* \def M3G_SUPPORT_DITHERING
|
sl@0
|
280 |
* \brief Enable or disable support for dithering
|
sl@0
|
281 |
*/
|
sl@0
|
282 |
#if !defined(M3G_SUPPORT_DITHERING)
|
sl@0
|
283 |
# define M3G_SUPPORT_DITHERING M3G_FALSE
|
sl@0
|
284 |
#endif
|
sl@0
|
285 |
|
sl@0
|
286 |
/*!
|
sl@0
|
287 |
* \internal
|
sl@0
|
288 |
* \def M3G_SUPPORT_LOCAL_CAMERA_LIGHTING
|
sl@0
|
289 |
* \brief Enable or disable support for local camera lighting
|
sl@0
|
290 |
*/
|
sl@0
|
291 |
#if !defined(M3G_SUPPORT_LOCAL_CAMERA_LIGHTING)
|
sl@0
|
292 |
# define M3G_SUPPORT_LOCAL_CAMERA_LIGHTING M3G_FALSE
|
sl@0
|
293 |
#endif
|
sl@0
|
294 |
|
sl@0
|
295 |
/*!
|
sl@0
|
296 |
* \internal
|
sl@0
|
297 |
* \def M3G_SUPPORT_MIPMAPPING
|
sl@0
|
298 |
* \brief Enable or disable support for mipmapping
|
sl@0
|
299 |
*/
|
sl@0
|
300 |
#if !defined(M3G_SUPPORT_MIPMAPPING)
|
sl@0
|
301 |
# define M3G_SUPPORT_MIPMAPPING M3G_TRUE
|
sl@0
|
302 |
#endif
|
sl@0
|
303 |
|
sl@0
|
304 |
/*!
|
sl@0
|
305 |
* \internal
|
sl@0
|
306 |
* \def M3G_SUPPORT_PERSPECTIVE_CORRECTION
|
sl@0
|
307 |
* \brief Enable or disable support for perspective correct texturing
|
sl@0
|
308 |
*/
|
sl@0
|
309 |
#if !defined(M3G_SUPPORT_PERSPECTIVE_CORRECTION)
|
sl@0
|
310 |
# define M3G_SUPPORT_PERSPECTIVE_CORRECTION M3G_TRUE
|
sl@0
|
311 |
#endif
|
sl@0
|
312 |
|
sl@0
|
313 |
/*!
|
sl@0
|
314 |
* \internal
|
sl@0
|
315 |
* \def M3G_SUPPORT_TRUE_COLOR
|
sl@0
|
316 |
* \brief Enable or disable support for "true color" rendering
|
sl@0
|
317 |
*/
|
sl@0
|
318 |
#if !defined(M3G_SUPPORT_TRUE_COLOR)
|
sl@0
|
319 |
# define M3G_SUPPORT_TRUE_COLOR M3G_FALSE
|
sl@0
|
320 |
#endif
|
sl@0
|
321 |
|
sl@0
|
322 |
/*!
|
sl@0
|
323 |
* \internal
|
sl@0
|
324 |
* \def M3G_USE_16BIT_TEXTURES
|
sl@0
|
325 |
* \brief Use 16-bit RGB textures internally to save memory
|
sl@0
|
326 |
*
|
sl@0
|
327 |
* This may reduce in some loss of performance, so it is defined
|
sl@0
|
328 |
* M3G_FALSE by default.
|
sl@0
|
329 |
*/
|
sl@0
|
330 |
#if !defined(M3G_USE_16BIT_TEXTURES)
|
sl@0
|
331 |
# define M3G_USE_16BIT_TEXTURES M3G_FALSE
|
sl@0
|
332 |
#endif
|
sl@0
|
333 |
|
sl@0
|
334 |
/*!
|
sl@0
|
335 |
* \internal
|
sl@0
|
336 |
* \def M3G_LOGLEVEL
|
sl@0
|
337 |
*
|
sl@0
|
338 |
* \brief Controls the amount of log output
|
sl@0
|
339 |
*
|
sl@0
|
340 |
* Log output can be enabled by defining M3G_LOGLEVEL in m3g_config.h.
|
sl@0
|
341 |
* It must be set to a bitmask indicating which categories of log
|
sl@0
|
342 |
* messages to output. Fatal internal errors are always output when
|
sl@0
|
343 |
* M3G_LOGLEVEL is defined; other kinds of messages can be included by
|
sl@0
|
344 |
* setting it to any combination of the following in m3g_config.h:
|
sl@0
|
345 |
*
|
sl@0
|
346 |
* M3G_LOG_FATAL_ERRORS fatal internal errors (equals 0)
|
sl@0
|
347 |
* M3G_LOG_USER_ERRORS user errors (the same as reported
|
sl@0
|
348 |
* via m3gGetError)
|
sl@0
|
349 |
* M3G_LOG_WARNINGS performance warnings
|
sl@0
|
350 |
* M3G_LOG_PROFILE profiling counters
|
sl@0
|
351 |
* M3G_LOG_INTERFACE interface construction/destruction events
|
sl@0
|
352 |
* M3G_LOG_OBJECTS object construction/destruction events
|
sl@0
|
353 |
* M3G_LOG_STAGES log processing stages (animate, render, etc.)
|
sl@0
|
354 |
* M3G_LOG_REFCOUNT reference count operations
|
sl@0
|
355 |
* M3G_LOG_MEMORY_USAGE memory usage counters
|
sl@0
|
356 |
* M3G_LOG_MEMORY_BLOCKS memory block allocs/deallocs
|
sl@0
|
357 |
* M3G_LOG_MEMORY_ALL output everything memory-related
|
sl@0
|
358 |
* M3G_LOG_RENDERING log rendering details
|
sl@0
|
359 |
* M3G_LOG_IMAGES log image memory usage details
|
sl@0
|
360 |
*
|
sl@0
|
361 |
* \note The amount of log output may be limited in non-debug builds.
|
sl@0
|
362 |
*/
|
sl@0
|
363 |
|
sl@0
|
364 |
/*!
|
sl@0
|
365 |
* \internal
|
sl@0
|
366 |
* \def M3G_PROFILE_LOG_INTERVAL
|
sl@0
|
367 |
* \brief Profile logging interval
|
sl@0
|
368 |
*
|
sl@0
|
369 |
* Number of frames to wait between outputting (and resetting!) the
|
sl@0
|
370 |
* profiling counters. Zero (default) disables profile logging.
|
sl@0
|
371 |
*/
|
sl@0
|
372 |
#if !defined(M3G_PROFILE_LOG_INTERVAL)
|
sl@0
|
373 |
# define M3G_PROFILE_LOG_INTERVAL 0
|
sl@0
|
374 |
#endif
|
sl@0
|
375 |
|
sl@0
|
376 |
/*----------------------------------------------------------------------
|
sl@0
|
377 |
* Debug build setup
|
sl@0
|
378 |
*--------------------------------------------------------------------*/
|
sl@0
|
379 |
|
sl@0
|
380 |
/* General settings enabled in debug builds */
|
sl@0
|
381 |
#if defined(M3G_DEBUG)
|
sl@0
|
382 |
# define M3G_DEBUG_ASSERTS
|
sl@0
|
383 |
# define M3G_DEBUG_RANGE_CHECKING
|
sl@0
|
384 |
# define M3G_DEBUG_HEAP_TRACKING
|
sl@0
|
385 |
#endif
|
sl@0
|
386 |
|
sl@0
|
387 |
/*----------------------------------------------------------------------
|
sl@0
|
388 |
* Compiler dependent definitions
|
sl@0
|
389 |
*--------------------------------------------------------------------*/
|
sl@0
|
390 |
|
sl@0
|
391 |
/* Try to recognize the compiler */
|
sl@0
|
392 |
#if !defined(M3G_NO_COMPILER_DETECTION)
|
sl@0
|
393 |
# if (defined (_MSC_VER) || defined(__VC32__))&& !defined(__MWERKS__) /* Microsoft Visual C++ */
|
sl@0
|
394 |
# undef M3G_BUILD_MSVC
|
sl@0
|
395 |
# define M3G_BUILD_MSVC
|
sl@0
|
396 |
# elif defined(__ARMCC_VERSION) /* ARM Developer Suite */
|
sl@0
|
397 |
# undef M3G_BUILD_ADS
|
sl@0
|
398 |
# define M3G_BUILD_ADS
|
sl@0
|
399 |
# elif defined(__BORLANDC__) /* Borland C++ */
|
sl@0
|
400 |
# undef M3G_BUILD_BORLAND
|
sl@0
|
401 |
# define M3G_BUILD_BORLAND
|
sl@0
|
402 |
# elif defined(__MWERKS__) || defined(__CW32__) /* CodeWarrior */
|
sl@0
|
403 |
# undef M3G_BUILD_CW
|
sl@0
|
404 |
# define M3G_BUILD_CW
|
sl@0
|
405 |
# elif defined(__GNUC__) || defined(__GCC32__) /* GNU C */
|
sl@0
|
406 |
# undef M3G_BUILD_GCC
|
sl@0
|
407 |
# define M3G_BUILD_GCC
|
sl@0
|
408 |
# elif defined(__ARMCC__) /* RVCT */
|
sl@0
|
409 |
# undef M3G_BUILD_RVCT
|
sl@0
|
410 |
# define M3G_BUILD_RVCT
|
sl@0
|
411 |
# elif defined(S_SPLINT_S) /* Splint */
|
sl@0
|
412 |
# undef M3G_BUILD_SPLINT
|
sl@0
|
413 |
# define M3G_BUILD_SPLINT
|
sl@0
|
414 |
# else
|
sl@0
|
415 |
# error Could not identify the compiler. Please refer to m3g_defs.h for more information.
|
sl@0
|
416 |
# endif
|
sl@0
|
417 |
#endif
|
sl@0
|
418 |
|
sl@0
|
419 |
/* Try to recognize thumb/arm */
|
sl@0
|
420 |
#if defined(M3G_BUILD_ADS)
|
sl@0
|
421 |
# if defined(__thumb)
|
sl@0
|
422 |
# define M3G_BUILD_THUMB
|
sl@0
|
423 |
# else
|
sl@0
|
424 |
# define M3G_BUILD_ARM
|
sl@0
|
425 |
# endif
|
sl@0
|
426 |
#endif
|
sl@0
|
427 |
|
sl@0
|
428 |
/* Set up compiler-dependent definitions */
|
sl@0
|
429 |
|
sl@0
|
430 |
/*@-macroparams@*/
|
sl@0
|
431 |
/*@notfunction@*/
|
sl@0
|
432 |
/*!
|
sl@0
|
433 |
* \internal \brief Macro used to denote Splint constraints */
|
sl@0
|
434 |
#define M3G_SPLINT(def)
|
sl@0
|
435 |
/*@+macroparams@*/
|
sl@0
|
436 |
|
sl@0
|
437 |
/*!
|
sl@0
|
438 |
* \internal \def M3G_INLINE
|
sl@0
|
439 |
* \brief Platform-independent inline function specifier
|
sl@0
|
440 |
*/
|
sl@0
|
441 |
|
sl@0
|
442 |
#if defined(M3G_BUILD_MSVC)
|
sl@0
|
443 |
# define M3G_INLINE __inline
|
sl@0
|
444 |
# pragma warning (disable:4127) /* 4127: conditional expression is constant */
|
sl@0
|
445 |
# pragma warning (disable:4514) /* 4514: unreferenced inline function has been removed */
|
sl@0
|
446 |
# pragma warning (disable:4710) /* 4710: function not inlined */
|
sl@0
|
447 |
|
sl@0
|
448 |
#elif defined (M3G_BUILD_ADS)
|
sl@0
|
449 |
# define M3G_INLINE __inline
|
sl@0
|
450 |
|
sl@0
|
451 |
#elif defined(M3G_BUILD_BORLAND)
|
sl@0
|
452 |
# define M3G_INLINE __inline
|
sl@0
|
453 |
|
sl@0
|
454 |
#elif defined(M3G_BUILD_CW)
|
sl@0
|
455 |
# define M3G_INLINE
|
sl@0
|
456 |
|
sl@0
|
457 |
#elif defined(M3G_BUILD_GCC)
|
sl@0
|
458 |
# define M3G_INLINE inline
|
sl@0
|
459 |
|
sl@0
|
460 |
#elif defined(M3G_BUILD_RVCT)
|
sl@0
|
461 |
# define M3G_INLINE __inline
|
sl@0
|
462 |
|
sl@0
|
463 |
#elif defined(M3G_BUILD_SPLINT)
|
sl@0
|
464 |
# define M3G_INLINE
|
sl@0
|
465 |
# undef M3G_SPLINT
|
sl@0
|
466 |
/*@notfunction@*/
|
sl@0
|
467 |
# define M3G_SPLINT(def) def
|
sl@0
|
468 |
|
sl@0
|
469 |
# undef M3G_DEBUG
|
sl@0
|
470 |
/*# define M3G_DEBUG*/
|
sl@0
|
471 |
|
sl@0
|
472 |
#else /* generic fallback */
|
sl@0
|
473 |
# define M3G_INLINE
|
sl@0
|
474 |
|
sl@0
|
475 |
#endif
|
sl@0
|
476 |
|
sl@0
|
477 |
/* Optionally cancel non-portable definitions. This is mainly to
|
sl@0
|
478 |
* facilitate portability checking with GCC, which defines __STDC__
|
sl@0
|
479 |
* even in non-ANSI mode) */
|
sl@0
|
480 |
|
sl@0
|
481 |
#if defined(M3G_STRICT_STDC)
|
sl@0
|
482 |
# undef M3G_INLINE
|
sl@0
|
483 |
# define M3G_INLINE
|
sl@0
|
484 |
#endif
|
sl@0
|
485 |
|
sl@0
|
486 |
/*----------------------------------------------------------------------
|
sl@0
|
487 |
* Identify GL version
|
sl@0
|
488 |
*--------------------------------------------------------------------*/
|
sl@0
|
489 |
#if defined(GL_VERSION_ES_CM_1_1) || defined(GL_OES_VERSION_1_1)
|
sl@0
|
490 |
# define M3G_GL_ES_1_1
|
sl@0
|
491 |
#endif
|
sl@0
|
492 |
|
sl@0
|
493 |
/*----------------------------------------------------------------------
|
sl@0
|
494 |
* Internal configuration and performance tuning parameters
|
sl@0
|
495 |
*--------------------------------------------------------------------*/
|
sl@0
|
496 |
|
sl@0
|
497 |
#define M3G_RENDERQUEUE_BUCKET_BITS 8
|
sl@0
|
498 |
#define M3G_ENABLE_VF_CULLING
|
sl@0
|
499 |
#define M3G_GL_FORCE_PBUFFER_SIZE
|
sl@0
|
500 |
|
sl@0
|
501 |
/*----------------------------------------------------------------------
|
sl@0
|
502 |
* Standard C library
|
sl@0
|
503 |
*--------------------------------------------------------------------*/
|
sl@0
|
504 |
|
sl@0
|
505 |
#if defined(M3G_NO_STDLIB)
|
sl@0
|
506 |
# define NULL 0
|
sl@0
|
507 |
typedef M3Guint M3Gsize;
|
sl@0
|
508 |
#else
|
sl@0
|
509 |
# include <stdlib.h>
|
sl@0
|
510 |
typedef size_t M3Gsize;
|
sl@0
|
511 |
#endif
|
sl@0
|
512 |
|
sl@0
|
513 |
/*----------------------------------------------------------------------
|
sl@0
|
514 |
* Run time and compile time assertions
|
sl@0
|
515 |
*--------------------------------------------------------------------*/
|
sl@0
|
516 |
|
sl@0
|
517 |
/*!
|
sl@0
|
518 |
* \internal \def M3G_ASSERT(a)
|
sl@0
|
519 |
* \brief Run-time assertion
|
sl@0
|
520 |
*/
|
sl@0
|
521 |
#if defined(M3G_DEBUG_ASSERTS)
|
sl@0
|
522 |
|
sl@0
|
523 |
extern void m3gAssertFailed(const char *filename, int line);
|
sl@0
|
524 |
#define M3G_ASSERT(cond) \
|
sl@0
|
525 |
do { \
|
sl@0
|
526 |
if (!(cond)) m3gAssertFailed(__FILE__, __LINE__); \
|
sl@0
|
527 |
} while (M3G_FALSE)
|
sl@0
|
528 |
|
sl@0
|
529 |
M3G_SPLINT(extern /*@noreturnwhenfalse@*/ void M3G_ASSERT(/*@sef@*//*@null@*/ M3Gbool /*@alt const void*@*/ cond)/*@*/;)
|
sl@0
|
530 |
|
sl@0
|
531 |
#else
|
sl@0
|
532 |
|
sl@0
|
533 |
/*@-macroparams@*/
|
sl@0
|
534 |
# define M3G_ASSERT(cond)
|
sl@0
|
535 |
/*@+macroparams@*/
|
sl@0
|
536 |
M3G_SPLINT(extern /*@noreturnwhenfalse@*/ void M3G_ASSERT(/*@sef@*//*@null@*//*@unused@*/ M3Gbool /*@alt const void*@*/ cond)/*@*/;)
|
sl@0
|
537 |
|
sl@0
|
538 |
#endif /* M3G_DEBUG */
|
sl@0
|
539 |
|
sl@0
|
540 |
/*!
|
sl@0
|
541 |
* \internal
|
sl@0
|
542 |
* \brief Compile-time assertion
|
sl@0
|
543 |
*/
|
sl@0
|
544 |
/*@notfunction@*/
|
sl@0
|
545 |
#define M3G_CT_ASSERT(a) struct __M3G_UNIQUE_NAME { unsigned bf : (a) ? 1 : -1; }
|
sl@0
|
546 |
/*@notfunction@*/
|
sl@0
|
547 |
#define __M3G_UNIQUE_NAME __M3G_MAKE_UNIQUE_NAME(__LINE__, 0)
|
sl@0
|
548 |
/*@notfunction@*/
|
sl@0
|
549 |
#define __M3G_MAKE_UNIQUE_NAME(line, num) __M3G_MAKE_UNIQUE_NAME2(line, num)
|
sl@0
|
550 |
/*@notfunction@*/
|
sl@0
|
551 |
#define __M3G_MAKE_UNIQUE_NAME2(line, num) m3gCTassert ## num ## line
|
sl@0
|
552 |
|
sl@0
|
553 |
/*@notfunction@*/
|
sl@0
|
554 |
#define M3G_CT_ASSERT1(a) struct __M3G_UNIQUE_NAME1 { unsigned bf : (a) ? 1 : -1; }
|
sl@0
|
555 |
/*@notfunction@*/
|
sl@0
|
556 |
#define __M3G_UNIQUE_NAME1 M3G_MAKE_UNIQUE_NAME(__LINE__, 1)
|
sl@0
|
557 |
|
sl@0
|
558 |
/*@notfunction@*/
|
sl@0
|
559 |
#define M3G_CT_ASSERT2(a) struct __M3G_UNIQUE_NAME2 { unsigned bf : (a) ? 1 : -1; }
|
sl@0
|
560 |
/*@notfunction@*/
|
sl@0
|
561 |
#define __M3G_UNIQUE_NAME2 __M3G_MAKE_UNIQUE_NAME(__LINE__, 2)
|
sl@0
|
562 |
|
sl@0
|
563 |
#if defined(M3G_DEBUG_RANGE_CHECKING)
|
sl@0
|
564 |
#define M3G_ASSERT_RANGE(val, min, max) M3G_ASSERT(m3gInRange((val), (min), (max)))
|
sl@0
|
565 |
#else
|
sl@0
|
566 |
/*@-macroparams@*/
|
sl@0
|
567 |
#define M3G_ASSERT_RANGE(val, min, max)
|
sl@0
|
568 |
/*@+macroparams@*/
|
sl@0
|
569 |
#endif
|
sl@0
|
570 |
|
sl@0
|
571 |
/*----------------------------------------------------------------------
|
sl@0
|
572 |
* Verify any global definitions, expected type sizes etc.
|
sl@0
|
573 |
*--------------------------------------------------------------------*/
|
sl@0
|
574 |
|
sl@0
|
575 |
#if !defined(M3G_INLINE)
|
sl@0
|
576 |
# error M3G_INLINE not defined in platform definitions!
|
sl@0
|
577 |
#endif
|
sl@0
|
578 |
|
sl@0
|
579 |
#if !defined(M3G_ALIGNMENT)
|
sl@0
|
580 |
# error M3G_ALIGNMENT not defined in platform definitions!
|
sl@0
|
581 |
#endif
|
sl@0
|
582 |
|
sl@0
|
583 |
#if ((M3G_ALIGNMENT & (M3G_ALIGNMENT-1)) != 0)
|
sl@0
|
584 |
# error M3G_ALIGNMENT is not a power of two!
|
sl@0
|
585 |
#endif
|
sl@0
|
586 |
|
sl@0
|
587 |
#if defined(M3G_TARGET_ISA) && !defined(M3G_USE_NGL_API)
|
sl@0
|
588 |
# error ISA targets currently supported with M3G_USE_NGL_API only!
|
sl@0
|
589 |
#endif
|
sl@0
|
590 |
|
sl@0
|
591 |
#if (defined(M3G_NGL_CONTEXT_API) && !defined(M3G_NGL_TEXTURE_API)) \
|
sl@0
|
592 |
|| (defined(M3G_NGL_TEXTURE_API) && !defined(M3G_NGL_CONTEXT_API))
|
sl@0
|
593 |
# if !defined(M3G_DEBUG)
|
sl@0
|
594 |
# error Nonstandard NGL configurations only allowed in debug builds!
|
sl@0
|
595 |
# endif
|
sl@0
|
596 |
#endif
|
sl@0
|
597 |
|
sl@0
|
598 |
/* Verify our expected type sizes */
|
sl@0
|
599 |
M3G_CT_ASSERT(sizeof(M3Gbyte) == 1);
|
sl@0
|
600 |
M3G_CT_ASSERT(sizeof(M3Gubyte) == 1);
|
sl@0
|
601 |
M3G_CT_ASSERT(sizeof(M3Gshort) == 2);
|
sl@0
|
602 |
M3G_CT_ASSERT(sizeof(M3Gushort) == 2);
|
sl@0
|
603 |
M3G_CT_ASSERT(sizeof(M3Gint) == 4);
|
sl@0
|
604 |
M3G_CT_ASSERT(sizeof(M3Guint) == 4);
|
sl@0
|
605 |
M3G_CT_ASSERT(sizeof(M3Gfloat) == 4);
|
sl@0
|
606 |
|
sl@0
|
607 |
/* Unsigned is used extensively as a wrapper for object pointers, so
|
sl@0
|
608 |
* check that we can fit a pointer in there */
|
sl@0
|
609 |
M3G_CT_ASSERT(sizeof(M3Guint) >= sizeof(void*));
|
sl@0
|
610 |
|
sl@0
|
611 |
/*
|
sl@0
|
612 |
* Globally disable some redundant Lint messages
|
sl@0
|
613 |
*/
|
sl@0
|
614 |
|
sl@0
|
615 |
/*lint -e701 Signed shifts left should never be a problem */
|
sl@0
|
616 |
/*lint -e702 Signed shifts right are run-time verified (m3g_interface.c) */
|
sl@0
|
617 |
|
sl@0
|
618 |
/*----------------------------------------------------------------------
|
sl@0
|
619 |
* Event logging
|
sl@0
|
620 |
*--------------------------------------------------------------------*/
|
sl@0
|
621 |
|
sl@0
|
622 |
#if !defined(M3G_LOGLEVEL)
|
sl@0
|
623 |
# define M3G_LOG(level, msg) ((void)(level), (void)(msg))
|
sl@0
|
624 |
# define M3G_LOG1(level, msg, a) ((void)(level), (void)(msg), (void)(a))
|
sl@0
|
625 |
# define M3G_LOG2(level, msg, a, b) ((void)(level), (void)(msg), (void)(a), (void)(b))
|
sl@0
|
626 |
# define M3G_LOG3(level, msg, a, b, c) ((void)(level), (void)(msg), (void)(a), (void)(b), (void)(c))
|
sl@0
|
627 |
# define M3G_LOG4(level, msg, a, b, c, d) ((void)(level), (void)(msg), (void)(a), (void)(b), (void)(c), (void)(d))
|
sl@0
|
628 |
# define M3G_LOG5(level, msg, a, b, c, d, e) ((void)(level), (void)(msg), (void)(a), (void)(b), (void)(c), (void)(d), (void)(e))
|
sl@0
|
629 |
#else
|
sl@0
|
630 |
void m3gBeginLog(void);
|
sl@0
|
631 |
void m3gLogMessage(const char *format, ...);
|
sl@0
|
632 |
void m3gEndLog(void);
|
sl@0
|
633 |
# define M3G_LOG(level, msg) \
|
sl@0
|
634 |
do { if ((level) & (M3G_LOGLEVEL)) m3gLogMessage((msg)); } while (M3G_FALSE)
|
sl@0
|
635 |
# define M3G_LOG1(level, msg, a) \
|
sl@0
|
636 |
do { if ((level) & (M3G_LOGLEVEL)) m3gLogMessage((msg), (a)); } while (M3G_FALSE)
|
sl@0
|
637 |
# define M3G_LOG2(level, msg, a, b) \
|
sl@0
|
638 |
do { if ((level) & (M3G_LOGLEVEL)) m3gLogMessage((msg), (a), (b)); } while (M3G_FALSE)
|
sl@0
|
639 |
# define M3G_LOG3(level, msg, a, b, c) \
|
sl@0
|
640 |
do { if ((level) & (M3G_LOGLEVEL)) m3gLogMessage((msg), (a), (b), (c)); } while (M3G_FALSE)
|
sl@0
|
641 |
# define M3G_LOG4(level, msg, a, b, c, d) \
|
sl@0
|
642 |
do { if ((level) & (M3G_LOGLEVEL)) m3gLogMessage((msg), (a), (b), (c), (d)); } while (M3G_FALSE)
|
sl@0
|
643 |
# define M3G_LOG5(level, msg, a, b, c, d, e) \
|
sl@0
|
644 |
do { if ((level) & (M3G_LOGLEVEL)) m3gLogMessage((msg), (a), (b), (c), (d), (e)); } while (M3G_FALSE)
|
sl@0
|
645 |
#endif
|
sl@0
|
646 |
|
sl@0
|
647 |
/*----------------------------------------------------------------------
|
sl@0
|
648 |
* Useful stuff
|
sl@0
|
649 |
*--------------------------------------------------------------------*/
|
sl@0
|
650 |
|
sl@0
|
651 |
/*!
|
sl@0
|
652 |
* \internal
|
sl@0
|
653 |
* \brief Range checking inline function
|
sl@0
|
654 |
*
|
sl@0
|
655 |
* \param a Value to check
|
sl@0
|
656 |
* \param min Lower bound, inclusive
|
sl@0
|
657 |
* \param max Upper bound, inclusive
|
sl@0
|
658 |
*/
|
sl@0
|
659 |
static M3G_INLINE M3Gbool m3gInRange(M3Gint a, M3Gint min, M3Gint max)
|
sl@0
|
660 |
{
|
sl@0
|
661 |
return ((M3Guint)(a - min) <= (M3Guint)(max - min));
|
sl@0
|
662 |
}
|
sl@0
|
663 |
|
sl@0
|
664 |
/*!
|
sl@0
|
665 |
* \internal
|
sl@0
|
666 |
* \brief Range checking for floats
|
sl@0
|
667 |
*/
|
sl@0
|
668 |
static M3G_INLINE M3Gbool m3gInRangef(M3Gfloat a, M3Gfloat min, M3Gfloat max)
|
sl@0
|
669 |
{
|
sl@0
|
670 |
return (a >= min && a <= max);
|
sl@0
|
671 |
}
|
sl@0
|
672 |
|
sl@0
|
673 |
/*!
|
sl@0
|
674 |
* \internal
|
sl@0
|
675 |
* \brief Clamping function for floats
|
sl@0
|
676 |
*
|
sl@0
|
677 |
* \param a Value to clamp
|
sl@0
|
678 |
* \param min Minimum value
|
sl@0
|
679 |
* \param max Maximum value
|
sl@0
|
680 |
*/
|
sl@0
|
681 |
static M3G_INLINE M3Gfloat m3gClampFloat(M3Gfloat a, M3Gfloat min, M3Gfloat max)
|
sl@0
|
682 |
{
|
sl@0
|
683 |
return (a <= min) ? min : (a >= max) ? max : a;
|
sl@0
|
684 |
}
|
sl@0
|
685 |
|
sl@0
|
686 |
/*!
|
sl@0
|
687 |
* \internal
|
sl@0
|
688 |
* \brief Clamping function for floats
|
sl@0
|
689 |
*
|
sl@0
|
690 |
* \param a Value to clamp
|
sl@0
|
691 |
*/
|
sl@0
|
692 |
static M3G_INLINE M3Gfloat m3gClampFloatPositive(M3Gfloat a)
|
sl@0
|
693 |
{
|
sl@0
|
694 |
return (a <= 0) ? 0 : a;
|
sl@0
|
695 |
}
|
sl@0
|
696 |
|
sl@0
|
697 |
/*!
|
sl@0
|
698 |
* \internal
|
sl@0
|
699 |
*/
|
sl@0
|
700 |
static M3G_INLINE M3Gint m3gClampInt(M3Gint a, M3Gint min, M3Gint max)
|
sl@0
|
701 |
{
|
sl@0
|
702 |
return (a <= min) ? min : (a >= max) ? max : a;
|
sl@0
|
703 |
}
|
sl@0
|
704 |
|
sl@0
|
705 |
/*!
|
sl@0
|
706 |
* \internal
|
sl@0
|
707 |
*
|
sl@0
|
708 |
*/
|
sl@0
|
709 |
static M3G_INLINE M3Gbool m3gIsPowerOfTwo(M3Guint a)
|
sl@0
|
710 |
{
|
sl@0
|
711 |
return ((a & (a-1)) == 0u);
|
sl@0
|
712 |
}
|
sl@0
|
713 |
|
sl@0
|
714 |
/*!
|
sl@0
|
715 |
* \internal
|
sl@0
|
716 |
* \brief Returns the smallest power of two greater than or equal to a
|
sl@0
|
717 |
* given integer
|
sl@0
|
718 |
*
|
sl@0
|
719 |
* \note Only works with positive numbers of 2^30 or less
|
sl@0
|
720 |
*/
|
sl@0
|
721 |
static M3G_INLINE M3Gint m3gNextPowerOfTwo(M3Gint x)
|
sl@0
|
722 |
{
|
sl@0
|
723 |
M3Gint y = 1;
|
sl@0
|
724 |
M3G_ASSERT(m3gInRange(x, 0, 1 << 30));
|
sl@0
|
725 |
while (y < x) {
|
sl@0
|
726 |
y <<= 1;
|
sl@0
|
727 |
}
|
sl@0
|
728 |
return y;
|
sl@0
|
729 |
}
|
sl@0
|
730 |
|
sl@0
|
731 |
/*!
|
sl@0
|
732 |
* \internal
|
sl@0
|
733 |
* \brief Indicate (intentionally) unreferenced parameters
|
sl@0
|
734 |
*
|
sl@0
|
735 |
* This is used on virtual functions, where not every implementation
|
sl@0
|
736 |
* uses all the arguments.
|
sl@0
|
737 |
*/
|
sl@0
|
738 |
/*@notfunction@*/
|
sl@0
|
739 |
#define M3G_UNREF(a) ((void)(a)) /*@*/
|
sl@0
|
740 |
|
sl@0
|
741 |
/*!
|
sl@0
|
742 |
* \internal
|
sl@0
|
743 |
* \brief Clamp a value to signed 8-bit range
|
sl@0
|
744 |
*/
|
sl@0
|
745 |
#define M3G_CLAMP_BYTE(a) ((M3Gbyte) ((a) < -128 ? -128 : ((a) > 127 ? 127 : (a))))
|
sl@0
|
746 |
M3G_SPLINT(extern M3Gbyte M3G_CLAMP_BYTE(/*@sef@*/ int a);)
|
sl@0
|
747 |
|
sl@0
|
748 |
/*!
|
sl@0
|
749 |
* \internal
|
sl@0
|
750 |
* \brief Clamp a value to signed 16-bit range
|
sl@0
|
751 |
*/
|
sl@0
|
752 |
#define M3G_CLAMP_SHORT(a) ((M3Gshort) ((a) < -32768 ? -32768 : ((a) > 32767 ? 32767 : (a))))
|
sl@0
|
753 |
M3G_SPLINT(extern M3Gshort M3G_CLAMP_SHORT(/*@sef@*/ int a);)
|
sl@0
|
754 |
|
sl@0
|
755 |
/*!
|
sl@0
|
756 |
* \internal
|
sl@0
|
757 |
* \brief Clamp a value to unsigned 8-bit range
|
sl@0
|
758 |
*/
|
sl@0
|
759 |
#define M3G_CLAMP_UBYTE(a) ((M3Gubyte) ((a) < 0 ? 0 : ((a) > 255 ? 255 : (a))))
|
sl@0
|
760 |
M3G_SPLINT(extern M3Gubyte M3G_CLAMP_UBYTE(/*@sef@*/ int a);)
|
sl@0
|
761 |
|
sl@0
|
762 |
/*!
|
sl@0
|
763 |
* \internal
|
sl@0
|
764 |
* \brief Clamp a value to unsigned 16-bit range
|
sl@0
|
765 |
*/
|
sl@0
|
766 |
#define M3G_CLAMP_USHORT(a) ((M3Gushort)((a) < 0 ? 0 : ((a) > 65535 ? 65535 : (a))))
|
sl@0
|
767 |
M3G_SPLINT(extern M3Gushort M3G_CLAMP_USHORT(/*@sef@*/ int a);)
|
sl@0
|
768 |
|
sl@0
|
769 |
/*!
|
sl@0
|
770 |
* \internal
|
sl@0
|
771 |
* \brief Offset any pointer by a given number of bytes
|
sl@0
|
772 |
*/
|
sl@0
|
773 |
#define M3G_OFFSET_PTR(ptr, bytes) (void*)(((M3Gbyte*)(ptr)) + bytes)
|
sl@0
|
774 |
|
sl@0
|
775 |
/* Min & max macros and inline functions
|
sl@0
|
776 |
*
|
sl@0
|
777 |
* The inline function may be better optimized when one or both of the
|
sl@0
|
778 |
* arguments are expressions */
|
sl@0
|
779 |
|
sl@0
|
780 |
#define M3G_MIN(a, b) ((a) <= (b) ? (a) : (b))
|
sl@0
|
781 |
#define M3G_MAX(a, b) ((a) >= (b) ? (a) : (b))
|
sl@0
|
782 |
|
sl@0
|
783 |
static M3G_INLINE M3Gint m3gMaxInt(M3Gint a, M3Gint b)
|
sl@0
|
784 |
{
|
sl@0
|
785 |
return M3G_MAX(a, b);
|
sl@0
|
786 |
}
|
sl@0
|
787 |
|
sl@0
|
788 |
static M3G_INLINE M3Gint m3gMinInt(M3Gint a, M3Gint b)
|
sl@0
|
789 |
{
|
sl@0
|
790 |
return M3G_MIN(a, b);
|
sl@0
|
791 |
}
|
sl@0
|
792 |
|
sl@0
|
793 |
/*!
|
sl@0
|
794 |
* \internal
|
sl@0
|
795 |
* \brief RGB mask
|
sl@0
|
796 |
*/
|
sl@0
|
797 |
#define M3G_RGB_MASK 0x00FFFFFFu
|
sl@0
|
798 |
|
sl@0
|
799 |
/*!
|
sl@0
|
800 |
* \internal
|
sl@0
|
801 |
* \brief Alpha mask
|
sl@0
|
802 |
*/
|
sl@0
|
803 |
#define M3G_ALPHA_MASK 0xFF000000u
|
sl@0
|
804 |
|
sl@0
|
805 |
/*----------------------------------------------------------------------
|
sl@0
|
806 |
* Data alignment macros
|
sl@0
|
807 |
*--------------------------------------------------------------------*/
|
sl@0
|
808 |
|
sl@0
|
809 |
/*!
|
sl@0
|
810 |
* \internal
|
sl@0
|
811 |
* \brief Align a pointer or size value to an N-byte boundary
|
sl@0
|
812 |
*
|
sl@0
|
813 |
* @param value Value to align.
|
sl@0
|
814 |
* @param size Alignment size; must be a power of two
|
sl@0
|
815 |
*/
|
sl@0
|
816 |
#define M3G_ALIGN_TO(value, size) ((((unsigned) (value)) + ((size) - 1)) & ~((size) - 1))
|
sl@0
|
817 |
M3G_SPLINT(extern int M3G_ALIGN_TO(int /*@alt size_t@*/ value, /*@sef@*/ int size);)
|
sl@0
|
818 |
|
sl@0
|
819 |
/*!
|
sl@0
|
820 |
* \internal
|
sl@0
|
821 |
* \brief Returns a truth value for whether a pointer is aligned or not
|
sl@0
|
822 |
*/
|
sl@0
|
823 |
#define M3G_IS_ALIGNED(ptr) ((((unsigned)(ptr)) & (M3G_ALIGNMENT-1)) == 0)
|
sl@0
|
824 |
|
sl@0
|
825 |
/*!
|
sl@0
|
826 |
* \internal
|
sl@0
|
827 |
* \brief Assert proper alignment of a pointer
|
sl@0
|
828 |
*
|
sl@0
|
829 |
* Currently, we assume alignment to 4-byte boundaries.
|
sl@0
|
830 |
*/
|
sl@0
|
831 |
#define M3G_ASSERT_ALIGNMENT(ptr) M3G_ASSERT(M3G_IS_ALIGNED(ptr))
|
sl@0
|
832 |
|
sl@0
|
833 |
/*!
|
sl@0
|
834 |
* \internal
|
sl@0
|
835 |
* \brief Asserts that a pointer is both non-null and aligned
|
sl@0
|
836 |
*/
|
sl@0
|
837 |
#define M3G_ASSERT_PTR(ptr) M3G_ASSERT((ptr) != NULL && M3G_IS_ALIGNED(ptr))
|
sl@0
|
838 |
#define M3G_VALIDATE_PTR(ptr) M3G_ASSERT_PTR(ptr)
|
sl@0
|
839 |
|
sl@0
|
840 |
/*----------------------------------------------------------------------
|
sl@0
|
841 |
* Easier names for math classes...
|
sl@0
|
842 |
*--------------------------------------------------------------------*/
|
sl@0
|
843 |
|
sl@0
|
844 |
typedef M3GMatrix Matrix;
|
sl@0
|
845 |
typedef M3GQuat Quat;
|
sl@0
|
846 |
typedef M3GVec3 Vec3;
|
sl@0
|
847 |
typedef M3GVec4 Vec4;
|
sl@0
|
848 |
typedef M3GRectangle Rect;
|
sl@0
|
849 |
|
sl@0
|
850 |
/* We rely on the layout of a Vec4 or a Quat matching an array of 4
|
sl@0
|
851 |
* floats in a number of places, so check that */
|
sl@0
|
852 |
|
sl@0
|
853 |
M3G_CT_ASSERT(sizeof(M3GVec4) == 4 * sizeof(M3Gfloat));
|
sl@0
|
854 |
M3G_CT_ASSERT(sizeof(M3GQuat) == 4 * sizeof(M3Gfloat));
|
sl@0
|
855 |
|
sl@0
|
856 |
#if defined(__cplusplus)
|
sl@0
|
857 |
} /* extern "C" */
|
sl@0
|
858 |
#endif
|
sl@0
|
859 |
|
sl@0
|
860 |
#endif /*__M3G_DEFS_H__*/
|