2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
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.
38 #include "main/glheader.h"
39 #include "main/mtypes.h"
40 #include "tnl/t_context.h"
44 #define offsetof( type, member ) ((size_t) &((type *)0)->member)
47 #define OFFSET_HEADER( x ) \
51 printf( "/* =====================================================" \
53 printf( " * Offsets for " x "\n" ); \
58 #define DEFINE_HEADER( x ) \
62 printf( " * Flags for " x "\n" ); \
70 * Format the asm output in a special way that we can manipulate
71 * after the fact and turn into the final header for the target.
74 #define DEFINE_UL( s, ul ) \
75 __asm__ __volatile__ ( "\n->" s " %0" : : "i" (ul) )
77 #define DEFINE( s, d ) \
81 __asm__ __volatile__ ( "\n->" x )
85 #define DEFINE_UL( s, ul ) \
86 printf( "#define %s\t%lu\n", s, (unsigned long) (ul) );
88 #define DEFINE( s, d ) \
89 printf( "#define %s\t0x%" PRIx64 "\n", s, (uint64_t) d );
93 #define OFFSET( s, t, m ) \
94 DEFINE_UL( s, offsetof( t, m ) )
96 #define SIZEOF( s, t ) \
97 DEFINE_UL( s, sizeof(t) )
101 int main( int argc
, char **argv
)
104 printf( " * This file is automatically generated from the Mesa internal type\n" );
105 printf( " * definitions. Do not edit directly.\n" );
108 printf( "#ifndef __ASM_TYPES_H__\n" );
109 printf( "#define __ASM_TYPES_H__\n" );
113 /* struct gl_context offsets:
115 OFFSET_HEADER( "struct gl_context" );
118 OFFSET( "CTX_LIGHT_ENABLED ", struct gl_context
, Light
.Enabled
);
119 OFFSET( "CTX_LIGHT_SHADE_MODEL ", struct gl_context
, Light
.ShadeModel
);
120 OFFSET( "CTX_LIGHT_COLOR_MAT_FACE ", struct gl_context
, Light
.ColorMaterialFace
);
121 OFFSET( "CTX_LIGHT_COLOR_MAT_MODE ", struct gl_context
, Light
.ColorMaterialMode
);
122 OFFSET( "CTX_LIGHT_COLOR_MAT_MASK ", struct gl_context
, Light
._ColorMaterialBitmask
);
123 OFFSET( "CTX_LIGHT_COLOR_MAT_ENABLED ", struct gl_context
, Light
.ColorMaterialEnabled
);
124 OFFSET( "CTX_LIGHT_ENABLED_LIGHTS ", struct gl_context
, Light
._EnabledLights
);
125 OFFSET( "CTX_LIGHT_NEED_VERTS ", struct gl_context
, Light
._NeedVertices
);
126 OFFSET( "CTX_LIGHT_BASE_COLOR ", struct gl_context
, Light
._BaseColor
);
129 /* struct vertex_buffer offsets:
131 OFFSET_HEADER( "struct vertex_buffer" );
133 OFFSET( "VB_SIZE ", struct vertex_buffer
, Size
);
134 OFFSET( "VB_COUNT ", struct vertex_buffer
, Count
);
136 OFFSET( "VB_ELTS ", struct vertex_buffer
, Elts
);
137 OFFSET( "VB_OBJ_PTR ", struct vertex_buffer
, AttribPtr
[_TNL_ATTRIB_POS
] );
138 OFFSET( "VB_EYE_PTR ", struct vertex_buffer
, EyePtr
);
139 OFFSET( "VB_CLIP_PTR ", struct vertex_buffer
, ClipPtr
);
140 OFFSET( "VB_PROJ_CLIP_PTR ", struct vertex_buffer
, NdcPtr
);
141 OFFSET( "VB_CLIP_OR_MASK ", struct vertex_buffer
, ClipOrMask
);
142 OFFSET( "VB_CLIP_MASK ", struct vertex_buffer
, ClipMask
);
143 OFFSET( "VB_NORMAL_PTR ", struct vertex_buffer
, AttribPtr
[_TNL_ATTRIB_NORMAL
] );
144 OFFSET( "VB_EDGE_FLAG ", struct vertex_buffer
, EdgeFlag
);
145 OFFSET( "VB_TEX0_COORD_PTR ", struct vertex_buffer
, AttribPtr
[_TNL_ATTRIB_TEX0
] );
146 OFFSET( "VB_TEX1_COORD_PTR ", struct vertex_buffer
, AttribPtr
[_TNL_ATTRIB_TEX1
] );
147 OFFSET( "VB_TEX2_COORD_PTR ", struct vertex_buffer
, AttribPtr
[_TNL_ATTRIB_TEX2
] );
148 OFFSET( "VB_TEX3_COORD_PTR ", struct vertex_buffer
, AttribPtr
[_TNL_ATTRIB_TEX3
] );
149 OFFSET( "VB_INDEX_PTR ", struct vertex_buffer
, AttribPtr
[_TNL_ATTRIB_COLOR_INDEX
] );
150 OFFSET( "VB_COLOR_PTR ", struct vertex_buffer
, AttribPtr
[_TNL_ATTRIB_COLOR0
] );
151 OFFSET( "VB_SECONDARY_COLOR_PTR ", struct vertex_buffer
, AttribPtr
[_TNL_ATTRIB_COLOR1
] );
152 OFFSET( "VB_FOG_COORD_PTR ", struct vertex_buffer
, AttribPtr
[_TNL_ATTRIB_FOG
] );
153 OFFSET( "VB_PRIMITIVE ", struct vertex_buffer
, Primitive
);
156 DEFINE_HEADER( "struct vertex_buffer" );
158 /* XXX use new labels here someday after vertex proram is done */
159 DEFINE( "VERT_BIT_OBJ ", VERT_BIT_POS
);
160 DEFINE( "VERT_BIT_NORM ", VERT_BIT_NORMAL
);
161 DEFINE( "VERT_BIT_RGBA ", VERT_BIT_COLOR0
);
162 DEFINE( "VERT_BIT_SPEC_RGB ", VERT_BIT_COLOR1
);
163 DEFINE( "VERT_BIT_FOG_COORD ", VERT_BIT_FOG
);
164 DEFINE( "VERT_BIT_TEX0 ", VERT_BIT_TEX0
);
165 DEFINE( "VERT_BIT_TEX1 ", VERT_BIT_TEX1
);
166 DEFINE( "VERT_BIT_TEX2 ", VERT_BIT_TEX2
);
167 DEFINE( "VERT_BIT_TEX3 ", VERT_BIT_TEX3
);
170 /* GLvector4f offsets:
172 OFFSET_HEADER( "GLvector4f" );
174 OFFSET( "V4F_DATA ", GLvector4f
, data
);
175 OFFSET( "V4F_START ", GLvector4f
, start
);
176 OFFSET( "V4F_COUNT ", GLvector4f
, count
);
177 OFFSET( "V4F_STRIDE ", GLvector4f
, stride
);
178 OFFSET( "V4F_SIZE ", GLvector4f
, size
);
179 OFFSET( "V4F_FLAGS ", GLvector4f
, flags
);
181 DEFINE_HEADER( "GLvector4f" );
183 DEFINE( "VEC_MALLOC ", VEC_MALLOC
);
184 DEFINE( "VEC_NOT_WRITEABLE ", VEC_NOT_WRITEABLE
);
185 DEFINE( "VEC_BAD_STRIDE ", VEC_BAD_STRIDE
);
187 DEFINE( "VEC_SIZE_1 ", VEC_SIZE_1
);
188 DEFINE( "VEC_SIZE_2 ", VEC_SIZE_2
);
189 DEFINE( "VEC_SIZE_3 ", VEC_SIZE_3
);
190 DEFINE( "VEC_SIZE_4 ", VEC_SIZE_4
);
195 OFFSET_HEADER( "GLmatrix" );
197 OFFSET( "MATRIX_DATA ", GLmatrix
, m
);
198 OFFSET( "MATRIX_INV ", GLmatrix
, inv
);
199 OFFSET( "MATRIX_FLAGS ", GLmatrix
, flags
);
200 OFFSET( "MATRIX_TYPE ", GLmatrix
, type
);
203 /* struct gl_light offsets:
205 OFFSET_HEADER( "struct gl_light" );
208 OFFSET( "LIGHT_AMBIENT ", struct gl_light
, Ambient
);
209 OFFSET( "LIGHT_DIFFUSE ", struct gl_light
, Diffuse
);
210 OFFSET( "LIGHT_SPECULAR ", struct gl_light
, Specular
);
211 OFFSET( "LIGHT_EYE_POSITION ", struct gl_light
, EyePosition
);
212 OFFSET( "LIGHT_SPOT_DIRECTION ", struct gl_light
, SpotDirection
);
213 OFFSET( "LIGHT_SPOT_EXPONENT ", struct gl_light
, SpotExponent
);
214 OFFSET( "LIGHT_SPOT_CUTOFF ", struct gl_light
, SpotCutoff
);
215 OFFSET( "LIGHT_COS_CUTOFF ", struct gl_light
, _CosCutoff
);
216 OFFSET( "LIGHT_CONST_ATTEN ", struct gl_light
, ConstantAttenuation
);
217 OFFSET( "LIGHT_LINEAR_ATTEN ", struct gl_light
, LinearAttenuation
);
218 OFFSET( "LIGHT_QUADRATIC_ATTEN ", struct gl_light
, QuadraticAttenuation
);
219 OFFSET( "LIGHT_ENABLED ", struct gl_light
, Enabled
);
221 OFFSET( "LIGHT_FLAGS ", struct gl_light
, _Flags
);
223 OFFSET( "LIGHT_POSITION ", struct gl_light
, _Position
);
224 OFFSET( "LIGHT_VP_INF_NORM ", struct gl_light
, _VP_inf_norm
);
225 OFFSET( "LIGHT_H_INF_NORM ", struct gl_light
, _h_inf_norm
);
226 OFFSET( "LIGHT_NORM_DIRECTION ", struct gl_light
, _NormSpotDirection
);
227 OFFSET( "LIGHT_VP_INF_SPOT_ATTEN ", struct gl_light
, _VP_inf_spot_attenuation
);
229 OFFSET( "LIGHT_MAT_AMBIENT ", struct gl_light
, _MatAmbient
);
230 OFFSET( "LIGHT_MAT_DIFFUSE ", struct gl_light
, _MatDiffuse
);
231 OFFSET( "LIGHT_MAT_SPECULAR ", struct gl_light
, _MatSpecular
);
233 SIZEOF( "SIZEOF_GL_LIGHT ", struct gl_light
);
235 DEFINE_HEADER( "struct gl_light" );
237 DEFINE( "LIGHT_SPOT ", LIGHT_SPOT
);
238 DEFINE( "LIGHT_LOCAL_VIEWER ", LIGHT_LOCAL_VIEWER
);
239 DEFINE( "LIGHT_POSITIONAL ", LIGHT_POSITIONAL
);
241 DEFINE( "LIGHT_NEED_VERTICES ", LIGHT_NEED_VERTICES
);
244 /* struct gl_lightmodel offsets:
246 OFFSET_HEADER( "struct gl_lightmodel" );
248 OFFSET( "LIGHT_MODEL_AMBIENT ", struct gl_lightmodel
, Ambient
);
249 OFFSET( "LIGHT_MODEL_LOCAL_VIEWER ", struct gl_lightmodel
, LocalViewer
);
250 OFFSET( "LIGHT_MODEL_TWO_SIDE ", struct gl_lightmodel
, TwoSide
);
251 OFFSET( "LIGHT_MODEL_COLOR_CONTROL ", struct gl_lightmodel
, ColorControl
);
256 printf( "#endif /* __ASM_TYPES_H__ */\n" );