1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* -*- c++ -*- */ 2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright © 2009 Intel Corporation 4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a 6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the "Software"), 7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to deal in the Software without restriction, including without limitation 8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * and/or sell copies of the Software, and to permit persons to whom the 10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Software is furnished to do so, subject to the following conditions: 11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice (including the next 13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * paragraph) shall be included in all copies or substantial portions of the 14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Software. 15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * DEALINGS IN THE SOFTWARE. 23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#pragma once 26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef GLSL_TYPES_H 27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GLSL_TYPES_H 28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <string.h> 30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <assert.h> 31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "main/mtypes.h" /* for gl_texture_index, C++'s enum rules are broken */ 32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef __cplusplus 34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgextern "C" { 35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct _mesa_glsl_parse_state; 38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct glsl_symbol_table; 39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgextern void 41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state); 42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgextern void 44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_glsl_release_types(void); 45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef __cplusplus 47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgenum glsl_base_type { 51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org GLSL_TYPE_UINT = 0, 52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org GLSL_TYPE_INT, 53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org GLSL_TYPE_FLOAT, 54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org GLSL_TYPE_BOOL, 55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org GLSL_TYPE_SAMPLER, 56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org GLSL_TYPE_STRUCT, 57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org GLSL_TYPE_ARRAY, 58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org GLSL_TYPE_VOID, 59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org GLSL_TYPE_ERROR 60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}; 61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgenum glsl_sampler_dim { 63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org GLSL_SAMPLER_DIM_1D = 0, 64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org GLSL_SAMPLER_DIM_2D, 65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org GLSL_SAMPLER_DIM_3D, 66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org GLSL_SAMPLER_DIM_CUBE, 67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org GLSL_SAMPLER_DIM_RECT, 68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org GLSL_SAMPLER_DIM_BUF, 69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org GLSL_SAMPLER_DIM_EXTERNAL 70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}; 71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef __cplusplus 73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "GL/gl.h" 74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "ralloc.h" 75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct glsl_type { 77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org GLenum gl_type; 78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_base_type base_type; 79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned sampler_dimensionality:3; /**< \see glsl_sampler_dim */ 81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned sampler_shadow:1; 82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned sampler_array:1; 83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned sampler_type:2; /**< Type of data returned using this sampler. 84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * only \c GLSL_TYPE_FLOAT, \c GLSL_TYPE_INT, 85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * and \c GLSL_TYPE_UINT are valid. 86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Callers of this ralloc-based new need not call delete. It's 89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * easier to just ralloc_free 'mem_ctx' (or any of its ancestors). */ 90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static void* operator new(size_t size) 91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (glsl_type::mem_ctx == NULL) { 93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_type::mem_ctx = ralloc_context(NULL); 94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org assert(glsl_type::mem_ctx != NULL); 95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org void *type; 98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org type = ralloc_size(glsl_type::mem_ctx, size); 100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org assert(type != NULL); 101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return type; 103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* If the user *does* call delete, that's OK, we will just 106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * ralloc_free in that case. */ 107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static void operator delete(void *type) 108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org ralloc_free(type); 110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \name Vector and matrix element counts 114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * For scalars, each of these values will be 1. For non-numeric types 116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * these will be 0. 117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /*@{*/ 119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned vector_elements:3; /**< 1, 2, 3, or 4 vector elements. */ 120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned matrix_columns:3; /**< 1, 2, 3, or 4 matrix columns. */ 121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /*@}*/ 122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Name of the data type 125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * This may be \c NULL for anonymous structures, for arrays, or for 127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * function types. 128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const char *name; 130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * For \c GLSL_TYPE_ARRAY, this is the length of the array. For 133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \c GLSL_TYPE_STRUCT, it is the number of elements in the structure and 134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the number of values pointed to by \c fields.structure (below). 135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned length; 137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Subtype of composite data types. 140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org union { 142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const struct glsl_type *array; /**< Type of array elements. */ 143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const struct glsl_type *parameters; /**< Parameters to function. */ 144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct glsl_struct_field *structure; /**< List of struct fields. */ 145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } fields; 146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \name Pointers to various public type singletons 150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /*@{*/ 152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const error_type; 153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const void_type; 154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const int_type; 155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const ivec2_type; 156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const ivec3_type; 157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const ivec4_type; 158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const uint_type; 159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const uvec2_type; 160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const uvec3_type; 161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const uvec4_type; 162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const float_type; 163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const vec2_type; 164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const vec3_type; 165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const vec4_type; 166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const bool_type; 167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const bvec2_type; 168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const bvec3_type; 169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const bvec4_type; 170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const mat2_type; 171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const mat2x3_type; 172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const mat2x4_type; 173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const mat3x2_type; 174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const mat3_type; 175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const mat3x4_type; 176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const mat4x2_type; 177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const mat4x3_type; 178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *const mat4_type; 179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /*@}*/ 180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * For numeric and boolean derrived types returns the basic scalar type 184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * If the type is a numeric or boolean scalar, vector, or matrix type, 186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * this function gets the scalar type of the individual components. For 187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * all other types, including arrays of numeric or boolean types, the 188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * error type is returned. 189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const glsl_type *get_base_type() const; 191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Get the basic scalar type which this type aggregates. 194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * If the type is a numeric or boolean scalar, vector, or matrix, or an 196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * array of any of those, this function gets the scalar type of the 197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * individual components. For structs and arrays of structs, this function 198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * returns the struct type. For samplers and arrays of samplers, this 199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * function returns the sampler type. 200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const glsl_type *get_scalar_type() const; 202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Query the type of elements in an array 205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \return 207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Pointer to the type of elements in the array for array types, or \c NULL 208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * for non-array types. 209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const glsl_type *element_type() const 211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return is_array() ? fields.array : NULL; 213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Get the instance of a built-in scalar, vector, or matrix type 217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *get_instance(unsigned base_type, unsigned rows, 219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned columns); 220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Get the instance of an array type 223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *get_array_instance(const glsl_type *base, 225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned elements); 226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Get the instance of a record type 229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type *get_record_instance(const glsl_struct_field *fields, 231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned num_fields, 232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const char *name); 233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 234f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 235f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Query the total number of scalars that make up a scalar, vector or matrix 236f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 237f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned components() const 238f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 239f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return vector_elements * matrix_columns; 240f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 241f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 242f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 243f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Calculate the number of components slots required to hold this type 244f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 245f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * This is used to determine how many uniform or varying locations a type 246f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * might occupy. 247f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 248f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned component_slots() const; 249f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 250f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 251f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Alignment in bytes of the start of this type in a std140 uniform 252f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * block. 253f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 254f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned std140_base_alignment(bool row_major) const; 255f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 256f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** Size in bytes of this type in a std140 uniform block. 257f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 258f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Note that this is not GL_UNIFORM_SIZE (which is the number of 259f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * elements in the array) 260f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 261f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned std140_size(bool row_major) const; 262f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 263f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 264f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Can this type be implicitly converted to another? 265f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 266f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \return True if the types are identical or if this type can be converted 267f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to \c desired according to Section 4.1.10 of the GLSL spec. 268f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 269f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \verbatim 270f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * From page 25 (31 of the pdf) of the GLSL 1.50 spec, Section 4.1.10 271f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Implicit Conversions: 272f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 273f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * In some situations, an expression and its type will be implicitly 274f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * converted to a different type. The following table shows all allowed 275f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * implicit conversions: 276f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 277f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Type of expression | Can be implicitly converted to 278f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * -------------------------------------------------- 279f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * int float 280f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * uint 281f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 282f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * ivec2 vec2 283f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * uvec2 284f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 285f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * ivec3 vec3 286f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * uvec3 287f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 288f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * ivec4 vec4 289f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * uvec4 290f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 291f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * There are no implicit array or structure conversions. For example, 292f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * an array of int cannot be implicitly converted to an array of float. 293f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * There are no implicit conversions between signed and unsigned 294f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * integers. 295f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \endverbatim 296f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 297f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bool can_implicitly_convert_to(const glsl_type *desired) const; 298f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 299f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 300f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Query whether or not a type is a scalar (non-vector and non-matrix). 301f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 302f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bool is_scalar() const 303f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 304f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return (vector_elements == 1) 305f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org && (base_type >= GLSL_TYPE_UINT) 306f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org && (base_type <= GLSL_TYPE_BOOL); 307f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 308f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 309f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 310f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Query whether or not a type is a vector 311f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 312f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bool is_vector() const 313f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 314f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return (vector_elements > 1) 315f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org && (matrix_columns == 1) 316f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org && (base_type >= GLSL_TYPE_UINT) 317f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org && (base_type <= GLSL_TYPE_BOOL); 318f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 319f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 320f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 321f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Query whether or not a type is a matrix 322f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 323f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bool is_matrix() const 324f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 325f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* GLSL only has float matrices. */ 326f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return (matrix_columns > 1) && (base_type == GLSL_TYPE_FLOAT); 327f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 328f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 329f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 330f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Query whether or not a type is a non-array numeric type 331f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 332f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bool is_numeric() const 333f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 334f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return (base_type >= GLSL_TYPE_UINT) && (base_type <= GLSL_TYPE_FLOAT); 335f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 336f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 337f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 338f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Query whether or not a type is an integral type 339f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 340f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bool is_integer() const 341f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 342f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return (base_type == GLSL_TYPE_UINT) || (base_type == GLSL_TYPE_INT); 343f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 344f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 345f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 346f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Query whether or not a type is a float type 347f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 348f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bool is_float() const 349f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 350f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return base_type == GLSL_TYPE_FLOAT; 351f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 352f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 353f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 354f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Query whether or not a type is a non-array boolean type 355f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 356f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bool is_boolean() const 357f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 358f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return base_type == GLSL_TYPE_BOOL; 359f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 360f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 361f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 362f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Query whether or not a type is a sampler 363f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 364f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bool is_sampler() const 365f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 366f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return base_type == GLSL_TYPE_SAMPLER; 367f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 368f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 369f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 370f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Query whether or not type is a sampler, or for struct and array 371f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * types, contains a sampler. 372f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 373f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bool contains_sampler() const; 374f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 375f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 376f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Get the Mesa texture target index for a sampler type. 377f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 378f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org gl_texture_index sampler_index() const; 379f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 380f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 381f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Query whether or not a type is an array 382f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 383f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bool is_array() const 384f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 385f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return base_type == GLSL_TYPE_ARRAY; 386f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 387f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 388f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 389f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Query whether or not a type is a record 390f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 391f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bool is_record() const 392f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 393f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return base_type == GLSL_TYPE_STRUCT; 394f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 395f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 396f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 397f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Query whether or not a type is the void type singleton. 398f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 399f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bool is_void() const 400f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 401f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return base_type == GLSL_TYPE_VOID; 402f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 403f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 404f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 405f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Query whether or not a type is the error type singleton. 406f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 407f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bool is_error() const 408f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 409f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return base_type == GLSL_TYPE_ERROR; 410f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 411f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 412f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 413f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Query the full type of a matrix row 414f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 415f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \return 416f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * If the type is not a matrix, \c glsl_type::error_type is returned. 417f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Otherwise a type matching the rows of the matrix is returned. 418f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 419f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const glsl_type *row_type() const 420f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 421f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return is_matrix() 422f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org ? get_instance(base_type, matrix_columns, 1) 423f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org : error_type; 424f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 425f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 426f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 427f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Query the full type of a matrix column 428f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 429f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \return 430f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * If the type is not a matrix, \c glsl_type::error_type is returned. 431f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Otherwise a type matching the columns of the matrix is returned. 432f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 433f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const glsl_type *column_type() const 434f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 435f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return is_matrix() 436f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org ? get_instance(base_type, vector_elements, 1) 437f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org : error_type; 438f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 439f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 440f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 441f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 442f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Get the type of a structure field 443f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 444f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \return 445f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Pointer to the type of the named field. If the type is not a structure 446f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * or the named field does not exist, \c glsl_type::error_type is returned. 447f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 448f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const glsl_type *field_type(const char *name) const; 449f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 450f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 451f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 452f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Get the location of a filed within a record type 453f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 454f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org int field_index(const char *name) const; 455f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 456f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 457f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 458f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Query the number of elements in an array type 459f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 460f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \return 461f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The number of elements in the array for array types or -1 for non-array 462f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * types. If the number of elements in the array has not yet been declared, 463f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * zero is returned. 464f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 465f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org int array_size() const 466f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 467f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return is_array() ? length : -1; 468f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 469f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 470f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgprivate: 471f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 472f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * ralloc context for all glsl_type allocations 473f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 474f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Set on the first call to \c glsl_type::new. 475f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 476f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static void *mem_ctx; 477f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 478f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org void init_ralloc_type_ctx(void); 479f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 480f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** Constructor for vector and matrix types */ 481f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_type(GLenum gl_type, 482f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_base_type base_type, unsigned vector_elements, 483f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned matrix_columns, const char *name); 484f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 485f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** Constructor for sampler types */ 486f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_type(GLenum gl_type, 487f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org enum glsl_sampler_dim dim, bool shadow, bool array, 488f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned type, const char *name); 489f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 490f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** Constructor for record types */ 491f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_type(const glsl_struct_field *fields, unsigned num_fields, 492f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const char *name); 493f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 494f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** Constructor for array types */ 495f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org glsl_type(const glsl_type *array, unsigned length); 496f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 497f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** Hash table containing the known array types. */ 498f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static struct hash_table *array_types; 499f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 500f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** Hash table containing the known record types. */ 501f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static struct hash_table *record_types; 502f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 503f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static int record_key_compare(const void *a, const void *b); 504f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static unsigned record_key_hash(const void *key); 505f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 506f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 507f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \name Pointers to various type singletons 508f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 509f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /*@{*/ 510f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type _error_type; 511f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type _void_type; 512f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type _sampler3D_type; 513f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type builtin_core_types[]; 514f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type builtin_structure_types[]; 515f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type builtin_110_deprecated_structure_types[]; 516f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type builtin_110_types[]; 517f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type builtin_120_types[]; 518f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type builtin_130_types[]; 519f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type builtin_140_types[]; 520f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type builtin_ARB_texture_rectangle_types[]; 521f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type builtin_EXT_texture_array_types[]; 522f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type builtin_EXT_texture_buffer_object_types[]; 523f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const glsl_type builtin_OES_EGL_image_external_types[]; 524f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /*@}*/ 525f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 526f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 527f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \name Methods to populate a symbol table with built-in types. 528f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 529f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \internal 530f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * This is one of the truely annoying things about C++. Methods that are 531f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * completely internal and private to a type still have to be advertised to 532f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the world in a public header file. 533f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 534f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /*@{*/ 535f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static void generate_100ES_types(glsl_symbol_table *); 536f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static void generate_110_types(glsl_symbol_table *, bool add_deprecated); 537f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static void generate_120_types(glsl_symbol_table *, bool add_deprecated); 538f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static void generate_130_types(glsl_symbol_table *, bool add_deprecated); 539f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static void generate_140_types(glsl_symbol_table *); 540f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static void generate_ARB_texture_rectangle_types(glsl_symbol_table *, bool); 541f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static void generate_EXT_texture_array_types(glsl_symbol_table *, bool); 542f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static void generate_OES_texture_3D_types(glsl_symbol_table *, bool); 543f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static void generate_OES_EGL_image_external_types(glsl_symbol_table *, bool); 544f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /*@}*/ 545f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 546f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** 547f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \name Friend functions. 548f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 549f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * These functions are friends because they must have C linkage and the 550f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * need to call various private methods or access various private static 551f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * data. 552f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 553f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /*@{*/ 554f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org friend void _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *); 555f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org friend void _mesa_glsl_release_types(void); 556f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /*@}*/ 557f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}; 558f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 559f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct glsl_struct_field { 560f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const struct glsl_type *type; 561f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const char *name; 562f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}; 563f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 564f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif /* __cplusplus */ 565f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 566f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif /* GLSL_TYPES_H */ 567