conservativeraster.c revision 7ec681f3
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 35static ALWAYS_INLINE void 36conservative_raster_parameter(GLenum pname, GLfloat param, 37 bool no_error, const char *func) 38{ 39 GET_CURRENT_CONTEXT(ctx); 40 41 if (!no_error && !ctx->Extensions.NV_conservative_raster_dilate && 42 !ctx->Extensions.NV_conservative_raster_pre_snap_triangles) { 43 _mesa_error(ctx, GL_INVALID_OPERATION, "%s not supported", func); 44 return; 45 } 46 47 if (MESA_VERBOSE & VERBOSE_API) 48 _mesa_debug(ctx, "%s(%s, %g)\n", 49 func, _mesa_enum_to_string(pname), param); 50 51 ASSERT_OUTSIDE_BEGIN_END(ctx); 52 53 switch (pname) { 54 case GL_CONSERVATIVE_RASTER_DILATE_NV: 55 if (!no_error && !ctx->Extensions.NV_conservative_raster_dilate) 56 goto invalid_pname_enum; 57 58 if (!no_error && param<0.0) { 59 _mesa_error(ctx, GL_INVALID_VALUE, "%s(param=%g)", func, param); 60 return; 61 } 62 63 FLUSH_VERTICES(ctx, 0, 0); 64 ctx->NewDriverState |= 65 ctx->DriverFlags.NewNvConservativeRasterizationParams; 66 67 ctx->ConservativeRasterDilate = 68 CLAMP(param, 69 ctx->Const.ConservativeRasterDilateRange[0], 70 ctx->Const.ConservativeRasterDilateRange[1]); 71 break; 72 case GL_CONSERVATIVE_RASTER_MODE_NV: 73 if (!no_error && !ctx->Extensions.NV_conservative_raster_pre_snap_triangles) 74 goto invalid_pname_enum; 75 76 if (!no_error && param != GL_CONSERVATIVE_RASTER_MODE_POST_SNAP_NV && 77 param != GL_CONSERVATIVE_RASTER_MODE_PRE_SNAP_TRIANGLES_NV) { 78 _mesa_error(ctx, GL_INVALID_ENUM, 79 "%s(pname=%s)", func, _mesa_enum_to_string(param)); 80 return; 81 } 82 83 FLUSH_VERTICES(ctx, 0, 0); 84 ctx->NewDriverState |= 85 ctx->DriverFlags.NewNvConservativeRasterizationParams; 86 87 ctx->ConservativeRasterMode = param; 88 break; 89 default: 90 goto invalid_pname_enum; 91 break; 92 } 93 94 return; 95invalid_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 101void GLAPIENTRY 102_mesa_ConservativeRasterParameteriNV_no_error(GLenum pname, GLint param) 103{ 104 conservative_raster_parameter(pname, param, true, 105 "glConservativeRasterParameteriNV"); 106} 107 108void GLAPIENTRY 109_mesa_ConservativeRasterParameteriNV(GLenum pname, GLint param) 110{ 111 conservative_raster_parameter(pname, param, false, 112 "glConservativeRasterParameteriNV"); 113} 114 115void GLAPIENTRY 116_mesa_ConservativeRasterParameterfNV_no_error(GLenum pname, GLfloat param) 117{ 118 conservative_raster_parameter(pname, param, true, 119 "glConservativeRasterParameterfNV"); 120} 121 122void GLAPIENTRY 123_mesa_ConservativeRasterParameterfNV(GLenum pname, GLfloat param) 124{ 125 conservative_raster_parameter(pname, param, false, 126 "glConservativeRasterParameterfNV"); 127} 128 129void 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