bool WebGLTexture::canGenerateMipmaps() { if (isNPOT()) return false; const LevelInfo& first = m_info[0][0]; for (size_t ii = 0; ii < m_info.size(); ++ii) { const LevelInfo& info = m_info[ii][0]; if (!info.valid || info.width != first.width || info.height != first.height || info.internalFormat != first.internalFormat || info.type != first.type) return false; } return true; }
void WebGLTexture::update() { m_isNPOT = false; for (size_t ii = 0; ii < m_info.size(); ++ii) { if (isNPOT(m_info[ii][0].width, m_info[ii][0].height)) { m_isNPOT = true; break; } } m_isComplete = true; const LevelInfo& first = m_info[0][0]; int levelCount = computeLevelCount(first.width, first.height); if (levelCount < 1) m_isComplete = false; else { for (size_t ii = 0; ii < m_info.size() && m_isComplete; ++ii) { const LevelInfo& info0 = m_info[ii][0]; if (!info0.valid || info0.width != first.width || info0.height != first.height || info0.internalFormat != first.internalFormat || info0.type != first.type) { m_isComplete = false; break; } int width = info0.width; int height = info0.height; for (int level = 1; level < levelCount; ++level) { width = std::max(1, width >> 1); height = std::max(1, height >> 1); const LevelInfo& info = m_info[ii][level]; if (!info.valid || info.width != width || info.height != height || info.internalFormat != info0.internalFormat || info.type != info0.type) { m_isComplete = false; break; } } } } m_needToUseBlackTexture = false; // NPOT if (m_isNPOT && ((m_minFilter != GraphicsContext3D::NEAREST && m_minFilter != GraphicsContext3D::LINEAR) || m_wrapS != GraphicsContext3D::CLAMP_TO_EDGE || m_wrapT != GraphicsContext3D::CLAMP_TO_EDGE)) m_needToUseBlackTexture = true; // Completeness if (!m_isComplete && m_minFilter != GraphicsContext3D::NEAREST && m_minFilter != GraphicsContext3D::LINEAR) m_needToUseBlackTexture = true; }
void WebGLTexture::updateNPOTStates() { int numTargets = 0; if (m_target == GraphicsContext3D::TEXTURE_2D) numTargets = 1; else if (m_target == GraphicsContext3D::TEXTURE_CUBE_MAP) numTargets = 6; m_isNPOT = false; unsigned w0 = m_width[0], h0 = m_height[0]; for (int ii = 0; ii < numTargets; ++ii) { if (ii && (!m_width[ii] || !m_height[ii] || m_width[ii] != w0 || m_height[ii] != h0)) { // We only set NPOT for complete cube map textures. m_isNPOT = false; break; } if (isNPOT(m_width[ii], m_height[ii])) m_isNPOT = true; } m_needToUseBlackTexture = false; if (m_isNPOT && ((m_minFilter != GraphicsContext3D::NEAREST && m_minFilter != GraphicsContext3D::LINEAR) || m_wrapS != GraphicsContext3D::CLAMP_TO_EDGE || m_wrapT != GraphicsContext3D::CLAMP_TO_EDGE)) m_needToUseBlackTexture = true; }