main: remove extern C around #includes in ff_fragment_shader.cpp
[mesa.git] / src / mesa / main / fbobject.c
index cd04fbe11147e48b3dd3290b708b124621d0d635..4c3c157a47e798b10147c7277a0c2de59f039e84 100644 (file)
@@ -500,6 +500,12 @@ _mesa_framebuffer_renderbuffer(struct gl_context *ctx,
    }
    else {
       remove_attachment(ctx, att);
+      if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
+         /* detach stencil (depth was detached above) */
+         att = get_attachment(ctx, fb, GL_STENCIL_ATTACHMENT_EXT);
+         assert(att);
+         remove_attachment(ctx, att);
+      }
    }
 
    invalidate_framebuffer(fb);
@@ -593,6 +599,7 @@ fbo_incomplete(struct gl_context *ctx, const char *msg, int index)
    static GLuint msg_id;
 
    _mesa_gl_debug(ctx, &msg_id,
+                  MESA_DEBUG_SOURCE_API,
                   MESA_DEBUG_TYPE_OTHER,
                   MESA_DEBUG_SEVERITY_MEDIUM,
                   "FBO incomplete: %s [%d]\n", msg, index);
@@ -1058,6 +1065,8 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
       if (att->Layered) {
          if (att_tex_target == GL_TEXTURE_CUBE_MAP)
             att_layer_count = 6;
+         else if (att_tex_target == GL_TEXTURE_1D_ARRAY)
+            att_layer_count = att->Renderbuffer->Height;
          else
             att_layer_count = att->Renderbuffer->Depth;
       } else {
@@ -1421,6 +1430,9 @@ _mesa_base_fbo_format(struct gl_context *ctx, GLenum internalFormat)
    case GL_RGB8:
       return GL_RGB;
    case GL_RGB:
+      if (_mesa_is_gles3(ctx))
+         return GL_RGB;
+      /* fallthrough */
    case GL_R3_G3_B2:
    case GL_RGB4:
    case GL_RGB5:
@@ -1435,6 +1447,9 @@ _mesa_base_fbo_format(struct gl_context *ctx, GLenum internalFormat)
    case GL_RGBA8:
       return GL_RGBA;
    case GL_RGBA:
+      if (_mesa_is_gles3(ctx))
+         return GL_RGBA;
+      /* fallthrough */
    case GL_RGBA2:
    case GL_RGBA12:
    case GL_RGBA16:
@@ -2295,8 +2310,8 @@ reuse_framebuffer_texture_attachment(struct gl_framebuffer *fb,
 
 
 /**
- * Common code called by glFramebufferTexture1D/2D/3DEXT() and
- * glFramebufferTextureLayerEXT().
+ * Common code called by glFramebufferTexture1D/2D/3D() and
+ * glFramebufferTextureLayer().
  *
  * \param textarget is the textarget that was passed to the
  * glFramebufferTexture...() function, or 0 if the corresponding function
@@ -2318,14 +2333,14 @@ framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target,
    fb = get_framebuffer_target(ctx, target);
    if (!fb) {
       _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glFramebufferTexture%sEXT(target=0x%x)", caller, target);
+                  "glFramebufferTexture%s(target=0x%x)", caller, target);
       return;
    }
 
    /* check framebuffer binding */
    if (_mesa_is_winsys_fbo(fb)) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glFramebufferTexture%sEXT", caller);
+                  "glFramebufferTexture%s", caller);
       return;
    }
 
@@ -2389,14 +2404,14 @@ framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target,
       else {
          /* can't render to a non-existant texture */
          _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glFramebufferTexture%sEXT(non existant texture)",
+                     "glFramebufferTexture%s(non existant texture)",
                      caller);
          return;
       }
 
       if (err) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glFramebufferTexture%sEXT(texture target mismatch)",
+                     "glFramebufferTexture%s(texture target mismatch)",
                      caller);
          return;
       }
@@ -2405,7 +2420,7 @@ framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target,
          const GLint maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1);
          if (zoffset < 0 || zoffset >= maxSize) {
             _mesa_error(ctx, GL_INVALID_VALUE,
-                        "glFramebufferTexture%sEXT(zoffset)", caller);
+                        "glFramebufferTexture%s(zoffset)", caller);
             return;
          }
       }
@@ -2416,7 +2431,7 @@ framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target,
          if (zoffset < 0 ||
              zoffset >= (GLint) ctx->Const.MaxArrayTextureLayers) {
             _mesa_error(ctx, GL_INVALID_VALUE,
-                        "glFramebufferTexture%sEXT(layer)", caller);
+                        "glFramebufferTexture%s(layer)", caller);
             return;
          }
       }
@@ -2425,7 +2440,7 @@ framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target,
       if ((level < 0) ||
           (level >= _mesa_max_texture_levels(ctx, maxLevelsTarget))) {
          _mesa_error(ctx, GL_INVALID_VALUE,
-                     "glFramebufferTexture%sEXT(level)", caller);
+                     "glFramebufferTexture%s(level)", caller);
          return;
       }
    }
@@ -2433,7 +2448,7 @@ framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target,
    att = get_attachment(ctx, fb, attachment);
    if (att == NULL) {
       _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glFramebufferTexture%sEXT(attachment)", caller);
+                  "glFramebufferTexture%s(attachment)", caller);
       return;
    }
 
@@ -2523,7 +2538,7 @@ _mesa_FramebufferTexture1D(GLenum target, GLenum attachment,
 
       if (error) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glFramebufferTexture1DEXT(textarget=%s)",
+                     "glFramebufferTexture1D(textarget=%s)",
                      _mesa_lookup_enum_by_nr(textarget));
          return;
       }
@@ -2574,7 +2589,7 @@ _mesa_FramebufferTexture2D(GLenum target, GLenum attachment,
 
       if (error) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glFramebufferTexture2DEXT(textarget=%s)",
+                     "glFramebufferTexture2D(textarget=%s)",
                      _mesa_lookup_enum_by_nr(textarget));
          return;
       }
@@ -2594,7 +2609,7 @@ _mesa_FramebufferTexture3D(GLenum target, GLenum attachment,
 
    if ((texture != 0) && (textarget != GL_TEXTURE_3D)) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glFramebufferTexture3DEXT(textarget)");
+                  "glFramebufferTexture3D(textarget)");
       return;
    }
 
@@ -2621,7 +2636,7 @@ _mesa_FramebufferTexture(GLenum target, GLenum attachment,
    GET_CURRENT_CONTEXT(ctx);
 
    if (_mesa_has_geometry_shaders(ctx)) {
-      framebuffer_texture(ctx, "Layer", target, attachment, 0, texture,
+      framebuffer_texture(ctx, "", target, attachment, 0, texture,
                           level, 0, GL_TRUE);
    } else {
       _mesa_error(ctx, GL_INVALID_OPERATION,
@@ -2643,26 +2658,26 @@ _mesa_FramebufferRenderbuffer(GLenum target, GLenum attachment,
    fb = get_framebuffer_target(ctx, target);
    if (!fb) {
       _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glFramebufferRenderbufferEXT(target)");
+                  "glFramebufferRenderbuffer(target)");
       return;
    }
 
    if (renderbufferTarget != GL_RENDERBUFFER_EXT) {
       _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glFramebufferRenderbufferEXT(renderbufferTarget)");
+                  "glFramebufferRenderbuffer(renderbufferTarget)");
       return;
    }
 
    if (_mesa_is_winsys_fbo(fb)) {
       /* Can't attach new renderbuffers to a window system framebuffer */
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glFramebufferRenderbufferEXT");
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glFramebufferRenderbuffer");
       return;
    }
 
    att = get_attachment(ctx, fb, attachment);
    if (att == NULL) {
       _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glFramebufferRenderbufferEXT(invalid attachment %s)",
+                  "glFramebufferRenderbuffer(invalid attachment %s)",
                   _mesa_lookup_enum_by_nr(attachment));
       return;
    }
@@ -2671,13 +2686,13 @@ _mesa_FramebufferRenderbuffer(GLenum target, GLenum attachment,
       rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
       if (!rb) {
         _mesa_error(ctx, GL_INVALID_OPERATION,
-                    "glFramebufferRenderbufferEXT(non-existant"
+                    "glFramebufferRenderbuffer(non-existant"
                      " renderbuffer %u)", renderbuffer);
         return;
       }
       else if (rb == &DummyRenderbuffer) {
         _mesa_error(ctx, GL_INVALID_OPERATION,
-                    "glFramebufferRenderbufferEXT(renderbuffer %u)",
+                    "glFramebufferRenderbuffer(renderbuffer %u)",
                      renderbuffer);
         return;
       }
@@ -2693,7 +2708,7 @@ _mesa_FramebufferRenderbuffer(GLenum target, GLenum attachment,
       const GLenum baseFormat = _mesa_get_format_base_format(rb->Format);
       if (baseFormat != GL_DEPTH_STENCIL) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glFramebufferRenderbufferEXT(renderbuffer"
+                     "glFramebufferRenderbuffer(renderbuffer"
                      " is not DEPTH_STENCIL format)");
          return;
       }
@@ -2726,7 +2741,7 @@ _mesa_GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment,
    buffer = get_framebuffer_target(ctx, target);
    if (!buffer) {
       _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glGetFramebufferAttachmentParameterivEXT(target)");
+                  "glGetFramebufferAttachmentParameteriv(target)");
       return;
    }
 
@@ -2765,11 +2780,12 @@ _mesa_GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment,
 
    if (att == NULL) {
       _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glGetFramebufferAttachmentParameterivEXT(attachment)");
+                  "glGetFramebufferAttachmentParameteriv(attachment)");
       return;
    }
 
    if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
+      const struct gl_renderbuffer_attachment *depthAtt, *stencilAtt;
       if (pname == GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE) {
          /* This behavior is first specified in OpenGL 4.4 specification.
           *
@@ -2784,12 +2800,11 @@ _mesa_GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment,
          return;
       }
       /* the depth and stencil attachments must point to the same buffer */
-      const struct gl_renderbuffer_attachment *depthAtt, *stencilAtt;
       depthAtt = get_attachment(ctx, buffer, GL_DEPTH_ATTACHMENT);
       stencilAtt = get_attachment(ctx, buffer, GL_STENCIL_ATTACHMENT);
       if (depthAtt->Renderbuffer != stencilAtt->Renderbuffer) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
+                     "glGetFramebufferAttachmentParameteriv(DEPTH/STENCIL"
                      " attachments differ)");
          return;
       }
@@ -2824,7 +2839,7 @@ _mesa_GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment,
       }
       else if (att->Type == GL_NONE) {
          _mesa_error(ctx, err,
-                     "glGetFramebufferAttachmentParameterivEXT(pname)");
+                     "glGetFramebufferAttachmentParameteriv(pname)");
       }
       else {
          goto invalid_pname_enum;
@@ -2841,7 +2856,7 @@ _mesa_GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment,
       }
       else if (att->Type == GL_NONE) {
          _mesa_error(ctx, err,
-                     "glGetFramebufferAttachmentParameterivEXT(pname)");
+                     "glGetFramebufferAttachmentParameteriv(pname)");
       }
       else {
          goto invalid_pname_enum;
@@ -2852,7 +2867,7 @@ _mesa_GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment,
          goto invalid_pname_enum;
       } else if (att->Type == GL_NONE) {
          _mesa_error(ctx, err,
-                     "glGetFramebufferAttachmentParameterivEXT(pname)");
+                     "glGetFramebufferAttachmentParameteriv(pname)");
       } else if (att->Type == GL_TEXTURE) {
          if (att->Texture && att->Texture->Target == GL_TEXTURE_3D) {
             *params = att->Zoffset;
@@ -2873,7 +2888,7 @@ _mesa_GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment,
       }
       else if (att->Type == GL_NONE) {
          _mesa_error(ctx, err,
-                     "glGetFramebufferAttachmentParameterivEXT(pname)");
+                     "glGetFramebufferAttachmentParameteriv(pname)");
       }
       else {
          if (ctx->Extensions.EXT_framebuffer_sRGB) {
@@ -2896,7 +2911,7 @@ _mesa_GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment,
       }
       else if (att->Type == GL_NONE) {
          _mesa_error(ctx, err,
-                     "glGetFramebufferAttachmentParameterivEXT(pname)");
+                     "glGetFramebufferAttachmentParameteriv(pname)");
       }
       else {
          mesa_format format = att->Renderbuffer->Format;
@@ -2948,7 +2963,7 @@ _mesa_GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment,
       }
       else if (att->Type == GL_NONE) {
          _mesa_error(ctx, err,
-                     "glGetFramebufferAttachmentParameterivEXT(pname)");
+                     "glGetFramebufferAttachmentParameteriv(pname)");
       }
       else if (att->Texture) {
          const struct gl_texture_image *texImage =
@@ -3065,6 +3080,14 @@ invalidate_framebuffer_storage(GLenum target, GLsizei numAttachments,
          case GL_DEPTH_ATTACHMENT:
          case GL_STENCIL_ATTACHMENT:
             break;
+         case GL_DEPTH_STENCIL_ATTACHMENT:
+            /* GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point only
+             * in desktop and ES 3.0 profiles. Note that OES_packed_depth_stencil
+             * extension does not make this attachment point valid on ES 2.0.
+             */
+            if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx))
+               break;
+            /* fallthrough */
          case GL_COLOR_ATTACHMENT0:
          case GL_COLOR_ATTACHMENT1:
          case GL_COLOR_ATTACHMENT2: