[Mesa-dev] [PATCH 10/18] meta: Don't stray outside the confines of the API specified in the context

Ian Romanick idr at freedesktop.org
Fri Aug 24 08:49:09 PDT 2012


From: Paul Berry <stereotype441 at gmail.com>

Signed-off-by: Paul Berry <stereotype441 at gmail.com>
Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/mesa/drivers/common/meta.c |  110 +++++++++++++++++++++++----------------
 src/mesa/main/enable.c         |    5 +-
 2 files changed, 68 insertions(+), 47 deletions(-)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 7d7113c..58d6fa6 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -549,8 +549,10 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield state)
       save->PolygonCull = ctx->Polygon.CullFlag;
       _mesa_PolygonMode(GL_FRONT_AND_BACK, GL_FILL);
       _mesa_set_enable(ctx, GL_POLYGON_OFFSET_FILL, GL_FALSE);
-      _mesa_set_enable(ctx, GL_POLYGON_SMOOTH, GL_FALSE);
-      _mesa_set_enable(ctx, GL_POLYGON_STIPPLE, GL_FALSE);
+      if (ctx->API == API_OPENGL) {
+         _mesa_set_enable(ctx, GL_POLYGON_SMOOTH, GL_FALSE);
+         _mesa_set_enable(ctx, GL_POLYGON_STIPPLE, GL_FALSE);
+      }
       _mesa_set_enable(ctx, GL_CULL_FACE, GL_FALSE);
    }
 
@@ -560,14 +562,14 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield state)
    }
 
    if (state & MESA_META_SHADER) {
-      if (ctx->Extensions.ARB_vertex_program) {
+      if (ctx->API == API_OPENGL && ctx->Extensions.ARB_vertex_program) {
          save->VertexProgramEnabled = ctx->VertexProgram.Enabled;
          _mesa_reference_vertprog(ctx, &save->VertexProgram,
 				  ctx->VertexProgram.Current);
          _mesa_set_enable(ctx, GL_VERTEX_PROGRAM_ARB, GL_FALSE);
       }
 
-      if (ctx->Extensions.ARB_fragment_program) {
+      if (ctx->API == API_OPENGL && ctx->Extensions.ARB_fragment_program) {
          save->FragmentProgramEnabled = ctx->FragmentProgram.Enabled;
          _mesa_reference_fragprog(ctx, &save->FragmentProgram,
 				  ctx->FragmentProgram.Current);
@@ -603,25 +605,27 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield state)
       save->EnvMode = ctx->Texture.Unit[0].EnvMode;
 
       /* Disable all texture units */
-      for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
-         save->TexEnabled[u] = ctx->Texture.Unit[u].Enabled;
-         save->TexGenEnabled[u] = ctx->Texture.Unit[u].TexGenEnabled;
-         if (ctx->Texture.Unit[u].Enabled ||
-             ctx->Texture.Unit[u].TexGenEnabled) {
-            _mesa_ActiveTextureARB(GL_TEXTURE0 + u);
-            _mesa_set_enable(ctx, GL_TEXTURE_1D, GL_FALSE);
-            _mesa_set_enable(ctx, GL_TEXTURE_2D, GL_FALSE);
-            _mesa_set_enable(ctx, GL_TEXTURE_3D, GL_FALSE);
-            if (ctx->Extensions.ARB_texture_cube_map)
-               _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE);
-            if (ctx->Extensions.NV_texture_rectangle)
-               _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE, GL_FALSE);
-            if (ctx->Extensions.OES_EGL_image_external)
-               _mesa_set_enable(ctx, GL_TEXTURE_EXTERNAL_OES, GL_FALSE);
-            _mesa_set_enable(ctx, GL_TEXTURE_GEN_S, GL_FALSE);
-            _mesa_set_enable(ctx, GL_TEXTURE_GEN_T, GL_FALSE);
-            _mesa_set_enable(ctx, GL_TEXTURE_GEN_R, GL_FALSE);
-            _mesa_set_enable(ctx, GL_TEXTURE_GEN_Q, GL_FALSE);
+      if (ctx->API == API_OPENGL || ctx->API == API_OPENGLES) {
+         for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
+            save->TexEnabled[u] = ctx->Texture.Unit[u].Enabled;
+            save->TexGenEnabled[u] = ctx->Texture.Unit[u].TexGenEnabled;
+            if (ctx->Texture.Unit[u].Enabled ||
+                ctx->Texture.Unit[u].TexGenEnabled) {
+               _mesa_ActiveTextureARB(GL_TEXTURE0 + u);
+               _mesa_set_enable(ctx, GL_TEXTURE_1D, GL_FALSE);
+               _mesa_set_enable(ctx, GL_TEXTURE_2D, GL_FALSE);
+               _mesa_set_enable(ctx, GL_TEXTURE_3D, GL_FALSE);
+               if (ctx->Extensions.ARB_texture_cube_map)
+                  _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE);
+               if (ctx->Extensions.NV_texture_rectangle)
+                  _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE, GL_FALSE);
+               if (ctx->Extensions.OES_EGL_image_external)
+                  _mesa_set_enable(ctx, GL_TEXTURE_EXTERNAL_OES, GL_FALSE);
+               _mesa_set_enable(ctx, GL_TEXTURE_GEN_S, GL_FALSE);
+               _mesa_set_enable(ctx, GL_TEXTURE_GEN_T, GL_FALSE);
+               _mesa_set_enable(ctx, GL_TEXTURE_GEN_R, GL_FALSE);
+               _mesa_set_enable(ctx, GL_TEXTURE_GEN_Q, GL_FALSE);
+            }
          }
       }
 
@@ -634,7 +638,9 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield state)
       /* set defaults for unit[0] */
       _mesa_ActiveTextureARB(GL_TEXTURE0);
       _mesa_ClientActiveTextureARB(GL_TEXTURE0);
-      _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+      if (ctx->API == API_OPENGL || ctx->API == API_OPENGLES) {
+         _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+      }
    }
 
    if (state & MESA_META_TRANSFORM) {
@@ -842,9 +848,11 @@ _mesa_meta_end(struct gl_context *ctx)
    if (state & MESA_META_RASTERIZATION) {
       _mesa_PolygonMode(GL_FRONT, save->FrontPolygonMode);
       _mesa_PolygonMode(GL_BACK, save->BackPolygonMode);
-      _mesa_set_enable(ctx, GL_POLYGON_STIPPLE, save->PolygonStipple);
+      if (ctx->API == API_OPENGL) {
+         _mesa_set_enable(ctx, GL_POLYGON_STIPPLE, save->PolygonStipple);
+         _mesa_set_enable(ctx, GL_POLYGON_SMOOTH, save->PolygonSmooth);
+      }
       _mesa_set_enable(ctx, GL_POLYGON_OFFSET_FILL, save->PolygonOffset);
-      _mesa_set_enable(ctx, GL_POLYGON_SMOOTH, save->PolygonSmooth);
       _mesa_set_enable(ctx, GL_CULL_FACE, save->PolygonCull);
    }
 
@@ -855,7 +863,7 @@ _mesa_meta_end(struct gl_context *ctx)
    }
 
    if (state & MESA_META_SHADER) {
-      if (ctx->Extensions.ARB_vertex_program) {
+      if (ctx->API == API_OPENGL && ctx->Extensions.ARB_vertex_program) {
          _mesa_set_enable(ctx, GL_VERTEX_PROGRAM_ARB,
                           save->VertexProgramEnabled);
          _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, 
@@ -863,7 +871,7 @@ _mesa_meta_end(struct gl_context *ctx)
 	 _mesa_reference_vertprog(ctx, &save->VertexProgram, NULL);
       }
 
-      if (ctx->Extensions.ARB_fragment_program) {
+      if (ctx->API == API_OPENGL && ctx->Extensions.ARB_fragment_program) {
          _mesa_set_enable(ctx, GL_FRAGMENT_PROGRAM_ARB,
                           save->FragmentProgramEnabled);
          _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current,
@@ -896,7 +904,7 @@ _mesa_meta_end(struct gl_context *ctx)
 
       _mesa_set_enable(ctx, GL_STENCIL_TEST, stencil->Enabled);
       _mesa_ClearStencil(stencil->Clear);
-      if (ctx->Extensions.EXT_stencil_two_side) {
+      if (ctx->API == API_OPENGL && ctx->Extensions.EXT_stencil_two_side) {
          _mesa_set_enable(ctx, GL_STENCIL_TEST_TWO_SIDE_EXT,
                           stencil->TestTwoSide);
          _mesa_ActiveStencilFaceEXT(stencil->ActiveFace
@@ -928,7 +936,9 @@ _mesa_meta_end(struct gl_context *ctx)
       ASSERT(ctx->Texture.CurrentUnit == 0);
 
       /* restore texenv for unit[0] */
-      _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, save->EnvMode);
+      if (ctx->API == API_OPENGL || ctx->API == API_OPENGLES) {
+         _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, save->EnvMode);
+      }
 
       /* restore texture objects for unit[0] only */
       for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
@@ -941,16 +951,18 @@ _mesa_meta_end(struct gl_context *ctx)
       }
 
       /* Restore fixed function texture enables, texgen */
-      for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
-	 if (ctx->Texture.Unit[u].Enabled != save->TexEnabled[u]) {
-	    FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-	    ctx->Texture.Unit[u].Enabled = save->TexEnabled[u];
-	 }
+      if (ctx->API == API_OPENGL || ctx->API == API_OPENGLES) {
+         for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
+            if (ctx->Texture.Unit[u].Enabled != save->TexEnabled[u]) {
+               FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+               ctx->Texture.Unit[u].Enabled = save->TexEnabled[u];
+            }
 
-	 if (ctx->Texture.Unit[u].TexGenEnabled != save->TexGenEnabled[u]) {
-	    FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-	    ctx->Texture.Unit[u].TexGenEnabled = save->TexGenEnabled[u];
-	 }
+            if (ctx->Texture.Unit[u].TexGenEnabled != save->TexGenEnabled[u]) {
+               FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+               ctx->Texture.Unit[u].TexGenEnabled = save->TexGenEnabled[u];
+            }
+         }
       }
 
       /* restore current unit state */
@@ -1396,11 +1408,13 @@ blitframebuffer_texture(struct gl_context *ctx,
          _mesa_SamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
 	 /* Always do our blits with no sRGB decode or encode.*/
-	 if (ctx->Extensions.EXT_texture_sRGB_decode) {
+         if (_mesa_is_desktop_gl(ctx)
+             && ctx->Extensions.EXT_texture_sRGB_decode) {
 	    _mesa_SamplerParameteri(sampler, GL_TEXTURE_SRGB_DECODE_EXT,
 				GL_SKIP_DECODE_EXT);
 	 }
-         if (ctx->Extensions.EXT_framebuffer_sRGB) {
+         if (_mesa_is_desktop_gl(ctx)
+             && ctx->Extensions.EXT_framebuffer_sRGB) {
             _mesa_set_enable(ctx, GL_FRAMEBUFFER_SRGB_EXT, GL_FALSE);
          }
 
@@ -1461,7 +1475,8 @@ blitframebuffer_texture(struct gl_context *ctx,
             _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, baseLevelSave);
             _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, maxLevelSave);
          }
-	 if (ctx->Extensions.EXT_framebuffer_sRGB && fbo_srgb_save) {
+         if (_mesa_is_desktop_gl(ctx)
+             && ctx->Extensions.EXT_framebuffer_sRGB && fbo_srgb_save) {
 	    _mesa_set_enable(ctx, GL_FRAMEBUFFER_SRGB_EXT, GL_TRUE);
 	 }
 
@@ -2696,6 +2711,12 @@ _mesa_meta_check_generate_mipmap_fallback(struct gl_context *ctx, GLenum target,
    GLuint srcLevel;
    GLenum status;
 
+   /* HACK: GLES2 doesn't support the fixed function paths that we need to
+    * generate mipmaps
+    */
+   if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
+      return GL_TRUE;
+
    /* check for fallbacks */
    if (!ctx->Extensions.EXT_framebuffer_object ||
        target == GL_TEXTURE_3D ||
@@ -3380,11 +3401,10 @@ decompress_texture_image(struct gl_context *ctx,
       _mesa_SamplerParameteri(decompress->Sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
       _mesa_SamplerParameteri(decompress->Sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
       /* No sRGB decode or encode.*/
-      if (ctx->Extensions.EXT_texture_sRGB_decode) {
+      if (_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_sRGB_decode) {
          _mesa_SamplerParameteri(decompress->Sampler, GL_TEXTURE_SRGB_DECODE_EXT,
                              GL_SKIP_DECODE_EXT);
       }
-
    } else {
       _mesa_BindSampler(ctx->Texture.CurrentUnit, decompress->Sampler);
    }
@@ -3424,7 +3444,7 @@ decompress_texture_image(struct gl_context *ctx,
       }
 
       /* No sRGB decode or encode.*/
-      if (ctx->Extensions.EXT_framebuffer_sRGB) {
+      if (_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_framebuffer_sRGB) {
          _mesa_set_enable(ctx, GL_FRAMEBUFFER_SRGB_EXT, GL_FALSE);
       }
 
diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c
index 214f84d..ac1ed9f 100644
--- a/src/mesa/main/enable.c
+++ b/src/mesa/main/enable.c
@@ -764,8 +764,9 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
 
       /* GL_ARB_multisample */
       case GL_MULTISAMPLE_ARB:
-         if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
-            goto invalid_enum_error;
+         /* Technically speaking, this should not be allowed for OpenGL ES 2.0
+          * or 3.0.  However, meta really needs it.
+          */
          if (ctx->Multisample.Enabled == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
-- 
1.7.6.5



More information about the mesa-dev mailing list