[Mesa-dev] [PATCH 10/21] mesa: add validate_depth_buffer() helper
Samuel Pitoiset
samuel.pitoiset at gmail.com
Thu Jun 1 13:04:59 UTC 2017
Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
src/mesa/main/blit.c | 105 +++++++++++++++++++++++++++------------------------
1 file changed, 56 insertions(+), 49 deletions(-)
diff --git a/src/mesa/main/blit.c b/src/mesa/main/blit.c
index 207ce7d501..455a9a647f 100644
--- a/src/mesa/main/blit.c
+++ b/src/mesa/main/blit.c
@@ -233,6 +233,60 @@ validate_stencil_buffer(struct gl_context *ctx, struct gl_framebuffer *readFb,
}
}
+
+static void
+validate_depth_buffer(struct gl_context *ctx, struct gl_framebuffer *readFb,
+ struct gl_framebuffer *drawFb, GLbitfield *mask,
+ bool no_error, const char *func)
+{
+ struct gl_renderbuffer *readRb =
+ readFb->Attachment[BUFFER_DEPTH].Renderbuffer;
+ struct gl_renderbuffer *drawRb =
+ drawFb->Attachment[BUFFER_DEPTH].Renderbuffer;
+
+ /* From the EXT_framebuffer_object spec:
+ *
+ * "If a buffer is specified in <mask> and does not exist in both
+ * the read and draw framebuffers, the corresponding bit is silently
+ * ignored."
+ */
+ if (readRb == NULL || drawRb == NULL) {
+ *mask &= ~GL_DEPTH_BUFFER_BIT;
+ } else if (!no_error) {
+ int read_s_bit, draw_s_bit;
+
+ if (_mesa_is_gles3(ctx) && (drawRb == readRb)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(source and destination depth buffer cannot be the "
+ "same)", func);
+ return;
+ }
+
+ if ((_mesa_get_format_bits(readRb->Format, GL_DEPTH_BITS) !=
+ _mesa_get_format_bits(drawRb->Format, GL_DEPTH_BITS)) ||
+ (_mesa_get_format_datatype(readRb->Format) !=
+ _mesa_get_format_datatype(drawRb->Format))) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(depth attachment format mismatch)", func);
+ return;
+ }
+
+ read_s_bit = _mesa_get_format_bits(readRb->Format, GL_STENCIL_BITS);
+ draw_s_bit = _mesa_get_format_bits(drawRb->Format, GL_STENCIL_BITS);
+
+ /* If both buffers also have stencil data, the stencil formats must
+ * match as well. If one doesn't have stencil, it's not blitted, so
+ * we should ignore the stencil format check.
+ */
+ if (read_s_bit > 0 && draw_s_bit > 0 && read_s_bit != draw_s_bit) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(depth attachment stencil bits mismatch)", func);
+ return;
+ }
+ }
+}
+
+
static void
blit_framebuffer(struct gl_context *ctx,
struct gl_framebuffer *readFb, struct gl_framebuffer *drawFb,
@@ -376,55 +430,8 @@ blit_framebuffer(struct gl_context *ctx,
if (mask & GL_STENCIL_BUFFER_BIT)
validate_stencil_buffer(ctx, readFb, drawFb, &mask, false, func);
- if (mask & GL_DEPTH_BUFFER_BIT) {
- struct gl_renderbuffer *readRb =
- readFb->Attachment[BUFFER_DEPTH].Renderbuffer;
- struct gl_renderbuffer *drawRb =
- drawFb->Attachment[BUFFER_DEPTH].Renderbuffer;
-
- /* From the EXT_framebuffer_object spec:
- *
- * "If a buffer is specified in <mask> and does not exist in both
- * the read and draw framebuffers, the corresponding bit is silently
- * ignored."
- */
- if ((readRb == NULL) || (drawRb == NULL)) {
- mask &= ~GL_DEPTH_BUFFER_BIT;
- }
- else {
- int read_s_bit, draw_s_bit;
-
- if (_mesa_is_gles3(ctx) && (drawRb == readRb)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "%s(source and destination depth "
- "buffer cannot be the same)", func);
- return;
- }
-
- if ((_mesa_get_format_bits(readRb->Format, GL_DEPTH_BITS) !=
- _mesa_get_format_bits(drawRb->Format, GL_DEPTH_BITS)) ||
- (_mesa_get_format_datatype(readRb->Format) !=
- _mesa_get_format_datatype(drawRb->Format))) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "%s(depth attachment format mismatch)", func);
- return;
- }
-
- read_s_bit = _mesa_get_format_bits(readRb->Format, GL_STENCIL_BITS);
- draw_s_bit = _mesa_get_format_bits(drawRb->Format, GL_STENCIL_BITS);
-
- /* If both buffers also have stencil data, the stencil formats must
- * match as well. If one doesn't have stencil, it's not blitted, so
- * we should ignore the stencil format check.
- */
- if (read_s_bit > 0 && draw_s_bit > 0 && read_s_bit != draw_s_bit) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "%s(depth attachment stencil bits mismatch)", func);
- return;
- }
- }
- }
-
+ if (mask & GL_DEPTH_BUFFER_BIT)
+ validate_depth_buffer(ctx, readFb, drawFb, &mask, false, func);
if (_mesa_is_gles3(ctx)) {
/* Page 194 (page 206 of the PDF) in section 4.3.2 of the OpenGL ES
--
2.13.0
More information about the mesa-dev
mailing list