mojoshader_internal.h
changeset 464 eba4cf79437f
child 465 0a75f98f785b
equal deleted inserted replaced
463:6f3a82d7e3d2 464:eba4cf79437f
       
     1 #ifndef _INCLUDE_MOJOSHADER_INTERNAL_H_
       
     2 #define _INCLUDE_MOJOSHADER_INTERNAL_H_
       
     3 
       
     4 #ifndef __MOJOSHADER_INTERNAL__
       
     5 #error Do not include this header from your applications.
       
     6 #endif
       
     7 
       
     8 // Shader bytecode format is described at MSDN:
       
     9 //  http://msdn2.microsoft.com/en-us/library/ms800307.aspx
       
    10 
       
    11 #include <stdio.h>
       
    12 #include <string.h>
       
    13 #include <stdlib.h>
       
    14 #include <stdarg.h>
       
    15 #include <assert.h>
       
    16 
       
    17 #include "mojoshader.h"
       
    18 
       
    19 #if (defined(__APPLE__) && defined(__MACH__))
       
    20 #define PLATFORM_MACOSX 1
       
    21 #endif
       
    22 
       
    23 // This is the highest shader version we currently support.
       
    24 
       
    25 #define MAX_SHADER_MAJOR 3
       
    26 #define MAX_SHADER_MINOR 0
       
    27 
       
    28 
       
    29 // If SUPPORT_PROFILE_* isn't defined, we assume an implicit desire to support.
       
    30 //  You get all the profiles unless you go out of your way to disable them.
       
    31 
       
    32 #ifndef SUPPORT_PROFILE_D3D
       
    33 #define SUPPORT_PROFILE_D3D 1
       
    34 #endif
       
    35 
       
    36 #ifndef SUPPORT_PROFILE_PASSTHROUGH
       
    37 #define SUPPORT_PROFILE_PASSTHROUGH 1
       
    38 #endif
       
    39 
       
    40 #ifndef SUPPORT_PROFILE_GLSL
       
    41 #define SUPPORT_PROFILE_GLSL 1
       
    42 #endif
       
    43 
       
    44 #ifndef SUPPORT_PROFILE_ARB1
       
    45 #define SUPPORT_PROFILE_ARB1 1
       
    46 #endif
       
    47 
       
    48 
       
    49 // Get basic wankery out of the way here...
       
    50 
       
    51 #ifdef _WINDOWS
       
    52 #define ENDLINE_STR "\r\n"
       
    53 #else
       
    54 #define ENDLINE_STR "\n";
       
    55 #endif
       
    56 
       
    57 typedef unsigned int uint;  // this is a printf() helper. don't use for code.
       
    58 
       
    59 #ifdef _MSC_VER
       
    60 #include <malloc.h>
       
    61 #define snprintf _snprintf
       
    62 typedef unsigned __int8 uint8;
       
    63 typedef unsigned __int16 uint16;
       
    64 typedef unsigned __int32 uint32;
       
    65 typedef __int32 int32;
       
    66 // Warning Level 4 considered harmful.  :)
       
    67 #pragma warning(disable: 4100)  // "unreferenced formal parameter"
       
    68 #pragma warning(disable: 4389)  // "signed/unsigned mismatch"
       
    69 #else
       
    70 #include <stdint.h>
       
    71 typedef uint8_t uint8;
       
    72 typedef uint16_t uint16;
       
    73 typedef uint32_t uint32;
       
    74 typedef int32_t int32;
       
    75 #endif
       
    76 
       
    77 #ifdef __GNUC__
       
    78 #define ISPRINTF(x,y) __attribute__((format (printf, x, y)))
       
    79 #else
       
    80 #define ISPRINTF(x,y)
       
    81 #endif
       
    82 
       
    83 #define STATICARRAYLEN(x) ( (sizeof ((x))) / (sizeof ((x)[0])) )
       
    84 
       
    85 // Special-case return values from the parsing pipeline...
       
    86 #define FAIL (-1)
       
    87 #define NOFAIL (-2)
       
    88 #define END_OF_STREAM (-3)
       
    89 
       
    90 
       
    91 // Byteswap magic...
       
    92 
       
    93 #if ((defined __GNUC__) && (defined __POWERPC__))
       
    94     static inline uint32 SWAP32(uint32 x)
       
    95     {
       
    96         __asm__ __volatile__("lwbrx %0,0,%1" : "=r" (x) : "r" (&x));
       
    97         return x;
       
    98     } // SWAP32
       
    99     static inline uint16 SWAP16(uint16 x)
       
   100     {
       
   101         __asm__ __volatile__("lhbrx %0,0,%1" : "=r" (x) : "r" (&x));
       
   102         return x;
       
   103     } // SWAP16
       
   104 #elif defined(__POWERPC__)
       
   105     static inline uint32 SWAP32(uint32 x)
       
   106     {
       
   107         return ( (((x) >> 24) & 0x000000FF) | (((x) >>  8) & 0x0000FF00) |
       
   108                  (((x) <<  8) & 0x00FF0000) | (((x) << 24) & 0xFF000000) );
       
   109     } // SWAP32
       
   110     static inline uint16 SWAP16(uint16 x)
       
   111     {
       
   112         return ( (((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00) );
       
   113     } // SWAP16
       
   114 #else
       
   115 #   define SWAP16(x) (x)
       
   116 #   define SWAP32(x) (x)
       
   117 #endif
       
   118 
       
   119 #endif  // _INCLUDE_MOJOSHADER_INTERNAL_H_
       
   120 
       
   121 // end of mojoshader_internal.h ...
       
   122