⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tex.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
					psTexFormat = gc->sTexture.psDefaultRGBAFormat;
					break;
				case GL_UNSIGNED_SHORT_5_5_5_1:
					pfnCopySpan = (PFNCopySpan) Copy5551Span;
					ui32SrcBytesPerPixel = 2;
					psTexFormat = &TexFormatRGBA5551;
					break;
				case GL_UNSIGNED_SHORT_4_4_4_4:
					pfnCopySpan = (PFNCopySpan) Copy4444Span;
					ui32SrcBytesPerPixel = 2;
					psTexFormat = &TexFormatRGBA4444;
					break;
				default:
					goto bad_enum;
			}
			break;
		}
		case GL_RGB:
		{
			switch(type)
			{
				case GL_UNSIGNED_BYTE:
					pfnCopySpan = gc->sTexture.pfnDefaultRGBCopySpan;
					ui32SrcBytesPerPixel = 3;
					psTexFormat = gc->sTexture.psDefaultRGBFormat;
					break;
				case GL_UNSIGNED_SHORT_5_6_5:
					pfnCopySpan = (PFNCopySpan) Copy16Span;
					ui32SrcBytesPerPixel = 2;
					psTexFormat = &TexFormatRGB565;
					break;
				default:
					goto bad_enum;
			}
			break;
		}
		case GL_ALPHA:
			if(type != GL_UNSIGNED_BYTE)
				goto bad_enum;
			
			pfnCopySpan = (PFNCopySpan) Copy8Span;
			ui32SrcBytesPerPixel = 1;			
			psTexFormat = (GLEStextureFormat *)&TexFormatAlpha;
			break;
		case GL_LUMINANCE:
			if(type != GL_UNSIGNED_BYTE)
				goto bad_enum;
			
			pfnCopySpan = (PFNCopySpan) Copy8Span;
			ui32SrcBytesPerPixel = 1;			
			psTexFormat = (GLEStextureFormat *)&TexFormatLuminance;
			break;
		case GL_LUMINANCE_ALPHA:
			if(type != GL_UNSIGNED_BYTE)
				goto bad_enum;
			
			pfnCopySpan = (PFNCopySpan) Copy16Span;
			ui32SrcBytesPerPixel = 2;
			psTexFormat = (GLEStextureFormat *)&TexFormatLuminanceAlpha;
			break;
		default:
			goto bad_enum;
	}

	    /* Allocate memory for the level data */
    pui8Dest = TextureCreateLevel(gc, psTex, (IMG_UINT32)level, (IMG_UINT32)internalformat, 
				psTexFormat, (IMG_UINT32)width, (IMG_UINT32)height);

	if(pixels && pui8Dest)
	{
		IMG_VOID *pvDest = psTex->asMipLevel[level].pui8Buffer;
		IMG_UINT8 *pui8Src = (IMG_UINT8 *)pixels;
		IMG_UINT32 ui32Align = gc->sClientPixel.ui32UnpackAlignment;
		IMG_UINT32 ui32SrcRowSize = width * ui32SrcBytesPerPixel;
		IMG_UINT32 ui32DstRowSize = width * ((psTex->psFormat->ui32BitsPerTexel+7) >> 3);
		IMG_UINT32 ui32Padding = ui32SrcRowSize % ui32Align;

		if(ui32Padding)
		{
			ui32SrcRowSize += (ui32Align - ui32Padding);
		}

		for(i=0; i < (IMG_UINT32)height; i++)
		{
			(*pfnCopySpan)(pvDest, pui8Src, (IMG_UINT32)width);

			pvDest = (IMG_UINT8 *)pvDest + ui32DstRowSize;
			pui8Src += ui32SrcRowSize;
		}
	}
	 
	/* 
	 * remove texture from active list.  If needed, validation will reload 
	 */
	TextureRemoveResident(gc, psTex);
	

	GLES_INC_PIXEL_COUNT(GLES_TIMER_TEXIMAGE_TIME, width*height);
		
	GLES_TIME_STOP(GLES_TIMES_glTexImage2D);
	GLES_TIME_STOP(GLES_TIMER_TEXIMAGE_TIME);
}


/***********************************************************************************
 Function Name      : glTexSubImage2D
 Inputs             : target, level, xoffset, yoffset, width, height, format, type, 
					  pixels
 Outputs            : -
 Returns            : -
 Description        : ENTRYPOINT: Provides texture subdata in a specified format.
					  Host texture data memory is already allocated/may have already 
					  been uploaded to HW. Subdata will need to be integrated/uploaded. 
************************************************************************************/

GLAPI void APIENTRY glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 
							GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)
{
	GLEStexture *psTex;
    GLEStextureBuffer *pui8Dest;
	IMG_UINT32 i;
	PFNCopySpan pfnCopySpan;
	IMG_UINT32 ui32SrcBytesPerPixel, ui32DstStride;
	const GLEStextureFormat *psTexFormat;
	 
	__GL_GET_CONTEXT();

	GLES_TIME_START(GLES_TIMER_TEXSUBIMAGE_TIME);
	GLES_TIME_START(GLES_TIMES_glTexSubImage2D);

	psTex = CheckTexSubImageArgs(gc, target, level, xoffset, yoffset, width, height);

	if(!psTex)
	{
		GLES_TIME_STOP(GLES_TIMER_TEXSUBIMAGE_TIME);
		return;
	}
	
	switch(format)
	{
		case GL_RGBA:
		{
			switch(type)
			{
				case GL_UNSIGNED_BYTE:
					pfnCopySpan = gc->sTexture.pfnDefaultRGBACopySpan;
					ui32SrcBytesPerPixel = 4;
					psTexFormat = gc->sTexture.psDefaultRGBAFormat;
					break;
				case GL_UNSIGNED_SHORT_5_5_5_1:
					pfnCopySpan = (PFNCopySpan) Copy5551Span;
					ui32SrcBytesPerPixel = 2;
					psTexFormat = &TexFormatRGBA5551;
					break;
				case GL_UNSIGNED_SHORT_4_4_4_4:
					pfnCopySpan = (PFNCopySpan) Copy4444Span;
					ui32SrcBytesPerPixel = 2;
					psTexFormat = &TexFormatRGBA4444;
					break;
				default:
bad_enum:
					SetError(gc, GL_INVALID_ENUM);
					GLES_TIME_STOP(GLES_TIMER_TEXSUBIMAGE_TIME);
					return;
			}
			break;
		}
		case GL_RGB:
		{
			switch(type)
			{
				case GL_UNSIGNED_BYTE:
					pfnCopySpan = gc->sTexture.pfnDefaultRGBCopySpan;
					ui32SrcBytesPerPixel = 3;
					psTexFormat = gc->sTexture.psDefaultRGBFormat;
					break;
				case GL_UNSIGNED_SHORT_5_6_5:
					pfnCopySpan = (PFNCopySpan) Copy16Span;
					ui32SrcBytesPerPixel = 2;
					psTexFormat = &TexFormatRGB565;
					break;
				default:
					goto bad_enum;
			}
			break;
		}
		case GL_ALPHA:
			if(type != GL_UNSIGNED_BYTE)
				goto bad_enum;
			
			pfnCopySpan = (PFNCopySpan) Copy8Span;
			ui32SrcBytesPerPixel = 1;			
			psTexFormat = (GLEStextureFormat *)&TexFormatAlpha;
			break;
		case GL_LUMINANCE:
			if(type != GL_UNSIGNED_BYTE)
				goto bad_enum;
			
			pfnCopySpan = (PFNCopySpan) Copy8Span;
			ui32SrcBytesPerPixel = 1;			
			psTexFormat = (GLEStextureFormat *)&TexFormatLuminance;
			break;
		case GL_LUMINANCE_ALPHA:
			if(type != GL_UNSIGNED_BYTE)
				goto bad_enum;
			
			pfnCopySpan = (PFNCopySpan) Copy16Span;
			ui32SrcBytesPerPixel = 2;
			psTexFormat = (GLEStextureFormat *)&TexFormatLuminanceAlpha;
			break;
		default:
			goto bad_enum;
	}

	if(psTexFormat != psTex->asMipLevel[level].psTexFormat)
	{
		goto bad_enum;
	}

	pui8Dest = psTex->asMipLevel[level].pui8Buffer;
	ui32DstStride = psTex->asMipLevel[level].ui32Width * ((psTexFormat->ui32BitsPerTexel+7) >> 3);

	if(pui8Dest == GLES_LOADED_LEVEL)
	{
		IMG_UINT32 ui32BufferSize = ui32DstStride * psTex->asMipLevel[level].ui32Height;
		
		pui8Dest = GLESMalloc(gc, ui32BufferSize);

		if(!pui8Dest)
		{
			SetError(gc, GL_OUT_OF_MEMORY);
			GLES_TIME_STOP(GLES_TIMER_TEXSUBIMAGE_TIME);
			return;
		}
		
		/* Don't need to readback for full size subtexture */
		if((IMG_UINT32)width != psTex->asMipLevel[level].ui32Width || 
			(IMG_UINT32)height != psTex->asMipLevel[level].ui32Height)
		{
			ReadBackTextureData(psTex, level + psTex->ui32ScaleShift, level, pui8Dest);
		}
		psTex->asMipLevel[level].pui8Buffer = pui8Dest;
	}

	if(pui8Dest && pixels)
	{
		IMG_UINT8 *pui8Src = (IMG_UINT8 *)pixels;
		IMG_UINT32 ui32Align = gc->sClientPixel.ui32UnpackAlignment;
		IMG_UINT32 ui32SrcRowSize = width * ui32SrcBytesPerPixel;
		IMG_VOID *pvDest = pui8Dest + (yoffset * ui32DstStride) + (xoffset * ((psTexFormat->ui32BitsPerTexel+7) >> 3));
		IMG_UINT32 ui32Padding = ui32SrcRowSize % ui32Align;

		if(ui32Padding)
		{
			ui32SrcRowSize += (ui32Align - ui32Padding);
		}

		for(i=0; i < (IMG_UINT32)height; i++)
		{
			(*pfnCopySpan)(pvDest, pui8Src, (IMG_UINT32)width);

			pvDest = (GLubyte *)pvDest + ui32DstStride;
			pui8Src += ui32SrcRowSize;
		}
	}

	TextureRemoveResident(gc, psTex);

	GLES_INC_PIXEL_COUNT(GLES_TIMER_TEXSUBIMAGE_TIME, width*height);
	GLES_TIME_STOP(GLES_TIMES_glTexSubImage2D);
	GLES_TIME_STOP(GLES_TIMER_TEXSUBIMAGE_TIME);
}


/***********************************************************************************
 Function Name      : glCompressedTexImage2D
 Inputs             : target, level, internalformat, width, height, border, format, 
					  imageSize, data
 Outputs            : -
 Returns            : -
 Description        : ENTRYPOINT: Provides texture data in a pre-compressed format. 
					  suggests an internal storage format. Host texture data memory 
					  is allocated but not loaded to HW until use. Palette data will need
					  decompression first.
************************************************************************************/


GLAPI void APIENTRY glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, 
								   GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data)
{
	GLEStexture *psTex;
    GLEStextureBuffer *pui8Dest;
	IMG_UINT32 i;
	PFNCopyPaletteSpan pfnCopySpan;
	IMG_UINT32 ui32SrcBitsPerPixel;
	const GLEStextureFormat *psTexFormat;
	IMG_UINT32 ui32NumLevels, ui32PaletteSize, ui32Size;
	IMG_UINT32 ui32Width = width;
	IMG_UINT32 ui32Height = height;
	IMG_VOID *pvPixels = (IMG_VOID *)data;

	__GL_GET_CONTEXT();

	GLES_TIME_START(GLES_TIMER_COMPRESSTEXIMAGE_TIME);
	GLES_TIME_START(GLES_TIMES_glCompressedTexImage2D);

	ui32PaletteSize = 0;

	switch(internalformat)
	{
		case GL_PALETTE4_RGB8_OES:
			ui32PaletteSize = 3 * (1 << 4);
			ui32SrcBitsPerPixel = 4;
			pfnCopySpan = 	(PFNCopyPaletteSpan) Copy888Palette4Span;
			psTexFormat = (GLEStextureFormat *)&TexFormatRGB888;
			break;
		case GL_PALETTE4_RGBA8_OES:
			ui32PaletteSize = 4 * (1 << 4);
			ui32SrcBitsPerPixel = 4;
			pfnCopySpan = 	(PFNCopyPaletteSpan) Copy8888Palette4Span;
			psTexFormat = (GLEStextureFormat *)&TexFormatRGBA8888;
			break;
		case GL_PALETTE4_R5_G6_B5_OES:
			ui32PaletteSize = 2 * (1 << 4);
			ui32SrcBitsPerPixel = 4;
			pfnCopySpan = 	(PFNCopyPaletteSpan) Copy565Palette4Span;
			psTexFormat = (GLEStextureFormat *)&TexFormatRGB565;
			break;
		case GL_PALETTE4_RGBA4_OES:
			ui32PaletteSize = 2 * (1 << 4);
			ui32SrcBitsPerPixel = 4;
			pfnCopySpan = 	(PFNCopyPaletteSpan) Copy4444Palette4Span;
			psTexFormat = (GLEStextureFormat *)&TexFormatRGBA4444;
			break;
		case GL_PALETTE4_RGB5_A1_OES:
			ui32PaletteSize = 2 * (1 << 4);
			ui32SrcBitsPerPixel = 4;
			pfnCopySpan = 	(PFNCopyPaletteSpan) Copy5551Palette4Span;
			psTexFormat = (GLEStextureFormat *)&TexFormatRGBA5551;
			break;
		case GL_PALETTE8_RGB8_OES:
			ui32PaletteSize = 3 * (1 << 8);
			ui32SrcBitsPerPixel = 8;
			pfnCopySpan = 	(PFNCopyPaletteSpan) Copy888Palette8Span;
			psTexFormat = (GLEStextureFormat *)&TexFormatRGB888;
			break;
		case GL_PALETTE8_RGBA8_OES:
			ui32PaletteSize = 4 * (1 << 8);
			ui32SrcBitsPerPixel = 8;
			pfnCopySpan = 	(PFNCopyPaletteSpan) Copy8888Palette8Span;
			psTexFormat = (GLEStextureFormat *)&TexFormatRGBA8888;
			break;
		case GL_PALETTE8_R5_G6_B5_OES:
			ui32PaletteSize = 2 * (1 << 8);
			ui32SrcBitsPerPixel = 8;
			pfnCopySpan = 	(PFNCopyPaletteSpan) Copy565Palette8Span;
			psTexFormat = (GLEStextureFormat *)&TexFormatRGB565;
			break;
		case GL_PALETTE8_RGBA4_OES:
			ui32PaletteSize = 2 * (1 << 8);
			ui32SrcBitsPerPixel = 8;
			pfnCopySpan = 	(PFNCopyPaletteSpan) Copy4444Palette8Span;
			psTexFormat = (GLEStextureFormat *)&TexFormatRGBA4444;
			break;
		case GL_PALETTE8_RGB5_A1_OES:
			ui32PaletteSize = 2 * (1 << 8);
			ui32SrcBitsPerPixel = 8;
			pfnCopySpan = 	(PFNCopyPaletteSpan) Copy5551Palette8Span;
			psTexFormat = (GLEStextureFormat *)&TexFormatRGBA5551;
			break;
		case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG:
			ui32SrcBitsPerPixel = 64;
			pfnCopySpan = 	(PFNCopyPaletteSpan) Copy64Span;
			psTexFormat = (GLEStextureFormat *)&TexFormatPVRTC2RGB;
			break;
		case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:
			ui32SrcBitsPerPixel = 64;
			pfnCopySpan = 	(PFNCopyPaletteSpan) Copy64Span;
			psTexFormat = (GLEStextureFormat *)&TexFormatPVRTC2RGBA;
			break;
		case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG:
			ui32SrcBitsPerPixel = 64;
			pfnCopySpan = 	(PFNCopyPaletteSpan) Copy64Span;
			psTexFormat = (GLEStextureFormat *)&TexFormatPVRTC4RGB;
			break;
		case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG:
			ui32SrcBitsPerPixel = 64;
			pfnCopySpan = 	(PFNCopyPaletteSpan) Copy64Span;
			psTexFormat = (GLEStextureFormat *)&TexFormatPVRTC4RGBA;
			break;
		default:
			SetError(gc, GL_INVALID_ENUM);
			GLES_TIME_STOP(GLES_TIMER_COMPRESSTEXIMAGE_TIME);
			return;
	}

	psTex = CheckTexImageArgs(gc, target, level, ui32PaletteSize ? IMG_TRUE : IMG_FALSE, width, height, border);

	if(!psTex)
	{
		GLES_TIME_STOP(GLES_TIMER_COMPRESSTEXIMAGE_TIME);
		return;
	}

	if(ui32PaletteSize)
	{
		ui32NumLevels = (IMG_UINT32)GLES_ABS(level) + 1;
		
		ui32Size = 0;
		
		if(ui32NumLevels > 1)
		{
			for(i=0; i < GLES_MAX_TEXTURE_MIPMAP_LEVELS; i++)
			{
				ui32Size += ((ui32Width * ui32Height * ui32SrcBitsPerPixel) >> 3);
				
				if(ui32Width == 1 && ui32Height == 1)
					break;
				
				ui32Width >>= 1;
				ui32Height >>= 1;
				
				if(ui32Width == 0)
					ui32Width = 1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -