1 #include "mof/private/TextureImpl.hpp"
2 #include "mof/ConsoleIO.hpp"
3 #include "mof/private/FileTextureBuilder.hpp"
4 #include "mof/private/PixelMapTextureBuilder.hpp"
6 mof::Texture::Texture( const tstring& filename)
9 m_pImpl->pTexture = mof::FileTextureBuilder( filename).create();
11 m_pImpl->pTexture->GetLevelDesc(0 , &desc);
12 m_pImpl->width = desc.Width;
13 m_pImpl->height = desc.Height;
16 mof::Texture::Texture( const std::shared_ptr<mof::PixelMap>& pPixelMap)
19 m_pImpl->pTexture = mof::PixelMapTextureBuilder(pPixelMap).create();
21 m_pImpl->pTexture->GetLevelDesc(0 , &desc);
22 m_pImpl->width = desc.Width;
23 m_pImpl->height = desc.Height;
26 mof::Texture::~Texture(){}
28 std::shared_ptr<mof::PixelMap> mof::Texture::getPixelMap(){
29 typedef mof::PixelMap::size_type size_type;
30 boost::array<size_type , 2> sizes = {{getWidth() , getHeight()}};
32 std::shared_ptr<mof::PixelMap> pMap(new mof::PixelMap(sizes));
34 m_pImpl->pTexture->LockRect(0 , &rect , NULL , 0);
35 for(int y = 0 ; y < getHeight() ; y++){
36 for(int x = 0 ; x < getWidth() ; x++){
37 BYTE* pPixel = (BYTE*)rect.pBits + x * 4 + y * rect.Pitch;
38 (*pMap)[x][y] = mof::createColor(*(pPixel + 3) , *(pPixel+2) , *(pPixel+1) , *(pPixel));
41 m_pImpl->pTexture->UnlockRect(0);
45 int mof::Texture::getWidth(){
46 return m_pImpl->width;
49 int mof::Texture::getHeight(){
50 return m_pImpl->height;