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.  
  39. #include <stdio.h>
  40. #include <inttypes.h>
  41.  
  42. #include "main/glheader.h"
  43. #include "main/mtypes.h"
  44. #include "tnl/t_context.h"
  45.  
  46.  
  47. #undef offsetof
  48. #define offsetof( type, member ) ((size_t) &((type *)0)->member)
  49.  
  50.  
  51. #define OFFSET_HEADER( x )                                              \
  52. do {                                                                    \
  53.    printf( "\n" );                                                      \
  54.    printf( "\n" );                                                      \
  55.    printf( "/* ====================================================="   \
  56.            "========\n" );                                              \
  57.    printf( " * Offsets for " x "\n" );                                  \
  58.    printf( " */\n" );                                                   \
  59.    printf( "\n" );                                                      \
  60. } while (0)
  61.  
  62. #define DEFINE_HEADER( x )                                              \
  63. do {                                                                    \
  64.    printf( "\n" );                                                      \
  65.    printf( "/*\n" );                                                    \
  66.    printf( " * Flags for " x "\n" );                                    \
  67.    printf( " */\n" );                                                   \
  68.    printf( "\n" );                                                      \
  69. } while (0)
  70.  
  71. #ifdef ASM_OFFSETS
  72.  
  73. /*
  74.  * Format the asm output in a special way that we can manipulate
  75.  * after the fact and turn into the final header for the target.
  76.  */
  77.  
  78. #define DEFINE_UL( s, ul )                                              \
  79.    __asm__ __volatile__ ( "\n->" s " %0" : : "i" (ul) )
  80.  
  81. #define DEFINE( s, d )                                                  \
  82.    DEFINE_UL( s, d )
  83.  
  84. #define printf( x )                                                     \
  85.    __asm__ __volatile__ ( "\n->" x )
  86.  
  87. #else
  88.  
  89. #define DEFINE_UL( s, ul )                                              \
  90.    printf( "#define %s\t%lu\n", s, (unsigned long) (ul) );
  91.  
  92. #define DEFINE( s, d )                                                  \
  93.    printf( "#define %s\t0x%" PRIx64 "\n", s, (uint64_t) d );
  94.  
  95. #endif
  96.  
  97. #define OFFSET( s, t, m )                                               \
  98.    DEFINE_UL( s, offsetof( t, m ) )
  99.  
  100. #define SIZEOF( s, t )                                                  \
  101.    DEFINE_UL( s, sizeof(t) )
  102.  
  103.  
  104.  
  105. int main( int argc, char **argv )
  106. {
  107.    printf( "/*\n" );
  108.    printf( " * This file is automatically generated from the Mesa internal type\n" );
  109.    printf( " * definitions.  Do not edit directly.\n" );
  110.    printf( " */\n" );
  111.    printf( "\n" );
  112.    printf( "#ifndef __ASM_TYPES_H__\n" );
  113.    printf( "#define __ASM_TYPES_H__\n" );
  114.    printf( "\n" );
  115.  
  116.  
  117.    /* struct gl_context offsets:
  118.     */
  119.    OFFSET_HEADER( "struct gl_context" );
  120.  
  121.    printf( "\n" );
  122.    OFFSET( "CTX_LIGHT_ENABLED           ", struct gl_context, Light.Enabled );
  123.    OFFSET( "CTX_LIGHT_SHADE_MODEL       ", struct gl_context, Light.ShadeModel );
  124.    OFFSET( "CTX_LIGHT_COLOR_MAT_FACE    ", struct gl_context, Light.ColorMaterialFace );
  125.    OFFSET( "CTX_LIGHT_COLOR_MAT_MODE    ", struct gl_context, Light.ColorMaterialMode );
  126.    OFFSET( "CTX_LIGHT_COLOR_MAT_MASK    ", struct gl_context, Light._ColorMaterialBitmask );
  127.    OFFSET( "CTX_LIGHT_COLOR_MAT_ENABLED ", struct gl_context, Light.ColorMaterialEnabled );
  128.    OFFSET( "CTX_LIGHT_ENABLED_LIST      ", struct gl_context, Light.EnabledList );
  129.    OFFSET( "CTX_LIGHT_NEED_VERTS        ", struct gl_context, Light._NeedVertices );
  130.    OFFSET( "CTX_LIGHT_BASE_COLOR        ", struct gl_context, Light._BaseColor );
  131.  
  132.  
  133.    /* struct vertex_buffer offsets:
  134.     */
  135.    OFFSET_HEADER( "struct vertex_buffer" );
  136.  
  137.    OFFSET( "VB_SIZE                ", struct vertex_buffer, Size );
  138.    OFFSET( "VB_COUNT               ", struct vertex_buffer, Count );
  139.    printf( "\n" );
  140.    OFFSET( "VB_ELTS                ", struct vertex_buffer, Elts );
  141.    OFFSET( "VB_OBJ_PTR             ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_POS] );
  142.    OFFSET( "VB_EYE_PTR             ", struct vertex_buffer, EyePtr );
  143.    OFFSET( "VB_CLIP_PTR            ", struct vertex_buffer, ClipPtr );
  144.    OFFSET( "VB_PROJ_CLIP_PTR       ", struct vertex_buffer, NdcPtr );
  145.    OFFSET( "VB_CLIP_OR_MASK        ", struct vertex_buffer, ClipOrMask );
  146.    OFFSET( "VB_CLIP_MASK           ", struct vertex_buffer, ClipMask );
  147.    OFFSET( "VB_NORMAL_PTR          ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_NORMAL] );
  148.    OFFSET( "VB_EDGE_FLAG           ", struct vertex_buffer, EdgeFlag );
  149.    OFFSET( "VB_TEX0_COORD_PTR      ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_TEX0] );
  150.    OFFSET( "VB_TEX1_COORD_PTR      ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_TEX1] );
  151.    OFFSET( "VB_TEX2_COORD_PTR      ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_TEX2] );
  152.    OFFSET( "VB_TEX3_COORD_PTR      ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_TEX3] );
  153.    OFFSET( "VB_INDEX_PTR           ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_COLOR_INDEX] );
  154.    OFFSET( "VB_COLOR_PTR           ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_COLOR0] );
  155.    OFFSET( "VB_SECONDARY_COLOR_PTR ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_COLOR1] );
  156.    OFFSET( "VB_FOG_COORD_PTR       ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_FOG] );
  157.    OFFSET( "VB_PRIMITIVE           ", struct vertex_buffer, Primitive );
  158.    printf( "\n" );
  159.  
  160.    DEFINE_HEADER( "struct vertex_buffer" );
  161.  
  162.    /* XXX use new labels here someday after vertex proram is done */
  163.    DEFINE( "VERT_BIT_OBJ           ", VERT_BIT_POS );
  164.    DEFINE( "VERT_BIT_NORM          ", VERT_BIT_NORMAL );
  165.    DEFINE( "VERT_BIT_RGBA          ", VERT_BIT_COLOR0 );
  166.    DEFINE( "VERT_BIT_SPEC_RGB      ", VERT_BIT_COLOR1 );
  167.    DEFINE( "VERT_BIT_FOG_COORD     ", VERT_BIT_FOG );
  168.    DEFINE( "VERT_BIT_TEX0          ", VERT_BIT_TEX0 );
  169.    DEFINE( "VERT_BIT_TEX1          ", VERT_BIT_TEX1 );
  170.    DEFINE( "VERT_BIT_TEX2          ", VERT_BIT_TEX2 );
  171.    DEFINE( "VERT_BIT_TEX3          ", VERT_BIT_TEX3 );
  172.  
  173.  
  174.    /* GLvector4f offsets:
  175.     */
  176.    OFFSET_HEADER( "GLvector4f" );
  177.  
  178.    OFFSET( "V4F_DATA          ", GLvector4f, data );
  179.    OFFSET( "V4F_START         ", GLvector4f, start );
  180.    OFFSET( "V4F_COUNT         ", GLvector4f, count );
  181.    OFFSET( "V4F_STRIDE        ", GLvector4f, stride );
  182.    OFFSET( "V4F_SIZE          ", GLvector4f, size );
  183.    OFFSET( "V4F_FLAGS         ", GLvector4f, flags );
  184.  
  185.    DEFINE_HEADER( "GLvector4f" );
  186.  
  187.    DEFINE( "VEC_MALLOC        ", VEC_MALLOC );
  188.    DEFINE( "VEC_NOT_WRITEABLE ", VEC_NOT_WRITEABLE );
  189.    DEFINE( "VEC_BAD_STRIDE    ", VEC_BAD_STRIDE );
  190.    printf( "\n" );
  191.    DEFINE( "VEC_SIZE_1        ", VEC_SIZE_1 );
  192.    DEFINE( "VEC_SIZE_2        ", VEC_SIZE_2 );
  193.    DEFINE( "VEC_SIZE_3        ", VEC_SIZE_3 );
  194.    DEFINE( "VEC_SIZE_4        ", VEC_SIZE_4 );
  195.  
  196.  
  197.    /* GLmatrix offsets:
  198.     */
  199.    OFFSET_HEADER( "GLmatrix" );
  200.  
  201.    OFFSET( "MATRIX_DATA   ", GLmatrix, m );
  202.    OFFSET( "MATRIX_INV    ", GLmatrix, inv );
  203.    OFFSET( "MATRIX_FLAGS  ", GLmatrix, flags );
  204.    OFFSET( "MATRIX_TYPE   ", GLmatrix, type );
  205.  
  206.  
  207.    /* struct gl_light offsets:
  208.     */
  209.    OFFSET_HEADER( "struct gl_light" );
  210.  
  211.    OFFSET( "LIGHT_NEXT              ", struct gl_light, next );
  212.    OFFSET( "LIGHT_PREV              ", struct gl_light, prev );
  213.    printf( "\n" );
  214.    OFFSET( "LIGHT_AMBIENT           ", struct gl_light, Ambient );
  215.    OFFSET( "LIGHT_DIFFUSE           ", struct gl_light, Diffuse );
  216.    OFFSET( "LIGHT_SPECULAR          ", struct gl_light, Specular );
  217.    OFFSET( "LIGHT_EYE_POSITION      ", struct gl_light, EyePosition );
  218.    OFFSET( "LIGHT_SPOT_DIRECTION    ", struct gl_light, SpotDirection );
  219.    OFFSET( "LIGHT_SPOT_EXPONENT     ", struct gl_light, SpotExponent );
  220.    OFFSET( "LIGHT_SPOT_CUTOFF       ", struct gl_light, SpotCutoff );
  221.    OFFSET( "LIGHT_COS_CUTOFF        ", struct gl_light, _CosCutoff );
  222.    OFFSET( "LIGHT_CONST_ATTEN       ", struct gl_light, ConstantAttenuation );
  223.    OFFSET( "LIGHT_LINEAR_ATTEN      ", struct gl_light, LinearAttenuation );
  224.    OFFSET( "LIGHT_QUADRATIC_ATTEN   ", struct gl_light, QuadraticAttenuation );
  225.    OFFSET( "LIGHT_ENABLED           ", struct gl_light, Enabled );
  226.    printf( "\n" );
  227.    OFFSET( "LIGHT_FLAGS             ", struct gl_light, _Flags );
  228.    printf( "\n" );
  229.    OFFSET( "LIGHT_POSITION          ", struct gl_light, _Position );
  230.    OFFSET( "LIGHT_VP_INF_NORM       ", struct gl_light, _VP_inf_norm );
  231.    OFFSET( "LIGHT_H_INF_NORM        ", struct gl_light, _h_inf_norm );
  232.    OFFSET( "LIGHT_NORM_DIRECTION    ", struct gl_light, _NormSpotDirection );
  233.    OFFSET( "LIGHT_VP_INF_SPOT_ATTEN ", struct gl_light, _VP_inf_spot_attenuation );
  234.    printf( "\n" );
  235.    OFFSET( "LIGHT_MAT_AMBIENT       ", struct gl_light, _MatAmbient );
  236.    OFFSET( "LIGHT_MAT_DIFFUSE       ", struct gl_light, _MatDiffuse );
  237.    OFFSET( "LIGHT_MAT_SPECULAR      ", struct gl_light, _MatSpecular );
  238.    printf( "\n" );
  239.    SIZEOF( "SIZEOF_GL_LIGHT         ", struct gl_light );
  240.  
  241.    DEFINE_HEADER( "struct gl_light" );
  242.  
  243.    DEFINE( "LIGHT_SPOT              ", LIGHT_SPOT );
  244.    DEFINE( "LIGHT_LOCAL_VIEWER      ", LIGHT_LOCAL_VIEWER );
  245.    DEFINE( "LIGHT_POSITIONAL        ", LIGHT_POSITIONAL );
  246.    printf( "\n" );
  247.    DEFINE( "LIGHT_NEED_VERTICES     ", LIGHT_NEED_VERTICES );
  248.  
  249.  
  250.    /* struct gl_lightmodel offsets:
  251.     */
  252.    OFFSET_HEADER( "struct gl_lightmodel" );
  253.  
  254.    OFFSET( "LIGHT_MODEL_AMBIENT       ", struct gl_lightmodel, Ambient );
  255.    OFFSET( "LIGHT_MODEL_LOCAL_VIEWER  ", struct gl_lightmodel, LocalViewer );
  256.    OFFSET( "LIGHT_MODEL_TWO_SIDE      ", struct gl_lightmodel, TwoSide );
  257.    OFFSET( "LIGHT_MODEL_COLOR_CONTROL ", struct gl_lightmodel, ColorControl );
  258.  
  259.  
  260.    printf( "\n" );
  261.    printf( "\n" );
  262.    printf( "#endif /* __ASM_TYPES_H__ */\n" );
  263.  
  264.    return 0;
  265. }
  266.