1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2018 Rhys Perry
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 /**
27 * \file conservativeraster.c
28 * glConservativeRasterParameteriNV and glConservativeRasterParameterfNV functions
29 */
30
31 #include "conservativeraster.h"
32 #include "context.h"
33 #include "enums.h"
34 #include "api_exec_decl.h"
35
36 #include "state_tracker/st_context.h"
37
38 static ALWAYS_INLINE void
conservative_raster_parameter(GLenum pname,GLfloat param,bool no_error,const char * func)39 conservative_raster_parameter(GLenum pname, GLfloat param,
40 bool no_error, const char *func)
41 {
42 GET_CURRENT_CONTEXT(ctx);
43
44 if (!no_error && !ctx->Extensions.NV_conservative_raster_dilate &&
45 !ctx->Extensions.NV_conservative_raster_pre_snap_triangles) {
46 _mesa_error(ctx, GL_INVALID_OPERATION, "%s not supported", func);
47 return;
48 }
49
50 if (MESA_VERBOSE & VERBOSE_API)
51 _mesa_debug(ctx, "%s(%s, %g)\n",
52 func, _mesa_enum_to_string(pname), param);
53
54 ASSERT_OUTSIDE_BEGIN_END(ctx);
55
56 switch (pname) {
57 case GL_CONSERVATIVE_RASTER_DILATE_NV:
58 if (!no_error && !ctx->Extensions.NV_conservative_raster_dilate)
59 goto invalid_pname_enum;
60
61 if (!no_error && param<0.0) {
62 _mesa_error(ctx, GL_INVALID_VALUE, "%s(param=%g)", func, param);
63 return;
64 }
65
66 FLUSH_VERTICES(ctx, 0, 0);
67 ctx->NewDriverState |= ST_NEW_RASTERIZER;
68
69 ctx->ConservativeRasterDilate =
70 CLAMP(param,
71 ctx->Const.ConservativeRasterDilateRange[0],
72 ctx->Const.ConservativeRasterDilateRange[1]);
73 break;
74 case GL_CONSERVATIVE_RASTER_MODE_NV:
75 if (!no_error && !ctx->Extensions.NV_conservative_raster_pre_snap_triangles)
76 goto invalid_pname_enum;
77
78 if (!no_error && param != GL_CONSERVATIVE_RASTER_MODE_POST_SNAP_NV &&
79 param != GL_CONSERVATIVE_RASTER_MODE_PRE_SNAP_TRIANGLES_NV) {
80 _mesa_error(ctx, GL_INVALID_ENUM,
81 "%s(pname=%s)", func, _mesa_enum_to_string(param));
82 return;
83 }
84
85 FLUSH_VERTICES(ctx, 0, 0);
86 ctx->NewDriverState |= ST_NEW_RASTERIZER;
87 ctx->ConservativeRasterMode = param;
88 break;
89 default:
90 goto invalid_pname_enum;
91 break;
92 }
93
94 return;
95 invalid_pname_enum:
96 if (!no_error)
97 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)",
98 func, _mesa_enum_to_string(pname));
99 }
100
101 void GLAPIENTRY
_mesa_ConservativeRasterParameteriNV_no_error(GLenum pname,GLint param)102 _mesa_ConservativeRasterParameteriNV_no_error(GLenum pname, GLint param)
103 {
104 conservative_raster_parameter(pname, param, true,
105 "glConservativeRasterParameteriNV");
106 }
107
108 void GLAPIENTRY
_mesa_ConservativeRasterParameteriNV(GLenum pname,GLint param)109 _mesa_ConservativeRasterParameteriNV(GLenum pname, GLint param)
110 {
111 conservative_raster_parameter(pname, param, false,
112 "glConservativeRasterParameteriNV");
113 }
114
115 void GLAPIENTRY
_mesa_ConservativeRasterParameterfNV_no_error(GLenum pname,GLfloat param)116 _mesa_ConservativeRasterParameterfNV_no_error(GLenum pname, GLfloat param)
117 {
118 conservative_raster_parameter(pname, param, true,
119 "glConservativeRasterParameterfNV");
120 }
121
122 void GLAPIENTRY
_mesa_ConservativeRasterParameterfNV(GLenum pname,GLfloat param)123 _mesa_ConservativeRasterParameterfNV(GLenum pname, GLfloat param)
124 {
125 conservative_raster_parameter(pname, param, false,
126 "glConservativeRasterParameterfNV");
127 }
128
129 void
_mesa_init_conservative_raster(struct gl_context * ctx)130 _mesa_init_conservative_raster(struct gl_context *ctx)
131 {
132 ctx->ConservativeRasterDilate = 0.0;
133 ctx->ConservativeRasterMode = GL_CONSERVATIVE_RASTER_MODE_POST_SNAP_NV;
134 }
135