void MFFileSystem_UnregisterFileSystem(MFFileSystemHandle filesystemHandle) { MFDebug_Assert((uint32)filesystemHandle < gDefaults.filesys.maxFileSystems, "Invalid filesystem"); GET_MODULE_DATA(MFFileSystemState); MFFileSystem *pFS = pModuleData->ppFileSystemList[filesystemHandle]; MFDebug_Assert(pFS, "Filesystem not mounted"); if(pFS->callbacks.UnregisterFS) pFS->callbacks.UnregisterFS(); if(pFS->thread) { // terminate job thread MFJob *pJob = NewJob(pFS); PostJob(pFS, pJob); while(pJob->status != MFJS_Finished) { // yield } MFThread_DestroySemaphore(pFS->semaphore); pFS->jobs.Deinit(); MFHeap_Free(pFS->ppJobQueue); } pModuleData->gFileSystems.Destroy(pFS); pModuleData->ppFileSystemList[filesystemHandle] = NULL; }
MF_API void MFVertex_UnlockIndexBuffer(MFIndexBuffer *pIndexBuffer) { MFDebug_Assert(pIndexBuffer, "NULL index buffer"); MFDebug_Assert(pIndexBuffer->bLocked, "Index buffer not locked!"); ID3D11Buffer *pIB = (ID3D11Buffer*)pIndexBuffer->pPlatformData; if(pIB) pIB->Release(); D3D11_BUFFER_DESC bd; MFZeroMemory(&bd, sizeof(bd)); bd.Usage = D3D11_USAGE_IMMUTABLE; bd.ByteWidth = sizeof(WORD) * pIndexBuffer->numIndices; bd.BindFlags = D3D11_BIND_INDEX_BUFFER; D3D11_SUBRESOURCE_DATA initData; MFZeroMemory(&initData, sizeof(initData)); initData.pSysMem = pIndexBuffer->pLocked; HRESULT hr = g_pd3dDevice->CreateBuffer(&bd, &initData, &pIB); MFDebug_Assert(SUCCEEDED(hr), "Couldn't create index buffer!"); if (FAILED(hr)) return; pIndexBuffer->pPlatformData = pIB; MFHeap_Free(pIndexBuffer->pLocked); pIndexBuffer->pLocked = NULL; pIndexBuffer->bLocked = false; }
MF_API void DebugMenu_AddMenuTo(const char *name, Menu *pParent, DebugCallback callback, void *userData) { MFDebug_Assert(pParent, "Invalid parent menu."); MFDebug_Assert(pParent->type == MenuType_Menu, MFStr("Cant add menu '%s', Parent is not of Menu type.", name)); MFDebug_Assert(MFString_Length(name) < 64, "Max of 64 characters in Menu Name."); MFDebug_Assert(pParent->numChildren < MENU_MAX_CHILDREN, MFStr("Maximum number of items in menu: '%s'", pParent->name)); // Menu *pMenu = Heap_New(Menu); Menu *pMenu = new Menu; MFString_Copy(pMenu->name, name); pMenu->type = MenuType_Menu; pMenu->pParent = pParent; pMenu->menuDepth = pParent->menuDepth+1; pMenu->numChildren = 0; pMenu->selection = 0; pMenu->pCallback = callback; pMenu->pUserData = userData; pParent->pChildren[pParent->numChildren] = pMenu; ++pParent->numChildren; }
// interface functions void MFTexture_CreatePlatformSpecific(MFTexture *pTexture, bool generateMipChain) { MFCALLSTACK; HRESULT hr; MFTextureTemplateData *pTemplate = pTexture->pTemplateData; // create texture D3DFORMAT platformFormat = (D3DFORMAT)MFTexture_GetPlatformFormatID(pTemplate->imageFormat, MFDD_D3D9); hr = D3DXCreateTexture(pd3dDevice, pTemplate->pSurfaces[0].width, pTemplate->pSurfaces[0].height, generateMipChain ? 0 : 1, 0, platformFormat, D3DPOOL_MANAGED, (IDirect3DTexture9**)&pTexture->pInternalData); MFDebug_Assert(hr != D3DERR_NOTAVAILABLE, MFStr("LoadTexture failed: D3DERR_NOTAVAILABLE, 0x%08X", hr)); MFDebug_Assert(hr != D3DERR_OUTOFVIDEOMEMORY, MFStr("LoadTexture failed: D3DERR_OUTOFVIDEOMEMORY, 0x%08X", hr)); MFDebug_Assert(hr != D3DERR_INVALIDCALL, MFStr("LoadTexture failed: D3DERR_INVALIDCALL, 0x%08X", hr)); MFDebug_Assert(hr != D3DXERR_INVALIDDATA, MFStr("LoadTexture failed: D3DXERR_INVALIDDATA, 0x%08X", hr)); MFDebug_Assert(hr == D3D_OK, MFStr("Failed to create texture '%s'.", pTexture->name)); IDirect3DTexture9 *pTex = (IDirect3DTexture9*)pTexture->pInternalData; // copy image data D3DLOCKED_RECT rect; pTex->LockRect(0, &rect, NULL, 0); MFCopyMemory(rect.pBits, pTemplate->pSurfaces[0].pImageData, pTemplate->pSurfaces[0].bufferLength); pTex->UnlockRect(0); // filter mip levels if(generateMipChain) D3DXFilterTexture(pTex, NULL, 0, D3DX_DEFAULT); }
bool MFCheckForOpenGLError(bool bBreakOnError) { GLenum err = glGetError(); if(err != GL_NO_ERROR) { #if !defined(MF_OPENGL_ES) const GLubyte *errorString = gluErrorString(err); if(bBreakOnError) { MFDebug_Assert(err == GL_NO_ERROR, MFStr("OpenGL Error %04X: %s", err, errorString)); } else { MFDebug_Warn(1, MFStr("OpenGL Error %04X: %s", err, errorString)); } #else if(bBreakOnError) { MFDebug_Assert(err == GL_NO_ERROR, MFStr("OpenGL Error: %04X", err)); } else { MFDebug_Warn(1, MFStr("OpenGL Error: %04X", err)); } #endif return true; } return false; }
//--------------------------------------------------------------------------------------------------------------------- MF_API void MFBegin(uint32 vertexCount) { MFDebug_Assert(phase == 1, "not in order 1"); MFDebug_Assert(vertexCount > 0, "Invalid primitive count."); currentPrim.numVertices = vertexCount; if(gImmitateQuads) currentPrim.numVertices *= 3; // create an appropriate vertex buffer pVB = MFVertex_CreateVertexBuffer(pDecl, currentPrim.numVertices, MFVBType_Scratch); currentPrim.pMeshState = MFStateBlock_CreateTemporary(gLargeStateblock ? 256 : 64); MFStateBlock_SetRenderState(currentPrim.pMeshState, MFSCRS_VertexDeclaration, pDecl); MFStateBlock_SetRenderState(currentPrim.pMeshState, MFSCRS_VertexBuffer0, pVB); MFVertex_LockVertexBuffer(pVB, (void**)&pLocked); currentVert = 0; current.u = current.v = 0.0f; current.colour = 0xFFFFFFFF; current.normal.x = current.normal.z = 0.0f; current.normal.y = 1.0f; phase = 2; }
MF_API void MFVertex_LockVertexBuffer(MFVertexBuffer *pVertexBuffer, void **ppVertices) { MFDebug_Assert(pVertexBuffer, "Null vertex buffer"); MFDebug_Assert(!pVertexBuffer->bLocked, "Vertex buffer already locked!"); if(pVertexBuffer->bufferType == MFVBType_Dynamic) { ID3D11Buffer *pVB = (ID3D11Buffer*)pVertexBuffer->pPlatformData; D3D11_MAPPED_SUBRESOURCE subresource; D3D11_MAP map = (pVertexBuffer->bufferType == MFVBType_Dynamic) ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE; HRESULT hr = g_pImmediateContext->Map(pVB, 0, map, D3D11_MAP_FLAG_DO_NOT_WAIT, &subresource); if(hr == DXGI_ERROR_WAS_STILL_DRAWING) { MFDebug_Message("waiting on vertex buffer lock"); hr = g_pImmediateContext->Map(pVB, 0, map, 0, &subresource); } MFDebug_Assert(SUCCEEDED(hr), "Failed to map vertex buffer"); pVertexBuffer->pLocked = subresource.pData; } else { pVertexBuffer->pLocked = MFHeap_Alloc(pVertexBuffer->numVerts*pVertexBuffer->pVertexDeclatation->pElementData[0].stride, MFHeap_GetHeap(MFHT_ActiveTemporary)); } if(ppVertices) *ppVertices = pVertexBuffer->pLocked; pVertexBuffer->bLocked = true; }
void MFPoolHeap::Init(int num, size_t size, void *pMem, size_t memsize) { MFDebug_Assert(num > 0 && size >= 4 && (size & 3) == 0, "Bad args"); itemSize = size; numItems = num; pNext = NULL; #if !defined(MF_RETAIL) peakNumUsed = 0; #endif // Get the memory for the heap if(pMem) { MFDebug_Assert(memsize > num*size, "Not enought memory"); pStorage = pMem; bOwnStorage = false; } else { pStorage = MFHeap_Alloc(num*size); bOwnStorage = true; } DeleteAll(); }
bool MFCollision_RayMeshTest(const MFVector& rayPos, const MFVector& rayDir, MFCollisionItem *pMesh, MFRayIntersectionResult *pResult) { MFDebug_Assert(pMesh->pTemplate->type == MFCT_Mesh, "Item is not a collision mesh"); MFDebug_Assert(false, "No dice.."); return false; }
bool MFCollision_SphereMeshTest(const MFVector &spherePos, float radius, MFCollisionItem *pMesh, MFCollisionResult *pResult) { MFDebug_Assert(pMesh->pTemplate->type == MFCT_Mesh, "Item is not a collision mesh"); MFDebug_Assert(false, "No dice.."); return false; }
int MFFileNative_Open(MFFile *pFile, MFOpenData *pOpenData) { MFCALLSTACK; MFDebug_Assert(pOpenData->cbSize == sizeof(MFOpenDataNative), "Incorrect size for MFOpenDataNative structure. Invalid pOpenData."); MFOpenDataNative *pNative = (MFOpenDataNative*)pOpenData; int flags = 0; if(pOpenData->openFlags & MFOF_Read) { if(pNative->openFlags & MFOF_Write) { flags = O_RDWR | O_CREAT; } else { flags = O_RDONLY; } } else if(pOpenData->openFlags & MFOF_Write) { flags = O_WRONLY | O_CREAT; } else { MFDebug_Assert(0, "Neither MFOF_Read nor MFOF_Write specified."); } int file = open(pNative->pFilename, flags); if(file == -1) { // MFDebug_Warn(3, MFStr("Failed to open file '%s'.", pNative->pFilename)); pFile->pFilesysData = 0; return -1; } pFile->pFilesysData = (void*)(size_t)file; pFile->createFlags = pOpenData->openFlags; pFile->offset = 0; struct stat fileStats; if(fstat(file, &fileStats) == -1) { close(file); pFile->pFilesysData = 0; return -1; } pFile->length = fileStats.st_size; #if defined(_DEBUG) MFString_Copy(pFile->fileIdentifier, pNative->pFilename); #endif return 0; }
int MFFileNative_Open(MFFile *pFile, MFOpenData *pOpenData) { MFCALLSTACK; #if defined(_USE_CRT_FOR_NULL_DRIVERS) MFDebug_Assert(pOpenData->cbSize == sizeof(MFOpenDataNative), "Incorrect size for MFOpenDataNative structure. Invalid pOpenData."); MFOpenDataNative *pNative = (MFOpenDataNative*)pOpenData; int flags = 0; const char *pAccess = ""; if(pOpenData->openFlags & MFOF_Read) { if(pNative->openFlags & MFOF_Write) { pAccess = "w+b"; } else { pAccess = "rb"; } } else if(pOpenData->openFlags & MFOF_Write) { pAccess = "wb"; } else { MFDebug_Assert(0, "Neither MFOF_Read nor MFOF_Write specified."); } FILE *pF = fopen(pNative->pFilename, pAccess); if(pF == NULL) { // MFDebug_Warn(3, MFStr("Failed to open file '%s'.", pNative->pFilename)); pFile->pFilesysData = 0; return -1; } pFile->pFilesysData = (void*)pF; pFile->createFlags = pOpenData->openFlags; pFile->offset = 0; fseek(pF, 0, SEEK_END); pFile->length = ftell(pF); fseek(pF, 0, SEEK_SET); #if defined(_DEBUG) MFString_Copy(pFile->fileIdentifier, pNative->pFilename); #endif return 0; #else return -1; #endif }
//--------------------------------------------------------------------------------------------------------------------- MF_API void MFEnd() { MFDebug_Assert(phase == 2, "not in order 2"); MFVertex_UnlockVertexBuffer(pVB); MFDebug_Assert(currentVert == currentPrim.numVertices, "Incorrect number of vertices."); MFRenderer_AddMesh(¤tPrim, pMaterial, pEntity, NULL, MFView_GetViewState()); phase = 0; }
MF_API void MFVertex_LockIndexBuffer(MFIndexBuffer *pIndexBuffer, uint16 **ppIndices) { MFDebug_Assert(pIndexBuffer, "NULL index buffer"); MFDebug_Assert(!pIndexBuffer->bLocked, "Index buffer already locked!"); pIndexBuffer->pLocked = MFHeap_Alloc(sizeof(uint16)*pIndexBuffer->numIndices, MFHeap_GetHeap(MFHT_ActiveTemporary)); if(ppIndices) *ppIndices = (uint16*)pIndexBuffer->pLocked; pIndexBuffer->bLocked = true; }
MF_API void MFVertex_LockIndexBuffer(MFIndexBuffer *pIndexBuffer, uint16 **ppIndices) { MFDebug_Assert(!pIndexBuffer->bLocked, "Index buffer already locked!"); IDirect3DIndexBuffer9 *pIB = (IDirect3DIndexBuffer9*)pIndexBuffer->pPlatformData; HRESULT hr = pIB->Lock(0, sizeof(uint16)*pIndexBuffer->numIndices, &pIndexBuffer->pLocked, 0); MFDebug_Assert(SUCCEEDED(hr), "Failed to lock index buffer"); if(ppIndices) *ppIndices = (uint16*)pIndexBuffer->pLocked; pIndexBuffer->bLocked = true; }
MF_API void MFVertex_LockVertexBuffer(MFVertexBuffer *pVertexBuffer, void **ppVertices) { MFDebug_Assert(!pVertexBuffer->bLocked, "Vertex buffer already locked!"); IDirect3DVertexBuffer9 *pVB = (IDirect3DVertexBuffer9*)pVertexBuffer->pPlatformData; HRESULT hr = pVB->Lock(0, 0, &pVertexBuffer->pLocked, pVertexBuffer->bufferType == MFVBType_Dynamic ? D3DLOCK_DISCARD | D3DLOCK_NOOVERWRITE : 0); MFDebug_Assert(SUCCEEDED(hr), "Failed to lock vertex buffer"); if(ppVertices) *ppVertices = pVertexBuffer->pLocked; pVertexBuffer->bLocked = true; }
bool MFVertex_CreateVertexBufferPlatformSpecific(MFVertexBuffer *pVertexBuffer, void *pVertexBufferMemory) { DWORD usage; D3DPOOL pool; DWORD lockFlags = 0; switch(pVertexBuffer->bufferType) { case MFVBType_Static: pool = D3DPOOL_MANAGED; usage = 0; break; case MFVBType_Dynamic: pool = D3DPOOL_DEFAULT; usage = D3DUSAGE_WRITEONLY; usage = D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY; lockFlags = D3DLOCK_DISCARD; break; case MFVBType_Scratch: // Maybe it's better to use UP draw calls for scratch buffers? pool = D3DPOOL_DEFAULT; usage = D3DUSAGE_WRITEONLY; // usage = D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY; // DYNAMIC is supposedly only for frequent locking... we don't intend to lock more than once break; default: MFDebug_Assert(false, "Invalid vertex buffer type!"); return false; } int stride = pVertexBuffer->pVertexDeclatation->pElementData[0].stride; IDirect3DVertexBuffer9 *pVertBuffer; HRESULT hr = pd3dDevice->CreateVertexBuffer(stride*pVertexBuffer->numVerts, usage, 0, pool, &pVertBuffer, NULL); MFDebug_Assert(SUCCEEDED(hr), "Failed to create vertex buffer"); if(FAILED(hr)) return false; if(pVertexBuffer->pName) MFRenderer_D3D9_SetDebugName(pVertBuffer, pVertexBuffer->pName); pVertexBuffer->pPlatformData = pVertBuffer; if(pVertexBufferMemory) { void *pData; pVertBuffer->Lock(0, 0, &pData, lockFlags); MFCopyMemory(pData, pVertexBufferMemory, stride*pVertexBuffer->numVerts); pVertBuffer->Unlock(); } return true; }
void MFPoolHeapCollection::Init(int _numHeaps, const int *pNum, const size_t *pSizes, void *pMem, size_t memsize) { MFDebug_Assert(_numHeaps > 0 && pNum && pSizes, "Bad parameters"); numHeaps = _numHeaps; #if !defined(MF_RETAIL) overflows = 0; #endif if(pMem) { size_t size = (sizeof(MFPoolHeap*)+sizeof(MFPoolHeap))*numHeaps; for(int i=0; i<numHeaps; ++i) size += pNum[i]*pSizes[i]; MFDebug_Assert(memsize >= size, "Not enough memory"); pHeaps = (MFPoolHeap**)pMem; pMem = ((MFPoolHeap**)pMem) + numHeaps; } else { pHeaps = (MFPoolHeap**)MFHeap_Alloc(sizeof(MFPoolHeap*)*numHeaps); } size_t lastSize = 0; for(int i = 0; i < numHeaps; ++i) { const size_t size = pSizes[i]; const int num = pNum[i]; MFDebug_Assert(size > lastSize && num > 0, "Bad heap params"); lastSize = size; if(pMem) { pHeaps[i] = (MFPoolHeap*)pMem; pMem = ((MFPoolHeap*)pMem) + 1; const size_t memorySize = size*num; pHeaps[i]->Init(num, size, pMem, memorySize); pMem = ((char *)pMem) + memorySize; } else { pHeaps[i] = (MFPoolHeap*)MFHeap_Alloc(sizeof(MFPoolHeap)); pHeaps[i]->Init(num, size); } } }
MF_API bool MFInput_IsAvailable(int device, int deviceID) { MFDebug_Assert(device >= 0 && device < IDD_Max, "Invalid Input Device"); MFDebug_Assert(deviceID >= 0 && deviceID < MFInput_MaxInputID, "Invalid DeviceID"); bool available = gDeviceStatus[device][deviceID] != IDS_Unavailable; #if !defined(_RETAIL) // this allow's a device with a keyboard and no gamepad's to emulate a gamepad with the keyboard if(!available && device == IDD_Gamepad && deviceID == 0 && gNumKeyboards) available = true; #endif return available; }
// interface functions void MFTexture_CreatePlatformSpecific(MFTexture *pTexture, bool generateMipChain) { MFTextureTemplateData *pTemplate = pTexture->pTemplateData; // create texture D3DFORMAT platformFormat = (D3DFORMAT)MFTexture_GetPlatformFormatID(pTemplate->imageFormat, MFDD_XBOX); #if defined(XB_XGTEXTURES) pTexture->pTexture = &pTexture->texture; XGSetTextureHeader(pTemplate->pSurfaces[0].width, pTemplate->pSurfaces[0].height, 1, 0, platformFormat, 0, pTexture->pTexture, 0, 0); pTexture->pTexture->Register(pTemplate->pSurfaces[0].pImageData); if(pTemplate->imageFormat >= TexFmt_XB_A8R8G8B8s && pTemplate->imageFormat <= TexFmt_XB_R4G4B4A4s) { XGSwizzleRect(pTemplate->pSurfaces[0].pImageData, 0, NULL, pTemplate->pSurfaces[0].pImageData, pTemplate->pSurfaces[0].width, pTemplate->pSurfaces[0].height, NULL, pTemplate->pSurfaces[0].bitsPerPixel/8); } #else HRESULT hr; hr = D3DXCreateTexture(pd3dDevice, pTemplate->pSurfaces[0].width, pTemplate->pSurfaces[0].height, generateMipChain ? 0 : 1, 0, platformFormat, 0, &pTexture->pTexture); MFDebug_Assert(hr != D3DERR_NOTAVAILABLE, MFStr("LoadTexture failed: D3DERR_NOTAVAILABLE, 0x%08X", hr)); MFDebug_Assert(hr != D3DERR_OUTOFVIDEOMEMORY, MFStr("LoadTexture failed: D3DERR_OUTOFVIDEOMEMORY, 0x%08X", hr)); MFDebug_Assert(hr != D3DERR_INVALIDCALL, MFStr("LoadTexture failed: D3DERR_INVALIDCALL, 0x%08X", hr)); MFDebug_Assert(hr != D3DXERR_INVALIDDATA, MFStr("LoadTexture failed: D3DXERR_INVALIDDATA, 0x%08X", hr)); MFDebug_Assert(hr == D3D_OK, MFStr("Failed to create texture '%s'.", pTexture->name)); // copy image data D3DLOCKED_RECT rect; pTexture->pTexture->LockRect(0, &rect, NULL, 0); if(pTemplate->imageFormat >= TexFmt_XB_A8R8G8B8s && pTemplate->imageFormat <= TexFmt_XB_R4G4B4A4s) { XGSwizzleRect(pTemplate->pSurfaces[0].pImageData, 0, NULL, rect.pBits, pTemplate->pSurfaces[0].width, pTemplate->pSurfaces[0].height, NULL, pTemplate->pSurfaces[0].bitsPerPixel/8); } else { MFCopyMemory(rect.pBits, pTemplate->pSurfaces[0].pImageData, pTemplate->pSurfaces[0].bufferLength); } pTexture->pTexture->UnlockRect(0); // filter mip levels if(generateMipChain) D3DXFilterTexture(pTexture->pTexture, NULL, 0, D3DX_DEFAULT); #endif }
void MFSound_CreateInternal(MFSound *pSound) { MFSoundTemplate *pTemplate = pSound->pTemplate; MFSoundDataInternal *pInternal = pSound->pInternal; alGenBuffers(1, &pInternal->buffer); // if dynamic, allocate buffer if(pTemplate->flags & MFSF_Dynamic) { long bufferSize = ((pTemplate->numChannels * pTemplate->bitsPerSample) >> 3) * pTemplate->numSamples; if(gpCurrentContext->ext.static_buffer) { pTemplate->ppStreams = (char**)MFHeap_Alloc(sizeof(char*) + bufferSize); pTemplate->ppStreams[0] = (char*)&pTemplate->ppStreams[1]; alBufferDataStatic(pInternal->buffer, pInternal->format, pTemplate->ppStreams[0], bufferSize, pTemplate->sampleRate); } else if(gpCurrentContext->ext.buffer_sub_data) { switch((pTemplate->numChannels << 16) | pTemplate->bitsPerSample) { case 0x10000 | 8: pInternal->format = AL_FORMAT_MONO8; break; case 0x20000 | 8: pInternal->format = AL_FORMAT_STEREO8; break; case 0x10000 | 16: pInternal->format = AL_FORMAT_MONO16; break; case 0x20000 | 16: pInternal->format = AL_FORMAT_STEREO16; break; case 0x10000 | 32: if(gpCurrentContext->ext.float32) pInternal->format = AL_FORMAT_MONO_FLOAT32; else MFDebug_Assert(false, "Unsupported sample format!"); break; case 0x20000 | 32: if(gpCurrentContext->ext.float32) pInternal->format = AL_FORMAT_STEREO_FLOAT32; else MFDebug_Assert(false, "Unsupported sample format!"); break; default: MFDebug_Assert(false, "Unsupported sample format!"); break; } // set buffer data with null allocates a buffer filled with undefined junk alBufferData(pInternal->buffer, pInternal->format, NULL, bufferSize, pTemplate->sampleRate); } }
void MFSound_UpdateInternal() { const int NumSamples = 4096; float buffer[NumSamples]; size_t numCaptureDevices = MFDevice_GetNumDevices(MFDT_AudioCapture); for(size_t i=0; i<numCaptureDevices; ++i) { MFDevice *pDevice = MFDevice_GetDeviceByIndex(MFDT_AudioCapture, i); AudioDevice &device = *(AudioDevice*)pDevice->pInternal; if(device.pDevice && device.bActive) { // get samples, and feed to callback ALint numSamples; alcGetIntegerv(device.pDevice, ALC_CAPTURE_SAMPLES, (ALCsizei)sizeof(ALint), &numSamples); MFDebug_Assert(false, "TODO: check if numSamples is in samples or bytes..."); while(numSamples > 0) { ALint samples = MFMin(1024, numSamples); alcCaptureSamples(device.pDevice, (ALCvoid *)buffer, samples); numSamples -= samples; // feed samples to the callback device.pSampleCallback((float*)buffer, samples, 1, device.pUserData); } } } }
bool MFRasteriserState_CreatePlatformSpecific(MFRasteriserState *pRS) { D3D11_RASTERIZER_DESC rasterizerDesc; switch(pRS->stateDesc.fillMode) { case MFCullMode_None: rasterizerDesc.CullMode = D3D11_CULL_NONE; rasterizerDesc.FrontCounterClockwise = false; break; case MFCullMode_CCW: rasterizerDesc.CullMode = D3D11_CULL_BACK; rasterizerDesc.FrontCounterClockwise = false; break; case MFCullMode_CW: rasterizerDesc.CullMode = D3D11_CULL_BACK; rasterizerDesc.FrontCounterClockwise = true; break; default: MFDebug_Assert(false, "Invalid cull mode!"); } rasterizerDesc.FillMode = sFillMode[pRS->stateDesc.fillMode]; rasterizerDesc.DepthBias = pRS->stateDesc.depthBias; rasterizerDesc.DepthBiasClamp = pRS->stateDesc.depthBiasClamp; rasterizerDesc.SlopeScaledDepthBias = pRS->stateDesc.slopeScaledDepthBias; rasterizerDesc.DepthClipEnable = pRS->stateDesc.bDepthClipEnable; rasterizerDesc.ScissorEnable = pRS->stateDesc.bScissorEnable; rasterizerDesc.MultisampleEnable = pRS->stateDesc.bMultisampleEnable; rasterizerDesc.AntialiasedLineEnable = pRS->stateDesc.bAntialiasedLineEnable; ID3D11RasterizerState *pD3D11RS; HRESULT hr = g_pd3dDevice->CreateRasterizerState(&rasterizerDesc, &pD3D11RS); pRS->pPlatformData = pD3D11RS; return SUCCEEDED(hr); }
bool MFFileNative_FindNext(MFFind *pFind, MFFindData *pFindData) { #if defined(_USE_CRT_FOR_NULL_DRIVERS) && defined(CRT_SUPPORTS_FIND) _finddata_t fd; int more = _findnext((intptr_t)pFind->pFilesystemData, &fd); if(more == -1) return false; MFDebug_Assert(more == 0, "Something's not quite right here.. You have a bad CRT."); pFindData->attributes = ((fd.attrib & _A_SUBDIR) ? MFFA_Directory : 0) | ((fd.attrib & _A_HIDDEN) ? MFFA_Hidden : 0) | ((fd.attrib & _A_RDONLY) ? MFFA_ReadOnly : 0); pFindData->fileSize = fd.size; pFindData->createTime = (uint64)fd.time_write; pFindData->writeTime = (uint64)fd.time_write; pFindData->accessTime = (uint64)fd.time_access; MFString_Copy((char*)pFindData->pFilename, fd.name); return true; #else return false; #endif }
void MFMesh_FixUpMeshChunkGeneric(MFMeshChunk *pMeshChunk, void *pBase, bool load) { MFCALLSTACK; MFDebug_Assert(pMeshChunk->type == MFMCT_Generic, "Not a Generic type meshchunk!!"); MFMeshChunk_Generic *pMC = (MFMeshChunk_Generic*)pMeshChunk; MFFixUp(pMC->pMaterial, pBase, load); MFFixUp(pMC->pIndexData, pBase, load); MFFixUp(pMC->pBatchIndices, pBase, load); if(load) { MFFixUp(pMC->pVertexFormat, pBase, 1); MFFixUp(pMC->pVertexFormat->pStreams, pBase, 1); MFFixUp(pMC->ppVertexStreams, pBase, 1); } for(int b=0; b<pMC->pVertexFormat->numVertexStreams; ++b) { if(pMC->pVertexFormat->pStreams[b].pStreamName) MFFixUp(pMC->pVertexFormat->pStreams[b].pStreamName, pBase, load); MFFixUp(pMC->pVertexFormat->pStreams[b].pElements, pBase, load); MFFixUp(pMC->ppVertexStreams[b], pBase, load); } if(!load) { MFFixUp(pMC->pVertexFormat->pStreams, pBase, 0); MFFixUp(pMC->pVertexFormat, pBase, 0); MFFixUp(pMC->ppVertexStreams, pBase, 0); } }
bool MFVertex_CreateVertexDeclarationPlatformSpecific(MFVertexDeclaration *pDeclaration) { MFVertexElement *pElements = pDeclaration->pElements; MFVertexElementData *pElementData = pDeclaration->pElementData; D3D11_INPUT_ELEMENT_DESC elements[32]; for(int a=0; a<pDeclaration->numElements; ++a) { MFDebug_Assert(s_MFVDF_To_DXGI[pElements[a].format] != (DXGI_FORMAT)-1, "Invalid vertex data format!"); elements[a].SemanticName = s_SemanticName[pElements[a].type]; elements[a].SemanticIndex = (UINT)pElements[a].index; elements[a].Format = s_MFVDF_To_DXGI[pElements[a].format]; elements[a].InputSlot = (UINT)pElements[a].stream; elements[a].AlignedByteOffset = (UINT)pElementData[a].offset; elements[a].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; elements[a].InstanceDataStepRate = 0; } // this needs the vertex shader ID3D11InputLayout* pVertexLayout = NULL; HRESULT hr = g_pd3dDevice->CreateInputLayout(elements, pDeclaration->numElements, g_pVertexShaderData, g_vertexShaderSize, &pVertexLayout); if (FAILED(hr)) return false; pDeclaration->pPlatformData = pVertexLayout; return true; }
MF_API MFCollisionTriangle* MFCollision_LockDynamicCollisionMeshTriangleBuffer(MFCollisionItem *pDynamicCollisionMesh) { MFDebug_Assert(pDynamicCollisionMesh->pTemplate->type == MFCT_Mesh, "Collision item is not an MFCollisionMesh."); MFCollisionMesh *pMesh = (MFCollisionMesh*)pDynamicCollisionMesh->pTemplate->pCollisionTemplateData; return pMesh->pTriangles; }
MF_API MFCollisionItem* MFCollision_CreateDynamicCollisionMesh(const char *pItemName, int numTris) { MFDebug_Assert(numTris > 0, "Cant create collision mesh with no triangles.."); MFCollisionItem *pItem; MFCollisionTemplate *pTemplate; MFCollisionMesh *pMesh; MFCollisionTriangle *pTris; pItem = MFCollision_CreateCollisionItem(); pTemplate = (MFCollisionTemplate*)MFHeap_Alloc(MFALIGN16(sizeof(MFCollisionTemplate)) + MFALIGN16(sizeof(MFCollisionMesh)) + sizeof(MFCollisionTriangle)*numTris + MFString_Length(pItemName) + 1); pMesh = (MFCollisionMesh*)MFALIGN16(&pTemplate[1]); pTris = (MFCollisionTriangle*)MFALIGN16(&pMesh[1]); pItem->pTemplate = pTemplate; pItem->flags = 0; pItem->refCount = 1; pItem->worldPos = MFMatrix::identity; pTemplate->pCollisionTemplateData = pMesh; pTemplate->type = MFCT_Mesh; pTemplate->pName = (char*)&pTris[numTris]; MFString_Copy((char*)pTemplate->pName, pItemName); pMesh->numTris = numTris; pMesh->pTriangles = pTris; return pItem; }
void MFObjectPool::Init(size_t _objectSize, int numObjects, int growObjects, void *_pMemory, size_t _bytes) { objectSize = _objectSize; maxItems = numObjects; grow = growObjects; allocated = 0; bytes = _objectSize * numObjects; if(_pMemory) { MFDebug_Assert((uint32)bytes <= _bytes, "Supplied allocation is too small!"); pMemory = (char*)_pMemory; bOwnMemory = false; } else { pMemory = (char*)MFHeap_Alloc(bytes + sizeof(void**)*numObjects); bOwnMemory = true; } ppItems = (void**)(pMemory + bytes); for(int a=0; a<numObjects; ++a) ppItems[a] = pMemory + _objectSize*a; pNext = NULL; mutex = MFThread_CreateMutex("MFObjectPool alloc mutex"); }
// gets the temp heap associated with a heap MF_API MFHeap* MFHeap_GetTempHeap(MFHeap *pHeap) { MFCALLSTACK; MFDebug_Assert(pHeap, "Invalid heap"); return pHeap->pTempHeap ? pHeap->pTempHeap : pHeap; }