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; } }
void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum pixelformat, GLenum type, const GLvoid *pixels) { int format; int need_texture = 1; struct XenosSurface * surf = NULL; if (type != GL_UNSIGNED_BYTE) { xe_gl_error("glTexImage2D: Unrecognised pixel format\n"); return; } if (target != GL_TEXTURE_2D) return; if (!xeTmus[xeCurrentTMU].boundtexture) { printf("No texture bound\n"); return; } if (level > 0) return; #if 1 int srcbytes = src_format_to_bypp(pixelformat); int dstbytes = 4; // validate format switch (internalformat) { case 1: case GL_LUMINANCE: dstbytes = 1; format = XE_FMT_8; break; case 3: case GL_RGB: dstbytes = 4; format = XE_FMT_ARGB|XE_FMT_8888; break; case 4: case GL_RGB8: case GL_RGBA: dstbytes = 4; format = XE_FMT_ARGB|XE_FMT_8888; break; default: printf("%X internalformat\n" , internalformat); xe_gl_error ("invalid texture internal format\n"); return; } if (xeTmus[xeCurrentTMU].boundtexture->teximg) { surf = xeTmus[xeCurrentTMU].boundtexture->teximg; if ((surf->width != width) || (surf->height != height) || (surf->format != format)) { need_texture = 1; // destroy texture Xe_DestroyTexture(xe, xeTmus[xeCurrentTMU].boundtexture->teximg); } else { need_texture = 0; } } if (need_texture) { #ifdef USE_TILED_TEXTURE surf = MyXeCreateTexture(xe, width, height, 0, format, 1); #else surf = MyXeCreateTexture(xe, width, height, 0, format, 0); #endif xeTmus[xeCurrentTMU].boundtexture->teximg = surf; } memset(surf->base, 0xFF, surf->wpitch * surf->hpitch); xeTmus[xeCurrentTMU].boundtexture->internalformat = 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; check_format(srcbytes, dstbytes); for (y = 0; y <height; y++) { dstdata = surfbuf + ((y * width) * dstbytes); for (x = 0; x < 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; #endif handle_small_surface(surf, NULL); }
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 } }
void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum pixelformat, GLenum type, const GLvoid *pixels) { D3DFORMAT format; int need_texture = 1; GLTexture * surf= NULL; if (type != GL_UNSIGNED_BYTE) { xe_gl_error("glTexImage2D: Unrecognised pixel format\n"); return; } if (target != GL_TEXTURE_2D) return; if (!GLImpl.tmus[GLImpl.current_tmu].boundtexture) { printf("No texture bound\n"); return; } #if 1 // no mipmap if (level > 0) return; #endif GLImpl.device->SetTexture(0, NULL); int srcbytes = src_format_to_bypp(pixelformat); int dstbytes = 4; // validate format switch (internalformat) { case 1: case GL_LUMINANCE: dstbytes = 1; //format = D3DFMT_LIN_L8; format = D3DFMT_L8; break; case 3: case GL_RGB8: case GL_RGB: dstbytes = 4; //format = D3DFMT_LIN_A8R8G8B8; format = D3DFMT_A8R8G8B8; break; case 4: case GL_RGBA: case GL_RGBA8: dstbytes = 4; //format = D3DFMT_LIN_A8R8G8B8; format = D3DFMT_A8R8G8B8; break; default: printf("%X internalformat\n" , internalformat); xe_gl_error ("invalid texture internal format\n"); return; } if (level > 0) { need_texture = 0; } if (GLImpl.tmus[GLImpl.current_tmu].boundtexture->teximg && level == 0) { D3DSURFACE_DESC desc; surf = GLImpl.tmus[GLImpl.current_tmu].boundtexture->teximg; surf->GetLevelDesc(level, &desc); if ((desc.Width != width) || (desc.Height != height) || (desc.Format != format)) { need_texture = 1; // destroy texture delete GLImpl.tmus[GLImpl.current_tmu].boundtexture->teximg; } else { need_texture = 0; } } if (need_texture) { surf = new GLTexture(width, height, format); GLImpl.tmus[GLImpl.current_tmu].boundtexture->teximg = surf; } else { surf = GLImpl.tmus[GLImpl.current_tmu].boundtexture->teximg; } // lock texture surf->lockTexture(level); memset(surf->getData(), 0x00, surf->getPitch() * height); GLImpl.tmus[GLImpl.current_tmu].boundtexture->internalformat = internalformat; BYTE * surfbuf = (BYTE*) surf->getData(); BYTE * srcdata = (BYTE*) pixels; BYTE * dstdata = surfbuf; check_format(srcbytes, dstbytes); copyImage(0, 0, width, height, srcdata, srcbytes, surfbuf, dstbytes); surf->unlockTexture(level); GLImpl.tmus[GLImpl.current_tmu].boundtexture->dirty = 1; }