ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

slang_storage.c
Go to the documentation of this file.
00001 /*
00002  * Mesa 3-D graphics library
00003  * Version:  6.5
00004  *
00005  * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a
00008  * copy of this software and associated documentation files (the "Software"),
00009  * to deal in the Software without restriction, including without limitation
00010  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00011  * and/or sell copies of the Software, and to permit persons to whom the
00012  * Software is furnished to do so, subject to the following conditions:
00013  *
00014  * The above copyright notice and this permission notice shall be included
00015  * in all copies or substantial portions of the Software.
00016  *
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00018  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00020  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023  */
00024 
00031 #include "main/imports.h"
00032 #include "slang_storage.h"
00033 #include "slang_mem.h"
00034 
00035 /* slang_storage_array */
00036 
00037 GLboolean
00038 slang_storage_array_construct(slang_storage_array * arr)
00039 {
00040    arr->type = SLANG_STORE_AGGREGATE;
00041    arr->aggregate = NULL;
00042    arr->length = 0;
00043    return GL_TRUE;
00044 }
00045 
00046 GLvoid
00047 slang_storage_array_destruct(slang_storage_array * arr)
00048 {
00049    if (arr->aggregate != NULL) {
00050       slang_storage_aggregate_destruct(arr->aggregate);
00051       _slang_free(arr->aggregate);
00052    }
00053 }
00054 
00055 /* slang_storage_aggregate */
00056 
00057 GLboolean
00058 slang_storage_aggregate_construct(slang_storage_aggregate * agg)
00059 {
00060    agg->arrays = NULL;
00061    agg->count = 0;
00062    return GL_TRUE;
00063 }
00064 
00065 GLvoid
00066 slang_storage_aggregate_destruct(slang_storage_aggregate * agg)
00067 {
00068    GLuint i;
00069 
00070    for (i = 0; i < agg->count; i++)
00071       slang_storage_array_destruct(agg->arrays + i);
00072    _slang_free(agg->arrays);
00073 }
00074 
00075 static slang_storage_array *
00076 slang_storage_aggregate_push_new(slang_storage_aggregate * agg)
00077 {
00078    slang_storage_array *arr = NULL;
00079 
00080    agg->arrays = (slang_storage_array *)
00081       _slang_realloc(agg->arrays,
00082                      agg->count * sizeof(slang_storage_array),
00083                      (agg->count + 1) * sizeof(slang_storage_array));
00084    if (agg->arrays != NULL) {
00085       arr = agg->arrays + agg->count;
00086       if (!slang_storage_array_construct(arr))
00087          return NULL;
00088       agg->count++;
00089    }
00090    return arr;
00091 }
00092 
00093 /* _slang_aggregate_variable() */
00094 
00095 static GLboolean
00096 aggregate_vector(slang_storage_aggregate * agg, slang_storage_type basic_type,
00097                  GLuint row_count)
00098 {
00099    slang_storage_array *arr = slang_storage_aggregate_push_new(agg);
00100    if (arr == NULL)
00101       return GL_FALSE;
00102    arr->type = basic_type;
00103    arr->length = row_count;
00104    return GL_TRUE;
00105 }
00106 
00107 static GLboolean
00108 aggregate_matrix(slang_storage_aggregate * agg, slang_storage_type basic_type,
00109                  GLuint columns, GLuint rows)
00110 {
00111    slang_storage_array *arr = slang_storage_aggregate_push_new(agg);
00112    if (arr == NULL)
00113       return GL_FALSE;
00114    arr->type = SLANG_STORE_AGGREGATE;
00115    arr->length = columns;
00116    arr->aggregate = (slang_storage_aggregate *)
00117       _slang_alloc(sizeof(slang_storage_aggregate));
00118    if (arr->aggregate == NULL)
00119       return GL_FALSE;
00120    if (!slang_storage_aggregate_construct(arr->aggregate)) {
00121       _slang_free(arr->aggregate);
00122       arr->aggregate = NULL;
00123       return GL_FALSE;
00124    }
00125    if (!aggregate_vector(arr->aggregate, basic_type, rows))
00126       return GL_FALSE;
00127    return GL_TRUE;
00128 }
00129 
00130 
00131 static GLboolean
00132 aggregate_variables(slang_storage_aggregate * agg,
00133                     slang_variable_scope * vars, slang_function_scope * funcs,
00134                     slang_struct_scope * structs,
00135                     slang_variable_scope * globals,
00136                     slang_atom_pool * atoms)
00137 {
00138    GLuint i;
00139 
00140    for (i = 0; i < vars->num_variables; i++)
00141       if (!_slang_aggregate_variable(agg, &vars->variables[i]->type.specifier,
00142                                      vars->variables[i]->array_len, funcs,
00143                                      structs, globals, atoms))
00144          return GL_FALSE;
00145    return GL_TRUE;
00146 }
00147 
00148 
00149 GLboolean
00150 _slang_aggregate_variable(slang_storage_aggregate * agg,
00151                           slang_type_specifier * spec, GLuint array_len,
00152                           slang_function_scope * funcs,
00153                           slang_struct_scope * structs,
00154                           slang_variable_scope * vars,
00155                           slang_atom_pool * atoms)
00156 {
00157    switch (spec->type) {
00158    case SLANG_SPEC_BOOL:
00159       return aggregate_vector(agg, SLANG_STORE_BOOL, 1);
00160    case SLANG_SPEC_BVEC2:
00161       return aggregate_vector(agg, SLANG_STORE_BOOL, 2);
00162    case SLANG_SPEC_BVEC3:
00163       return aggregate_vector(agg, SLANG_STORE_BOOL, 3);
00164    case SLANG_SPEC_BVEC4:
00165       return aggregate_vector(agg, SLANG_STORE_BOOL, 4);
00166    case SLANG_SPEC_INT:
00167       return aggregate_vector(agg, SLANG_STORE_INT, 1);
00168    case SLANG_SPEC_IVEC2:
00169       return aggregate_vector(agg, SLANG_STORE_INT, 2);
00170    case SLANG_SPEC_IVEC3:
00171       return aggregate_vector(agg, SLANG_STORE_INT, 3);
00172    case SLANG_SPEC_IVEC4:
00173       return aggregate_vector(agg, SLANG_STORE_INT, 4);
00174    case SLANG_SPEC_FLOAT:
00175       return aggregate_vector(agg, SLANG_STORE_FLOAT, 1);
00176    case SLANG_SPEC_VEC2:
00177       return aggregate_vector(agg, SLANG_STORE_FLOAT, 2);
00178    case SLANG_SPEC_VEC3:
00179       return aggregate_vector(agg, SLANG_STORE_FLOAT, 3);
00180    case SLANG_SPEC_VEC4:
00181       return aggregate_vector(agg, SLANG_STORE_FLOAT, 4);
00182    case SLANG_SPEC_MAT2:
00183       return aggregate_matrix(agg, SLANG_STORE_FLOAT, 2, 2);
00184    case SLANG_SPEC_MAT3:
00185       return aggregate_matrix(agg, SLANG_STORE_FLOAT, 3, 3);
00186    case SLANG_SPEC_MAT4:
00187       return aggregate_matrix(agg, SLANG_STORE_FLOAT, 4, 4);
00188 
00189    case SLANG_SPEC_MAT23:
00190       return aggregate_matrix(agg, SLANG_STORE_FLOAT, 2, 3);
00191    case SLANG_SPEC_MAT32:
00192       return aggregate_matrix(agg, SLANG_STORE_FLOAT, 3, 2);
00193    case SLANG_SPEC_MAT24:
00194       return aggregate_matrix(agg, SLANG_STORE_FLOAT, 2, 4);
00195    case SLANG_SPEC_MAT42:
00196       return aggregate_matrix(agg, SLANG_STORE_FLOAT, 4, 2);
00197    case SLANG_SPEC_MAT34:
00198       return aggregate_matrix(agg, SLANG_STORE_FLOAT, 3, 4);
00199    case SLANG_SPEC_MAT43:
00200       return aggregate_matrix(agg, SLANG_STORE_FLOAT, 4, 3);
00201 
00202    case SLANG_SPEC_SAMPLER1D:
00203    case SLANG_SPEC_SAMPLER2D:
00204    case SLANG_SPEC_SAMPLER3D:
00205    case SLANG_SPEC_SAMPLERCUBE:
00206    case SLANG_SPEC_SAMPLER1DSHADOW:
00207    case SLANG_SPEC_SAMPLER2DSHADOW:
00208    case SLANG_SPEC_SAMPLER2DRECT:
00209    case SLANG_SPEC_SAMPLER2DRECTSHADOW:
00210       return aggregate_vector(agg, SLANG_STORE_INT, 1);
00211    case SLANG_SPEC_STRUCT:
00212       return aggregate_variables(agg, spec->_struct->fields, funcs, structs,
00213                                  vars, atoms);
00214    case SLANG_SPEC_ARRAY:
00215       {
00216          slang_storage_array *arr;
00217 
00218          arr = slang_storage_aggregate_push_new(agg);
00219          if (arr == NULL)
00220             return GL_FALSE;
00221          arr->type = SLANG_STORE_AGGREGATE;
00222          arr->aggregate = (slang_storage_aggregate *)
00223             _slang_alloc(sizeof(slang_storage_aggregate));
00224          if (arr->aggregate == NULL)
00225             return GL_FALSE;
00226          if (!slang_storage_aggregate_construct(arr->aggregate)) {
00227             _slang_free(arr->aggregate);
00228             arr->aggregate = NULL;
00229             return GL_FALSE;
00230          }
00231          if (!_slang_aggregate_variable(arr->aggregate, spec->_array, 0,
00232                                         funcs, structs, vars, atoms))
00233             return GL_FALSE;
00234          arr->length = array_len;
00235          /* TODO: check if 0 < arr->length <= 65535 */
00236       }
00237       return GL_TRUE;
00238    default:
00239       return GL_FALSE;
00240    }
00241 }
00242 
00243 
00244 GLuint
00245 _slang_sizeof_type(slang_storage_type type)
00246 {
00247    if (type == SLANG_STORE_AGGREGATE)
00248       return 0;
00249    if (type == SLANG_STORE_VEC4)
00250       return 4 * sizeof(GLfloat);
00251    return sizeof(GLfloat);
00252 }
00253 
00254 
00255 GLuint
00256 _slang_sizeof_aggregate(const slang_storage_aggregate * agg)
00257 {
00258    GLuint i, size = 0;
00259 
00260    for (i = 0; i < agg->count; i++) {
00261       slang_storage_array *arr = &agg->arrays[i];
00262       GLuint element_size;
00263 
00264       if (arr->type == SLANG_STORE_AGGREGATE)
00265          element_size = _slang_sizeof_aggregate(arr->aggregate);
00266       else
00267          element_size = _slang_sizeof_type(arr->type);
00268       size += element_size * arr->length;
00269    }
00270    return size;
00271 }
00272 
00273 
00274 #if 0
00275 GLboolean
00276 _slang_flatten_aggregate(slang_storage_aggregate * flat,
00277                          const slang_storage_aggregate * agg)
00278 {
00279    GLuint i;
00280 
00281    for (i = 0; i < agg->count; i++) {
00282       GLuint j;
00283 
00284       for (j = 0; j < agg->arrays[i].length; j++) {
00285          if (agg->arrays[i].type == SLANG_STORE_AGGREGATE) {
00286             if (!_slang_flatten_aggregate(flat, agg->arrays[i].aggregate))
00287                return GL_FALSE;
00288          }
00289          else {
00290             GLuint k, count;
00291             slang_storage_type type;
00292 
00293             if (agg->arrays[i].type == SLANG_STORE_VEC4) {
00294                count = 4;
00295                type = SLANG_STORE_FLOAT;
00296             }
00297             else {
00298                count = 1;
00299                type = agg->arrays[i].type;
00300             }
00301 
00302             for (k = 0; k < count; k++) {
00303                slang_storage_array *arr;
00304 
00305                arr = slang_storage_aggregate_push_new(flat);
00306                if (arr == NULL)
00307                   return GL_FALSE;
00308                arr->type = type;
00309                arr->length = 1;
00310             }
00311          }
00312       }
00313    }
00314    return GL_TRUE;
00315 }
00316 #endif

Generated on Fri May 25 2012 04:18:49 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.