コード例 #1
0
void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * pixels)
{
	bool is_set = false;
	
#ifdef _DEBUG
	return;
#endif

#if 1 // no mipmap
	if (level > 0)
		return;
#endif

	if (!GLImpl.tmus[GLImpl.current_tmu].boundtexture) {
		printf("Not texture binded\n");
		return;
	}
		
	GLImpl.device->SetTexture(0, NULL);
	GLTexture * surf = NULL;
	
	if (GLImpl.tmus[GLImpl.current_tmu].boundtexture && GLImpl.tmus[GLImpl.current_tmu].boundtexture->teximg ) {
		surf = GLImpl.tmus[GLImpl.current_tmu].boundtexture->teximg;
	}
	
	if (surf) {
		int srcbytes = src_format_to_bypp(format);
		int dstbytes = dst_format_to_bypp(GLImpl.tmus[GLImpl.current_tmu].boundtexture->internalformat);
		BYTE * surfbuf;
		BYTE * srcdata = (BYTE*) pixels;
		BYTE * dstdata;

		surf->lockTexture(level);

		srcdata = (BYTE*) pixels;
		surfbuf = (BYTE*)surf->getData();		
		dstdata = (BYTE*)surf->getData();
		
		check_format(srcbytes, dstbytes);

		copyImage(xoffset, yoffset, width, height, srcdata, srcbytes, surfbuf, dstbytes);

		surf->unlockTexture(level);

		GLImpl.tmus[GLImpl.current_tmu].boundtexture->dirty = 1;
	}
}
コード例 #2
0
void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * pixels)
{
	if (level > 0)
		return;
		
	if (!xeTmus[xeCurrentTMU].boundtexture) {
		printf("Not texture binded\n");
		return;
	}
		
	struct XenosSurface * surf = NULL;
	
	if (xeTmus[xeCurrentTMU].boundtexture && xeTmus[xeCurrentTMU].boundtexture->teximg ) {
		surf = xeTmus[xeCurrentTMU].boundtexture->teximg;
	}
	
	if (surf) {
		int srcbytes = src_format_to_bypp(format);
		int dstbytes = dst_format_to_bypp(xeTmus[xeCurrentTMU].boundtexture->internalformat);
		
		uint8_t * surfbuf = (uint8_t*) MyXeSurfaceLockRect(xe, surf, 0, 0, 0, 0, XE_LOCK_WRITE);
		uint8_t * srcdata = (uint8_t*) pixels;
		uint8_t * dstdata = surfbuf;
		
		int y, x;

		int pitch = (width * dstbytes);
		int offset = 0;
		
		check_format(srcbytes, dstbytes);

		for (y = yoffset; y < (yoffset + height); y++) {
			offset = (y * pitch)+(xoffset * dstbytes);
			dstdata = surfbuf + offset;
			
			for (x = xoffset; x < (xoffset + width); x++) {
				if (srcbytes == 4) {
					if (dstbytes == 4) {
						dstdata[0] = srcdata[3];
						dstdata[3] = srcdata[2];
						dstdata[2] = srcdata[1];
						dstdata[1] = srcdata[0];
					} else if(dstbytes == 1) {
						dstdata[0] = ((int) srcdata[0] + (int) srcdata[1] + (int) srcdata[2] + (int) srcdata[3]) / 3;
					}
						
					srcdata += srcbytes;
					dstdata += dstbytes;
					
				} else if (srcbytes == 3) {
					if (dstbytes == 4) {					
						dstdata[0] = 0xff;
						dstdata[3] = srcdata[2];
						dstdata[2] = srcdata[1];
						dstdata[1] = srcdata[0];
					} else if (dstbytes == 1) {
						dstdata[0] = ((int) srcdata[0] + (int) srcdata[1] + (int) srcdata[2]) / 3;
					}
						
					srcdata += srcbytes;
					dstdata += dstbytes;
				} else if (srcbytes == 1) {
					if (dstbytes == 1) {
						dstdata[0] = srcdata[0];
					} else if (dstbytes == 4) {
						dstdata[0] = srcdata[0];
						dstdata[1] = srcdata[0];
						dstdata[2] = srcdata[0];
						dstdata[3] = srcdata[0];
					}
					srcdata += srcbytes;
					dstdata += dstbytes;
				}
			}
		}
	
		MyXeSurfaceUnlock(xe, surf);		
		
		xeTmus[xeCurrentTMU].boundtexture->dirty = 1;

#ifndef USE_TILED_TEXTURE	
		handle_small_surface(surf, NULL);
#endif		
	}
}