X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fmultisample.c;h=8beb1d839ec350f12a23e22169b0e56ab39e0949;hb=e66c2158f86d798fc25555d493febc5c9e778899;hp=ae2e94b198f945437865cb60f938fd336b1b5b78;hpb=96ff2edc73ccf11d4d198ba3665507f73ae4a9f7;p=mesa.git diff --git a/src/mesa/main/multisample.c b/src/mesa/main/multisample.c index ae2e94b198f..8beb1d839ec 100644 --- a/src/mesa/main/multisample.c +++ b/src/mesa/main/multisample.c @@ -1,6 +1,5 @@ /* * Mesa 3-D graphics library - * Version: 7.1 * * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. * @@ -17,9 +16,10 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. */ @@ -41,11 +41,16 @@ _mesa_SampleCoverage(GLclampf value, GLboolean invert) { GET_CURRENT_CONTEXT(ctx); - FLUSH_VERTICES(ctx, 0); + value = CLAMP(value, 0.0f, 1.0f); - ctx->Multisample.SampleCoverageValue = (GLfloat) CLAMP(value, 0.0, 1.0); + if (ctx->Multisample.SampleCoverageInvert == invert && + ctx->Multisample.SampleCoverageValue == value) + return; + + FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 : _NEW_MULTISAMPLE); + ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask; + ctx->Multisample.SampleCoverageValue = value; ctx->Multisample.SampleCoverageInvert = invert; - ctx->NewState |= _NEW_MULTISAMPLE; } @@ -62,6 +67,8 @@ _mesa_init_multisample(struct gl_context *ctx) ctx->Multisample.SampleCoverage = GL_FALSE; ctx->Multisample.SampleCoverageValue = 1.0; ctx->Multisample.SampleCoverageInvert = GL_FALSE; + ctx->Multisample.SampleShading = GL_FALSE; + ctx->Multisample.MinSampleShadingValue = 0.0f; /* ARB_texture_multisample / GL3.2 additions */ ctx->Multisample.SampleMask = GL_FALSE; @@ -89,17 +96,53 @@ _mesa_GetMultisamplefv(GLenum pname, GLuint index, GLfloat * val) /* winsys FBOs are upside down */ if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) - val[1] = 1 - val[1]; + val[1] = 1.0f - val[1]; return; } + case GL_PROGRAMMABLE_SAMPLE_LOCATION_ARB: + if (!ctx->Extensions.ARB_sample_locations) { + _mesa_error( ctx, GL_INVALID_ENUM, "glGetMultisamplefv(pname)" ); + return; + } + + if (index >= MAX_SAMPLE_LOCATION_TABLE_SIZE * 2) { + _mesa_error( ctx, GL_INVALID_VALUE, "glGetMultisamplefv(index)" ); + return; + } + + if (ctx->DrawBuffer->SampleLocationTable) + *val = ctx->DrawBuffer->SampleLocationTable[index]; + else + *val = 0.5f; + + return; + default: _mesa_error( ctx, GL_INVALID_ENUM, "glGetMultisamplefv(pname)" ); return; } } +static void +sample_maski(struct gl_context *ctx, GLuint index, GLbitfield mask) +{ + if (ctx->Multisample.SampleMaskValue == mask) + return; + + FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 : _NEW_MULTISAMPLE); + ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask; + ctx->Multisample.SampleMaskValue = mask; +} + +void GLAPIENTRY +_mesa_SampleMaski_no_error(GLuint index, GLbitfield mask) +{ + GET_CURRENT_CONTEXT(ctx); + sample_maski(ctx, index, mask); +} + void GLAPIENTRY _mesa_SampleMaski(GLuint index, GLbitfield mask) { @@ -115,12 +158,49 @@ _mesa_SampleMaski(GLuint index, GLbitfield mask) return; } - FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE); - ctx->Multisample.SampleMaskValue = mask; + sample_maski(ctx, index, mask); +} + +static void +min_sample_shading(struct gl_context *ctx, GLclampf value) +{ + value = CLAMP(value, 0.0f, 1.0f); + + if (ctx->Multisample.MinSampleShadingValue == value) + return; + + FLUSH_VERTICES(ctx, + ctx->DriverFlags.NewSampleShading ? 0 : _NEW_MULTISAMPLE); + ctx->NewDriverState |= ctx->DriverFlags.NewSampleShading; + ctx->Multisample.MinSampleShadingValue = value; } +/** + * Called via glMinSampleShadingARB + */ +void GLAPIENTRY +_mesa_MinSampleShading_no_error(GLclampf value) +{ + GET_CURRENT_CONTEXT(ctx); + min_sample_shading(ctx, value); +} -/* Helper for checking a requested sample count against the limit +void GLAPIENTRY +_mesa_MinSampleShading(GLclampf value) +{ + GET_CURRENT_CONTEXT(ctx); + + if (!_mesa_has_ARB_sample_shading(ctx) && + !_mesa_has_OES_sample_shading(ctx)) { + _mesa_error(ctx, GL_INVALID_OPERATION, "glMinSampleShading"); + return; + } + + min_sample_shading(ctx, value); +} + +/** + * Helper for checking a requested sample count against the limit * for a particular (target, internalFormat) pair. The limit imposed, * and the error generated, both depend on which extensions are supported. * @@ -129,10 +209,78 @@ _mesa_SampleMaski(GLuint index, GLbitfield mask) */ GLenum _mesa_check_sample_count(struct gl_context *ctx, GLenum target, - GLenum internalFormat, GLsizei samples) + GLenum internalFormat, GLsizei samples, + GLsizei storageSamples) { - /* If ARB_internalformat_query is supported, then treat its highest returned sample - * count as the absolute maximum for this format; it is allowed to exceed MAX_SAMPLES. + /* Section 4.4 (Framebuffer objects), page 198 of the OpenGL ES 3.0.0 + * specification says: + * + * "If internalformat is a signed or unsigned integer format and samples + * is greater than zero, then the error INVALID_OPERATION is generated." + * + * This restriction is relaxed for OpenGL ES 3.1. + */ + if ((ctx->API == API_OPENGLES2 && ctx->Version == 30) && + _mesa_is_enum_format_integer(internalFormat) + && samples > 0) { + return GL_INVALID_OPERATION; + } + + if (ctx->Extensions.AMD_framebuffer_multisample_advanced && + target == GL_RENDERBUFFER) { + if (!_mesa_is_depth_or_stencil_format(internalFormat)) { + /* From the AMD_framebuffer_multisample_advanced spec: + * + * "An INVALID_OPERATION error is generated if + * is a color format and is greater than + * the implementation-dependent limit MAX_COLOR_FRAMEBUFFER_- + * STORAGE_SAMPLES_AMD." + */ + if (samples > ctx->Const.MaxColorFramebufferSamples) + return GL_INVALID_OPERATION; + + /* From the AMD_framebuffer_multisample_advanced spec: + * + * "An INVALID_OPERATION error is generated if + * is a color format and is greater than + * the implementation-dependent limit MAX_COLOR_FRAMEBUFFER_- + * STORAGE_SAMPLES_AMD." + */ + if (storageSamples > ctx->Const.MaxColorFramebufferStorageSamples) + return GL_INVALID_OPERATION; + + /* From the AMD_framebuffer_multisample_advanced spec: + * + * "An INVALID_OPERATION error is generated if is + * greater than ." + */ + if (storageSamples > samples) + return GL_INVALID_OPERATION; + + /* Color renderbuffer sample counts are now fully validated + * according to AMD_framebuffer_multisample_advanced. + */ + return GL_NO_ERROR; + } else { + /* From the AMD_framebuffer_multisample_advanced spec: + * + * "An INVALID_OPERATION error is generated if is + * a depth or stencil format and is not equal to + * ." + */ + if (storageSamples != samples) + return GL_INVALID_OPERATION; + } + } else { + /* If the extension is unsupported, it's not possible to set + * storageSamples differently. + */ + assert(samples == storageSamples); + } + + /* If ARB_internalformat_query is supported, then treat its highest + * returned sample count as the absolute maximum for this format; it is + * allowed to exceed MAX_SAMPLES. * * From the ARB_internalformat_query spec: * @@ -140,9 +288,15 @@ _mesa_check_sample_count(struct gl_context *ctx, GLenum target, * for then the error INVALID_OPERATION is generated." */ if (ctx->Extensions.ARB_internalformat_query) { - GLint buffer[16]; - int count = ctx->Driver.QuerySamplesForFormat(ctx, target, internalFormat, buffer); - int limit = count ? buffer[0] : -1; + GLint buffer[16] = {-1}; + GLint limit; + + ctx->Driver.QueryInternalFormat(ctx, target, internalFormat, + GL_SAMPLES, buffer); + /* since the query returns samples sorted in descending order, + * the first element is the greatest supported sample value. + */ + limit = buffer[0]; return samples > limit ? GL_INVALID_OPERATION : GL_NO_ERROR; } @@ -159,7 +313,8 @@ _mesa_check_sample_count(struct gl_context *ctx, GLenum target, * * And when describing the operation of TexImage*Multisample: * - * "The error INVALID_OPERATION may be generated if any of the following are true: + * "The error INVALID_OPERATION may be generated if any of the following + * are true: * * * is a depth/stencil-renderable format and * is greater than the value of MAX_DEPTH_TEXTURE_SAMPLES @@ -171,7 +326,8 @@ _mesa_check_sample_count(struct gl_context *ctx, GLenum target, if (ctx->Extensions.ARB_texture_multisample) { if (_mesa_is_enum_format_integer(internalFormat)) - return samples > ctx->Const.MaxIntegerSamples ? GL_INVALID_OPERATION : GL_NO_ERROR; + return samples > ctx->Const.MaxIntegerSamples + ? GL_INVALID_OPERATION : GL_NO_ERROR; if (target == GL_TEXTURE_2D_MULTISAMPLE || target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) { @@ -192,5 +348,6 @@ _mesa_check_sample_count(struct gl_context *ctx, GLenum target, * "... or if samples is greater than MAX_SAMPLES, then the error * INVALID_VALUE is generated" */ - return samples > ctx->Const.MaxSamples ? GL_INVALID_VALUE : GL_NO_ERROR; + return (GLuint) samples > ctx->Const.MaxSamples + ? GL_INVALID_VALUE : GL_NO_ERROR; }