conservativeraster.c revision 01e04c3f
101e04c3fSmrg/* 201e04c3fSmrg * Mesa 3-D graphics library 301e04c3fSmrg * 401e04c3fSmrg * Copyright (C) 2018 Rhys Perry 501e04c3fSmrg * 601e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a 701e04c3fSmrg * copy of this software and associated documentation files (the "Software"), 801e04c3fSmrg * to deal in the Software without restriction, including without limitation 901e04c3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 1001e04c3fSmrg * and/or sell copies of the Software, and to permit persons to whom the 1101e04c3fSmrg * Software is furnished to do so, subject to the following conditions: 1201e04c3fSmrg * 1301e04c3fSmrg * The above copyright notice and this permission notice shall be included 1401e04c3fSmrg * in all copies or substantial portions of the Software. 1501e04c3fSmrg * 1601e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 1701e04c3fSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1801e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1901e04c3fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 2001e04c3fSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 2101e04c3fSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 2201e04c3fSmrg * OTHER DEALINGS IN THE SOFTWARE. 2301e04c3fSmrg */ 2401e04c3fSmrg 2501e04c3fSmrg 2601e04c3fSmrg/** 2701e04c3fSmrg * \file conservativeraster.c 2801e04c3fSmrg * glConservativeRasterParameteriNV and glConservativeRasterParameterfNV functions 2901e04c3fSmrg */ 3001e04c3fSmrg 3101e04c3fSmrg#include "conservativeraster.h" 3201e04c3fSmrg#include "context.h" 3301e04c3fSmrg#include "enums.h" 3401e04c3fSmrg 3501e04c3fSmrgstatic ALWAYS_INLINE void 3601e04c3fSmrgconservative_raster_parameter(GLenum pname, GLfloat param, 3701e04c3fSmrg bool no_error, const char *func) 3801e04c3fSmrg{ 3901e04c3fSmrg GET_CURRENT_CONTEXT(ctx); 4001e04c3fSmrg 4101e04c3fSmrg if (!no_error && !ctx->Extensions.NV_conservative_raster_dilate && 4201e04c3fSmrg !ctx->Extensions.NV_conservative_raster_pre_snap_triangles) { 4301e04c3fSmrg _mesa_error(ctx, GL_INVALID_OPERATION, "%s not supported", func); 4401e04c3fSmrg return; 4501e04c3fSmrg } 4601e04c3fSmrg 4701e04c3fSmrg if (MESA_VERBOSE & VERBOSE_API) 4801e04c3fSmrg _mesa_debug(ctx, "%s(%s, %g)\n", 4901e04c3fSmrg func, _mesa_enum_to_string(pname), param); 5001e04c3fSmrg 5101e04c3fSmrg ASSERT_OUTSIDE_BEGIN_END(ctx); 5201e04c3fSmrg 5301e04c3fSmrg switch (pname) { 5401e04c3fSmrg case GL_CONSERVATIVE_RASTER_DILATE_NV: 5501e04c3fSmrg if (!no_error && !ctx->Extensions.NV_conservative_raster_dilate) 5601e04c3fSmrg goto invalid_pname_enum; 5701e04c3fSmrg 5801e04c3fSmrg if (!no_error && param<0.0) { 5901e04c3fSmrg _mesa_error(ctx, GL_INVALID_VALUE, "%s(param=%g)", func, param); 6001e04c3fSmrg return; 6101e04c3fSmrg } 6201e04c3fSmrg ctx->ConservativeRasterDilate = 6301e04c3fSmrg CLAMP(param, 6401e04c3fSmrg ctx->Const.ConservativeRasterDilateRange[0], 6501e04c3fSmrg ctx->Const.ConservativeRasterDilateRange[1]); 6601e04c3fSmrg break; 6701e04c3fSmrg case GL_CONSERVATIVE_RASTER_MODE_NV: 6801e04c3fSmrg if (!no_error && !ctx->Extensions.NV_conservative_raster_pre_snap_triangles) 6901e04c3fSmrg goto invalid_pname_enum; 7001e04c3fSmrg 7101e04c3fSmrg if (!no_error && param != GL_CONSERVATIVE_RASTER_MODE_POST_SNAP_NV && 7201e04c3fSmrg param != GL_CONSERVATIVE_RASTER_MODE_PRE_SNAP_TRIANGLES_NV) { 7301e04c3fSmrg _mesa_error(ctx, GL_INVALID_ENUM, 7401e04c3fSmrg "%s(pname=%s)", func, _mesa_enum_to_string(param)); 7501e04c3fSmrg return; 7601e04c3fSmrg } 7701e04c3fSmrg ctx->ConservativeRasterMode = param; 7801e04c3fSmrg break; 7901e04c3fSmrg default: 8001e04c3fSmrg goto invalid_pname_enum; 8101e04c3fSmrg break; 8201e04c3fSmrg } 8301e04c3fSmrg 8401e04c3fSmrg FLUSH_VERTICES(ctx, 0); 8501e04c3fSmrg ctx->NewDriverState |= 8601e04c3fSmrg ctx->DriverFlags.NewNvConservativeRasterizationParams; 8701e04c3fSmrg 8801e04c3fSmrg return; 8901e04c3fSmrginvalid_pname_enum: 9001e04c3fSmrg if (!no_error) 9101e04c3fSmrg _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", 9201e04c3fSmrg func, _mesa_enum_to_string(pname)); 9301e04c3fSmrg} 9401e04c3fSmrg 9501e04c3fSmrgvoid GLAPIENTRY 9601e04c3fSmrg_mesa_ConservativeRasterParameteriNV_no_error(GLenum pname, GLint param) 9701e04c3fSmrg{ 9801e04c3fSmrg conservative_raster_parameter(pname, param, true, 9901e04c3fSmrg "glConservativeRasterParameteriNV"); 10001e04c3fSmrg} 10101e04c3fSmrg 10201e04c3fSmrgvoid GLAPIENTRY 10301e04c3fSmrg_mesa_ConservativeRasterParameteriNV(GLenum pname, GLint param) 10401e04c3fSmrg{ 10501e04c3fSmrg conservative_raster_parameter(pname, param, false, 10601e04c3fSmrg "glConservativeRasterParameteriNV"); 10701e04c3fSmrg} 10801e04c3fSmrg 10901e04c3fSmrgvoid GLAPIENTRY 11001e04c3fSmrg_mesa_ConservativeRasterParameterfNV_no_error(GLenum pname, GLfloat param) 11101e04c3fSmrg{ 11201e04c3fSmrg conservative_raster_parameter(pname, param, true, 11301e04c3fSmrg "glConservativeRasterParameterfNV"); 11401e04c3fSmrg} 11501e04c3fSmrg 11601e04c3fSmrgvoid GLAPIENTRY 11701e04c3fSmrg_mesa_ConservativeRasterParameterfNV(GLenum pname, GLfloat param) 11801e04c3fSmrg{ 11901e04c3fSmrg conservative_raster_parameter(pname, param, false, 12001e04c3fSmrg "glConservativeRasterParameterfNV"); 12101e04c3fSmrg} 12201e04c3fSmrg 12301e04c3fSmrgvoid 12401e04c3fSmrg_mesa_init_conservative_raster(struct gl_context *ctx) 12501e04c3fSmrg{ 12601e04c3fSmrg ctx->ConservativeRasterDilate = 0.0; 12701e04c3fSmrg ctx->ConservativeRasterMode = GL_CONSERVATIVE_RASTER_MODE_POST_SNAP_NV; 12801e04c3fSmrg} 129