[2/7] util: Refactor data generation for depth levels

Submitted by Topi Pohjolainen on April 28, 2016, 7:17 p.m.

Details

Message ID 05d5811eba5642900e67509c2a3d336cb1e852c8.1461870915.git.topi.pohjolainen@intel.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Piglit

Not browsing as part of any series.

Commit Message

Topi Pohjolainen April 28, 2016, 7:17 p.m.
Signed-off-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
---
 tests/util/piglit-util-gl.c | 42 +++++++++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 17 deletions(-)

Patch hide | download patch | download mbox

diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index b288a67..5e96c33 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -2624,6 +2624,29 @@  GLuint piglit_integer_texture(GLenum internalFormat, int w, int h, int b, int a)
 	return tex;
 }
 
+static void
+generate_depth_layer(GLenum internalformat, int w, int h, int layer, void *data)
+{
+	int x, y;
+	float *f = data, *f2 = data;
+	unsigned int *i = data;
+
+	for (y = 0; y < h; y++) {
+		for (x = 0; x < w; x++) {
+			float val = (float)(x) / (w - 1);
+
+			if (internalformat == GL_DEPTH_STENCIL_EXT ||
+			    internalformat == GL_DEPTH24_STENCIL8_EXT) {
+				i[y * w + x] = 0xffffff00 * val;
+			} else if (internalformat == GL_DEPTH32F_STENCIL8) {
+				f2[(y * w + x)*2] = val;
+			} else {
+				f[y * w + x] = val;
+			}
+		}
+	}
+}
+
 /**
  * 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,
@@ -2641,9 +2664,7 @@  GLuint
 piglit_depth_texture(GLenum target, GLenum internalformat, int w, int h, int d, GLboolean mip)
 {
 	void *data;
-	float *f = NULL, *f2 = NULL;
-	unsigned int  *i = NULL;
-	int size, x, y, level, layer;
+	int size, level, layer;
 	GLuint tex;
 	GLenum type, format;
 
@@ -2668,29 +2689,16 @@  piglit_depth_texture(GLenum target, GLenum internalformat, int w, int h, int d,
 	    internalformat == GL_DEPTH24_STENCIL8_EXT) {
 		format = GL_DEPTH_STENCIL_EXT;
 		type = GL_UNSIGNED_INT_24_8_EXT;
-		i = data;
 	} else if (internalformat == GL_DEPTH32F_STENCIL8) {
 		format = GL_DEPTH_STENCIL;
 		type = GL_FLOAT_32_UNSIGNED_INT_24_8_REV;
-		f2 = data;
 	} else {
 		format = GL_DEPTH_COMPONENT;
 		type = GL_FLOAT;
-		f = data;
 	}
 
 	for (level = 0, size = w > h ? w : h; size > 0; level++, size >>= 1) {
-		for (y = 0; y < h; y++) {
-			for (x = 0; x < w; x++) {
-				float val = (float)(x) / (w - 1);
-				if (f)
-					f[y * w + x] = val;
-				else if (f2)
-					f2[(y * w + x)*2] = val;
-				else
-					i[y * w + x] = 0xffffff00 * val;
-			}
-		}
+		generate_depth_layer(internalformat, w, h, 0, data);
 
 		switch (target) {
 		case GL_TEXTURE_1D: