os/graphics/m3g/m3gcore11/inc/m3g_defs.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/m3g/m3gcore11/inc/m3g_defs.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,860 @@
     1.4 +/*
     1.5 +* Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: Global definitions
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +#ifndef __M3G_DEFS_H__
    1.22 +#define __M3G_DEFS_H__
    1.23 +
    1.24 +/*!
    1.25 + * \internal
    1.26 + * \file
    1.27 + * \brief Global definitions for the Nokia M3G API implementation
    1.28 + */
    1.29 +
    1.30 +/* Include public API */
    1.31 +#include "M3G/m3g_core.h"
    1.32 +
    1.33 +#if defined(__cplusplus)
    1.34 +extern "C" {
    1.35 +#endif
    1.36 +
    1.37 +/* Try to recognize debug builds */
    1.38 +#if defined(_DEBUG) || defined(DEBUG)
    1.39 +#undef M3G_DEBUG
    1.40 +#define M3G_DEBUG
    1.41 +#endif
    1.42 +
    1.43 +/*----------------------------------------------------------------------
    1.44 + * Platform dependent definitions
    1.45 + *--------------------------------------------------------------------*/
    1.46 +
    1.47 +/* Define constants for use in m3g_config.h */
    1.48 +    
    1.49 +#define M3G_LOG_FATAL_ERRORS    0x0001
    1.50 +#define M3G_LOG_USER_ERRORS     0x0002
    1.51 +#define M3G_LOG_WARNINGS        0x0003
    1.52 +#define M3G_LOG_PROFILE         0x0004
    1.53 +#define M3G_LOG_INTERFACE       0x0010
    1.54 +#define M3G_LOG_OBJECTS         0x0020
    1.55 +#define M3G_LOG_STAGES          0x0040
    1.56 +#define M3G_LOG_REFCOUNT        0x0080
    1.57 +#define M3G_LOG_MEMORY_USAGE    0x0100
    1.58 +#define M3G_LOG_MEMORY_BLOCKS   0x0200
    1.59 +#define M3G_LOG_MEMORY_MAPPING  0x0400
    1.60 +#define M3G_LOG_MEMORY_ALL      0x0F00
    1.61 +#define M3G_LOG_RENDERING       0x1000
    1.62 +#define M3G_LOG_IMAGES          0x2000
    1.63 +#define M3G_LOG_ALL             0xFFFF
    1.64 +    
    1.65 +/* Include the platform configuration file; the possible configuration
    1.66 + * options are documented and their default values set below */
    1.67 +    
    1.68 +#include "m3g_config.h"
    1.69 +
    1.70 +/*!
    1.71 + * \internal
    1.72 + * \def M3G_TARGET_GENERIC
    1.73 + * \brief Enables a generic C build
    1.74 + */   
    1.75 +/*!
    1.76 + * \internal
    1.77 + * \def M3G_TARGET_ISA
    1.78 + * \brief Enables building for ISA
    1.79 + */   
    1.80 +/*!
    1.81 + * \internal
    1.82 + * \def M3G_TARGET_SYMBIAN
    1.83 + * \brief Enables building for Symbian
    1.84 + */
    1.85 +/*!
    1.86 + * \internal
    1.87 + * \def M3G_TARGET_WIN32
    1.88 + * \brief Enables building for Win32
    1.89 + */      
    1.90 +#if defined(M3G_TARGET_GENERIC)
    1.91 +#elif defined(M3G_TARGET_ISA)
    1.92 +#elif defined(M3G_TARGET_SYMBIAN)
    1.93 +#elif defined(M3G_TARGET_WIN32)
    1.94 +#elif defined(S_SPLINT_S) /* auto-recognize Splint as a special case */
    1.95 +#   define M3G_TARGET_GENERIC
    1.96 +#else
    1.97 +#   error Build target undefined! Supply one of the M3G_TARGET_* definitions.
    1.98 +#endif
    1.99 +    
   1.100 +/*!
   1.101 + * \internal
   1.102 + * \def M3G_USE_NGL_API
   1.103 + * \brief Enable the legacy "NGL" OpenGL context management interface
   1.104 + */
   1.105 +#if defined(M3G_USE_NGL_API)
   1.106 +#   define M3G_NGL_CONTEXT_API
   1.107 +#   define M3G_NGL_TEXTURE_API
   1.108 +#endif
   1.109 +    
   1.110 +#if defined(M3G_TARGET_ISA)
   1.111 +#   if !defined(M3G_NGL_CONTEXT_API)
   1.112 +#       error ISA builds must define M3G_USE_NGL_API
   1.113 +#   endif
   1.114 +#endif   
   1.115 +#if defined(M3G_TARGET_SYMBIAN)
   1.116 +#   if defined(M3G_NGL_TEXTURE_API) || defined(M3G_NGL_CONTEXT_API)
   1.117 +#       error Legacy NGL API not supported in Symbian builds
   1.118 +#   endif
   1.119 +#endif
   1.120 +    
   1.121 +/*!
   1.122 + * \internal
   1.123 + * \def M3G_ALIGNMENT
   1.124 + * \brief Alignment, in bytes, mandated for internal data structures
   1.125 + *
   1.126 + * This must meet or exceed the alignment requirement of the
   1.127 + * underlying hardware. The default is 4 bytes.
   1.128 + */
   1.129 +#if !defined(M3G_ALIGNMENT)
   1.130 +#   define M3G_ALIGNMENT        4
   1.131 +#endif
   1.132 +
   1.133 +/*!
   1.134 + * \internal
   1.135 + * \def M3G_MAX_GL_CONTEXTS
   1.136 + * \brief Maximum number of GL contexts to cache at once
   1.137 + *
   1.138 + * \note This only applies to builds using the EGL API.
   1.139 + */
   1.140 +#if !defined(M3G_MAX_GL_CONTEXTS)
   1.141 +#   define M3G_MAX_GL_CONTEXTS  3
   1.142 +#endif
   1.143 +
   1.144 +/*!
   1.145 + * \internal
   1.146 + * \def M3G_MAX_GL_SURFACES
   1.147 + * \brief Maximum number of GL surfaces to cache at once
   1.148 + *
   1.149 + * \note This only applies to builds using the EGL API.
   1.150 + */
   1.151 +#if !defined(M3G_MAX_GL_SURFACES)
   1.152 +#   define M3G_MAX_GL_SURFACES  4
   1.153 +#endif
   1.154 +
   1.155 +/*!
   1.156 + * \internal
   1.157 + * \def M3G_MAX_LIGHTS
   1.158 + * \brief Maximum number of lights in use simultaneously
   1.159 + *
   1.160 + * This is a rendering quality / performance trade-off; less lights
   1.161 + * will be (slightly) faster, but reduce the quality of lighting.
   1.162 + * 
   1.163 + * \note The value set here must not exceed the limits of the
   1.164 + * underlying OpenGL implementation; this is not automatically
   1.165 + * verified, but the default should be safe for all compliant OpenGL
   1.166 + * ES implementation
   1.167 + */
   1.168 +#if !defined(M3G_MAX_LIGHTS)
   1.169 +#   define M3G_MAX_LIGHTS       8
   1.170 +#endif
   1.171 +
   1.172 +/*!
   1.173 + * \internal
   1.174 + * \def M3G_MAX_TEXTURE_DIMENSION
   1.175 + * \brief Maximum supported texture dimension
   1.176 + *
   1.177 + * \note The value set here must not exceed the limits of the
   1.178 + * underlying OpenGL implementation; this is not automatically
   1.179 + * verified, but the default should be safe for all compliant OpenGL
   1.180 + * ES implementation
   1.181 + */
   1.182 +#if !defined(M3G_MAX_TEXTURE_DIMENSION)
   1.183 +#   define M3G_MAX_TEXTURE_DIMENSION    256
   1.184 +#endif
   1.185 +    
   1.186 +/*!
   1.187 + * \internal
   1.188 + * \def M3G_MAX_VERTEX_TRANSFORMS
   1.189 + * \brief Maximum number of transforms per vertex
   1.190 + *
   1.191 + * \note The value set here must not exceed the limits of the
   1.192 + * underlying OpenGL implementation; this is not automatically
   1.193 + * verified
   1.194 + */
   1.195 +#if !defined(M3G_MAX_VERTEX_TRANSFORMS)
   1.196 +#   define M3G_MAX_VERTEX_TRANSFORMS    4
   1.197 +#endif
   1.198 +
   1.199 +/*!
   1.200 + * \internal
   1.201 + * \def M3G_MAX_VIEWPORT_DIMENSION
   1.202 + * \brief Maximum supported viewport dimension
   1.203 + *
   1.204 + * \note The value set here must not exceed the limits of the
   1.205 + * underlying OpenGL implementation; this is not automatically
   1.206 + * verified, but the default should be safe for all compliant OpenGL
   1.207 + * ES implementation
   1.208 + */
   1.209 +#if !defined(M3G_MAX_VIEWPORT_DIMENSION)
   1.210 +#   define M3G_MAX_VIEWPORT_DIMENSION   1024
   1.211 +#endif
   1.212 +
   1.213 +/*!
   1.214 + * \internal
   1.215 + * \def M3G_MAX_VIEWPORT_WIDTH
   1.216 + * \brief Maximum supported viewport width
   1.217 + *
   1.218 + * \note The value set here must not exceed the limits of the
   1.219 + * underlying OpenGL implementation; this is not automatically
   1.220 + * verified, but the default should be safe for all compliant OpenGL
   1.221 + * ES implementation
   1.222 + */
   1.223 +#if !defined(M3G_MAX_VIEWPORT_WIDTH)
   1.224 +#   define M3G_MAX_VIEWPORT_WIDTH       1024
   1.225 +#endif
   1.226 +
   1.227 +/*!
   1.228 + * \internal
   1.229 + * \def M3G_MAX_VIEWPORT_HEIGHT
   1.230 + * \brief Maximum supported viewport height
   1.231 + *
   1.232 + * \note The value set here must not exceed the limits of the
   1.233 + * underlying OpenGL implementation; this is not automatically
   1.234 + * verified, but the default should be safe for all compliant OpenGL
   1.235 + * ES implementation
   1.236 + */
   1.237 +#if !defined(M3G_MAX_VIEWPORT_HEIGHT)
   1.238 +#   define M3G_MAX_VIEWPORT_HEIGHT      1024
   1.239 +#endif
   1.240 +
   1.241 +/*!
   1.242 + * \internal
   1.243 + * \def M3G_NATIVE_LOADER
   1.244 + * \brief Include a native loader implementation
   1.245 + *
   1.246 + * This is always enabled in current builds.
   1.247 + */
   1.248 +#undef M3G_NATIVE_LOADER
   1.249 +#define M3G_NATIVE_LOADER
   1.250 +    
   1.251 +/*!
   1.252 + * \internal
   1.253 + * \def M3G_NUM_TEXTURE_UNITS
   1.254 + * \brief Number of texture units to support
   1.255 + *
   1.256 + * \note The value set here must not exceed the limits of the
   1.257 + * underlying OpenGL implementation; this is not automatically
   1.258 + * verified, but the default should be safe for all compliant OpenGL
   1.259 + * ES implementation
   1.260 + */
   1.261 +#if !defined(M3G_NUM_TEXTURE_UNITS)
   1.262 +#   define M3G_NUM_TEXTURE_UNITS        2
   1.263 +#endif
   1.264 +
   1.265 +/*!
   1.266 + * \internal
   1.267 + * \def M3G_SUPPORT_ANTIALIASING
   1.268 + * \brief Enable or disable support for antialiasing
   1.269 + *
   1.270 + * \note This is currently only supported for Symbian.
   1.271 + */
   1.272 +#if !defined(M3G_SUPPORT_ANTIALIASING)
   1.273 +#   if defined(M3G_NGL_CONTEXT_API)
   1.274 +#       define M3G_SUPPORT_ANTIALIASING         M3G_FALSE
   1.275 +#   else
   1.276 +#       define M3G_SUPPORT_ANTIALIASING         M3G_TRUE
   1.277 +#   endif
   1.278 +#endif
   1.279 +
   1.280 +/*!
   1.281 + * \internal
   1.282 + * \def M3G_SUPPORT_DITHERING
   1.283 + * \brief Enable or disable support for dithering
   1.284 + */
   1.285 +#if !defined(M3G_SUPPORT_DITHERING)
   1.286 +#   define M3G_SUPPORT_DITHERING                M3G_FALSE
   1.287 +#endif
   1.288 +
   1.289 +/*!
   1.290 + * \internal
   1.291 + * \def M3G_SUPPORT_LOCAL_CAMERA_LIGHTING
   1.292 + * \brief Enable or disable support for local camera lighting
   1.293 + */
   1.294 +#if !defined(M3G_SUPPORT_LOCAL_CAMERA_LIGHTING)
   1.295 +#   define M3G_SUPPORT_LOCAL_CAMERA_LIGHTING    M3G_FALSE
   1.296 +#endif
   1.297 +
   1.298 +/*!
   1.299 + * \internal
   1.300 + * \def M3G_SUPPORT_MIPMAPPING
   1.301 + * \brief Enable or disable support for mipmapping
   1.302 + */
   1.303 +#if !defined(M3G_SUPPORT_MIPMAPPING)
   1.304 +#   define M3G_SUPPORT_MIPMAPPING               M3G_TRUE
   1.305 +#endif
   1.306 +
   1.307 +/*!
   1.308 + * \internal
   1.309 + * \def M3G_SUPPORT_PERSPECTIVE_CORRECTION
   1.310 + * \brief Enable or disable support for perspective correct texturing
   1.311 + */
   1.312 +#if !defined(M3G_SUPPORT_PERSPECTIVE_CORRECTION)
   1.313 +#   define M3G_SUPPORT_PERSPECTIVE_CORRECTION   M3G_TRUE
   1.314 +#endif
   1.315 +
   1.316 +/*!
   1.317 + * \internal
   1.318 + * \def M3G_SUPPORT_TRUE_COLOR
   1.319 + * \brief Enable or disable support for "true color" rendering
   1.320 + */
   1.321 +#if !defined(M3G_SUPPORT_TRUE_COLOR)
   1.322 +#   define M3G_SUPPORT_TRUE_COLOR               M3G_FALSE
   1.323 +#endif
   1.324 +
   1.325 +/*!
   1.326 + * \internal
   1.327 + * \def M3G_USE_16BIT_TEXTURES
   1.328 + * \brief Use 16-bit RGB textures internally to save memory
   1.329 + *
   1.330 + * This may reduce in some loss of performance, so it is defined
   1.331 + * M3G_FALSE by default.
   1.332 + */
   1.333 +#if !defined(M3G_USE_16BIT_TEXTURES)
   1.334 +#   define M3G_USE_16BIT_TEXTURES               M3G_FALSE
   1.335 +#endif
   1.336 +    
   1.337 +/*!
   1.338 + * \internal
   1.339 + * \def M3G_LOGLEVEL
   1.340 + * 
   1.341 + * \brief Controls the amount of log output
   1.342 + *
   1.343 + * Log output can be enabled by defining M3G_LOGLEVEL in m3g_config.h.
   1.344 + * It must be set to a bitmask indicating which categories of log
   1.345 + * messages to output.  Fatal internal errors are always output when
   1.346 + * M3G_LOGLEVEL is defined; other kinds of messages can be included by
   1.347 + * setting it to any combination of the following in m3g_config.h:
   1.348 + *
   1.349 + *  M3G_LOG_FATAL_ERRORS    fatal internal errors (equals 0)
   1.350 + *  M3G_LOG_USER_ERRORS     user errors (the same as reported
   1.351 + *                          via m3gGetError)
   1.352 + *  M3G_LOG_WARNINGS        performance warnings
   1.353 + *  M3G_LOG_PROFILE         profiling counters
   1.354 + *  M3G_LOG_INTERFACE       interface construction/destruction events
   1.355 + *  M3G_LOG_OBJECTS         object construction/destruction events
   1.356 + *  M3G_LOG_STAGES          log processing stages (animate, render, etc.)
   1.357 + *  M3G_LOG_REFCOUNT        reference count operations
   1.358 + *  M3G_LOG_MEMORY_USAGE    memory usage counters
   1.359 + *  M3G_LOG_MEMORY_BLOCKS   memory block allocs/deallocs
   1.360 + *  M3G_LOG_MEMORY_ALL      output everything memory-related
   1.361 + *  M3G_LOG_RENDERING       log rendering details
   1.362 + *  M3G_LOG_IMAGES          log image memory usage details
   1.363 + *
   1.364 + * \note The amount of log output may be limited in non-debug builds.
   1.365 + */
   1.366 +
   1.367 +/*!
   1.368 + * \internal
   1.369 + * \def M3G_PROFILE_LOG_INTERVAL
   1.370 + * \brief Profile logging interval
   1.371 + * 
   1.372 + * Number of frames to wait between outputting (and resetting!) the
   1.373 + * profiling counters.  Zero (default) disables profile logging.
   1.374 + */
   1.375 +#if !defined(M3G_PROFILE_LOG_INTERVAL)
   1.376 +#   define M3G_PROFILE_LOG_INTERVAL     0
   1.377 +#endif
   1.378 +    
   1.379 +/*----------------------------------------------------------------------
   1.380 + * Debug build setup
   1.381 + *--------------------------------------------------------------------*/
   1.382 +
   1.383 +/* General settings enabled in debug builds */
   1.384 +#if defined(M3G_DEBUG)
   1.385 +#   define M3G_DEBUG_ASSERTS
   1.386 +#   define M3G_DEBUG_RANGE_CHECKING
   1.387 +#   define M3G_DEBUG_HEAP_TRACKING
   1.388 +#endif
   1.389 +
   1.390 +/*----------------------------------------------------------------------
   1.391 + * Compiler dependent definitions
   1.392 + *--------------------------------------------------------------------*/
   1.393 +
   1.394 +/* Try to recognize the compiler */
   1.395 +#if !defined(M3G_NO_COMPILER_DETECTION)
   1.396 +#   if (defined (_MSC_VER) || defined(__VC32__))&& !defined(__MWERKS__) /* Microsoft Visual C++ */
   1.397 +#       undef M3G_BUILD_MSVC
   1.398 +#       define M3G_BUILD_MSVC
   1.399 +#   elif defined(__ARMCC_VERSION)   /* ARM Developer Suite */
   1.400 +#       undef M3G_BUILD_ADS
   1.401 +#       define M3G_BUILD_ADS
   1.402 +#   elif defined(__BORLANDC__)      /* Borland C++ */
   1.403 +#       undef M3G_BUILD_BORLAND
   1.404 +#       define M3G_BUILD_BORLAND
   1.405 +#   elif defined(__MWERKS__) || defined(__CW32__) /* CodeWarrior */
   1.406 +#       undef M3G_BUILD_CW
   1.407 +#       define M3G_BUILD_CW
   1.408 +#   elif defined(__GNUC__) || defined(__GCC32__) /* GNU C */
   1.409 +#       undef M3G_BUILD_GCC
   1.410 +#       define M3G_BUILD_GCC
   1.411 +#   elif defined(__ARMCC__)         /* RVCT */
   1.412 +#       undef M3G_BUILD_RVCT
   1.413 +#       define M3G_BUILD_RVCT
   1.414 +#   elif defined(S_SPLINT_S)        /* Splint */
   1.415 +#       undef M3G_BUILD_SPLINT
   1.416 +#       define M3G_BUILD_SPLINT
   1.417 +#   else
   1.418 +#       error Could not identify the compiler. Please refer to m3g_defs.h for more information.
   1.419 +#   endif
   1.420 +#endif
   1.421 +
   1.422 +/* Try to recognize thumb/arm */
   1.423 +#if defined(M3G_BUILD_ADS)
   1.424 +#   if defined(__thumb)
   1.425 +#       define M3G_BUILD_THUMB
   1.426 +#   else
   1.427 +#       define M3G_BUILD_ARM
   1.428 +#   endif
   1.429 +#endif
   1.430 +
   1.431 +/* Set up compiler-dependent definitions */
   1.432 +
   1.433 +/*@-macroparams@*/
   1.434 +/*@notfunction@*/
   1.435 +/*!
   1.436 + * \internal \brief Macro used to denote Splint constraints */
   1.437 +#define M3G_SPLINT(def)
   1.438 +/*@+macroparams@*/
   1.439 +
   1.440 +/*!
   1.441 + * \internal \def M3G_INLINE
   1.442 + * \brief Platform-independent inline function specifier
   1.443 + */
   1.444 +
   1.445 +#if defined(M3G_BUILD_MSVC)
   1.446 +#   define M3G_INLINE  __inline
   1.447 +#   pragma warning (disable:4127) /* 4127: conditional expression is constant */
   1.448 +#   pragma warning (disable:4514) /* 4514: unreferenced inline function has been removed */
   1.449 +#   pragma warning (disable:4710) /* 4710: function not inlined */
   1.450 +
   1.451 +#elif defined (M3G_BUILD_ADS)
   1.452 +#   define M3G_INLINE __inline
   1.453 +
   1.454 +#elif defined(M3G_BUILD_BORLAND)
   1.455 +#   define M3G_INLINE  __inline
   1.456 +
   1.457 +#elif defined(M3G_BUILD_CW)
   1.458 +#   define M3G_INLINE
   1.459 +    
   1.460 +#elif defined(M3G_BUILD_GCC)
   1.461 +#   define M3G_INLINE inline
   1.462 +
   1.463 +#elif defined(M3G_BUILD_RVCT)
   1.464 +#   define M3G_INLINE __inline
   1.465 +    
   1.466 +#elif defined(M3G_BUILD_SPLINT)
   1.467 +#   define M3G_INLINE
   1.468 +#   undef M3G_SPLINT
   1.469 +/*@notfunction@*/
   1.470 +#   define M3G_SPLINT(def) def
   1.471 +
   1.472 +#   undef M3G_DEBUG
   1.473 +/*#   define M3G_DEBUG*/
   1.474 +
   1.475 +#else           /* generic fallback */
   1.476 +#   define M3G_INLINE
   1.477 +
   1.478 +#endif
   1.479 +
   1.480 +/* Optionally cancel non-portable definitions. This is mainly to
   1.481 + * facilitate portability checking with GCC, which defines __STDC__
   1.482 + * even in non-ANSI mode) */
   1.483 +
   1.484 +#if defined(M3G_STRICT_STDC)
   1.485 +#   undef M3G_INLINE
   1.486 +#   define M3G_INLINE
   1.487 +#endif
   1.488 +
   1.489 +/*----------------------------------------------------------------------
   1.490 + * Identify GL version
   1.491 + *--------------------------------------------------------------------*/
   1.492 +#if defined(GL_VERSION_ES_CM_1_1) || defined(GL_OES_VERSION_1_1)
   1.493 +#   define M3G_GL_ES_1_1
   1.494 +#endif
   1.495 +
   1.496 +/*----------------------------------------------------------------------
   1.497 + * Internal configuration and performance tuning parameters
   1.498 + *--------------------------------------------------------------------*/
   1.499 +
   1.500 +#define M3G_RENDERQUEUE_BUCKET_BITS 8
   1.501 +#define M3G_ENABLE_VF_CULLING
   1.502 +#define M3G_GL_FORCE_PBUFFER_SIZE
   1.503 +    
   1.504 +/*----------------------------------------------------------------------
   1.505 + * Standard C library
   1.506 + *--------------------------------------------------------------------*/
   1.507 +
   1.508 +#if defined(M3G_NO_STDLIB)
   1.509 +#   define NULL 0
   1.510 +typedef M3Guint M3Gsize;
   1.511 +#else
   1.512 +#   include <stdlib.h>
   1.513 +typedef size_t M3Gsize;
   1.514 +#endif
   1.515 +
   1.516 +/*----------------------------------------------------------------------
   1.517 + * Run time and compile time assertions
   1.518 + *--------------------------------------------------------------------*/
   1.519 +
   1.520 +/*!
   1.521 + * \internal \def M3G_ASSERT(a)
   1.522 + * \brief Run-time assertion
   1.523 + */
   1.524 +#if defined(M3G_DEBUG_ASSERTS)
   1.525 +
   1.526 +extern void m3gAssertFailed(const char *filename, int line);
   1.527 +#define M3G_ASSERT(cond)                                        \
   1.528 +    do {                                                        \
   1.529 +        if (!(cond)) m3gAssertFailed(__FILE__, __LINE__);       \
   1.530 +    } while (M3G_FALSE)
   1.531 +
   1.532 +M3G_SPLINT(extern /*@noreturnwhenfalse@*/ void M3G_ASSERT(/*@sef@*//*@null@*/ M3Gbool /*@alt const void*@*/ cond)/*@*/;)
   1.533 +
   1.534 +#else
   1.535 +
   1.536 +/*@-macroparams@*/
   1.537 +#   define M3G_ASSERT(cond)
   1.538 +/*@+macroparams@*/
   1.539 +M3G_SPLINT(extern /*@noreturnwhenfalse@*/ void M3G_ASSERT(/*@sef@*//*@null@*//*@unused@*/ M3Gbool /*@alt const void*@*/ cond)/*@*/;)
   1.540 +    
   1.541 +#endif /* M3G_DEBUG */
   1.542 +
   1.543 +/*!
   1.544 + * \internal
   1.545 + * \brief Compile-time assertion
   1.546 + */
   1.547 +/*@notfunction@*/
   1.548 +#define M3G_CT_ASSERT(a)    struct __M3G_UNIQUE_NAME { unsigned bf : (a) ? 1 : -1; }
   1.549 +/*@notfunction@*/
   1.550 +#define __M3G_UNIQUE_NAME           __M3G_MAKE_UNIQUE_NAME(__LINE__, 0)
   1.551 +/*@notfunction@*/
   1.552 +#define __M3G_MAKE_UNIQUE_NAME(line, num)   __M3G_MAKE_UNIQUE_NAME2(line, num)
   1.553 +/*@notfunction@*/
   1.554 +#define __M3G_MAKE_UNIQUE_NAME2(line, num)  m3gCTassert ## num ## line
   1.555 +
   1.556 +/*@notfunction@*/
   1.557 +#define M3G_CT_ASSERT1(a)   struct __M3G_UNIQUE_NAME1 { unsigned bf : (a) ? 1 : -1; }
   1.558 +/*@notfunction@*/
   1.559 +#define __M3G_UNIQUE_NAME1  M3G_MAKE_UNIQUE_NAME(__LINE__, 1)
   1.560 +
   1.561 +/*@notfunction@*/
   1.562 +#define M3G_CT_ASSERT2(a)   struct __M3G_UNIQUE_NAME2 { unsigned bf : (a) ? 1 : -1; }
   1.563 +/*@notfunction@*/
   1.564 +#define __M3G_UNIQUE_NAME2  __M3G_MAKE_UNIQUE_NAME(__LINE__, 2)
   1.565 +
   1.566 +#if defined(M3G_DEBUG_RANGE_CHECKING)
   1.567 +#define M3G_ASSERT_RANGE(val, min, max) M3G_ASSERT(m3gInRange((val), (min), (max)))
   1.568 +#else
   1.569 +/*@-macroparams@*/
   1.570 +#define M3G_ASSERT_RANGE(val, min, max)
   1.571 +/*@+macroparams@*/
   1.572 +#endif
   1.573 +
   1.574 +/*----------------------------------------------------------------------
   1.575 + * Verify any global definitions, expected type sizes etc.
   1.576 + *--------------------------------------------------------------------*/
   1.577 +
   1.578 +#if !defined(M3G_INLINE)
   1.579 +#   error M3G_INLINE not defined in platform definitions!
   1.580 +#endif
   1.581 +
   1.582 +#if !defined(M3G_ALIGNMENT)
   1.583 +#   error M3G_ALIGNMENT not defined in platform definitions!
   1.584 +#endif
   1.585 +
   1.586 +#if ((M3G_ALIGNMENT & (M3G_ALIGNMENT-1)) != 0)
   1.587 +#   error M3G_ALIGNMENT is not a power of two!
   1.588 +#endif
   1.589 +
   1.590 +#if defined(M3G_TARGET_ISA) && !defined(M3G_USE_NGL_API)
   1.591 +#   error ISA targets currently supported with M3G_USE_NGL_API only!
   1.592 +#endif
   1.593 +
   1.594 +#if (defined(M3G_NGL_CONTEXT_API) && !defined(M3G_NGL_TEXTURE_API)) \
   1.595 +        || (defined(M3G_NGL_TEXTURE_API) && !defined(M3G_NGL_CONTEXT_API))
   1.596 +#   if !defined(M3G_DEBUG)
   1.597 +#       error Nonstandard NGL configurations only allowed in debug builds!
   1.598 +#   endif
   1.599 +#endif
   1.600 +
   1.601 +/* Verify our expected type sizes */
   1.602 +M3G_CT_ASSERT(sizeof(M3Gbyte)   == 1);
   1.603 +M3G_CT_ASSERT(sizeof(M3Gubyte)  == 1);
   1.604 +M3G_CT_ASSERT(sizeof(M3Gshort)  == 2);
   1.605 +M3G_CT_ASSERT(sizeof(M3Gushort) == 2);
   1.606 +M3G_CT_ASSERT(sizeof(M3Gint)    == 4);
   1.607 +M3G_CT_ASSERT(sizeof(M3Guint)   == 4);
   1.608 +M3G_CT_ASSERT(sizeof(M3Gfloat)   == 4);
   1.609 +
   1.610 +/* Unsigned is used extensively as a wrapper for object pointers, so
   1.611 + * check that we can fit a pointer in there */
   1.612 +M3G_CT_ASSERT(sizeof(M3Guint) >= sizeof(void*));
   1.613 +
   1.614 +/*
   1.615 + * Globally disable some redundant Lint messages
   1.616 + */
   1.617 +
   1.618 +/*lint -e701 Signed shifts left should never be a problem */
   1.619 +/*lint -e702 Signed shifts right are run-time verified (m3g_interface.c) */
   1.620 +
   1.621 +/*----------------------------------------------------------------------
   1.622 + * Event logging
   1.623 + *--------------------------------------------------------------------*/
   1.624 +
   1.625 +#if !defined(M3G_LOGLEVEL)    
   1.626 +#   define M3G_LOG(level, msg)              ((void)(level), (void)(msg))
   1.627 +#   define M3G_LOG1(level, msg, a)          ((void)(level), (void)(msg), (void)(a))
   1.628 +#   define M3G_LOG2(level, msg, a, b)       ((void)(level), (void)(msg), (void)(a), (void)(b))
   1.629 +#   define M3G_LOG3(level, msg, a, b, c)    ((void)(level), (void)(msg), (void)(a), (void)(b), (void)(c))
   1.630 +#   define M3G_LOG4(level, msg, a, b, c, d) ((void)(level), (void)(msg), (void)(a), (void)(b), (void)(c), (void)(d))
   1.631 +#   define M3G_LOG5(level, msg, a, b, c, d, e) ((void)(level), (void)(msg), (void)(a), (void)(b), (void)(c), (void)(d), (void)(e))
   1.632 +#else
   1.633 +    void m3gBeginLog(void);
   1.634 +    void m3gLogMessage(const char *format, ...);
   1.635 +    void m3gEndLog(void);
   1.636 +#   define M3G_LOG(level, msg) \
   1.637 +    do { if ((level) & (M3G_LOGLEVEL)) m3gLogMessage((msg)); } while (M3G_FALSE)
   1.638 +#   define M3G_LOG1(level, msg, a) \
   1.639 +    do { if ((level) & (M3G_LOGLEVEL)) m3gLogMessage((msg), (a)); } while (M3G_FALSE)
   1.640 +#   define M3G_LOG2(level, msg, a, b) \
   1.641 +    do { if ((level) & (M3G_LOGLEVEL)) m3gLogMessage((msg), (a), (b)); } while (M3G_FALSE)
   1.642 +#   define M3G_LOG3(level, msg, a, b, c) \
   1.643 +    do { if ((level) & (M3G_LOGLEVEL)) m3gLogMessage((msg), (a), (b), (c)); } while (M3G_FALSE)
   1.644 +#   define M3G_LOG4(level, msg, a, b, c, d) \
   1.645 +    do { if ((level) & (M3G_LOGLEVEL)) m3gLogMessage((msg), (a), (b), (c), (d)); } while (M3G_FALSE)
   1.646 +#   define M3G_LOG5(level, msg, a, b, c, d, e) \
   1.647 +    do { if ((level) & (M3G_LOGLEVEL)) m3gLogMessage((msg), (a), (b), (c), (d), (e)); } while (M3G_FALSE)
   1.648 +#endif
   1.649 +    
   1.650 +/*----------------------------------------------------------------------
   1.651 + * Useful stuff
   1.652 + *--------------------------------------------------------------------*/
   1.653 +
   1.654 +/*!
   1.655 + * \internal
   1.656 + * \brief Range checking inline function
   1.657 + *
   1.658 + * \param a     Value to check
   1.659 + * \param min   Lower bound, inclusive
   1.660 + * \param max   Upper bound, inclusive
   1.661 + */
   1.662 +static M3G_INLINE M3Gbool m3gInRange(M3Gint a, M3Gint min, M3Gint max)
   1.663 +{
   1.664 +    return ((M3Guint)(a - min) <= (M3Guint)(max - min));
   1.665 +}
   1.666 +
   1.667 +/*!
   1.668 + * \internal
   1.669 + * \brief Range checking for floats
   1.670 + */
   1.671 +static M3G_INLINE M3Gbool m3gInRangef(M3Gfloat a, M3Gfloat min, M3Gfloat max)
   1.672 +{
   1.673 +    return (a >= min && a <= max);
   1.674 +}
   1.675 +    
   1.676 +/*!
   1.677 + * \internal
   1.678 + * \brief Clamping function for floats
   1.679 + *
   1.680 + * \param a     Value to clamp
   1.681 + * \param min   Minimum value
   1.682 + * \param max   Maximum value
   1.683 + */
   1.684 +static M3G_INLINE M3Gfloat m3gClampFloat(M3Gfloat a, M3Gfloat min, M3Gfloat max)
   1.685 +{
   1.686 +    return (a <= min) ? min : (a >= max) ? max : a;
   1.687 +}
   1.688 +
   1.689 +/*!
   1.690 + * \internal
   1.691 + * \brief Clamping function for floats
   1.692 + *
   1.693 + * \param a     Value to clamp
   1.694 + */
   1.695 +static M3G_INLINE M3Gfloat m3gClampFloatPositive(M3Gfloat a)
   1.696 +{
   1.697 +    return (a <= 0) ? 0 : a;
   1.698 +}
   1.699 +
   1.700 +/*!
   1.701 + * \internal
   1.702 + */
   1.703 +static M3G_INLINE M3Gint m3gClampInt(M3Gint a, M3Gint min, M3Gint max)
   1.704 +{
   1.705 +    return (a <= min) ? min : (a >= max) ? max : a;
   1.706 +}
   1.707 +
   1.708 +/*!
   1.709 + * \internal
   1.710 + *
   1.711 + */
   1.712 +static M3G_INLINE M3Gbool m3gIsPowerOfTwo(M3Guint a)
   1.713 +{
   1.714 +    return ((a & (a-1)) == 0u);
   1.715 +}
   1.716 +
   1.717 +/*!
   1.718 + * \internal
   1.719 + * \brief Returns the smallest power of two greater than or equal to a
   1.720 + * given integer
   1.721 + *
   1.722 + * \note Only works with positive numbers of 2^30 or less
   1.723 + */
   1.724 +static M3G_INLINE M3Gint m3gNextPowerOfTwo(M3Gint x)
   1.725 +{
   1.726 +    M3Gint y = 1;
   1.727 +    M3G_ASSERT(m3gInRange(x, 0, 1 << 30));
   1.728 +    while (y < x) {
   1.729 +        y <<= 1;
   1.730 +    }
   1.731 +    return y;
   1.732 +}
   1.733 +
   1.734 +/*!
   1.735 + * \internal
   1.736 + * \brief Indicate (intentionally) unreferenced parameters
   1.737 + *
   1.738 + * This is used on virtual functions, where not every implementation
   1.739 + * uses all the arguments.
   1.740 + */
   1.741 +/*@notfunction@*/
   1.742 +#define M3G_UNREF(a)    ((void)(a)) /*@*/
   1.743 +
   1.744 +/*!
   1.745 + * \internal
   1.746 + * \brief Clamp a value to signed 8-bit range
   1.747 + */
   1.748 +#define M3G_CLAMP_BYTE(a) ((M3Gbyte)  ((a) <   -128 ?   -128 : ((a) >   127 ?   127 : (a))))
   1.749 +M3G_SPLINT(extern M3Gbyte M3G_CLAMP_BYTE(/*@sef@*/ int a);)
   1.750 +
   1.751 +/*!
   1.752 + * \internal
   1.753 + * \brief Clamp a value to signed 16-bit range
   1.754 + */
   1.755 +#define M3G_CLAMP_SHORT(a) ((M3Gshort) ((a) < -32768 ? -32768 : ((a) > 32767 ? 32767 : (a))))
   1.756 +M3G_SPLINT(extern M3Gshort M3G_CLAMP_SHORT(/*@sef@*/ int a);)
   1.757 +
   1.758 +/*!
   1.759 + * \internal
   1.760 + * \brief Clamp a value to unsigned 8-bit range
   1.761 + */
   1.762 +#define M3G_CLAMP_UBYTE(a) ((M3Gubyte) ((a) < 0 ? 0 : ((a) >   255 ?   255 : (a))))
   1.763 +M3G_SPLINT(extern M3Gubyte M3G_CLAMP_UBYTE(/*@sef@*/ int a);)
   1.764 +
   1.765 +/*!
   1.766 + * \internal
   1.767 + * \brief Clamp a value to unsigned 16-bit range
   1.768 + */
   1.769 +#define M3G_CLAMP_USHORT(a) ((M3Gushort)((a) < 0 ? 0 : ((a) > 65535 ? 65535 : (a))))
   1.770 +M3G_SPLINT(extern M3Gushort M3G_CLAMP_USHORT(/*@sef@*/ int a);)
   1.771 +
   1.772 +/*!
   1.773 + * \internal
   1.774 + * \brief Offset any pointer by a given number of bytes
   1.775 + */
   1.776 +#define M3G_OFFSET_PTR(ptr, bytes) (void*)(((M3Gbyte*)(ptr)) + bytes)
   1.777 +
   1.778 +/* Min & max macros and inline functions
   1.779 + *
   1.780 + * The inline function may be better optimized when one or both of the
   1.781 + * arguments are expressions */
   1.782 +    
   1.783 +#define M3G_MIN(a, b) ((a) <= (b) ? (a) : (b))
   1.784 +#define M3G_MAX(a, b) ((a) >= (b) ? (a) : (b))
   1.785 +
   1.786 +static M3G_INLINE M3Gint m3gMaxInt(M3Gint a, M3Gint b)
   1.787 +{
   1.788 +    return M3G_MAX(a, b);
   1.789 +}
   1.790 +
   1.791 +static M3G_INLINE M3Gint m3gMinInt(M3Gint a, M3Gint b)
   1.792 +{
   1.793 +    return M3G_MIN(a, b);
   1.794 +}
   1.795 +
   1.796 +/*!
   1.797 + * \internal
   1.798 + * \brief RGB mask
   1.799 + */
   1.800 +#define M3G_RGB_MASK    0x00FFFFFFu
   1.801 +
   1.802 +/*!
   1.803 + * \internal
   1.804 + * \brief Alpha mask
   1.805 + */
   1.806 +#define M3G_ALPHA_MASK  0xFF000000u
   1.807 +
   1.808 +/*----------------------------------------------------------------------
   1.809 + * Data alignment macros
   1.810 + *--------------------------------------------------------------------*/
   1.811 +
   1.812 +/*!
   1.813 + * \internal
   1.814 + * \brief Align a pointer or size value to an N-byte boundary
   1.815 + *
   1.816 + * @param value Value to align.
   1.817 + * @param size  Alignment size; must be a power of two
   1.818 + */
   1.819 +#define M3G_ALIGN_TO(value, size) ((((unsigned) (value)) + ((size) - 1)) & ~((size) - 1))
   1.820 +M3G_SPLINT(extern int M3G_ALIGN_TO(int /*@alt size_t@*/ value, /*@sef@*/ int size);)
   1.821 +
   1.822 +/*!
   1.823 + * \internal
   1.824 + * \brief Returns a truth value for whether a pointer is aligned or not
   1.825 + */
   1.826 +#define M3G_IS_ALIGNED(ptr) ((((unsigned)(ptr)) & (M3G_ALIGNMENT-1)) == 0)
   1.827 +
   1.828 +/*!
   1.829 + * \internal
   1.830 + * \brief Assert proper alignment of a pointer
   1.831 + *
   1.832 + * Currently, we assume alignment to 4-byte boundaries.
   1.833 + */
   1.834 +#define M3G_ASSERT_ALIGNMENT(ptr) M3G_ASSERT(M3G_IS_ALIGNED(ptr))
   1.835 +
   1.836 +/*!
   1.837 + * \internal
   1.838 + * \brief Asserts that a pointer is both non-null and aligned
   1.839 + */
   1.840 +#define M3G_ASSERT_PTR(ptr) M3G_ASSERT((ptr) != NULL && M3G_IS_ALIGNED(ptr))
   1.841 +#define M3G_VALIDATE_PTR(ptr) M3G_ASSERT_PTR(ptr)
   1.842 +    
   1.843 +/*----------------------------------------------------------------------
   1.844 + * Easier names for math classes...
   1.845 + *--------------------------------------------------------------------*/
   1.846 +
   1.847 +typedef M3GMatrix       Matrix;
   1.848 +typedef M3GQuat         Quat;
   1.849 +typedef M3GVec3         Vec3;
   1.850 +typedef M3GVec4         Vec4;
   1.851 +typedef M3GRectangle    Rect;
   1.852 +
   1.853 +/* We rely on the layout of a Vec4 or a Quat matching an array of 4
   1.854 + * floats in a number of places, so check that */
   1.855 +
   1.856 +M3G_CT_ASSERT(sizeof(M3GVec4) == 4 * sizeof(M3Gfloat));
   1.857 +M3G_CT_ASSERT(sizeof(M3GQuat) == 4 * sizeof(M3Gfloat));
   1.858 +
   1.859 +#if defined(__cplusplus)
   1.860 +} /* extern "C" */
   1.861 +#endif
   1.862 +
   1.863 +#endif /*__M3G_DEFS_H__*/