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