Home | History | Annotate | Download | only in glsl
      1 /*
      2  * Copyright  2009 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 const glsl_type glsl_type::_error_type =
     25    glsl_type(GL_INVALID_ENUM, GLSL_TYPE_ERROR, 0, 0, "");
     26 
     27 const glsl_type glsl_type::void_type =
     28    glsl_type(GL_INVALID_ENUM, GLSL_TYPE_VOID, 0, 0, "void");
     29 
     30 const glsl_type *const glsl_type::error_type = & glsl_type::_error_type;
     31 
     32 /** \name Core built-in types
     33  *
     34  * These types exist in all versions of GLSL.
     35  */
     36 /*@{*/
     37 
     38 const glsl_type glsl_type::builtin_core_types[] = {
     39    glsl_type(GL_BOOL,         GLSL_TYPE_BOOL, 1, 1, "bool"),
     40    glsl_type(GL_BOOL_VEC2,    GLSL_TYPE_BOOL, 2, 1, "bvec2"),
     41    glsl_type(GL_BOOL_VEC3,    GLSL_TYPE_BOOL, 3, 1, "bvec3"),
     42    glsl_type(GL_BOOL_VEC4,    GLSL_TYPE_BOOL, 4, 1, "bvec4"),
     43    glsl_type(GL_INT,          GLSL_TYPE_INT, 1, 1, "int"),
     44    glsl_type(GL_INT_VEC2,     GLSL_TYPE_INT, 2, 1, "ivec2"),
     45    glsl_type(GL_INT_VEC3,     GLSL_TYPE_INT, 3, 1, "ivec3"),
     46    glsl_type(GL_INT_VEC4,     GLSL_TYPE_INT, 4, 1, "ivec4"),
     47    glsl_type(GL_FLOAT,        GLSL_TYPE_FLOAT, 1, 1, "float"),
     48    glsl_type(GL_FLOAT_VEC2,   GLSL_TYPE_FLOAT, 2, 1, "vec2"),
     49    glsl_type(GL_FLOAT_VEC3,   GLSL_TYPE_FLOAT, 3, 1, "vec3"),
     50    glsl_type(GL_FLOAT_VEC4,   GLSL_TYPE_FLOAT, 4, 1, "vec4"),
     51    glsl_type(GL_FLOAT_MAT2,   GLSL_TYPE_FLOAT, 2, 2, "mat2"),
     52    glsl_type(GL_FLOAT_MAT3,   GLSL_TYPE_FLOAT, 3, 3, "mat3"),
     53    glsl_type(GL_FLOAT_MAT4,   GLSL_TYPE_FLOAT, 4, 4, "mat4"),
     54    glsl_type(GL_SAMPLER_2D,   GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_FLOAT,
     55 	     "sampler2D"),
     56    glsl_type(GL_SAMPLER_CUBE, GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_FLOAT,
     57 	     "samplerCube"),
     58 };
     59 
     60 const glsl_type *const glsl_type::bool_type  = & builtin_core_types[0];
     61 const glsl_type *const glsl_type::int_type   = & builtin_core_types[4];
     62 const glsl_type *const glsl_type::ivec4_type = & builtin_core_types[7];
     63 const glsl_type *const glsl_type::float_type = & builtin_core_types[8];
     64 const glsl_type *const glsl_type::vec2_type = & builtin_core_types[9];
     65 const glsl_type *const glsl_type::vec3_type = & builtin_core_types[10];
     66 const glsl_type *const glsl_type::vec4_type = & builtin_core_types[11];
     67 const glsl_type *const glsl_type::mat2_type = & builtin_core_types[12];
     68 const glsl_type *const glsl_type::mat3_type = & builtin_core_types[13];
     69 const glsl_type *const glsl_type::mat4_type = & builtin_core_types[14];
     70 /*@}*/
     71 
     72 /** \name GLSL structures that have not been deprecated.
     73  */
     74 /*@{*/
     75 
     76 static const struct glsl_struct_field gl_DepthRangeParameters_fields[] = {
     77    { glsl_type::float_type, "near" },
     78    { glsl_type::float_type, "far" },
     79    { glsl_type::float_type, "diff" },
     80 };
     81 
     82 const glsl_type glsl_type::builtin_structure_types[] = {
     83    glsl_type(gl_DepthRangeParameters_fields,
     84              Elements(gl_DepthRangeParameters_fields),
     85              "gl_DepthRangeParameters"),
     86 };
     87 /*@}*/
     88 
     89 /** \name GLSL 1.00 / 1.10 structures that are deprecated in GLSL 1.30
     90  */
     91 /*@{*/
     92 
     93 static const struct glsl_struct_field gl_PointParameters_fields[] = {
     94    { glsl_type::float_type, "size" },
     95    { glsl_type::float_type, "sizeMin" },
     96    { glsl_type::float_type, "sizeMax" },
     97    { glsl_type::float_type, "fadeThresholdSize" },
     98    { glsl_type::float_type, "distanceConstantAttenuation" },
     99    { glsl_type::float_type, "distanceLinearAttenuation" },
    100    { glsl_type::float_type, "distanceQuadraticAttenuation" },
    101 };
    102 
    103 static const struct glsl_struct_field gl_MaterialParameters_fields[] = {
    104    { glsl_type::vec4_type, "emission" },
    105    { glsl_type::vec4_type, "ambient" },
    106    { glsl_type::vec4_type, "diffuse" },
    107    { glsl_type::vec4_type, "specular" },
    108    { glsl_type::float_type, "shininess" },
    109 };
    110 
    111 static const struct glsl_struct_field gl_LightSourceParameters_fields[] = {
    112    { glsl_type::vec4_type, "ambient" },
    113    { glsl_type::vec4_type, "diffuse" },
    114    { glsl_type::vec4_type, "specular" },
    115    { glsl_type::vec4_type, "position" },
    116    { glsl_type::vec4_type, "halfVector" },
    117    { glsl_type::vec3_type, "spotDirection" },
    118    { glsl_type::float_type, "spotExponent" },
    119    { glsl_type::float_type, "spotCutoff" },
    120    { glsl_type::float_type, "spotCosCutoff" },
    121    { glsl_type::float_type, "constantAttenuation" },
    122    { glsl_type::float_type, "linearAttenuation" },
    123    { glsl_type::float_type, "quadraticAttenuation" },
    124 };
    125 
    126 static const struct glsl_struct_field gl_LightModelParameters_fields[] = {
    127    { glsl_type::vec4_type, "ambient" },
    128 };
    129 
    130 static const struct glsl_struct_field gl_LightModelProducts_fields[] = {
    131    { glsl_type::vec4_type, "sceneColor" },
    132 };
    133 
    134 static const struct glsl_struct_field gl_LightProducts_fields[] = {
    135    { glsl_type::vec4_type, "ambient" },
    136    { glsl_type::vec4_type, "diffuse" },
    137    { glsl_type::vec4_type, "specular" },
    138 };
    139 
    140 static const struct glsl_struct_field gl_FogParameters_fields[] = {
    141    { glsl_type::vec4_type, "color" },
    142    { glsl_type::float_type, "density" },
    143    { glsl_type::float_type, "start" },
    144    { glsl_type::float_type, "end" },
    145    { glsl_type::float_type, "scale" },
    146 };
    147 
    148 const glsl_type glsl_type::builtin_110_deprecated_structure_types[] = {
    149    glsl_type(gl_PointParameters_fields,
    150              Elements(gl_PointParameters_fields),
    151              "gl_PointParameters"),
    152    glsl_type(gl_MaterialParameters_fields,
    153              Elements(gl_MaterialParameters_fields),
    154              "gl_MaterialParameters"),
    155    glsl_type(gl_LightSourceParameters_fields,
    156              Elements(gl_LightSourceParameters_fields),
    157              "gl_LightSourceParameters"),
    158    glsl_type(gl_LightModelParameters_fields,
    159              Elements(gl_LightModelParameters_fields),
    160              "gl_LightModelParameters"),
    161    glsl_type(gl_LightModelProducts_fields,
    162              Elements(gl_LightModelProducts_fields),
    163              "gl_LightModelProducts"),
    164    glsl_type(gl_LightProducts_fields,
    165              Elements(gl_LightProducts_fields),
    166              "gl_LightProducts"),
    167    glsl_type(gl_FogParameters_fields,
    168              Elements(gl_FogParameters_fields),
    169              "gl_FogParameters"),
    170 };
    171 /*@}*/
    172 
    173 /** \name Types in GLSL 1.10 (but not GLSL ES 1.00)
    174  */
    175 /*@{*/
    176 const glsl_type glsl_type::builtin_110_types[] = {
    177    glsl_type(GL_SAMPLER_1D,   GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_FLOAT,
    178 	     "sampler1D"),
    179    glsl_type(GL_SAMPLER_1D_SHADOW, GLSL_SAMPLER_DIM_1D, 1, 0, GLSL_TYPE_FLOAT,
    180 	     "sampler1DShadow"),
    181    glsl_type(GL_SAMPLER_2D_SHADOW, GLSL_SAMPLER_DIM_2D, 1, 0, GLSL_TYPE_FLOAT,
    182 	     "sampler2DShadow"),
    183    glsl_type(GL_SAMPLER_3D,   GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_FLOAT,
    184 	     "sampler3D"),
    185 };
    186 /*@}*/
    187 
    188 /** \name Types added in GLSL 1.20
    189  */
    190 /*@{*/
    191 
    192 const glsl_type glsl_type::builtin_120_types[] = {
    193    glsl_type(GL_FLOAT_MAT2x3, GLSL_TYPE_FLOAT, 3, 2, "mat2x3"),
    194    glsl_type(GL_FLOAT_MAT2x4, GLSL_TYPE_FLOAT, 4, 2, "mat2x4"),
    195    glsl_type(GL_FLOAT_MAT3x2, GLSL_TYPE_FLOAT, 2, 3, "mat3x2"),
    196    glsl_type(GL_FLOAT_MAT3x4, GLSL_TYPE_FLOAT, 4, 3, "mat3x4"),
    197    glsl_type(GL_FLOAT_MAT4x2, GLSL_TYPE_FLOAT, 2, 4, "mat4x2"),
    198    glsl_type(GL_FLOAT_MAT4x3, GLSL_TYPE_FLOAT, 3, 4, "mat4x3"),
    199 };
    200 const glsl_type *const glsl_type::mat2x3_type = & builtin_120_types[0];
    201 const glsl_type *const glsl_type::mat2x4_type = & builtin_120_types[1];
    202 const glsl_type *const glsl_type::mat3x2_type = & builtin_120_types[2];
    203 const glsl_type *const glsl_type::mat3x4_type = & builtin_120_types[3];
    204 const glsl_type *const glsl_type::mat4x2_type = & builtin_120_types[4];
    205 const glsl_type *const glsl_type::mat4x3_type = & builtin_120_types[5];
    206 /*@}*/
    207 
    208 /** \name Types added in GLSL 1.30
    209  */
    210 /*@{*/
    211 
    212 const glsl_type glsl_type::builtin_130_types[] = {
    213    glsl_type(GL_UNSIGNED_INT,      GLSL_TYPE_UINT, 1, 1, "uint"),
    214    glsl_type(GL_UNSIGNED_INT_VEC2, GLSL_TYPE_UINT, 2, 1, "uvec2"),
    215    glsl_type(GL_UNSIGNED_INT_VEC3, GLSL_TYPE_UINT, 3, 1, "uvec3"),
    216    glsl_type(GL_UNSIGNED_INT_VEC4, GLSL_TYPE_UINT, 4, 1, "uvec4"),
    217 
    218    /* 1D and 2D texture arrays - several of these are included only in
    219     * builtin_EXT_texture_array_types.
    220     */
    221    glsl_type(GL_INT_SAMPLER_1D_ARRAY,
    222 	     GLSL_SAMPLER_DIM_1D, 0, 1,   GLSL_TYPE_INT, "isampler1DArray"),
    223    glsl_type(GL_UNSIGNED_INT_SAMPLER_1D_ARRAY,
    224 	     GLSL_SAMPLER_DIM_1D, 0, 1,  GLSL_TYPE_UINT, "usampler1DArray"),
    225    glsl_type(GL_INT_SAMPLER_2D_ARRAY,
    226 	     GLSL_SAMPLER_DIM_2D, 0, 1,   GLSL_TYPE_INT, "isampler2DArray"),
    227    glsl_type(GL_UNSIGNED_INT_SAMPLER_2D_ARRAY,
    228 	     GLSL_SAMPLER_DIM_2D, 0, 1,  GLSL_TYPE_UINT, "usampler2DArray"),
    229 
    230    /* cube shadow samplers */
    231    glsl_type(GL_SAMPLER_CUBE_SHADOW,
    232 	     GLSL_SAMPLER_DIM_CUBE, 1, 0, GLSL_TYPE_FLOAT, "samplerCubeShadow"),
    233 
    234    /* signed and unsigned integer samplers */
    235    glsl_type(GL_INT_SAMPLER_1D,
    236 	     GLSL_SAMPLER_DIM_1D, 0, 0,   GLSL_TYPE_INT, "isampler1D"),
    237    glsl_type(GL_UNSIGNED_INT_SAMPLER_1D,
    238 	     GLSL_SAMPLER_DIM_1D, 0, 0,  GLSL_TYPE_UINT, "usampler1D"),
    239    glsl_type(GL_INT_SAMPLER_2D,
    240 	     GLSL_SAMPLER_DIM_2D, 0, 0,   GLSL_TYPE_INT, "isampler2D"),
    241    glsl_type(GL_UNSIGNED_INT_SAMPLER_2D,
    242 	     GLSL_SAMPLER_DIM_2D, 0, 0,  GLSL_TYPE_UINT, "usampler2D"),
    243    glsl_type(GL_INT_SAMPLER_3D,
    244 	     GLSL_SAMPLER_DIM_3D, 0, 0,   GLSL_TYPE_INT, "isampler3D"),
    245    glsl_type(GL_UNSIGNED_INT_SAMPLER_3D,
    246 	     GLSL_SAMPLER_DIM_3D, 0, 0,  GLSL_TYPE_UINT, "usampler3D"),
    247    glsl_type(GL_INT_SAMPLER_CUBE,
    248 	     GLSL_SAMPLER_DIM_CUBE, 0, 0,   GLSL_TYPE_INT, "isamplerCube"),
    249    glsl_type(GL_INT_SAMPLER_CUBE,
    250 	     GLSL_SAMPLER_DIM_CUBE, 0, 0,  GLSL_TYPE_UINT, "usamplerCube"),
    251 };
    252 
    253 const glsl_type *const glsl_type::uint_type = & builtin_130_types[0];
    254 const glsl_type *const glsl_type::uvec2_type = & builtin_130_types[1];
    255 const glsl_type *const glsl_type::uvec3_type = & builtin_130_types[2];
    256 const glsl_type *const glsl_type::uvec4_type = & builtin_130_types[3];
    257 /*@}*/
    258 
    259 /** \name Sampler types added by GL_ARB_texture_rectangle
    260  */
    261 /*@{*/
    262 
    263 const glsl_type glsl_type::builtin_ARB_texture_rectangle_types[] = {
    264    glsl_type(GL_SAMPLER_2D_RECT,
    265 	     GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_FLOAT, "sampler2DRect"),
    266    glsl_type(GL_SAMPLER_2D_RECT_SHADOW,
    267 	     GLSL_SAMPLER_DIM_RECT, 1, 0, GLSL_TYPE_FLOAT, "sampler2DRectShadow"),
    268 };
    269 /*@}*/
    270 
    271 /** \name Sampler types added by GL_EXT_texture_array
    272  */
    273 /*@{*/
    274 
    275 const glsl_type glsl_type::builtin_EXT_texture_array_types[] = {
    276    glsl_type(GL_SAMPLER_1D_ARRAY,
    277 	     GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_FLOAT, "sampler1DArray"),
    278    glsl_type(GL_SAMPLER_2D_ARRAY,
    279 	     GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_FLOAT, "sampler2DArray"),
    280    glsl_type(GL_SAMPLER_1D_ARRAY_SHADOW,
    281 	     GLSL_SAMPLER_DIM_1D, 1, 1, GLSL_TYPE_FLOAT, "sampler1DArrayShadow"),
    282    glsl_type(GL_SAMPLER_2D_ARRAY_SHADOW,
    283 	     GLSL_SAMPLER_DIM_2D, 1, 1, GLSL_TYPE_FLOAT, "sampler2DArrayShadow"),
    284 };
    285 /*@}*/
    286 
    287 /** \name Sampler types added by GL_EXT_texture_buffer_object
    288  */
    289 /*@{*/
    290 
    291 const glsl_type glsl_type::builtin_EXT_texture_buffer_object_types[] = {
    292    glsl_type(GL_SAMPLER_BUFFER,
    293 	     GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_FLOAT, "samplerBuffer"),
    294    glsl_type(GL_INT_SAMPLER_BUFFER,
    295 	     GLSL_SAMPLER_DIM_BUF, 0, 0,   GLSL_TYPE_INT, "isamplerBuffer"),
    296    glsl_type(GL_UNSIGNED_INT_SAMPLER_BUFFER,
    297 	     GLSL_SAMPLER_DIM_BUF, 0, 0,  GLSL_TYPE_UINT, "usamplerBuffer"),
    298 };
    299 /*@}*/
    300