[760] | 1 | #include "dxstdafx.h"
|
---|
| 2 | #include ".\dxtexture.h"
|
---|
| 3 | #include <d3dx9.h>
|
---|
| 4 | #include <dxerr9.h>
|
---|
| 5 |
|
---|
| 6 |
|
---|
| 7 | CDXTexture::CDXTexture()
|
---|
| 8 | {
|
---|
| 9 | SetStage(0);
|
---|
| 10 | m_Stencil = NULL;
|
---|
| 11 | m_Tex = NULL;
|
---|
| 12 | m_pBackBuffer = NULL;
|
---|
| 13 | m_OrigDepthStencil = NULL;
|
---|
| 14 | m_RTindex = 0;
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | CDXTexture::~CDXTexture(void)
|
---|
| 18 | {
|
---|
| 19 | SAFE_RELEASE(m_Tex);
|
---|
| 20 | SAFE_RELEASE(m_Stencil);
|
---|
| 21 | SAFE_RELEASE(m_pBackBuffer);
|
---|
| 22 | SAFE_RELEASE(m_OrigDepthStencil);
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | bool CDXTexture::InitTex(LPDIRECT3DDEVICE9 dev, char* filename, char* tex_name, D3DFORMAT format)
|
---|
| 26 | {
|
---|
| 27 | CopyToName(tex_name);
|
---|
| 28 |
|
---|
| 29 | m_Dev = dev;
|
---|
| 30 |
|
---|
| 31 | D3DXIMAGE_INFO info;
|
---|
| 32 |
|
---|
| 33 | D3DXCreateTextureFromFileEx(
|
---|
| 34 | dev, // device
|
---|
| 35 | (LPCWSTR)filename, // filename
|
---|
| 36 | D3DX_DEFAULT, // x size
|
---|
| 37 | D3DX_DEFAULT, // y size
|
---|
| 38 | D3DX_DEFAULT, // mipmap
|
---|
| 39 | 0, // usage
|
---|
| 40 | format,// a tárolási formát a file határozza meg
|
---|
| 41 | D3DPOOL_DEFAULT,// a videomemóriába legyen
|
---|
| 42 | D3DX_DEFAULT, // filterek
|
---|
| 43 | D3DX_DEFAULT, // mipmap filter
|
---|
| 44 | 0, // nincs colorkey
|
---|
| 45 | &info, // file infókat ide adja
|
---|
| 46 | NULL,
|
---|
| 47 | &m_Tex);
|
---|
| 48 |
|
---|
| 49 | return true;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | bool CDXTexture::InitTex(LPDIRECT3DDEVICE9 dev, char* tex_name, int width, int height, D3DFORMAT format, bool mipmapped)
|
---|
| 53 | {
|
---|
| 54 | CopyToName(tex_name);
|
---|
| 55 |
|
---|
| 56 | m_Dev = dev;
|
---|
| 57 | m_Width = width;
|
---|
| 58 | m_Height = height;
|
---|
| 59 | // create new texture
|
---|
| 60 | HRESULT res = D3DXCreateTexture(m_Dev, width, height, mipmapped ? 0 : 1, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &m_Tex);
|
---|
| 61 | if (res != D3D_OK)
|
---|
| 62 | {
|
---|
| 63 | return false;
|
---|
| 64 | }
|
---|
| 65 | res = m_Dev->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE,0,true,&m_Stencil,NULL);
|
---|
| 66 | if (res != D3D_OK){
|
---|
| 67 | return false;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | return true;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | void CDXTexture::CopyToName(char* name)
|
---|
| 76 | {
|
---|
| 77 | if (strlen(name) > 512)
|
---|
| 78 | name[500] = '\0';
|
---|
| 79 |
|
---|
| 80 | strcpy(m_Name, name);
|
---|
| 81 | }
|
---|