afTexture.cpp
资源名称:AirForce.rar [点击查看]
上传用户:kaiguan
上传日期:2007-10-28
资源大小:1074k
文件大小:1k
源码类别:
其他游戏
开发平台:
Visual C++
- #include "afTexture.h"
- #include "afLog.h"
- afTexture::afTexture() : d3dTexture(NULL)
- {
- width = height = 0;
- format = afImage::UNKNOWN;
- name = "noname";
- lockLevel = -1;
- }
- afTexture::afTexture(const afString& nName, LPDIRECT3DTEXTURE9 nD3DTex,
- int nWidth, int nHeight, afImage::FORMAT nFormat) : d3dTexture(nD3DTex)
- {
- name = nName;
- width = nWidth;
- height = nHeight;
- format = nFormat;
- lockLevel = -1;
- }
- bool afTexture::isCompressed() const
- {
- return afImage::isCompressed(format);
- }
- bool afTexture::getData(unsigned char*& nData, int& nPitch, int nLevel, bool nReadOnly)
- {
- if(!d3dTexture || lockLevel>=0)
- return false;
- D3DLOCKED_RECT lockedRect;
- if(d3dTexture->LockRect(nLevel, &lockedRect, NULL, nReadOnly ? D3DLOCK_READONLY : 0) != D3D_OK)
- return false;
- nData = (unsigned char*)lockedRect.pBits;
- nPitch = lockedRect.Pitch;
- lockLevel = nLevel;
- return true;
- }
- void afTexture::releaseData()
- {
- if(lockLevel<0)
- return;
- d3dTexture->UnlockRect(lockLevel);
- lockLevel = -1;
- }