/** * @brief Remove and delete all surfaces */ void GraphicsManager::ClearSurfaces() { for(SurfaceIT it = mSurfaces.begin(); it != mSurfaces.end(); ++it) { DeleteSurface(*it); } for(SurfaceIT it = mUIElements.begin(); it != mUIElements.end(); ++it) { DeleteSurface(*it); } }
void CGraphicsBuffer::SaveBMP(const std::string& aFilename,const CPalette* aPalette) const { ASSERT(aPalette); ASSERT(aFilename.length()>0); SDL_Surface* s; s=CopyToSurface(aPalette); if (s==NULL) error("CGraphicsBuffer::CopyToSurface failed. Saving to BMP possible."); SDL_SaveBMP(s,aFilename.c_str()); DeleteSurface(s); }
// ---------------- // DestroyRunObject // ---------------- // Destroys the run-time object // short WINAPI DLLExport DestroyRunObject(LPRDATA rdPtr, long fast) { /* When your object is destroyed (either with a Destroy action or at the end of the frame) this routine is called. You must free any resources you have allocated! */ // Free collision mask FreeColMask(rdPtr); // Delete picture surface if ( rdPtr->pSf != NULL ) { DeleteSurface(rdPtr->pSf); rdPtr->pSf = NULL; } // No errors return 0; }
template <class T> void CIsoSurface<T>::GenerateSurface(const T* ptScalarField, T tIsoLevel, unsigned int nCellsX, unsigned int nCellsY, unsigned int nCellsZ, float fCellLengthX, float fCellLengthY, float fCellLengthZ) { if (m_bValidSurface) DeleteSurface(); m_tIsoLevel = tIsoLevel; m_nCellsX = nCellsX; m_nCellsY = nCellsY; m_nCellsZ = nCellsZ; m_fCellLengthX = fCellLengthX; m_fCellLengthY = fCellLengthY; m_fCellLengthZ = fCellLengthZ; m_ptScalarField = ptScalarField; unsigned int nPointsInXDirection = (m_nCellsX + 1); unsigned int nPointsInSlice = nPointsInXDirection*(m_nCellsY + 1); // Generate isosurface. for (unsigned int z = 0; z < m_nCellsZ; z++) for (unsigned int y = 0; y < m_nCellsY; y++) for (unsigned int x = 0; x < m_nCellsX; x++) { // Calculate table lookup index from those // vertices which are below the isolevel.% unsigned int tableIndex = 0; if (m_ptScalarField[z*nPointsInSlice + y*nPointsInXDirection + x] < m_tIsoLevel) tableIndex |= 1; if (m_ptScalarField[z*nPointsInSlice + (y+1)*nPointsInXDirection + x] < m_tIsoLevel) tableIndex |= 2; if (m_ptScalarField[z*nPointsInSlice + (y+1)*nPointsInXDirection + (x+1)] < m_tIsoLevel) tableIndex |= 4; if (m_ptScalarField[z*nPointsInSlice + y*nPointsInXDirection + (x+1)] < m_tIsoLevel) tableIndex |= 8; if (m_ptScalarField[(z+1)*nPointsInSlice + y*nPointsInXDirection + x] < m_tIsoLevel) tableIndex |= 16; if (m_ptScalarField[(z+1)*nPointsInSlice + (y+1)*nPointsInXDirection + x] < m_tIsoLevel) tableIndex |= 32; if (m_ptScalarField[(z+1)*nPointsInSlice + (y+1)*nPointsInXDirection + (x+1)] < m_tIsoLevel) tableIndex |= 64; if (m_ptScalarField[(z+1)*nPointsInSlice + y*nPointsInXDirection + (x+1)] < m_tIsoLevel) tableIndex |= 128; // Now create a triangulation of the isosurface in this // cell. if (m_edgeTable[tableIndex] != 0) { if (m_edgeTable[tableIndex] & 8) { POINT3DID pt = CalculateIntersection(x, y, z, 3); unsigned int id = GetEdgeID(x, y, z, 3); m_i2pt3idVertices.insert(ID2POINT3DID::value_type(id, pt)); } if (m_edgeTable[tableIndex] & 1) { POINT3DID pt = CalculateIntersection(x, y, z, 0); unsigned int id = GetEdgeID(x, y, z, 0); m_i2pt3idVertices.insert(ID2POINT3DID::value_type(id, pt)); } if (m_edgeTable[tableIndex] & 256) { POINT3DID pt = CalculateIntersection(x, y, z, 8); unsigned int id = GetEdgeID(x, y, z, 8); m_i2pt3idVertices.insert(ID2POINT3DID::value_type(id, pt)); } if (x == m_nCellsX - 1) { if (m_edgeTable[tableIndex] & 4) { POINT3DID pt = CalculateIntersection(x, y, z, 2); unsigned int id = GetEdgeID(x, y, z, 2); m_i2pt3idVertices.insert(ID2POINT3DID::value_type(id, pt)); } if (m_edgeTable[tableIndex] & 2048) { POINT3DID pt = CalculateIntersection(x, y, z, 11); unsigned int id = GetEdgeID(x, y, z, 11); m_i2pt3idVertices.insert(ID2POINT3DID::value_type(id, pt)); } } if (y == m_nCellsY - 1) { if (m_edgeTable[tableIndex] & 2) { POINT3DID pt = CalculateIntersection(x, y, z, 1); unsigned int id = GetEdgeID(x, y, z, 1); m_i2pt3idVertices.insert(ID2POINT3DID::value_type(id, pt)); } if (m_edgeTable[tableIndex] & 512) { POINT3DID pt = CalculateIntersection(x, y, z, 9); unsigned int id = GetEdgeID(x, y, z, 9); m_i2pt3idVertices.insert(ID2POINT3DID::value_type(id, pt)); } } if (z == m_nCellsZ - 1) { if (m_edgeTable[tableIndex] & 16) { POINT3DID pt = CalculateIntersection(x, y, z, 4); unsigned int id = GetEdgeID(x, y, z, 4); m_i2pt3idVertices.insert(ID2POINT3DID::value_type(id, pt)); } if (m_edgeTable[tableIndex] & 128) { POINT3DID pt = CalculateIntersection(x, y, z, 7); unsigned int id = GetEdgeID(x, y, z, 7); m_i2pt3idVertices.insert(ID2POINT3DID::value_type(id, pt)); } } if ((x==m_nCellsX - 1) && (y==m_nCellsY - 1)) if (m_edgeTable[tableIndex] & 1024) { POINT3DID pt = CalculateIntersection(x, y, z, 10); unsigned int id = GetEdgeID(x, y, z, 10); m_i2pt3idVertices.insert(ID2POINT3DID::value_type(id, pt)); } if ((x==m_nCellsX - 1) && (z==m_nCellsZ - 1)) if (m_edgeTable[tableIndex] & 64) { POINT3DID pt = CalculateIntersection(x, y, z, 6); unsigned int id = GetEdgeID(x, y, z, 6); m_i2pt3idVertices.insert(ID2POINT3DID::value_type(id, pt)); } if ((y==m_nCellsY - 1) && (z==m_nCellsZ - 1)) if (m_edgeTable[tableIndex] & 32) { POINT3DID pt = CalculateIntersection(x, y, z, 5); unsigned int id = GetEdgeID(x, y, z, 5); m_i2pt3idVertices.insert(ID2POINT3DID::value_type(id, pt)); } for (unsigned int i = 0; m_triTable[tableIndex][i] != -1; i += 3) { TRIANGLE triangle; unsigned int pointID0, pointID1, pointID2; pointID0 = GetEdgeID(x, y, z, m_triTable[tableIndex][i]); pointID1 = GetEdgeID(x, y, z, m_triTable[tableIndex][i+1]); pointID2 = GetEdgeID(x, y, z, m_triTable[tableIndex][i+2]); triangle.pointID[0] = pointID0; triangle.pointID[1] = pointID1; triangle.pointID[2] = pointID2; m_trivecTriangles.push_back(triangle); } } } RenameVerticesAndTriangles(); CalculateNormals(); m_bValidSurface = true; }
template <class T> CIsoSurface<T>::~CIsoSurface() { DeleteSurface(); }
void LoadImageFile(LPRDATA rdPtr, LPSTR pFileName) { LPRH rhPtr = rdPtr->rHo.hoAdRunHeader; HANDLE hf = INVALID_HANDLE_VALUE; do { if ( pFileName == NULL || *pFileName == 0 ) break; // Copy filename to temp buffer char fname[MAX_PATH]; strcpy(fname, pFileName); // Get surface prototype LPSURFACE wSurf = WinGetSurface((int)rhPtr->rhIdEditWin); LPSURFACE proto; GetSurfacePrototype(&proto, (wSurf != NULL) ? wSurf->GetDepth() : 24, ST_MEMORYWITHDC, SD_DIB); if ( proto == NULL ) break; // Ask MMF2 to open the file (opens external file and embedded files, and downloads files in Vitalize mode) DWORD dwSize; hf = rhPtr->rh4.rh4Mv->mvOpenHFile(fname, &dwSize, 0); if ( hf == INVALID_HANDLE_VALUE ) break; // Create CInpuBufFile object associated with the file handle DWORD dwOff = File_GetPosition((HFILE)hf); CInputBufFile bf; if ( bf.Create((HFILE)hf, dwOff, dwSize) != 0 ) break; // Create surface cSurface* psf = NewSurface(); if ( psf == NULL ) break; psf->Create(4, 4, proto); psf->Fill(RGB(0,0,0)); if ( psf->GetDepth() == 8 ) psf->SetPalette (*wSurf); // Load picture CImageFilterMgr* pImgMgr = rhPtr->rh4.rh4Mv->mvImgFilterMgr; if ( ImportImageFromInputFile(pImgMgr, &bf, psf, NULL, IMPORT_IMAGE_USESURFACEDEPTH | IMPORT_IMAGE_USESURFACEPALETTE) ) { // Copy filename if file successfully loaded strcpy(rdPtr->sFilename, fname); rdPtr->nWidth = rdPtr->rHo.hoImgWidth = psf->GetWidth(); rdPtr->nHeight = rdPtr->rHo.hoImgHeight = psf->GetHeight(); // Replace picture surface if ( rdPtr->pSf != NULL ) DeleteSurface(rdPtr->pSf); rdPtr->pSf = psf; // Free collision mask FreeColMask(rdPtr); // Set transparent color if ( psf->GetTransparentColor() == RGB(0,0,0) ) { COLORREF trspColor = rdPtr->dwTranspColor; if ( (rdPtr->dwOptions & SPICTFLAGS_TRANSP_FIRSTPIXEL) != 0 ) psf->GetPixel(0,0,trspColor); psf->SetTransparentColor(trspColor); } } else DeleteSurface(psf); } while(FALSE); // Close picture file (opened with mvOpenHFile) if ( hf != INVALID_HANDLE_VALUE ) rhPtr->rh4.rh4Mv->mvCloseHFile(hf); }
CIsoSurfaceBase::~CIsoSurfaceBase() { DeleteSurface(); // TODO selection iso check this delete m_tMesh; }
STDMETHODIMP VMRSurfaceAllocator::TerminateDevice( DWORD_PTR dwUserID ) { DeleteSurface(); return S_OK; }
STDMETHODIMP VMRSurfaceAllocator::InitializeDevice( DWORD_PTR dwUserID, VMR9AllocationInfo *lpAllocInfo, DWORD *lpNumBuffers ) { IDirect3DTexture9 *lpTexture; D3DCAPS9 d3dcaps; D3DDISPLAYMODE d3ddm; HRESULT hr; unsigned long ulWidth, ulHeight;//, ul; unsigned int i; CheckPointer( lpAllocInfo, E_POINTER ); CheckPointer( lpNumBuffers, E_POINTER ); CheckPointer( SurfaceAllocNotify, E_FAIL ); mwidth = ulWidth = lpAllocInfo->dwWidth; mheight = ulHeight = lpAllocInfo->dwHeight; m_fmtTexture = lpAllocInfo->Format; if ( m_fmtTexture == D3DFMT_UNKNOWN ) { hr = D3DDev->GetDisplayMode( NULL, &d3ddm ); if ( hr != S_OK ) { return hr; } lpAllocInfo->Format = m_fmtTexture = d3ddm.Format; } hr = D3DDev->GetDeviceCaps( &d3dcaps ); if ( d3dcaps.TextureCaps & D3DPTEXTURECAPS_POW2 ) { for ( ulWidth = 1 ; ulWidth < lpAllocInfo->dwWidth ; ulWidth <<= 1 ); for ( ulHeight = 1 ; ulHeight < lpAllocInfo->dwHeight ; ulHeight <<= 1 ); lpAllocInfo->dwWidth = ulWidth; lpAllocInfo->dwHeight = ulHeight; } lpAllocInfo->dwFlags |= VMR9AllocFlag_TextureSurface; DeleteSurface(); Surfaces.Resize( *lpNumBuffers ); hr = SurfaceAllocNotify->AllocateSurfaceHelper( lpAllocInfo, lpNumBuffers, Surfaces.GetPointer( 0 ) ); if ( hr != S_OK && !( lpAllocInfo->dwFlags & VMR9AllocFlag_3DRenderTarget ) ) { DeleteSurface(); if ( lpAllocInfo->Format > '0000' ) { hr = D3DDev->GetDisplayMode( NULL, &d3ddm ); if ( hr != S_OK ) { return hr; } for ( i = 0 ; i < VMRSALLOC_USE_TEXTURE_MAX ; ++i ) { hr = D3DDev->CreateTexture( lpAllocInfo->dwWidth, lpAllocInfo->dwHeight, 1, D3DUSAGE_RENDERTARGET, d3ddm.Format, D3DPOOL_DEFAULT, &lpTexture, NULL ); if ( hr != S_OK ) { return hr; } m_alpDirect3DTexture[ i ] = lpTexture; } m_fmtTexture = d3ddm.Format; } lpAllocInfo->dwFlags &= ~VMR9AllocFlag_TextureSurface; lpAllocInfo->dwFlags |= VMR9AllocFlag_OffscreenSurface; hr = SurfaceAllocNotify->AllocateSurfaceHelper( lpAllocInfo, lpNumBuffers, Surfaces.GetPointer( 0 ) ); } else { for ( i = 0 ; i < VMRSALLOC_USE_TEXTURE_MAX ; ++i ) { hr = D3DDev->CreateTexture( lpAllocInfo->dwWidth, lpAllocInfo->dwHeight, 1, D3DUSAGE_RENDERTARGET, d3ddm.Format, D3DPOOL_DEFAULT, &lpTexture, NULL ); if ( hr != S_OK ) { return hr; } m_alpDirect3DTexture[ i ] = lpTexture; } } m_nFilpTexNum = texnum = -1; if ( m_alpDirect3DTexture[ 0 ] ) { m_nFilpTexNum = 0; texnum = 1; } twidth = lpAllocInfo->dwWidth; theight = lpAllocInfo->dwHeight; return hr; }