Merge branch 'draw-instanced'
[mesa.git] / src / mesa / main / hint.c
1
2 /*
3 * Mesa 3-D graphics library
4 * Version: 4.1
5 *
6 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 #include "glheader.h"
28 #include "enums.h"
29 #include "context.h"
30 #include "hint.h"
31 #include "imports.h"
32 #include "mtypes.h"
33
34
35
36 void GLAPIENTRY
37 _mesa_Hint( GLenum target, GLenum mode )
38 {
39 GET_CURRENT_CONTEXT(ctx);
40 ASSERT_OUTSIDE_BEGIN_END(ctx);
41
42 if (MESA_VERBOSE & VERBOSE_API)
43 _mesa_debug(ctx, "glHint %s %d\n",
44 _mesa_lookup_enum_by_nr(target), mode);
45
46 if (mode != GL_NICEST && mode != GL_FASTEST && mode != GL_DONT_CARE) {
47 _mesa_error(ctx, GL_INVALID_ENUM, "glHint(mode)");
48 return;
49 }
50
51 switch (target) {
52 case GL_FOG_HINT:
53 if (ctx->Hint.Fog == mode)
54 return;
55 FLUSH_VERTICES(ctx, _NEW_HINT);
56 ctx->Hint.Fog = mode;
57 break;
58 case GL_LINE_SMOOTH_HINT:
59 if (ctx->Hint.LineSmooth == mode)
60 return;
61 FLUSH_VERTICES(ctx, _NEW_HINT);
62 ctx->Hint.LineSmooth = mode;
63 break;
64 case GL_PERSPECTIVE_CORRECTION_HINT:
65 if (ctx->Hint.PerspectiveCorrection == mode)
66 return;
67 FLUSH_VERTICES(ctx, _NEW_HINT);
68 ctx->Hint.PerspectiveCorrection = mode;
69 break;
70 case GL_POINT_SMOOTH_HINT:
71 if (ctx->Hint.PointSmooth == mode)
72 return;
73 FLUSH_VERTICES(ctx, _NEW_HINT);
74 ctx->Hint.PointSmooth = mode;
75 break;
76 case GL_POLYGON_SMOOTH_HINT:
77 if (ctx->Hint.PolygonSmooth == mode)
78 return;
79 FLUSH_VERTICES(ctx, _NEW_HINT);
80 ctx->Hint.PolygonSmooth = mode;
81 break;
82
83 /* GL_EXT_clip_volume_hint */
84 case GL_CLIP_VOLUME_CLIPPING_HINT_EXT:
85 if (ctx->Hint.ClipVolumeClipping == mode)
86 return;
87 FLUSH_VERTICES(ctx, _NEW_HINT);
88 ctx->Hint.ClipVolumeClipping = mode;
89 break;
90
91 /* GL_ARB_texture_compression */
92 case GL_TEXTURE_COMPRESSION_HINT_ARB:
93 if (ctx->Hint.TextureCompression == mode)
94 return;
95 FLUSH_VERTICES(ctx, _NEW_HINT);
96 ctx->Hint.TextureCompression = mode;
97 break;
98
99 /* GL_SGIS_generate_mipmap */
100 case GL_GENERATE_MIPMAP_HINT_SGIS:
101 if (ctx->Hint.GenerateMipmap == mode)
102 return;
103 FLUSH_VERTICES(ctx, _NEW_HINT);
104 ctx->Hint.GenerateMipmap = mode;
105 break;
106
107 /* GL_ARB_fragment_shader */
108 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB:
109 if (!ctx->Extensions.ARB_fragment_shader) {
110 _mesa_error(ctx, GL_INVALID_ENUM, "glHint(target)");
111 return;
112 }
113 if (ctx->Hint.FragmentShaderDerivative == mode)
114 return;
115 FLUSH_VERTICES(ctx, _NEW_HINT);
116 ctx->Hint.FragmentShaderDerivative = mode;
117 break;
118
119 default:
120 _mesa_error(ctx, GL_INVALID_ENUM, "glHint(target)");
121 return;
122 }
123
124 if (ctx->Driver.Hint) {
125 (*ctx->Driver.Hint)( ctx, target, mode );
126 }
127 }
128
129
130 /**********************************************************************/
131 /***** Initialization *****/
132 /**********************************************************************/
133
134 void _mesa_init_hint( struct gl_context * ctx )
135 {
136 /* Hint group */
137 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
138 ctx->Hint.PointSmooth = GL_DONT_CARE;
139 ctx->Hint.LineSmooth = GL_DONT_CARE;
140 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
141 ctx->Hint.Fog = GL_DONT_CARE;
142 ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
143 ctx->Hint.TextureCompression = GL_DONT_CARE;
144 ctx->Hint.GenerateMipmap = GL_DONT_CARE;
145 ctx->Hint.FragmentShaderDerivative = GL_DONT_CARE;
146 }