[Mesa-dev] [PATCH 2/4] mesa: add support for GL_EXT_polygon_offset_clamp

Ilia Mirkin imirkin at alum.mit.edu
Tue Dec 30 23:38:12 PST 2014


Nothing enables the extension yet, but the values are now available.
The spec calls for it to only be exposed for GL 3.3+, which is core-only
in mesa. Restrict it as such so that drivers enabling the extension
don't end up accidentally exposing the function in compat contexts.

Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
---
 src/mesa/drivers/dri/nouveau/nouveau_state.c |  2 +-
 src/mesa/drivers/dri/r200/r200_state.c       |  2 +-
 src/mesa/drivers/dri/radeon/radeon_state.c   |  2 +-
 src/mesa/main/dd.h                           |  2 +-
 src/mesa/main/extensions.c                   |  1 +
 src/mesa/main/get.c                          |  1 +
 src/mesa/main/get_hash_params.py             |  4 ++++
 src/mesa/main/mtypes.h                       |  2 ++
 src/mesa/main/polygon.c                      | 28 ++++++++++++++++++++++++++--
 9 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/src/mesa/drivers/dri/nouveau/nouveau_state.c b/src/mesa/drivers/dri/nouveau/nouveau_state.c
index db4915f..3aad10e 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_state.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_state.c
@@ -319,7 +319,7 @@ nouveau_polygon_mode(struct gl_context *ctx, GLenum face, GLenum mode)
 }
 
 static void
-nouveau_polygon_offset(struct gl_context *ctx, GLfloat factor, GLfloat units)
+nouveau_polygon_offset(struct gl_context *ctx, GLfloat factor, GLfloat units, GLfloat clamp)
 {
 	context_dirty(ctx, POLYGON_OFFSET);
 }
diff --git a/src/mesa/drivers/dri/r200/r200_state.c b/src/mesa/drivers/dri/r200/r200_state.c
index 2ad8439..930ead8 100644
--- a/src/mesa/drivers/dri/r200/r200_state.c
+++ b/src/mesa/drivers/dri/r200/r200_state.c
@@ -712,7 +712,7 @@ static void r200ColorMask( struct gl_context *ctx,
  */
 
 static void r200PolygonOffset( struct gl_context *ctx,
-			       GLfloat factor, GLfloat units )
+			       GLfloat factor, GLfloat units, GLfloat clamp )
 {
    r200ContextPtr rmesa = R200_CONTEXT(ctx);
    const GLfloat depthScale = 1.0F / ctx->DrawBuffer->_DepthMaxF;
diff --git a/src/mesa/drivers/dri/radeon/radeon_state.c b/src/mesa/drivers/dri/radeon/radeon_state.c
index 0f4d84f..726b06d 100644
--- a/src/mesa/drivers/dri/radeon/radeon_state.c
+++ b/src/mesa/drivers/dri/radeon/radeon_state.c
@@ -520,7 +520,7 @@ static void radeonColorMask( struct gl_context *ctx,
  */
 
 static void radeonPolygonOffset( struct gl_context *ctx,
-				 GLfloat factor, GLfloat units )
+				 GLfloat factor, GLfloat units, GLfloat clamp )
 {
    r100ContextPtr rmesa = R100_CONTEXT(ctx);
    const GLfloat depthScale = 1.0F / ctx->DrawBuffer->_DepthMaxF;
diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index 2f40915..6ba0959 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -563,7 +563,7 @@ struct dd_function_table {
    /** Select a polygon rasterization mode */
    void (*PolygonMode)(struct gl_context *ctx, GLenum face, GLenum mode);
    /** Set the scale and units used to calculate depth values */
-   void (*PolygonOffset)(struct gl_context *ctx, GLfloat factor, GLfloat units);
+   void (*PolygonOffset)(struct gl_context *ctx, GLfloat factor, GLfloat units, GLfloat clamp);
    /** Set the polygon stippling pattern */
    void (*PolygonStipple)(struct gl_context *ctx, const GLubyte *mask );
    /* Specifies the current buffer for reading */
diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
index 0df04c2..bffa6b2 100644
--- a/src/mesa/main/extensions.c
+++ b/src/mesa/main/extensions.c
@@ -231,6 +231,7 @@ static const struct extension extension_table[] = {
    { "GL_EXT_pixel_buffer_object",                 o(EXT_pixel_buffer_object),                 GL,             2004 },
    { "GL_EXT_point_parameters",                    o(EXT_point_parameters),                    GLL,            1997 },
    { "GL_EXT_polygon_offset",                      o(dummy_true),                              GLL,            1995 },
+   { "GL_EXT_polygon_offset_clamp",                o(EXT_polygon_offset_clamp),                GLC,            2014 },
    { "GL_EXT_provoking_vertex",                    o(EXT_provoking_vertex),                    GL,             2009 },
    { "GL_EXT_rescale_normal",                      o(dummy_true),                              GLL,            1997 },
    { "GL_EXT_secondary_color",                     o(dummy_true),                              GLL,            1999 },
diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index 6091efc..3f9d745 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -392,6 +392,7 @@ EXTRA_EXT2(ARB_transform_feedback3, ARB_gpu_shader5);
 EXTRA_EXT(INTEL_performance_query);
 EXTRA_EXT(ARB_explicit_uniform_location);
 EXTRA_EXT(ARB_clip_control);
+EXTRA_EXT(EXT_polygon_offset_clamp);
 
 static const int
 extra_ARB_color_buffer_float_or_glcore[] = {
diff --git a/src/mesa/main/get_hash_params.py b/src/mesa/main/get_hash_params.py
index 09a61ac..299ad24 100644
--- a/src/mesa/main/get_hash_params.py
+++ b/src/mesa/main/get_hash_params.py
@@ -811,6 +811,10 @@ descriptor=[
   [ "VIEWPORT_BOUNDS_RANGE", "CONTEXT_FLOAT2(Const.ViewportBounds), extra_ARB_viewport_array" ],
   [ "LAYER_PROVOKING_VERTEX", "CONTEXT_ENUM(Light.ProvokingVertex), extra_ARB_viewport_array" ],
   [ "VIEWPORT_INDEX_PROVOKING_VERTEX", "CONTEXT_ENUM(Light.ProvokingVertex), extra_ARB_viewport_array" ],
+
+# GL_EXT_polygon_offset_clamp
+  [ "POLYGON_OFFSET_CLAMP_EXT", "CONTEXT_FLOAT(Polygon.OffsetUnits), extra_EXT_polygon_offset_clamp" ],
+
 ]}
 
 ]
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index b95dfb9..ab04aed 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1004,6 +1004,7 @@ struct gl_polygon_attrib
    GLenum CullFaceMode;		/**< Culling mode GL_FRONT or GL_BACK */
    GLfloat OffsetFactor;	/**< Polygon offset factor, from user */
    GLfloat OffsetUnits;		/**< Polygon offset units, from user */
+   GLfloat OffsetClamp;		/**< Polygon offset clamp, from user */
    GLboolean OffsetPoint;	/**< Offset in GL_POINT mode */
    GLboolean OffsetLine;	/**< Offset in GL_LINE mode */
    GLboolean OffsetFill;	/**< Offset in GL_FILL mode */
@@ -3810,6 +3811,7 @@ struct gl_extensions
    GLboolean EXT_packed_float;
    GLboolean EXT_pixel_buffer_object;
    GLboolean EXT_point_parameters;
+   GLboolean EXT_polygon_offset_clamp;
    GLboolean EXT_provoking_vertex;
    GLboolean EXT_shader_integer_mix;
    GLboolean EXT_stencil_two_side;
diff --git a/src/mesa/main/polygon.c b/src/mesa/main/polygon.c
index e3b9073..75a32e0 100644
--- a/src/mesa/main/polygon.c
+++ b/src/mesa/main/polygon.c
@@ -245,15 +245,17 @@ _mesa_PolygonOffset( GLfloat factor, GLfloat units )
       _mesa_debug(ctx, "glPolygonOffset %f %f\n", factor, units);
 
    if (ctx->Polygon.OffsetFactor == factor &&
-       ctx->Polygon.OffsetUnits == units)
+       ctx->Polygon.OffsetUnits == units &&
+       ctx->Polygon.OffsetClamp == 0.0)
       return;
 
    FLUSH_VERTICES(ctx, _NEW_POLYGON);
    ctx->Polygon.OffsetFactor = factor;
    ctx->Polygon.OffsetUnits = units;
+   ctx->Polygon.OffsetClamp = 0.0;
 
    if (ctx->Driver.PolygonOffset)
-      ctx->Driver.PolygonOffset( ctx, factor, units );
+      ctx->Driver.PolygonOffset( ctx, factor, units, 0.0 );
 }
 
 
@@ -268,7 +270,29 @@ _mesa_PolygonOffsetEXT( GLfloat factor, GLfloat bias )
 void GLAPIENTRY
 _mesa_PolygonOffsetClampEXT( GLfloat factor, GLfloat units, GLfloat clamp )
 {
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (!ctx->Extensions.EXT_polygon_offset_clamp ||
+       ctx->API != API_OPENGL_CORE) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "unsupported function (glPolygonOffsetClampEXT) called");
+   }
 
+   if (MESA_VERBOSE&VERBOSE_API)
+      _mesa_debug(ctx, "glPolygonOffsetClampEXT %f %f %f\n", factor, units, clamp);
+
+   if (ctx->Polygon.OffsetFactor == factor &&
+       ctx->Polygon.OffsetUnits == units &&
+       ctx->Polygon.OffsetClamp == clamp)
+      return;
+
+   FLUSH_VERTICES(ctx, _NEW_POLYGON);
+   ctx->Polygon.OffsetFactor = factor;
+   ctx->Polygon.OffsetUnits = units;
+   ctx->Polygon.OffsetClamp = clamp;
+
+   if (ctx->Driver.PolygonOffset)
+      ctx->Driver.PolygonOffset( ctx, factor, units, clamp );
 }
 
 
-- 
2.0.5



More information about the mesa-dev mailing list