| 43 | |
| 44 | |
| 45 | void initialize() |
| 46 | { |
| 47 | // Initialize OpenGL objects |
| 48 | int numPageSizes; |
| 49 | glGetInternalformativ(GL_TEXTURE_2D, GL_RGBA8, GL_NUM_VIRTUAL_PAGE_SIZES_ARB, sizeof(int), &numPageSizes); |
| 50 | globjects::info("GL_NUM_VIRTUAL_PAGE_SIZES_ARB = %d;", numPageSizes); |
| 51 | |
| 52 | if (numPageSizes == 0) |
| 53 | { |
| 54 | globjects::fatal("Sparse Texture not supported for GL_RGBA8"); |
| 55 | exit(1); |
| 56 | } |
| 57 | |
| 58 | auto pageSizesX = std::vector<int>(numPageSizes); |
| 59 | glGetInternalformativ(GL_TEXTURE_2D, GL_RGBA8, GL_VIRTUAL_PAGE_SIZE_X_ARB |
| 60 | , static_cast<GLsizei>(numPageSizes * sizeof(int)), pageSizesX.data()); |
| 61 | for (int i = 0; i < numPageSizes; ++i) |
| 62 | globjects::info("GL_VIRTUAL_PAGE_SIZE_X_ARB[%;] = %;", i, pageSizesX[i]); |
| 63 | |
| 64 | auto pageSizesY = std::vector<int>(numPageSizes); |
| 65 | glGetInternalformativ(GL_TEXTURE_2D, GL_RGBA8, GL_VIRTUAL_PAGE_SIZE_Y_ARB |
| 66 | , static_cast<GLsizei>(numPageSizes * sizeof(int)), pageSizesY.data()); |
| 67 | for (int i = 0; i < numPageSizes; ++i) |
| 68 | globjects::info("GL_VIRTUAL_PAGE_SIZE_Y_ARB[%;] = %;", i, pageSizesY[i]); |
| 69 | |
| 70 | auto pageSizesZ = std::vector<int>(numPageSizes); |
| 71 | glGetInternalformativ(GL_TEXTURE_2D, GL_RGBA8, GL_VIRTUAL_PAGE_SIZE_Z_ARB |
| 72 | , static_cast<GLsizei>(numPageSizes * sizeof(int)), pageSizesZ.data()); |
| 73 | for (int i = 0; i < numPageSizes; ++i) |
| 74 | globjects::info("GL_VIRTUAL_PAGE_SIZE_Z_ARB[%;] = %;", i, pageSizesZ[i]); |
| 75 | |
| 76 | g_pageSize = glm::ivec2(pageSizesX[0], pageSizesY[0]); |
| 77 | g_numPages = g_textureSize / g_pageSize; |
| 78 | g_totalPages = g_numPages.x * g_numPages.y; |
| 79 | |
| 80 | // Get maximum sparse texture size |
| 81 | |
| 82 | int maxSparseTextureSize; |
| 83 | glGetIntegerv(GL_MAX_SPARSE_TEXTURE_SIZE_ARB, &maxSparseTextureSize); |
| 84 | globjects::info("GL_MAX_SPARSE_TEXTURE_SIZE_ARB = %d;", maxSparseTextureSize); |
| 85 | |
| 86 | g_texture = new globjects::Texture(GL_TEXTURE_2D); |
| 87 | g_texture->ref(); |
| 88 | |
| 89 | // make texture sparse |
| 90 | g_texture->setParameter(GL_TEXTURE_SPARSE_ARB, static_cast<GLint>(GL_TRUE)); |
| 91 | // specify the page size via its index in the array retrieved above (we simply use the first here) |
| 92 | g_texture->setParameter(GL_VIRTUAL_PAGE_SIZE_INDEX_ARB, 0); |
| 93 | |
| 94 | g_texture->setParameter(GL_TEXTURE_MIN_FILTER, static_cast<GLint>(GL_LINEAR)); |
| 95 | g_texture->setParameter(GL_TEXTURE_MAG_FILTER, static_cast<GLint>(GL_LINEAR)); |
| 96 | |
| 97 | g_texture->setParameter(GL_TEXTURE_WRAP_S, static_cast<GLint>(GL_CLAMP_TO_EDGE)); |
| 98 | g_texture->setParameter(GL_TEXTURE_WRAP_T, static_cast<GLint>(GL_CLAMP_TO_EDGE)); |
| 99 | g_texture->setParameter(GL_TEXTURE_WRAP_R, static_cast<GLint>(GL_CLAMP_TO_EDGE)); |
| 100 | |
| 101 | // allocate virtual(!) storage for texture |
| 102 | g_texture->storage2D(1, GL_RGBA8, g_textureSize); |
no test coverage detected