[Mesa-dev] [PATCH 05/34] main: Allow for the possibility of GL 3.2 without ARB_geometry_shader4.

Paul Berry stereotype441 at gmail.com
Sun Jul 28 23:03:31 PDT 2013


Previously, we assumed that the only way Mesa would expose geometry
shader support was via the ARB_geometry_shader4 extension.  But this
extension has some extra complications over GL 3.2 (interactions with
compatibility-only features, and link-time initialization of the
constant gl_VerticesIn).  So we want to allow for the possibility of
supporting GL 3.2 (with GLSL 1.50 style geometry shaders) even if
ctx->Extensions.ARB_geometry_shader4 is false.

This patch adds a new function, _mesa_has_geometry_shaders(), which
returns true if either ARB_geometry_shader4 is supported or the GL
version is at least 3.2 desktop.  It also adds a new constant,
GeometryShaders150, which the driver can set to true to inform the
front-end that it supports GLSL 1.50-style geometry shaders.
---
 src/mesa/drivers/common/meta.c |  2 +-
 src/mesa/main/api_validate.c   |  2 +-
 src/mesa/main/context.h        | 11 +++++++++++
 src/mesa/main/fbobject.c       |  2 +-
 src/mesa/main/get.c            |  2 +-
 src/mesa/main/mtypes.h         |  8 ++++++++
 src/mesa/main/shaderapi.c      |  5 ++---
 src/mesa/main/version.c        |  2 +-
 8 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 4a3497c..c62927c 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -956,7 +956,7 @@ _mesa_meta_end(struct gl_context *ctx)
       if (ctx->Extensions.ARB_vertex_shader)
 	 _mesa_use_shader_program(ctx, GL_VERTEX_SHADER, save->VertexShader);
 
-      if (ctx->Extensions.ARB_geometry_shader4)
+      if (_mesa_has_geometry_shaders(ctx))
 	 _mesa_use_shader_program(ctx, GL_GEOMETRY_SHADER_ARB,
 				  save->GeometryShader);
 
diff --git a/src/mesa/main/api_validate.c b/src/mesa/main/api_validate.c
index 7ab8e30..8a2ec7b 100644
--- a/src/mesa/main/api_validate.c
+++ b/src/mesa/main/api_validate.c
@@ -222,7 +222,7 @@ _mesa_is_valid_prim_mode(struct gl_context *ctx, GLenum mode)
    case GL_LINE_STRIP_ADJACENCY:
    case GL_TRIANGLES_ADJACENCY:
    case GL_TRIANGLE_STRIP_ADJACENCY:
-      return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_geometry_shader4;
+      return _mesa_has_geometry_shaders(ctx);
    default:
       return false;
    }
diff --git a/src/mesa/main/context.h b/src/mesa/main/context.h
index 8872be1..792ab4c 100644
--- a/src/mesa/main/context.h
+++ b/src/mesa/main/context.h
@@ -312,6 +312,17 @@ _mesa_is_gles3(const struct gl_context *ctx)
 }
 
 
+/**
+ * Checks if the context supports geometry shaders.
+ */
+static inline GLboolean
+_mesa_has_geometry_shaders(const struct gl_context *ctx)
+{
+   return _mesa_is_desktop_gl(ctx) &&
+      (ctx->Version >= 32 || ctx->Extensions.ARB_geometry_shader4);
+}
+
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
index a29f1ab..f0f59a6 100644
--- a/src/mesa/main/fbobject.c
+++ b/src/mesa/main/fbobject.c
@@ -2472,7 +2472,7 @@ _mesa_FramebufferTexture(GLenum target, GLenum attachment,
 {
    GET_CURRENT_CONTEXT(ctx);
 
-   if (ctx->Version >= 32 || ctx->Extensions.ARB_geometry_shader4) {
+   if (_mesa_has_geometry_shaders(ctx)) {
       framebuffer_texture(ctx, "Layer", target, attachment, 0, texture,
                           level, 0, GL_TRUE);
    } else {
diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index 0b33fa4..09b008a 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -989,7 +989,7 @@ check_extra(struct gl_context *ctx, const char *func, const struct value_desc *d
       case EXTRA_EXT_UBO_GS4:
          api_check = GL_TRUE;
          api_found = (ctx->Extensions.ARB_uniform_buffer_object &&
-                      ctx->Extensions.ARB_geometry_shader4);
+                      _mesa_has_geometry_shaders(ctx));
          break;
       case EXTRA_END:
 	 break;
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index aba7d84..efa2d39 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2978,6 +2978,14 @@ struct gl_constants
    GLint MaxColorTextureSamples;
    GLint MaxDepthTextureSamples;
    GLint MaxIntegerSamples;
+
+   /**
+    * True if the implementation supports GLSL 1.50 style geometry shaders.
+    * This boolean is distinct from gl_extensions::ARB_geometry_shader4 so
+    * that we can expose GLSL 1.50 (and GL 3.2) functionality without exposing
+    * {ARB,EXT}_geometry_shader4.
+    */
+   GLboolean GeometryShaders150;
 };
 
 
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index 9c8af87..e8303c8 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -177,7 +177,7 @@ validate_shader_target(const struct gl_context *ctx, GLenum type)
    case GL_VERTEX_SHADER:
       return ctx->Extensions.ARB_vertex_shader;
    case GL_GEOMETRY_SHADER_ARB:
-      return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_geometry_shader4;
+      return _mesa_has_geometry_shaders(ctx);
    default:
       return false;
    }
@@ -476,8 +476,7 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, GLint *param
 
    /* Are geometry shaders available in this context?
     */
-   const bool has_gs =
-      _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_geometry_shader4;
+   const bool has_gs = _mesa_has_geometry_shaders(ctx);
 
    /* Are uniform buffer objects available in this context?
     */
diff --git a/src/mesa/main/version.c b/src/mesa/main/version.c
index ab9b14c..0e836cc 100644
--- a/src/mesa/main/version.c
+++ b/src/mesa/main/version.c
@@ -262,7 +262,7 @@ compute_version(struct gl_context *ctx)
                               ctx->Extensions.ARB_depth_clamp &&
                               ctx->Extensions.ARB_draw_elements_base_vertex &&
                               ctx->Extensions.ARB_fragment_coord_conventions &&
-                              ctx->Extensions.ARB_geometry_shader4 &&
+                              ctx->Const.GeometryShaders150 &&
                               ctx->Extensions.EXT_provoking_vertex &&
                               ctx->Extensions.ARB_seamless_cube_map &&
                               ctx->Extensions.ARB_sync &&
-- 
1.8.3.4



More information about the mesa-dev mailing list