OSDN Git Service

Merge branch 'master' of git://anongit.freedesktop.org/mesa/mesa
[android-x86/external-mesa.git] / src / mesa / program / prog_parameter.h
1 /*
2  * Mesa 3-D graphics library
3  * Version:  7.3
4  *
5  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24
25 /**
26  * \file prog_parameter.c
27  * Program parameter lists and functions.
28  * \author Brian Paul
29  */
30
31 #ifndef PROG_PARAMETER_H
32 #define PROG_PARAMETER_H
33
34 #include "main/mtypes.h"
35 #include "prog_statevars.h"
36
37
38 /**
39  * Program parameter flags
40  */
41 /*@{*/
42 #define PROG_PARAM_BIT_CENTROID   0x1  /**< for varying vars (GLSL 1.20) */
43 #define PROG_PARAM_BIT_INVARIANT  0x2  /**< for varying vars (GLSL 1.20) */
44 #define PROG_PARAM_BIT_FLAT       0x4  /**< for varying vars (GLSL 1.30) */
45 #define PROG_PARAM_BIT_LINEAR     0x8  /**< for varying vars (GLSL 1.30) */
46 #define PROG_PARAM_BIT_CYL_WRAP  0x10  /**< XXX gallium debug */
47 /*@}*/
48
49
50 /**
51  * Actual data for constant values of parameters.
52  */
53 typedef union gl_constant_value
54 {
55    GLfloat f;
56    GLboolean b;
57    GLint i;
58    GLuint u;
59 } gl_constant_value;
60
61
62 /**
63  * Program parameter.
64  * Used by shaders/programs for uniforms, constants, varying vars, etc.
65  */
66 struct gl_program_parameter
67 {
68    const char *Name;        /**< Null-terminated string */
69    gl_register_file Type;   /**< PROGRAM_NAMED_PARAM, CONSTANT or STATE_VAR */
70    GLenum DataType;         /**< GL_FLOAT, GL_FLOAT_VEC2, etc */
71    /**
72     * Number of components (1..4), or more.
73     * If the number of components is greater than 4,
74     * this parameter is part of a larger uniform like a GLSL matrix or array.
75     * The next program parameter's Size will be Size-4 of this parameter.
76     */
77    GLuint Size;
78    GLboolean Initialized;   /**< debug: Has the ParameterValue[] been set? */
79    GLbitfield Flags;        /**< Bitmask of PROG_PARAM_*_BIT */
80    /**
81     * A sequence of STATE_* tokens and integers to identify GL state.
82     */
83    gl_state_index StateIndexes[STATE_LENGTH];
84 };
85
86
87 /**
88  * List of gl_program_parameter instances.
89  */
90 struct gl_program_parameter_list
91 {
92    GLuint Size;           /**< allocated size of Parameters, ParameterValues */
93    GLuint NumParameters;  /**< number of parameters in arrays */
94    struct gl_program_parameter *Parameters; /**< Array [Size] */
95    gl_constant_value (*ParameterValues)[4]; /**< Array [Size] of constant[4] */
96    GLbitfield StateFlags; /**< _NEW_* flags indicating which state changes
97                                might invalidate ParameterValues[] */
98 };
99
100
101 extern struct gl_program_parameter_list *
102 _mesa_new_parameter_list(void);
103
104 extern struct gl_program_parameter_list *
105 _mesa_new_parameter_list_sized(unsigned size);
106
107 extern void
108 _mesa_free_parameter_list(struct gl_program_parameter_list *paramList);
109
110 extern struct gl_program_parameter_list *
111 _mesa_clone_parameter_list(const struct gl_program_parameter_list *list);
112
113 extern struct gl_program_parameter_list *
114 _mesa_combine_parameter_lists(const struct gl_program_parameter_list *a,
115                               const struct gl_program_parameter_list *b);
116
117 static INLINE GLuint
118 _mesa_num_parameters(const struct gl_program_parameter_list *list)
119 {
120    return list ? list->NumParameters : 0;
121 }
122
123 extern GLint
124 _mesa_add_parameter(struct gl_program_parameter_list *paramList,
125                     gl_register_file type, const char *name,
126                     GLuint size, GLenum datatype,
127                     const gl_constant_value *values,
128                     const gl_state_index state[STATE_LENGTH],
129                     GLbitfield flags);
130
131 extern GLint
132 _mesa_add_named_parameter(struct gl_program_parameter_list *paramList,
133                           const char *name, const gl_constant_value values[4]);
134
135 extern GLint
136 _mesa_add_named_constant(struct gl_program_parameter_list *paramList,
137                          const char *name, const gl_constant_value values[4],
138                          GLuint size);
139
140 extern GLint
141 _mesa_add_typed_unnamed_constant(struct gl_program_parameter_list *paramList,
142                            const gl_constant_value values[4], GLuint size,
143                            GLenum datatype, GLuint *swizzleOut);
144
145 extern GLint
146 _mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
147                            const gl_constant_value values[4], GLuint size,
148                            GLuint *swizzleOut);
149
150 extern GLint
151 _mesa_add_varying(struct gl_program_parameter_list *paramList,
152                   const char *name, GLuint size, GLenum datatype,
153                   GLbitfield flags);
154
155 extern GLint
156 _mesa_add_attribute(struct gl_program_parameter_list *paramList,
157                     const char *name, GLint size, GLenum datatype, GLint attrib);
158
159 extern GLint
160 _mesa_add_state_reference(struct gl_program_parameter_list *paramList,
161                           const gl_state_index stateTokens[STATE_LENGTH]);
162
163 extern gl_constant_value *
164 _mesa_lookup_parameter_value(const struct gl_program_parameter_list *paramList,
165                              GLsizei nameLen, const char *name);
166
167 extern GLint
168 _mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList,
169                              GLsizei nameLen, const char *name);
170
171 extern GLboolean
172 _mesa_lookup_parameter_constant(const struct gl_program_parameter_list *list,
173                                 const gl_constant_value v[], GLuint vSize,
174                                 GLint *posOut, GLuint *swizzleOut);
175
176 extern GLuint
177 _mesa_longest_parameter_name(const struct gl_program_parameter_list *list,
178                              gl_register_file type);
179
180 extern GLuint
181 _mesa_num_parameters_of_type(const struct gl_program_parameter_list *list,
182                              gl_register_file type);
183
184
185 #endif /* PROG_PARAMETER_H */