13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES Utilities 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ------------------------------------------------ 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Texture classes. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTexture.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTextureUtil.hpp" 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deFilePath.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuImageIO.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuSurface.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp" 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp" 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deUniquePtr.hpp" 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector; 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace glu 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline int computePixelStore (const tcu::TextureFormat& format) 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int pixelSize = format.getPixelSize(); 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (deIsPowerOfTwo32(pixelSize)) 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return de::min(pixelSize, 8); 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return 1; 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Texture1D 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 523c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture1D::Texture1D (const RenderContext& context, deUint32 format, deUint32 dataType, int width) 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_context (context) 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (format) 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_refTexture (mapGLTransferFormat(format, dataType), width) 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glTexture (0) 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = context.getFunctions(); 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genTextures(1, &m_glTexture); 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 633c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture1D::Texture1D (const RenderContext& context, deUint32 sizedFormat, int width) 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_context (context) 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (sizedFormat) 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_refTexture (mapGLInternalFormat(sizedFormat), width) 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glTexture (0) 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = context.getFunctions(); 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genTextures(1, &m_glTexture); 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 743c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture1D::~Texture1D (void) 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_glTexture) 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_context.getFunctions().deleteTextures(1, &m_glTexture); 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture1D::upload (void) 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(m_glTexture); 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_1D, m_glTexture); 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.pixelStorei(GL_UNPACK_ALIGNMENT, computePixelStore(m_refTexture.getFormat())); 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TransferFormat transferFormat = getTransferFormat(m_refTexture.getFormat()); 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < m_refTexture.getNumLevels(); levelNdx++) 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_refTexture.isLevelEmpty(levelNdx)) 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; // Don't upload. 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ConstPixelBufferAccess access = m_refTexture.getLevel(levelNdx); 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texImage1D(GL_TEXTURE_1D, levelNdx, m_format, access.getWidth(), 0 /* border */, transferFormat.format, transferFormat.dataType, access.getDataPtr()); 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Texture2D 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1053c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2D::Texture2D (const RenderContext& context, deUint32 format, deUint32 dataType, int width, int height) 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_context (context) 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_isCompressed (false) 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (format) 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_refTexture (mapGLTransferFormat(format, dataType), width, height) 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glTexture (0) 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = context.getFunctions(); 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genTextures(1, &m_glTexture); 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1173c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2D::Texture2D (const RenderContext& context, deUint32 sizedFormat, int width, int height) 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_context (context) 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_isCompressed (false) 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (sizedFormat) 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_refTexture (mapGLInternalFormat(sizedFormat), width, height) 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glTexture (0) 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = context.getFunctions(); 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genTextures(1, &m_glTexture); 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 129becd5d53015521acf7536ba754de326d8b1da2f3Mika IsojärviTexture2D::Texture2D (const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams) 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_context (context) 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_isCompressed (true) 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (getGLFormat(levels[0].getFormat())) 133becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi , m_refTexture (getUncompressedFormat(levels[0].getFormat()), levels[0].getWidth(), levels[0].getHeight()) 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glTexture (0) 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = context.getFunctions(); 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!contextInfo.isCompressedTextureFormatSupported(m_format)) 139246a880f1d59f8f5dcf4b68aec8226d8b2f87320Pyry Haulos TCU_THROW(NotSupportedError, "Compressed texture format not supported"); 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genTextures(1, &m_glTexture); 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry try 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry loadCompressed(numLevels, levels, decompressionParams); 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry catch (const std::exception&) 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.deleteTextures(1, &m_glTexture); 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw; 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1553c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2D::~Texture2D (void) 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_glTexture) 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_context.getFunctions().deleteTextures(1, &m_glTexture); 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2D::upload (void) 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(!m_isCompressed); 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(m_glTexture); 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_2D, m_glTexture); 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.pixelStorei(GL_UNPACK_ALIGNMENT, computePixelStore(m_refTexture.getFormat())); 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TransferFormat transferFormat = getTransferFormat(m_refTexture.getFormat()); 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < m_refTexture.getNumLevels(); levelNdx++) 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_refTexture.isLevelEmpty(levelNdx)) 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; // Don't upload. 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ConstPixelBufferAccess access = m_refTexture.getLevel(levelNdx); 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(access.getRowPitch() == access.getFormat().getPixelSize()*access.getWidth()); 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texImage2D(GL_TEXTURE_2D, levelNdx, m_format, access.getWidth(), access.getHeight(), 0 /* border */, transferFormat.format, transferFormat.dataType, access.getDataPtr()); 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 187becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvivoid Texture2D::loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams) 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 compressedFormat = getGLFormat(levels[0].getFormat()); 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(m_glTexture); 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_2D, m_glTexture); 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::CompressedTexture& level = levels[levelNdx]; 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Decompress to reference texture. 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_refTexture.allocLevel(levelNdx); 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::PixelBufferAccess refLevelAccess = m_refTexture.getLevel(levelNdx); 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(level.getWidth() == refLevelAccess.getWidth() && 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry level.getHeight() == refLevelAccess.getHeight()); 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry level.decompress(refLevelAccess, decompressionParams); 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Upload to GL texture in compressed form. 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.compressedTexImage2D(GL_TEXTURE_2D, levelNdx, compressedFormat, 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry level.getWidth(), level.getHeight(), 0 /* border */, level.getDataSize(), level.getData()); 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2143c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2D* Texture2D::create (const RenderContext& context, const ContextInfo& contextInfo, const tcu::Archive& archive, int numLevels, const char* const* levelFileNames) 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(numLevels > 0); 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string ext = de::FilePath(levelFileNames[0]).getFileExtension(); 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (ext == "png") 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Uncompressed texture. 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TextureLevel level; 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Load level 0. 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ImageIO::loadPNG(level, archive, levelFileNames[0]); 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK_INTERNAL(level.getFormat() == tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8) || 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry level.getFormat() == tcu::TextureFormat(tcu::TextureFormat::RGB, tcu::TextureFormat::UNORM_INT8)); 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isRGBA = level.getFormat() == tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8); 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Texture2D* texture = new Texture2D(context, isRGBA ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, level.getWidth(), level.getHeight()); 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry try 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fill level 0. 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry texture->getRefTexture().allocLevel(0); 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::copy(texture->getRefTexture().getLevel(0), level.getAccess()); 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fill remaining levels. 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 1; levelNdx < numLevels; levelNdx++) 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ImageIO::loadPNG(level, archive, levelFileNames[levelNdx]); 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry texture->getRefTexture().allocLevel(levelNdx); 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::copy(texture->getRefTexture().getLevel(levelNdx), level.getAccess()); 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Upload data. 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry texture->upload(); 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry catch (const std::exception&) 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete texture; 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw; 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return texture; 2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (ext == "pkm") 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compressed texture. 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<tcu::CompressedTexture> levels(numLevels); 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < numLevels; ndx++) 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ImageIO::loadPKM(levels[ndx], archive, levelFileNames[ndx]); 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return new Texture2D(context, contextInfo, numLevels, &levels[0]); 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_FAIL("Unsupported file format"); 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2753c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2D* Texture2D::create (const RenderContext& context, const ContextInfo& contextInfo, const tcu::Archive& archive, int numLevels, const std::vector<std::string>& filenames) 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(numLevels == (int)filenames.size()); 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<const char*> charPtrs(filenames.size()); 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < (int)filenames.size(); ndx++) 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry charPtrs[ndx] = filenames[ndx].c_str(); 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return Texture2D::create(context, contextInfo, archive, numLevels, &charPtrs[0]); 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// TextureCube 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 288becd5d53015521acf7536ba754de326d8b1da2f3Mika IsojärviTextureCube::TextureCube (const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams) 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_context (context) 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_isCompressed (true) 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (getGLFormat(levels[0].getFormat())) 292becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi , m_refTexture (getUncompressedFormat(levels[0].getFormat()), levels[0].getWidth()) 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glTexture (0) 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK_INTERNAL(levels[0].getWidth() == levels[0].getHeight()); 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!contextInfo.isCompressedTextureFormatSupported(m_format)) 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("Compressed texture format not supported", "", __FILE__, __LINE__); 3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genTextures(1, &m_glTexture); 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); 3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry try 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry loadCompressed(numLevels, levels, decompressionParams); 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry catch (const std::exception&) 3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.deleteTextures(1, &m_glTexture); 3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw; 3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3163c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureCube::TextureCube (const RenderContext& context, deUint32 format, deUint32 dataType, int size) 3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_context (context) 3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_isCompressed (false) 3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (format) 3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_refTexture (mapGLTransferFormat(format, dataType), size) 3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glTexture (0) 3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genTextures(1, &m_glTexture); 3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); 3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3283c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureCube::TextureCube (const RenderContext& context, deUint32 internalFormat, int size) 3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_context (context) 3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_isCompressed (false) 3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (internalFormat) 3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_refTexture (mapGLInternalFormat(internalFormat), size) 3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glTexture (0) 3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genTextures(1, &m_glTexture); 3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); 3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3403c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureCube::~TextureCube (void) 3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_glTexture) 3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_context.getFunctions().deleteTextures(1, &m_glTexture); 3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureCube::upload (void) 3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(!m_isCompressed); 3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(m_glTexture); 3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_CUBE_MAP, m_glTexture); 3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.pixelStorei(GL_UNPACK_ALIGNMENT, computePixelStore(m_refTexture.getFormat())); 3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); 3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TransferFormat transferFormat = getTransferFormat(m_refTexture.getFormat()); 3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int face = 0; face < tcu::CUBEFACE_LAST; face++) 3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < m_refTexture.getNumLevels(); levelNdx++) 3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_refTexture.isLevelEmpty((tcu::CubeFace)face, levelNdx)) 3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; // Don't upload. 3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ConstPixelBufferAccess access = m_refTexture.getLevelFace(levelNdx, (tcu::CubeFace)face); 3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(access.getRowPitch() == access.getFormat().getPixelSize()*access.getWidth()); 36807b89ce0885a4a9e02b7057d45a4260d24740ba9Mika Isojärvi gl.texImage2D(getGLCubeFace((tcu::CubeFace)face), levelNdx, m_format, access.getWidth(), access.getHeight(), 0 /* border */, transferFormat.format, transferFormat.dataType, access.getDataPtr()); 3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); 3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 375becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvivoid TextureCube::loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams) 3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 compressedFormat = getGLFormat(levels[0].getFormat()); 3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(m_glTexture); 3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_CUBE_MAP, m_glTexture); 3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) 3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int face = 0; face < tcu::CUBEFACE_LAST; face++) 3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::CompressedTexture& level = levels[levelNdx*tcu::CUBEFACE_LAST + face]; 3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Decompress to reference texture. 3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_refTexture.allocLevel((tcu::CubeFace)face, levelNdx); 3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::PixelBufferAccess refLevelAccess = m_refTexture.getLevelFace(levelNdx, (tcu::CubeFace)face); 3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(level.getWidth() == refLevelAccess.getWidth() && 3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry level.getHeight() == refLevelAccess.getHeight()); 3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry level.decompress(refLevelAccess, decompressionParams); 3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Upload to GL texture in compressed form. 39707b89ce0885a4a9e02b7057d45a4260d24740ba9Mika Isojärvi gl.compressedTexImage2D(getGLCubeFace((tcu::CubeFace)face), levelNdx, compressedFormat, 3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry level.getWidth(), level.getHeight(), 0 /* border */, level.getDataSize(), level.getData()); 3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); 4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4053c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureCube* TextureCube::create (const RenderContext& context, const ContextInfo& contextInfo, const tcu::Archive& archive, int numLevels, const char* const* filenames) 4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(numLevels > 0); 4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string ext = de::FilePath(filenames[0]).getFileExtension(); 4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \todo [2011-11-21 pyry] Support PNG images. 4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (ext == "pkm") 4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compressed texture. 4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int numImages = numLevels*tcu::CUBEFACE_LAST; 4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<tcu::CompressedTexture> levels (numImages); 4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < numImages; ndx++) 4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ImageIO::loadPKM(levels[ndx], archive, filenames[ndx]); 4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return new TextureCube(context, contextInfo, numLevels, &levels[0]); 4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_FAIL("Unsupported file format"); 4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4273c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureCube* TextureCube::create (const RenderContext& context, const ContextInfo& contextInfo, const tcu::Archive& archive, int numLevels, const std::vector<std::string>& filenames) 4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_STATIC_ASSERT(tcu::CUBEFACE_LAST == 6); 4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(numLevels*tcu::CUBEFACE_LAST == (int)filenames.size()); 4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<const char*> charPtrs(filenames.size()); 4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < (int)filenames.size(); ndx++) 4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry charPtrs[ndx] = filenames[ndx].c_str(); 4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return TextureCube::create(context, contextInfo, archive, numLevels, &charPtrs[0]); 4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Texture1DArray 4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4413c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture1DArray::Texture1DArray (const RenderContext& context, deUint32 format, deUint32 dataType, int width, int numLevels) 4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_context (context) 4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (format) 4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_refTexture (mapGLTransferFormat(format, dataType), width, numLevels) 4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glTexture (0) 4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genTextures(1, &m_glTexture); 4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); 4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4523c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture1DArray::Texture1DArray (const RenderContext& context, deUint32 sizedFormat, int width, int numLevels) 4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_context (context) 4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (sizedFormat) 4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_refTexture (mapGLInternalFormat(sizedFormat), width, numLevels) 4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glTexture (0) 4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genTextures(1, &m_glTexture); 4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); 4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4633c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture1DArray::~Texture1DArray (void) 4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_glTexture) 4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_context.getFunctions().deleteTextures(1, &m_glTexture); 4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture1DArray::upload (void) 4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(m_glTexture); 4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_1D_ARRAY, m_glTexture); 4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.pixelStorei(GL_UNPACK_ALIGNMENT, computePixelStore(m_refTexture.getFormat())); 4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); 4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TransferFormat transferFormat = getTransferFormat(m_refTexture.getFormat()); 4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < m_refTexture.getNumLevels(); levelNdx++) 4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_refTexture.isLevelEmpty(levelNdx)) 4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; // Don't upload. 4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ConstPixelBufferAccess access = m_refTexture.getLevel(levelNdx); 4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(access.getRowPitch() == access.getFormat().getPixelSize()*access.getWidth()); 4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texImage2D(GL_TEXTURE_1D_ARRAY, levelNdx, m_format, access.getWidth(), access.getHeight(), 0 /* border */, transferFormat.format, transferFormat.dataType, access.getDataPtr()); 4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); 4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Texture2DArray 4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4953c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2DArray::Texture2DArray (const RenderContext& context, deUint32 format, deUint32 dataType, int width, int height, int numLevels) 4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_context (context) 497becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi , m_isCompressed (false) 4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (format) 4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_refTexture (mapGLTransferFormat(format, dataType), width, height, numLevels) 5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glTexture (0) 5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \todo [2013-04-08 pyry] Check support here. 5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genTextures(1, &m_glTexture); 5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); 5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5083c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2DArray::Texture2DArray (const RenderContext& context, deUint32 sizedFormat, int width, int height, int numLevels) 5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_context (context) 510becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi , m_isCompressed (false) 5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (sizedFormat) 5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_refTexture (mapGLInternalFormat(sizedFormat), width, height, numLevels) 5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glTexture (0) 5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \todo [2013-04-08 pyry] Check support here. 5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genTextures(1, &m_glTexture); 5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); 5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 521becd5d53015521acf7536ba754de326d8b1da2f3Mika IsojärviTexture2DArray::Texture2DArray (const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams) 522becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi : m_context (context) 523becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi , m_isCompressed (true) 524becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi , m_format (getGLFormat(levels[0].getFormat())) 525becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi , m_refTexture (getUncompressedFormat(levels[0].getFormat()), levels[0].getWidth(), levels[0].getHeight(), levels[0].getDepth()) 526becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi , m_glTexture (0) 527becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi{ 528becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi const glw::Functions& gl = context.getFunctions(); 529becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi 530becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi if (!contextInfo.isCompressedTextureFormatSupported(m_format)) 531becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi throw tcu::NotSupportedError("Compressed texture format not supported", "", __FILE__, __LINE__); 532becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi 533becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi gl.genTextures(1, &m_glTexture); 534becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); 535becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi 536becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi try 537becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi { 538becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi loadCompressed(numLevels, levels, decompressionParams); 539becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi } 540becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi catch (const std::exception&) 541becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi { 542becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi gl.deleteTextures(1, &m_glTexture); 543becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi throw; 544becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi } 545becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi} 546becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi 5473c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2DArray::~Texture2DArray (void) 5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_glTexture) 5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_context.getFunctions().deleteTextures(1, &m_glTexture); 5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DArray::upload (void) 5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!gl.texImage3D) 5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("glTexImage3D() is not supported"); 5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(m_glTexture); 5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_2D_ARRAY, m_glTexture); 5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.pixelStorei(GL_UNPACK_ALIGNMENT, computePixelStore(m_refTexture.getFormat())); 5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); 5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TransferFormat transferFormat = getTransferFormat(m_refTexture.getFormat()); 5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < m_refTexture.getNumLevels(); levelNdx++) 5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_refTexture.isLevelEmpty(levelNdx)) 5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; // Don't upload. 5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ConstPixelBufferAccess access = m_refTexture.getLevel(levelNdx); 5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(access.getRowPitch() == access.getFormat().getPixelSize()*access.getWidth()); 5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(access.getSlicePitch() == access.getFormat().getPixelSize()*access.getWidth()*access.getHeight()); 5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texImage3D(GL_TEXTURE_2D_ARRAY, levelNdx, m_format, access.getWidth(), access.getHeight(), access.getDepth(), 0 /* border */, transferFormat.format, transferFormat.dataType, access.getDataPtr()); 5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); 5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 581becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvivoid Texture2DArray::loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams) 582becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi{ 583becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi const glw::Functions& gl = m_context.getFunctions(); 584becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi deUint32 compressedFormat = getGLFormat(levels[0].getFormat()); 585becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi 586becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi TCU_CHECK(m_glTexture); 587becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi gl.bindTexture(GL_TEXTURE_2D_ARRAY, m_glTexture); 588becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi 589becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) 590becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi { 591becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi const tcu::CompressedTexture& level = levels[levelNdx]; 592becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi 593becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi // Decompress to reference texture. 594becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi m_refTexture.allocLevel(levelNdx); 595becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi tcu::PixelBufferAccess refLevelAccess = m_refTexture.getLevel(levelNdx); 596becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi TCU_CHECK(level.getWidth() == refLevelAccess.getWidth() && 597becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi level.getHeight() == refLevelAccess.getHeight() && 598becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi level.getDepth() == refLevelAccess.getDepth()); 599becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi level.decompress(refLevelAccess, decompressionParams); 600becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi 601becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi // Upload to GL texture in compressed form. 602becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi gl.compressedTexImage3D(GL_TEXTURE_2D_ARRAY, levelNdx, compressedFormat, 603becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi level.getWidth(), level.getHeight(), m_refTexture.getLevel(levelNdx).getDepth(), 0 /* border */, level.getDataSize(), level.getData()); 604becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi } 605becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi 606becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); 607becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi} 608becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi 6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Texture3D 6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6113c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture3D::Texture3D (const RenderContext& context, deUint32 format, deUint32 dataType, int width, int height, int depth) 6123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_context (context) 6137785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry , m_isCompressed (false) 6143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (format) 6153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_refTexture (mapGLTransferFormat(format, dataType), width, height, depth) 6163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glTexture (0) 6173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \todo [2013-04-08 pyry] Check support here. 6193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 6203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genTextures(1, &m_glTexture); 6213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); 6223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6243c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture3D::Texture3D (const RenderContext& context, deUint32 sizedFormat, int width, int height, int depth) 6253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_context (context) 6267785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry , m_isCompressed (false) 6273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (sizedFormat) 6283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_refTexture (mapGLInternalFormat(sizedFormat), width, height, depth) 6293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glTexture (0) 6303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \todo [2013-04-08 pyry] Check support here. 6323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 6333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genTextures(1, &m_glTexture); 6343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); 6353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6377785313bbe673ac62d24612fdb72be3248772f29Jarkko PöyryTexture3D::Texture3D (const RenderContext& context, 6387785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry const ContextInfo& contextInfo, 6397785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry int numLevels, 6407785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry const tcu::CompressedTexture* levels, 6417785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry const tcu::TexDecompressionParams& decompressionParams) 6427785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry : m_context (context) 6437785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry , m_isCompressed (true) 6447785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry , m_format (getGLFormat(levels[0].getFormat())) 6457785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry , m_refTexture (getUncompressedFormat(levels[0].getFormat()), levels[0].getWidth(), levels[0].getHeight(), levels[0].getDepth()) 6467785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry , m_glTexture (0) 6477785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry{ 6487785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry const glw::Functions& gl = context.getFunctions(); 6497785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry 6507785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry if (!contextInfo.isCompressedTextureFormatSupported(m_format)) 6517785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry throw tcu::NotSupportedError("Compressed texture format not supported", "", __FILE__, __LINE__); 6527785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry 6537785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry gl.genTextures(1, &m_glTexture); 6547785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); 6557785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry 6567785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry try 6577785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry { 6587785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry loadCompressed(numLevels, levels, decompressionParams); 6597785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry } 6607785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry catch (const std::exception&) 6617785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry { 6627785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry gl.deleteTextures(1, &m_glTexture); 6637785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry throw; 6647785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry } 6657785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry} 6667785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry 6673c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture3D::~Texture3D (void) 6683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_glTexture) 6703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_context.getFunctions().deleteTextures(1, &m_glTexture); 6713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6733c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture3D::upload (void) 6743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 6763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6777785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry DE_ASSERT(!m_isCompressed); 6787785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry 6793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!gl.texImage3D) 6803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("glTexImage3D() is not supported"); 6813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(m_glTexture); 6833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_3D, m_glTexture); 6843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.pixelStorei(GL_UNPACK_ALIGNMENT, computePixelStore(m_refTexture.getFormat())); 6853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); 6863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TransferFormat transferFormat = getTransferFormat(m_refTexture.getFormat()); 6883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < m_refTexture.getNumLevels(); levelNdx++) 6903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_refTexture.isLevelEmpty(levelNdx)) 6923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; // Don't upload. 6933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ConstPixelBufferAccess access = m_refTexture.getLevel(levelNdx); 6953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(access.getRowPitch() == access.getFormat().getPixelSize()*access.getWidth()); 6963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(access.getSlicePitch() == access.getFormat().getPixelSize()*access.getWidth()*access.getHeight()); 6973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texImage3D(GL_TEXTURE_3D, levelNdx, m_format, access.getWidth(), access.getHeight(), access.getDepth(), 0 /* border */, transferFormat.format, transferFormat.dataType, access.getDataPtr()); 6983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); 7013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7037785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyryvoid Texture3D::loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams) 7047785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry{ 7057785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry const glw::Functions& gl = m_context.getFunctions(); 7067785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry deUint32 compressedFormat = getGLFormat(levels[0].getFormat()); 7077785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry 7087785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry if (!gl.compressedTexImage3D) 7097785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry throw tcu::NotSupportedError("glCompressedTexImage3D() is not supported"); 7107785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry 7117785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry TCU_CHECK(m_glTexture); 7127785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry gl.bindTexture(GL_TEXTURE_3D, m_glTexture); 7137785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry 7147785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) 7157785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry { 7167785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry const tcu::CompressedTexture& level = levels[levelNdx]; 7177785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry 7187785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry // Decompress to reference texture. 7197785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry m_refTexture.allocLevel(levelNdx); 7207785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry tcu::PixelBufferAccess refLevelAccess = m_refTexture.getLevel(levelNdx); 7217785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry TCU_CHECK(level.getWidth() == refLevelAccess.getWidth() && 7227785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry level.getHeight() == refLevelAccess.getHeight() && 7237785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry level.getDepth() == refLevelAccess.getDepth()); 7247785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry level.decompress(refLevelAccess, decompressionParams); 7257785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry 7267785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry // Upload to GL texture in compressed form. 7277785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry gl.compressedTexImage3D(GL_TEXTURE_3D, levelNdx, compressedFormat, 7287785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry level.getWidth(), level.getHeight(), level.getDepth(), 0 /* border */, level.getDataSize(), level.getData()); 7297785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry } 7307785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry 7317785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); 7327785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry} 7337785313bbe673ac62d24612fdb72be3248772f29Jarkko Pöyry 7343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// TextureCubeArray 7353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7363c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureCubeArray::TextureCubeArray (const RenderContext& context, deUint32 format, deUint32 dataType, int size, int numLayers) 7373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_context (context) 7383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (format) 7393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_refTexture (mapGLTransferFormat(format, dataType), size, numLayers) 7403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glTexture (0) 7413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \todo [2013-04-08 pyry] Check support here. 7433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 7443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genTextures(1, &m_glTexture); 7453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); 7463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7483c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureCubeArray::TextureCubeArray (const RenderContext& context, deUint32 sizedFormat, int size, int numLayers) 7493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_context (context) 7503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (sizedFormat) 7513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_refTexture (mapGLInternalFormat(sizedFormat), size, numLayers) 7523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glTexture (0) 7533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \todo [2013-04-08 pyry] Check support here. 7553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 7563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genTextures(1, &m_glTexture); 7573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); 7583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7603c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureCubeArray::~TextureCubeArray (void) 7613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_glTexture) 7633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_context.getFunctions().deleteTextures(1, &m_glTexture); 7643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7663c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureCubeArray::upload (void) 7673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 7693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!gl.texImage3D) 7713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("glTexImage3D() is not supported"); 7723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(m_glTexture); 7743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, m_glTexture); 7753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.pixelStorei(GL_UNPACK_ALIGNMENT, computePixelStore(m_refTexture.getFormat())); 7763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); 7773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TransferFormat transferFormat = getTransferFormat(m_refTexture.getFormat()); 7793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < m_refTexture.getNumLevels(); levelNdx++) 7813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_refTexture.isLevelEmpty(levelNdx)) 7833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; // Don't upload. 7843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ConstPixelBufferAccess access = m_refTexture.getLevel(levelNdx); 7863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(access.getRowPitch() == access.getFormat().getPixelSize()*access.getWidth()); 7873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(access.getSlicePitch() == access.getFormat().getPixelSize()*access.getWidth()*access.getHeight()); 7883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, levelNdx, m_format, access.getWidth(), access.getHeight(), access.getDepth(), 0 /* border */, transferFormat.format, transferFormat.dataType, access.getDataPtr()); 7893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); 7923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// TextureBuffer 7953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7963c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureBuffer::TextureBuffer (const RenderContext& context, deUint32 internalFormat, size_t bufferSize) 7973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_context (context) 7983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (0) 7993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_offset (0) 8003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_size (0) 8013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glTexture (0) 8023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glBuffer (0) 8033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 8043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry init(internalFormat, bufferSize, 0, 0, DE_NULL); 8053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 8063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8073c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureBuffer::TextureBuffer (const RenderContext& context, deUint32 internalFormat, size_t bufferSize, size_t offset, size_t size, const void* data) 8083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_context (context) 8093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (0) 8103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_offset (0) 8113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_size (0) 8123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glTexture (0) 8133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_glBuffer (0) 8143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 8153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry init(internalFormat, bufferSize, offset, size, data); 8163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 8173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8183c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureBuffer::init (deUint32 internalFormat, size_t bufferSize, size_t offset, size_t size, const void* data) 8193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 8203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getFunctions(); 8213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::UniquePtr<ContextInfo> info (ContextInfo::create(m_context)); 8223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (offset != 0 || size != 0) 8243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!(contextSupports(m_context.getType(), glu::ApiType(3, 3, glu::PROFILE_CORE)) && info->isExtensionSupported("GL_ARB_texture_buffer_range")) 8263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry && !(contextSupports(m_context.getType(), glu::ApiType(3, 1, glu::PROFILE_ES)) 8273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry && info->isExtensionSupported("GL_EXT_texture_buffer"))) 8283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("Ranged texture buffers not supported", "", __FILE__, __LINE__); 8303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 8333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!contextSupports(m_context.getType(), glu::ApiType(3, 3, glu::PROFILE_CORE)) 8353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry && !(contextSupports(m_context.getType(), glu::ApiType(3, 1, glu::PROFILE_ES)) 8363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry && info->isExtensionSupported("GL_EXT_texture_buffer"))) 8373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("Texture buffers not supported", "", __FILE__, __LINE__); 8393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 84212fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry m_refBuffer.setStorage(bufferSize); 8433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (data) 84412fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry deMemcpy(m_refBuffer.getPtr(), data, (int)bufferSize); 8453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_format = internalFormat; 8473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_offset = offset; 8483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_size = size; 8493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(size != 0 || offset == 0); 8513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genTextures(1, &m_glTexture); 8543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); 8553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genBuffers(1, &m_glBuffer); 8573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers() failed"); 8583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_TEXTURE_BUFFER, m_glBuffer); 86012fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry gl.bufferData(GL_TEXTURE_BUFFER, (glw::GLsizei)m_refBuffer.size(), data, GL_STATIC_DRAW); 8613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_TEXTURE_BUFFER, 0); 8623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to create buffer"); 8633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_BUFFER, m_glTexture); 8653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (offset != 0 || size != 0) 8673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texBufferRange(GL_TEXTURE_BUFFER, m_format, m_glBuffer, (glw::GLintptr)m_offset, (glw::GLsizeiptr)m_size); 8683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 8693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texBuffer(GL_TEXTURE_BUFFER, m_format, m_glBuffer); 8703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_BUFFER, 0); 8723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to bind buffer to texture"); 8733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 8753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8763c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureBuffer::~TextureBuffer (void) 8773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 8783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_glTexture) 8793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_context.getFunctions().deleteTextures(1, &m_glTexture); 8803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_glBuffer) 8823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_context.getFunctions().deleteBuffers(1, &m_glBuffer); 8833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 8843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 88512fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry 88612fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyryconst tcu::PixelBufferAccess TextureBuffer::getFullRefTexture (void) 8873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 88812fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const tcu::TextureFormat format = mapGLInternalFormat(m_format); 88912fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const size_t bufferLengthBytes = (m_size != 0) ? (m_size) : (m_refBuffer.size()); 89012fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const int bufferLengthPixels = (int)bufferLengthBytes / format.getPixelSize(); 8913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 89212fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry return tcu::PixelBufferAccess(format, 89312fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry tcu::IVec3(bufferLengthPixels, 1, 1), 89412fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry (deUint8*)m_refBuffer.getPtr() + m_offset); 8953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 8963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 89712fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyryconst tcu::ConstPixelBufferAccess TextureBuffer::getFullRefTexture (void) const 8983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 89912fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry return const_cast<TextureBuffer*>(this)->getFullRefTexture(); 90012fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry} 9013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 90212fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyryvoid TextureBuffer::upload (void) 90312fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry{ 90412fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const glw::Functions& gl = m_context.getFunctions(); 9053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 90612fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry gl.bindBuffer(GL_TEXTURE_BUFFER, m_glBuffer); 90712fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry gl.bufferData(GL_TEXTURE_BUFFER, (glw::GLsizei)m_refBuffer.size(), m_refBuffer.getPtr(), GL_STATIC_DRAW); 90812fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry gl.bindBuffer(GL_TEXTURE_BUFFER, 0); 90912fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to upload buffer"); 9103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 9113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // glu 913