Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Mesa 3-D graphics library
  3.  *
  4.  * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the "Software"),
  8.  * to deal in the Software without restriction, including without limitation
  9.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10.  * and/or sell copies of the Software, and to permit persons to whom the
  11.  * Software is furnished to do so, subject to the following conditions:
  12.  *
  13.  * The above copyright notice and this permission notice shall be included
  14.  * in all copies or substantial portions of the Software.
  15.  *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  19.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20.  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21.  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22.  * OTHER DEALINGS IN THE SOFTWARE.
  23.  *
  24.  * Authors:
  25.  *    Gareth Hughes
  26.  */
  27.  
  28. /*
  29.  * This generates an asm version of mtypes.h (called matypes.h), so that
  30.  * Mesa's x86 assembly code can access the internal structures easily.
  31.  * This will be particularly useful when developing new x86 asm code for
  32.  * Mesa, including lighting, clipping, texture image conversion etc.
  33.  */
  34.  
  35. #ifndef __STDC_FORMAT_MACROS
  36. #define __STDC_FORMAT_MACROS
  37. #endif
  38. #include <inttypes.h>
  39.  
  40. #include "main/glheader.h"
  41. #include "main/mtypes.h"
  42. #include "tnl/t_context.h"
  43.  
  44.  
  45. #undef offsetof
  46. #define offsetof( type, member ) ((size_t) &((type *)0)->member)
  47.  
  48.  
  49. #define OFFSET_HEADER( x )                                              \
  50. do {                                                                    \
  51.    printf( "\n" );                                                      \
  52.    printf( "\n" );                                                      \
  53.    printf( "/* ====================================================="   \
  54.            "========\n" );                                              \
  55.    printf( " * Offsets for " x "\n" );                                  \
  56.    printf( " */\n" );                                                   \
  57.    printf( "\n" );                                                      \
  58. } while (0)
  59.  
  60. #define DEFINE_HEADER( x )                                              \
  61. do {                                                                    \
  62.    printf( "\n" );                                                      \
  63.    printf( "/*\n" );                                                    \
  64.    printf( " * Flags for " x "\n" );                                    \
  65.    printf( " */\n" );                                                   \
  66.    printf( "\n" );                                                      \
  67. } while (0)
  68.  
  69. #ifdef ASM_OFFSETS
  70.  
  71. /*
  72.  * Format the asm output in a special way that we can manipulate
  73.  * after the fact and turn into the final header for the target.
  74.  */
  75.  
  76. #define DEFINE_UL( s, ul )                                              \
  77.    __asm__ __volatile__ ( "\n->" s " %0" : : "i" (ul) )
  78.  
  79. #define DEFINE( s, d )                                                  \
  80.    DEFINE_UL( s, d )
  81.  
  82. #define printf( x )                                                     \
  83.    __asm__ __volatile__ ( "\n->" x )
  84.  
  85. #else
  86.  
  87. #define DEFINE_UL( s, ul )                                              \
  88.    printf( "#define %s\t%lu\n", s, (unsigned long) (ul) );
  89.  
  90. #define DEFINE( s, d )                                                  \
  91.    printf( "#define %s\t0x%" PRIx64 "\n", s, (uint64_t) d );
  92.  
  93. #endif
  94.  
  95. #define OFFSET( s, t, m )                                               \
  96.    DEFINE_UL( s, offsetof( t, m ) )
  97.  
  98. #define SIZEOF( s, t )                                                  \
  99.    DEFINE_UL( s, sizeof(t) )
  100.  
  101.  
  102.  
  103. int main( int argc, char **argv )
  104. {
  105.    printf( "/*\n" );
  106.    printf( " * This file is automatically generated from the Mesa internal type\n" );
  107.    printf( " * definitions.  Do not edit directly.\n" );
  108.    printf( " */\n" );
  109.    printf( "\n" );
  110.    printf( "#ifndef __ASM_TYPES_H__\n" );
  111.    printf( "#define __ASM_TYPES_H__\n" );
  112.    printf( "\n" );
  113.  
  114.  
  115.    /* struct gl_context offsets:
  116.     */
  117.    OFFSET_HEADER( "struct gl_context" );
  118.  
  119.    printf( "\n" );
  120.    OFFSET( "CTX_LIGHT_ENABLED           ", struct gl_context, Light.Enabled );
  121.    OFFSET( "CTX_LIGHT_SHADE_MODEL       ", struct gl_context, Light.ShadeModel );
  122.    OFFSET( "CTX_LIGHT_COLOR_MAT_FACE    ", struct gl_context, Light.ColorMaterialFace );
  123.    OFFSET( "CTX_LIGHT_COLOR_MAT_MODE    ", struct gl_context, Light.ColorMaterialMode );
  124.    OFFSET( "CTX_LIGHT_COLOR_MAT_MASK    ", struct gl_context, Light._ColorMaterialBitmask );
  125.    OFFSET( "CTX_LIGHT_COLOR_MAT_ENABLED ", struct gl_context, Light.ColorMaterialEnabled );
  126.    OFFSET( "CTX_LIGHT_ENABLED_LIST      ", struct gl_context, Light.EnabledList );
  127.    OFFSET( "CTX_LIGHT_NEED_VERTS        ", struct gl_context, Light._NeedVertices );
  128.    OFFSET( "CTX_LIGHT_BASE_COLOR        ", struct gl_context, Light._BaseColor );
  129.  
  130.  
  131.    /* struct vertex_buffer offsets:
  132.     */
  133.    OFFSET_HEADER( "struct vertex_buffer" );
  134.  
  135.    OFFSET( "VB_SIZE                ", struct vertex_buffer, Size );
  136.    OFFSET( "VB_COUNT               ", struct vertex_buffer, Count );
  137.    printf( "\n" );
  138.    OFFSET( "VB_ELTS                ", struct vertex_buffer, Elts );
  139.    OFFSET( "VB_OBJ_PTR             ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_POS] );
  140.    OFFSET( "VB_EYE_PTR             ", struct vertex_buffer, EyePtr );
  141.    OFFSET( "VB_CLIP_PTR            ", struct vertex_buffer, ClipPtr );
  142.    OFFSET( "VB_PROJ_CLIP_PTR       ", struct vertex_buffer, NdcPtr );
  143.    OFFSET( "VB_CLIP_OR_MASK        ", struct vertex_buffer, ClipOrMask );
  144.    OFFSET( "VB_CLIP_MASK           ", struct vertex_buffer, ClipMask );
  145.    OFFSET( "VB_NORMAL_PTR          ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_NORMAL] );
  146.    OFFSET( "VB_EDGE_FLAG           ", struct vertex_buffer, EdgeFlag );
  147.    OFFSET( "VB_TEX0_COORD_PTR      ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_TEX0] );
  148.    OFFSET( "VB_TEX1_COORD_PTR      ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_TEX1] );
  149.    OFFSET( "VB_TEX2_COORD_PTR      ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_TEX2] );
  150.    OFFSET( "VB_TEX3_COORD_PTR      ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_TEX3] );
  151.    OFFSET( "VB_INDEX_PTR           ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_COLOR_INDEX] );
  152.    OFFSET( "VB_COLOR_PTR           ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_COLOR0] );
  153.    OFFSET( "VB_SECONDARY_COLOR_PTR ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_COLOR1] );
  154.    OFFSET( "VB_FOG_COORD_PTR       ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_FOG] );
  155.    OFFSET( "VB_PRIMITIVE           ", struct vertex_buffer, Primitive );
  156.    printf( "\n" );
  157.  
  158.    DEFINE_HEADER( "struct vertex_buffer" );
  159.  
  160.    /* XXX use new labels here someday after vertex proram is done */
  161.    DEFINE( "VERT_BIT_OBJ           ", VERT_BIT_POS );
  162.    DEFINE( "VERT_BIT_NORM          ", VERT_BIT_NORMAL );
  163.    DEFINE( "VERT_BIT_RGBA          ", VERT_BIT_COLOR0 );
  164.    DEFINE( "VERT_BIT_SPEC_RGB      ", VERT_BIT_COLOR1 );
  165.    DEFINE( "VERT_BIT_FOG_COORD     ", VERT_BIT_FOG );
  166.    DEFINE( "VERT_BIT_TEX0          ", VERT_BIT_TEX0 );
  167.    DEFINE( "VERT_BIT_TEX1          ", VERT_BIT_TEX1 );
  168.    DEFINE( "VERT_BIT_TEX2          ", VERT_BIT_TEX2 );
  169.    DEFINE( "VERT_BIT_TEX3          ", VERT_BIT_TEX3 );
  170.  
  171.  
  172.    /* GLvector4f offsets:
  173.     */
  174.    OFFSET_HEADER( "GLvector4f" );
  175.  
  176.    OFFSET( "V4F_DATA          ", GLvector4f, data );
  177.    OFFSET( "V4F_START         ", GLvector4f, start );
  178.    OFFSET( "V4F_COUNT         ", GLvector4f, count );
  179.    OFFSET( "V4F_STRIDE        ", GLvector4f, stride );
  180.    OFFSET( "V4F_SIZE          ", GLvector4f, size );
  181.    OFFSET( "V4F_FLAGS         ", GLvector4f, flags );
  182.  
  183.    DEFINE_HEADER( "GLvector4f" );
  184.  
  185.    DEFINE( "VEC_MALLOC        ", VEC_MALLOC );
  186.    DEFINE( "VEC_NOT_WRITEABLE ", VEC_NOT_WRITEABLE );
  187.    DEFINE( "VEC_BAD_STRIDE    ", VEC_BAD_STRIDE );
  188.    printf( "\n" );
  189.    DEFINE( "VEC_SIZE_1        ", VEC_SIZE_1 );
  190.    DEFINE( "VEC_SIZE_2        ", VEC_SIZE_2 );
  191.    DEFINE( "VEC_SIZE_3        ", VEC_SIZE_3 );
  192.    DEFINE( "VEC_SIZE_4        ", VEC_SIZE_4 );
  193.  
  194.  
  195.    /* GLmatrix offsets:
  196.     */
  197.    OFFSET_HEADER( "GLmatrix" );
  198.  
  199.    OFFSET( "MATRIX_DATA   ", GLmatrix, m );
  200.    OFFSET( "MATRIX_INV    ", GLmatrix, inv );
  201.    OFFSET( "MATRIX_FLAGS  ", GLmatrix, flags );
  202.    OFFSET( "MATRIX_TYPE   ", GLmatrix, type );
  203.  
  204.  
  205.    /* struct gl_light offsets:
  206.     */
  207.    OFFSET_HEADER( "struct gl_light" );
  208.  
  209.    OFFSET( "LIGHT_NEXT              ", struct gl_light, next );
  210.    OFFSET( "LIGHT_PREV              ", struct gl_light, prev );
  211.    printf( "\n" );
  212.    OFFSET( "LIGHT_AMBIENT           ", struct gl_light, Ambient );
  213.    OFFSET( "LIGHT_DIFFUSE           ", struct gl_light, Diffuse );
  214.    OFFSET( "LIGHT_SPECULAR          ", struct gl_light, Specular );
  215.    OFFSET( "LIGHT_EYE_POSITION      ", struct gl_light, EyePosition );
  216.    OFFSET( "LIGHT_SPOT_DIRECTION    ", struct gl_light, SpotDirection );
  217.    OFFSET( "LIGHT_SPOT_EXPONENT     ", struct gl_light, SpotExponent );
  218.    OFFSET( "LIGHT_SPOT_CUTOFF       ", struct gl_light, SpotCutoff );
  219.    OFFSET( "LIGHT_COS_CUTOFF        ", struct gl_light, _CosCutoff );
  220.    OFFSET( "LIGHT_CONST_ATTEN       ", struct gl_light, ConstantAttenuation );
  221.    OFFSET( "LIGHT_LINEAR_ATTEN      ", struct gl_light, LinearAttenuation );
  222.    OFFSET( "LIGHT_QUADRATIC_ATTEN   ", struct gl_light, QuadraticAttenuation );
  223.    OFFSET( "LIGHT_ENABLED           ", struct gl_light, Enabled );
  224.    printf( "\n" );
  225.    OFFSET( "LIGHT_FLAGS             ", struct gl_light, _Flags );
  226.    printf( "\n" );
  227.    OFFSET( "LIGHT_POSITION          ", struct gl_light, _Position );
  228.    OFFSET( "LIGHT_VP_INF_NORM       ", struct gl_light, _VP_inf_norm );
  229.    OFFSET( "LIGHT_H_INF_NORM        ", struct gl_light, _h_inf_norm );
  230.    OFFSET( "LIGHT_NORM_DIRECTION    ", struct gl_light, _NormSpotDirection );
  231.    OFFSET( "LIGHT_VP_INF_SPOT_ATTEN ", struct gl_light, _VP_inf_spot_attenuation );
  232.    printf( "\n" );
  233.    OFFSET( "LIGHT_MAT_AMBIENT       ", struct gl_light, _MatAmbient );
  234.    OFFSET( "LIGHT_MAT_DIFFUSE       ", struct gl_light, _MatDiffuse );
  235.    OFFSET( "LIGHT_MAT_SPECULAR      ", struct gl_light, _MatSpecular );
  236.    printf( "\n" );
  237.    SIZEOF( "SIZEOF_GL_LIGHT         ", struct gl_light );
  238.  
  239.    DEFINE_HEADER( "struct gl_light" );
  240.  
  241.    DEFINE( "LIGHT_SPOT              ", LIGHT_SPOT );
  242.    DEFINE( "LIGHT_LOCAL_VIEWER      ", LIGHT_LOCAL_VIEWER );
  243.    DEFINE( "LIGHT_POSITIONAL        ", LIGHT_POSITIONAL );
  244.    printf( "\n" );
  245.    DEFINE( "LIGHT_NEED_VERTICES     ", LIGHT_NEED_VERTICES );
  246.  
  247.  
  248.    /* struct gl_lightmodel offsets:
  249.     */
  250.    OFFSET_HEADER( "struct gl_lightmodel" );
  251.  
  252.    OFFSET( "LIGHT_MODEL_AMBIENT       ", struct gl_lightmodel, Ambient );
  253.    OFFSET( "LIGHT_MODEL_LOCAL_VIEWER  ", struct gl_lightmodel, LocalViewer );
  254.    OFFSET( "LIGHT_MODEL_TWO_SIDE      ", struct gl_lightmodel, TwoSide );
  255.    OFFSET( "LIGHT_MODEL_COLOR_CONTROL ", struct gl_lightmodel, ColorControl );
  256.  
  257.  
  258.    printf( "\n" );
  259.    printf( "\n" );
  260.    printf( "#endif /* __ASM_TYPES_H__ */\n" );
  261.  
  262.    return 0;
  263. }
  264.