static int TestSparseImageSplit(const IceTImage image) { #define NUM_PARTITIONS 7 IceTVoid *full_sparse_buffer; IceTSparseImage full_sparse; IceTVoid *sparse_partition_buffer[NUM_PARTITIONS]; IceTSparseImage sparse_partition[NUM_PARTITIONS]; IceTSizeType offsets[NUM_PARTITIONS]; IceTVoid *compare_sparse_buffer; IceTSparseImage compare_sparse; IceTSizeType width; IceTSizeType height; IceTSizeType num_partition_pixels; IceTInt partition; width = icetImageGetWidth(image); height = icetImageGetHeight(image); num_partition_pixels = icetSparseImageSplitPartitionNumPixels(width*height, NUM_PARTITIONS, NUM_PARTITIONS); full_sparse_buffer = malloc(icetSparseImageBufferSize(width, height)); full_sparse = icetSparseImageAssignBuffer(full_sparse_buffer,width,height); for (partition = 0; partition < NUM_PARTITIONS; partition++) { sparse_partition_buffer[partition] = malloc(icetSparseImageBufferSize(num_partition_pixels, 1)); sparse_partition[partition] = icetSparseImageAssignBuffer(sparse_partition_buffer[partition], num_partition_pixels, 1); } compare_sparse_buffer = malloc(icetSparseImageBufferSize(num_partition_pixels, 1)); compare_sparse = icetSparseImageAssignBuffer(compare_sparse_buffer, num_partition_pixels, 1); icetCompressImage(image, full_sparse); printf("Spliting image %d times\n", NUM_PARTITIONS); icetSparseImageSplit(full_sparse, 0, NUM_PARTITIONS, NUM_PARTITIONS, sparse_partition, offsets); for (partition = 0; partition < NUM_PARTITIONS; partition++) { IceTInt result; icetCompressSubImage(image, offsets[partition], icetSparseImageGetNumPixels( sparse_partition[partition]), compare_sparse); printf(" Comparing partition %d\n", partition); result = CompareSparseImages(compare_sparse, sparse_partition[partition]); if (result != TEST_PASSED) return result; } printf("Spliting image %d times with first partition in place.\n", NUM_PARTITIONS); sparse_partition[0] = full_sparse; icetSparseImageSplit(full_sparse, 0, NUM_PARTITIONS, NUM_PARTITIONS, sparse_partition, offsets); for (partition = 0; partition < NUM_PARTITIONS; partition++) { IceTInt result; icetCompressSubImage(image, offsets[partition], icetSparseImageGetNumPixels( sparse_partition[partition]), compare_sparse); printf(" Comparing partition %d\n", partition); result = CompareSparseImages(compare_sparse, sparse_partition[partition]); if (result != TEST_PASSED) return result; } free(full_sparse_buffer); for (partition = 0; partition < NUM_PARTITIONS; partition++) { free(sparse_partition_buffer[partition]); } free(compare_sparse_buffer); return TEST_PASSED; #undef NUM_PARTITIONS }
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 TestInterlaceSplit(const IceTImage image) { #define NUM_PARTITIONS 13 IceTVoid *original_sparse_buffer; IceTSparseImage original_sparse; IceTVoid *interlaced_sparse_buffer; IceTSparseImage interlaced_sparse; IceTVoid *sparse_partition_buffer[NUM_PARTITIONS]; IceTSparseImage sparse_partition[NUM_PARTITIONS]; IceTSizeType offsets[NUM_PARTITIONS]; IceTVoid *reconstruction_buffer; IceTImage reconstruction; IceTSizeType width; IceTSizeType height; IceTSizeType num_partition_pixels; IceTInt partition; width = icetImageGetWidth(image); height = icetImageGetHeight(image); num_partition_pixels = icetSparseImageSplitPartitionNumPixels(width*height, NUM_PARTITIONS, NUM_PARTITIONS); original_sparse_buffer = malloc(icetSparseImageBufferSize(width, height)); original_sparse = icetSparseImageAssignBuffer(original_sparse_buffer, width, height); interlaced_sparse_buffer = malloc(icetSparseImageBufferSize(width, height)); interlaced_sparse = icetSparseImageAssignBuffer(interlaced_sparse_buffer, width, height); for (partition = 0; partition < NUM_PARTITIONS; partition++) { sparse_partition_buffer[partition] = malloc(icetSparseImageBufferSize(num_partition_pixels, 1)); sparse_partition[partition] = icetSparseImageAssignBuffer(sparse_partition_buffer[partition], num_partition_pixels, 1); } reconstruction_buffer = malloc(icetImageBufferSize(width, height)); reconstruction = icetImageAssignBuffer(reconstruction_buffer,width,height); icetCompressImage(image, original_sparse); printf("Interlacing image for %d pieces\n", NUM_PARTITIONS); icetSparseImageInterlace(original_sparse, NUM_PARTITIONS, ICET_SI_STRATEGY_BUFFER_0, interlaced_sparse); printf("Splitting image %d times\n", NUM_PARTITIONS); icetSparseImageSplit(interlaced_sparse, 0, NUM_PARTITIONS, NUM_PARTITIONS, sparse_partition, offsets); printf("Reconstructing image.\n"); for (partition = 0; partition < NUM_PARTITIONS; partition++) { IceTSizeType real_offset = icetGetInterlaceOffset(partition, NUM_PARTITIONS, width*height); icetDecompressSubImage(sparse_partition[partition], real_offset, reconstruction); } if (!CompareImageColors(image, reconstruction)) { return TEST_FAILED; } if (!CompareImageDepths(image, reconstruction)) { return TEST_FAILED; } free(original_sparse_buffer); free(interlaced_sparse_buffer); for (partition = 0; partition < NUM_PARTITIONS; partition++) { free(sparse_partition_buffer[partition]); } free(reconstruction_buffer); return TEST_PASSED; }
static int BlankTilesDoTest(void) { int result = TEST_PASSED; int tile_dim; IceTInt rank, num_proc; icetGetIntegerv(ICET_RANK, &rank); icetGetIntegerv(ICET_NUM_PROCESSES, &num_proc); for (tile_dim = 1; tile_dim*tile_dim <= num_proc; tile_dim++) { int x, y; IceTSizeType my_width = -1; IceTSizeType my_height = -1; IceTImage image; printstat("\nRunning on a %d x %d display.\n", tile_dim, tile_dim); icetResetTiles(); for (y = 0; y < tile_dim; y++) { for (x = 0; x < tile_dim; x++) { int tile_rank = y*tile_dim + x; /* Modify the width and height a bit to detect bad image sizes. */ IceTSizeType tile_width = SCREEN_WIDTH - x; IceTSizeType tile_height = SCREEN_HEIGHT - y; icetAddTile((IceTInt)(x*SCREEN_WIDTH), (IceTInt)(y*SCREEN_HEIGHT), tile_width, tile_height, tile_rank); if (tile_rank == rank) { my_width = tile_width; my_height = tile_height; } } } printstat("Rendering frame.\n"); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1, tile_dim*2-1, -1, tile_dim*2-1, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); image = icetGLDrawFrame(); swap_buffers(); if (rank == 0) { /* printrank("Rank == 0, tile should have stuff in it.\n"); */ } else if (rank < tile_dim*tile_dim) { IceTFloat *cb; int color_component; if ( (my_width != icetImageGetWidth(image)) || (my_height != icetImageGetHeight(image)) ) { printrank("Image size is wrong!!!!!!!!!\n"); result = TEST_FAILED; } /* printrank("Checking returned image data.\n"); */ cb = icetImageGetColorf(image); for (color_component = 0; color_component < my_width*my_height*4; color_component++) { if (cb[color_component] != 0.25f) { printrank("Found bad pixel!!!!!!!!\n"); result = TEST_FAILED; break; } } } else { /* printrank("Not a display node. Not testing image.\n"); */ } } return result; }
static void BackgroundCorrectDraw(const IceTDouble *projection_matrix, const IceTDouble *modelview_matrix, const IceTFloat *background_color, const IceTInt *readback_viewport, IceTImage result) { IceTDouble full_transform[16]; IceTSizeType width; IceTSizeType height; IceTFloat *colors; IceTFloat blended_color[4]; /* This is mostly done for completeness. Because we are blending and correcting the color, we totally expect background_color to be all zeros, and therefore blended_color should be equal to g_foreground_color. The real blending will happen within IceT under the covers. */ ICET_BLEND_FLOAT(g_foreground_color, background_color, blended_color); width = icetImageGetWidth(result); height = icetImageGetHeight(result); colors = icetImageGetColorf(result); /* Get full transform all the way to window coordinates (pixels). */ { IceTDouble scale_transform[16]; IceTDouble translate_transform[16]; icetMatrixScale(0.5*width, 0.5*height, 0.5, scale_transform); icetMatrixTranslate(1.0, 1.0, 1.0, translate_transform); icetMatrixMultiply(full_transform,scale_transform,translate_transform); icetMatrixPostMultiply(full_transform, projection_matrix); icetMatrixPostMultiply(full_transform, modelview_matrix); } /* Clear out the image (testing purposes only). */ { IceTSizeType pixel; for (pixel = 0; pixel < width*height; pixel++) { colors[pixel] = -1.0; } } /* Set my pixels. */ { IceTInt rank; IceTSizeType region_y_start; IceTSizeType region_x; IceTSizeType region_y; icetGetIntegerv(ICET_RANK, &rank); region_y_start = rank*PROC_REGION_HEIGHT; for (region_y = 0; region_y < PROC_REGION_HEIGHT; region_y++) { for (region_x = 0; region_x < PROC_REGION_WIDTH; region_x++) { IceTDouble object_coord[4]; IceTDouble window_coord[4]; IceTSizeType window_pixel[2]; IceTSizeType readback_lower[2]; IceTSizeType readback_upper[2]; IceTBoolean in_readback; object_coord[0] = (IceTDouble)region_x; object_coord[1] = (IceTDouble)(region_y + region_y_start); object_coord[2] = 0.0; object_coord[3] = 1.0; icetMatrixVectorMultiply(window_coord, full_transform, object_coord); window_pixel[0]=(IceTSizeType)(window_coord[0]/window_coord[3]); window_pixel[1]=(IceTSizeType)(window_coord[1]/window_coord[3]); readback_lower[0] = readback_viewport[0]; readback_lower[1] = readback_viewport[1]; readback_upper[0] = readback_viewport[0] + readback_viewport[2]; readback_upper[1] = readback_viewport[1] + readback_viewport[3]; in_readback = (readback_lower[0] <= window_pixel[0]); in_readback &= (readback_lower[1] <= window_pixel[1]); in_readback &= (window_pixel[0] < readback_upper[0]); in_readback &= (window_pixel[1] < readback_upper[1]); if (in_readback) { IceTSizeType pixel_idx = window_pixel[0] + window_pixel[1]*PROC_REGION_WIDTH; colors[4*pixel_idx + 0] = blended_color[0]; colors[4*pixel_idx + 1] = blended_color[1]; colors[4*pixel_idx + 2] = blended_color[2]; colors[4*pixel_idx + 3] = blended_color[3]; } } } } }