void icetResizeBuffer(int size) { /* Add some padding in case the user's data does not lie on byte boundries. */ size += 32*sizeof(IceTInt64); if (icet_current_context->buffer_size < size) { free(icet_current_context->buffer); icet_current_context->buffer = malloc(size); if (icet_current_context->buffer == NULL) { icetRaiseError("Could not allocate more buffer space", ICET_OUT_OF_MEMORY); /* Try to back out of change. */ icet_current_context->buffer = malloc(icet_current_context->buffer_size); if (icet_current_context->buffer == NULL) { icetRaiseError("Could not back out of memory change", ICET_OUT_OF_MEMORY); icet_current_context->buffer_size = 0; } } else { icet_current_context->buffer_size = size; } } icet_current_context->buffer_offset = 0; /* The color and depth buffers rely on this memory pool, so we have probably just invalidated them. */ icetStateSetBoolean(ICET_COLOR_BUFFER_VALID, 0); icetStateSetBoolean(ICET_DEPTH_BUFFER_VALID, 0); }
static void stateCheck(IceTEnum pname, const IceTState state) { if (state[pname].type != ICET_NULL) { if (state[pname].num_entries > 0) { IceTSizeType i; IceTByte *padding; padding = STATE_DATA_PRE_PADDING(pname, state); for (i = 0; i < STATE_PADDING_SIZE; i++) { if (padding[i] != g_pre_padding[i]) { char message[256]; sprintf(message, "Lower buffer overrun detected in " " state variable 0x%X", pname); icetRaiseError(message, ICET_SANITY_CHECK_FAIL); } } padding = STATE_DATA_POST_PADDING(pname, state); for (i = 0; i < STATE_PADDING_SIZE; i++) { if (padding[i] != g_post_padding[i]) { char message[256]; sprintf(message, "Upper buffer overrun detected in " " state variable 0x%X", pname); icetRaiseError(message, ICET_SANITY_CHECK_FAIL); } } } else { if (state[pname].data != NULL) { char message[256]; sprintf(message, "State variable 0x%X has zero entries but" " non-null pointer.", pname); icetRaiseError(message, ICET_SANITY_CHECK_FAIL); } } } else { /* state[pname].type == ICET_NULL */ if (state[pname].data != NULL) { char message[256]; sprintf(message, "State variable 0x%X has ICET_NULL type but" " non-null pointer.", pname); icetRaiseError(message, ICET_SANITY_CHECK_FAIL); } if (state[pname].num_entries != 0) { char message[256]; sprintf(message, "State variable 0x%X has ICET_NULL type but" " also has %d entries (!= 0).", pname, (int)state[pname].num_entries); icetRaiseError(message, ICET_SANITY_CHECK_FAIL); } } }
static IceTImage drawInvokeStrategy(void) { IceTImage image; IceTVoid *value; IceTEnum strategy; IceTInt display_tile; IceTInt valid_tile; icetGetPointerv(ICET_DRAW_FUNCTION, &value); if (value == NULL) { icetRaiseError("Drawing function not set. Call icetDrawCallback.", ICET_INVALID_OPERATION); return icetImageNull(); } icetRaiseDebug("Calling strategy"); icetStateSetBoolean(ICET_IS_DRAWING_FRAME, 1); icetGetEnumv(ICET_STRATEGY, &strategy); image = icetInvokeStrategy(strategy); icetStateSetBoolean(ICET_IS_DRAWING_FRAME, 0); /* Ensure that the returned image is the expected size. */ icetGetIntegerv(ICET_VALID_PIXELS_TILE, &valid_tile); icetGetIntegerv(ICET_TILE_DISPLAYED, &display_tile); if ((valid_tile != display_tile) && icetIsEnabled(ICET_COLLECT_IMAGES)) { icetRaiseDebug2("Display tile: %d, valid tile: %d", display_tile, valid_tile); icetRaiseError("Got unexpected tile from strategy.", ICET_SANITY_CHECK_FAIL); } if (valid_tile >= 0) { const IceTInt *valid_tile_viewport = icetUnsafeStateGetInteger(ICET_TILE_VIEWPORTS) + 4*valid_tile; if ( (valid_tile_viewport[2] != icetImageGetWidth(image)) || (valid_tile_viewport[3] != icetImageGetHeight(image)) ) { IceTInt valid_offset; IceTInt valid_num; icetRaiseDebug1("Tile returned from strategy: %d\n", valid_tile); icetRaiseDebug4("Expected size: %d %d. Returned size: %d %d", valid_tile_viewport[2], valid_tile_viewport[3], (int)icetImageGetWidth(image), (int)icetImageGetHeight(image)); icetGetIntegerv(ICET_VALID_PIXELS_OFFSET, &valid_offset); icetGetIntegerv(ICET_VALID_PIXELS_NUM, &valid_num); icetRaiseDebug2("Reported pixel offset: %d. Reported pixel count: %d", valid_offset, valid_num); icetRaiseError("Got unexpected image size from strategy.", ICET_SANITY_CHECK_FAIL); } } icetStateCheckMemory(); return image; }
void icetBoundingVertices(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer) { GLdouble *verts; int i, j; if (stride < 1) { switch (type) { case ICET_SHORT: stride = size*sizeof(GLshort); break; case ICET_INT: stride = size*sizeof(GLint); break; case ICET_FLOAT: stride = size*sizeof(GLfloat); break; case ICET_DOUBLE: stride = size*sizeof(GLdouble); break; default: icetRaiseError("Bad type to icetBoundingVertices.", ICET_INVALID_VALUE); return; } } verts = malloc(count*3*sizeof(GLdouble)); for (i = 0; i < count; i++) { for (j = 0; j < 3; j++) { switch (type) { #define castcopy(ptype) \ if (j < size) { \ verts[i*3+j] = ((ptype *)pointer)[i*stride/sizeof(type)+j]; \ } else { \ verts[i*3+j] = 0.0; \ } \ if (size >= 4) { \ verts[i*3+j] /= ((ptype *)pointer)[i*stride/sizeof(type)+4]; \ } \ break; case ICET_SHORT: castcopy(GLshort); case ICET_INT: castcopy(GLint); case ICET_FLOAT: castcopy(GLfloat); case ICET_DOUBLE: castcopy(GLdouble); default: icetRaiseError("Bad type to icetBoundingVertices.", ICET_INVALID_VALUE); free(verts); return; } } } icetUnsafeStateSet(ICET_GEOMETRY_BOUNDS, count*3, ICET_DOUBLE, verts); icetStateSetInteger(ICET_NUM_BOUNDING_VERTS, count); }
void icetGetPointerv(GLenum pname, GLvoid **params) { struct IceTStateValue *value = icetGetState() + pname; int i; if (value->type == ICET_NULL) { char msg[256]; sprintf(msg, "No such parameter, 0x%x.", (int)pname); icetRaiseError(msg, ICET_INVALID_ENUM); } if (value->type != ICET_POINTER) { char msg[256]; sprintf(msg, "Could not cast value for 0x%x.", (int)pname); icetRaiseError(msg, ICET_BAD_CAST); } copyArrayGivenCType(GLvoid *, params, GLvoid *, value->data, value->size); }
void icetSetContext(IceTContext context) { if (context && (context->magic_number != CONTEXT_MAGIC_NUMBER)) { icetRaiseError("Invalid context.", ICET_INVALID_VALUE); return; } icet_current_context = context; }
void icetSingleImageStrategy(IceTEnum strategy) { if (icetSingleImageStrategyValid(strategy)) { icetStateSetInteger(ICET_SINGLE_IMAGE_STRATEGY, strategy); } else { icetRaiseError("Invalid single image strategy.", ICET_INVALID_ENUM); } }
void icetDisable(IceTEnum pname) { if ((pname < ICET_STATE_ENABLE_START) || (pname >= ICET_STATE_ENABLE_END)) { icetRaiseError("Bad value to icetDisable", ICET_INVALID_VALUE); return; } icetStateSetBoolean(pname, ICET_FALSE); }
void icetStrategy(IceTEnum strategy) { if (icetStrategyValid(strategy)) { icetStateSetInteger(ICET_STRATEGY, strategy); icetStateSetBoolean(ICET_STRATEGY_SUPPORTS_ORDERING, icetStrategySupportsOrdering(strategy)); } else { icetRaiseError("Invalid strategy.", ICET_INVALID_ENUM); } }
void icetCompositeMode(IceTEnum mode) { if ( (mode != ICET_COMPOSITE_MODE_Z_BUFFER) && (mode != ICET_COMPOSITE_MODE_BLEND) ) { icetRaiseError("Invalid composite mode.", ICET_INVALID_ENUM); return; } icetStateSetInteger(ICET_COMPOSITE_MODE, mode); }
void icetGLSetReadBuffer(GLenum mode) { if (!icetGLIsInitialized()) { icetRaiseError("IceT OpenGL layer not initialized." " Call icetGLInitialize.", ICET_INVALID_OPERATION); return; } if ( (mode == GL_FRONT_LEFT) || (mode == GL_FRONT_RIGHT) || (mode == GL_BACK_LEFT) || (mode == GL_BACK_RIGHT) || (mode == GL_FRONT) || (mode == GL_BACK) || (mode == GL_LEFT) || (mode == GL_RIGHT) || ((mode >= GL_AUX0) && (mode < GL_AUX0 + GL_AUX_BUFFERS)) ) { icetStateSetInteger(ICET_GL_READ_BUFFER, GL_BACK); } else { icetRaiseError("Invalid OpenGL read buffer.", ICET_INVALID_ENUM); } }
void icetSetContext(IceTContext context) { if ( (context < 0) || (context >= num_contexts) || (context_list[context].state == NULL) ) { icetRaiseError("No such context", ICET_INVALID_VALUE); return; } current_context_index = context; icet_current_context = &(context_list[context]); }
static void *icetUnsafeStateGet(IceTEnum pname, IceTEnum type) { stateCheck(pname, icetGetState()); if (icetGetState()[pname].type != type) { icetRaiseError("Mismatched types in unsafe state get.", ICET_SANITY_CHECK_FAIL); return NULL; } return icetGetState()[pname].data; }
IceTBoolean icetIsEnabled(IceTEnum pname) { IceTBoolean isEnabled; if ((pname < ICET_STATE_ENABLE_START) || (pname >= ICET_STATE_ENABLE_END)) { icetRaiseError("Bad value to icetIsEnabled", ICET_INVALID_VALUE); return ICET_FALSE; } icetGetBooleanv(pname, &isEnabled); return isEnabled; }
void icetGetEnumv(IceTEnum pname, IceTEnum *params) { struct IceTStateValue *value = icetGetState() + pname; int i; stateCheck(pname, icetGetState()); if ((value->type == ICET_FLOAT) || (value->type == ICET_DOUBLE)) { icetRaiseError("Floating point values cannot be enumerations.", ICET_BAD_CAST); } copyArray(IceTEnum, params, value->type, value->data, value->num_entries); }
void icetProjectTile(IceTInt tile, IceTDouble *mat_out) { IceTInt num_tiles; const IceTInt *viewports; const IceTDouble *tile_projections; IceTInt tile_width, tile_height; IceTInt renderable_width, renderable_height; const IceTDouble *tile_proj; IceTDouble tile_viewport_proj[16]; const IceTDouble *global_proj; /* Update tile projections. */ update_tile_projections(); icetGetIntegerv(ICET_NUM_TILES, &num_tiles); if ((tile < 0) || (tile >= num_tiles)) { icetRaiseError("Bad tile passed to icetProjectTile.", ICET_INVALID_VALUE); return; } viewports = icetUnsafeStateGetInteger(ICET_TILE_VIEWPORTS); tile_width = viewports[tile*4+2]; tile_height = viewports[tile*4+3]; icetGetIntegerv(ICET_PHYSICAL_RENDER_WIDTH, &renderable_width); icetGetIntegerv(ICET_PHYSICAL_RENDER_HEIGHT, &renderable_height); tile_projections = icetUnsafeStateGetDouble(ICET_TILE_PROJECTIONS); tile_proj = tile_projections + 16*tile; if ((renderable_width != tile_width) || (renderable_height != tile_height)){ /* Compensate for fact that tile is smaller than actual window. Use an orthographic projection to place the tile in the lower left corner of the tile. */ IceTDouble viewport_proj[16]; icetMatrixOrtho(-1.0, 2.0*renderable_width/tile_width - 1.0, -1.0, 2.0*renderable_height/tile_height - 1.0, 1.0, -1.0, viewport_proj); icetMatrixMultiply(tile_viewport_proj, (const IceTDouble *)viewport_proj, (const IceTDouble *)tile_proj); } else { memcpy(tile_viewport_proj, (const IceTDouble*)tile_proj, 16*sizeof(IceTDouble)); } /* Project the user requested view to the tile projection. */ global_proj = icetUnsafeStateGetDouble(ICET_PROJECTION_MATRIX); icetMatrixMultiply(mat_out, (const IceTDouble *)tile_viewport_proj, (const IceTDouble *)global_proj); }
const char *icetGetStrategyName(void) { IceTEnum strategy; icetGetEnumv(ICET_STRATEGY, &strategy); if (strategy != ICET_STRATEGY_UNDEFINED) { return icetStrategyNameFromEnum(strategy); } else { icetRaiseError("No strategy set. Use icetStrategy to set the strategy.", ICET_INVALID_ENUM); return NULL; } }
IceTState icetStateCreate(void) { IceTState state; state = (IceTState)malloc(sizeof(struct IceTStateValue) * ICET_STATE_SIZE); if (state == NULL) { icetRaiseError("Could not allocate memory for state.", ICET_OUT_OF_MEMORY); return NULL; } memset(state, 0, sizeof(struct IceTStateValue) * ICET_STATE_SIZE); return state; }
void *icetReserveBufferMem(int size) { void *mem = ((GLubyte *)icet_current_context->buffer) + icet_current_context->buffer_offset; /* Integer boundries are good. */ if (size%sizeof(IceTInt64) != 0) { size += sizeof(IceTInt64) - size%sizeof(IceTInt64); } icet_current_context->buffer_offset += size; if (icet_current_context->buffer_offset > icet_current_context->buffer_size) icetRaiseError("Reserved more memory then allocated.", ICET_OUT_OF_MEMORY); return mem; }
void icetProjectTile(GLint tile) { GLint *viewports; GLint physical_viewport[4]; GLint tile_width, tile_height; GLint renderable_width, renderable_height; /* Update tile projections. */ if (viewport_time != icetStateGetTime(ICET_TILE_VIEWPORTS)) { update_tile_projections(); viewport_time = icetStateGetTime(ICET_TILE_VIEWPORTS); } if ((tile < 0) || (tile >= num_tiles)) { icetRaiseError("Bad tile passed to icetProjectTile.", ICET_INVALID_VALUE); return; } viewports = icetUnsafeStateGet(ICET_TILE_VIEWPORTS); tile_width = viewports[tile*4+2]; tile_height = viewports[tile*4+3]; glGetIntegerv(GL_VIEWPORT, physical_viewport); renderable_width = physical_viewport[2]; renderable_height = physical_viewport[3]; if ((renderable_width != tile_width) || (renderable_height != tile_height)){ /* Compensate for fact that tile is smaller than actual window. */ glOrtho(-1.0, 2.0*renderable_width/tile_width - 1.0, -1.0, 2.0*renderable_height/tile_height - 1.0, 1.0, -1.0); } glMultMatrixd(tile_projections + 16*tile); if (projection_time != icetStateGetTime(ICET_PROJECTION_MATRIX)) { icetGetDoublev(ICET_PROJECTION_MATRIX, global_projection); projection_time = icetStateGetTime(ICET_PROJECTION_MATRIX); } glMultMatrixd(global_projection); }
static void rtsi_handleDataFunc(void *inSparseImageBuffer, IceTInt src) { if (inSparseImageBuffer == NULL) { /* Superfluous call from send to self. */ if (!rtsi_first) { icetRaiseError("Unexpected callback order" " in icetRenderTransferSparseImages.", ICET_SANITY_CHECK_FAIL); } } else { IceTSparseImage inSparseImage = icetSparseImageUnpackageFromReceive(inSparseImageBuffer); if (rtsi_first) { IceTSizeType num_pixels = icetSparseImageGetNumPixels(inSparseImage); icetSparseImageCopyPixels(inSparseImage, 0, num_pixels, rtsi_workingImage); } else { IceTInt rank; const IceTInt *process_orders; IceTSparseImage old_workingImage; icetGetIntegerv(ICET_RANK, &rank); process_orders = icetUnsafeStateGetInteger(ICET_PROCESS_ORDERS); if (process_orders[src] < process_orders[rank]) { icetCompressedCompressedComposite(inSparseImage, rtsi_workingImage, rtsi_availableImage); } else { icetCompressedCompressedComposite(rtsi_workingImage, inSparseImage, rtsi_availableImage); } old_workingImage = rtsi_workingImage; rtsi_workingImage = rtsi_availableImage; rtsi_availableImage = old_workingImage; } } rtsi_first = ICET_FALSE; }
void icetCompositeOrder(const IceTInt *process_ranks) { IceTInt num_proc; IceTInt i; IceTInt *process_orders; icetGetIntegerv(ICET_NUM_PROCESSES, &num_proc); process_orders = icetStateAllocateInteger(ICET_PROCESS_ORDERS, num_proc); for (i = 0; i < num_proc; i++) { process_orders[i] = -1; } for (i = 0; i < num_proc; i++) { process_orders[process_ranks[i]] = i; } for (i = 0; i < num_proc; i++) { if (process_orders[i] == -1) { icetRaiseError("Invalid composite order.", ICET_INVALID_VALUE); return; } } icetStateSetIntegerv(ICET_COMPOSITE_ORDER, num_proc, process_ranks); }
void icetDataReplicationGroup(IceTInt size, const IceTInt *processes) { IceTInt rank; IceTBoolean found_myself = ICET_FALSE; IceTInt i; icetGetIntegerv(ICET_RANK, &rank); for (i = 0; i < size; i++) { if (processes[i] == rank) { found_myself = ICET_TRUE; break; } } if (!found_myself) { icetRaiseError("Local process not part of data replication group.", ICET_INVALID_VALUE); return; } icetStateSetIntegerv(ICET_DATA_REPLICATION_GROUP_SIZE, 1, &size); icetStateSetIntegerv(ICET_DATA_REPLICATION_GROUP, size, processes); }
static int typeWidth(GLenum type) { switch (type) { case ICET_DOUBLE: return sizeof(GLdouble); case ICET_FLOAT: return sizeof(GLfloat); case ICET_BOOLEAN: return sizeof(GLboolean); case ICET_SHORT: return sizeof(GLshort); case ICET_INT: return sizeof(GLint); case ICET_POINTER: return sizeof(GLvoid *); case ICET_NULL: return 0; default: icetRaiseError("Bad type detected in state.", ICET_SANITY_CHECK_FAIL); } return 0; }
static void rtfi_handleDataFunc(void *inSparseImageBuffer, IceTInt src) { if (inSparseImageBuffer == NULL) { /* Superfluous call from send to self. */ if (!rtfi_first) { icetRaiseError("Unexpected callback order" " in icetRenderTransferFullImages.", ICET_SANITY_CHECK_FAIL); } } else { IceTSparseImage inSparseImage = icetSparseImageUnpackageFromReceive(inSparseImageBuffer); if (rtfi_first) { icetDecompressImage(inSparseImage, rtfi_image); } else { IceTInt rank; const IceTInt *process_orders; icetGetIntegerv(ICET_RANK, &rank); process_orders = icetUnsafeStateGetInteger(ICET_PROCESS_ORDERS); icetCompressedComposite(rtfi_image, inSparseImage, process_orders[src] < process_orders[rank]); } } rtfi_first = ICET_FALSE; }
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(); }
void icetStateSetDefaults(void) { IceTInt *int_array; int i; int comm_size, comm_rank; icetDiagnostics(ICET_DIAG_ALL_NODES | ICET_DIAG_WARNINGS); comm_size = icetCommSize(); comm_rank = icetCommRank(); icetStateSetInteger(ICET_RANK, comm_rank); icetStateSetInteger(ICET_NUM_PROCESSES, comm_size); /* icetStateSetInteger(ICET_ABSOLUTE_FAR_DEPTH, 1); */ /*icetStateSetInteger(ICET_ABSOLUTE_FAR_DEPTH, 0xFFFFFFFF);*/ icetStateSetFloatv(ICET_BACKGROUND_COLOR, 4, black); icetStateSetInteger(ICET_BACKGROUND_COLOR_WORD, 0); icetStateSetInteger(ICET_COLOR_FORMAT, ICET_IMAGE_COLOR_RGBA_UBYTE); icetStateSetInteger(ICET_DEPTH_FORMAT, ICET_IMAGE_DEPTH_FLOAT); icetResetTiles(); icetStateSetIntegerv(ICET_DISPLAY_NODES, 0, NULL); icetStateSetDoublev(ICET_GEOMETRY_BOUNDS, 0, NULL); icetStateSetInteger(ICET_NUM_BOUNDING_VERTS, 0); icetStateSetInteger(ICET_STRATEGY, ICET_STRATEGY_UNDEFINED); icetSingleImageStrategy(ICET_SINGLE_IMAGE_STRATEGY_AUTOMATIC); icetCompositeMode(ICET_COMPOSITE_MODE_Z_BUFFER); int_array = icetStateAllocateInteger(ICET_COMPOSITE_ORDER, comm_size); for (i = 0; i < comm_size; i++) { int_array[i] = i; } int_array = icetStateAllocateInteger(ICET_PROCESS_ORDERS, comm_size); for (i = 0; i < comm_size; i++) { int_array[i] = i; } icetStateSetInteger(ICET_DATA_REPLICATION_GROUP, comm_rank); icetStateSetInteger(ICET_DATA_REPLICATION_GROUP_SIZE, 1); icetStateSetInteger(ICET_FRAME_COUNT, 0); if (getenv("ICET_MAGIC_K") != NULL) { IceTInt magic_k = atoi(getenv("ICET_MAGIC_K")); if (magic_k > 1) { icetStateSetInteger(ICET_MAGIC_K, magic_k); } else { icetRaiseError("Environment varible ICET_MAGIC_K must be set" " to an integer greater than 1.", ICET_INVALID_VALUE); icetStateSetInteger(ICET_MAGIC_K, ICET_MAGIC_K_DEFAULT); } } else { icetStateSetInteger(ICET_MAGIC_K, ICET_MAGIC_K_DEFAULT); } if (getenv("ICET_MAX_IMAGE_SPLIT") != NULL) { IceTInt max_image_split = atoi(getenv("ICET_MAX_IMAGE_SPLIT")); if (max_image_split > 0) { icetStateSetInteger(ICET_MAX_IMAGE_SPLIT, max_image_split); } else { icetRaiseError("Environment variable ICET_MAX_IMAGE_SPLIT must be" " set to an integer greater than 0.", ICET_INVALID_VALUE); icetStateSetInteger(ICET_MAX_IMAGE_SPLIT, ICET_MAX_IMAGE_SPLIT_DEFAULT); } } else { icetStateSetInteger(ICET_MAX_IMAGE_SPLIT, ICET_MAX_IMAGE_SPLIT_DEFAULT); } icetStateSetPointer(ICET_DRAW_FUNCTION, NULL); icetStateSetPointer(ICET_RENDER_LAYER_DESTRUCTOR, NULL); icetEnable(ICET_FLOATING_VIEWPORT); icetDisable(ICET_ORDERED_COMPOSITE); icetDisable(ICET_CORRECT_COLORED_BACKGROUND); icetEnable(ICET_COMPOSITE_ONE_BUFFER); icetEnable(ICET_INTERLACE_IMAGES); icetEnable(ICET_COLLECT_IMAGES); icetDisable(ICET_RENDER_EMPTY_IMAGES); icetStateSetBoolean(ICET_IS_DRAWING_FRAME, 0); icetStateSetBoolean(ICET_RENDER_BUFFER_SIZE, 0); icetStateSetInteger(ICET_VALID_PIXELS_TILE, -1); icetStateSetInteger(ICET_VALID_PIXELS_OFFSET, 0); icetStateSetInteger(ICET_VALID_PIXELS_NUM, 0); icetStateResetTiming(); }
static IceTVoid *stateAllocate(IceTEnum pname, IceTSizeType num_entries, IceTEnum type, IceTState state) { IceTVoid *buffer; stateCheck(pname, state); if ( (num_entries == state[pname].num_entries) && (type == state[pname].type) ) { /* Return the current buffer. */ state[pname].mod_time = icetGetTimeStamp(); buffer = state[pname].data; } else if (num_entries > 0) { stateFree(pname, state); /* Create a new buffer. */ buffer = malloc(STATE_DATA_ALLOCATE(type, num_entries)); if (buffer == NULL) { icetRaiseError("Could not allocate memory for state variable.", ICET_OUT_OF_MEMORY); return NULL; } #ifdef ICET_STATE_CHECK_MEM /* Skip past padding. */ buffer = (IceTByte *)buffer + STATE_PADDING_SIZE; #endif state[pname].type = type; state[pname].num_entries = num_entries; state[pname].data = buffer; state[pname].mod_time = icetGetTimeStamp(); #ifdef ICET_STATE_CHECK_MEM /* Set padding data. */ { IceTSizeType i; IceTByte *padding; padding = STATE_DATA_PRE_PADDING(pname, state); for (i = 0; i < STATE_PADDING_SIZE; i++) { padding[i] = g_pre_padding[i]; } padding = STATE_DATA_POST_PADDING(pname, state); for (i = 0; i < STATE_PADDING_SIZE; i++) { padding[i] = g_post_padding[i]; } } #endif } else { /* num_entries <= 0 */ buffer = NULL; state[pname].type = type; state[pname].num_entries = 0; state[pname].data = buffer; state[pname].mod_time = icetGetTimeStamp(); } #ifdef ICET_STATE_CHECK_MEM memset(buffer, 0xDC, STATE_DATA_WIDTH(type, num_entries)); #endif return buffer; }
int icetAddTile(GLint x, GLint y, GLsizei width, GLsizei height, int display_rank) { GLint num_tiles; GLint *viewports; GLint gvp[4]; GLint max_width, max_height; GLint *display_nodes; GLint rank; GLint num_processors; char msg[256]; int i; /* Get current number of tiles and viewports. */ icetGetIntegerv(ICET_NUM_TILES, &num_tiles); viewports = malloc((num_tiles+1)*4*sizeof(GLint)); icetGetIntegerv(ICET_TILE_VIEWPORTS, viewports); /* Get display node information. */ icetGetIntegerv(ICET_RANK, &rank); icetGetIntegerv(ICET_NUM_PROCESSES, &num_processors); display_nodes = malloc((num_tiles+1)*4*sizeof(GLint)); icetGetIntegerv(ICET_DISPLAY_NODES, display_nodes); /* Check and update display ranks. */ if (display_rank >= num_processors) { sprintf(msg, "icetDisplayNodes: Invalid rank for tile %d.", (int)num_tiles); icetRaiseError(msg, ICET_INVALID_VALUE); free(viewports); free(display_nodes); return -1; } for (i = 0; i < num_tiles; i++) { if (display_nodes[i] == display_rank) { sprintf(msg, "icetDisplayNodes: Rank %d used for tiles %d and %d.", display_rank, i, (int)num_tiles); icetRaiseError(msg, ICET_INVALID_VALUE); free(viewports); free(display_nodes); return -1; } } display_nodes[num_tiles] = display_rank; icetUnsafeStateSet(ICET_DISPLAY_NODES, num_tiles+1, ICET_INT, display_nodes); if (display_rank == rank) { icetStateSetInteger(ICET_TILE_DISPLAYED, num_tiles); } /* Figure out current global viewport. */ gvp[0] = x; gvp[1] = y; gvp[2] = x + width; gvp[3] = y + height; for (i = 0; i < num_tiles; i++) { gvp[0] = MIN(gvp[0], viewports[i*4+0]); gvp[1] = MIN(gvp[1], viewports[i*4+1]); gvp[2] = MAX(gvp[2], viewports[i*4+0] + viewports[i*4+2]); gvp[3] = MAX(gvp[3], viewports[i*4+1] + viewports[i*4+3]); } gvp[2] -= gvp[0]; gvp[3] -= gvp[1]; /* Add new viewport to current viewports. */ viewports[4*num_tiles+0] = x; viewports[4*num_tiles+1] = y; viewports[4*num_tiles+2] = width; viewports[4*num_tiles+3] = height; /* Set new state. */ icetStateSetInteger(ICET_NUM_TILES, num_tiles+1); icetUnsafeStateSet(ICET_TILE_VIEWPORTS, (num_tiles+1)*4, ICET_INT, viewports); icetStateSetIntegerv(ICET_GLOBAL_VIEWPORT, 4, gvp); icetGetIntegerv(ICET_TILE_MAX_WIDTH, &max_width); max_width = MAX(max_width, width); icetStateSetInteger(ICET_TILE_MAX_WIDTH, max_width); icetGetIntegerv(ICET_TILE_MAX_HEIGHT, &max_height); max_height = MAX(max_height, height); icetStateSetInteger(ICET_TILE_MAX_HEIGHT, max_height); /* When storing max pixels, leave some padding so that pixels may be dropped if the image needs to be divided amongst processors. */ icetStateSetInteger(ICET_TILE_MAX_PIXELS, max_width*max_height + num_processors); /* Return index to tile. */ return num_tiles; }
IceTImage icetDrawFrame(const IceTDouble *projection_matrix, const IceTDouble *modelview_matrix, const IceTFloat *background_color) { IceTInt frame_count; IceTImage image; IceTDouble render_time; IceTDouble buf_read_time; IceTDouble compose_time; IceTDouble total_time; icetRaiseDebug("In icetDrawFrame"); { IceTBoolean isDrawing; icetGetBooleanv(ICET_IS_DRAWING_FRAME, &isDrawing); if (isDrawing) { icetRaiseError("Recursive frame draw detected.", ICET_INVALID_OPERATION); return icetImageNull(); } } icetStateResetTiming(); icetTimingDrawFrameBegin(); icetStateSetDoublev(ICET_PROJECTION_MATRIX, 16, projection_matrix); icetStateSetDoublev(ICET_MODELVIEW_MATRIX, 16, modelview_matrix); drawUseBackgroundColor(background_color); icetGetIntegerv(ICET_FRAME_COUNT, &frame_count); frame_count++; icetStateSetIntegerv(ICET_FRAME_COUNT, 1, &frame_count); drawProjectBounds(); { IceTEnum strategy; icetGetEnumv(ICET_STRATEGY, &strategy); /* drawCollectTileInformation does an allgather to get information * about the tiles in other processes. These variables are * ICET_ALL_CONTAINED_TILES_MASKS, ICET_TILE_CONTRIB_COUNTS, and * ICET_TOTAL_IMAGE_COUNT. However, the sequential strategy ignores * this information and just uses all processes for all tiles. When * compositing a single tile, this is a fine strategy and we can save * a significant proportion of frame time by skipping this step. */ if (strategy != ICET_STRATEGY_SEQUENTIAL) { drawCollectTileInformation(); } } { IceTInt tile_displayed; icetGetIntegerv(ICET_TILE_DISPLAYED, &tile_displayed); if (tile_displayed >= 0) { const IceTInt *tile_viewports = icetUnsafeStateGetInteger(ICET_TILE_VIEWPORTS); IceTInt num_pixels = ( tile_viewports[4*tile_displayed+2] * tile_viewports[4*tile_displayed+3] ); icetStateSetInteger(ICET_VALID_PIXELS_TILE, tile_displayed); icetStateSetInteger(ICET_VALID_PIXELS_OFFSET, 0); icetStateSetInteger(ICET_VALID_PIXELS_NUM, num_pixels); } else { icetStateSetInteger(ICET_VALID_PIXELS_TILE, -1); icetStateSetInteger(ICET_VALID_PIXELS_OFFSET, 0); icetStateSetInteger(ICET_VALID_PIXELS_NUM, 0); } } image = drawInvokeStrategy(); /* Calculate times. */ icetGetDoublev(ICET_RENDER_TIME, &render_time); icetGetDoublev(ICET_BUFFER_READ_TIME, &buf_read_time); icetTimingDrawFrameEnd(); icetGetDoublev(ICET_TOTAL_DRAW_TIME, &total_time); compose_time = total_time - render_time - buf_read_time; icetStateSetDouble(ICET_COMPOSITE_TIME, compose_time); icetStateSetDouble(ICET_BUFFER_WRITE_TIME, 0.0); icetStateCheckMemory(); return image; }