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