1 /* $Id: polygon.c,v 1.7 1997/07/24 01:23:44 brianp Exp $ */ 2 3 /* 4 * Mesa 3-D graphics library 5 * Version: 2.4 6 * Copyright (C) 1995-1997 Brian Paul 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Library General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Library General Public License for more details. 17 * 18 * You should have received a copy of the GNU Library General Public 19 * License along with this library; if not, write to the Free 20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 */ 22 23 24 /* 25 * $Log: polygon.c,v $ 26 * Revision 1.7 1997/07/24 01:23:44 brianp 27 * changed precompiled header symbol from PCH to PC_HEADER 28 * 29 * Revision 1.6 1997/06/03 01:58:27 brianp 30 * fixed unpacking bug in gl_PolygonStipple() 31 * 32 * Revision 1.5 1997/05/28 03:26:02 brianp 33 * added precompiled header (PCH) support 34 * 35 * Revision 1.4 1997/04/12 16:54:05 brianp 36 * new NEW_POLYGON state flag 37 * 38 * Revision 1.3 1996/10/11 03:44:58 brianp 39 * removed Polygon.OffsetBias 40 * 41 * Revision 1.2 1996/09/26 22:48:40 brianp 42 * set NEW_RASTER_OPS flag in gl_PolygonStipple() if stippling enabled 43 * 44 * Revision 1.1 1996/09/13 01:38:16 brianp 45 * Initial revision 46 * 47 */ 48 49 50 #ifdef PC_HEADER 51 #include "all.h" 52 #else 53 #include <assert.h> 54 #include <stdlib.h> 55 #include <string.h> 56 #include "context.h" 57 #include "macros.h" 58 #include "polygon.h" 59 #include "types.h" 60 #endif 61 62 63 64 void gl_CullFace( GLcontext *ctx, GLenum mode ) 65 { 66 if (mode!=GL_FRONT && mode!=GL_BACK && mode!=GL_FRONT_AND_BACK) { 67 gl_error( ctx, GL_INVALID_ENUM, "glCullFace" ); 68 return; 69 } 70 if (INSIDE_BEGIN_END(ctx)) { 71 gl_error( ctx, GL_INVALID_OPERATION, "glCullFace" ); 72 return; 73 } 74 ctx->Polygon.CullFaceMode = mode; 75 ctx->NewState |= NEW_POLYGON; 76 } 77 78 79 80 void gl_FrontFace( GLcontext *ctx, GLenum mode ) 81 { 82 if (INSIDE_BEGIN_END(ctx)) { 83 gl_error( ctx, GL_INVALID_OPERATION, "glFrontFace" ); 84 return; 85 } 86 if (mode!=GL_CW && mode!=GL_CCW) { 87 gl_error( ctx, GL_INVALID_ENUM, "glFrontFace" ); 88 return; 89 } 90 ctx->Polygon.FrontFace = mode; 91 } 92 93 94 95 void gl_PolygonMode( GLcontext *ctx, GLenum face, GLenum mode ) 96 { 97 if (INSIDE_BEGIN_END(ctx)) { 98 gl_error( ctx, GL_INVALID_OPERATION, "glPolygonMode" ); 99 return; 100 } 101 if (face!=GL_FRONT && face!=GL_BACK && face!=GL_FRONT_AND_BACK) { 102 gl_error( ctx, GL_INVALID_ENUM, "glPolygonMode(face)" ); 103 return; 104 } 105 else if (mode!=GL_POINT && mode!=GL_LINE && mode!=GL_FILL) { 106 gl_error( ctx, GL_INVALID_ENUM, "glPolygonMode(mode)" ); 107 return; 108 } 109 110 if (face==GL_FRONT || face==GL_FRONT_AND_BACK) { 111 ctx->Polygon.FrontMode = mode; 112 } 113 if (face==GL_BACK || face==GL_FRONT_AND_BACK) { 114 ctx->Polygon.BackMode = mode; 115 } 116 117 /* Compute a handy "shortcut" value: */ 118 if (ctx->Polygon.FrontMode!=GL_FILL || ctx->Polygon.BackMode!=GL_FILL) { 119 ctx->Polygon.Unfilled = GL_TRUE; 120 } 121 else { 122 ctx->Polygon.Unfilled = GL_FALSE; 123 } 124 125 ctx->NewState |= NEW_POLYGON; 126 } 127 128 129 130 void gl_PolygonStipple( GLcontext *ctx, const GLubyte *mask ) 131 { 132 GLint i; 133 134 if (INSIDE_BEGIN_END(ctx)) { 135 gl_error( ctx, GL_INVALID_OPERATION, "glPolygonStipple" ); 136 return; 137 } 138 139 /* TODO: bit twiddling, unpacking */ 140 for (i=0;i<32;i++) { 141 ctx->PolygonStipple[i] = (mask[i*4+0] << 24) 142 | (mask[i*4+1] << 16) 143 | (mask[i*4+2] << 8) 144 | (mask[i*4+3]); 145 } 146 147 if (ctx->Polygon.StippleFlag) { 148 ctx->NewState |= NEW_RASTER_OPS; 149 } 150 } 151 152 153 154 void gl_GetPolygonStipple( GLcontext *ctx, GLubyte *mask ) 155 { 156 /* TODO */ 157 } 158 159 160 161 void gl_PolygonOffset( GLcontext *ctx, 162 GLfloat factor, GLfloat units ) 163 { 164 if (INSIDE_BEGIN_END(ctx)) { 165 gl_error( ctx, GL_INVALID_OPERATION, "glPolygonOffset" ); 166 return; 167 } 168 ctx->Polygon.OffsetFactor = factor; 169 ctx->Polygon.OffsetUnits = units; 170 } 171 172