1
2 /*
3 * Mesa 3-D graphics library
4 *
5 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * 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
32 #include "mtypes.h"
33 #include "api_exec_decl.h"
34
35 #include "pipe/p_screen.h"
36
37 void GLAPIENTRY
_mesa_Hint(GLenum target,GLenum mode)38 _mesa_Hint( GLenum target, GLenum mode )
39 {
40 GET_CURRENT_CONTEXT(ctx);
41
42 if (MESA_VERBOSE & VERBOSE_API)
43 _mesa_debug(ctx, "glHint %s %s\n",
44 _mesa_enum_to_string(target),
45 _mesa_enum_to_string(mode));
46
47 if (mode != GL_NICEST && mode != GL_FASTEST && mode != GL_DONT_CARE) {
48 _mesa_error(ctx, GL_INVALID_ENUM, "glHint(mode)");
49 return;
50 }
51
52 switch (target) {
53 case GL_FOG_HINT:
54 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
55 goto invalid_target;
56 if (ctx->Hint.Fog == mode)
57 return;
58 FLUSH_VERTICES(ctx, _NEW_HINT, GL_HINT_BIT);
59 ctx->Hint.Fog = mode;
60 break;
61 case GL_LINE_SMOOTH_HINT:
62 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
63 goto invalid_target;
64 if (ctx->Hint.LineSmooth == mode)
65 return;
66 FLUSH_VERTICES(ctx, _NEW_HINT, GL_HINT_BIT);
67 ctx->Hint.LineSmooth = mode;
68 break;
69 case GL_PERSPECTIVE_CORRECTION_HINT:
70 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
71 goto invalid_target;
72 if (ctx->Hint.PerspectiveCorrection == mode)
73 return;
74 FLUSH_VERTICES(ctx, _NEW_HINT, GL_HINT_BIT);
75 ctx->Hint.PerspectiveCorrection = mode;
76 break;
77 case GL_POINT_SMOOTH_HINT:
78 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
79 goto invalid_target;
80 if (ctx->Hint.PointSmooth == mode)
81 return;
82 FLUSH_VERTICES(ctx, _NEW_HINT, GL_HINT_BIT);
83 ctx->Hint.PointSmooth = mode;
84 break;
85 case GL_POLYGON_SMOOTH_HINT:
86 if (!_mesa_is_desktop_gl(ctx))
87 goto invalid_target;
88 if (ctx->Hint.PolygonSmooth == mode)
89 return;
90 FLUSH_VERTICES(ctx, _NEW_HINT, GL_HINT_BIT);
91 ctx->Hint.PolygonSmooth = mode;
92 break;
93
94 /* GL_ARB_texture_compression */
95 case GL_TEXTURE_COMPRESSION_HINT_ARB:
96 if (!_mesa_is_desktop_gl(ctx))
97 goto invalid_target;
98 if (ctx->Hint.TextureCompression == mode)
99 return;
100 FLUSH_VERTICES(ctx, _NEW_HINT, GL_HINT_BIT);
101 ctx->Hint.TextureCompression = mode;
102 break;
103
104 /* GL_SGIS_generate_mipmap */
105 case GL_GENERATE_MIPMAP_HINT_SGIS:
106 if (ctx->API == API_OPENGL_CORE)
107 goto invalid_target;
108 if (ctx->Hint.GenerateMipmap == mode)
109 return;
110 FLUSH_VERTICES(ctx, _NEW_HINT, GL_HINT_BIT);
111 ctx->Hint.GenerateMipmap = mode;
112 break;
113
114 /* GL_ARB_fragment_shader */
115 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB:
116 if (ctx->API == API_OPENGLES || !ctx->Extensions.ARB_fragment_shader)
117 goto invalid_target;
118 if (ctx->Hint.FragmentShaderDerivative == mode)
119 return;
120 FLUSH_VERTICES(ctx, _NEW_HINT, GL_HINT_BIT);
121 ctx->Hint.FragmentShaderDerivative = mode;
122 break;
123
124 default:
125 goto invalid_target;
126 }
127 return;
128
129 invalid_target:
130 _mesa_error(ctx, GL_INVALID_ENUM, "glHint(target)");
131 return;
132 }
133
134 /* GL_ARB_parallel_shader_compile */
135 void GLAPIENTRY
_mesa_MaxShaderCompilerThreadsKHR(GLuint count)136 _mesa_MaxShaderCompilerThreadsKHR(GLuint count)
137 {
138 GET_CURRENT_CONTEXT(ctx);
139
140 ctx->Hint.MaxShaderCompilerThreads = count;
141
142 struct pipe_screen *screen = ctx->screen;
143 if (screen->set_max_shader_compiler_threads)
144 screen->set_max_shader_compiler_threads(screen, count);
145 }
146
147 /**********************************************************************/
148 /***** Initialization *****/
149 /**********************************************************************/
150
_mesa_init_hint(struct gl_context * ctx)151 void _mesa_init_hint( struct gl_context * ctx )
152 {
153 /* Hint group */
154 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
155 ctx->Hint.PointSmooth = GL_DONT_CARE;
156 ctx->Hint.LineSmooth = GL_DONT_CARE;
157 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
158 ctx->Hint.Fog = GL_DONT_CARE;
159 ctx->Hint.TextureCompression = GL_DONT_CARE;
160 ctx->Hint.GenerateMipmap = GL_DONT_CARE;
161 ctx->Hint.FragmentShaderDerivative = GL_DONT_CARE;
162 ctx->Hint.MaxShaderCompilerThreads = 0xffffffff;
163 }
164