mesa: add bind_texture() helper
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 19 Jul 2017 09:03:48 +0000 (11:03 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Mon, 31 Jul 2017 11:53:39 +0000 (13:53 +0200)
For KHR_no_error support.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/mesa/main/texobj.c

index 2eb8eae4b13be18de05cdc3da2472a6ab2c5f0c8..04f320cbcdd10b7011846a4f3edfc14fd242a14f 100644 (file)
@@ -1637,18 +1637,15 @@ bind_texture_object(struct gl_context *ctx, unsigned unit,
  * \param target texture target.
  * \param texName texture name.
  */
-void GLAPIENTRY
-_mesa_BindTexture( GLenum target, GLuint texName )
+static ALWAYS_INLINE void
+bind_texture(struct gl_context *ctx, GLenum target, GLuint texName,
+             bool no_error)
 {
-   GET_CURRENT_CONTEXT(ctx);
    struct gl_texture_object *newTexObj = NULL;
+   int targetIndex;
 
-   if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
-      _mesa_debug(ctx, "glBindTexture %s %d\n",
-                  _mesa_enum_to_string(target), (GLint) texName);
-
-   int targetIndex = _mesa_tex_target_to_index(ctx, target);
-   if (targetIndex < 0) {
+   targetIndex = _mesa_tex_target_to_index(ctx, target);
+   if (!no_error && targetIndex < 0) {
       _mesa_error(ctx, GL_INVALID_ENUM, "glBindTexture(target = %s)",
                   _mesa_enum_to_string(target));
       return;
@@ -1661,13 +1658,13 @@ _mesa_BindTexture( GLenum target, GLuint texName )
    if (texName == 0) {
       /* Use a default texture object */
       newTexObj = ctx->Shared->DefaultTex[targetIndex];
-   }
-   else {
+   } else {
       /* non-default texture object */
       newTexObj = _mesa_lookup_texture(ctx, texName);
       if (newTexObj) {
          /* error checking */
-         if (newTexObj->Target != 0 && newTexObj->Target != target) {
+         if (!no_error &&
+             newTexObj->Target != 0 && newTexObj->Target != target) {
             /* The named texture object's target doesn't match the
              * given target
              */
@@ -1680,7 +1677,7 @@ _mesa_BindTexture( GLenum target, GLuint texName )
          }
       }
       else {
-         if (ctx->API == API_OPENGL_CORE) {
+         if (!no_error && ctx->API == API_OPENGL_CORE) {
             _mesa_error(ctx, GL_INVALID_OPERATION,
                         "glBindTexture(non-gen name)");
             return;
@@ -1705,6 +1702,19 @@ _mesa_BindTexture( GLenum target, GLuint texName )
 }
 
 
+void GLAPIENTRY
+_mesa_BindTexture(GLenum target, GLuint texName)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
+      _mesa_debug(ctx, "glBindTexture %s %d\n",
+                  _mesa_enum_to_string(target), (GLint) texName);
+
+   bind_texture(ctx, target, texName, false);
+}
+
+
 /**
  * OpenGL 4.5 / GL_ARB_direct_state_access glBindTextureUnit().
  *