[Mesa-dev] [PATCH 2/5] mesa: Implement ARB_clip_control.
Ilia Mirkin
imirkin at alum.mit.edu
Wed Oct 22 10:22:22 PDT 2014
On Wed, Oct 22, 2014 at 1:13 PM, <Mathias.Froehlich at gmx.net> wrote:
> From: Mathias Fröhlich <Mathias.Froehlich at gmx.net>
>
> Implement the mesa parts of ARB_clip_control.
> So far no driver enables this.
>
> Signed-off-by: Mathias Froehlich <Mathias.Froehlich at web.de>
> ---
> src/mapi/glapi/gen/ARB_clip_control.xml | 25 +++++++++++
> src/mapi/glapi/gen/gl_API.xml | 4 +-
> src/mesa/main/dlist.c | 26 +++++++++++
> src/mesa/main/extensions.c | 1 +
> src/mesa/main/get_hash_params.py | 2 +
> src/mesa/main/mtypes.h | 12 +++++
> src/mesa/main/polygon.c | 5 ++-
> src/mesa/main/tests/dispatch_sanity.cpp | 3 ++
> src/mesa/main/viewport.c | 79 +++++++++++++++++++++++++++++++--
> src/mesa/main/viewport.h | 3 ++
> 10 files changed, 154 insertions(+), 6 deletions(-)
> create mode 100644 src/mapi/glapi/gen/ARB_clip_control.xml
>
> diff --git a/src/mapi/glapi/gen/ARB_clip_control.xml b/src/mapi/glapi/gen/ARB_clip_control.xml
> new file mode 100644
> index 0000000..2973a31
> --- /dev/null
> +++ b/src/mapi/glapi/gen/ARB_clip_control.xml
> @@ -0,0 +1,25 @@
> +<?xml version="1.0"?>
> +<!DOCTYPE OpenGLAPI SYSTEM "gl_API.dtd">
> +
> +<OpenGLAPI>
> +
> +<category name="GL_ARB_clip_control" number="160">
> +
> + <enum name="LOWER_LEFT" value = "0x8CA1"/>
> + <enum name="UPPER_LEFT" value = "0x8CA2"/>
> +
> + <enum name="NEGATIVE_ONE_TO_ONE" value = "0x935E"/>
> + <enum name="ZERO_TO_ONE" value = "0x935F"/>
> +
> + <enum name="CLIP_ORIGIN" value = "0x935C"/>
> + <enum name="CLIP_DEPTH_MODE" value = "0x935D"/>
> +
> + <function name="ClipControl" offset="assign">
> + <param name="origin" type="GLenum"/>
> + <param name="depth" type="GLenum"/>
> + <glx rop="1340"/>
> + </function>
> +
> +</category>
> +
> +</OpenGLAPI>
> diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml
> index 73f2f75..534e6a0 100644
> --- a/src/mapi/glapi/gen/gl_API.xml
> +++ b/src/mapi/glapi/gen/gl_API.xml
> @@ -8364,7 +8364,9 @@
>
> <xi:include href="ARB_multi_bind.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
>
> -<!-- ARB extensions 148 - 160 -->
> +<!-- ARB extensions 148 - 159 -->
> +
> +<xi:include href="ARB_clip_control.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
>
> <category name="GL_ARB_conditional_render_inverted" number="161">
> <enum name="QUERY_WAIT_INVERTED" value="0x8E17"/>
> diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c
> index 5c7160d..4b7b060 100644
> --- a/src/mesa/main/dlist.c
> +++ b/src/mesa/main/dlist.c
> @@ -398,6 +398,9 @@ typedef enum
> OPCODE_PROGRAM_UNIFORM_MATRIX34F,
> OPCODE_PROGRAM_UNIFORM_MATRIX43F,
>
> + /* GL_ARB_clip_control */
> + OPCODE_CLIP_CONTROL,
> +
> /* GL_ARB_color_buffer_float */
> OPCODE_CLAMP_COLOR,
>
> @@ -7208,6 +7211,22 @@ save_ProgramUniformMatrix4fv(GLuint program, GLint location, GLsizei count,
> }
>
> static void GLAPIENTRY
> +save_ClipControl(GLenum origin, GLenum depth)
> +{
> + GET_CURRENT_CONTEXT(ctx);
> + Node *n;
> + ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
> + n = alloc_instruction(ctx, OPCODE_CLIP_CONTROL, 2);
> + if (n) {
> + n[1].e = origin;
> + n[2].e = depth;
> + }
> + if (ctx->ExecuteFlag) {
> + CALL_ClipControl(ctx->Exec, (origin, depth));
> + }
> +}
> +
> +static void GLAPIENTRY
> save_ClampColorARB(GLenum target, GLenum clamp)
> {
> GET_CURRENT_CONTEXT(ctx);
> @@ -8617,6 +8636,10 @@ execute_list(struct gl_context *ctx, GLuint list)
> get_pointer(&n[5])));
> break;
>
> + case OPCODE_CLIP_CONTROL:
> + CALL_ClipControl(ctx->Exec, (n[1].e, n[2].e));
> + break;
> +
> case OPCODE_CLAMP_COLOR:
> CALL_ClampColor(ctx->Exec, (n[1].e, n[2].e));
> break;
> @@ -9551,6 +9574,9 @@ _mesa_initialize_save_table(const struct gl_context *ctx)
> SET_TexParameterIiv(table, save_TexParameterIiv);
> SET_TexParameterIuiv(table, save_TexParameterIuiv);
>
> + /* GL_ARB_clip_control */
> + SET_ClipControl(table, save_ClipControl);
> +
> /* GL_ARB_color_buffer_float */
> SET_ClampColor(table, save_ClampColorARB);
>
> diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
> index f0e2f89..15d66a7 100644
> --- a/src/mesa/main/extensions.c
> +++ b/src/mesa/main/extensions.c
> @@ -91,6 +91,7 @@ static const struct extension extension_table[] = {
> { "GL_ARB_buffer_storage", o(ARB_buffer_storage), GL, 2013 },
> { "GL_ARB_clear_buffer_object", o(dummy_true), GL, 2012 },
> { "GL_ARB_clear_texture", o(ARB_clear_texture), GL, 2013 },
> + { "GL_ARB_clip_control", o(ARB_clip_control), GL, 2014 },
> { "GL_ARB_color_buffer_float", o(ARB_color_buffer_float), GL, 2004 },
> { "GL_ARB_compressed_texture_pixel_storage", o(dummy_true), GL, 2011 },
> { "GL_ARB_compute_shader", o(ARB_compute_shader), GL, 2012 },
> diff --git a/src/mesa/main/get_hash_params.py b/src/mesa/main/get_hash_params.py
> index da35684..ed1f390 100644
> --- a/src/mesa/main/get_hash_params.py
> +++ b/src/mesa/main/get_hash_params.py
> @@ -414,6 +414,8 @@ descriptor=[
> [ "AUX_BUFFERS", "BUFFER_INT(Visual.numAuxBuffers), NO_EXTRA" ],
> [ "BLUE_BIAS", "CONTEXT_FLOAT(Pixel.BlueBias), NO_EXTRA" ],
> [ "BLUE_SCALE", "CONTEXT_FLOAT(Pixel.BlueScale), NO_EXTRA" ],
> + [ "CLIP_DEPTH_MODE", "CONTEXT_ENUM(ClipControl.Depth), NO_EXTRA" ],
> + [ "CLIP_ORIGIN", "CONTEXT_ENUM(ClipControl.Origin), NO_EXTRA" ],
Don't you need to check for ARB_clip_control being enabled? So like an
EXTRA_clip_control + relevant define or whatever (don't remember
exactly how that stuff works).
> [ "CLIENT_ATTRIB_STACK_DEPTH", "CONTEXT_INT(ClientAttribStackDepth), NO_EXTRA" ],
> [ "COLOR_MATERIAL_FACE", "CONTEXT_ENUM(Light.ColorMaterialFace), NO_EXTRA" ],
> [ "COLOR_MATERIAL_PARAMETER", "CONTEXT_ENUM(Light.ColorMaterialMode), NO_EXTRA" ],
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> index 415d302..be52d4e 100644
> --- a/src/mesa/main/mtypes.h
> +++ b/src/mesa/main/mtypes.h
> @@ -1434,6 +1434,16 @@ struct gl_transform_attrib
>
>
> /**
> + * Clip control parameters (GL_ARB_clip_control)
> + */
> +struct gl_clip_control
> +{
> + GLenum Origin;
> + GLenum Depth;
> +};
> +
> +
> +/**
> * Viewport attribute group (GL_VIEWPORT_BIT).
> */
> struct gl_viewport_attrib
> @@ -3698,6 +3708,7 @@ struct gl_extensions
> GLboolean ARB_blend_func_extended;
> GLboolean ARB_buffer_storage;
> GLboolean ARB_clear_texture;
> + GLboolean ARB_clip_control;
> GLboolean ARB_color_buffer_float;
> GLboolean ARB_compute_shader;
> GLboolean ARB_conditional_render_inverted;
> @@ -4273,6 +4284,7 @@ struct gl_context
> struct gl_stencil_attrib Stencil; /**< Stencil buffer attributes */
> struct gl_texture_attrib Texture; /**< Texture attributes */
> struct gl_transform_attrib Transform; /**< Transformation attributes */
> + struct gl_clip_control ClipControl; /**< Clip Control (xform) attributes */
> struct gl_viewport_attrib ViewportArray[MAX_VIEWPORTS]; /**< Viewport attributes */
> /*@}*/
>
> diff --git a/src/mesa/main/polygon.c b/src/mesa/main/polygon.c
> index 611cef6..bd239bc 100644
> --- a/src/mesa/main/polygon.c
> +++ b/src/mesa/main/polygon.c
> @@ -104,7 +104,10 @@ _mesa_FrontFace( GLenum mode )
> FLUSH_VERTICES(ctx, _NEW_POLYGON);
> ctx->Polygon.FrontFace = mode;
>
> - ctx->Polygon._FrontBit = (GLboolean) (mode == GL_CW);
> + if (ctx->ClipControl.Origin == GL_LOWER_LEFT)
> + ctx->Polygon._FrontBit = (GLboolean)(ctx->Polygon.FrontFace == GL_CW);
> + else
> + ctx->Polygon._FrontBit = (GLboolean)(ctx->Polygon.FrontFace == GL_CCW);
>
> if (ctx->Driver.FrontFace)
> ctx->Driver.FrontFace( ctx, mode );
> diff --git a/src/mesa/main/tests/dispatch_sanity.cpp b/src/mesa/main/tests/dispatch_sanity.cpp
> index 04fa86b..03428dd 100644
> --- a/src/mesa/main/tests/dispatch_sanity.cpp
> +++ b/src/mesa/main/tests/dispatch_sanity.cpp
> @@ -951,6 +951,9 @@ const struct function gl_core_functions_possible[] = {
> { "glClearTexImage", 13, -1 },
> { "glClearTexSubImage", 13, -1 },
>
> + /* GL_ARB_clip_control */
> + { "glClipControl", 45, -1 },
> +
> { NULL, 0, -1 }
> };
>
> diff --git a/src/mesa/main/viewport.c b/src/mesa/main/viewport.c
> index 89766cf..69107a1 100644
> --- a/src/mesa/main/viewport.c
> +++ b/src/mesa/main/viewport.c
> @@ -30,6 +30,7 @@
>
>
> #include "context.h"
> +#include "enums.h"
> #include "macros.h"
> #include "mtypes.h"
> #include "viewport.h"
> @@ -390,6 +391,9 @@ void _mesa_init_viewport(struct gl_context *ctx)
> GLfloat depthMax = 65535.0F; /* sorf of arbitrary */
> unsigned i;
>
> + ctx->ClipControl.Origin = GL_LOWER_LEFT;
> + ctx->ClipControl.Depth = GL_NEGATIVE_ONE_TO_ONE;
> +
> /* Note: ctx->Const.MaxViewports may not have been set by the driver yet,
> * so just initialize all of them.
> */
> @@ -424,6 +428,63 @@ void _mesa_free_viewport_data(struct gl_context *ctx)
> _math_matrix_dtr(&ctx->ViewportArray[i]._WindowMap);
> }
>
> +extern void GLAPIENTRY
> +_mesa_ClipControl(GLenum origin, GLenum depth)
> +{
> + GET_CURRENT_CONTEXT(ctx);
> +
> + if (MESA_VERBOSE&VERBOSE_API)
> + _mesa_debug(ctx, "glClipControl(%s, %s)\n",
> + _mesa_lookup_enum_by_nr(origin),
> + _mesa_lookup_enum_by_nr(depth));
> +
> + ASSERT_OUTSIDE_BEGIN_END(ctx);
> +
> + if (!ctx->Extensions.ARB_clip_control) {
> + _mesa_error(ctx, GL_INVALID_OPERATION, "glClipControl");
> + return;
> + }
> +
> + if (origin != GL_LOWER_LEFT && origin != GL_UPPER_LEFT) {
> + _mesa_error(ctx, GL_INVALID_ENUM, "glClipControl");
> + return;
> + }
> +
> + if (depth != GL_NEGATIVE_ONE_TO_ONE && depth != GL_ZERO_TO_ONE) {
> + _mesa_error(ctx, GL_INVALID_ENUM, "glClipControl");
> + return;
> + }
> +
> + FLUSH_VERTICES(ctx, 0);
> +
> + if (ctx->ClipControl.Origin != origin) {
> + ctx->ClipControl.Origin = origin;
> +
> + if (ctx->ClipControl.Origin == GL_LOWER_LEFT)
> + ctx->Polygon._FrontBit = (GLboolean)(ctx->Polygon.FrontFace == GL_CW);
> + else
> + ctx->Polygon._FrontBit = (GLboolean)(ctx->Polygon.FrontFace == GL_CCW);
> +
> + /* Affects the winding order of the front face. */
> + ctx->NewState |= _NEW_POLYGON;
> + /* Affects the y component of the viewport transform. */
> + ctx->NewState |= _NEW_VIEWPORT;
> +
> + if (ctx->Driver.FrontFace)
> + ctx->Driver.FrontFace(ctx, ctx->Polygon.FrontFace);
> + }
> +
> + if (ctx->ClipControl.Depth != depth) {
> + ctx->ClipControl.Depth = depth;
> +
> + /* Affects the z part of the viewpoint transform. */
> + ctx->NewState |= _NEW_VIEWPORT;
> +
> + if (ctx->Driver.DepthRange)
> + ctx->Driver.DepthRange(ctx);
> + }
> +}
> +
> void
> _mesa_get_viewport_xform(struct gl_context *ctx, unsigned i,
> double scale[3], double translate[3])
> @@ -437,8 +498,18 @@ _mesa_get_viewport_xform(struct gl_context *ctx, unsigned i,
>
> scale[0] = half_width;
> translate[0] = half_width + x;
> - scale[1] = half_height;
> - translate[1] = half_height + y;
> - scale[2] = 0.5*(f - n);
> - translate[2] = 0.5*(n + f);
> + if (ctx->ClipControl.Origin == GL_UPPER_LEFT) {
> + scale[1] = -half_height;
> + translate[1] = half_height - y;
> + } else {
> + scale[1] = half_height;
> + translate[1] = half_height + y;
> + }
> + if (ctx->ClipControl.Depth == GL_NEGATIVE_ONE_TO_ONE) {
> + scale[2] = 0.5*(f - n);
> + translate[2] = 0.5*(n + f);
> + } else {
> + scale[2] = f - n;
> + translate[2] = n;
> + }
> }
> diff --git a/src/mesa/main/viewport.h b/src/mesa/main/viewport.h
> index 514ff10..426e194 100644
> --- a/src/mesa/main/viewport.h
> +++ b/src/mesa/main/viewport.h
> @@ -71,6 +71,9 @@ _mesa_init_viewport(struct gl_context *ctx);
> extern void
> _mesa_free_viewport_data(struct gl_context *ctx);
>
> +extern void GLAPIENTRY
> +_mesa_ClipControl(GLenum origin, GLenum depth);
> +
> extern void
> _mesa_get_viewport_xform(struct gl_context *ctx, unsigned i,
> double scale[3], double translate[3]);
> --
> 1.9.3
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list