bool initTexture()
	{
		gli::texture2d Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str()));
		if(Texture.empty())
			return false;

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

		glGenTextures(1, &TextureName);

		glBindTexture(GL_TEXTURE_2D_ARRAY, TextureName);
		glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0);
		glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, GLint(Texture.levels() - 1));
		glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R, Format.Swizzles[0]);
		glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G, Format.Swizzles[1]);
		glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B, Format.Swizzles[2]);
		glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A, Format.Swizzles[3]);
		glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexStorage3D(GL_TEXTURE_2D_ARRAY, 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(std::size_t Level = 0; Level < Texture.levels(); ++Level)
		{
			glTexSubImage3D(GL_TEXTURE_2D_ARRAY, static_cast<GLint>(Level),
				0, 0, 0,
				static_cast<GLsizei>(Texture[Level].extent().x), static_cast<GLsizei>(Texture[Level].extent().y), GLsizei(1),
				Format.External, Format.Type,
				Texture[Level].data());
		}

		return true;
	}
void LightfieldRenderer::add_texture( BackendResponseDataType type, size_t index, const ClipRect& clip, const ResultData& image )
{
    assert( impl->state == LFRS_FRAME_BEGUN );

    switch ( type ) {
    case BRDT_COLOR_IMAGE:
    {
        glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, impl->color_texname);
        
        glTexSubImage3D(
            GL_TEXTURE_2D_ARRAY_EXT, 0, 
            0, 0, index, clip.width, clip.height,
            1, GL_RGBA, GL_UNSIGNED_BYTE, image.data);
    } break;
    case BRDT_DEPTH_IMAGE:
    {
        glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, impl->depth_texname);
        
        glTexSubImage3D(
            GL_TEXTURE_2D_ARRAY_EXT, 0, 
            0, 0, index, clip.width, clip.height,
            1, GL_LUMINANCE, GL_UNSIGNED_BYTE, image.data);
    } break;
    case BRDT_DATA:
    {
        throw InvalidArgumentException("add_texture received data of type BRDT_DATA"); 
    } break;
    }
}
	bool initTexture()
	{
		glm::uvec2 WindowSize(this->getWindowSize());

		glGenTextures(texture::MAX, &TextureName[0]);

		{
			glBindTexture(GL_TEXTURE_2D_ARRAY, TextureName[texture::DIFFUSE]);
			glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED);
			glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
			glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
			glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
			glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0);
			glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0);
			glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
			glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

			std::vector<glm::u8vec4> Colors;
			Colors.resize(2048);
			for(std::size_t ColorIndex = 0; ColorIndex < Colors.size(); ++ColorIndex)
				Colors[ColorIndex] = glm::u8vec4(glm::vec4(glm::linearRand(glm::vec3(0), glm::vec3(1)) * 255.f, 1.0f));

			glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 1, 1, static_cast<GLsizei>(Colors.size()));
			glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0,
					0, 0, 0,
					1, 1, static_cast<GLsizei>(Colors.size()),
					GL_RGBA, GL_UNSIGNED_BYTE, &Colors[0][0]);
		}

		{
			glBindTexture(GL_TEXTURE_2D_ARRAY, TextureName[texture::INDIRECTION]);
			glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED);
			glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
			glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
			glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
			glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0);
			glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0);
			glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
			glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

			std::vector<glm::u32vec1> Data;
			Data.resize(WindowSize.x * WindowSize.y);
			for(std::size_t Index = 0; Index < Data.size(); ++Index)
				//Data[Index] = glm::u32vec1(glm::linearRand(glm::vec1(0), glm::vec1(1)) * 255.0f);
				Data[Index] = glm::u32vec1(glm::linearRand(glm::vec1(0), glm::vec1(1)) * glm::vec1(Data.size() - 1));

			glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_R32UI, WindowSize.x, WindowSize.y, 1);
			glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0,
					0, 0, 0,
					WindowSize.x, WindowSize.y, 1,
					GL_RED_INTEGER, GL_UNSIGNED_INT, &Data[0][0]);
		}

		return true;
	}
static bool
test_single_layer(const Params* p, int layer)
{
	int l;
	GLuint tex_src, tex_view;
	GLboolean pass;
	GLubyte *image;

	assert(layer < p->num_layers);

	glGenTextures(1, &tex_src);
	glBindTexture(GL_TEXTURE_2D_ARRAY, tex_src);

	glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, p->width, p->height, p->num_layers);

	/* load each array layer with red */
	image = makesolidimage(p->width, p->height, red);
	for (l = 0; l < p->num_layers; l++) {
		glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, l,
				p->width, p->height, 1, GL_RGBA, GL_UNSIGNED_BYTE, image);
	}

	/* make layer to check red, but green for pixel at (0,0) which should be the only one sampled */
	memcpy(image, green, sizeof(green));

	glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, layer,
			p->width, p->height, 1, GL_RGBA, GL_UNSIGNED_BYTE, image);

	free(image);

	glGenTextures(1, &tex_view);
	/* checked layer is supposed to be green */
	glTextureView(tex_view, GL_TEXTURE_2D, tex_src, GL_RGBA8,
		      0, 1, layer, 1);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

	glBindTexture(GL_TEXTURE_2D, tex_view);

	/* draw it! */
	piglit_draw_rect(-1, -1, 2, 2);

	pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, greenf);
	if (!pass) {
		printf("layer %d failed\n", layer);
	}

	glDeleteTextures(1, &tex_view);
	glDeleteTextures(1, &tex_src);

	return pass;
}
void r_TextureArray::TextureLayer( int layer, unsigned char* data )
{
    if( layer > layers || id == 0xffffffff )
        return;
    Bind();
    #ifdef OGL21
    glTexSubImage3D( GL_TEXTURE_3D, 0, 0, 0, layer, width, height,
                     1, texture_type, data_type, data );
    #else
    glTexSubImage3D( GL_TEXTURE_2D_ARRAY, 0, 0, 0, layer, width, height,
                     1, texture_type, data_type, data );
	#endif
}
Exemple #6
0
void Renderer::loadTextures()
{
    {
        QVector<QString> files;
        files << "dirt.png" << "sand.png" << "grass.png" << "mountain.png";
        QVector<QImage> images(files.count(), QImage(QSize(700,700), QImage::Format_RGBA8888));

        for (int i=0; i<images.count(); i++)
        {
            QImage &image = images[i];
            if (!image.load(gDefaultPathTextures + files[i]))
                qDebug() << "Error loading texture " << gDefaultPathTextures + files[i];
        }

        int imageSize = images.first().width();	//for now, assume all images are the same width and height

        glGenTextures(1, &mTextures.terrain);
        qDebug() << "I am " << mTextures.terrain;
        glBindTexture(GL_TEXTURE_2D_ARRAY, mTextures.terrain);

        GLenum format = GL_BGRA;

        int mipLevels = 8;
        glTexStorage3D(GL_TEXTURE_2D_ARRAY, mipLevels, GL_RGBA8, imageSize, imageSize, 4);

        glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0,
                        0, 0, 0,
                        imageSize, imageSize, 1,
                        format, GL_UNSIGNED_BYTE, images[0].bits());

        glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0,
                        0, 0, 1,
                        imageSize, imageSize, 1,
                        format, GL_UNSIGNED_BYTE, images[1].bits());

        glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0,
                        0, 0, 2,
                        imageSize, imageSize, 1,
                        format, GL_UNSIGNED_BYTE, images[2].bits());

        glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0,
                        0, 0, 3,
                        imageSize, imageSize, 1,
                        format, GL_UNSIGNED_BYTE, images[3].bits());

        glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
        glSamplerParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
        glSamplerParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    }
}
Exemple #7
0
static void
upload_array_slice(GLenum target, int slice, void *pixels)
{
	glTexSubImage3D(target, 0, 0, 0, slice, TEXTURE_WIDTH, TEXTURE_HEIGHT, 1,
			format_for_components[comptype][components-1],
			GL_UNSIGNED_BYTE, pixels);
}
Exemple #8
0
void LandRenderer::initTerrainTexture()
{
    const Region& region = Core::get().region();

    GLsizei numTextures = static_cast<GLsizei>(region.terrainTextures.size());

    // allocate terrain texture
    glGenTextures(1, &terrainTexture_);
    glBindTexture(GL_TEXTURE_2D_ARRAY, terrainTexture_);
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, Core::get().renderer().textureMinFilter());
    glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_ANISOTROPY_EXT, Core::get().renderer().textureMaxAnisotropy());
    glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB8, kTerrainArraySize, kTerrainArraySize, numTextures, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);

    // populate terrain texture
    for(GLint i = 0; i < numTextures; i++)
    {
        ResourcePtr imgTex = Core::get().resourceCache().get(region.terrainTextures[i].resourceId);
        const Image& image = imgTex->cast<ImgTex>().imgColor->cast<ImgColor>().image;

        if(image.width() != kTerrainArraySize || image.height() != kTerrainArraySize)
        {
            throw runtime_error("Bad terrain image size");
        }

        if(image.format() != PixelFormat::kA8R8G8B8)
        {
            throw runtime_error("Bad terrain image format");
        }

        glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, kTerrainArraySize, kTerrainArraySize, 1, GL_BGRA, GL_UNSIGNED_BYTE, image.data());
    }

    glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
}
Exemple #9
0
    bool loadTextureToGPU(const LODNode& lodNode, const DataSource& dataSource,
                          const TexturePool& texturePool,
                          const ConstDataObjectPtr& data) const
    {
#ifdef LIVRE_DEBUG_RENDERING
        std::cout << "Upload " << lodNode.getNodeId().getLevel() << ' '
                  << lodNode.getRelativePosition() << " to "
                  << _textureState.textureId << std::endl;
#endif
        const Vector3ui& overlap = dataSource.getVolumeInfo().overlap;
        const Vector3ui& voxSizeVec = lodNode.getBlockSize() + overlap * 2;
        _textureState.bind();

        glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, voxSizeVec[0], voxSizeVec[1],
                        voxSizeVec[2], texturePool.getFormat(),
                        texturePool.getTextureType(), data->getDataPtr());

        const GLenum glErr = glGetError();
        if (glErr != GL_NO_ERROR)
        {
            LBERROR << "Error loading the texture into GPU, error number : "
                    << glErr << std::endl;
            return false;
        }

        return true;
    }
Exemple #10
0
GLTextureArray::GLTextureArray(const std::vector<std::string>& imageNames, 
	unsigned int textureWidth, unsigned int textureHeight,
	bool generateMipMaps,
	GLint minFilter, GLint magFilter,
	GLint textureWrapS, GLint textureWrapT)
{
	CHECK_GL_ERROR();
	glGenTextures(1, &m_textureID);
	glBindTexture(GL_TEXTURE_2D_ARRAY, m_textureID);

	//glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, textureWidth, textureHeight, imageNames.size());
	glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA, textureWidth, textureHeight, imageNames.size(), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, minFilter);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, magFilter);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, textureWrapS);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, textureWrapT);
	int i = 0;
	for (const std::string& imageName : imageNames)
	{
		Pixmap p(imageName.c_str());
		assert(p.m_width == textureWidth);
		assert(p.m_height == textureHeight);
		glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, textureWidth, textureHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE, p.m_data);
		++i;
	}

	if (generateMipMaps)
		glGenerateMipmap(GL_TEXTURE_2D_ARRAY);

	glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
}
Exemple #11
0
GLTextureArray::GLTextureArray(const char** filePaths, unsigned int numTextures, unsigned int textureWidth, unsigned int textureHeight,
	bool generateMipMaps,
	GLint minFilter, GLint magFilter,
	GLint textureWrapS, GLint textureWrapT)
{
	glGenTextures(1, &m_textureID);
	glBindTexture(GL_TEXTURE_2D_ARRAY, m_textureID);

	//glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, textureWidth, textureHeight, imageNames.size());
	glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA, textureWidth, textureHeight, numTextures, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, minFilter);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, magFilter);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, textureWrapS);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, textureWrapT);

	for (unsigned int i = 0; i < numTextures; ++i)
	{
		const char* imageName = filePaths[i];
		Pixmap p(imageName);
		assert(p.m_width == textureWidth && "Image width does not match with the width of this array");
		assert(p.m_height == textureHeight && "Image height does not match with the height of this array");
		glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, textureWidth, textureHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE, p.m_data);
	}

	if (generateMipMaps)
		glGenerateMipmap(GL_TEXTURE_2D_ARRAY);

	glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
}
static void
load_texture_2d_array(void)
{
	float *p = malloc(TEX_WIDTH * TEX_HEIGHT * num_layers * 4 * sizeof(float));
	int x,y,z;

	for (z = 0; z < num_layers; z++) {
		for (y = 0; y < TEX_HEIGHT; y++) {
			for (x = 0; x < TEX_WIDTH; x++) {
				int quadrant = y < TEX_HEIGHT/2 ? (x < TEX_WIDTH/2 ? 0 : 1) :
								  (x < TEX_WIDTH/2 ? 2 : 3);
				float *dest = &p[(z*TEX_HEIGHT*TEX_WIDTH + y*TEX_WIDTH + x)*4];

				switch (quadrant) {
				case 0:
					memcpy(dest, layer_color[z], 4 * sizeof(float));
					break;
				case 1:
					memcpy(dest, green, 4 * sizeof(float));
					break;
				case 2:
					memcpy(dest, blue, 4 * sizeof(float));
					break;
				case 3:
					memcpy(dest, white, 4 * sizeof(float));
					break;
				}
			}
		}
	}

	glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, TEX_WIDTH, TEX_HEIGHT,
			num_layers, GL_RGBA, GL_FLOAT, p);
	free(p);
}
static void
load_texcube(void)
{
	float *p = malloc(TEX_SIZE * TEX_SIZE * num_layers * 4 * sizeof(float));
	int x,y,z;

	for (z = 0; z < num_layers; z++) {
		for (y = 0; y < TEX_SIZE; y++) {
			for (x = 0; x < TEX_SIZE; x++) {
				int quadrant = y < TEX_SIZE/2 ? (x < TEX_SIZE/2 ? 0 : 1) :
								(x < TEX_SIZE/2 ? 2 : 3);
				float *dest = &p[(z*TEX_SIZE*TEX_SIZE + y*TEX_SIZE + x)*4];

				memcpy(dest, colors[(z + quadrant*2) % NUM_COLORS],
				       4 * sizeof(float));
			}
		}
	}

	if (test_array) {
		glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0, 0, 0, 0,
				TEX_SIZE, TEX_SIZE, num_layers, GL_RGBA, GL_FLOAT, p);
	}
	else {
		int i;

		for (i = 0; i < 6; i++) {
			glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0,
					TEX_SIZE, TEX_SIZE, GL_RGBA, GL_FLOAT,
					p + i*TEX_SIZE*TEX_SIZE*4);
		}
	}
	free(p);
}
bool Material::loadTexture()
{
	glGenTextures(1, &m_textureID);
	glBindTexture(GL_TEXTURE_2D_ARRAY, m_textureID);

	int count = p_images.size();

	glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, p_width[0], p_height[0], count,GL_CLAMP, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);

	for (int i = 0; i < count; i++)
	{
		glTexSubImage3D(GL_TEXTURE_2D_ARRAY, i, 0, 0, 0, p_width[i], p_height[i], 1, GL_RGBA, GL_UNSIGNED_BYTE, p_images[i]);
	}

	// Sets texture parameters, given a target, symbolic name of the texture parameter, and a value for that parameter.
	// Valid symbolic names are GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER, GL_TEXTURE_WRAP_S, or GL_TEXTURE_WRAP_T.
	// Each has their own different set of values as well.
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);

	// Generates a mipmap for the texture, and there's no reason not to.
	glGenerateMipmap(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, 0);

	return true;
}
Exemple #15
0
bool TextureObject::loadTextureToGPU_( ) const
{
#ifdef LIVRE_DEBUG_RENDERING
    std::cout << "Upload "  << lodNodePtr_->getRefLevel() << ' '
              << lodNodePtr_->getRelativePosition() << " to "
              << textureState_->textureId << std::endl;
#endif

    const Vector3i& voxSizeVec = lodNodePtr_->getVoxelBox( ).getDimension( );

    textureState_->bind( );
    glTexSubImage3D( GL_TEXTURE_3D, 0, 0, 0, 0,
                     voxSizeVec[0], voxSizeVec[1], voxSizeVec[2],
                     textureState_->texturePoolPtr->getFormat() ,
                     textureState_->texturePoolPtr->getGPUDataType(),
                     getTextureDataObject_().getDataPtr( ));

    // Something went wrong with loading the data
    // TODO: Log message
    const GLenum glErr = glGetError();
    if ( glErr != GL_NO_ERROR )
    {
        LBERROR << "Error loading the texture into GPU, error number : "  << glErr << std::endl;
        return false;
    }

    glFinish( );
    return true;
}
	bool initTexture()
	{
		gli::textureCube Texture(gli::FORMAT_RGBA8_UNORM_PACK8, gli::textureCube::texelcoord_type(2), 1);
		assert(!Texture.empty());

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

		Texture[0].clear<glm::u8vec4>(glm::u8vec4(255,   0,   0, 255));
		Texture[1].clear<glm::u8vec4>(glm::u8vec4(255, 128,   0, 255));
		Texture[2].clear<glm::u8vec4>(glm::u8vec4(255, 255,   0, 255));
		Texture[3].clear<glm::u8vec4>(glm::u8vec4(  0, 255,   0, 255));
		Texture[4].clear<glm::u8vec4>(glm::u8vec4(  0, 255, 255, 255));
		Texture[5].clear<glm::u8vec4>(glm::u8vec4(  0,   0, 255, 255));

		glGenTextures(1, &TextureName);
		glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, TextureName);
		glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_BASE_LEVEL, 0);
		glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAX_LEVEL, 0);

		glTexStorage3D(GL_TEXTURE_CUBE_MAP_ARRAY, GLint(Texture.levels()),
			Format.Internal, GLsizei(Texture.dimensions().x), GLsizei(Texture.dimensions().y), GLsizei(Texture.faces()));

		glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0,
			0, 0, 0,
			static_cast<GLsizei>(Texture.dimensions().x),
			static_cast<GLsizei>(Texture.dimensions().y),
			static_cast<GLsizei>(Texture.faces()),
			Format.External, Format.Type,
			Texture.data());

		return true;
	}
void APIENTRY FWGLExtension::initTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels)
{
	spTexSubImage3D = (PFNGLTEXSUBIMAGE3D)FW_GETGLPROC("glTexSubImage3D");
	if(!spTexSubImage3D)
		reportError("glTexSubImage3D");
	glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
}
 inline void VL_glTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels)
 {
   if (glTexSubImage3D)
     glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
   else
     VL_UNSUPPORTED_FUNC();
 }
Exemple #19
0
void transferTo3DTexture(int width, int height, int depth, textureParameters tp, GLuint tex, GLenum type, void *data, int stride)
{
  glBindTexture(tp.texTarget, tex);  
  glPixelStorei(GL_UNPACK_ROW_LENGTH, stride);
  glTexSubImage3D(tp.texTarget,0,0,0,depth,width,height,1,tp.texFormat,type,data);
  checkGLErrors("transferTo3DTexture");
}
Exemple #20
0
static void
upload_array_slice(GLenum target, int slice, void *pixels)
{
	glTexSubImage3D(target, 0, 0, 0, slice, texture_width, texture_height, 1,
			format_for_components[comptype][components-1],
			GL_UNSIGNED_BYTE, pixels);
}
Exemple #21
0
void GenerateArrayTexture()
{
  //Generate an array texture
  glGenTextures( 1, &gArrayTexture );
  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D_ARRAY, gArrayTexture);
 
  //Create storage for the texture. (100 layers of 1x1 texels)
  glTexStorage3D( GL_TEXTURE_2D_ARRAY,
                  1,                    //No mipmaps as textures are 1x1
                  GL_RGB8,              //Internal format
                  1, 1,                 //width,height
                  100                   //Number of layers
                );
 
  for( unsigned int i(0); i!=100;++i)
  {
    //Choose a random color for the i-essim image
    GLubyte color[3] = {rand()%255,rand()%255,rand()%255};
 
    //Specify i-essim image
    glTexSubImage3D( GL_TEXTURE_2D_ARRAY,
                     0,                     //Mipmap number
                     0,0,i,                 //xoffset, yoffset, zoffset
                     1,1,1,                 //width, height, depth
                     GL_RGB,                //format
                     GL_UNSIGNED_BYTE,      //type
                     color);                //pointer to data
  }
 
  glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
}
Exemple #22
0
void UpdateGlTexture3D(ge_Image3D* image){
	if(!image)return;
	
	printf("UpdateGlTexture3D 1\n");
	image->u = (float)image->width / (float)image->textureWidth;
	image->v = (float)image->height / (float)image->textureHeight;
	printf("UpdateGlTexture3D 2\n");

	if(!image->id){
		glGenTextures(1, &image->id);
		glBindTexture(GL_TEXTURE_3D, image->id);
		glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA/*4*/, image->textureWidth, image->textureHeight, image->textureDepth, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
		libge_context->gpumem += image->textureWidth*image->textureHeight*sizeof(u32);
	//	InitMipmaps(image, mipmap_detail);
	}
	
	printf("UpdateGlTexture3D 3\n");
	glBindTexture(GL_TEXTURE_3D, image->id);
	glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, image->textureWidth, image->textureHeight, image->textureDepth, GL_RGBA, GL_UNSIGNED_BYTE, image->data);
	printf("UpdateGlTexture3D 4\n");

	glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glBindTexture(GL_TEXTURE_3D, 0);
	printf("UpdateGlTexture3D 5\n");
}
Exemple #23
0
	int gl_TexSubImage3D(State& state){
		size_t size = 0;
		unsigned char * data;
		vector<unsigned char> _data;

		if (state.stack->is<LUA_TLIGHTUSERDATA>(10)){
			data = (unsigned char *) state.stack->to<void*>(10);
		}else{
			if (state.stack->is<LUA_TTABLE>(10)){
				size = getArray<unsigned char>(state, 10, _data);
				data = _data.data();
			}else{
				data = nullptr;
			}
		}

		glTexSubImage3D(
			(GLenum) state.stack->to<int>(1),
			(GLint) state.stack->to<int>(2),
			(GLint) state.stack->to<int>(3),
			(GLint) state.stack->to<int>(4),
			(GLint) state.stack->to<int>(5),
			(GLsizei) state.stack->to<int>(6),
			(GLsizei) state.stack->to<int>(7),
			(GLsizei) state.stack->to<int>(8),
			(GLenum) state.stack->to<int>(9),
			(GLenum) GL_UNSIGNED_BYTE,
			(GLvoid*) data
			);
		return 0;
	}
Exemple #24
0
GLuint CreateArrayTexture2D (U32 width, U32 height, std::vector<std::string>& filenames) {
	GLuint textureID = 0;
	GLuint mipLevelCount = 1;
	glGenTextures(1, &textureID);
	glBindTexture(GL_TEXTURE_2D_ARRAY, textureID);
	// Allocate the storage.
	glTexStorage3D(GL_TEXTURE_2D_ARRAY, mipLevelCount, GL_RGBA8, width, height, filenames.size());
	// Upload pixel data.
	// The first 0 refers to the mipmap level (level 0, since there's only 1)
	// The following 2 zeroes refers to the x and y offsets in case you only want to specify a subrectangle.
	// The final 0 refers to the layer index offset (we start from index 0 and have 2 levels).
	// Altogether you can specify a 3D box subset of the overall texture, but only one mip level at a time.

	for (U32 i = 0; i < filenames.size(); i++) {
		int w, h;
        auto pixels = stbi_load(filenames[i].c_str(), &w, &h, nullptr, 4);
        assert(w == height);
        assert(h == height);
		glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
		stbi_image_free(pixels);
	}

	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	return textureID;
}
Exemple #25
0
ArrayTexture::ArrayTexture(string tmpl, int num, const unsigned int width, const unsigned int height, GLenum format, GLenum internalFormat, GLenum precision) {
	this->width = width;
	this->height = height;

	this->format = format;
	this->internalFormat = internalFormat;
	this->precision = precision;
	this->target = GL_TEXTURE_2D_ARRAY;
	mipLevels = 10;
	this->layers = num;

	glGenTextures(1, &glId);
	GL_CHECK_ERRORS();
	glBindTexture(target, glId);
	GL_CHECK_ERRORS();

	glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, 0);
	glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, mipLevels);

	glTexStorage3D(target, mipLevels, precision, width, height, layers);

	tmpl = FOLDER + tmpl;

	for (int i = 0; i < num; i++) {
		char buff[1024];
		snprintf(buff, sizeof(buff), tmpl.c_str(), i);
		string file = buff;

		if (!Globals::File_Exists(file)) {
			cout << "File " << file << " does not exist. Can not load texture." << endl;
			return;
		}


		int load_width;
		int load_height;
		int load_channels;
		unsigned char *image = SOIL_load_image((file).c_str(), &load_width, &load_height, &load_channels, format == GL_RGBA ? SOIL_LOAD_RGBA : SOIL_LOAD_RGB);

		//cout << file << " " << width << "x" << height << " (" << load_channels << ") " << endl;

		assert(width == load_width);
		assert(height == load_height);

		glTexSubImage3D(target, 0, 0, 0, i, width, height, 1, format, internalFormat, image);
		SOIL_free_image_data(image);
	}

	if (mipLevels > 0)
		glGenerateMipmap(target);

	glBindTexture(target, 0);
	GL_CHECK_ERRORS();
}
void QOpenGLTextureHelper::qt_TextureSubImage3D(GLuint texture, GLenum target, GLenum bindingTarget, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels)
{
    GLint oldTexture;
    glGetIntegerv(bindingTarget, &oldTexture);
    glBindTexture(target, texture);
    glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
    glBindTexture(target, oldTexture);
}
Exemple #27
0
	void sub_image_3d( GLint level, T xoffset, U yoffset, V zoffset, W the_width, X the_height, Y the_depth, GLenum format, GLenum type, const GLvoid* data ) {
		assert( xoffset + the_width < m_width );
		assert( yoffset + the_height < m_height );
		assert( zoffset + the_depth < m_depth );
		bind();
		check_gl_error( glTexSubImage3D( Target, level, static_cast<GLint>( xoffset ), static_cast<GLint>( yoffset ), static_cast<GLint>( zoffset ), static_cast<GLsizei>( the_width ), static_cast<GLsizei>( the_height ), static_cast<GLsizei>( the_depth ), format, type, data ) );
		unbind();
	}
Exemple #28
0
void Texture3D::setCompressedSubImage(int level, int x, int y, int z, int w, int h, int d, int s, const Buffer &pixels)
{
    bindToTextureUnit();
    pixels.bind(GL_PIXEL_UNPACK_BUFFER);
    glTexSubImage3D(GL_TEXTURE_3D, level, x, y, z, w, h, d, getTextureInternalFormat(internalFormat), s, pixels.data(0));
    pixels.unbind(GL_PIXEL_UNPACK_BUFFER);
    assert(FrameBuffer::getError() == GL_NO_ERROR);
}
Exemple #29
0
int mrgss_renderer_get_bitmap_layer(mrgss_renderer* renderer, mrgss_bitmap* bitmap){
    if (bitmap->texLayer == -1) {
        glTexSubImage3D( GL_TEXTURE_2D_ARRAY, 0, 0,0,renderer->tex_count, bitmap->width, bitmap->height ,1, GL_RGBA, GL_UNSIGNED_BYTE, bitmap->data);
        bitmap->texLayer = renderer->tex_count;
        renderer->tex_count += 1; 
    }
    return bitmap->texLayer;
}
Exemple #30
0
void Texture::setSubImage3D( GLsizei width, GLsizei height, GLsizei depth, const GLvoid* data, GLint xoffset, GLint yoffset, GLint zoffset )
{
    KVS_ASSERT( m_target == GL_TEXTURE_3D );
    KVS_ASSERT( this->isBound() );

    const GLint level = 0; // level-of-detail number
    KVS_GL_CALL( glTexSubImage3D( m_target, level, xoffset, yoffset, zoffset, width, height, depth, m_external_format, m_external_type, data ) );
}