示例#1
0
static bool
test_cube_array_texture(void)
{
	const GLint width = 16, height = 16;
	const GLenum target = GL_TEXTURE_CUBE_MAP_ARRAY;
	GLuint tex;
	bool pass = true;

	/* Test valid cube array dimensions */
	glCreateTextures(target, 1, &tex);
	glBindTextureUnit(0, tex);
	glTextureStorage3D(tex, 1, GL_RGBA8, width, height, 12);
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
	glDeleteTextures(1, &tex);

	if (!piglit_khr_no_error) {
		/* Test invalid cube array width, height dimensions */
		glCreateTextures(target, 1, &tex);
		glBindTextureUnit(0, tex);
		glTextureStorage3D(tex, 1, GL_RGBA8, width, height+3, 12);
		pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
		glDeleteTextures(1, &tex);

		/* Test invalid cube array depth */
		glCreateTextures(target, 1, &tex);
		glBindTextureUnit(0, tex);
		glTextureStorage3D(tex, 1, GL_RGBA8, width, height, 12+2);
		pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
		glDeleteTextures(1, &tex);
	}

	return pass;
}
void Texture2DArray::pushToGPU(bool deleteAfterPush) {
	glTextureStorage3D(name, mipmapLevels, images[0].format.sizedFormat, images[0].width, images[0].height, images.size()); //allocate space for all

	for (unsigned int i = 0; i < images.size(); ++i) {
		ImageData &imageData = images[i];

		if (imageData.data != 0)
			glTextureSubImage3D(name,
				0,
				0, 0, i,
				imageData.width, imageData.height, 1,
				imageData.format.baseFormat, imageData.format.type, imageData.data);

		if (deleteAfterPush) {
			delete[] imageData.data;
			imageData.data = 0;
		}
	}

	if (mipmapLevels > 1) {
		glGenerateTextureMipmap(name); //generate the remaining mipmaps
		glTextureParameterf(name, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	}
	else
		glTextureParameterf(name, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	glTextureParameterf(name, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	glTextureParameterf(name, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTextureParameterf(name, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
	bool initTexture()
	{
		bool Validated(true);

		gli::gl GL;
		gli::texture2d Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str()));
		gli::gl::format const Format = GL.translate(Texture.format());

		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

		glCreateTextures(GL_TEXTURE_2D_ARRAY, 1, &TextureName);
		glTextureParameteri(TextureName, GL_TEXTURE_SWIZZLE_R, GL_RED);
		glTextureParameteri(TextureName, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
		glTextureParameteri(TextureName, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
		glTextureParameteri(TextureName, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
		glTextureParameteri(TextureName, GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName, GL_TEXTURE_MAX_LEVEL, static_cast<GLint>(Texture.levels() - 1));
		glTextureParameteri(TextureName, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glTextureParameteri(TextureName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

		glTextureStorage3D(TextureName, static_cast<GLint>(Texture.levels()),
			Format.Internal,
			static_cast<GLsizei>(Texture[0].extent().x), static_cast<GLsizei>(Texture[0].extent().y), static_cast<GLsizei>(1));

		for(gli::texture2d::size_type Level = 0; Level < Texture.levels(); ++Level)
		{
			glTextureSubImage3D(TextureName, static_cast<GLint>(Level),
				0, 0, 0,
				static_cast<GLsizei>(Texture[Level].extent().x), static_cast<GLsizei>(Texture[Level].extent().y), static_cast<GLsizei>(1),
				Format.External, Format.Type,
				Texture[Level].data());
		}
	
		return Validated;
	}
GLuint glCreateTextureGTC(GLenum target, GLsizei layers, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei samples, GLboolean fixedsamplelocations)
{
	GLuint texture = 0;
	glCreateTextures(target, 1, &texture);
	glTextureParameteri(texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTextureParameteri(texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

	switch (target)
	{
	case GL_TEXTURE_2D:
		assert(layers == 1 && width >= 1 && height >= 1 && depth == 1 && samples == 1 && fixedsamplelocations == GL_TRUE);
		glTextureStorage2D(texture, levels, internalformat, width, height);
		break;
	case GL_TEXTURE_2D_ARRAY:
		assert(layers >= 1 && width >= 1 && height >= 1 && depth == 1 && samples == 1 && fixedsamplelocations == GL_TRUE);
		glTextureStorage3D(texture, levels, internalformat, width, height, layers);
		break;
	case GL_TEXTURE_2D_MULTISAMPLE:
		assert(layers == 1 && width >= 1 && height >= 1 && depth == 1 && samples >= 1);
		glTextureStorage2DMultisample(texture, samples, internalformat, width, height, fixedsamplelocations);
		break;
	case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
		assert(layers >= 1 && width >= 1 && height >= 1 && depth == 1 && samples >= 1);
		glTextureStorage3DMultisample(texture, samples, internalformat, width, height, layers, fixedsamplelocations);
		break;
	case GL_TEXTURE_3D:
		assert(layers == 1 && width >= 1 && height >= 1 && depth >= 1 && samples == 1 && fixedsamplelocations == GL_TRUE);
		glTextureStorage3D(texture, levels, internalformat, width, height, depth);
		break;
	case GL_TEXTURE_CUBE_MAP:
		assert(layers == 1 && width >= 1 && height >= 1 && depth == 1 && samples == 1 && fixedsamplelocations == GL_TRUE);
		glTextureStorage2D(texture, levels, internalformat, width, height);
		break;
	case GL_TEXTURE_CUBE_MAP_ARRAY:
		assert(layers >= 1 && width >= 1 && height >= 1 && depth == 1 && samples == 1 && fixedsamplelocations == GL_TRUE);
		glTextureStorage3D(texture, levels, internalformat, width, height, layers * 6);
		break;
	}

	return texture;
}
	bool initTexture()
	{
		gli::texture2d Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str()));
		assert(!Texture.empty());

		glm::uvec2 FramebufferSize(this->getWindowSize() / 16u);

		glCreateTextures(GL_TEXTURE_2D_ARRAY, texture::MAX, &TextureName[0]);
		glTextureParameteri(TextureName[0], GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName[0], GL_TEXTURE_MAX_LEVEL, 0);
		glTextureParameteri(TextureName[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTextureParameteri(TextureName[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTextureStorage3D(TextureName[0], GLint(1), GL_RGBA8, GLsizei(FramebufferSize.x), GLsizei(FramebufferSize.y), 1);

		return true;
	}
示例#6
0
kit::Texture::Ptr kit::Texture::create3DFromFile(std::string filename, kit::Texture::InternalFormat format, kit::Texture::EdgeSamplingMode edgemode, kit::Texture::FilteringMode minfilter, kit::Texture::FilteringMode magfilter)
{
  kit::Texture::Ptr returner = std::make_shared<kit::Texture>(Texture3D);
  returner->m_internalFormat = format;

  // Try to load data from file
  unsigned char* bufferdata;
  int x, y, n;

  stbi_set_flip_vertically_on_load(0);
  bufferdata = stbi_load(filename.c_str(), &x, &y, &n, 4);
  if (bufferdata == nullptr) {
    KIT_ERR(stbi_failure_reason());
    return nullptr;
  }

  if (y != x*x || y%y != 0)
  {
    KIT_ERR("Failed to load 3d texture from file, not perfectly cubical");
  }

  // Set resolution
  returner->m_resolution = glm::uvec3(x, x, x);

  // Specify storage and upload data to GPU
  KIT_GL(glTextureStorage3D(returner->m_glHandle, 1, returner->m_internalFormat, x, x, x));
  KIT_GL(glTextureSubImage3D(returner->m_glHandle, 0, 0, 0, 0, x, x, x, GL_RGBA, GL_UNSIGNED_BYTE, bufferdata));

  // Free loaded data
  stbi_image_free(bufferdata);

  // Set parameters
  returner->setEdgeSamplingMode(edgemode);
  returner->setMinFilteringMode(minfilter);
  returner->setMagFilteringMode(magfilter);

  // Generate mipmap
  //returner->generateMipmap();

  return returner;
}
	bool initTexture()
	{
		bool Validated(true);

		gli::gl GL(gli::gl::PROFILE_GL33);

		gli::texture2d Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str()));
		assert(!Texture.empty());

		gli::gl::format const Format = GL.translate(Texture.format(), Texture.swizzles());

		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
		glCreateTextures(GL_TEXTURE_2D_ARRAY, 1, &TextureName);
		glTextureParameteri(TextureName, GL_TEXTURE_SWIZZLE_R, Format.Swizzles[0]);
		glTextureParameteri(TextureName, GL_TEXTURE_SWIZZLE_G, Format.Swizzles[1]);
		glTextureParameteri(TextureName, GL_TEXTURE_SWIZZLE_B, Format.Swizzles[2]);
		glTextureParameteri(TextureName, GL_TEXTURE_SWIZZLE_A, Format.Swizzles[3]);
		glTextureParameteri(TextureName, GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName, GL_TEXTURE_MAX_LEVEL, GLint(Texture.levels() - 1));
		glTextureParameteri(TextureName, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glTextureParameteri(TextureName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTextureStorage3D(TextureName, static_cast<GLint>(Texture.levels()), Format.Internal,
			static_cast<GLsizei>(Texture.extent().x), static_cast<GLsizei>(Texture.extent().y), 1);

		for(gli::texture2d::size_type Level(0); Level < Texture.levels(); ++Level)
		{
			glTextureSubImage3D(TextureName, static_cast<GLint>(Level),
				0, 0, 0,
				static_cast<GLsizei>(Texture[Level].extent().x), static_cast<GLsizei>(Texture[Level].extent().y), 1,
				Format.External, Format.Type,
				Texture[Level].data());
		}

		glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

		// Query the texture handle and make the texture resident
		TextureHandle = glGetTextureHandleNV(TextureName);
		glMakeTextureHandleResidentNV(TextureHandle);

		return Validated;
	}
示例#8
0
bool glPixelBuffer::create(GLushort width, GLushort height, GLushort depth,
                           GFXImageFormat formatEnum,
                           GFXDataFormat dataTypeEnum) {
    GLenum textureTypeEnum = GLUtil::glTextureTypeTable[to_U32(_textureType)];
    _internalFormat = GLUtil::internalFormat(formatEnum, dataTypeEnum, false);
    _format = GLUtil::glImageFormatTable[to_U32(formatEnum)];
    _dataType = GLUtil::glDataFormat[to_U32(dataTypeEnum)];

    Console::printfn(Locale::get(_ID("GL_PB_GEN")), width, height);
    _width = width;
    _height = height;
    _depth = depth;

    _bufferSize = _width * 4;
    switch (_pbtype) {
        case PBType::PB_TEXTURE_2D:
            _bufferSize *= _height;
            break;
        case PBType::PB_TEXTURE_3D:
            _bufferSize *= _height * _depth;
            break;
    };

    switch (_dataType) {
        case GL_SHORT:
        case GL_HALF_FLOAT:
        case GL_UNSIGNED_SHORT:
            _dataSizeBytes = 2;
            break;
        case GL_FLOAT:
        case GL_INT:
        case GL_UNSIGNED_INT:
            _dataSizeBytes = 4;
            break;
        default:
            break;
    }
    _bufferSize *= _dataSizeBytes;

    GL_API::deleteTextures(1, &_textureID, _textureType);

    glCreateTextures(textureTypeEnum, 1, &_textureID);
    glTextureParameteri(_textureID, GL_GENERATE_MIPMAP, 0);
    glTextureParameteri(_textureID, GL_TEXTURE_MIN_FILTER, to_I32(GL_NEAREST));
    glTextureParameteri(_textureID, GL_TEXTURE_MAG_FILTER, to_I32(GL_NEAREST));
    glTextureParameteri(_textureID, GL_TEXTURE_BASE_LEVEL, 0);
    glTextureParameteri(_textureID, GL_TEXTURE_MAX_LEVEL, 1000);
    glTextureParameteri(_textureID, GL_TEXTURE_WRAP_S, to_I32(GL_REPEAT));

    if (_pbtype != PBType::PB_TEXTURE_1D) {
        glTextureParameteri(_textureID, GL_TEXTURE_WRAP_T, to_I32(GL_REPEAT));
    }
    if (_pbtype == PBType::PB_TEXTURE_3D) {
        glTextureParameteri(_textureID, GL_TEXTURE_WRAP_R, to_I32(GL_REPEAT));
    }

    U16 mipLevels = to_U16(std::floor(std::log2(std::max(_width, _height))) + 1);
    GL_API::getStateTracker().setPixelPackUnpackAlignment();
    switch (_pbtype) {
        case PBType::PB_TEXTURE_1D:
            glTextureStorage1D(_textureID, mipLevels, _internalFormat, _width);
            break;
        case PBType::PB_TEXTURE_2D:
            glTextureStorage2D(_textureID, mipLevels, _internalFormat, _width, _height);
            break;
        case PBType::PB_TEXTURE_3D:
            glTextureStorage3D(_textureID, mipLevels, _internalFormat, _width, _height, _depth);
            break;
    };

    if (_pixelBufferHandle > 0) {
        GLUtil::freeBuffer(_pixelBufferHandle);
    }

    GLUtil::createAndAllocBuffer(_bufferSize, GL_STREAM_DRAW, _pixelBufferHandle, NULL, _name.empty() ? nullptr : _name.c_str());

    return _pixelBufferHandle != 0 && _textureID != 0;
}
示例#9
0
文件: tex2darray.cpp 项目: TdroL/pr0
void Tex2DArray::reload()
{
	double timer = ngn::time();

	reset();

	// RN_CHECK(glGenTextures(1, &id));

	// RN_CHECK(glBindTexture(GL_TEXTURE_2D_ARRAY, id));

	RN_CHECK(glCreateTextures(GL_TEXTURE_2D_ARRAY, 1, &id));

	// RN_CHECK_PARAM(glTextureParameteri(id, GL_TEXTURE_MIN_FILTER, minFilter), rn::getEnumName(minFilter));
	// RN_CHECK_PARAM(glTextureParameteri(id, GL_TEXTURE_MAG_FILTER, magFilter), rn::getEnumName(magFilter));
	// RN_CHECK_PARAM(glTextureParameteri(id, GL_TEXTURE_WRAP_S, wrapS), rn::getEnumName(wrapS));
	// RN_CHECK_PARAM(glTextureParameteri(id, GL_TEXTURE_WRAP_T, wrapT), rn::getEnumName(wrapT));

	setParam(GL_TEXTURE_MIN_FILTER, minFilter);
	setParam(GL_TEXTURE_MAG_FILTER, magFilter);
	setParam(GL_TEXTURE_WRAP_S, wrapS);
	setParam(GL_TEXTURE_WRAP_T, wrapT);

	// RN_CHECK(glTextureParameterfv(id, GL_TEXTURE_BORDER_COLOR, glm::value_ptr(borderColor)));
	setParam(GL_TEXTURE_BORDER_COLOR, glm::value_ptr(borderColor));

	if (mipLevels > 0)
	{
		// RN_CHECK_PARAM(glTextureParameteri(id, GL_TEXTURE_MAX_LEVEL, mipLevels), mipLevels);
		setParam(GL_TEXTURE_MAX_LEVEL, mipLevels);
	}

	switch (internalFormat)
	{
		case GL_DEPTH_COMPONENT:
			format = GL_DEPTH_COMPONENT;
			type = GL_UNSIGNED_INT;
		break;
		case GL_DEPTH_COMPONENT16:
			format = GL_DEPTH_COMPONENT;
			type = GL_UNSIGNED_INT;
		break;
		case GL_DEPTH_COMPONENT24:
			format = GL_DEPTH_COMPONENT;
			type = GL_UNSIGNED_INT;
		break;
		case GL_DEPTH_COMPONENT32:
			format = GL_DEPTH_COMPONENT;
			type = GL_UNSIGNED_INT;
		break;
		case GL_DEPTH_COMPONENT32F:
			format = GL_DEPTH_COMPONENT;
			type = GL_FLOAT;
		break;
		case GL_DEPTH24_STENCIL8:
			format = GL_DEPTH_STENCIL;
			type = GL_UNSIGNED_INT_24_8;
		break;
		case GL_DEPTH32F_STENCIL8:
			format = GL_DEPTH_STENCIL;
			type = GL_FLOAT_32_UNSIGNED_INT_24_8_REV;
		break;
		default:
			format = GL_RED;
			type = GL_UNSIGNED_BYTE;
	}

	if (isDepth() && compareFunc != COMPARE_NONE)
	{
		// RN_CHECK(glTextureParameteri(id, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE));
		// RN_CHECK_PARAM(glTextureParameteri(id, GL_TEXTURE_COMPARE_FUNC, compareFunc), rn::getEnumName(compareFunc));
		setParam(GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
		setParam(GL_TEXTURE_COMPARE_FUNC, compareFunc);
	}

	RN_CHECK_PARAM(glTextureStorage3D(id, mipLevels + 1, internalFormat, width, height, size), mipLevels << ", " << rn::getEnumName(internalFormat) << ", " << width << ", " << height << ", " << size);
	/*
	GLsizei mipWidth = width;
	GLsizei mipHeight = height;

	for (GLint i = 0; i <= mipLevels; i++)
	{
		RN_CHECK_PARAM(glTexImage3D(GL_TEXTURE_2D_ARRAY, i, internalFormat, mipWidth, mipHeight, size, 0, format, type, nullptr), i << ", " << rn::getEnumName(internalFormat) << ", " << mipWidth << ", " << mipHeight << ", " << rn::getEnumName(format) << ", " << rn::getEnumName(type));

		mipWidth = max(1, mipWidth / 2);
		mipHeight = max(1, mipHeight / 2);
	}
	*/

	// RN_CHECK(glBindTexture(GL_TEXTURE_2D_ARRAY, 0));

	UTIL_DEBUG
	{
		clog << fixed;
		clog << "  [Tex2DArray \"" << texName << "\":" << (ngn::time() - timer) << "s]" << endl;
		clog.unsetf(ios::floatfield);
	}
}
示例#10
0
文件: Texture.cpp 项目: xHaVoK87/kit
kit::Texture::Texture(const std::string & filename, kit::Texture::InternalFormat format, uint8_t levels, Type t) : kit::Texture(t)
{
    std::cout << "Loading texture from file \"" << filename.c_str() << "\"" << std::endl;
    m_filename = filename;
    if(t == Type::Texture2D)
    {
        m_internalFormat    = format;

        // Try to load data from file
        unsigned char* bufferdata;
        int x, y, n;

        stbi_set_flip_vertically_on_load(1);
        bufferdata = stbi_load(filename.c_str(), &x, &y, &n, 4);
        if (bufferdata == nullptr)
        {
            KIT_THROW(stbi_failure_reason());
        }

        // Set resolution
        m_resolution        = glm::uvec3(x, y, 0);

        uint8_t mipLevels = levels > 0 ? levels : calculateMipLevels();

        // Specify storage and upload data to GPU
#ifndef KIT_SHITTY_INTEL
        glTextureStorage2D(m_glHandle, mipLevels, m_internalFormat, m_resolution.x, m_resolution.y);
        glTextureSubImage2D(m_glHandle, 0, 0, 0, x, y, GL_RGBA, GL_UNSIGNED_BYTE, bufferdata);
#else
        bind();
        glTexStorage2D(m_type, mipLevels, m_internalFormat, m_resolution.x, m_resolution.y);
        glTexSubImage2D(m_type, 0, 0, 0, x, y, GL_RGBA, GL_UNSIGNED_BYTE, bufferdata);
#endif

        // Free loaded data
        stbi_image_free(bufferdata);

        // Set parameters
        setEdgeSamplingMode(EdgeSamplingMode::Repeat);
        setMinFilteringMode(m_minFilteringMode);
        setMagFilteringMode(m_magFilteringMode);

        setAnisotropicLevel(1.0f);
    }
    if(t == Type::Texture3D)
    {
        m_internalFormat = format;

        // Try to load data from file
        unsigned char* bufferdata;
        int x, y, n;

        stbi_set_flip_vertically_on_load(0);
        bufferdata = stbi_load(filename.c_str(), &x, &y, &n, 4);
        if (bufferdata == nullptr) {
            KIT_THROW(stbi_failure_reason());
        }

        if (y != x*x || y%y != 0)
        {
            KIT_THROW("Failed to load 3d texture from file, not perfectly cubical");
        }

        // Set resolution
        m_resolution = glm::uvec3(x, x, x);

        // Specify storage and upload data to GPU
#ifndef KIT_SHITTY_INTEL
        glTextureStorage3D(m_glHandle, 1, m_internalFormat, x, x, x);
        glTextureSubImage3D(m_glHandle, 0, 0, 0, 0, x, x, x, GL_RGBA, GL_UNSIGNED_BYTE, bufferdata);
#else
        returner->bind();
        glTexStorage3D(returner->m_type, 1, m_internalFormat, x, x, x);
        glTexSubImage3D(returner->m_type, 0, 0, 0, 0, x, x, x, GL_RGBA, GL_UNSIGNED_BYTE, bufferdata);
#endif
        // Free loaded data
        stbi_image_free(bufferdata);

        setEdgeSamplingMode(EdgeSamplingMode::Repeat);
        setMinFilteringMode(m_minFilteringMode);
        setMagFilteringMode(m_magFilteringMode);

        setAnisotropicLevel(1.0f);
    }
}
示例#11
0
	//[-------------------------------------------------------]
	//[ Public methods                                        ]
	//[-------------------------------------------------------]
	Texture2DArrayDsa::Texture2DArrayDsa(OpenGLRenderer &openGLRenderer, uint32_t width, uint32_t height, uint32_t numberOfSlices, Renderer::TextureFormat::Enum textureFormat, const void *data, uint32_t flags) :
		Texture2DArray(openGLRenderer, width, height, numberOfSlices)
	{
		#ifndef OPENGLRENDERER_NO_STATE_CLEANUP
			// Backup the currently set alignment
			GLint openGLAlignmentBackup = 0;
			glGetIntegerv(GL_UNPACK_ALIGNMENT, &openGLAlignmentBackup);
		#endif

		// Set correct alignment
		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

		// Create the OpenGL texture instance
		const bool isARB_DSA = openGLRenderer.getExtensions().isGL_ARB_direct_state_access();
		if (isARB_DSA)
		{
			glCreateTextures(GL_TEXTURE_2D_ARRAY_EXT, 1, &mOpenGLTexture);
		}
		else
		{
			glGenTextures(1, &mOpenGLTexture);
		}

		// Upload the base map of the texture (mipmaps are automatically created as soon as the base map is changed)
		if (isARB_DSA)
		{
			glTextureStorage3D(mOpenGLTexture, 1, Mapping::getOpenGLInternalFormat(textureFormat), static_cast<GLsizei>(width), static_cast<GLsizei>(height), static_cast<GLsizei>(numberOfSlices));
			if (nullptr != data)
			{
				glTextureSubImage3D(mOpenGLTexture, 0, 0, 0, 0, static_cast<GLsizei>(width), static_cast<GLsizei>(height), static_cast<GLsizei>(numberOfSlices), Mapping::getOpenGLFormat(textureFormat), Mapping::getOpenGLType(textureFormat), data);
			}
		}
		else
		{
			glTextureImage3DEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT, 0, static_cast<GLint>(Mapping::getOpenGLInternalFormat(textureFormat)), static_cast<GLsizei>(width), static_cast<GLsizei>(height), static_cast<GLsizei>(numberOfSlices), 0, Mapping::getOpenGLFormat(textureFormat), Mapping::getOpenGLType(textureFormat), data);
		}

		// Build mipmaps automatically on the GPU? (or GPU driver)
		if (flags & Renderer::TextureFlag::GENERATE_MIPMAPS)
		{
			if (isARB_DSA)
			{
				glGenerateTextureMipmap(mOpenGLTexture);
				glTextureParameteri(mOpenGLTexture, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
			}
			else
			{
				glGenerateTextureMipmapEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT);
				glTextureParameteriEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
			}
		}
		else
		{
			if (isARB_DSA)
			{
				glTextureParameteri(mOpenGLTexture, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			}
			else
			{
				glTextureParameteriEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			}
		}

		if (isARB_DSA)
		{
			glTextureParameteri(mOpenGLTexture, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		}
		else
		{
			glTextureParameteriEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		}

		#ifndef OPENGLRENDERER_NO_STATE_CLEANUP
			// Restore previous alignment
			glPixelStorei(GL_UNPACK_ALIGNMENT, openGLAlignmentBackup);
		#endif
	}
示例#12
0
/**
 * Do error-check tests for a non-mipmapped texture.
 */
static bool
test_one_level_errors(GLenum target)
{
	const GLint width = 64, height = 4, depth = 8;
	GLuint tex;
	GLint v;

	assert(target == GL_TEXTURE_1D ||
	       target == GL_TEXTURE_2D ||
	       target == GL_TEXTURE_3D);

	glCreateTextures(target, 1, &tex);
	glBindTextureUnit(0, tex);

	if (target == GL_TEXTURE_1D) {
		glTextureStorage1D(tex, 1, GL_RGBA8, width);
	} else if (target == GL_TEXTURE_2D) {
		glTextureStorage2D(tex, 1, GL_RGBA8, width, height);
	} else if (target == GL_TEXTURE_3D) {
		glTextureStorage3D(tex, 1, GL_RGBA8, width, height, depth);
	}

	piglit_check_gl_error(GL_NO_ERROR);

	glGetTextureLevelParameteriv(tex, 0, GL_TEXTURE_WIDTH, &v);
	if (v != width) {
		printf("%s: bad width: %d, should be %d\n", TestName, v, width);
		return false;
	}

	if (target != GL_TEXTURE_1D) {
		glGetTextureLevelParameteriv(tex, 0, GL_TEXTURE_HEIGHT, &v);
		if (v != height) {
			printf("%s: bad height: %d, should be %d\n", TestName,
			       v, height);
			return false;
		}
	}

	if (target == GL_TEXTURE_3D) {
		glGetTextureLevelParameteriv(tex, 0, GL_TEXTURE_DEPTH, &v);
		if (v != depth) {
			printf("%s: bad depth: %d, should be %d\n", TestName,
			       v, depth);
			return false;
		}
	}

	/* The ARB_texture_storage spec says:
	 *
	 *     "Using any of the following commands with the same texture will
	 *     result in the error INVALID_OPERATION being generated, even if
	 *     it does not affect the dimensions or format:
	 *
	 *         - TexImage*
	 *         - CompressedTexImage*
	 *         - CopyTexImage*
	 *         - TexStorage*"
	 */
	if (!piglit_khr_no_error && target == GL_TEXTURE_2D) {
		glTexImage2D(target, 0, GL_RGBA, width, height, 0,
			     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
		if (glGetError() != GL_INVALID_OPERATION) {
			printf("%s: glTexImage2D failed to generate error\n",
			       TestName);
			return false;
		}

		glTextureStorage2D(tex, 1, GL_RGBA8, width, height);
		if (glGetError() != GL_INVALID_OPERATION) {
			printf("%s: glTextureStorage2D() failed to generate "
			       "error\n", TestName);
			return false;
		}

		glCopyTexImage2D(target, 0, GL_RGBA, 0, 0, width, height, 0);
		if (glGetError() != GL_INVALID_OPERATION) {
			printf("%s: glCopyTexImage2D() failed to generate "
			       "error\n", TestName);
			return false;
		}
	}

	glDeleteTextures(1, &tex);

	return true;
}
示例#13
0
/**
 * Do error-check tests for a mipmapped texture.
 */
static bool
test_mipmap_errors(GLenum target)
{
	GLint width = 128, height = 64, depth = 4, levels = 8;
	const char *targetString = piglit_get_gl_enum_name(target);
	GLuint tex;
	GLint v, l;

	assert(target == GL_TEXTURE_1D ||
	       target == GL_TEXTURE_2D ||
	       target == GL_TEXTURE_3D);

	glCreateTextures(target, 1, &tex);
	glBindTextureUnit(0, tex);

	if (target == GL_TEXTURE_1D) {
		glTextureStorage1D(tex, levels, GL_RGBA8, width);
	} else if (target == GL_TEXTURE_2D) {
		glTextureStorage2D(tex, levels, GL_RGBA8, width, height);
	} else if (target == GL_TEXTURE_3D) {
		glTextureStorage3D(tex, levels, GL_RGBA8, width, 
			height, depth);
	}

	piglit_check_gl_error(GL_NO_ERROR);

	glGetTextureParameteriv(tex, GL_TEXTURE_IMMUTABLE_FORMAT, &v);
	if (!v) {
		printf("%s: %s GL_TEXTURE_IMMUTABLE_FORMAT query returned "
		       "false\n",
		       TestName, targetString);
		return false;
	}

	for (l = 0; l < levels; l++) {
		glGetTextureLevelParameteriv(tex, l, GL_TEXTURE_WIDTH, &v);
		if (v != width) {
			printf("%s: %s level %d: bad width: %d, should be %d\n",
			       TestName, targetString, l, v, width);
			return false;
		}

		if (target != GL_TEXTURE_1D) {
			glGetTextureLevelParameteriv(tex, l, 
						     GL_TEXTURE_HEIGHT, &v);
			if (v != height) {
				printf("%s: %s level %d: bad height: %d, "
				       "should be %d\n",
				       TestName, targetString, l, v, height);
				return false;
			}
		}

		if (target == GL_TEXTURE_3D) {
			glGetTextureLevelParameteriv(tex, l, 
						     GL_TEXTURE_DEPTH, &v);
			if (v != depth) {
				printf("%s: %s level %d: bad depth: %d, "
				       "should be %d\n",
				       TestName, targetString, l, v, depth);
				return false;
			}
		}

		if (width > 1)
			width /= 2;
		if (height > 1)
			height /= 2;
		if (depth > 1)
			depth /= 2;
	}

	glDeleteTextures(1, &tex);

	return true;
}