void * k_pool_replace(MemPool_t *pool, ptr_t block, size_t bytes) { struct BlockHeader_t *pHeader = (struct BlockHeader_t *) block - 1; const byte newListNum = get_next_power_of_two(bytes + sizeof(struct BlockHeader_t)); if (pHeader->listNum != newListNum) { size_t oldSize = 1U << pHeader->listNum; void *newp = k_pool_select(pool, bytes); if (bytes <= oldSize) k_memcpy(newp, block, bytes); else k_memcpy(newp, block, oldSize); k_pool_release(pool, block); return newp; } else { return block; } }
void * k_pool_select(MemPool_t *pool, size_t bytes) { if(!pool) return NULL; const byte listNum = get_next_power_of_two(bytes + sizeof(struct BlockHeader_t)); if (!pool->freeSlicesLists[listNum]) { if (!find_new_block_for_list(pool, listNum)) { return NULL; } } pool->numAllocatedBlocks[listNum]++; pool->numBlockAllocations[listNum]++; void * res = 1 + detach_first_block(pool, listNum); return res; }
void GL1TextureProvider::create(int new_width, int new_height, int new_depth, int array_size, TextureFormat texture_format, int levels) { throw_if_disposed(); GLint gl_internal_format; GLenum gl_pixel_format; to_opengl_textureformat(texture_format, gl_internal_format, gl_pixel_format); if ( (new_width > 32768) || (new_width < 1) ) { throw Exception("Invalid texture width in the GL1 target"); } if ( (texture_type == GL_TEXTURE_2D) || (texture_type == GL_TEXTURE_3D) ) { if ( (new_height > 32768) || (new_height < 1) ) { throw Exception("Invalid texture height in the GL1 target"); } } if ( texture_type == GL_TEXTURE_3D ) { if ( (new_depth > 32768) || (new_depth < 1) ) { throw Exception("Invalid texture depth in the GL1 target"); } } width = new_width; height = new_height; depth = new_depth; GL1TextureStateTracker state_tracker(texture_type, handle); #ifndef __ANDROID__ if (texture_type == GL_TEXTURE_1D) { pot_width = get_next_power_of_two(new_width); if (pot_width == new_width) { power_of_two_texture=true; } else { power_of_two_texture=false; } pot_ratio_width = (float) width / pot_width; glTexImage1D( GL_TEXTURE_1D, // target 0, // level gl_internal_format, // internalformat pot_width, // width 0, // border gl_pixel_format, // format GL_UNSIGNED_BYTE, // type (it really doesn't matter since nothing is uploaded) nullptr); // texels (0 to avoid uploading) } #endif if (texture_type == GL_TEXTURE_2D) { pot_width = get_next_power_of_two(new_width); pot_height = get_next_power_of_two(new_height); if ( (pot_width == new_width) && (pot_height == new_height)) { power_of_two_texture=true; } else { power_of_two_texture=false; } pot_ratio_width = (float) width / pot_width; pot_ratio_height = (float) height / pot_height; glTexImage2D( GL_TEXTURE_2D, // target 0, // level gl_internal_format, // internalformat pot_width, // width pot_height, // height 0, // border gl_pixel_format, // format GL_UNSIGNED_BYTE, // type (it really doesn't matter since nothing is uploaded) nullptr); // texels (0 to avoid uploading) // Clear the whole texture if it is npot if (!power_of_two_texture) { PixelBuffer image = PixelBuffer(pot_width, pot_height, tf_rgba8); void *data = image.get_data(); memset(data, 0, pot_width * pot_height * 4); GLenum format; GLenum type; to_opengl_pixelformat(image, format, type); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); const int bytesPerPixel = image.get_bytes_per_pixel(); #ifndef __ANDROID__ glPixelStorei(GL_UNPACK_ROW_LENGTH, image.get_pitch() / bytesPerPixel); glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); #endif glTexImage2D( GL_TEXTURE_2D, // target 0, // level gl_internal_format, // internalformat pot_width, // width pot_height, // height 0, // border format, // format type, // type data); // texels } } else { pot_width = get_next_power_of_two(new_width); pot_height = get_next_power_of_two(new_height); pot_depth = get_next_power_of_two(new_depth); pot_ratio_width = (float) width / pot_width; pot_ratio_height = (float) height / pot_height; pot_ratio_depth = (float) depth / pot_depth; if ( (pot_width == new_width) && (pot_height == new_height) && (pot_depth == new_depth)) { power_of_two_texture=true; } else { power_of_two_texture=false; } glTexImage3D( GL_TEXTURE_3D, // target 0, // level gl_internal_format, // internalformat pot_width, // width pot_height, // height pot_depth, // depth 0, // border gl_pixel_format, // format GL_UNSIGNED_BYTE, // type (it really doesn't matter since nothing is uploaded) nullptr); // texels (0 to avoid uploading) } }