conservativeraster.c revision 01e04c3f
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 ctx->ConservativeRasterDilate = 63 CLAMP(param, 64 ctx->Const.ConservativeRasterDilateRange[0], 65 ctx->Const.ConservativeRasterDilateRange[1]); 66 break; 67 case GL_CONSERVATIVE_RASTER_MODE_NV: 68 if (!no_error && !ctx->Extensions.NV_conservative_raster_pre_snap_triangles) 69 goto invalid_pname_enum; 70 71 if (!no_error && param != GL_CONSERVATIVE_RASTER_MODE_POST_SNAP_NV && 72 param != GL_CONSERVATIVE_RASTER_MODE_PRE_SNAP_TRIANGLES_NV) { 73 _mesa_error(ctx, GL_INVALID_ENUM, 74 "%s(pname=%s)", func, _mesa_enum_to_string(param)); 75 return; 76 } 77 ctx->ConservativeRasterMode = param; 78 break; 79 default: 80 goto invalid_pname_enum; 81 break; 82 } 83 84 FLUSH_VERTICES(ctx, 0); 85 ctx->NewDriverState |= 86 ctx->DriverFlags.NewNvConservativeRasterizationParams; 87 88 return; 89invalid_pname_enum: 90 if (!no_error) 91 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", 92 func, _mesa_enum_to_string(pname)); 93} 94 95void GLAPIENTRY 96_mesa_ConservativeRasterParameteriNV_no_error(GLenum pname, GLint param) 97{ 98 conservative_raster_parameter(pname, param, true, 99 "glConservativeRasterParameteriNV"); 100} 101 102void GLAPIENTRY 103_mesa_ConservativeRasterParameteriNV(GLenum pname, GLint param) 104{ 105 conservative_raster_parameter(pname, param, false, 106 "glConservativeRasterParameteriNV"); 107} 108 109void GLAPIENTRY 110_mesa_ConservativeRasterParameterfNV_no_error(GLenum pname, GLfloat param) 111{ 112 conservative_raster_parameter(pname, param, true, 113 "glConservativeRasterParameterfNV"); 114} 115 116void GLAPIENTRY 117_mesa_ConservativeRasterParameterfNV(GLenum pname, GLfloat param) 118{ 119 conservative_raster_parameter(pname, param, false, 120 "glConservativeRasterParameterfNV"); 121} 122 123void 124_mesa_init_conservative_raster(struct gl_context *ctx) 125{ 126 ctx->ConservativeRasterDilate = 0.0; 127 ctx->ConservativeRasterMode = GL_CONSERVATIVE_RASTER_MODE_POST_SNAP_NV; 128} 129