[Piglit] [PATCH] Test case for glTexImage2D with depth cube map

Anuj Phogat anuj.phogat at gmail.com
Wed Nov 23 14:40:21 PST 2011


>> +
>> +static const char *vertShaderText =
>> +       "attribute vec3 textureCoords;\n"
>> +       "varying vec3 texCoords;\n"
>> +       "void main()\n"
>> +       "{ \n"
>> +       "       gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
>> +       "       texCoords = textureCoords;\n"
>> +       "} \n";
>
> Is there any particular reason why you're not using the pre-defined
> gl_MultiTexCoord0 attribute and gl_TexCoord[0] varying variables?

No particular reason. I'm more used to write shaders in GLSL ES. I'll 
modify it.

>> +static const char *fragShaderText =
>> +       "uniform samplerCube depthcubeTex;\n"
>> +       "varying vec3 texCoords;\n"
>> +       "void main()\n"
>> +       "{ \n"
>> +       "       vec4 depth = textureCube(depthcubeTex, texCoords);\n"
>> +       "       gl_FragColor = vec4(depth.xyz, 1.0);\n"
>> +       "} \n";
>> +
>> +static void compileLinkProg(void);
>> +static void loadTex(void);
>
> We generally implement functions before they're called to avoid
> forward prototypes like this.
ok
>
>> +void
>> +piglit_init(int argc, char **argv)
>> +{
>> +       if (!GLEW_VERSION_2_0) {
>> +               printf("Requires OpenGL 2.0\n");
>> +               piglit_report_result(PIGLIT_SKIP);
>> +       }
>> +
>> +       if (piglit_automatic)
>> +               printf(" Depth Cube Map\n");
>> +
>> +       loadTex();
>> +
>> +       piglit_require_extension("GL_ARB_texture_rectangle");
>
> I think you meant GL_ARB_texture_cube_map there, right?
right. This was left from the exisiting testcase which i modified to 
create test-cube-map.

>> +       glMatrixMode(GL_PROJECTION);
>> +       glPushMatrix();
>> +       glLoadIdentity();
>> +       glOrtho(0, 400, 0, 400, -1, 1);
>> +
>> +       glMatrixMode(GL_MODELVIEW);
>> +       glPushMatrix();
>> +       glLoadIdentity();
>> +
>> +       glEnable(GL_TEXTURE_CUBE_MAP);
>> +       glClearColor(0.0, 0.0, 0.0, 1.0);
>> +
>> +       compileLinkProg();
>> +}
>> +
>> +static void
>> +compileLinkProg(void)
>> +{
>> +       GLint stat;
>> +
>> +       vs = glCreateShader(GL_VERTEX_SHADER);
>> +       fs = glCreateShader(GL_FRAGMENT_SHADER);
>> +       glShaderSource(vs, 1, (const GLchar **)&vertShaderText, NULL);
>> +       glShaderSource(fs, 1, (const GLchar **)&fragShaderText, NULL);
>> +       glCompileShader(vs);
>> +       glGetShaderiv(vs, GL_COMPILE_STATUS,&stat);
>> +       if (!stat) {
>> +               printf("error compiling vertex shader!\n");
>> +               exit(1);
>> +       }
>> +       glCompileShader(fs);
>> +       glGetShaderiv(fs, GL_COMPILE_STATUS,&stat);
>> +       if (!stat) {
>> +               printf("error compiling fragment shader!\n");
>> +               exit(1);
>> +       }
>> +       prog = glCreateProgram();
>> +       glAttachShader(prog, vs);
>> +       glAttachShader(prog, fs);
>> +       glBindAttribLocation(prog, 1, "textureCoords");
>> +       glLinkProgram(prog);
>> +       glUseProgram(prog);
>
> There are a bunch of piglit utility functions for compiling and
> linking simple shaders like this.  Take a look at some other tests to
> learn more.
I'll take a look and try try to use existing piglit functions in 
testcase.

>> +
>> +       glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), vertices);
>> +       glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), texCoords);
>> +       glEnableVertexAttribArray(0);
>> +       glEnableVertexAttribArray(1);
>> +}
>> +
>> +static void
>> +loadTex(void)
>> +{
>> +       #define height 2
>> +       #define width 2
>> +       int i, j;
>> +       unsigned int face;
>> +
>> +       GLfloat texDepthData[width][height];
>> +       GLfloat texDepthData1[width][height];
>> +       for (i=0; i<  width; ++i) {
>> +               for (j=0; j<  height; ++j) {
>> +                    texDepthData[i][j] = 1.0;
>> +               }
>> +       }
>
> I think the test would be better if the texture images weren't all
> solid 1.0 (white).  Maybe make each cube face a different value/depth
> and draw/probe each.
True. I'm already working on updating the testcase. 

>> +
>> +       //render the cube depth texture using LUMINANCE
>> +       glGenTextures(1,&tex);
>> +       glActiveTexture(GL_TEXTURE0);
>> +       glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
>> +       glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_FALSE);
>> +       glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
>> +       glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
>> +       glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
>> +       glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
>> +       glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
>> +       glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);
>> +       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
>> +
>> +       for ( face = 0; face<  6; face++) {
>> +            // Set a white colored texture to all the faces of cubemap
>> +            glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_DEPTH_COMPONENT,
>> +                   width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, texDepthData);
>> +       }
>> +
>> +       #undef height
>> +       #undef width
>> +}
>> +
>> +enum piglit_result
>> +piglit_display(void)
>> +{
>> +       GLint loc1;
>> +
>> +       GLboolean pass = GL_TRUE;
>> +       GLfloat white[3] = {1.0, 1.0, 1.0};
>> +       GLenum err;
>> +
>> +       loc1 = glGetUniformLocation(prog, "depthcubeTex");
>> +       glClear(GL_COLOR_BUFFER_BIT);
>> +       glMatrixMode(GL_MODELVIEW);
>> +
>> +       glUniform1i(loc1, 0);
>> +       glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, elements);
>> +       glFinish();
>> +       pass = piglit_probe_pixel_rgb(200, 200, white);
>> +
>> +       err = glGetError();
>> +       switch (err)
>> +       {
>> +       case GL_INVALID_ENUM:
>> +               printf("GL_INVALID_ENUM\n");
>> +               break;
>> +       case GL_INVALID_VALUE:
>> +               printf("GL_INVALID_VALUE\n");
>> +               break;
>> +       case GL_INVALID_OPERATION:
>> +               printf("GL_INVALID_OPERATION\n");
>> +               break;
>> +       case GL_STACK_OVERFLOW:
>> +               printf("GL_STACK_OVERLFOW\n");
>> +               break;
>> +       case GL_STACK_UNDERFLOW:
>> +               printf("GL_STACK_UNDERFLOW\n");
>> +               break;
>> +       case GL_OUT_OF_MEMORY:
>> +               printf("GL_OUT_OF_MEMORY\n");
>> +               break;
>> +
>> +       }
>
> I think there's also a piglit utility for looking up GL error strings like this.
Ok. Thanks for the review comments. I'll soon update the testcase.

-Anuj


More information about the Piglit mailing list