diff options
author | Ilia Mirkin <[email protected]> | 2020-04-06 01:56:48 -0400 |
---|---|---|
committer | Ilia Mirkin <[email protected]> | 2020-04-12 12:01:46 -0400 |
commit | ff168b297d94f656899a904ac147a9ce5add65c9 (patch) | |
tree | 96712a9315b7dedafb2181b9a91dcc76a8a02e80 /src/mesa/main/viewport.c | |
parent | 4137a79c2a7edb5f0caf0964ab748da7c279b61c (diff) |
mesa: add GL_NV_viewport_swizzle support
Signed-off-by: Ilia Mirkin <[email protected]>
Reviewed-by: Marek Olšák <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4519>
Diffstat (limited to 'src/mesa/main/viewport.c')
-rw-r--r-- | src/mesa/main/viewport.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/mesa/main/viewport.c b/src/mesa/main/viewport.c index f4dc74ae41a..a501e245626 100644 --- a/src/mesa/main/viewport.c +++ b/src/mesa/main/viewport.c @@ -488,6 +488,10 @@ void _mesa_init_viewport(struct gl_context *ctx) ctx->ViewportArray[i].Height = 0; ctx->ViewportArray[i].Near = 0.0; ctx->ViewportArray[i].Far = 1.0; + ctx->ViewportArray[i].SwizzleX = GL_VIEWPORT_SWIZZLE_POSITIVE_X_NV; + ctx->ViewportArray[i].SwizzleY = GL_VIEWPORT_SWIZZLE_POSITIVE_Y_NV; + ctx->ViewportArray[i].SwizzleZ = GL_VIEWPORT_SWIZZLE_POSITIVE_Z_NV; + ctx->ViewportArray[i].SwizzleW = GL_VIEWPORT_SWIZZLE_POSITIVE_W_NV; } ctx->SubpixelPrecisionBias[0] = 0; @@ -658,3 +662,96 @@ _mesa_SubpixelPrecisionBiasNV(GLuint xbits, GLuint ybits) subpixel_precision_bias(ctx, xbits, ybits); } + +static void +set_viewport_swizzle(struct gl_context *ctx, GLuint index, + GLenum swizzlex, GLenum swizzley, + GLenum swizzlez, GLenum swizzlew) +{ + struct gl_viewport_attrib *viewport = &ctx->ViewportArray[index]; + if (viewport->SwizzleX == swizzlex && + viewport->SwizzleY == swizzley && + viewport->SwizzleZ == swizzlez && + viewport->SwizzleW == swizzlew) + return; + + FLUSH_VERTICES(ctx, _NEW_VIEWPORT); + ctx->NewDriverState |= ctx->DriverFlags.NewViewport; + + viewport->SwizzleX = swizzlex; + viewport->SwizzleY = swizzley; + viewport->SwizzleZ = swizzlez; + viewport->SwizzleW = swizzlew; +} + +void GLAPIENTRY +_mesa_ViewportSwizzleNV_no_error(GLuint index, + GLenum swizzlex, GLenum swizzley, + GLenum swizzlez, GLenum swizzlew) +{ + GET_CURRENT_CONTEXT(ctx); + + if (MESA_VERBOSE & VERBOSE_API) + _mesa_debug(ctx, "glViewportSwizzleNV(%x, %x, %x, %x)\n", + swizzlex, swizzley, swizzlez, swizzlew); + + set_viewport_swizzle(ctx, index, swizzlex, swizzley, swizzlez, swizzlew); +} + +static bool +verify_viewport_swizzle(GLenum swizzle) +{ + return swizzle >= GL_VIEWPORT_SWIZZLE_POSITIVE_X_NV && + swizzle <= GL_VIEWPORT_SWIZZLE_NEGATIVE_W_NV; +} + +void GLAPIENTRY +_mesa_ViewportSwizzleNV(GLuint index, + GLenum swizzlex, GLenum swizzley, + GLenum swizzlez, GLenum swizzlew) +{ + GET_CURRENT_CONTEXT(ctx); + + if (MESA_VERBOSE & VERBOSE_API) + _mesa_debug(ctx, "glViewportSwizzleNV(%x, %x, %x, %x)\n", + swizzlex, swizzley, swizzlez, swizzlew); + + if (!ctx->Extensions.NV_viewport_swizzle) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glViewportSwizzleNV not supported"); + return; + } + + if (index >= ctx->Const.MaxViewports) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glViewportSwizzleNV: index (%d) >= MaxViewports (%d)", + index, ctx->Const.MaxViewports); + return; + } + + if (!verify_viewport_swizzle(swizzlex)) { + _mesa_error(ctx, GL_INVALID_ENUM, + "glViewportSwizzleNV(swizzlex=%x)", swizzlex); + return; + } + + if (!verify_viewport_swizzle(swizzley)) { + _mesa_error(ctx, GL_INVALID_ENUM, + "glViewportSwizzleNV(swizzley=%x)", swizzley); + return; + } + + if (!verify_viewport_swizzle(swizzlez)) { + _mesa_error(ctx, GL_INVALID_ENUM, + "glViewportSwizzleNV(swizzlez=%x)", swizzlez); + return; + } + + if (!verify_viewport_swizzle(swizzlew)) { + _mesa_error(ctx, GL_INVALID_ENUM, + "glViewportSwizzleNV(swizzlew=%x)", swizzlew); + return; + } + + set_viewport_swizzle(ctx, index, swizzlex, swizzley, swizzlez, swizzlew); +} |