summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTopi Pohjolainen <topi.pohjolainen@intel.com>2014-02-23 23:07:37 +0200
committerTopi Pohjolainen <topi.pohjolainen@intel.com>2016-05-19 23:35:59 +0300
commitad3789cd4d3115b0618f0484973c2c1e0d475c4c (patch)
tree5f98a2ff64fd1274ff502651c080dc7c31520cc9
parenta25d63d44352173a1f300defb84e771f28d898e1 (diff)
util: Refactor depth level setup
Signed-off-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
-rw-r--r--tests/util/piglit-util-gl.c87
1 files changed, 49 insertions, 38 deletions
diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index bb58d6a7b..188007f03 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -2664,6 +2664,52 @@ generate_depth_layer(GLenum internalformat, int w, int h, int layer, void *data)
}
}
+static void
+setup_depth_level(GLenum target, GLenum internalformat, GLenum format,
+ GLenum type, int w, int h, int d, int level)
+{
+ int layer;
+ void *data = malloc(w * h * 4 * sizeof(GLfloat));
+
+ switch (target) {
+ case GL_TEXTURE_1D:
+ generate_depth_layer(internalformat, w, h, 0, data);
+ glTexImage1D(target, level,
+ internalformat,
+ w, 0,
+ format, type, data);
+ break;
+
+ case GL_TEXTURE_1D_ARRAY:
+ case GL_TEXTURE_2D:
+ case GL_TEXTURE_RECTANGLE:
+ generate_depth_layer(internalformat, w, h, 0, data);
+ glTexImage2D(target, level,
+ internalformat,
+ w, h, 0,
+ format, type, data);
+ break;
+
+ case GL_TEXTURE_2D_ARRAY:
+ glTexImage3D(target, level,
+ internalformat,
+ w, h, d, 0,
+ format, type, NULL);
+ for (layer = 0; layer < d; layer++) {
+ generate_depth_layer(internalformat, w, h, layer, data);
+ glTexSubImage3D(target, level,
+ 0, 0, layer, w, h, 1,
+ format, type, data);
+ }
+ break;
+
+ default:
+ assert(0);
+ }
+
+ free(data);
+}
+
/**
* Create a depth texture. The depth texture will be a gradient which varies
* from 0.0 at the left side to 1.0 at the right side. For a 2D array texture,
@@ -2680,8 +2726,7 @@ generate_depth_layer(GLenum internalformat, int w, int h, int layer, void *data)
GLuint
piglit_depth_texture(GLenum target, GLenum internalformat, int w, int h, int d, GLboolean mip)
{
- void *data;
- int size, level, layer;
+ int size, level;
GLuint tex;
GLenum type, format;
@@ -2700,7 +2745,6 @@ piglit_depth_texture(GLenum target, GLenum internalformat, int w, int h, int d,
glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
}
- data = malloc(w * h * 4 * sizeof(GLfloat));
if (internalformat == GL_DEPTH_STENCIL_EXT ||
internalformat == GL_DEPTH24_STENCIL8_EXT) {
@@ -2715,40 +2759,8 @@ piglit_depth_texture(GLenum target, GLenum internalformat, int w, int h, int d,
}
for (level = 0, size = w > h ? w : h; size > 0; level++, size >>= 1) {
- generate_depth_layer(internalformat, w, h, 0, data);
-
- switch (target) {
- case GL_TEXTURE_1D:
- glTexImage1D(target, level,
- internalformat,
- w, 0,
- format, type, data);
- break;
-
- case GL_TEXTURE_1D_ARRAY:
- case GL_TEXTURE_2D:
- case GL_TEXTURE_RECTANGLE:
- glTexImage2D(target, level,
- internalformat,
- w, h, 0,
- format, type, data);
- break;
-
- case GL_TEXTURE_2D_ARRAY:
- glTexImage3D(target, level,
- internalformat,
- w, h, d, 0,
- format, type, NULL);
- for (layer = 0; layer < d; layer++) {
- glTexSubImage3D(target, level,
- 0, 0, layer, w, h, 1,
- format, type, data);
- }
- break;
-
- default:
- assert(0);
- }
+ setup_depth_level(target, internalformat, format, type,
+ w, h, d, level);
if (!mip)
break;
@@ -2760,7 +2772,6 @@ piglit_depth_texture(GLenum target, GLenum internalformat, int w, int h, int d,
h > 1)
h >>= 1;
}
- free(data);
return tex;
}