R8Image::R8Image(size_t width, size_t height) : Image(width, height, PixelFormat::R8) { setPixelData(new Byte[1 * width * height]); }
//---------------------------------------------------------------------------// void TextureGL4::create(const TextureCreationParams& clDeclaration, CreationMethod eCreationMethod /*= CreationMethod::UPLOADED_ONCE*/) { // TODO: Implement Cubemap- and array textures destroy(); TextureCreationParams* pBaseParams = &m_clParameters; *pBaseParams = clDeclaration; GLenum eGLformat, eGLinternalFormat, eGLpixelType; Adapter::mapGLpixelFormats(clDeclaration.eFormat, clDeclaration.bIsDepthStencil, eGLformat, eGLinternalFormat, eGLpixelType); m_clParameters.eFormatGL = eGLformat; m_clParameters.eInternalFormatGL = eGLinternalFormat; m_clParameters.ePixelTypeGL = eGLpixelType; GLenum eTextureType = 0u; GLenum eTexBindingQuery = 0u; GLuint uNumDimensions = 0u; ASSERT(clDeclaration.u16Width > 0u, "Invalid texture dimensions"); if (clDeclaration.u16Height == 0u && clDeclaration.u16Depth == 0u ) { eTextureType = GL_TEXTURE_1D; eTexBindingQuery = GL_TEXTURE_BINDING_1D; uNumDimensions = 1u; } else if (clDeclaration.u16Height > 0u && clDeclaration.u16Depth == 0u) { eTextureType = GL_TEXTURE_2D; eTexBindingQuery = GL_TEXTURE_BINDING_2D; uNumDimensions = 2u; } else if (clDeclaration.u16Height > 0u && clDeclaration.u16Depth > 0u) { eTextureType = GL_TEXTURE_3D; eTexBindingQuery = GL_TEXTURE_BINDING_3D; uNumDimensions = 3u; } ASSERT (uNumDimensions > 0u, "Invalid texture dimensions"); m_clParameters.eTextureTypeGL = eTextureType; m_clParameters.eTexBindQueryGL = eTexBindingQuery; m_clStateInfo.isArrayTexture = false; // TODO: Implement m_clStateInfo.isCubemap = false; // TODO: Implement m_clStateInfo.isLocked = false; m_clStateInfo.isSRGB = (eGLinternalFormat == GL_SRGB8_ALPHA8 || eGLinternalFormat == GL_SRGB8); m_clStateInfo.numDimensions = uNumDimensions; // Determine the max number of miplevels uint8 u8MipLevelsWidth = clDeclaration.u16Width == 0u ? 0u : glm::log2(clDeclaration.u16Width); uint8 u8MipLevelsHeight = clDeclaration.u16Height == 0u ? 0u : glm::log2(clDeclaration.u16Height); uint8 u8MipLevelsDepth = clDeclaration.u16Depth == 0u ? 0u : glm::log2(clDeclaration.u16Depth); uint8 u8MaxMipLevels = u8MipLevelsWidth; if (uNumDimensions > 1u) { u8MaxMipLevels = glm::min(u8MaxMipLevels, u8MipLevelsHeight); } if (uNumDimensions > 2u) { u8MaxMipLevels = glm::min(u8MaxMipLevels, u8MipLevelsDepth); } m_clParameters.u8NumMipLevels = glm::min(glm::max(static_cast<uint8>(1u), m_clParameters.u8NumMipLevels), u8MaxMipLevels); // Internally store the raw texture data if required m_clStateInfo.cachesTextureData = false; if (m_clParameters.pPixelData != nullptr && eCreationMethod == CreationMethod::UPLOADED_OFTEN) { void* pDataCache = FANCY_ALLOCATE(m_clParameters.uPixelDataSizeBytes, MemoryCategory::TEXTURES); memcpy(pDataCache, m_clParameters.pPixelData, m_clParameters.uPixelDataSizeBytes); m_clParameters.pPixelData = pDataCache; m_clStateInfo.cachesTextureData = true; } // determine the currently bound texture GLint origBoundTexture; glGetIntegerv(eTexBindingQuery, &origBoundTexture); // construct the new texture glGenTextures(1u, &m_uGLhandle); glBindTexture(eTextureType, m_uGLhandle); if (uNumDimensions == 2u) { glTexStorage2D(eTextureType, m_clParameters.u8NumMipLevels, eGLinternalFormat, m_clParameters.u16Width, m_clParameters.u16Height ); } else if (uNumDimensions == 3u) { glTexStorage3D(eTextureType, m_clParameters.u8NumMipLevels, eGLinternalFormat, m_clParameters.u16Width, m_clParameters.u16Height, m_clParameters.u16Depth ); } else { glTexStorage1D(eTextureType, m_clParameters.u8NumMipLevels, eGLinternalFormat, m_clParameters.u16Width ); } if (m_clParameters.pPixelData != nullptr) { setPixelData(m_clParameters.pPixelData, m_clParameters.uPixelDataSizeBytes); } // restore originally bound texture glBindTexture(eTextureType, static_cast<GLuint>(origBoundTexture)); }