| 1 | /* $Id: polygon.c,v 1.2 2000-03-01 18:49:35 jeroen Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * Mesa 3-D graphics library | 
|---|
| 5 | * Version:  3.1 | 
|---|
| 6 | * | 
|---|
| 7 | * Copyright (C) 1999  Brian Paul   All Rights Reserved. | 
|---|
| 8 | * | 
|---|
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a | 
|---|
| 10 | * copy of this software and associated documentation files (the "Software"), | 
|---|
| 11 | * to deal in the Software without restriction, including without limitation | 
|---|
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | 
|---|
| 13 | * and/or sell copies of the Software, and to permit persons to whom the | 
|---|
| 14 | * Software is furnished to do so, subject to the following conditions: | 
|---|
| 15 | * | 
|---|
| 16 | * The above copyright notice and this permission notice shall be included | 
|---|
| 17 | * in all copies or substantial portions of the Software. | 
|---|
| 18 | * | 
|---|
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | 
|---|
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
|---|
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL | 
|---|
| 22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | 
|---|
| 23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | 
|---|
| 24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 
|---|
| 25 | */ | 
|---|
| 26 |  | 
|---|
| 27 |  | 
|---|
| 28 | /* $XFree86: xc/lib/GL/mesa/src/polygon.c,v 1.3 1999/04/04 00:20:29 dawes Exp $ */ | 
|---|
| 29 |  | 
|---|
| 30 | #ifdef PC_HEADER | 
|---|
| 31 | #include "all.h" | 
|---|
| 32 | #else | 
|---|
| 33 | #ifndef XFree86Server | 
|---|
| 34 | #include <assert.h> | 
|---|
| 35 | #include <stdlib.h> | 
|---|
| 36 | #include <stdio.h> | 
|---|
| 37 | #include <string.h> | 
|---|
| 38 | #else | 
|---|
| 39 | #include "GL/xf86glx.h" | 
|---|
| 40 | #endif | 
|---|
| 41 | #include "types.h" | 
|---|
| 42 | #include "context.h" | 
|---|
| 43 | #include "image.h" | 
|---|
| 44 | #include "enums.h" | 
|---|
| 45 | #include "macros.h" | 
|---|
| 46 | #include "polygon.h" | 
|---|
| 47 | #endif | 
|---|
| 48 |  | 
|---|
| 49 |  | 
|---|
| 50 |  | 
|---|
| 51 | void gl_CullFace( GLcontext *ctx, GLenum mode ) | 
|---|
| 52 | { | 
|---|
| 53 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCullFace"); | 
|---|
| 54 |  | 
|---|
| 55 | if (MESA_VERBOSE&VERBOSE_API) | 
|---|
| 56 | fprintf(stderr, "glCullFace %s\n", gl_lookup_enum_by_nr(mode)); | 
|---|
| 57 |  | 
|---|
| 58 | if (mode!=GL_FRONT && mode!=GL_BACK && mode!=GL_FRONT_AND_BACK) { | 
|---|
| 59 | gl_error( ctx, GL_INVALID_ENUM, "glCullFace" ); | 
|---|
| 60 | return; | 
|---|
| 61 | } | 
|---|
| 62 |  | 
|---|
| 63 | ctx->Polygon.CullFaceMode = mode; | 
|---|
| 64 | ctx->NewState |= NEW_POLYGON; | 
|---|
| 65 |  | 
|---|
| 66 | if (ctx->Driver.CullFace) | 
|---|
| 67 | ctx->Driver.CullFace( ctx, mode ); | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 |  | 
|---|
| 71 |  | 
|---|
| 72 | void gl_FrontFace( GLcontext *ctx, GLenum mode ) | 
|---|
| 73 | { | 
|---|
| 74 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFrontFace"); | 
|---|
| 75 |  | 
|---|
| 76 | if (MESA_VERBOSE&VERBOSE_API) | 
|---|
| 77 | fprintf(stderr, "glFrontFace %s\n", gl_lookup_enum_by_nr(mode)); | 
|---|
| 78 |  | 
|---|
| 79 | if (mode!=GL_CW && mode!=GL_CCW) { | 
|---|
| 80 | gl_error( ctx, GL_INVALID_ENUM, "glFrontFace" ); | 
|---|
| 81 | return; | 
|---|
| 82 | } | 
|---|
| 83 |  | 
|---|
| 84 | ctx->Polygon.FrontFace = mode; | 
|---|
| 85 | ctx->Polygon.FrontBit = (GLboolean) (mode == GL_CW); | 
|---|
| 86 | ctx->NewState |= NEW_POLYGON; | 
|---|
| 87 |  | 
|---|
| 88 | if (ctx->Driver.FrontFace) | 
|---|
| 89 | ctx->Driver.FrontFace( ctx, mode ); | 
|---|
| 90 | } | 
|---|
| 91 |  | 
|---|
| 92 |  | 
|---|
| 93 |  | 
|---|
| 94 | void gl_PolygonMode( GLcontext *ctx, GLenum face, GLenum mode ) | 
|---|
| 95 | { | 
|---|
| 96 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPolygonMode"); | 
|---|
| 97 |  | 
|---|
| 98 | if (MESA_VERBOSE&VERBOSE_API) | 
|---|
| 99 | fprintf(stderr, "glPolygonMode %s %s\n", | 
|---|
| 100 | gl_lookup_enum_by_nr(face), | 
|---|
| 101 | gl_lookup_enum_by_nr(mode)); | 
|---|
| 102 |  | 
|---|
| 103 | if (face!=GL_FRONT && face!=GL_BACK && face!=GL_FRONT_AND_BACK) { | 
|---|
| 104 | gl_error( ctx, GL_INVALID_ENUM, "glPolygonMode(face)" ); | 
|---|
| 105 | return; | 
|---|
| 106 | } | 
|---|
| 107 | else if (mode!=GL_POINT && mode!=GL_LINE && mode!=GL_FILL) { | 
|---|
| 108 | gl_error( ctx, GL_INVALID_ENUM, "glPolygonMode(mode)" ); | 
|---|
| 109 | return; | 
|---|
| 110 | } | 
|---|
| 111 |  | 
|---|
| 112 | if (face==GL_FRONT || face==GL_FRONT_AND_BACK) { | 
|---|
| 113 | ctx->Polygon.FrontMode = mode; | 
|---|
| 114 | } | 
|---|
| 115 | if (face==GL_BACK || face==GL_FRONT_AND_BACK) { | 
|---|
| 116 | ctx->Polygon.BackMode = mode; | 
|---|
| 117 | } | 
|---|
| 118 |  | 
|---|
| 119 | /* Compute a handy "shortcut" value: */ | 
|---|
| 120 | ctx->TriangleCaps &= ~DD_TRI_UNFILLED; | 
|---|
| 121 | ctx->Polygon.Unfilled = GL_FALSE; | 
|---|
| 122 |  | 
|---|
| 123 | if (ctx->Polygon.FrontMode!=GL_FILL || ctx->Polygon.BackMode!=GL_FILL) { | 
|---|
| 124 | ctx->Polygon.Unfilled = GL_TRUE; | 
|---|
| 125 | ctx->TriangleCaps |= DD_TRI_UNFILLED; | 
|---|
| 126 | } | 
|---|
| 127 |  | 
|---|
| 128 | ctx->NewState |= (NEW_POLYGON | NEW_RASTER_OPS); | 
|---|
| 129 |  | 
|---|
| 130 | if (ctx->Driver.PolygonMode) { | 
|---|
| 131 | (*ctx->Driver.PolygonMode)( ctx, face, mode ); | 
|---|
| 132 | } | 
|---|
| 133 | } | 
|---|
| 134 |  | 
|---|
| 135 |  | 
|---|
| 136 |  | 
|---|
| 137 | /* | 
|---|
| 138 | * NOTE:  stipple pattern has already been unpacked. | 
|---|
| 139 | */ | 
|---|
| 140 | void gl_PolygonStipple( GLcontext *ctx, const GLuint pattern[32] ) | 
|---|
| 141 | { | 
|---|
| 142 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPolygonStipple"); | 
|---|
| 143 |  | 
|---|
| 144 | if (MESA_VERBOSE&VERBOSE_API) | 
|---|
| 145 | fprintf(stderr, "glPolygonStipple\n"); | 
|---|
| 146 |  | 
|---|
| 147 | MEMCPY( ctx->PolygonStipple, pattern, 32 * 4 ); | 
|---|
| 148 |  | 
|---|
| 149 | if (ctx->Polygon.StippleFlag) { | 
|---|
| 150 | ctx->NewState |= NEW_RASTER_OPS; | 
|---|
| 151 | } | 
|---|
| 152 | } | 
|---|
| 153 |  | 
|---|
| 154 |  | 
|---|
| 155 |  | 
|---|
| 156 | void gl_GetPolygonStipple( GLcontext *ctx, GLubyte *dest ) | 
|---|
| 157 | { | 
|---|
| 158 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPolygonOffset"); | 
|---|
| 159 |  | 
|---|
| 160 | if (MESA_VERBOSE&VERBOSE_API) | 
|---|
| 161 | fprintf(stderr, "glGetPolygonStipple\n"); | 
|---|
| 162 |  | 
|---|
| 163 | gl_pack_polygon_stipple( ctx, ctx->PolygonStipple, dest ); | 
|---|
| 164 | } | 
|---|
| 165 |  | 
|---|
| 166 |  | 
|---|
| 167 |  | 
|---|
| 168 | void gl_PolygonOffset( GLcontext *ctx, | 
|---|
| 169 | GLfloat factor, GLfloat units ) | 
|---|
| 170 | { | 
|---|
| 171 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPolygonOffset"); | 
|---|
| 172 |  | 
|---|
| 173 | if (MESA_VERBOSE&VERBOSE_API) | 
|---|
| 174 | fprintf(stderr, "glPolygonOffset %f %f\n", factor, units); | 
|---|
| 175 |  | 
|---|
| 176 | ctx->Polygon.OffsetFactor = factor; | 
|---|
| 177 | ctx->Polygon.OffsetUnits = units; | 
|---|
| 178 | } | 
|---|
| 179 |  | 
|---|