be9f6b254378c0f318c6d45f553b6639f409e453
[mesa.git] / src / glsl / ir_uniform.h
1 /*
2 * Copyright © 2011 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #pragma once
25 #ifndef IR_UNIFORM_H
26 #define IR_UNIFORM_H
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 /* stdbool.h is necessary because this file is included in both C and C++ code.
33 */
34 #include <stdbool.h>
35 #include "program/prog_parameter.h" /* For union gl_constant_value. */
36
37 enum gl_uniform_driver_format {
38 uniform_native = 0, /**< Store data in the native format. */
39 uniform_int_float, /**< Store integer data as floats. */
40 uniform_bool_float, /**< Store boolean data as floats. */
41
42 /**
43 * Store boolean data as integer using 1 for \c true.
44 */
45 uniform_bool_int_0_1,
46
47 /**
48 * Store boolean data as integer using ~0 for \c true.
49 */
50 uniform_bool_int_0_not0
51 };
52
53 struct gl_uniform_driver_storage {
54 /**
55 * Number of bytes from one array element to the next.
56 */
57 uint8_t element_stride;
58
59 /**
60 * Number of bytes from one vector in a matrix to the next.
61 */
62 uint8_t vector_stride;
63
64 /**
65 * Base format of the stored data.
66 *
67 * This field must have a value from \c GLSL_TYPE_UINT through \c
68 * GLSL_TYPE_SAMPLER.
69 */
70 uint8_t format;
71
72 /**
73 * Pointer to the base of the data.
74 */
75 void *data;
76 };
77
78 struct gl_uniform_storage {
79 char *name;
80 const struct glsl_type *type;
81
82 /**
83 * The number of elements in this uniform.
84 *
85 * For non-arrays, this is always 0. For arrays, the value is the size of
86 * the array.
87 */
88 unsigned array_elements;
89
90 /**
91 * Has this uniform ever been set?
92 */
93 bool initialized;
94
95 /**
96 * Base sampler index
97 *
98 * If \c ::base_type is \c GLSL_TYPE_SAMPLER, this represents the index of
99 * this sampler. If \c ::array_elements is not zero, the array will use
100 * sampler indexes \c ::sampler through \c ::sampler + \c ::array_elements
101 * - 1, inclusive.
102 */
103 uint8_t sampler;
104
105 /**
106 * Storage used by the driver for the uniform
107 */
108 unsigned num_driver_storage;
109 struct gl_uniform_driver_storage *driver_storage;
110
111 /**
112 * Storage used by Mesa for the uniform
113 *
114 * This form of the uniform is used by Mesa's implementation of \c
115 * glGetUniform. It can also be used by drivers to obtain the value of the
116 * uniform if the \c ::driver_storage interface is not used.
117 */
118 union gl_constant_value *storage;
119 };
120
121 #ifdef __cplusplus
122 }
123 #endif
124
125 #endif /* IR_UNIFORM_H */