#pragma once #include class CDXTexture { friend class CTextureManager; protected: LPDIRECT3DDEVICE9 m_Dev; LPDIRECT3DSURFACE9 m_pBackBuffer; IDirect3DSurface9* m_OrigDepthStencil; int m_RTindex; D3DVIEWPORT9 m_OldViewport; int m_Width, m_Height; int m_ColorStage; char m_Name[512]; public: IDirect3DTexture9* m_Tex; IDirect3DSurface9* m_Stencil; void SetStage(int color) { m_ColorStage = color; } static void SetLinearFilters(LPDIRECT3DDEVICE9 dev, DWORD stage) { dev->SetSamplerState(stage, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); dev->SetSamplerState(stage, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); dev->SetSamplerState(stage, D3DSAMP_MAXANISOTROPY, 2); dev->SetSamplerState(stage, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); } static void SetPointFilters(LPDIRECT3DDEVICE9 dev, DWORD stage) { dev->SetSamplerState(stage, D3DSAMP_MAGFILTER, D3DTEXF_NONE); dev->SetSamplerState(stage, D3DSAMP_MINFILTER, D3DTEXF_NONE); dev->SetSamplerState(stage, D3DSAMP_MIPFILTER, D3DTEXF_NONE); } inline void CopyFromBackBuffer() { LPDIRECT3DSURFACE9 backBuffer; m_Dev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer); m_Dev->StretchRect(backBuffer, NULL, this->GetSurface(0), NULL, D3DTEXF_POINT); SAFE_RELEASE(backBuffer); } inline void CopyToBackBuffer() { LPDIRECT3DSURFACE9 backBuffer; m_Dev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer); m_Dev->StretchRect(this->GetSurface(0), NULL, backBuffer, NULL, D3DTEXF_POINT); SAFE_RELEASE(backBuffer); } virtual bool InitTex(LPDIRECT3DDEVICE9 dev, char* name, char* tex_name, D3DFORMAT format = D3DFMT_UNKNOWN); virtual bool InitTex(LPDIRECT3DDEVICE9 dev, char* tex_name, int width, int height, D3DFORMAT format = D3DFMT_A8R8G8B8, bool mipmapped = false); CDXTexture(); ~CDXTexture(void); virtual inline void Bind() { m_Dev->SetTexture(m_ColorStage, m_Tex); } virtual inline void Bind(int stage) { m_Dev->SetTexture(stage, m_Tex); } virtual inline void BindVertexSampler(int stage) { m_Dev->SetTexture(D3DVERTEXTEXTURESAMPLER0 + stage, m_Tex); } inline void BindColor() { m_Dev->SetTexture(m_ColorStage, m_Tex); } inline virtual void BindOther() {} LPDIRECT3DSURFACE9 GetSurface(int level) { LPDIRECT3DSURFACE9 surface; m_Tex->GetSurfaceLevel(level, &surface); return surface; } inline void StartRender(bool depth = true, int RTindex = 0) { m_RTindex = RTindex; // set new, funky viewport D3DVIEWPORT9 newViewport; newViewport.X = 0; newViewport.Y = 0; newViewport.Width = m_Width; newViewport.Height = m_Height; newViewport.MinZ = 0.0f; newViewport.MaxZ = 1.0f; if (m_RTindex == 0) { m_Dev->GetViewport(&m_OldViewport); m_Dev->SetViewport(&newViewport); m_Dev->GetRenderTarget(0, &m_pBackBuffer); m_Dev->GetDepthStencilSurface(&m_OrigDepthStencil); if (depth) m_Dev->SetDepthStencilSurface(m_Stencil); } LPDIRECT3DSURFACE9 surface; m_Tex->GetSurfaceLevel(0, &surface); m_Dev->SetRenderTarget(m_RTindex, surface); SAFE_RELEASE(surface); } inline void EndRender() { if (m_RTindex == 0){ m_Dev->SetRenderTarget(0, m_pBackBuffer); m_Dev->SetDepthStencilSurface(m_OrigDepthStencil); m_Dev->SetViewport(&m_OldViewport); SAFE_RELEASE(m_pBackBuffer); SAFE_RELEASE(m_OrigDepthStencil); } else m_Dev->SetRenderTarget(m_RTindex, NULL); } void CopyToName(char* name); };