Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenprog_uniform.c
Go to the documentation of this file.
00001 /* 00002 * Mesa 3-D graphics library 00003 * Version: 7.1 00004 * 00005 * Copyright (C) 1999-2008 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 "main/mtypes.h" 00033 #include "prog_uniform.h" 00034 00035 00036 struct gl_uniform_list * 00037 _mesa_new_uniform_list(void) 00038 { 00039 return CALLOC_STRUCT(gl_uniform_list); 00040 } 00041 00042 00043 void 00044 _mesa_free_uniform_list(struct gl_uniform_list *list) 00045 { 00046 GLuint i; 00047 for (i = 0; i < list->NumUniforms; i++) { 00048 _mesa_free((void *) list->Uniforms[i].Name); 00049 } 00050 _mesa_free(list->Uniforms); 00051 _mesa_free(list); 00052 } 00053 00054 00055 struct gl_uniform * 00056 _mesa_append_uniform(struct gl_uniform_list *list, 00057 const char *name, GLenum target, GLuint progPos) 00058 { 00059 const GLuint oldNum = list->NumUniforms; 00060 struct gl_uniform *uniform; 00061 GLint index; 00062 00063 assert(target == GL_VERTEX_PROGRAM_ARB || 00064 target == GL_FRAGMENT_PROGRAM_ARB); 00065 00066 index = _mesa_lookup_uniform(list, name); 00067 if (index < 0) { 00068 /* not found - append to list */ 00069 00070 if (oldNum + 1 > list->Size) { 00071 /* Need to grow the list array (alloc some extra) */ 00072 list->Size += 4; 00073 00074 /* realloc arrays */ 00075 list->Uniforms = (struct gl_uniform *) 00076 _mesa_realloc(list->Uniforms, 00077 oldNum * sizeof(struct gl_uniform), 00078 list->Size * sizeof(struct gl_uniform)); 00079 } 00080 00081 if (!list->Uniforms) { 00082 /* out of memory */ 00083 list->NumUniforms = 0; 00084 list->Size = 0; 00085 return GL_FALSE; 00086 } 00087 00088 uniform = list->Uniforms + oldNum; 00089 00090 uniform->Name = _mesa_strdup(name); 00091 uniform->VertPos = -1; 00092 uniform->FragPos = -1; 00093 uniform->Initialized = GL_FALSE; 00094 00095 list->NumUniforms++; 00096 } 00097 else { 00098 /* found */ 00099 uniform = list->Uniforms + index; 00100 } 00101 00102 /* update position for the vertex or fragment program */ 00103 if (target == GL_VERTEX_PROGRAM_ARB) { 00104 if (uniform->VertPos != -1) { 00105 /* this uniform is already in the list - that shouldn't happen */ 00106 return GL_FALSE; 00107 } 00108 uniform->VertPos = progPos; 00109 } 00110 else { 00111 if (uniform->FragPos != -1) { 00112 /* this uniform is already in the list - that shouldn't happen */ 00113 return GL_FALSE; 00114 } 00115 uniform->FragPos = progPos; 00116 } 00117 00118 return uniform; 00119 } 00120 00121 00126 GLint 00127 _mesa_lookup_uniform(const struct gl_uniform_list *list, const char *name) 00128 { 00129 GLuint i; 00130 for (i = 0; list && i < list->NumUniforms; i++) { 00131 if (!_mesa_strcmp(list->Uniforms[i].Name, name)) { 00132 return i; 00133 } 00134 } 00135 return -1; 00136 } 00137 00138 00139 GLint 00140 _mesa_longest_uniform_name(const struct gl_uniform_list *list) 00141 { 00142 GLint max = 0; 00143 GLuint i; 00144 for (i = 0; list && i < list->NumUniforms; i++) { 00145 GLuint len = _mesa_strlen(list->Uniforms[i].Name); 00146 if (len > (GLuint)max) 00147 max = len; 00148 } 00149 return max; 00150 } 00151 00152 00153 void 00154 _mesa_print_uniforms(const struct gl_uniform_list *list) 00155 { 00156 GLuint i; 00157 printf("Uniform list %p:\n", (void *) list); 00158 for (i = 0; i < list->NumUniforms; i++) { 00159 printf("%d: %s %d %d\n", 00160 i, 00161 list->Uniforms[i].Name, 00162 list->Uniforms[i].VertPos, 00163 list->Uniforms[i].FragPos); 00164 } 00165 } Generated on Sat May 26 2012 04:19:22 for ReactOS by
1.7.6.1
|