Texture* APIBridge::CreateTexture(const void *data, int byteSize) { assert(d3dDevice); IDirect3DTexture9 *d3dTexture = NULL; /** The created d3dTexture is located in managed pool.*/ if (D3D_OK != D3DXCreateTextureFromFileInMemory(d3dDevice, data, byteSize, &d3dTexture)) return NULL; Texture *texture = new Texture; texture->apitexture = d3dTexture; /** Get d3d texture's attributes, copy them to texture spec.*/ D3DSURFACE_DESC desc; d3dTexture->GetLevelDesc(0, &desc); Texture::Spec& spec = texture->spec; spec.format = static_cast<EPixelFormat>(desc.Format); spec.usage = static_cast<EResourceUsage>(desc.Usage); spec.width = desc.Width; spec.height = desc.Height; spec.mipLevels = d3dTexture->GetLevelCount(); return texture; }
CTexture::CTexture(CDisplayDevice *pDevice, void *pBuffer, int iSize) { bool bResult; #if (RENDER == DX9) bResult = D3DXCreateTextureFromFileInMemory(pDevice->m_pDevice, pBuffer, iSize, &m_poTexture) == D3D_OK; #endif }
u32 Texture::load() { release(); if(!buffer->data || !buffer->size)return 0; if(SUCCEEDED( D3DXCreateTextureFromFileInMemory(gEngine.device->getDev(), buffer->data, buffer->size, &lpTexture) )) //if(SUCCEEDED( D3DXCreateTextureFromFileInMemoryEx(gEngine.device->getDev(), buffer->data, buffer->size, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &lpTexture) )) { D3DSURFACE_DESC surfaceDesc; lpTexture->GetLevelDesc(0, &surfaceDesc); width = surfaceDesc.Width; height = surfaceDesc.Height; //lpTexture->GenerateMipSubLevels(); gEngine.kernel->addMemUsage("Texture", width * height * sizeof(u32)); gEngine.kernel->mem->freeBuff(*buffer); delete(buffer); buffer = 0; gEngine.kernel->log->prnEx(LT_SUCCESS, "Texture", "Created texture '%s'.", strFilename.c_str()); return 1; } else { width = height = 0; lpTexture = 0; gEngine.kernel->mem->freeBuff(*buffer); delete(buffer); buffer = 0; return 0; } }
bool CMeshRenderer::Init ( char* pFileName ) { int nLen = 0, i = 0; s_cMeshLoader.Initial( pFileName ); nObjCount = s_cMeshLoader.GetObjectCount(); nMatCount = s_cMeshLoader.GetTextureCount(); m_vRot = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); m_vPos = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); m_vScl = D3DXVECTOR3( 1.0f, 1.0f, 1.0f ); D3DXMatrixIdentity ( &m_mWorld ); m_ppTB = new LPDIRECT3DTEXTURE9 [nMatCount]; m_ppVB = new LPDIRECT3DVERTEXBUFFER9 [nObjCount]; m_ppIB = new LPDIRECT3DINDEXBUFFER9 [nObjCount]; m_pnMatID = new int [nObjCount]; m_pnVNum = new int [nObjCount]; m_pnINum = new int [nObjCount]; m_pmMatrix = new D3DXMATRIX [nObjCount]; m_pvPivot = new D3DXVECTOR3 [nObjCount]; m_pvRot = new D3DXVECTOR3 [nObjCount]; m_pvPos = new D3DXVECTOR3 [nObjCount]; m_pvScl = new D3DXVECTOR3 [nObjCount]; for ( i = 0; i < nMatCount; i ++ ) { unsigned char* pData = s_cMeshLoader.GetTextureSource( i, &nLen ); D3DXCreateTextureFromFileInMemory( D3DFRAME->GetDevice(), pData, nLen, &m_ppTB[i] ); } for ( i = 0; i < nObjCount; i ++ ) { POBJECT pObj = s_cMeshLoader.GetObjectSource(i); m_pnVNum[i] = pObj->nVCount; m_pnINum[i] = pObj->nICount; void* pData = NULL; D3DFRAME->GetDevice()->CreateVertexBuffer ( m_pnVNum[i] * sizeof(SCUSTOMVERTEX), 0, 0, D3DPOOL_DEFAULT, &m_ppVB[i], NULL ); D3DFRAME->GetDevice()->CreateIndexBuffer ( m_pnINum[i] * sizeof(unsigned short), D3DUSAGE_DYNAMIC, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &m_ppIB[i], NULL ); m_ppVB[i]->Lock( 0, 0, &pData, D3DLOCK_DISCARD ); memcpy ( pData, pObj->pVertices, sizeof(SCUSTOMVERTEX)*m_pnVNum[i]); m_ppVB[i]->Unlock(); m_ppIB[i]->Lock( 0, 0, &pData, D3DLOCK_DISCARD ); memcpy ( pData, pObj->pIndices, sizeof(unsigned short)*m_pnINum[i]); m_ppIB[i]->Unlock(); m_pnMatID[i] = pObj->uTexIndex; D3DXMatrixIdentity ( &m_pmMatrix[i] ); m_pvPivot[i] = D3DXVECTOR3( pObj->pivotX, pObj->pivotY, pObj->pivotZ); m_pvRot[i] = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); m_pvPos[i] = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); m_pvScl[i] = D3DXVECTOR3( 1.0f, 1.0f, 1.0f ); } s_cMeshLoader.Release(); return true; }
//---------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------- void Renderer::LoadBackgroundImage( void* data, int32_t size ) { ES_SAFE_RELEASE( m_backGroundTexture ); if( data != NULL ) { D3DXCreateTextureFromFileInMemory( m_renderer->GetDevice(), data, size, &m_backGroundTexture ); } else { } }
void TextureImpl_DirectX9::LoadFromMemory(const void *data, size_t size) { LPDIRECT3DDEVICE9 device = NULL; if (device = DrawManager::GetDeviceHandle()) { D3DXCreateTextureFromFileInMemory(device, data, size, &_texture); } if (!_texture) return; D3DSURFACE_DESC desc; _texture->GetLevelDesc(0, &desc); _size.width = desc.Width; _size.height = desc.Height; _format = desc.Format; }
Texture * Texture::Create( void * i_pData, unsigned int i_DataSizeB ) { assert( i_pData ); assert( i_DataSizeB > 0 ); assert( g_pD3DDevice ); IDirect3DTexture9 * pNewTexture = NULL; HRESULT result = D3DXCreateTextureFromFileInMemory( g_pD3DDevice, i_pData, i_DataSizeB, &pNewTexture ); if( result == D3D_OK ) return new Texture( pNewTexture ); return NULL; }
bool CD3DMGEng::LoadFontTextureFromMem ( PVOID pvMemory, DWORD dwSizeOfFile ) { D3DSURFACE_DESC desc; ////////////////////////////////////////////////// // Release any existing texture. SAFE_RELEASE( m_pFontTexture ); ////////////////////////////////////////////////// // Load the requested texture from memory. if ( (D3D_OK != D3DXCreateTextureFromFileInMemory( m_pDevice, pvMemory, dwSizeOfFile, &m_pFontTexture )) ) { return false; } m_pFontTexture->GetLevelDesc( 0, &desc ); m_fFontTexWidth = static_cast<float>(desc.Width); m_fFontTexHeight = static_cast<float>(desc.Height); LoadDefaultFontInfo(); return true; }
Texture* RendererD3D::CreateTexture(DDS* dds, uint dataSize) { /* D3DFORMAT format = D3DFMT_UNKNOWN; if( dds->HasFourCC() ) { if( !dds->HasDDSHeader10() ) { format = (D3DFORMAT)dds->mPixelFormat.mFourCC; } } else if( dds->HasRGB() ) { if( dds->HasAlphaPixels() ) { if( dds->mPixelFormat.mRGBBitCount == 32 ) { if( dds->mPixelFormat.mRedMask == 0x3ff00000 ) format = D3DFMT_A2R10G10B10; else format = D3DFMT_A8R8G8B8; } else // 16 bit { if( dds->mPixelFormat.mRedMask == 0xf00 ) format = D3DFMT_A4R4G4B4; else format = D3DFMT_A8R3G3B2; } } else { if( dds->mPixelFormat.mRGBBitCount == 32 ) { if( dds->mPixelFormat.mRedMask == 0xff0000 ) format = D3DFMT_X8R8G8B8; else format = D3DFMT_X8B8G8R8; } else if( dds->mPixelFormat.mRGBBitCount == 24 ) { format = D3DFMT_R8G8B8; } else // 16 bit { if( dds->mPixelFormat.mRedMask == 0x7c00 ) format = D3DFMT_X1R5G5B5; else format = D3DFMT_X4R4G4B4; } } } else if( dds->HasLuminance() ) { if( dds->mPixelFormat.mRGBBitCount == 16 ) { if( dds->mPixelFormat.mRedMask == 0xffff ) format = D3DFMT_L16; else format = D3DFMT_A8L8; } else // 8 bit { if( dds->mPixelFormat.mRedMask == 0xF ) format = D3DFMT_A4L4; else format = D3DFMT_L8; } } if( format == D3DFMT_UNKNOWN ) return 0; */ TextureD3D9* texture = 0; IDirect3DTexture9* d3dTexture = 0; HRESULT res = D3DXCreateTextureFromFileInMemory(mDevice, dds, dataSize, &d3dTexture); if( res == D3D_OK ) { texture = new TextureD3D9(d3dTexture, dds); } return texture; }
// コンストラクタ CMesh::CMesh(LPDIRECT3DDEVICE9 device, string file, CArchiveLoader* archive) : Device(device), Mesh(NULL), NumMaterials(0), Materials(NULL), Textures(NULL), ColorMultiplier(1, 1, 1, 1), ColorAddition(0, 0, 0, 0) { string path=ExtractFilePath(file); // ファイルを読み込む LPD3DXBUFFER buf_materials=NULL; if (archive) { ARCHIVE_ENTRY* e=archive->Find(file); if (e) { D3DXLoadMeshFromXInMemory( e->Data, e->Size, D3DXMESH_SYSTEMMEM, Device, NULL, &buf_materials, NULL, &NumMaterials, &Mesh); } } else { D3DXLoadMeshFromX( file.c_str(), D3DXMESH_SYSTEMMEM, Device, NULL, &buf_materials, NULL, &NumMaterials, &Mesh); } // マテリアルとテクスチャのための配列を確保する D3DXMATERIAL* materials; if (buf_materials) { materials=(D3DXMATERIAL*)buf_materials->GetBufferPointer(); Materials=new D3DMATERIAL9[NumMaterials]; Textures=new LPDIRECT3DTEXTURE9[NumMaterials]; } // マテリアルをコピーし,テクスチャを読み込む for (DWORD i=0; i<NumMaterials; i++ ) { // マテリアルをコピーする Materials[i]=materials[i].MatD3D; // アンビエント色を設定する Materials[i].Ambient=Materials[i].Diffuse; // テクスチャを読み込む Textures[i]=NULL; char* texture_file=materials[i].pTextureFilename; if (texture_file && lstrlen(texture_file)>0) { if (archive) { ARCHIVE_ENTRY* e=archive->Find(path+texture_file); if (!e) continue; D3DXCreateTextureFromFileInMemory( Device, e->Data, e->Size, &Textures[i]); } else { D3DXCreateTextureFromFile( Device, (path+texture_file).c_str(), &Textures[i]); } } } /* // 最適化 DWORD* adjacency=new DWORD[Mesh->GetNumFaces()*3]; HRESULT result; result=Mesh->GenerateAdjacency(0, adjacency); result=Mesh->OptimizeInplace(D3DXMESHOPT_STRIPREORDER, adjacency, NULL, NULL, NULL); delete adjacency; */ // 後片づけ if (buf_materials) buf_materials->Release(); }