1/*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2007  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
25#ifndef PROG_STATEVARS_H
26#define PROG_STATEVARS_H
27
28
29#include "main/glheader.h"
30#include "compiler/shader_enums.h"
31#include <stdint.h>
32
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38
39struct gl_context;
40struct gl_constants;
41struct gl_program_parameter_list;
42
43
44/**
45 * Used for describing GL state referenced from inside ARB vertex and
46 * fragment programs.
47 * A string such as "state.light[0].ambient" gets translated into a
48 * sequence of tokens such as [ STATE_LIGHT, 0, STATE_AMBIENT ].
49 *
50 * For state that's an array, like STATE_CLIPPLANE, the 2nd token [1] should
51 * always be the array index.
52 */
53typedef enum gl_state_index_ {
54   STATE_NOT_STATE_VAR = 0,
55
56   STATE_MATERIAL,
57
58   STATE_LIGHT,         /* One gl_light attribute. */
59   STATE_LIGHT_ARRAY, /* Multiple gl_light attributes loaded at once. */
60   STATE_LIGHT_ATTENUATION_ARRAY,
61   STATE_LIGHTMODEL_AMBIENT,
62   STATE_LIGHTMODEL_SCENECOLOR,
63   STATE_LIGHTPROD,
64   STATE_LIGHTPROD_ARRAY_FRONT,   /* multiple lights, only front faces */
65   STATE_LIGHTPROD_ARRAY_BACK,    /* multiple lights, only back faces */
66   STATE_LIGHTPROD_ARRAY_TWOSIDE, /* multiple lights, both sides */
67
68   STATE_TEXGEN,
69   STATE_TEXENV_COLOR,
70
71   STATE_FOG_COLOR,
72   STATE_FOG_PARAMS,
73
74   STATE_CLIPPLANE,
75
76   STATE_POINT_SIZE,
77   STATE_POINT_ATTENUATION,
78
79   STATE_MODELVIEW_MATRIX,
80   STATE_MODELVIEW_MATRIX_INVERSE,
81   STATE_MODELVIEW_MATRIX_TRANSPOSE,
82   STATE_MODELVIEW_MATRIX_INVTRANS,
83
84   STATE_PROJECTION_MATRIX,
85   STATE_PROJECTION_MATRIX_INVERSE,
86   STATE_PROJECTION_MATRIX_TRANSPOSE,
87   STATE_PROJECTION_MATRIX_INVTRANS,
88
89   STATE_MVP_MATRIX,
90   STATE_MVP_MATRIX_INVERSE,
91   STATE_MVP_MATRIX_TRANSPOSE,
92   STATE_MVP_MATRIX_INVTRANS,
93
94   STATE_TEXTURE_MATRIX,
95   STATE_TEXTURE_MATRIX_INVERSE,
96   STATE_TEXTURE_MATRIX_TRANSPOSE,
97   STATE_TEXTURE_MATRIX_INVTRANS,
98
99   STATE_PROGRAM_MATRIX,
100   STATE_PROGRAM_MATRIX_INVERSE,
101   STATE_PROGRAM_MATRIX_TRANSPOSE,
102   STATE_PROGRAM_MATRIX_INVTRANS,
103
104   STATE_NUM_SAMPLES,    /* An integer, not a float like the other state vars */
105
106   STATE_DEPTH_RANGE,
107
108   STATE_FRAGMENT_PROGRAM_ENV,
109   STATE_FRAGMENT_PROGRAM_ENV_ARRAY,
110   STATE_FRAGMENT_PROGRAM_LOCAL,
111   STATE_FRAGMENT_PROGRAM_LOCAL_ARRAY,
112   STATE_VERTEX_PROGRAM_ENV,
113   STATE_VERTEX_PROGRAM_ENV_ARRAY,
114   STATE_VERTEX_PROGRAM_LOCAL,
115   STATE_VERTEX_PROGRAM_LOCAL_ARRAY,
116
117   STATE_NORMAL_SCALE_EYESPACE,
118   STATE_CURRENT_ATTRIB,        /* ctx->Current vertex attrib value */
119   STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED,        /* ctx->Current vertex attrib value after passthrough vertex processing */
120   STATE_NORMAL_SCALE,
121   STATE_FOG_PARAMS_OPTIMIZED,  /* for faster fog calc */
122   STATE_POINT_SIZE_CLAMPED,    /* includes implementation dependent size clamp */
123   STATE_LIGHT_SPOT_DIR_NORMALIZED,   /* pre-normalized spot dir */
124   STATE_LIGHT_POSITION,              /* object vs eye space */
125   STATE_LIGHT_POSITION_ARRAY,
126   STATE_LIGHT_POSITION_NORMALIZED,   /* object vs eye space */
127   STATE_LIGHT_POSITION_NORMALIZED_ARRAY,
128   STATE_LIGHT_HALF_VECTOR,           /* object vs eye space */
129   STATE_PT_SCALE,              /**< Pixel transfer RGBA scale */
130   STATE_PT_BIAS,               /**< Pixel transfer RGBA bias */
131   STATE_FB_SIZE,               /**< (width-1, height-1, 0, 0) */
132   STATE_FB_WPOS_Y_TRANSFORM,   /**< (1, 0, -1, height) if a FBO is bound, (-1, height, 1, 0) otherwise */
133   STATE_FB_PNTC_Y_TRANSFORM,   /**< (1, 0, 0, 0) if point origin is upper left, (-1, 1, 0, 0) otherwise */
134   STATE_TCS_PATCH_VERTICES_IN, /**< gl_PatchVerticesIn for TCS (integer) */
135   STATE_TES_PATCH_VERTICES_IN, /**< gl_PatchVerticesIn for TES (integer) */
136   /**
137    * A single enum gl_blend_support_qualifier value representing the
138    * currently active advanced blending equation, or zero if disabled.
139    */
140   STATE_ADVANCED_BLENDING_MODE,
141   STATE_ALPHA_REF,        /* alpha-test reference value */
142   STATE_CLIP_INTERNAL,    /* similar to STATE_CLIPPLANE, but in clip-space */
143
144   STATE_INTERNAL_DRIVER,	/* first available state index for drivers (must be last) */
145
146
147   /** All enums below don't occur in state[0]. **/
148
149   /* These 8 enums must be in the same order as the gl_light union members,
150    * which should also match the order of gl_LightSource members.
151    */
152   STATE_AMBIENT,
153   STATE_DIFFUSE,
154   STATE_SPECULAR,
155   STATE_POSITION,       /**< xyzw = position */
156   STATE_HALF_VECTOR,
157   STATE_SPOT_DIRECTION, /**< xyz = direction, w = cos(cutoff) */
158   STATE_ATTENUATION,    /**< xyz = attenuation, w = spot exponent */
159   STATE_SPOT_CUTOFF,    /**< x = cutoff, yzw = undefined */
160
161   STATE_EMISSION,
162   STATE_SHININESS,
163
164   /* These 8 enums must be in the same order as the memory layout of
165    * gl_fixedfunc_texture_unit::EyePlane/ObjectPlane.
166    */
167   STATE_TEXGEN_EYE_S,
168   STATE_TEXGEN_EYE_T,
169   STATE_TEXGEN_EYE_R,
170   STATE_TEXGEN_EYE_Q,
171   STATE_TEXGEN_OBJECT_S,
172   STATE_TEXGEN_OBJECT_T,
173   STATE_TEXGEN_OBJECT_R,
174   STATE_TEXGEN_OBJECT_Q,
175} gl_state_index;
176
177
178extern void
179_mesa_load_state_parameters(struct gl_context *ctx,
180                            struct gl_program_parameter_list *paramList);
181
182extern void
183_mesa_upload_state_parameters(struct gl_context *ctx,
184                              struct gl_program_parameter_list *paramList,
185                              uint32_t *dst);
186
187extern void
188_mesa_optimize_state_parameters(struct gl_constants *consts,
189                                struct gl_program_parameter_list *list);
190
191extern unsigned
192_mesa_program_state_value_size(const gl_state_index16 state[STATE_LENGTH]);
193
194extern GLbitfield
195_mesa_program_state_flags(const gl_state_index16 state[STATE_LENGTH]);
196
197
198extern char *
199_mesa_program_state_string(const gl_state_index16 state[STATE_LENGTH]);
200
201
202
203#ifdef __cplusplus
204}
205#endif
206
207#endif /* PROG_STATEVARS_H */
208