bool Texture::Create(unsigned int width, unsigned int height) { // Check if texture parameters are valid before creating it if (!width || !height) { Err() << "Failed to create texture, invalid size (" << width << "x" << height << ")" << std::endl; return false; } // Compute the internal texture dimensions depending on NPOT textures support unsigned int textureWidth = GetValidSize(width); unsigned int textureHeight = GetValidSize(height); // Check the maximum texture size unsigned int maxSize = GetMaximumSize(); if ((textureWidth > maxSize) || (textureHeight > maxSize)) { Err() << "Failed to create texture, its internal size is too high " << "(" << textureWidth << "x" << textureHeight << ", " << "maximum is " << maxSize << "x" << maxSize << ")" << std::endl; return false; } // All the validity checks passed, we can store the new texture settings myWidth = width; myHeight = height; myTextureWidth = textureWidth; myTextureHeight = textureHeight; myPixelsFlipped = false; EnsureGlContext(); // Create the OpenGL texture if it doesn't exist yet if (!myTexture) { GLuint texture; GLCheck(glGenTextures(1, &texture)); myTexture = static_cast<unsigned int>(texture); } // Make sure that the current texture binding will be preserved priv::TextureSaver save; // Initialize the texture GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture)); GLCheck(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, myTextureWidth, myTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL)); GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, myIsRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE)); GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, myIsRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE)); GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, myIsSmooth ? GL_LINEAR : GL_NEAREST)); GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, myIsSmooth ? GL_LINEAR : GL_NEAREST)); myCacheId = GetUniqueId(); return true; }
template<class TA> void DynObjArray_cl<TA>::AdjustSize() { Resize(GetValidSize()); }