X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=source%2Frice_gles%2Fsrc%2FTexture.cpp;fp=source%2Frice_gles%2Fsrc%2FTexture.cpp;h=9eb82f4a07040a201a8a6bb1d4b9074feeb9bb38;hb=d07c171fa694cae985ad7045f9ce2b2f1a5699b4;hp=0000000000000000000000000000000000000000;hpb=ca22e7b76883b946060a6b40bb8709c1981e1cf6;p=mupen64plus-pandora.git diff --git a/source/rice_gles/src/Texture.cpp b/source/rice_gles/src/Texture.cpp new file mode 100755 index 0000000..9eb82f4 --- /dev/null +++ b/source/rice_gles/src/Texture.cpp @@ -0,0 +1,275 @@ +/* +Copyright (C) 2003 Rice1964 + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "TextureManager.h" + + +////////////////////////////////////////// +// Constructors / Deconstructors + +// Probably shouldn't need more than 4096 * 4096 + +CTexture::CTexture(uint32 dwWidth, uint32 dwHeight, TextureUsage usage) : + m_dwWidth(dwWidth), + m_dwHeight(dwHeight), + m_dwCreatedTextureWidth(dwWidth), + m_dwCreatedTextureHeight(dwHeight), + m_fXScale(1.0f), + m_fYScale(1.0f), + m_bScaledS(false), + m_bScaledT(false), + m_bClampedS(false), + m_bClampedT(false), + m_bIsEnhancedTexture(false), + m_Usage(usage), + m_pTexture(NULL), + m_dwTextureFmt(TEXTURE_FMT_A8R8G8B8) +{ + // fix me, do something here +} + + +CTexture::~CTexture(void) +{ +} + +TextureFmt CTexture::GetSurfaceFormat(void) +{ + if (m_pTexture == NULL) + return TEXTURE_FMT_UNKNOWN; + else + return m_dwTextureFmt; +} + +uint32 CTexture::GetPixelSize() +{ + if( m_dwTextureFmt == TEXTURE_FMT_A8R8G8B8 ) + return 4; + else + return 2; +} + + +// There are reasons to create this function. D3D and OGL will only create surface of width and height +// as 2's pow, for example, N64's 20x14 image, D3D and OGL will create a 32x16 surface. +// When we using such a surface as D3D texture, and the U and V address is for the D3D and OGL surface +// width and height. It is still OK if the U and V addr value is less than the real image within +// the D3D surface. But we will have problems if the U and V addr value is larger than it, or even +// large then 1.0. +// In such a case, we need to scale the image to the D3D surface dimension, to ease the U/V addr +// limition +void CTexture::ScaleImageToSurface(bool scaleS, bool scaleT) +{ + uint8 g_ucTempBuffer[1024*1024*4]; + + if( scaleS==false && scaleT==false) return; + + // If the image is not scaled, call this function to scale the real image to + // the D3D given dimension + + uint32 width = scaleS ? m_dwWidth : m_dwCreatedTextureWidth; + uint32 height = scaleT ? m_dwHeight : m_dwCreatedTextureHeight; + + uint32 xDst, yDst; + uint32 xSrc, ySrc; + + DrawInfo di; + + if (!StartUpdate(&di)) + { + return; + } + + int pixSize = GetPixelSize(); + + // Copy across from the temp buffer to the surface + switch (pixSize) + { + case 4: + { + memcpy((uint8*)g_ucTempBuffer, (uint8*)(di.lpSurface), m_dwHeight*m_dwCreatedTextureWidth*4); + + uint32 * pDst; + uint32 * pSrc; + + for (yDst = 0; yDst < m_dwCreatedTextureHeight; yDst++) + { + // ySrc ranges from 0..m_dwHeight + // I'd rather do this but sometimes very narrow (i.e. 1 pixel) + // surfaces are created which results in /0... + //ySrc = (yDst * (m_dwHeight-1)) / (d3dTextureHeight-1); + ySrc = (uint32)((yDst * height) / m_dwCreatedTextureHeight+0.49f); + + pSrc = (uint32*)((uint8*)g_ucTempBuffer + (ySrc * m_dwCreatedTextureWidth * 4)); + pDst = (uint32*)((uint8*)di.lpSurface + (yDst * di.lPitch)); + + for (xDst = 0; xDst < m_dwCreatedTextureWidth; xDst++) + { + xSrc = (uint32)((xDst * width) / m_dwCreatedTextureWidth+0.49f); + pDst[xDst] = pSrc[xSrc]; + } + } + } + + break; + case 2: + { + memcpy((uint8*)g_ucTempBuffer, (uint8*)(di.lpSurface), m_dwHeight*m_dwCreatedTextureWidth*2); + + uint16 * pDst; + uint16 * pSrc; + + for (yDst = 0; yDst < m_dwCreatedTextureHeight; yDst++) + { + // ySrc ranges from 0..m_dwHeight + ySrc = (yDst * height) / m_dwCreatedTextureHeight; + + pSrc = (uint16*)((uint8*)g_ucTempBuffer + (ySrc * m_dwCreatedTextureWidth * 2)); + pDst = (uint16*)((uint8*)di.lpSurface + (yDst * di.lPitch)); + + for (xDst = 0; xDst < m_dwCreatedTextureWidth; xDst++) + { + xSrc = (xDst * width) / m_dwCreatedTextureWidth; + pDst[xDst] = pSrc[xSrc]; + } + } + } + break; + + } + + EndUpdate(&di); + + if( scaleS ) m_bScaledS = true; + if( scaleT ) m_bScaledT = true; +} + +void CTexture::ClampImageToSurfaceS() +{ + if( !m_bClampedS && m_dwWidth < m_dwCreatedTextureWidth ) + { + DrawInfo di; + if( StartUpdate(&di) ) + { + if( m_dwTextureFmt == TEXTURE_FMT_A8R8G8B8 ) + { + for( uint32 y = 0; y>16); + uint32 dwGreen = (uint8)((dw & 0x0000FF00)>>8 ); + uint32 dwBlue = (uint8)((dw & 0x000000FF) ); + uint32 dwAlpha = (dwRed+dwGreen+dwBlue)/3; + dw &= 0x00FFFFFF; + dw |= (dwAlpha<<24); + + /* + uint32 dw = dwSrc[x]; + if( (dw&0x00FFFFFF) > 0 ) + dw |= 0xFF000000; + else + dw &= 0x00FFFFFF; + */ + } + } + EndUpdate(&di); + } + else + { + //TRACE0("Cannot lock texture"); + } +} +