/** This version loads both the raw data and the normalized samples * into two buffers and also returns the format and the sampling * frequency. * * @see LoadMemoryFromFileNormalized * @see LoadMemoryHelloWorldNormalized * * @alsymbols * @alutfunref{LoadMemoryFromFile} */ void LoadMemoryFromFile( std::vector<ALubyte>& raw, std::vector<ALfloat>& norm, const ALchar* file_path, DataFormat* data_format, ALfloat* frequency ) const { ::ALenum format = 0; ::ALsizei size = 0; ::ALvoid* ptr = OALPLUS_ALFUNC(alut,LoadMemoryFromFile)( file_path, &format, &size, frequency ); OALPLUS_CHECK_ALUT(OALPLUS_ERROR_INFO(alut, LoadMemoryFromFile)); _free_on_scope_exit cleaner = { ptr }; OALPLUS_FAKE_USE(cleaner); if(data_format) *data_format = DataFormat(format); raw = _load_memory(ptr, size); norm = _load_mem_norm(ptr, format, size); }
DX11WindowRenderTarget::DX11WindowRenderTarget(DX11Graphics& graphics, Window& window) : WindowRenderTarget(window.GetSize(), DataFormat(DataFormat::Int8UNorm, 4)), mDeviceContext(graphics.GetContext()) { DXGI_SWAP_CHAIN_DESC swapChainDesc; ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC)); swapChainDesc.BufferDesc.Width = window.GetSize().x; swapChainDesc.BufferDesc.Height = window.GetSize().y; swapChainDesc.BufferDesc.RefreshRate.Numerator = 60; swapChainDesc.BufferDesc.RefreshRate.Denominator = 1; swapChainDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; swapChainDesc.SampleDesc.Count = 1; swapChainDesc.SampleDesc.Quality = 0; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.BufferCount = 2; swapChainDesc.OutputWindow = window.GetWindowHandle(); swapChainDesc.Windowed = true; swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; swapChainDesc.Flags = 0; HRESULT result = graphics.GetDXGIFactory()->CreateSwapChain(graphics.GetDevice(), &swapChainDesc, &mSwapChain); if (FAILED(result)) { throw HResultException(result, "Could not initialize swap buffer"); } ID3D11Texture2D *backBuffer; result = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&backBuffer); if (FAILED(result)) { throw HResultException(result, "Could not retrieve back buffer"); } result = graphics.GetDevice()->CreateRenderTargetView(backBuffer, NULL, &mRenderTargetView); backBuffer->Release(); if (FAILED(result)) { throw HResultException(result, "Could not create render target view"); } }
/** This version normalizes the sound samples. * * @see LoadMemoryFromFileNormalized * * @alsymbols * @alutfunref{LoadMemoryHelloWorld} */ std::vector<ALfloat> LoadMemoryHelloWorldNormalized( DataFormat* data_format, ALfloat* frequency) const { ::ALenum format = 0; ::ALsizei size = 0; ::ALvoid* ptr = OALPLUS_ALUTFUNC(LoadMemoryHelloWorld)(&format, &size, frequency); OALPLUS_CHECK_SIMPLE_ALUT(LoadMemoryHelloWorld); _free_on_scope_exit cleaner = {ptr}; OALPLUS_FAKE_USE(cleaner); if(data_format) *data_format = DataFormat(format); return _load_mem_norm(ptr, format, size); }
OpenGLWindowRenderTarget::OpenGLWindowRenderTarget(Window& window) : WindowRenderTarget(window.GetSize(), DataFormat(DataFormat::Int8UNorm, 4)), mHDC(GetDC(window.GetWindowHandle())) { PIXELFORMATDESCRIPTOR pfd; ZeroMemory( &pfd, sizeof( pfd ) ); pfd.nSize = sizeof( pfd ); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 32; pfd.cDepthBits = 0; pfd.iLayerType = PFD_MAIN_PLANE; int iFormat = ChoosePixelFormat( mHDC, &pfd ); SetPixelFormat( mHDC, iFormat, &pfd ); mHGLRenderContext = wglCreateContext(mHDC); MakeActive(); }
/** * @see LoadMemoryFromFileNormalized * @see LoadMemoryHelloWorldNormalized * * @alsymbols * @alutfunref{LoadMemoryFromFile} */ std::vector<ALubyte> LoadMemoryFromFile( const StrCRef& file_path, DataFormat* data_format, ALfloat* frequency) const { ::ALenum format = 0; ::ALsizei size = 0; ::ALvoid* ptr = OALPLUS_ALUTFUNC(LoadMemoryFromFile)( file_path.is_nts() ? file_path.c_str() : file_path.str().c_str(), &format, &size, frequency); OALPLUS_CHECK_SIMPLE_ALUT(LoadMemoryFromFile); _free_on_scope_exit cleaner = {ptr}; OALPLUS_FAKE_USE(cleaner); if(data_format) *data_format = DataFormat(format); return _load_memory(ptr, size); }
Auto<Resource> Texture2DLoader::LoadResource(ResourceManager& resourceManager, istream& inputStream, const std::string& internalName) { FreeImageIO io; fi_handle handle = (fi_handle)(&inputStream); io.read_proc = [] (void *buffer, unsigned size, unsigned count, fi_handle handle) { istream* input = (istream*)handle; unsigned bytes = size * count; unsigned totalRead = 0; unsigned loopRead = 0; do { input->read((char*)buffer + totalRead, bytes - totalRead); loopRead = (unsigned)input->gcount(); totalRead += loopRead; } while (loopRead > 0 && totalRead < bytes); unsigned result = totalRead / size; unsigned overRead = totalRead % size; if (overRead > 0) { input->seekg(-(int)overRead, ios_base::cur); } return result; }; io.write_proc = NULL; io.seek_proc = [] (fi_handle handle, long offset, int origin) { istream* input = (istream*)handle; ios_base::seekdir seekDir = (origin == SEEK_END) ? ios_base::end : ( (origin == SEEK_CUR) ? ios_base::cur : ios_base::beg); try { input->seekg(offset, seekDir); return (int)(input->fail() ? 1 : 0); } catch (ios_base::failure&) { return (int)1; } }; io.tell_proc = [](fi_handle handle) { istream* input = (istream*)handle; return (long)input->tellg(); }; FREE_IMAGE_FORMAT imageFormat = FreeImage_GetFileTypeFromHandle(&io, handle, 0); if (imageFormat == FIF_UNKNOWN) { throw FormatException("Unrecogized image format"); } FIBITMAP* bitmap = FreeImage_LoadFromHandle(imageFormat, &io, handle, 0); FREE_IMAGE_TYPE dataType = FreeImage_GetImageType(bitmap); DataFormat::Type formatType; size_t channelCount = 0; vector<unsigned char> textureData; Vector2i size(FreeImage_GetWidth(bitmap), FreeImage_GetHeight(bitmap)); if (dataType == FIT_BITMAP) { formatType = DataFormat::Int8UNorm; channelCount = 4; FIBITMAP* bitmap32Bit = FreeImage_ConvertTo32Bits(bitmap); FreeImage_Unload(bitmap); bitmap = bitmap32Bit; textureData.resize(FreeImage_GetPitch(bitmap) * size.y); SwapChannels<unsigned char>(FreeImage_GetBits(bitmap), &textureData.front(), 0, 2, size.x * size.y, 4); } else { throw FormatException("Unsupported depth format"); } Auto<Texture2D> result = resourceManager.GetGraphics()->CreateTexture2D(size, DataFormat(formatType, channelCount)); result->LoadMemory(&textureData.front()); result->GenerateMipmaps(); if (bitmap != NULL) { FreeImage_Unload(bitmap); bitmap = NULL; } return result; }