Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenapi_validate.c
Go to the documentation of this file.
00001 /* 00002 * Mesa 3-D graphics library 00003 * Version: 7.1 00004 * 00005 * Copyright (C) 1999-2007 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 00025 #include "glheader.h" 00026 #include "api_validate.h" 00027 #include "context.h" 00028 #include "imports.h" 00029 #include "mtypes.h" 00030 #include "state.h" 00031 00032 00036 static GLuint 00037 max_buffer_index(GLcontext *ctx, GLuint count, GLenum type, 00038 const void *indices, 00039 struct gl_buffer_object *elementBuf) 00040 { 00041 const GLubyte *map = NULL; 00042 GLuint max = 0; 00043 GLint i; 00044 00045 if (elementBuf->Name) { 00046 /* elements are in a user-defined buffer object. need to map it */ 00047 map = ctx->Driver.MapBuffer(ctx, 00048 GL_ELEMENT_ARRAY_BUFFER_ARB, 00049 GL_READ_ONLY, 00050 elementBuf); 00051 /* Actual address is the sum of pointers */ 00052 indices = (const GLvoid *) ADD_POINTERS(map, (const GLubyte *) indices); 00053 } 00054 00055 if (type == GL_UNSIGNED_INT) { 00056 for (i = 0; i < count; i++) 00057 if (((GLuint *) indices)[i] > max) 00058 max = ((GLuint *) indices)[i]; 00059 } 00060 else if (type == GL_UNSIGNED_SHORT) { 00061 for (i = 0; i < count; i++) 00062 if (((GLushort *) indices)[i] > max) 00063 max = ((GLushort *) indices)[i]; 00064 } 00065 else { 00066 ASSERT(type == GL_UNSIGNED_BYTE); 00067 for (i = 0; i < count; i++) 00068 if (((GLubyte *) indices)[i] > max) 00069 max = ((GLubyte *) indices)[i]; 00070 } 00071 00072 if (map) { 00073 ctx->Driver.UnmapBuffer(ctx, 00074 GL_ELEMENT_ARRAY_BUFFER_ARB, 00075 ctx->Array.ElementArrayBufferObj); 00076 } 00077 00078 return max; 00079 } 00080 00081 static GLboolean 00082 check_valid_to_render(GLcontext *ctx, char *function) 00083 { 00084 if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { 00085 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, 00086 "glDraw%s(incomplete framebuffer)", function); 00087 return GL_FALSE; 00088 } 00089 00090 #if FEATURE_es2_glsl 00091 /* For ES2, we can draw if any vertex array is enabled (and we should 00092 * always have a vertex program/shader). 00093 */ 00094 if (ctx->Array.ArrayObj->_Enabled == 0x0 || !ctx->VertexProgram._Current) 00095 return GL_FALSE; 00096 #else 00097 /* For regular OpenGL, only draw if we have vertex positions (regardless 00098 * of whether or not we have a vertex program/shader). 00099 */ 00100 if (!ctx->Array.ArrayObj->Vertex.Enabled && 00101 !ctx->Array.ArrayObj->VertexAttrib[0].Enabled) 00102 return GL_FALSE; 00103 #endif 00104 00105 return GL_TRUE; 00106 } 00107 00108 GLboolean 00109 _mesa_validate_DrawElements(GLcontext *ctx, 00110 GLenum mode, GLsizei count, GLenum type, 00111 const GLvoid *indices) 00112 { 00113 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); 00114 00115 if (count <= 0) { 00116 if (count < 0) 00117 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawElements(count)" ); 00118 return GL_FALSE; 00119 } 00120 00121 if (mode > GL_POLYGON) { 00122 _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(mode)" ); 00123 return GL_FALSE; 00124 } 00125 00126 if (type != GL_UNSIGNED_INT && 00127 type != GL_UNSIGNED_BYTE && 00128 type != GL_UNSIGNED_SHORT) 00129 { 00130 _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(type)" ); 00131 return GL_FALSE; 00132 } 00133 00134 if (ctx->NewState) 00135 _mesa_update_state(ctx); 00136 00137 if (!check_valid_to_render(ctx, "Elements")) 00138 return GL_FALSE; 00139 00140 /* Vertex buffer object tests */ 00141 if (ctx->Array.ElementArrayBufferObj->Name) { 00142 /* use indices in the buffer object */ 00143 GLuint indexBytes; 00144 00145 if (type == GL_UNSIGNED_INT) { 00146 indexBytes = count * sizeof(GLuint); 00147 } 00148 else if (type == GL_UNSIGNED_BYTE) { 00149 indexBytes = count * sizeof(GLubyte); 00150 } 00151 else { 00152 ASSERT(type == GL_UNSIGNED_SHORT); 00153 indexBytes = count * sizeof(GLushort); 00154 } 00155 00156 /* make sure count doesn't go outside buffer bounds */ 00157 if (indexBytes > (GLuint) ctx->Array.ElementArrayBufferObj->Size) { 00158 _mesa_warning(ctx, "glDrawElements index out of buffer bounds"); 00159 return GL_FALSE; 00160 } 00161 } 00162 else { 00163 /* not using a VBO */ 00164 if (!indices) 00165 return GL_FALSE; 00166 } 00167 00168 if (ctx->Const.CheckArrayBounds) { 00169 /* find max array index */ 00170 GLuint max = max_buffer_index(ctx, count, type, indices, 00171 ctx->Array.ElementArrayBufferObj); 00172 if (max >= ctx->Array._MaxElement) { 00173 /* the max element is out of bounds of one or more enabled arrays */ 00174 return GL_FALSE; 00175 } 00176 } 00177 00178 return GL_TRUE; 00179 } 00180 00181 GLboolean 00182 _mesa_validate_DrawRangeElements(GLcontext *ctx, GLenum mode, 00183 GLuint start, GLuint end, 00184 GLsizei count, GLenum type, 00185 const GLvoid *indices) 00186 { 00187 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); 00188 00189 if (count <= 0) { 00190 if (count < 0) 00191 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(count)" ); 00192 return GL_FALSE; 00193 } 00194 00195 if (mode > GL_POLYGON) { 00196 _mesa_error(ctx, GL_INVALID_ENUM, "glDrawRangeElements(mode)" ); 00197 return GL_FALSE; 00198 } 00199 00200 if (end < start) { 00201 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(end<start)"); 00202 return GL_FALSE; 00203 } 00204 00205 if (type != GL_UNSIGNED_INT && 00206 type != GL_UNSIGNED_BYTE && 00207 type != GL_UNSIGNED_SHORT) { 00208 _mesa_error(ctx, GL_INVALID_ENUM, "glDrawRangeElements(type)" ); 00209 return GL_FALSE; 00210 } 00211 00212 if (ctx->NewState) 00213 _mesa_update_state(ctx); 00214 00215 if (!check_valid_to_render(ctx, "RangeElements")) 00216 return GL_FALSE; 00217 00218 /* Vertex buffer object tests */ 00219 if (ctx->Array.ElementArrayBufferObj->Name) { 00220 /* use indices in the buffer object */ 00221 GLuint indexBytes; 00222 00223 if (type == GL_UNSIGNED_INT) { 00224 indexBytes = count * sizeof(GLuint); 00225 } 00226 else if (type == GL_UNSIGNED_BYTE) { 00227 indexBytes = count * sizeof(GLubyte); 00228 } 00229 else { 00230 ASSERT(type == GL_UNSIGNED_SHORT); 00231 indexBytes = count * sizeof(GLushort); 00232 } 00233 00234 /* make sure count doesn't go outside buffer bounds */ 00235 if (indexBytes > ctx->Array.ElementArrayBufferObj->Size) { 00236 _mesa_warning(ctx, "glDrawRangeElements index out of buffer bounds"); 00237 return GL_FALSE; 00238 } 00239 } 00240 else { 00241 /* not using a VBO */ 00242 if (!indices) 00243 return GL_FALSE; 00244 } 00245 00246 if (ctx->Const.CheckArrayBounds) { 00247 GLuint max = max_buffer_index(ctx, count, type, indices, 00248 ctx->Array.ElementArrayBufferObj); 00249 if (max >= ctx->Array._MaxElement) { 00250 /* the max element is out of bounds of one or more enabled arrays */ 00251 return GL_FALSE; 00252 } 00253 } 00254 00255 return GL_TRUE; 00256 } 00257 00258 00263 GLboolean 00264 _mesa_validate_DrawArrays(GLcontext *ctx, 00265 GLenum mode, GLint start, GLsizei count) 00266 { 00267 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); 00268 00269 if (count <= 0) { 00270 if (count < 0) 00271 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawArrays(count)" ); 00272 return GL_FALSE; 00273 } 00274 00275 if (mode > GL_POLYGON) { 00276 _mesa_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" ); 00277 return GL_FALSE; 00278 } 00279 00280 if (ctx->NewState) 00281 _mesa_update_state(ctx); 00282 00283 if (!check_valid_to_render(ctx, "Arrays")) 00284 return GL_FALSE; 00285 00286 if (ctx->Const.CheckArrayBounds) { 00287 if (start + count > (GLint) ctx->Array._MaxElement) 00288 return GL_FALSE; 00289 } 00290 00291 return GL_TRUE; 00292 } Generated on Fri May 25 2012 04:18:16 for ReactOS by
1.7.6.1
|