diff options
author | Laura Ekstrand <laura@jlekstrand.net> | 2018-03-27 18:30:55 -0700 |
---|---|---|
committer | Laura Ekstrand <laura@jlekstrand.net> | 2018-03-27 18:30:55 -0700 |
commit | 0ad697127f54719e10a64358d3fa3ec4f8455349 (patch) | |
tree | 583ccdd76583f18800bfeac397c4286be69b5ecd | |
parent | 81507c5001e6b19c9da239372471aceacd8eb5c2 (diff) |
Add shader for comparison.
-rw-r--r-- | tests/spec/gl-1.0/bitmap-heart-dance.c | 81 |
1 files changed, 71 insertions, 10 deletions
diff --git a/tests/spec/gl-1.0/bitmap-heart-dance.c b/tests/spec/gl-1.0/bitmap-heart-dance.c index 444cac847..3cb28d0aa 100644 --- a/tests/spec/gl-1.0/bitmap-heart-dance.c +++ b/tests/spec/gl-1.0/bitmap-heart-dance.c @@ -56,11 +56,10 @@ PIGLIT_GL_TEST_CONFIG_BEGIN config.supports_gl_compat_version = 10; config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA; config.window_width = 900; - config.window_height = 300; + config.window_height = 600; config.khr_no_error_support = PIGLIT_NO_ERRORS; PIGLIT_GL_TEST_CONFIG_END -static GLubyte *refImage; static const float red[3] = {0.502, 0.082, 0.082}; static const float salmon[3] = {1.000, 0.353, 0.353}; static const float pink[3] = {0.945, 0.471, 0.639}; @@ -70,6 +69,68 @@ static const float yellow[3] = {1.000, 0.871, 0.133}; static GLubyte bitmap[8] = { 0x00, 0x10, 0x38, 0x7C, 0xFE, 0xFE, 0xEE, 0x44 }; +static const char *fragShaderText = + "#version 130 \n" + "vec4 red = vec4(0.502, 0.082, 0.082, 1.0); \n" + "vec4 salmon = vec4(1.000, 0.353, 0.353, 1.0); \n" + "vec4 pink = vec4(0.945, 0.471, 0.639, 1.0); \n" + "vec4 orange = vec4(1.000, 0.286, 0.000, 1.0); \n" + "vec4 ltorange = vec4(1.000, 0.514, 0.322, 1.0); \n" + "vec4 yellow = vec4(1.000, 0.871, 0.133, 1.0); \n" + "vec4 black = vec4(0.000, 0.000, 0.000, 1.0); \n" + "int heart[8] = int[](0, 16, 56, 124, 254, 254, 238, 68); \n" + "\n" + "void main() \n" + "{ \n" + " float zoom = 1.0; \n" + " int xorig = 50; \n" + " int yorig = 50; \n" + " int xsp = 48; // Must be > 8. \n" + " int ysp = 40; // Must be > 8. \n" + " int length = 17; \n" + " vec2 fragCoord = gl_FragCoord.xy; \n" + " fragCoord = fragCoord - vec2(xorig, yorig); \n" + " if ((fragCoord.x < 0.0) || (fragCoord.y < 0.0) || \n" + " (fragCoord.x > float(length * xsp)) || \n" + " (fragCoord.y > float((5 * ysp) + 300))) { \n" + " gl_FragColor = black; \n" + " return; \n" + " } \n" + " fragCoord = fragCoord/zoom; \n" + " int i = int(fragCoord.y) % ysp; \n" + " int pointmask = i > 8 ? 0 : heart[i]; \n" + " int j = int(fragCoord.x) % xsp; \n" + " for (int r = 0; r < j; r++) { \n" + " pointmask = pointmask/2; //left shift. \n" + " } \n" + " if (pointmask % 2 == 1) { \n" + " int c = (int(fragCoord.y) - 300 + yorig) / ysp % 6; \n" + " switch (c) { \n" + " case 0: \n" + " gl_FragColor = yellow; \n" + " break; \n" + " case 1: \n" + " gl_FragColor = ltorange; \n" + " break; \n" + " case 2: \n" + " gl_FragColor = orange; \n" + " break; \n" + " case 3: \n" + " gl_FragColor = pink; \n" + " break; \n" + " case 4: \n" + " gl_FragColor = salmon; \n" + " break; \n" + " case 5: \n" + " gl_FragColor = red; \n" + " break; \n" + " } \n" + " } else { \n" + " gl_FragColor = black; \n" + " } \n" + "} \n"; + + static void draw_row(const float* color, int length, int x, int y, int spacex) { @@ -77,21 +138,19 @@ draw_row(const float* color, int length, glRasterPos2f(x, y); for (int i = 0; i < length; i++) { // A line of hearts. - glBitmap(8, 8, 2, 2, 8 + spacex, 0, bitmap); + glBitmap(8, 8, 0, 0, 8 + spacex, 0, bitmap); } } enum piglit_result piglit_display(void) { + // Draw with glBitmap bool pass = true; - unsigned numBytes = piglit_width * piglit_height * 4 * sizeof(GLubyte); int length = 17; int x = 50; int spacing = 40; - refImage = malloc(numBytes); - glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); @@ -106,13 +165,15 @@ piglit_display(void) draw_row(ltorange, length, x, 50 + 1*spacing, spacing); draw_row( yellow, length, x, 50 + 0*spacing, spacing); - glReadPixels(0, 0, piglit_width, piglit_height, - GL_RGBA, GL_UNSIGNED_BYTE, refImage); + // Draw with shader. + GLuint fragShader, program; + fragShader = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fragShaderText); + program = piglit_link_simple_program(0, fragShader); + glUseProgram(program); + piglit_draw_rect(0, piglit_height/2, piglit_width, piglit_height/2); piglit_present_results(); - free(refImage); - return pass ? PIGLIT_PASS : PIGLIT_FAIL; } |