blob: dcc171ed74538c7e11ecaf415d31cec5635afb38 [file] [log] [blame]
Brian00cdc0a2006-12-14 15:01:06 -07001/*
2 * Mesa 3-D graphics library
Brian Paul0f228d72008-11-24 08:33:49 -07003 * Version: 7.3
Brian00cdc0a2006-12-14 15:01:06 -07004 *
Brian Paul0f228d72008-11-24 08:33:49 -07005 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
Brian00cdc0a2006-12-14 15:01:06 -07006 *
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
Brian Paul2d5087b2008-08-25 09:20:00 -060034#include "main/mtypes.h"
Brianb7978af2007-01-09 19:17:17 -070035#include "prog_statevars.h"
Brian00cdc0a2006-12-14 15:01:06 -070036
37
38/**
Brian Paul0f228d72008-11-24 08:33:49 -070039 * Program parameter flags
40 */
41/*@{*/
Brian Paulf490ec92008-11-24 09:04:52 -070042#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) */
Brian Paul4a9f1ee2010-02-04 16:40:47 -070046#define PROG_PARAM_BIT_CYL_WRAP 0x10 /**< XXX gallium debug */
Brian Paul0f228d72008-11-24 08:33:49 -070047/*@}*/
48
Bryan Cain6d89aba2011-05-17 17:13:20 -050049/**
50 * Actual data for constant values of parameters.
51 */
52typedef union gl_constant_value {
53 GLfloat f;
54 GLboolean b;
55 GLint i;
56 GLuint u;
57} gl_constant_value;
Brian Paul0f228d72008-11-24 08:33:49 -070058
59/**
Brian9805e762007-01-05 16:00:57 -070060 * Program parameter.
Brian Paul0f228d72008-11-24 08:33:49 -070061 * Used by shaders/programs for uniforms, constants, varying vars, etc.
Brian00cdc0a2006-12-14 15:01:06 -070062 */
63struct gl_program_parameter
64{
65 const char *Name; /**< Null-terminated string */
Brian Paulb4026d92009-03-07 12:02:52 -070066 gl_register_file Type; /**< PROGRAM_NAMED_PARAM, CONSTANT or STATE_VAR */
Brianc93e8832007-04-18 16:27:35 -060067 GLenum DataType; /**< GL_FLOAT, GL_FLOAT_VEC2, etc */
Nicolai Hähnle7d2699a2009-10-03 16:18:57 +020068 /**
69 * Number of components (1..4), or more.
70 * If the number of components is greater than 4,
71 * this parameter is part of a larger uniform like a GLSL matrix or array.
72 * The next program parameter's Size will be Size-4 of this parameter.
73 */
74 GLuint Size;
Eric Anholtea2231f2010-08-24 16:47:09 -070075 GLboolean Initialized; /**< debug: Has the ParameterValue[] been set? */
Brian Paul0f228d72008-11-24 08:33:49 -070076 GLbitfield Flags; /**< Bitmask of PROG_PARAM_*_BIT */
Brian00cdc0a2006-12-14 15:01:06 -070077 /**
78 * A sequence of STATE_* tokens and integers to identify GL state.
79 */
Brianaa9d22a2007-02-23 11:21:03 -070080 gl_state_index StateIndexes[STATE_LENGTH];
Brian00cdc0a2006-12-14 15:01:06 -070081};
82
83
84/**
Brian9805e762007-01-05 16:00:57 -070085 * List of gl_program_parameter instances.
Brian00cdc0a2006-12-14 15:01:06 -070086 */
87struct gl_program_parameter_list
88{
89 GLuint Size; /**< allocated size of Parameters, ParameterValues */
90 GLuint NumParameters; /**< number of parameters in arrays */
91 struct gl_program_parameter *Parameters; /**< Array [Size] */
Bryan Cain6d89aba2011-05-17 17:13:20 -050092 gl_constant_value (*ParameterValues)[4]; /**< Array [Size] of constant[4] */
Brian00cdc0a2006-12-14 15:01:06 -070093 GLbitfield StateFlags; /**< _NEW_* flags indicating which state changes
94 might invalidate ParameterValues[] */
95};
96
97
98extern struct gl_program_parameter_list *
99_mesa_new_parameter_list(void);
100
Ian Romanick480567d2009-07-08 11:39:13 -0700101extern struct gl_program_parameter_list *
102_mesa_new_parameter_list_sized(unsigned size);
103
Brian00cdc0a2006-12-14 15:01:06 -0700104extern void
105_mesa_free_parameter_list(struct gl_program_parameter_list *paramList);
106
107extern struct gl_program_parameter_list *
108_mesa_clone_parameter_list(const struct gl_program_parameter_list *list);
109
Brian Paul6ca948a2008-05-14 12:53:03 -0600110extern struct gl_program_parameter_list *
111_mesa_combine_parameter_lists(const struct gl_program_parameter_list *a,
112 const struct gl_program_parameter_list *b);
113
114static INLINE GLuint
115_mesa_num_parameters(const struct gl_program_parameter_list *list)
116{
117 return list ? list->NumParameters : 0;
118}
119
Brian00cdc0a2006-12-14 15:01:06 -0700120extern GLint
121_mesa_add_parameter(struct gl_program_parameter_list *paramList,
Brian Paulb4026d92009-03-07 12:02:52 -0700122 gl_register_file type, const char *name,
Bryan Cain6d89aba2011-05-17 17:13:20 -0500123 GLuint size, GLenum datatype,
124 const gl_constant_value *values,
Brian Paul0f228d72008-11-24 08:33:49 -0700125 const gl_state_index state[STATE_LENGTH],
126 GLbitfield flags);
Brian00cdc0a2006-12-14 15:01:06 -0700127
128extern GLint
129_mesa_add_named_parameter(struct gl_program_parameter_list *paramList,
Bryan Cain6d89aba2011-05-17 17:13:20 -0500130 const char *name, const gl_constant_value values[4]);
Brian00cdc0a2006-12-14 15:01:06 -0700131
132extern GLint
133_mesa_add_named_constant(struct gl_program_parameter_list *paramList,
Bryan Cain6d89aba2011-05-17 17:13:20 -0500134 const char *name, const gl_constant_value values[4],
Brian00cdc0a2006-12-14 15:01:06 -0700135 GLuint size);
136
137extern GLint
138_mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
Bryan Cain6d89aba2011-05-17 17:13:20 -0500139 const gl_constant_value values[4], GLuint size,
Brian00cdc0a2006-12-14 15:01:06 -0700140 GLuint *swizzleOut);
141
142extern GLint
Brian00cdc0a2006-12-14 15:01:06 -0700143_mesa_add_varying(struct gl_program_parameter_list *paramList,
Brian Paul038aba12010-04-01 22:15:16 -0600144 const char *name, GLuint size, GLenum datatype,
145 GLbitfield flags);
Brian00cdc0a2006-12-14 15:01:06 -0700146
147extern GLint
Brian3209c3e2007-01-09 17:49:24 -0700148_mesa_add_attribute(struct gl_program_parameter_list *paramList,
Brian Paulffbc66b2008-07-21 13:58:50 -0600149 const char *name, GLint size, GLenum datatype, GLint attrib);
Brian3209c3e2007-01-09 17:49:24 -0700150
151extern GLint
Brian00cdc0a2006-12-14 15:01:06 -0700152_mesa_add_state_reference(struct gl_program_parameter_list *paramList,
Brianaa9d22a2007-02-23 11:21:03 -0700153 const gl_state_index stateTokens[STATE_LENGTH]);
Brian00cdc0a2006-12-14 15:01:06 -0700154
Bryan Cain6d89aba2011-05-17 17:13:20 -0500155extern gl_constant_value *
Brian00cdc0a2006-12-14 15:01:06 -0700156_mesa_lookup_parameter_value(const struct gl_program_parameter_list *paramList,
157 GLsizei nameLen, const char *name);
158
159extern GLint
160_mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList,
161 GLsizei nameLen, const char *name);
162
163extern GLboolean
Brian5b01c5e2006-12-19 18:02:03 -0700164_mesa_lookup_parameter_constant(const struct gl_program_parameter_list *list,
Bryan Cain6d89aba2011-05-17 17:13:20 -0500165 const gl_constant_value v[], GLuint vSize,
Brian00cdc0a2006-12-14 15:01:06 -0700166 GLint *posOut, GLuint *swizzleOut);
167
Brian5b01c5e2006-12-19 18:02:03 -0700168extern GLuint
Brian6d3d9c12007-04-18 14:19:17 -0600169_mesa_longest_parameter_name(const struct gl_program_parameter_list *list,
Brian Paulb4026d92009-03-07 12:02:52 -0700170 gl_register_file type);
Brian6d3d9c12007-04-18 14:19:17 -0600171
Brian274ac7a2007-04-18 16:05:53 -0600172extern GLuint
173_mesa_num_parameters_of_type(const struct gl_program_parameter_list *list,
Brian Paulb4026d92009-03-07 12:02:52 -0700174 gl_register_file type);
Brian274ac7a2007-04-18 16:05:53 -0600175
Brian00cdc0a2006-12-14 15:01:06 -0700176
177#endif /* PROG_PARAMETER_H */