bool COpenGL1DTextureArray::updateSubRegion(const asset::E_FORMAT &inDataColorFormat, const void* data, const uint32_t* minimum, const uint32_t* maximum, int32_t mipmap, const uint32_t& unpackRowByteAlignment)
{
    bool sourceCompressed = isBlockCompressionFormat(inDataColorFormat);

    bool destinationCompressed = COpenGLTexture::isInternalFormatCompressed(InternalFormat);
    if ((!destinationCompressed)&&sourceCompressed)
        return false;

    if (destinationCompressed)
    {
        if (minimum[0])
            return false;

        uint32_t adjustedTexSize[1] = {TextureSize[0]};
        adjustedTexSize[0] /= 0x1u<<mipmap;
        /*
        adjustedTexSize[0] += 3u;
        adjustedTexSize[0] &= 0xfffffc;
        */
        if (maximum[0]!=adjustedTexSize[0])
            return false;
    }

    if (sourceCompressed)
    {
        size_t levelByteSize = (((maximum[0]-minimum[0]+3)&0xfffffc)*(maximum[1]-minimum[1])*COpenGLTexture::getOpenGLFormatBpp(InternalFormat))/8;

        COpenGLExtensionHandler::extGlCompressedTextureSubImage2D(TextureName,GL_TEXTURE_1D_ARRAY, mipmap, minimum[0],minimum[1],maximum[0]-minimum[0],maximum[1]-minimum[1], InternalFormat, levelByteSize, data);
    }
    else
    {
        GLenum pixFmt,pixType;
        getOpenGLFormatAndParametersFromColorFormat(inDataColorFormat, pixFmt, pixType);
        //! replace with
        ///COpenGLExtensionHandler::extGlGetInternalFormativ(GL_TEXTURE_1D_ARRAY,InternalFormat,GL_TEXTURE_IMAGE_FORMAT,1,&pixFmt);
        ///COpenGLExtensionHandler::extGlGetInternalFormativ(GL_TEXTURE_1D_ARRAY,InternalFormat,GL_TEXTURE_IMAGE_FORMAT,1,&pixType);

        //! we're going to have problems with uploading lower mip levels
        uint32_t bpp = video::getBitsPerPixelFromFormat(inDataColorFormat);
        uint32_t pitchInBits = ((maximum[0]-minimum[0])*bpp)/8;

        COpenGLExtensionHandler::setPixelUnpackAlignment(pitchInBits,const_cast<void*>(data),unpackRowByteAlignment);
        COpenGLExtensionHandler::extGlTextureSubImage2D(TextureName, GL_TEXTURE_1D_ARRAY, mipmap, minimum[0],minimum[1], maximum[0]-minimum[0],maximum[1]-minimum[1], pixFmt, pixType, data);
    }
    return true;
}
Пример #2
0
		//! copies the the texture into an open gl texture.
		void COpenGLTexture::uploadTexture(bool newTexture, void* mipmapData,
				u32 level)
		{
			// check which image needs to be uploaded
			IImage* image = level ? MipImage : Image;

			IRR_ASSERT(image);

			// get correct opengl color data values
			GLenum oldInternalFormat = InternalFormat;
			GLint filtering;
			InternalFormat = getOpenGLFormatAndParametersFromColorFormat(
					ColorFormat, filtering, PixelFormat, PixelType);
			// make sure we don't change the internal format of existing images
			if (!newTexture)
				InternalFormat = oldInternalFormat;

			static_cast<COpenGLDriver *>(Driver)->setActiveTexture(0, this);

			IRR_ASSERT(!Driver->haveError());

			// mipmap handling for main texture
			if (!level && newTexture)
			{
#ifndef DISABLE_MIPMAPPING
#ifdef GL_SGIS_generate_mipmap
				// auto generate if possible and no mipmap data is given
				if (HasMipMaps && !mipmapData
				//FIXME
				//&& Driver->queryFeature(EVDF_MIP_MAP_AUTO_UPDATE)
						)
				{

//					if (Driver->getTextureCreationFlag(
//							ETCF_OPTIMIZED_FOR_SPEED))
//						glHint(GL_GENERATE_MIPMAP_HINT_SGIS, GL_FASTEST);
//					else if (Driver->getTextureCreationFlag(
//							ETCF_OPTIMIZED_FOR_QUALITY))
//						glHint(GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST);
//					else
					glHint(GL_GENERATE_MIPMAP_HINT_SGIS, GL_DONT_CARE);
					// automatically generate and update mipmaps
					glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);

					//FIXME
//					AutomaticMipmapUpdate=true;
				}
				else
#endif

				{
					// Either generate manually due to missing capability
					// or use predefined mipmap data
//					AutomaticMipmapUpdate = false;
//					regenerateMipMapLevels(mipmapData);
				}
				//FIXME: refactor it
				if (false)
//				if (HasMipMaps) // might have changed in regenerateMipMapLevels
				{
					// enable bilinear mipmap filter
					glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
							GL_LINEAR_MIPMAP_NEAREST);
					glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
							GL_LINEAR);
				}
				else
#else
				//Did not create OpenGL texture mip maps.
				HasMipMaps=false;
#endif
				{
					// enable bilinear filter without mipmaps
					glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
							GL_LINEAR);
					glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
							GL_LINEAR);
				}
			}

			// now get image data and upload to GPU
			void* source = image->lock();
			if (newTexture)
			{
				glTexImage2D(GL_TEXTURE_2D, level, InternalFormat,
						image->getDimension().Width,
						image->getDimension().Height, 0, PixelFormat, PixelType,
						source);
			}
			else
			{
				glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0,
						image->getDimension().Width,
						image->getDimension().Height, PixelFormat, PixelType,
						source);
			}
			image->unlock();

			IRR_ASSERT(!Driver->haveError());
		}
Пример #3
0
//! copies the the texture into an open gl texture.
void COpenGLTexture::uploadTexture()
{
	COpenGLConfig* pOpenGLConfig = COpenGLConfig::getInstance();

	// check which image needs to be uploaded
	ISGPImage* image = m_Image;
	if( !image )
	{
		Logger::getCurrentLogger()->writeToLog(String("No image for OpenGL texture to upload"), ELL_ERROR);
		return;
	}

	// get correct opengl color data values
	
	GLint filtering;
	InternalFormat = getOpenGLFormatAndParametersFromColorFormat(m_ColorFormat, filtering, PixelFormat, PixelType);
	

	bool bindsucceed = BindTexture2D(0);
	if( !bindsucceed || RenderDevice->testGLError() )
		Logger::getCurrentLogger()->writeToLog(String("Could not bind Texture"), ELL_ERROR);


	glPixelStorei(GL_PACK_ALIGNMENT, 1);

	// now get image data and upload to GPU
	void* source = image->lock();

	glTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, image->getDimension().Width,
		image->getDimension().Height, 0, PixelFormat, PixelType, source);

	image->unlock();

	if (RenderDevice->testGLError())
		Logger::getCurrentLogger()->writeToLog(String("Could not glTexImage2D"), ELL_ERROR);


	if( pOpenGLConfig->Force_Disable_MIPMAPPING )
		HasMipMaps = false;
	if( HasMipMaps )
	{
/*	IMPORTANT NOTE:
		if OpenGL >= 3.0, use glGenerateMipmap
		else if OpenGL >= 1.4, use glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
		else video card is pretty old at this point, fall back to gluBuild2DMipmaps?
		else cut off support
*/
		if( RenderDevice->queryDriverFeature(SGPVDF_MIP_MAP_GEN_HW) )
		{
			RenderDevice->extGlGenerateMipmap(GL_TEXTURE_2D);

			{
				uint32 width = image->getDimension().Width;
				uint32 height = image->getDimension().Height;
				uint32 i=0;
				do
				{
					if(width>1)
						width>>=1;
					if(height>1)
						height>>=1;
					++i;
				}
				while (width!=1 || height!=1);
				MipMapLevels = i;
			}
		}
		else