+ GET_CURRENT_CONTEXT(ctx);
+
+ prepare_target(ctx, srcName, srcTarget, srcLevel, srcZ, &srcTexImage,
+ &srcRenderbuffer);
+
+ prepare_target(ctx, dstName, dstTarget, dstLevel, dstZ, &dstTexImage,
+ &dstRenderbuffer);
+
+ copy_image_subdata(ctx, srcTexImage, srcRenderbuffer, srcX, srcY, srcZ,
+ srcLevel, dstTexImage, dstRenderbuffer, dstX, dstY, dstZ,
+ dstLevel, srcWidth, srcHeight, srcDepth);
+}
+
+void GLAPIENTRY
+_mesa_CopyImageSubDataNV(GLuint srcName, GLenum srcTarget, GLint srcLevel,
+ GLint srcX, GLint srcY, GLint srcZ,
+ GLuint dstName, GLenum dstTarget, GLint dstLevel,
+ GLint dstX, GLint dstY, GLint dstZ,
+ GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_texture_image *srcTexImage, *dstTexImage;
+ struct gl_renderbuffer *srcRenderbuffer, *dstRenderbuffer;
+ mesa_format srcFormat, dstFormat;
+ GLenum srcIntFormat, dstIntFormat;
+ GLuint src_w, src_h, dst_w, dst_h;
+ GLuint src_bw, src_bh, dst_bw, dst_bh;
+ GLuint src_num_samples, dst_num_samples;
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glCopyImageSubDataNV(%u, %s, %d, %d, %d, %d, "
+ "%u, %s, %d, %d, %d, %d, "
+ "%d, %d, %d)\n",
+ srcName, _mesa_enum_to_string(srcTarget), srcLevel,
+ srcX, srcY, srcZ,
+ dstName, _mesa_enum_to_string(dstTarget), dstLevel,
+ dstX, dstY, dstZ,
+ srcWidth, srcHeight, srcDepth);
+
+ if (!ctx->Extensions.NV_copy_image) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glCopyImageSubDataNV(extension not available)");
+ return;
+ }
+
+ if (!prepare_target_err(ctx, srcName, srcTarget, srcLevel, srcZ, srcDepth,
+ &srcTexImage, &srcRenderbuffer, &srcFormat,
+ &srcIntFormat, &src_w, &src_h, &src_num_samples,
+ "src", false))
+ return;
+
+ if (!prepare_target_err(ctx, dstName, dstTarget, dstLevel, dstZ, srcDepth,
+ &dstTexImage, &dstRenderbuffer, &dstFormat,
+ &dstIntFormat, &dst_w, &dst_h, &dst_num_samples,
+ "dst", false))
+ return;
+
+ /*
+ * The NV_copy_image spec says:
+ *
+ * INVALID_OPERATION is generated if either object is a texture
+ * and the texture is not consistent, or if the source and destination
+ * internal formats or number of samples do not match.
+ *
+ * In the absence of any definition of texture consistency the texture
+ * completeness check, which is affected in the prepare_target_err function,
+ * is used instead in keeping with the ARB version.
+ * The check related to the internal format here is different from the ARB
+ * version which adds the ability to copy between images which have
+ * different formats where the formats are compatible for texture views.
+ */
+ if (srcIntFormat != dstIntFormat) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glCopyImageSubDataNV(internalFormat mismatch)");
+ return;
+ }
+
+ if (src_num_samples != dst_num_samples) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glCopyImageSubDataNV(number of samples mismatch)");
+ return;
+ }
+
+ /*
+ * The NV_copy_image spec says:
+ *
+ * INVALID_VALUE is generated if the image format is compressed
+ * and the dimensions of the subregion fail to meet the alignment
+ * constraints of the format.
+ *
+ * The check here is identical to the ARB version.
+ */
+ _mesa_get_format_block_size(srcFormat, &src_bw, &src_bh);
+ if ((srcX % src_bw != 0) || (srcY % src_bh != 0) ||
+ (srcWidth % src_bw != 0 && (srcX + srcWidth) != src_w) ||
+ (srcHeight % src_bh != 0 && (srcY + srcHeight) != src_h)) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyImageSubDataNV(unaligned src rectangle)");
+ return;
+ }
+
+ _mesa_get_format_block_size(dstFormat, &dst_bw, &dst_bh);
+ if ((dstX % dst_bw != 0) || (dstY % dst_bh != 0)) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyImageSubDataNV(unaligned dst rectangle)");
+ return;