2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 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.
26 * \file prog_parameter.c
27 * Program parameter lists and functions.
31 #ifndef PROG_PARAMETER_H
32 #define PROG_PARAMETER_H
34 #include "prog_statevars.h"
43 * Names of the various vertex/fragment program register files, etc.
45 * NOTE: first four tokens must fit into 2 bits (see t_vb_arbprogram.c)
46 * All values should fit in a 4-bit field.
48 * NOTE: PROGRAM_STATE_VAR, PROGRAM_CONSTANT, and PROGRAM_UNIFORM can all be
49 * considered to be "uniform" variables since they can only be set outside
50 * glBegin/End. They're also all stored in the same Parameters array.
54 PROGRAM_TEMPORARY
, /**< machine->Temporary[] */
55 PROGRAM_ARRAY
, /**< Arrays & Matrixes */
56 PROGRAM_INPUT
, /**< machine->Inputs[] */
57 PROGRAM_OUTPUT
, /**< machine->Outputs[] */
58 PROGRAM_STATE_VAR
, /**< gl_program->Parameters[] */
59 PROGRAM_CONSTANT
, /**< gl_program->Parameters[] */
60 PROGRAM_UNIFORM
, /**< gl_program->Parameters[] */
61 PROGRAM_WRITE_ONLY
, /**< A dummy, write-only register */
62 PROGRAM_ADDRESS
, /**< machine->AddressReg */
63 PROGRAM_SAMPLER
, /**< for shader samplers, compile-time only */
64 PROGRAM_SYSTEM_VALUE
,/**< InstanceId, PrimitiveID, etc. */
65 PROGRAM_UNDEFINED
, /**< Invalid/TBD value */
66 PROGRAM_IMMEDIATE
, /**< Immediate value, used by TGSI */
67 PROGRAM_BUFFER
, /**< for shader buffers, compile-time only */
68 PROGRAM_MEMORY
, /**< for shared, global and local memory */
69 PROGRAM_IMAGE
, /**< for shader images, compile-time only */
70 PROGRAM_HW_ATOMIC
, /**< for hw atomic counters, compile-time only */
76 * Actual data for constant values of parameters.
78 typedef union gl_constant_value
89 * Used by shaders/programs for uniforms, constants, varying vars, etc.
91 struct gl_program_parameter
93 const char *Name
; /**< Null-terminated string */
94 gl_register_file Type
:16; /**< PROGRAM_CONSTANT or STATE_VAR */
95 GLenum16 DataType
; /**< GL_FLOAT, GL_FLOAT_VEC2, etc */
97 * Number of components (1..4), or more.
98 * If the number of components is greater than 4,
99 * this parameter is part of a larger uniform like a GLSL matrix or array.
100 * The next program parameter's Size will be Size-4 of this parameter.
104 * A sequence of STATE_* tokens and integers to identify GL state.
106 gl_state_index16 StateIndexes
[STATE_LENGTH
];
111 * List of gl_program_parameter instances.
113 struct gl_program_parameter_list
115 GLuint Size
; /**< allocated size of Parameters, ParameterValues */
116 GLuint NumParameters
; /**< number of used parameters in array */
117 unsigned NumParameterValues
; /**< number of used parameter values array */
118 struct gl_program_parameter
*Parameters
; /**< Array [Size] */
119 unsigned *ParameterValueOffset
;
120 gl_constant_value
*ParameterValues
; /**< Array [Size] of gl_constant_value */
121 GLbitfield StateFlags
; /**< _NEW_* flags indicating which state changes
122 might invalidate ParameterValues[] */
126 extern struct gl_program_parameter_list
*
127 _mesa_new_parameter_list(void);
129 extern struct gl_program_parameter_list
*
130 _mesa_new_parameter_list_sized(unsigned size
);
133 _mesa_free_parameter_list(struct gl_program_parameter_list
*paramList
);
136 _mesa_reserve_parameter_storage(struct gl_program_parameter_list
*paramList
,
137 unsigned reserve_slots
);
140 _mesa_add_parameter(struct gl_program_parameter_list
*paramList
,
141 gl_register_file type
, const char *name
,
142 GLuint size
, GLenum datatype
,
143 const gl_constant_value
*values
,
144 const gl_state_index16 state
[STATE_LENGTH
],
148 _mesa_add_typed_unnamed_constant(struct gl_program_parameter_list
*paramList
,
149 const gl_constant_value values
[4], GLuint size
,
150 GLenum datatype
, GLuint
*swizzleOut
);
153 _mesa_add_unnamed_constant(struct gl_program_parameter_list
*paramList
,
154 const gl_constant_value values
[4], GLuint size
,
157 return _mesa_add_typed_unnamed_constant(paramList
, values
, size
, GL_NONE
,
162 _mesa_add_sized_state_reference(struct gl_program_parameter_list
*paramList
,
163 const gl_state_index16 stateTokens
[STATE_LENGTH
],
164 const unsigned size
, bool pad_and_align
);
167 _mesa_add_state_reference(struct gl_program_parameter_list
*paramList
,
168 const gl_state_index16 stateTokens
[]);
172 _mesa_lookup_parameter_index(const struct gl_program_parameter_list
*paramList
,
178 /* name must be null-terminated */
179 for (GLint i
= 0; i
< (GLint
) paramList
->NumParameters
; i
++) {
180 if (paramList
->Parameters
[i
].Name
&&
181 strcmp(paramList
->Parameters
[i
].Name
, name
) == 0)
192 #endif /* PROG_PARAMETER_H */