[Mesa-dev] [PATCH V4 7/9] mesa: add *FramebufferTexture() support to frame_buffer_texture helper

Nicolai Hähnle nhaehnle at gmail.com
Tue May 16 13:34:33 UTC 2017


On 16.05.2017 03:23, Timothy Arceri wrote:
> V2: call check_layered_texture_target() even for no_error
> ---
>  src/mesa/main/fbobject.c | 141 ++++++++++++++---------------------------------
>  1 file changed, 41 insertions(+), 100 deletions(-)
>
> diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
> index 8e25dfa..adebf60 100644
> --- a/src/mesa/main/fbobject.c
> +++ b/src/mesa/main/fbobject.c
> @@ -3420,26 +3420,35 @@ void GLAPIENTRY
>  _mesa_FramebufferTexture3D(GLenum target, GLenum attachment,
>                             GLenum textarget, GLuint texture,
>                             GLint level, GLint layer)
>  {
>     framebuffer_texture_with_dims(3, target, attachment, textarget, texture,
>                                   level, layer, "glFramebufferTexture3D");
>  }
>
>
>  static ALWAYS_INLINE void
> -frame_buffer_texture_layer(GLuint framebuffer, GLenum target,
> -                           GLenum attachment, GLuint texture,
> -                           GLint level, GLint layer, const char *func,
> -                           bool dsa, bool no_error)
> +frame_buffer_texture(GLuint framebuffer, GLenum target,
> +                     GLenum attachment, GLuint texture,
> +                     GLint level, GLint layer, const char *func,
> +                     bool dsa, bool no_error, bool check_layered)
>  {
>     GET_CURRENT_CONTEXT(ctx);
> +   GLboolean layered = GL_FALSE;
> +
> +   if (!no_error && check_layered) {
> +      if (!_mesa_has_geometry_shaders(ctx)) {
> +         _mesa_error(ctx, GL_INVALID_OPERATION,
> +                     "unsupported function (%s) called", func);
> +         return;
> +      }
> +   }
>
>     /* Get the framebuffer object */
>     struct gl_framebuffer *fb;
>     if (no_error) {
>        if (dsa) {
>           fb = _mesa_lookup_framebuffer(ctx, framebuffer);
>        } else {
>           fb = get_framebuffer_target(ctx, target);
>        }
>     } else {
> @@ -3457,184 +3466,116 @@ frame_buffer_texture_layer(GLuint framebuffer, GLenum target,
>        }
>     }
>
>     /* Get the texture object and framebuffer attachment*/
>     struct gl_renderbuffer_attachment *att;
>     struct gl_texture_object *texObj;
>     if (no_error) {
>        texObj = get_texture_for_framebuffer(ctx, texture);
>        att = get_attachment(ctx, fb, attachment, NULL);
>     } else {
> -      if (!get_texture_for_framebuffer_err(ctx, texture, false, func,
> +      if (!get_texture_for_framebuffer_err(ctx, texture, check_layered, func,
>                                             &texObj))
>           return;
>
>        att = _mesa_get_and_validate_attachment(ctx, fb, attachment, func);
>        if (!att)
>           return;
>     }
>
>     GLenum textarget = 0;
>     if (texObj) {
> -      if (!no_error) {
> -         if (!check_texture_target(ctx, texObj->Target, func))
> +      if (check_layered) {
> +         /* We do this regadless on no_error because it sets layered */

"regardless of"

With that fixed:

Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>


> +         if (!check_layered_texture_target(ctx, texObj->Target, func,
> +                                           &layered))
>              return;
> +      }
>
> -         if (!check_layer(ctx, texObj->Target, layer, func))
> -            return;
> +      if (!no_error) {
> +         if (!check_layered) {
> +            if (!check_texture_target(ctx, texObj->Target, func))
> +               return;
> +
> +            if (!check_layer(ctx, texObj->Target, layer, func))
> +               return;
> +         }
>
>           if (!check_level(ctx, texObj->Target, level, func))
>              return;
>        }
>
> -      if (texObj->Target == GL_TEXTURE_CUBE_MAP) {
> +      if (!check_layered && texObj->Target == GL_TEXTURE_CUBE_MAP) {
>           assert(layer >= 0 && layer < 6);
>           textarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer;
>           layer = 0;
>        }
>     }
>
>     _mesa_framebuffer_texture(ctx, fb, attachment, att, texObj, textarget,
> -                             level, layer, GL_FALSE);
> +                             level, layer, layered);
>  }
>
>  void GLAPIENTRY
>  _mesa_FramebufferTextureLayer_no_error(GLenum target, GLenum attachment,
>                                         GLuint texture, GLint level,
>                                         GLint layer)
>  {
> -   frame_buffer_texture_layer(0, target, attachment, texture, level, layer,
> -                              "glFramebufferTextureLayer", false, true);
> +   frame_buffer_texture(0, target, attachment, texture, level, layer,
> +                        "glFramebufferTextureLayer", false, true, false);
>  }
>
>
>  void GLAPIENTRY
>  _mesa_FramebufferTextureLayer(GLenum target, GLenum attachment,
>                                GLuint texture, GLint level, GLint layer)
>  {
> -   frame_buffer_texture_layer(0, target, attachment, texture, level, layer,
> -                              "glFramebufferTextureLayer", false, false);
> +   frame_buffer_texture(0, target, attachment, texture, level, layer,
> +                        "glFramebufferTextureLayer", false, false, false);
>  }
>
>
>  void GLAPIENTRY
>  _mesa_NamedFramebufferTextureLayer_no_error(GLuint framebuffer,
>                                              GLenum attachment,
>                                              GLuint texture, GLint level,
>                                              GLint layer)
>  {
> -   frame_buffer_texture_layer(framebuffer, 0, attachment, texture, level,
> -                              layer, "glNamedFramebufferTextureLayer", true,
> -                              true);
> +   frame_buffer_texture(framebuffer, 0, attachment, texture, level, layer,
> +                        "glNamedFramebufferTextureLayer", true, true, false);
>  }
>
>
>  void GLAPIENTRY
>  _mesa_NamedFramebufferTextureLayer(GLuint framebuffer, GLenum attachment,
>                                     GLuint texture, GLint level, GLint layer)
>  {
> -   frame_buffer_texture_layer(framebuffer, 0, attachment, texture, level,
> -                              layer, "glNamedFramebufferTextureLayer", true,
> -                              false);
> +   frame_buffer_texture(framebuffer, 0, attachment, texture, level, layer,
> +                        "glNamedFramebufferTextureLayer", true, false, false);
>  }
>
>
>  void GLAPIENTRY
>  _mesa_FramebufferTexture(GLenum target, GLenum attachment,
>                           GLuint texture, GLint level)
>  {
> -   GET_CURRENT_CONTEXT(ctx);
> -   struct gl_framebuffer *fb;
> -   struct gl_texture_object *texObj;
> -   GLboolean layered = GL_FALSE;
> -
> -   const char *func = "FramebufferTexture";
> -
> -   if (!_mesa_has_geometry_shaders(ctx)) {
> -      _mesa_error(ctx, GL_INVALID_OPERATION,
> -                  "unsupported function (glFramebufferTexture) called");
> -      return;
> -   }
> -
> -   /* Get the framebuffer object */
> -   fb = get_framebuffer_target(ctx, target);
> -   if (!fb) {
> -      _mesa_error(ctx, GL_INVALID_ENUM,
> -                  "glFramebufferTexture(invalid target %s)",
> -                  _mesa_enum_to_string(target));
> -      return;
> -   }
> -
> -   /* Get the texture object */
> -   if (!get_texture_for_framebuffer_err(ctx, texture, true, func, &texObj))
> -      return;
> -
> -   if (texObj) {
> -      if (!check_layered_texture_target(ctx, texObj->Target, func, &layered))
> -         return;
> -
> -      if (!check_level(ctx, texObj->Target, level, func))
> -         return;
> -   }
> -
> -   struct gl_renderbuffer_attachment *att =
> -      _mesa_get_and_validate_attachment(ctx, fb, attachment, func);
> -   if (!att)
> -      return;
> -
> -   _mesa_framebuffer_texture(ctx, fb, attachment, att, texObj, 0, level,
> -                             0, layered);
> +   frame_buffer_texture(0, target, attachment, texture, level, 0,
> +                        "glFramebufferTexture", false, false, true);
>  }
>
>
>  void GLAPIENTRY
>  _mesa_NamedFramebufferTexture(GLuint framebuffer, GLenum attachment,
>                                GLuint texture, GLint level)
>  {
> -   GET_CURRENT_CONTEXT(ctx);
> -   struct gl_framebuffer *fb;
> -   struct gl_texture_object *texObj;
> -   GLboolean layered = GL_FALSE;
> -
> -   const char *func = "glNamedFramebufferTexture";
> -
> -   if (!_mesa_has_geometry_shaders(ctx)) {
> -      _mesa_error(ctx, GL_INVALID_OPERATION,
> -                  "unsupported function (glNamedFramebufferTexture) called");
> -      return;
> -   }
> -
> -   /* Get the framebuffer object */
> -   fb = _mesa_lookup_framebuffer_err(ctx, framebuffer, func);
> -   if (!fb)
> -      return;
> -
> -   /* Get the texture object */
> -   if (!get_texture_for_framebuffer_err(ctx, texture, true, func, &texObj))
> -      return;
> -
> -   if (texObj) {
> -      if (!check_layered_texture_target(ctx, texObj->Target, func,
> -                                        &layered))
> -         return;
> -
> -      if (!check_level(ctx, texObj->Target, level, func))
> -         return;
> -   }
> -
> -   struct gl_renderbuffer_attachment *att =
> -      _mesa_get_and_validate_attachment(ctx, fb, attachment, func);
> -   if (!att)
> -      return;
> -
> -   _mesa_framebuffer_texture(ctx, fb, attachment, att, texObj, 0, level,
> -                             0, layered);
> +   frame_buffer_texture(framebuffer, 0, attachment, texture, level, 0,
> +                        "glNamedFramebufferTexture", true, false, true);
>  }
>
>
>  void
>  _mesa_framebuffer_renderbuffer(struct gl_context *ctx,
>                                 struct gl_framebuffer *fb,
>                                 GLenum attachment,
>                                 struct gl_renderbuffer *rb)
>  {
>     assert(!_mesa_is_winsys_fbo(fb));
>


-- 
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.


More information about the mesa-dev mailing list