Exemplo n.º 1
0
bool initTextureArray()
{
	GLint MaxTextureArrayLayers(0);
	glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &MaxTextureArrayLayers);

	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	glGenTextures(1, &Texture2DArrayName);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D_ARRAY, Texture2DArrayName);

	// Set image
	gli::texture2DArray Texture(gli::loadStorageDDS(glf::DATA_DIRECTORY + TEXTURE_DIFFUSE));

	glTexStorage3D(
		GL_TEXTURE_2D_ARRAY,
		GLsizei(Texture.levels()),
		gli::internal_format(Texture.format()), 
		GLsizei(Texture.dimensions().x), 
		GLsizei(Texture.dimensions().y), 
		GLsizei(Texture.layers())); //depth

	for(gli::texture2DArray::size_type Array = 0; Array < Texture.layers(); ++Array)
	for(gli::texture2DArray::size_type Level = 0; Level < Texture.levels(); ++Level)
	{
		glTexSubImage3D(
			GL_TEXTURE_2D_ARRAY, 
			GLint(Level), 
			0, // offset x 
			0, // offset y 
			GLint(Array), // offset z
			GLsizei(Texture[Array][Level].dimensions().x), 
			GLsizei(Texture[Array][Level].dimensions().y), 
			GLsizei(1), //depth
			gli::external_format(Texture.format()), 
			gli::type_format(Texture.format()), 
			Texture[Array][Level].data());
	}

	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

	return glf::checkError("initTextureArray");
}
Exemplo n.º 2
0
	bool initTexture()
	{
		GLint MaxTextureArrayLayers(0);
		glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &MaxTextureArrayLayers);

		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

		glGenTextures(1, &TextureName);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D_ARRAY, TextureName);

		gli::texture2DArray Texture(gli::FORMAT_RGBA8_UNORM_PACK8, gli::texture2DArray::texelcoord_type(4), 15, 1);
		for(gli::size_t LayerIndex = 0, LayerCount = Texture.layers(); LayerIndex < LayerCount; ++LayerIndex)
		{
			float const Progress = static_cast<float>(LayerIndex) / static_cast<float>(LayerCount);
			glm::u8vec4 const Color(glm::vec4(Progress, 0.5f + Progress * 0.5f, 1.f - Progress, 1.f) * 255.f);
			Texture[LayerIndex].clear<glm::u8vec4>(Color);
		}

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

		glTexStorage3D(GL_TEXTURE_2D_ARRAY, GLsizei(Texture.levels()),
			Format.Internal,
			GLsizei(Texture.dimensions().x), GLsizei(Texture.dimensions().y), GLsizei(Texture.layers()));

		for(gli::texture2DArray::size_type Array = 0; Array < Texture.layers(); ++Array)
		for(gli::texture2DArray::size_type Level = 0; Level < Texture.levels(); ++Level)
		{
			glTexSubImage3D(GL_TEXTURE_2D_ARRAY, GLint(Level),
				0, 0, GLint(Array),
				GLsizei(Texture[Array][Level].dimensions().x), GLsizei(Texture[Array][Level].dimensions().y), GLsizei(1),
				Format.External, Format.Type,
				Texture[Array][Level].data());
		}

		glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

		return true;
	}