00001 /************************************************************************** 00002 * 00003 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. 00004 * All Rights Reserved. 00005 * 00006 * Permission is hereby granted, free of charge, to any person obtaining a 00007 * copy of this software and associated documentation files (the 00008 * "Software"), to deal in the Software without restriction, including 00009 * without limitation the rights to use, copy, modify, merge, publish, 00010 * distribute, sub license, and/or sell copies of the Software, and to 00011 * permit persons to whom the Software is furnished to do so, subject to 00012 * the following conditions: 00013 * 00014 * The above copyright notice and this permission notice (including the 00015 * next paragraph) shall be included in all copies or substantial portions 00016 * of the Software. 00017 * 00018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00019 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00020 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 00021 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 00022 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 00023 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 00024 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00025 * 00026 **************************************************************************/ 00027 00028 00029 #ifndef U_BLIT_H 00030 #define U_BLIT_H 00031 00032 00033 #ifdef __cplusplus 00034 extern "C" { 00035 #endif 00036 00037 #include "pipe/p_defines.h" 00038 00039 static INLINE boolean u_validate_pipe_prim( unsigned pipe_prim, unsigned nr ) 00040 { 00041 boolean ok = TRUE; 00042 00043 switch (pipe_prim) { 00044 case PIPE_PRIM_POINTS: 00045 ok = (nr >= 1); 00046 break; 00047 case PIPE_PRIM_LINES: 00048 ok = (nr >= 2); 00049 break; 00050 case PIPE_PRIM_LINE_STRIP: 00051 case PIPE_PRIM_LINE_LOOP: 00052 ok = (nr >= 2); 00053 break; 00054 case PIPE_PRIM_TRIANGLES: 00055 ok = (nr >= 3); 00056 break; 00057 case PIPE_PRIM_TRIANGLE_STRIP: 00058 case PIPE_PRIM_TRIANGLE_FAN: 00059 case PIPE_PRIM_POLYGON: 00060 ok = (nr >= 3); 00061 break; 00062 case PIPE_PRIM_QUADS: 00063 ok = (nr >= 4); 00064 break; 00065 case PIPE_PRIM_QUAD_STRIP: 00066 ok = (nr >= 4); 00067 break; 00068 default: 00069 ok = 0; 00070 break; 00071 } 00072 00073 return ok; 00074 } 00075 00076 00077 static INLINE boolean u_trim_pipe_prim( unsigned pipe_prim, unsigned *nr ) 00078 { 00079 boolean ok = TRUE; 00080 00081 switch (pipe_prim) { 00082 case PIPE_PRIM_POINTS: 00083 ok = (*nr >= 1); 00084 break; 00085 case PIPE_PRIM_LINES: 00086 ok = (*nr >= 2); 00087 *nr -= (*nr % 2); 00088 break; 00089 case PIPE_PRIM_LINE_STRIP: 00090 case PIPE_PRIM_LINE_LOOP: 00091 ok = (*nr >= 2); 00092 break; 00093 case PIPE_PRIM_TRIANGLES: 00094 ok = (*nr >= 3); 00095 *nr -= (*nr % 3); 00096 break; 00097 case PIPE_PRIM_TRIANGLE_STRIP: 00098 case PIPE_PRIM_TRIANGLE_FAN: 00099 case PIPE_PRIM_POLYGON: 00100 ok = (*nr >= 3); 00101 break; 00102 case PIPE_PRIM_QUADS: 00103 ok = (*nr >= 4); 00104 *nr -= (*nr % 4); 00105 break; 00106 case PIPE_PRIM_QUAD_STRIP: 00107 ok = (*nr >= 4); 00108 *nr -= (*nr % 2); 00109 break; 00110 default: 00111 ok = 0; 00112 break; 00113 } 00114 00115 if (!ok) 00116 *nr = 0; 00117 00118 return ok; 00119 } 00120 00121 00122 #endif