bool API2Test::testShaderAttribs(void) { static const char *vertShaderText = "attribute vec4 generic; \n" "void main() { \n" " gl_Position = ftransform(); \n" " gl_FrontColor = generic; \n" "} \n"; GLuint vertShader, program; vertShader = loadAndCompileShader(GL_VERTEX_SHADER, vertShaderText); if (!vertShader) { return false; } program = createProgram(vertShader, 0); if (!program) { REPORT_FAILURE("glCreateProgram (uniform test) failed"); return false; } glUseProgram_func(program); static const GLfloat testColors[3][4] = { { 1.0, 0.5, 0.25, 0.0 }, { 0.0, 0.1, 0.2, 0.3 }, { 0.5, 0.6, 0.7, 0.8 }, }; // let compiler allocate the attribute location const GLint attr = glGetAttribLocation_func(program, "generic"); if (attr < 0) { REPORT_FAILURE("glGetAttribLocation failed"); return false; } for (int i = 0; i < 3; i++) { GLfloat pixel[4]; renderQuadWithArrays(attr, testColors[i], pixel); if (!equalColors(pixel, testColors[i])) { #if 0 printf("Expected color %f %f %f\n", testColors[i][0], testColors[i][1], testColors[i][2]); printf("Found color %f %f %f\n", pixel[0], pixel[1], pixel[2]); #endif REPORT_FAILURE("Vertex array test failed"); return false; } } // Test explicit attribute binding. const GLint bindAttr = 6; // XXX a non-colliding alias glBindAttribLocation_func(program, bindAttr, "generic"); glLinkProgram_func(program); GLint loc = glGetAttribLocation_func(program, "generic"); if (loc != bindAttr) { REPORT_FAILURE("glBindAttribLocation failed"); return false; } for (int i = 0; i < 3; i++) { GLfloat pixel[4]; renderQuadWithArrays(bindAttr, testColors[i], pixel); if (!equalColors(pixel, testColors[i])) { REPORT_FAILURE("Vertex array test failed (2)"); return false; } } return true; }
bool API2Test::testUniformiFuncs(void) { static const char *fragShaderText = "uniform int ui1; \n" "uniform ivec2 ui2; \n" "uniform ivec3 ui3; \n" "uniform ivec4 ui4; \n" "void main() { \n" " gl_FragColor = vec4(ui1, ui2.y, ui3.z, ui4.w) * 0.1; \n" "} \n"; GLuint fragShader, program; GLint ui1, ui2, ui3, ui4; fragShader = loadAndCompileShader(GL_FRAGMENT_SHADER, fragShaderText); if (!fragShader) { return false; } program = createProgram(0, fragShader); if (!program) { REPORT_FAILURE("glCreateProgram (uniform test) failed"); return false; } glUseProgram_func(program); ui1 = glGetUniformLocation_func(program, "ui1"); if (ui1 < 0) { REPORT_FAILURE("glGetUniform \"ui1\" failed"); return false; } ui2 = glGetUniformLocation_func(program, "ui2"); if (ui2 < 0) { REPORT_FAILURE("glGetUniform \"ui2\" failed"); return false; } ui3 = glGetUniformLocation_func(program, "ui3"); if (ui3 < 0) { REPORT_FAILURE("glGetUniform \"ui3\" failed"); return false; } ui4 = glGetUniformLocation_func(program, "ui4"); if (ui4 < 0) { REPORT_FAILURE("glGetUniform \"ui4\" failed"); return false; } GLfloat pixel[4], expected[4]; GLint expectedInt[4]; // Test glUniform[1234]i() expectedInt[0] = 1; expectedInt[1] = 2; expectedInt[2] = 3; expectedInt[3] = 4; expected[0] = 0.1; expected[1] = 0.2; expected[2] = 0.3; expected[3] = 0.4; glUniform1i_func(ui1, expectedInt[0]); glUniform2i_func(ui2, 0, expectedInt[1]); glUniform3i_func(ui3, 0, 0, expectedInt[2]); glUniform4i_func(ui4, 0, 0, 0, expectedInt[3]); renderQuad(pixel); if (!equalColors(pixel, expected)) { REPORT_FAILURE("glUniform[1234]i failed"); //printf("%f %f %f %f\n", pixel[0], pixel[1], pixel[2], pixel[3]); return false; } // Test glUniform[1234]iv() GLint u[4]; expectedInt[0] = 9; expectedInt[1] = 8; expectedInt[2] = 7; expectedInt[3] = 6; expected[0] = 0.9; expected[1] = 0.8; expected[2] = 0.7; expected[3] = 0.6; u[0] = expectedInt[0]; glUniform1iv_func(ui1, 1, u); u[0] = 0; u[1] = expectedInt[1]; glUniform2iv_func(ui2, 1, u); u[0] = 0; u[1] = 0; u[2] = expectedInt[2]; glUniform3iv_func(ui3, 1, u); u[0] = 0; u[1] = 0; u[2] = 0; u[3] = expectedInt[3]; glUniform4iv_func(ui4, 1, u); renderQuad(pixel); if (!equalColors(pixel, expected)) { REPORT_FAILURE("glUniform[1234]i failed"); #if 0 printf("Expected color %f %f %f %f\n", expected[0], expected[1], expected[2], expected[3]); printf("Found color %f %f %f %f\n", pixel[0], pixel[1], pixel[2], pixel[3]); #endif return false; } return true; }
bool VertexProgramTest::testProgram(const VertexProgram &p) { const GLfloat r = 0.25; glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(p.progString), (const GLubyte *) p.progString); GLenum err = glGetError(); if (err) { GLint errorPos; glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorPos); env->log << "OpenGL error " << (int) err << "\n"; env->log << "Invalid Vertex Program:\n"; env->log << p.progString; env->log << "Error position: " << errorPos << "\n"; env->log << "Error message: " << glGetString(GL_PROGRAM_ERROR_STRING_ARB) << "\n"; return false; } // to avoid potential issue with undefined result.depth.z if (p.expectedZ == DONT_CARE_Z) glDisable(GL_DEPTH_TEST); else glEnable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBegin(GL_POLYGON); glTexCoord2f(0, 0); glVertex2f(-r, -r); glTexCoord2f(1, 0); glVertex2f( r, -r); glTexCoord2f(1, 1); glVertex2f( r, r); glTexCoord2f(0, 1); glVertex2f(-r, r); glEnd(); GLfloat pixel[4]; glReadPixels(windowSize / 2, windowSize / 2, 1, 1, GL_RGBA, GL_FLOAT, pixel); if (0) // debug printf("%s: Expect: %.3f %.3f %.3f %.3f found: %.3f %.3f %.3f %.3f\n", p.name, p.expectedColor[0], p.expectedColor[1], p.expectedColor[2], p.expectedColor[3], pixel[0], pixel[1], pixel[2], pixel[3]); if (!equalColors(pixel, p.expectedColor, p.flags)) { reportFailure(p.name, p.expectedColor, pixel); return false; } if (p.expectedZ != DONT_CARE_Z) { GLfloat z; glReadPixels(windowSize / 2, windowSize / 2, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z); if (!equalDepth(z, p.expectedZ)) { reportZFailure(p.name, p.expectedZ, z); return false; } } if (0) // debug printf("%s passed\n", p.name); return true; }
bool API2Test::testUniformfFuncs(void) { static const char *fragShaderText = "uniform float uf1; \n" "uniform vec2 uf2; \n" "uniform vec3 uf3; \n" "uniform vec4 uf4; \n" "void main() { \n" " gl_FragColor = vec4(uf1, uf2.y, uf3.z, uf4.w); \n" "} \n"; GLuint fragShader, program; GLint uf1, uf2, uf3, uf4; GLfloat value[4]; fragShader = loadAndCompileShader(GL_FRAGMENT_SHADER, fragShaderText); if (!fragShader) { return false; } program = createProgram(0, fragShader); if (!program) { REPORT_FAILURE("glCreateProgram (uniform test) failed"); return false; } glUseProgram_func(program); uf1 = glGetUniformLocation_func(program, "uf1"); if (uf1 < 0) { REPORT_FAILURE("glGetUniform \"uf1\" failed"); return false; } uf2 = glGetUniformLocation_func(program, "uf2"); if (uf2 < 0) { REPORT_FAILURE("glGetUniform \"uf2\" failed"); return false; } uf3 = glGetUniformLocation_func(program, "uf3"); if (uf3 < 0) { REPORT_FAILURE("glGetUniform \"uf3\" failed"); return false; } uf4 = glGetUniformLocation_func(program, "uf4"); if (uf4 < 0) { REPORT_FAILURE("glGetUniform \"uf4\" failed"); return false; } GLfloat pixel[4], expected[4]; // Test glUniform[1234]f() expected[0] = 0.1; expected[1] = 0.2; expected[2] = 0.3; expected[3] = 0.4; glUniform1f_func(uf1, expected[0]); glUniform2f_func(uf2, 0.0, expected[1]); glUniform3f_func(uf3, 0.0, 0.0, expected[2]); glUniform4f_func(uf4, 0.0, 0.0, 0.0, expected[3]); renderQuad(pixel); if (!equalColors(pixel, expected)) { REPORT_FAILURE("glUniform[1234]f failed"); //printf("found: %f %f %f %f\n", pixel[0], pixel[1], pixel[2], pixel[3]); //printf("expected: %f %f %f %f\n", expected[0], expected[1], expected[2], expected[3]); return false; } // Test glUniform[1234]fv() GLfloat u[4]; expected[0] = 0.9; expected[1] = 0.8; expected[2] = 0.7; expected[3] = 0.6; u[0] = expected[0]; glUniform1fv_func(uf1, 1, u); u[0] = 0.0; u[1] = expected[1]; glUniform2fv_func(uf2, 1, u); u[0] = 0.0; u[1] = 0.0; u[2] = expected[2]; glUniform3fv_func(uf3, 1, u); u[0] = 0.0; u[1] = 0.0; u[2] = 0.0; u[3] = expected[3]; glUniform4fv_func(uf4, 1, u); renderQuad(pixel); if (!equalColors(pixel, expected)) { REPORT_FAILURE("glUniform[1234]f failed"); return false; } // Test glGetUniformfv glUniform4fv_func(uf4, 1, expected); glGetUniformfv_func(program, uf4, value); if (value[0] != expected[0] || value[1] != expected[1] || value[2] != expected[2] || value[3] != expected[3]) { REPORT_FAILURE("glGetUniformfv failed"); return false; } return true; }
// The initial color of the text. void PaintText::setColor(const GFXColor& c) { if(!equalColors(m_color,c)) { m_color = c; m_needLayout = true; } }