On 15 August 2012 12:51, Chad Versace <span dir="ltr"><<a href="mailto:chad.versace@linux.intel.com" target="_blank">chad.versace@linux.intel.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Extend the framebuffer-blit-levels test to verify that<br>
glBlitFramebuffer works when blitting to and from miplevels other than<br>
zero for depth textures.<br>
<br>
CC: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br>
---<br>
.../framebuffer-blit-levels.c | 125 ++++++++++++++++-----<br>
1 file changed, 94 insertions(+), 31 deletions(-)<br>
<br>
diff --git a/tests/spec/arb_framebuffer_object/framebuffer-blit-levels.c b/tests/spec/arb_framebuffer_object/framebuffer-blit-levels.c<br>
index 31e0cf2..65bc497 100644<br>
--- a/tests/spec/arb_framebuffer_object/framebuffer-blit-levels.c<br>
+++ b/tests/spec/arb_framebuffer_object/framebuffer-blit-levels.c<br>
@@ -70,6 +70,14 @@ GLuint aux_framebuffer;<br>
GLuint test_texture;<br>
GLuint aux_texture;<br>
<br>
+GLenum texture_internal_format;<br>
+GLenum texture_format;<br>
+GLenum texture_type;<br></blockquote><div><br>Is texture_type really necessary? It looks like we always use GL_FLOAT.<br><br>By the same token, it looks like we always use the same values for texture_internal_format and texture_format.<br>
<br>I won't push you on the subject, though, because I realize that this change makes the code more self-explanatory :)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+GLbitfield blit_mask;<br>
+GLenum framebuffer_attachment;<br>
+<br>
+<br>
#define LOG2_SIZE 7<br>
#define SIZE (1 << LOG2_SIZE)<br>
<br>
@@ -83,8 +91,8 @@ GLuint aux_texture;<br>
* by taking an integer mod four different primes.<br>
*/<br>
static void<br>
-create_test_data(GLfloat *data, unsigned level,<br>
- unsigned width, unsigned height)<br>
+create_test_data_rgba(GLfloat *data, unsigned level,<br>
+ unsigned width, unsigned height)<br>
{<br>
unsigned pixel;<br>
unsigned num_pixels = width * height;<br>
@@ -97,13 +105,47 @@ create_test_data(GLfloat *data, unsigned level,<br>
}<br>
}<br>
<br>
+/**<br>
+ * Generate a block of test data where each pixel has a unique depth value in<br>
+ * the range [0.0, 1.0).<br>
+ */<br>
+static void<br>
+create_test_data_depth(GLfloat *data, unsigned level,<br>
+ unsigned width, unsigned height)<br>
+{<br>
+ unsigned pixel;<br>
+ unsigned num_pixels = width * height;<br>
+ double depth_delta = 0.95 / ((SIZE >> level) * (SIZE >> level));<br></blockquote><div><br>Consider changing this to the equivalent "double depth_delta = 0.95 / (width * height);" just so that it's clearer how we know it won't overflow.<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ double depth_value = 0;<br>
+<br>
+ for (pixel = 0; pixel < num_pixels; ++pixel) {<br>
+ data[pixel] = depth_value;<br>
+ depth_value += depth_delta;<br>
+ }<br>
+}<br>
+<br>
+static void<br>
+create_test_data(GLfloat *data, GLenum texture_format,<br>
+ unsigned level, unsigned width, unsigned height)<br>
+{<br>
+ if (texture_format == GL_RGBA)<br>
+ create_test_data_rgba(data, level, width, height);<br>
+ else if (texture_format == GL_DEPTH_COMPONENT)<br>
+ create_test_data_depth(data, level, width, height);<br>
+ else<br>
+ assert(0);<br>
+}<br>
+<br>
static void<br>
print_usage_and_exit(char *prog_name)<br>
{<br>
printf("Usage: %s <test_mode>\n"<br>
" where <test_mode> is one of:\n"<br>
" draw: test blitting *to* the given texture type\n"<br>
- " read: test blitting *from* the given texture type\n",<br>
+ " read: test blitting *from* the given texture type\n"<br>
+ " where <format> is one of:\n"<br>
+ " rgba\n"<br>
+ " depth\n",<br>
prog_name);<br>
piglit_report_result(PIGLIT_FAIL);<br>
}<br></blockquote><div><br>all.tests needs to be updated to send in the new command-line parameter.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
@@ -113,7 +155,7 @@ piglit_init(int argc, char **argv)<br>
{<br>
unsigned level;<br>
<br>
- if (argc != 2) {<br>
+ if (argc != 3) {<br>
print_usage_and_exit(argv[0]);<br>
}<br>
<br>
@@ -125,6 +167,22 @@ piglit_init(int argc, char **argv)<br>
print_usage_and_exit(argv[0]);<br>
}<br>
<br>
+ if(strcmp(argv[2], "rgba") == 0) {<br>
+ texture_internal_format = GL_RGBA;<br>
+ texture_format = GL_RGBA;<br>
+ texture_type = GL_FLOAT;<br>
+ framebuffer_attachment = GL_COLOR_ATTACHMENT0;<br>
+ blit_mask = GL_COLOR_BUFFER_BIT;<br>
+ } else if (strcmp(argv[2], "depth") == 0) {<br>
+ texture_internal_format = GL_DEPTH_COMPONENT;<br>
+ texture_format = GL_DEPTH_COMPONENT;<br>
+ texture_type = GL_FLOAT;<br>
+ framebuffer_attachment = GL_DEPTH_ATTACHMENT;<br>
+ blit_mask = GL_DEPTH_BUFFER_BIT;<br>
+ } else {<br>
+ print_usage_and_exit(argv[0]);<br>
+ }<br>
+<br>
piglit_require_extension("GL_ARB_framebuffer_object");<br>
<br>
/* Set up test framebuffer and test texture, but don't<br>
@@ -139,9 +197,12 @@ piglit_init(int argc, char **argv)<br>
GL_NEAREST);<br>
for (level = 0; level < LOG2_SIZE; ++level) {<br>
glTexImage2D(GL_TEXTURE_2D, level,<br>
- GL_RGBA, SIZE >> level, SIZE >> level,<br>
- 0 /* border */, GL_RGBA,<br>
- GL_BYTE /* type */, NULL /* data */);<br>
+ texture_internal_format,<br>
+ SIZE >> level, SIZE >> level,<br>
+ 0 /* border */,<br>
+ texture_format,<br>
+ texture_type,<br>
+ NULL /* data */);<br>
}<br>
<br>
/* Set up aux framebuffer */<br>
@@ -151,11 +212,11 @@ piglit_init(int argc, char **argv)<br>
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);<br>
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);<br>
glTexImage2D(GL_TEXTURE_2D, 0 /* level */,<br>
- GL_RGBA, SIZE, SIZE,<br>
- 0 /* border */, GL_RGBA,<br>
- GL_BYTE /* type */, NULL /* data */);<br>
+ texture_internal_format, SIZE, SIZE,<br>
+ 0 /* border */, texture_format,<br>
+ texture_type, NULL /* data */);<br>
glBindFramebuffer(GL_FRAMEBUFFER, aux_framebuffer);<br>
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,<br>
+ glFramebufferTexture2D(GL_FRAMEBUFFER, framebuffer_attachment,<br>
GL_TEXTURE_2D, aux_texture, 0 /* level */);<br>
}<br>
<br>
@@ -170,14 +231,14 @@ piglit_display()<br>
for (level = 0; level < LOG2_SIZE; ++level) {<br>
unsigned width = SIZE >> level;<br>
unsigned height = SIZE >> level;<br>
- create_test_data(data, level, width, height);<br>
+ create_test_data(data, texture_format, level, width, height);<br>
if (test_mode == TEST_MODE_READ) {<br>
/* Populate directly */<br>
glBindTexture(GL_TEXTURE_2D, test_texture);<br>
glTexImage2D(GL_TEXTURE_2D, level,<br>
- GL_RGBA, width, height,<br>
- 0 /* border */, GL_RGBA,<br>
- GL_FLOAT /* type */, data);<br>
+ texture_internal_format, width, height,<br>
+ 0 /* border */, texture_format,<br>
+ texture_type, data);<br>
} else {<br>
/* Populate via aux texture */<br>
glBindFramebuffer(GL_READ_FRAMEBUFFER,<br>
@@ -186,18 +247,18 @@ piglit_display()<br>
test_framebuffer);<br>
glBindTexture(GL_TEXTURE_2D, aux_texture);<br>
glTexImage2D(GL_TEXTURE_2D, 0 /* level */,<br>
- GL_RGBA, width, height,<br>
- 0 /* border */, GL_RGBA,<br>
- GL_FLOAT /* type */, data);<br>
+ texture_internal_format, width, height,<br>
+ 0 /* border */, texture_format,<br>
+ texture_type, data);<br>
glBindTexture(GL_TEXTURE_2D, test_texture);<br>
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,<br>
- GL_COLOR_ATTACHMENT0,<br>
+ framebuffer_attachment,<br>
GL_TEXTURE_2D,<br>
test_texture,<br>
level);<br>
glBlitFramebuffer(0, 0, width, height,<br>
0, 0, width, height,<br>
- GL_COLOR_BUFFER_BIT, GL_NEAREST);<br>
+ blit_mask, GL_NEAREST);<br>
}<br>
}<br>
<br>
@@ -206,17 +267,18 @@ piglit_display()<br>
unsigned width = SIZE >> level;<br>
unsigned height = SIZE >> level;<br>
printf("Testing level %d\n", level);<br>
- create_test_data(data, level, width, height);<br>
+ create_test_data(data, texture_format, level, width, height);<br>
if (test_mode == TEST_MODE_DRAW) {<br>
/* Read texture data directly using glReadPixels() */<br>
glBindFramebuffer(GL_READ_FRAMEBUFFER, test_texture);<br>
glFramebufferTexture2D(GL_READ_FRAMEBUFFER,<br>
- GL_COLOR_ATTACHMENT0,<br>
+ framebuffer_attachment,<br>
GL_TEXTURE_2D,<br>
test_texture,<br>
level);<br>
- pass = piglit_probe_image_rgba(0, 0, width, height,<br>
- data) && pass;<br>
+ pass = piglit_probe_image_color(0, 0, width, height,<br>
+ texture_format,<br>
+ data) && pass;<br>
} else {<br>
/* Read via aux texture */<br>
glBindFramebuffer(GL_READ_FRAMEBUFFER,<br>
@@ -225,22 +287,23 @@ piglit_display()<br>
aux_framebuffer);<br>
glBindTexture(GL_TEXTURE_2D, test_texture);<br>
glFramebufferTexture2D(GL_READ_FRAMEBUFFER,<br>
- GL_COLOR_ATTACHMENT0,<br>
+ framebuffer_attachment,<br>
GL_TEXTURE_2D,<br>
test_texture,<br>
level);<br>
glBindTexture(GL_TEXTURE_2D, aux_texture);<br>
glTexImage2D(GL_TEXTURE_2D, 0 /* level */,<br>
- GL_RGBA, width, height,<br>
- 0 /* border */, GL_RGBA,<br>
- GL_BYTE /* type */, NULL);<br>
+ texture_internal_format, width, height,<br>
+ 0 /* border */, texture_format,<br>
+ texture_type, NULL);<br>
glBlitFramebuffer(0, 0, width, height,<br>
0, 0, width, height,<br>
- GL_COLOR_BUFFER_BIT, GL_NEAREST);<br>
+ blit_mask, GL_NEAREST);<br>
glBindFramebuffer(GL_READ_FRAMEBUFFER,<br>
aux_framebuffer);<br>
- pass = piglit_probe_image_rgba(0, 0, width, height,<br>
- data) && pass;<br>
+ pass = piglit_probe_image_color(0, 0, width, height,<br>
+ texture_format,<br>
+ data) && pass;<br>
}<br>
}<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
1.7.11.4<br>
<br>
</font></span></blockquote></div><br>My comment about all.tests is the only crucial one. With that fixed, this patch is:<br><br>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br>