/* Fills the given image to have data in the lower triangle like this: * * +-------------+ * | \ | * | \ | * | \ | * | \ | * | \ | * +-------------+ * * Where the lower half is filled with data and the upper half is background. */ static void LowerTriangleImage(IceTImage image) { IceTSizeType width = icetImageGetWidth(image); IceTSizeType height = icetImageGetHeight(image); IceTSizeType x, y; if (icetImageGetColorFormat(image) == ICET_IMAGE_COLOR_RGBA_UBYTE) { IceTUInt *data = icetImageGetColorui(image); for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { if ((height-y) < x) { data[0] = ACTIVE_COLOR(x, y); } else { data[0] = 0; } data++; } } } else if (icetImageGetColorFormat(image) == ICET_IMAGE_COLOR_RGBA_FLOAT) { IceTFloat *data = icetImageGetColorf(image); for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { if ((height-y) < x) { data[0] = (float)x; data[1] = (float)y; data[2] = 0.0; data[3] = 1.0; } else { data[0] = data[1] = data[2] = data[3] = 0.0; } data += 4; } } } else if (icetImageGetColorFormat(image) == ICET_IMAGE_COLOR_NONE) { /* Do nothing. */ } else { printf("ERROR: Encountered unknown color format."); } if (icetImageGetDepthFormat(image) == ICET_IMAGE_DEPTH_FLOAT) { IceTFloat *data = icetImageGetDepthf(image); for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { if ((height-y) < x) { data[0] = ACTIVE_DEPTH(x, y); } else { data[0] = 0.0; } data++; } } } else if (icetImageGetDepthFormat(image) == ICET_IMAGE_DEPTH_NONE) { /* Do nothing. */ } else { printf("ERROR: Encountered unknown depth format."); } }
static int CompareSparseImages(const IceTSparseImage image0, const IceTSparseImage image1) { IceTSizeType width; IceTSizeType height; IceTVoid *image_buffer[2]; IceTImage image[2]; IceTUInt *color_buffer[2]; IceTSizeType i; if ( icetSparseImageGetCompressedBufferSize(image0) != icetSparseImageGetCompressedBufferSize(image1) ) { printf("Buffer sizes do not match: %d vs %d!\n", icetSparseImageGetCompressedBufferSize(image0), icetSparseImageGetCompressedBufferSize(image1)); return TEST_FAILED; } width = icetSparseImageGetWidth(image1); height = icetSparseImageGetHeight(image1); image_buffer[0] = malloc(icetImageBufferSize(width, height)); image[0] = icetImageAssignBuffer(image_buffer[0], width, height); icetDecompressImage(image0, image[0]); color_buffer[0] = icetImageGetColorui(image[0]); image_buffer[1] = malloc(icetImageBufferSize(width, height)); image[1] = icetImageAssignBuffer(image_buffer[1], width, height); icetDecompressImage(image1, image[1]); color_buffer[1] = icetImageGetColorui(image[1]); for (i = 0; i < width*height; i++) { if (color_buffer[0][i] != color_buffer[1][i]) { printf("Buffer mismatch at uint %d\n", i); printf("0x%x vs 0x%x\n", color_buffer[0][i], color_buffer[1][i]); return TEST_FAILED; } } return TEST_PASSED; }
/* Fills the given image to have data in the upper triangle like this: * * +-------------+ * | \ | * | \ | * | \ | * | \ | * | \ | * +-------------+ * * Where the upper half is filled with data and the upper half is background. */ static void UpperTriangleImage(IceTImage image) { IceTUInt *data = icetImageGetColorui(image); IceTSizeType width = icetImageGetWidth(image); IceTSizeType height = icetImageGetHeight(image); IceTSizeType x, y; for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { if ((height-y) < x) { data[0] = ACTIVE_COLOR(x, y); } else { data[0] = 0; } data++; } } }
void icetGLDrawCallbackFunction(const IceTDouble *projection_matrix, const IceTDouble *modelview_matrix, const IceTFloat *background_color, const IceTInt *readback_viewport, IceTImage result) { IceTSizeType width = icetImageGetWidth(result); IceTSizeType height = icetImageGetHeight(result); GLint gl_viewport[4]; glGetIntegerv(GL_VIEWPORT, gl_viewport); /* Check OpenGL state. */ { if ((gl_viewport[2] != width) || (gl_viewport[3] != height)) { icetRaiseError("OpenGL viewport different than expected." " Was it changed?", ICET_SANITY_CHECK_FAIL); } } /* Set up OpenGL. */ { /* Load the matrices. */ glMatrixMode(GL_PROJECTION); glLoadMatrixd(projection_matrix); glMatrixMode(GL_MODELVIEW); glLoadMatrixd(modelview_matrix); /* Set the clear color as the background IceT currently wants. */ glClearColor(background_color[0], background_color[1], background_color[2], background_color[3]); } /* Call the rendering callback. */ { IceTVoid *value; IceTGLDrawCallbackType callback; icetRaiseDebug("Calling OpenGL draw function."); icetGetPointerv(ICET_GL_DRAW_FUNCTION, &value); callback = (IceTGLDrawCallbackType)value; (*callback)(); } /* Temporarily stop render time while reading back buffer. */ icetTimingRenderEnd(); icetTimingBufferReadBegin(); /* Read the OpenGL buffers. */ { IceTEnum color_format = icetImageGetColorFormat(result); IceTEnum depth_format = icetImageGetDepthFormat(result); IceTEnum readbuffer; IceTSizeType x_offset = gl_viewport[0] + readback_viewport[0]; IceTSizeType y_offset = gl_viewport[1] + readback_viewport[1]; glPixelStorei(GL_PACK_ROW_LENGTH, (GLint)icetImageGetWidth(result)); /* These pixel store parameters are not working on one of the platforms * I am testing on (thank you Mac). Instead of using these, just offset * the buffers we read in from. */ /* glPixelStorei(GL_PACK_SKIP_PIXELS, readback_viewport[0]); */ /* glPixelStorei(GL_PACK_SKIP_ROWS, readback_viewport[1]); */ icetGetEnumv(ICET_GL_READ_BUFFER, &readbuffer); glReadBuffer(readbuffer); if (color_format == ICET_IMAGE_COLOR_RGBA_UBYTE) { IceTUInt *colorBuffer = icetImageGetColorui(result); glReadPixels((GLint)x_offset, (GLint)y_offset, (GLsizei)readback_viewport[2], (GLsizei)readback_viewport[3], GL_RGBA, GL_UNSIGNED_BYTE, colorBuffer + ( readback_viewport[0] + width*readback_viewport[1])); } else if (color_format == ICET_IMAGE_COLOR_RGBA_FLOAT) { IceTFloat *colorBuffer = icetImageGetColorf(result); glReadPixels((GLint)x_offset, (GLint)y_offset, (GLsizei)readback_viewport[2], (GLsizei)readback_viewport[3], GL_RGBA, GL_FLOAT, colorBuffer + 4*( readback_viewport[0] + width*readback_viewport[1])); } else if (color_format != ICET_IMAGE_COLOR_NONE) { icetRaiseError("Invalid color format.", ICET_SANITY_CHECK_FAIL); } if (depth_format == ICET_IMAGE_DEPTH_FLOAT) { IceTFloat *depthBuffer = icetImageGetDepthf(result);; glReadPixels((GLint)x_offset, (GLint)y_offset, (GLsizei)readback_viewport[2], (GLsizei)readback_viewport[3], GL_DEPTH_COMPONENT, GL_FLOAT, depthBuffer + ( readback_viewport[0] + width*readback_viewport[1])); } else if (depth_format != ICET_IMAGE_DEPTH_NONE) { icetRaiseError("Invalid depth format.", ICET_SANITY_CHECK_FAIL); } glPixelStorei(GL_PACK_ROW_LENGTH, 0); /* glPixelStorei(GL_PACK_SKIP_PIXELS, 0); */ /* glPixelStorei(GL_PACK_SKIP_ROWS, 0); */ } icetTimingBufferReadEnd(); /* Start render timer again. It's going to be shut off immediately on return anyway, but the calling function expects it to be running. */ icetTimingRenderBegin(); }
static int BoundsBehindViewerRun() { float mat[16]; IceTImage image; IceTInt rank; icetGetIntegerv(ICET_RANK, &rank); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); icetGLDrawCallback(draw); icetStrategy(ICET_STRATEGY_REDUCE); icetBoundingBoxd(-1.0, 1.0, -1.0, 1.0, -0.0, 0.0); icetSetColorFormat(ICET_IMAGE_COLOR_RGBA_UBYTE); icetSetDepthFormat(ICET_IMAGE_DEPTH_FLOAT); /* We're just going to use one tile. */ icetResetTiles(); icetAddTile(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0); /* Set up the transformation such that the quad in draw should cover the entire screen, but part of it extends behind the viewpoint. Furthermore, a naive division by w will show all points to the right of the screen (which, of course, is wrong). */ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslated(0.0, 0.0, -1.5); glRotated(10.0, 0.0, 1.0, 0.0); glScaled(10.0, 10.0, 10.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 2.0); printstat("Modelview matrix:\n"); glGetFloatv(GL_MODELVIEW_MATRIX, mat); PrintMatrix(mat); printstat("Projection matrix:\n"); glGetFloatv(GL_PROJECTION_MATRIX, mat); PrintMatrix(mat); /* Other normal OpenGL setup. */ glEnable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glColor3d(1.0, 1.0, 1.0); /* All the processes have the same data. Go ahead and tell IceT. */ icetDataReplicationGroupColor(0); image = icetGLDrawFrame(); /* Test the resulting image to make sure the polygon was drawn over it. */ if (rank == 0) { IceTUInt *cb = icetImageGetColorui(image); if (cb[0] != 0xFFFFFFFF) { printstat("First pixel in color buffer wrong: 0x%x\n", cb[0]); return TEST_FAILED; } } return TEST_PASSED; }