HRESULT CompileShaderFromFile(const std::wstring &file , const StageInfo &info, ID3D10Blob** ppBlobOut) { DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS; #if defined(DEBUG) || defined(_DEBUG) dwShaderFlags |= D3DCOMPILE_DEBUG; #endif//defiend(DEBUG) || defined(_DEBUG) #if defined(NDEBUG) || defined(_NDEBUG) dwShaderFlags |= D3DCOMPILE_OPTIMIZATION_LEVEL3; #endif//defined(NDEBUG) || defined(_NDEBUG) Microsoft::WRL::ComPtr<ID3DBlob> pErrorBlob; auto hr = D3DCompileFromFile( file.c_str() , NULL , D3D_COMPILE_STANDARD_FILE_INCLUDE , info.entrypoint.c_str() , info.model.c_str() , dwShaderFlags , 0 , ppBlobOut , pErrorBlob.GetAddressOf() ); if ( FAILED( hr ) ) { if (pErrorBlob) { // エラーメッセージを出力. OutputDebugStringA( (char*)pErrorBlob->GetBufferPointer() ); } } return hr; }
RoundedRectangle::RoundedRectangle(FLOAT x, FLOAT y, FLOAT width, FLOAT height, FLOAT xRadius, FLOAT yRadius) : Shape(ShapeType::RoundedRectangle), m_X(x), m_Y(y), m_Width(width + x), m_Height(height + y), m_XRadius(xRadius), m_YRadius(yRadius) { HRESULT hr = E_FAIL; const D2D1_ROUNDED_RECT rect = { m_X, m_Y, m_Width, m_Height, m_XRadius, m_YRadius }; Microsoft::WRL::ComPtr<ID2D1RoundedRectangleGeometry> rectangle; hr = Canvas::c_D2DFactory->CreateRoundedRectangleGeometry(rect, rectangle.GetAddressOf()); if (FAILED(hr)) { LogErrorF( L"Could not create rounded rectangle object. X=%i, Y=%i, W=%i, H=%i, XRadius=%i, YRadius=%i", (int)m_X, (int)m_Y, (int)m_Width, (int)m_Height, (int)m_XRadius, (int)m_YRadius); return; } hr = rectangle.CopyTo(m_Shape.GetAddressOf()); if (FAILED(hr)) LogErrorF( L"Could not copy rounded rectangle object to shape object. X=%i, Y=%i, W=%i, H=%i, XRadius=%i, YRadius=%i", (int)m_X, (int)m_Y, (int)m_Width, (int)m_Height, (int)m_XRadius, (int)m_YRadius); }
void Shape::CreateRadialGradient(ID2D1RenderTarget* target, ID2D1GradientStopCollection* collection, Microsoft::WRL::ComPtr<ID2D1Brush>& brush, bool isStroke) { auto swapIfNotDefined = [](D2D1_POINT_2F& pt1, const D2D1_POINT_2F pt2) -> void { if (pt2.x != FLT_MAX) pt1.x = pt2.x; if (pt2.y != FLT_MAX) pt1.y = pt2.y; }; auto bounds = GetBounds(false); D2D1_POINT_2F offset = D2D1::Point2F(); D2D1_POINT_2F center = D2D1::Point2F(((bounds.left + bounds.right) / 2.0f), ((bounds.top + bounds.bottom) / 2.0f)); D2D1_POINT_2F radius = D2D1::Point2F((bounds.right - bounds.left) / 2.0f, (bounds.bottom - bounds.top) / 2.0f); // Offset from actual center of shape center = Util::AddPoint2F(center, isStroke ? m_StrokeRadialGradientCenter : m_FillRadialGradientCenter); // Check if offset and radii are defined swapIfNotDefined(offset, isStroke ? m_StrokeRadialGradientOffset : m_FillRadialGradientOffset); swapIfNotDefined(radius, isStroke ? m_StrokeRadialGradientRadius : m_FillRadialGradientRadius); Microsoft::WRL::ComPtr<ID2D1RadialGradientBrush> radial; HRESULT hr = target->CreateRadialGradientBrush( D2D1::RadialGradientBrushProperties( center, offset, radius.x, radius.y), collection, radial.GetAddressOf()); if (SUCCEEDED(hr)) radial.CopyTo(brush.ReleaseAndGetAddressOf()); }
void Shape::CreateSolidBrush(ID2D1RenderTarget* target, Microsoft::WRL::ComPtr<ID2D1Brush>& brush, const D2D1_COLOR_F& color) { Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> solid; HRESULT hr = target->CreateSolidColorBrush(color, solid.GetAddressOf()); if (SUCCEEDED(hr)) solid.CopyTo(brush.ReleaseAndGetAddressOf()); }
bool createVB(const Microsoft::WRL::ComPtr<ID3D11Device> &pDevice) { // Create VB auto size = 0.5f; Vertex pVertices[] = { // x { DirectX::XMFLOAT4(-size, -size, -size, 1.0f), DirectX::XMFLOAT4(0.5f, 0.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(0, 1) }, { DirectX::XMFLOAT4(-size, -size, size, 1.0f), DirectX::XMFLOAT4(0.5f, 0.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(0, 0) }, { DirectX::XMFLOAT4(-size, size, size, 1.0f), DirectX::XMFLOAT4(0.5f, 0.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(1, 0) }, { DirectX::XMFLOAT4(-size, size, -size, 1.0f), DirectX::XMFLOAT4(0.5f, 0.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(1, 1) }, { DirectX::XMFLOAT4(size, -size, -size, 1.0f), DirectX::XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(0, 1) }, { DirectX::XMFLOAT4(size, size, -size, 1.0f), DirectX::XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(1, 1) }, { DirectX::XMFLOAT4(size, size, size, 1.0f), DirectX::XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(1, 0) }, { DirectX::XMFLOAT4(size, -size, size, 1.0f), DirectX::XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(0, 0) }, // y { DirectX::XMFLOAT4(-size, size, -size, 1.0f), DirectX::XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(0, 1) }, { DirectX::XMFLOAT4(-size, size, size, 1.0f), DirectX::XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(0, 0) }, { DirectX::XMFLOAT4(size, size, size, 1.0f), DirectX::XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(1, 0) }, { DirectX::XMFLOAT4(size, size, -size, 1.0f), DirectX::XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(1, 1) }, { DirectX::XMFLOAT4(-size, -size, -size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.5f, 0.0f, 1.0f), DirectX::XMFLOAT2(0, 1) }, { DirectX::XMFLOAT4(size, -size, -size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.5f, 0.0f, 1.0f), DirectX::XMFLOAT2(1, 1) }, { DirectX::XMFLOAT4(size, -size, size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.5f, 0.0f, 1.0f), DirectX::XMFLOAT2(1, 0) }, { DirectX::XMFLOAT4(-size, -size, size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.5f, 0.0f, 1.0f), DirectX::XMFLOAT2(0, 0) }, // z { DirectX::XMFLOAT4(-size, -size, -size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.0f, 0.5f, 1.0f), DirectX::XMFLOAT2(0, 1) }, { DirectX::XMFLOAT4(-size, size, -size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.0f, 0.5f, 1.0f), DirectX::XMFLOAT2(0, 0) }, { DirectX::XMFLOAT4(size, size, -size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.0f, 0.5f, 1.0f), DirectX::XMFLOAT2(1, 0) }, { DirectX::XMFLOAT4(size, -size, -size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.0f, 0.5f, 1.0f), DirectX::XMFLOAT2(1, 1) }, { DirectX::XMFLOAT4(-size, -size, size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.0f, 1.0f, 1.0f), DirectX::XMFLOAT2(0, 1) }, { DirectX::XMFLOAT4(size, -size, size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.0f, 1.0f, 1.0f), DirectX::XMFLOAT2(1, 1) }, { DirectX::XMFLOAT4(size, size, size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.0f, 1.0f, 1.0f), DirectX::XMFLOAT2(1, 0) }, { DirectX::XMFLOAT4(-size, size, size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.0f, 1.0f, 1.0f), DirectX::XMFLOAT2(0, 0) }, }; unsigned int vsize = sizeof(pVertices); D3D11_BUFFER_DESC vdesc; ZeroMemory(&vdesc, sizeof(vdesc)); vdesc.ByteWidth = vsize; vdesc.Usage = D3D11_USAGE_DEFAULT; vdesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; vdesc.CPUAccessFlags = 0; D3D11_SUBRESOURCE_DATA vertexData; ZeroMemory(&vertexData, sizeof(vertexData)); vertexData.pSysMem = pVertices; HRESULT hr = pDevice->CreateBuffer(&vdesc, &vertexData, m_pVertexBuf.GetAddressOf()); if (FAILED(hr)){ return false; } return true; }
int sound_xaudio2::init(osd_options const &options) { HRESULT result; WAVEFORMATEX format = {0}; auto init_start = std::chrono::system_clock::now(); std::chrono::milliseconds init_time; CoInitializeEx(nullptr, COINIT_MULTITHREADED); // Make sure our XAudio2Create entrypoint is bound if (!XAudio2Create) { osd_printf_error("Could not find XAudio2. Please try to reinstall DirectX runtime package.\n"); return 1; } // Create the IXAudio2 object HR_GOERR(this->XAudio2Create(m_xAudio2.GetAddressOf(), 0, XAUDIO2_DEFAULT_PROCESSOR)); // make a format description for what we want format.wBitsPerSample = 16; format.wFormatTag = WAVE_FORMAT_PCM; format.nChannels = 2; format.nSamplesPerSec = sample_rate(); format.nBlockAlign = format.wBitsPerSample * format.nChannels / 8; format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign; m_sample_bytes = format.nBlockAlign; // Create the buffers create_buffers(format); // Initialize our events m_hEventBufferCompleted = CreateEvent(nullptr, FALSE, FALSE, nullptr); m_hEventDataAvailable = CreateEvent(nullptr, FALSE, FALSE, nullptr); m_hEventExiting = CreateEvent(nullptr, FALSE, FALSE, nullptr); // create the voices and start them HR_GOERR(create_voices(format)); HR_GOERR(m_sourceVoice->Start()); // Start the thread listening m_audioThread = std::thread([](sound_xaudio2* self) { self->process_audio(); }, this); init_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - init_start); osd_printf_verbose("Sound: XAudio2 initialized. %d ms.\n", static_cast<int>(init_time.count())); m_initialized = TRUE; return 0; Error: this->exit(); return 1; }
EncodedJSValue JSC_HOST_CALL COMMethodCall::call(ExecState* execState) { COMMethodCall* callee = jsCast<COMMethodCall*>(execState->callee()); if (execState->argumentCount() != callee->_parameterCells.size()) { // TODO: error CRASH(); } COMInterop* interop = jsCast<GlobalObject*>(execState->lexicalGlobalObject())->interop(); size_t numberOfABIParameters = callee->_parameterCells.size() + (callee->_isVoid ? 1 : 2); HRESULT hr; Microsoft::WRL::ComPtr<IUnknown> self; hr = interop->wrap(execState->thisValue(), callee->_methodInterface, self.GetAddressOf()); void** vtable = *reinterpret_cast<void***>(self.Get()); void* fn = vtable[callee->_methodIndex]; WTF::Vector<void*> arguments; arguments.reserveCapacity(numberOfABIParameters); IUnknown* thisValue = self.Get(); arguments.append(&thisValue); for (int i = 0; i < callee->_parameterCells.size(); i++) { JSCell* type = callee->_parameterCells[i].get(); void* buffer = _alloca(std::max(sizeof(ffi_arg), callee->_parameterTypes[i + 1]->size)); getFFIMethodTable(type)->marshalJSToNative(type, execState, execState->uncheckedArgument(i), buffer); arguments.append(buffer); } void* returnBuffer = nullptr; if (!callee->_isVoid) { returnBuffer = _alloca(std::max(sizeof(ffi_arg), callee->_parameterTypes[numberOfABIParameters - 1]->size)); arguments.append(&returnBuffer); } ffi_call(&callee->_cif, FFI_FN(fn), &hr, arguments.data()); JSValue jsResult; if (!SUCCEEDED(hr)) { _com_error error(hr, nullptr); jsResult = execState->vm().throwException(execState, createError(execState, error.ErrorMessage())); } else if (!callee->_isVoid) { JSCell* returnType = callee->_returnType.get(); jsResult = getFFIMethodTable(returnType)->marshalNativeToJS(returnType, execState, returnBuffer); } else { jsResult = jsUndefined(); } return JSValue::encode(jsResult); }
HRESULT GetGDIFamilyNameFromDWriteFont(IDWriteFont* font, WCHAR* buffer, UINT bufferSize) { Microsoft::WRL::ComPtr<IDWriteLocalizedStrings> strings; BOOL stringsExist; font->GetInformationalStrings( DWRITE_INFORMATIONAL_STRING_WIN32_FAMILY_NAMES, strings.GetAddressOf(), &stringsExist); if (strings && stringsExist) { return strings->GetString(0, buffer, bufferSize); } return E_FAIL; }
RenderTexture::RenderTexture(Canvas& canvas, UINT width, UINT height) : m_Bitmap() { m_Bitmap.m_Width = width; m_Bitmap.m_Height = height; D2D1_BITMAP_PROPERTIES1 bProps = D2D1::BitmapProperties1(D2D1_BITMAP_OPTIONS_TARGET, D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED)); Microsoft::WRL::ComPtr<ID2D1Bitmap1> segment; canvas.m_Target->CreateBitmap(D2D1::SizeU(width, height), NULL, 0, bProps, segment.GetAddressOf()); m_Bitmap.AddSegment(segment, 0u, 0u, width, height); }
static inline HRESULT CreateMemoryStream( _Outptr_ IStream** stream ) { Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IRandomAccessStream> abiStream; HRESULT hr = Windows::Foundation::ActivateInstance( Microsoft::WRL::Wrappers::HStringReference( RuntimeClass_Windows_Storage_Streams_InMemoryRandomAccessStream ).Get(), abiStream.GetAddressOf() ); if (SUCCEEDED(hr)) { hr = CreateStreamOverRandomAccessStream( abiStream.Get(), IID_PPV_ARGS( stream ) ); } return hr; }
Microsoft::WRL::ComPtr<ID3D12Resource> d3dUtil::CreateDefaultBuffer( ID3D12Device* device, ID3D12GraphicsCommandList* cmdList, const void* initData, UINT64 byteSize, Microsoft::WRL::ComPtr<ID3D12Resource>& uploadBuffer) { ComPtr<ID3D12Resource> defaultBuffer; // Create the actual default buffer resource. ThrowIfFailed(device->CreateCommittedResource( &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE, &CD3DX12_RESOURCE_DESC::Buffer(byteSize), D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(defaultBuffer.GetAddressOf()))); // In order to copy CPU memory data into our default buffer, we need to create // an intermediate upload heap. ThrowIfFailed(device->CreateCommittedResource( &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD), D3D12_HEAP_FLAG_NONE, &CD3DX12_RESOURCE_DESC::Buffer(byteSize), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(uploadBuffer.GetAddressOf()))); // Describe the data we want to copy into the default buffer. D3D12_SUBRESOURCE_DATA subResourceData ={}; subResourceData.pData = initData; subResourceData.RowPitch = byteSize; subResourceData.SlicePitch = subResourceData.RowPitch; // Schedule to copy the data to the default buffer resource. At a high level, the helper function UpdateSubresources // will copy the CPU memory into the intermediate upload heap. Then, using ID3D12CommandList::CopySubresourceRegion, // the intermediate upload heap data will be copied to mBuffer. cmdList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(defaultBuffer.Get(), D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_COPY_DEST)); UpdateSubresources<1>(cmdList, defaultBuffer.Get(), uploadBuffer.Get(), 0, 0, 1, &subResourceData); cmdList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(defaultBuffer.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_GENERIC_READ)); // Note: uploadBuffer has to be kept alive after the above function calls because // the command list has not been executed yet that performs the actual copy. // The caller can Release the uploadBuffer after it knows the copy has been executed. return defaultBuffer; }
void TextInlineFormat_Color::ApplyInlineFormat(ID2D1RenderTarget* target, IDWriteTextLayout* layout) { if (!target || !layout) return; Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> solidBrush; HRESULT hr = target->CreateSolidColorBrush(ToColorF(m_Color), solidBrush.GetAddressOf()); if (FAILED(hr)) return; for (const auto& range : GetRanges()) { if (range.length <= 0) continue; layout->SetDrawingEffect(solidBrush.Get(), range); } }
void Shape::CreateLinearGradient(ID2D1RenderTarget* target, ID2D1GradientStopCollection* collection, Microsoft::WRL::ComPtr<ID2D1Brush>& brush, const FLOAT angle) { auto bounds = GetBounds(false); D2D1_POINT_2F start = Util::FindEdgePoint(angle, bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top); D2D1_POINT_2F end = Util::FindEdgePoint(angle + 180, bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top); Microsoft::WRL::ComPtr<ID2D1LinearGradientBrush> linear; HRESULT hr = target->CreateLinearGradientBrush( D2D1::LinearGradientBrushProperties(start, end), collection, linear.GetAddressOf()); if (SUCCEEDED(hr)) linear.CopyTo(brush.ReleaseAndGetAddressOf()); }
void TextureManager::LoadTextures(const std::vector<std::string>& TexturesLocation) { for (std::string TextureLoc : TexturesLocation) { const std::string &fixed = "..\\examples\\assets\\" + TextureLoc.substr(0, TextureLoc.find_last_of('.')) + ".DDS"; std::ifstream DDSFile(fixed, std::ifstream::binary); irr::video::CImageLoaderDDS DDSPic(DDSFile); #ifdef GLBUILD WrapperResource *res = (WrapperResource*)malloc(sizeof(WrapperResource)); // TODO : clean it GLTexture *tmptexture = new GLTexture(DDSPic.getLoadedImage()); res->GLValue.Resource = tmptexture->Id; res->GLValue.Type = GL_TEXTURE_2D; #endif #ifdef DXBUILD D3DTexture TextureInRam(DDSPic.getLoadedImage()); WrapperResource *res = (WrapperResource*)malloc(sizeof(WrapperResource)); HRESULT hr = Context::getInstance()->dev->CreateCommittedResource( &CD3D12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_MISC_NONE, &CD3D12_RESOURCE_DESC::Tex2D(TextureInRam.getFormat(), (UINT)TextureInRam.getWidth(), (UINT)TextureInRam.getHeight(), 1, (UINT16)TextureInRam.getMipLevelsCount()), D3D12_RESOURCE_USAGE_GENERIC_READ, nullptr, IID_PPV_ARGS(&res->D3DValue.resource) ); Microsoft::WRL::ComPtr<ID3D12CommandAllocator> cmdalloc; Context::getInstance()->dev->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&cmdalloc)); Microsoft::WRL::ComPtr<ID3D12GraphicsCommandList> cmdlist; Context::getInstance()->dev->CreateCommandList(1, D3D12_COMMAND_LIST_TYPE_DIRECT, cmdalloc.Get(), nullptr, IID_PPV_ARGS(&cmdlist)); TextureInRam.CreateUploadCommandToResourceInDefaultHeap(cmdlist.Get(), res->D3DValue.resource); cmdlist->Close(); Context::getInstance()->cmdqueue->ExecuteCommandLists(1, (ID3D12CommandList**)cmdlist.GetAddressOf()); HANDLE handle = getCPUSyncHandle(Context::getInstance()->cmdqueue.Get()); res->D3DValue.description.TextureView.SRV = TextureInRam.getResourceViewDesc(); WaitForSingleObject(handle, INFINITE); CloseHandle(handle); #endif textureSet.emplace(TextureLoc, res); } }
void CanvasD2D::FillRectangle(Gdiplus::Rect& rect, const Gdiplus::SolidBrush& brush) { if (!m_Target) // Use GDI+ if D2D render target has not been created. { m_GdipGraphics->FillRectangle(&brush, rect); return; } Gdiplus::Color color; brush.GetColor(&color); Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> solidBrush; HRESULT hr = m_Target->CreateSolidColorBrush(ToColorF(color), solidBrush.GetAddressOf()); if (SUCCEEDED(hr)) { m_Target->FillRectangle(ToRectF(rect), solidBrush.Get()); } }
void TextInlineFormat_Typography::ApplyInlineFormat(IDWriteTextLayout* layout) { if (!layout) return; for (const auto& range : GetRanges()) { if (range.length <= 0) continue; Microsoft::WRL::ComPtr<IDWriteTypography> typography; HRESULT hr = Canvas::c_DWFactory->CreateTypography(typography.GetAddressOf()); if (FAILED(hr)) continue; DWRITE_FONT_FEATURE feature = { m_Tag, m_Parameter }; hr = typography->AddFontFeature(feature); if (FAILED(hr)) continue; layout->SetTypography(typography.Get(), range); } }
void DXWrapper_InitDeviceAndContext( Microsoft::WRL::ComPtr<ID3D11Device1> pDevice, Microsoft::WRL::ComPtr<ID3D11DeviceContext1> pContext, Microsoft::WRL::ComPtr<ID3D11RenderTargetView> pRenderTargetView, Microsoft::WRL::ComPtr<ID3D11DepthStencilView> pDepthStencilView ) { g_pD3DDevice = pDevice; g_pD3DContext = pContext; g_pD3DRenderTargetView = pRenderTargetView; g_pD3DDepthStencilView = pDepthStencilView; g_pD3DContext->OMSetRenderTargets( 1, g_pD3DRenderTargetView.GetAddressOf(), g_pD3DDepthStencilView.Get() ); D3DCreateDepthStencilStates(); D3DCreateSamplerStates(); D3DCreateBlendStates(); float blendfactor[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; g_pD3DContext->OMSetBlendState( g_pD3DBlendStateEnabled.Get(), blendfactor, 0xfff ); UpdateDepthState(); }
void Scene::onKeyUp(UINT8 key) { if (key == 'Z') { DXGI_SWAP_CHAIN_DESC desc; this->mpSwapChain->GetDesc(&desc); Microsoft::WRL::ComPtr<IDXGIOutput> pOutput; if (desc.Windowed) { //全画面モードに切り替える際はどのディスプレイを対象にするか決めれる if (DXGI_ERROR_NOT_FOUND == this->mpAdapter->EnumOutputs(0, pOutput.GetAddressOf())) { throw std::runtime_error("アダプターの出力先が見つかりません。"); } } auto hr = this->mpSwapChain->SetFullscreenState(desc.Windowed, pOutput.Get()); if (FAILED(hr)) { throw std::runtime_error("フルスリーンモードとウィンドウモードの切り替えに失敗。"); } } }
bool CanvasD2D::MeasureTextW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect) { Microsoft::WRL::ComPtr<IDWriteTextLayout> textLayout; HRESULT hr = c_DWFactory->CreateTextLayout( str, strLen, ((TextFormatD2D&)format).m_TextFormat.Get(), 10000, 10000, textLayout.GetAddressOf()); if (SUCCEEDED(hr)) { DWRITE_TEXT_METRICS metrics; textLayout->GetMetrics(&metrics); rect.Width = metrics.width + 5.0f; rect.Height = metrics.height + 1.0f; // 1.0f to get same result as GDI+. return true; } return false; }
void CanvasD2D::DrawTextW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect, const Gdiplus::SolidBrush& brush) { if (!BeginTargetDraw()) return; Gdiplus::Color color; brush.GetColor(&color); Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> solidBrush; HRESULT hr = m_Target->CreateSolidColorBrush(ToColorF(color), solidBrush.GetAddressOf()); if (SUCCEEDED(hr)) { TextFormatD2D& formatD2D = (TextFormatD2D&)format; const bool right = formatD2D.GetHorizontalAlignment() == Gfx::HorizontalAlignment::Right; formatD2D.CreateLayout(str, strLen, rect.Width, rect.Height); m_Target->DrawTextLayout( D2D1::Point2F(right ? rect.X - 2 : rect.X + 2.0f, rect.Y - 1.0f), formatD2D.m_TextLayout.Get(), solidBrush.Get()); } }
void Load(ID3D11ShaderResourceView* texture) { mTexture = texture; if (texture) { Microsoft::WRL::ComPtr<ID3D11Resource> resource; texture->GetResource(resource.GetAddressOf()); D3D11_RESOURCE_DIMENSION dim; resource->GetType(&dim); if (dim != D3D11_RESOURCE_DIMENSION_TEXTURE2D) throw std::exception("ScrollingBackground expects a Texture2D"); Microsoft::WRL::ComPtr<ID3D11Texture2D> tex2D; resource.As(&tex2D); D3D11_TEXTURE2D_DESC desc; tex2D->GetDesc(&desc); mTextureWidth = desc.Width; mTextureHeight = desc.Height; mTextureSize.x = float(desc.Width); mTextureSize.y = float( desc.Height ); mTextureSize.y = 0.f; //Wrong - loss of usefull data // mOrigin.y = desc.Width / 2.f; // mOrigin.x = desc.Width / 2.f; mOrigin.x = 0.f; mOrigin.y = 0.f; TempPlayerPos.x = 0; TempPlayerPos.y = 0; } }
Ellipse::Ellipse(FLOAT x, FLOAT y, FLOAT xRadius, FLOAT yRadius) : Shape(ShapeType::Ellipse), m_CenterPoint(D2D1::Point2F(x, y)), m_RadiusX(xRadius), m_RadiusY(yRadius) { HRESULT hr = E_FAIL; const D2D1_ELLIPSE ellipse = D2D1::Ellipse(m_CenterPoint, m_RadiusX, m_RadiusY); Microsoft::WRL::ComPtr<ID2D1EllipseGeometry> geometry; hr = Canvas::c_D2DFactory->CreateEllipseGeometry(ellipse, geometry.GetAddressOf()); if (FAILED(hr)) { LogErrorF( L"Could not create ellipse object. X=%i, Y=%i, RadiusX=%i, RadiusY=%i", (int)x, (int)y, (int)xRadius, (int)yRadius); return; } hr = geometry.CopyTo(m_Shape.GetAddressOf()); if (FAILED(hr)) LogErrorF( L"Could not copy ellipse object to shape object. X=%i, Y=%i, RadiusX=%i, RadiusY=%i", (int)x, (int)y, (int)xRadius, (int)yRadius); }
void Scene::onInit() { this->mpZBufferDSV.Reset(); this->mpZBuffer.Reset(); this->mpBackBufferRTV.Reset(); this->mpBackBuffer.Reset(); this->mpImmediateContext.Reset(); this->mpDevice.Reset(); this->mpSwapChain.Reset(); //デバイスなどを作り直す //DXGIを使う上で必要となるIDXGIFactory1を作成 HRESULT hr; Microsoft::WRL::ComPtr<IDXGIFactory1> pFactory; hr = CreateDXGIFactory1(IID_PPV_ARGS(pFactory.GetAddressOf())); if (FAILED(hr)) { throw std::runtime_error("IDXGIFactoryクラスの作成に失敗しました。"); } //GPUアダプターを列挙して一番最初に見つかった使えるものを選ぶ Microsoft::WRL::ComPtr<IDXGIAdapter1> pAdapterIt; for (UINT adapterIndex = 0; S_OK == pFactory->EnumAdapters1(adapterIndex, pAdapterIt.GetAddressOf()); ++adapterIndex) { DXGI_ADAPTER_DESC1 desc; pAdapterIt->GetDesc1(&desc); OutputDebugStringA( std::string("adapter " + std::to_string(adapterIndex) + "\n").c_str()); OutputDebugStringW((std::wstring(L" decription = ") + desc.Description + L"\n").c_str()); OutputDebugStringA( std::string(" VemdorId = " + std::to_string(desc.VendorId) + "\n").c_str()); OutputDebugStringA( std::string(" DeviceId = " + std::to_string(desc.DeviceId) + "\n").c_str()); OutputDebugStringA( std::string(" SubSysId = " + std::to_string(desc.SubSysId) + "\n").c_str()); OutputDebugStringA( std::string(" Revision = " + std::to_string(desc.Revision) + "\n").c_str()); OutputDebugStringA( std::string(" DedicatedVideoMemory = " + std::to_string(desc.DedicatedVideoMemory) + "\n").c_str()); OutputDebugStringA( std::string(" DedicatedSystemMemory = " + std::to_string(desc.DedicatedSystemMemory) + "\n").c_str()); OutputDebugStringA( std::string(" SharedSystemMemory = " + std::to_string(desc.SharedSystemMemory) + "\n").c_str()); OutputDebugStringA( std::string(" AdapterLuid = high:" + std::to_string(desc.AdapterLuid.HighPart) + " low:" + std::to_string(desc.AdapterLuid.LowPart) + "\n").c_str()); OutputDebugStringA( std::string(" Flag = " + std::to_string(desc.Flags) + "\n").c_str()); if (nullptr == this->mpAdapter) { if (desc.Flags ^= DXGI_ADAPTER_FLAG_SOFTWARE) { this->mpAdapter = pAdapterIt; OutputDebugStringA(std::string("このアダプターを使用します。 adapterIndex = " + std::to_string(adapterIndex) + "\n").c_str()); } //期待通りに動作してくれなかった //LARGE_INTEGER version; //hr = pAdapterIt->CheckInterfaceSupport(__uuidof(ID3D11Device), &version); //DXGI_ERROR_UNSUPPORTED; //if (S_OK == hr) { // pAdapter = pAdapterIt; // OutputDebugStringA(std::string("このアダプターを使用します。 adapterIndex = " + std::to_string(adapterIndex) + "\n").c_str()); //} } //使い終わったら必ずReleaseすること pAdapterIt.Reset(); } //ID3D11DeviceとID3D11DeviceContextの作成 std::array<D3D_FEATURE_LEVEL, 3> featureLevels = { { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0 } }; UINT flags = 0; #ifdef _DEBUG flags |= D3D11_CREATE_DEVICE_DEBUG; #endif D3D_FEATURE_LEVEL usedLevel; hr = D3D11CreateDevice( this->mpAdapter.Get(), D3D_DRIVER_TYPE_UNKNOWN, nullptr, flags, featureLevels.data(), static_cast<UINT>(featureLevels.size()), D3D11_SDK_VERSION, this->mpDevice.GetAddressOf(), &usedLevel, this->mpImmediateContext.GetAddressOf() ); if (FAILED(hr)) { throw std::runtime_error("ID3D11Deviceの作成に失敗。"); } //IDXGISwapChainの作成 DXGI_SWAP_CHAIN_DESC swapChainDesc = { 0 }; swapChainDesc.OutputWindow = Win32Application::hwnd(); swapChainDesc.BufferCount = 2; swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_SEQUENTIAL; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; //swapChainDesc.Flags = 0; swapChainDesc.SampleDesc.Count = 1; swapChainDesc.SampleDesc.Quality = 0; //フルスクリーンとウィンドモードの切り替えがしたい場合は、まずウィンドウモードとして生成することを推奨しているみたい //https://msdn.microsoft.com/en-us/library/bb174579(v=vs.85).aspx swapChainDesc.Windowed = true; //希望する画面設定 swapChainDesc.BufferDesc.Width = this->width(); swapChainDesc.BufferDesc.Height = this->height(); swapChainDesc.BufferDesc.RefreshRate.Numerator = 60; swapChainDesc.BufferDesc.RefreshRate.Denominator = 1; swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; //上の画面設定に一番近いものを調べる Microsoft::WRL::ComPtr<IDXGIOutput> pOutput; if (DXGI_ERROR_NOT_FOUND == this->mpAdapter->EnumOutputs(0, pOutput.GetAddressOf())) { throw std::runtime_error("アダプターの出力先が見つかりません。"); } DXGI_MODE_DESC modeDesc; hr = pOutput->FindClosestMatchingMode(&swapChainDesc.BufferDesc, &modeDesc, this->mpDevice.Get()); if (FAILED(hr)) { throw std::runtime_error("表示モードの取得に失敗"); } //IDXGISwapChainの作成 swapChainDesc.BufferDesc = modeDesc; hr = pFactory->CreateSwapChain(this->mpDevice.Get(), &swapChainDesc, this->mpSwapChain.GetAddressOf()); if (FAILED(hr)) { throw std::runtime_error("IDXGISwapChainの作成に失敗"); } //ディスプレイの画面モードの一覧を取得する //IDXGIOutput* pOutput; //this->mpSwapChain->GetContainingOutput(&pOutput); //UINT num; //UINT flag = DXGI_ENUM_MODES_INTERLACED; //pOutput->GetDisplayModeList(swapChainDesc.BufferDesc.Format, flag, &num, nullptr); //std::vector<DXGI_MODE_DESC> modeDesces; //modeDesces.resize(num); //pOutput->GetDisplayModeList(swapChainDesc.BufferDesc.Format, flag, &num, &modeDesces[0]); //pOutput->Release(); // // 後はバックバッファのレンダーターゲットビューの作成、必要ならZバッファの作成とビューポートの設定を行う // initRenderTargetAndDepthStencil(swapChainDesc.BufferDesc.Width, swapChainDesc.BufferDesc.Height); }
SettingsDialog::SettingsDialog(wxWindow *parent, rpcs3::config_t* cfg) : wxDialog(parent, wxID_ANY, "Settings", wxDefaultPosition) { const bool was_running = Emu.Pause(); if (was_running || Emu.IsReady()) cfg = &rpcs3::state.config; static const u32 width = 458; static const u32 height = 400; // Settings panels wxNotebook* nb_config = new wxNotebook(this, wxID_ANY, wxPoint(6, 6), wxSize(width, height)); wxPanel* p_system = new wxPanel(nb_config, wxID_ANY); wxPanel* p_core = new wxPanel(nb_config, wxID_ANY); wxPanel* p_graphics = new wxPanel(nb_config, wxID_ANY); wxPanel* p_audio = new wxPanel(nb_config, wxID_ANY); wxPanel* p_io = new wxPanel(nb_config, wxID_ANY); wxPanel* p_misc = new wxPanel(nb_config, wxID_ANY); wxPanel* p_networking = new wxPanel(nb_config, wxID_ANY); nb_config->AddPage(p_core, wxT("Core")); nb_config->AddPage(p_graphics, wxT("Graphics")); nb_config->AddPage(p_audio, wxT("Audio")); nb_config->AddPage(p_io, wxT("Input / Output")); nb_config->AddPage(p_misc, wxT("Miscellaneous")); nb_config->AddPage(p_networking, wxT("Networking")); nb_config->AddPage(p_system, wxT("System")); wxBoxSizer* s_subpanel_core = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer* s_subpanel_core1 = new wxBoxSizer(wxVERTICAL); wxBoxSizer* s_subpanel_core2 = new wxBoxSizer(wxVERTICAL); wxBoxSizer* s_subpanel_graphics = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer* s_subpanel_graphics1 = new wxBoxSizer(wxVERTICAL); wxBoxSizer* s_subpanel_graphics2 = new wxBoxSizer(wxVERTICAL); wxBoxSizer* s_subpanel_audio = new wxBoxSizer(wxVERTICAL); wxBoxSizer* s_subpanel_io = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer* s_subpanel_io1 = new wxBoxSizer(wxVERTICAL); wxBoxSizer* s_subpanel_io2 = new wxBoxSizer(wxVERTICAL); wxBoxSizer* s_subpanel_system = new wxBoxSizer(wxVERTICAL); wxBoxSizer* s_subpanel_misc = new wxBoxSizer(wxVERTICAL); wxBoxSizer* s_subpanel_networking = new wxBoxSizer(wxVERTICAL); // Core settings wxStaticBoxSizer* s_round_llvm = new wxStaticBoxSizer(wxVERTICAL, p_core, _("LLVM config")); wxStaticBoxSizer* s_round_llvm_range = new wxStaticBoxSizer(wxHORIZONTAL, p_core, _("Excluded block range")); wxStaticBoxSizer* s_round_llvm_threshold = new wxStaticBoxSizer(wxHORIZONTAL, p_core, _("Compilation threshold")); // Graphics wxStaticBoxSizer* s_round_gs_render = new wxStaticBoxSizer(wxVERTICAL, p_graphics, _("Render")); wxStaticBoxSizer* s_round_gs_d3d_adaptater = new wxStaticBoxSizer(wxVERTICAL, p_graphics, _("D3D Adaptater")); wxStaticBoxSizer* s_round_gs_res = new wxStaticBoxSizer(wxVERTICAL, p_graphics, _("Resolution")); wxStaticBoxSizer* s_round_gs_aspect = new wxStaticBoxSizer(wxVERTICAL, p_graphics, _("Aspect ratio")); wxStaticBoxSizer* s_round_gs_frame_limit = new wxStaticBoxSizer(wxVERTICAL, p_graphics, _("Frame limit")); // Input / Output wxStaticBoxSizer* s_round_io_pad_handler = new wxStaticBoxSizer(wxVERTICAL, p_io, _("Pad Handler")); wxStaticBoxSizer* s_round_io_keyboard_handler = new wxStaticBoxSizer(wxVERTICAL, p_io, _("Keyboard Handler")); wxStaticBoxSizer* s_round_io_mouse_handler = new wxStaticBoxSizer(wxVERTICAL, p_io, _("Mouse Handler")); wxStaticBoxSizer* s_round_io_camera = new wxStaticBoxSizer(wxVERTICAL, p_io, _("Camera")); wxStaticBoxSizer* s_round_io_camera_type = new wxStaticBoxSizer(wxVERTICAL, p_io, _("Camera type")); // Audio wxStaticBoxSizer* s_round_audio_out = new wxStaticBoxSizer(wxVERTICAL, p_audio, _("Audio Out")); // Miscellaneous wxStaticBoxSizer* s_round_hle_log_lvl = new wxStaticBoxSizer(wxVERTICAL, p_misc, _("Log Level")); // Networking wxStaticBoxSizer* s_round_net_status = new wxStaticBoxSizer(wxVERTICAL, p_networking, _("Connection status")); wxStaticBoxSizer* s_round_net_interface = new wxStaticBoxSizer(wxVERTICAL, p_networking, _("Network adapter")); // System wxStaticBoxSizer* s_round_sys_lang = new wxStaticBoxSizer(wxVERTICAL, p_system, _("Language")); wxRadioBox* rbox_ppu_decoder; wxRadioBox* rbox_spu_decoder; wxComboBox* cbox_gs_render = new wxComboBox(p_graphics, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(150, -1), 0, NULL, wxCB_READONLY); wxComboBox* cbox_gs_d3d_adaptater = new wxComboBox(p_graphics, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(150, -1), 0, NULL, wxCB_READONLY); wxComboBox* cbox_gs_resolution = new wxComboBox(p_graphics, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(150, -1), 0, NULL, wxCB_READONLY); wxComboBox* cbox_gs_aspect = new wxComboBox(p_graphics, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(150, -1), 0, NULL, wxCB_READONLY); wxComboBox* cbox_gs_frame_limit = new wxComboBox(p_graphics, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(150, -1), 0, NULL, wxCB_READONLY); wxComboBox* cbox_pad_handler = new wxComboBox(p_io, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(150, -1), 0, NULL, wxCB_READONLY);; wxComboBox* cbox_keyboard_handler = new wxComboBox(p_io, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(150, -1), 0, NULL, wxCB_READONLY); wxComboBox* cbox_mouse_handler = new wxComboBox(p_io, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(150, -1), 0, NULL, wxCB_READONLY); wxComboBox* cbox_camera = new wxComboBox(p_io, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(150, -1), 0, NULL, wxCB_READONLY); wxComboBox* cbox_camera_type = new wxComboBox(p_io, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(150, -1), 0, NULL, wxCB_READONLY); wxComboBox* cbox_audio_out = new wxComboBox(p_audio, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(150, -1), 0, NULL, wxCB_READONLY); wxComboBox* cbox_hle_loglvl = new wxComboBox(p_misc, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(150, -1), 0, NULL, wxCB_READONLY); wxComboBox* cbox_net_status = new wxComboBox(p_networking, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY); wxComboBox* cbox_net_interface = new wxComboBox(p_networking, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY); wxComboBox* cbox_sys_lang = new wxComboBox(p_system, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY); wxCheckBox* chbox_core_llvm_exclud = new wxCheckBox(p_core, wxID_ANY, "Compiled blocks exclusion"); wxCheckBox* chbox_core_hook_stfunc = new wxCheckBox(p_core, wxID_ANY, "Hook static functions"); wxCheckBox* chbox_core_load_liblv2 = new wxCheckBox(p_core, wxID_ANY, "Load liblv2.sprx"); wxCheckBox* chbox_gs_log_prog = new wxCheckBox(p_graphics, wxID_ANY, "Log shader programs"); wxCheckBox* chbox_gs_dump_depth = new wxCheckBox(p_graphics, wxID_ANY, "Write Depth Buffer"); wxCheckBox* chbox_gs_dump_color = new wxCheckBox(p_graphics, wxID_ANY, "Write Color Buffers"); wxCheckBox* chbox_gs_read_color = new wxCheckBox(p_graphics, wxID_ANY, "Read Color Buffers"); wxCheckBox* chbox_gs_read_depth = new wxCheckBox(p_graphics, wxID_ANY, "Read Depth Buffer"); wxCheckBox* chbox_gs_vsync = new wxCheckBox(p_graphics, wxID_ANY, "VSync"); wxCheckBox* chbox_gs_debug_output = new wxCheckBox(p_graphics, wxID_ANY, "Debug Output"); wxCheckBox* chbox_gs_3dmonitor = new wxCheckBox(p_graphics, wxID_ANY, "3D Monitor"); wxCheckBox* chbox_gs_overlay = new wxCheckBox(p_graphics, wxID_ANY, "Debug overlay"); wxCheckBox* chbox_audio_dump = new wxCheckBox(p_audio, wxID_ANY, "Dump to file"); wxCheckBox* chbox_audio_conv = new wxCheckBox(p_audio, wxID_ANY, "Convert to 16 bit"); wxCheckBox* chbox_hle_logging = new wxCheckBox(p_misc, wxID_ANY, "Log everything"); wxCheckBox* chbox_rsx_logging = new wxCheckBox(p_misc, wxID_ANY, "RSX Logging"); wxCheckBox* chbox_hle_savetty = new wxCheckBox(p_misc, wxID_ANY, "Save TTY output to file"); wxCheckBox* chbox_hle_exitonstop = new wxCheckBox(p_misc, wxID_ANY, "Exit RPCS3 when process finishes"); wxCheckBox* chbox_hle_always_start = new wxCheckBox(p_misc, wxID_ANY, "Always start after boot"); wxCheckBox* chbox_hle_use_default_ini = new wxCheckBox(p_misc, wxID_ANY, "Use default configuration"); wxTextCtrl* txt_dbg_range_min = new wxTextCtrl(p_core, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(55, 20)); wxTextCtrl* txt_dbg_range_max = new wxTextCtrl(p_core, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(55, 20)); wxTextCtrl* txt_llvm_threshold = new wxTextCtrl(p_core, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(55, 20)); //Auto Pause wxCheckBox* chbox_dbg_ap_systemcall = new wxCheckBox(p_misc, wxID_ANY, "Auto Pause at System Call"); wxCheckBox* chbox_dbg_ap_functioncall = new wxCheckBox(p_misc, wxID_ANY, "Auto Pause at Function Call"); //Custom EmulationDir wxCheckBox* chbox_emulationdir_enable = new wxCheckBox(p_system, wxID_ANY, "Use path below as EmulationDir. (Restart required)"); wxTextCtrl* txt_emulationdir_path = new wxTextCtrl(p_system, wxID_ANY, Emu.GetEmulatorPath()); wxArrayString ppu_decoder_modes; ppu_decoder_modes.Add("Interpreter"); ppu_decoder_modes.Add("Interpreter 2"); ppu_decoder_modes.Add("Recompiler (LLVM)"); rbox_ppu_decoder = new wxRadioBox(p_core, wxID_ANY, "PPU Decoder", wxDefaultPosition, wxSize(215, -1), ppu_decoder_modes, 1); #if !defined(LLVM_AVAILABLE) rbox_ppu_decoder->Enable(2, false); #endif wxArrayString spu_decoder_modes; spu_decoder_modes.Add("Interpreter (precise)"); spu_decoder_modes.Add("Interpreter (fast)"); spu_decoder_modes.Add("Recompiler (ASMJIT)"); rbox_spu_decoder = new wxRadioBox(p_core, wxID_ANY, "SPU Decoder", wxDefaultPosition, wxSize(215, -1), spu_decoder_modes, 1); cbox_gs_render->Append("Null"); cbox_gs_render->Append("OpenGL"); #ifdef _WIN32 Microsoft::WRL::ComPtr<IDXGIFactory4> dxgiFactory; Microsoft::WRL::ComPtr<IDXGIAdapter> adapter; if (SUCCEEDED(CreateDXGIFactory(IID_PPV_ARGS(&dxgiFactory)))) { cbox_gs_render->Append("DirectX 12"); for (uint id = 0; dxgiFactory->EnumAdapters(id, adapter.GetAddressOf()) != DXGI_ERROR_NOT_FOUND; id++) { DXGI_ADAPTER_DESC adapterDesc; adapter->GetDesc(&adapterDesc); cbox_gs_d3d_adaptater->Append(adapterDesc.Description); } } else { cbox_gs_d3d_adaptater->Enable(false); chbox_gs_overlay->Enable(false); } #endif for (int i = 1; i < WXSIZEOF(ResolutionTable); ++i) { cbox_gs_resolution->Append(wxString::Format("%dx%d", ResolutionTable[i].width.value(), ResolutionTable[i].height.value())); } cbox_gs_aspect->Append("4:3"); cbox_gs_aspect->Append("16:9"); for (auto item : { "Off", "50", "59.94", "30", "60", "Auto" }) cbox_gs_frame_limit->Append(item); cbox_pad_handler->Append("Null"); cbox_pad_handler->Append("Windows"); #if defined (_WIN32) cbox_pad_handler->Append("XInput"); #endif //cbox_pad_handler->Append("DirectInput"); cbox_keyboard_handler->Append("Null"); cbox_keyboard_handler->Append("Windows"); //cbox_keyboard_handler->Append("DirectInput"); cbox_mouse_handler->Append("Null"); cbox_mouse_handler->Append("Windows"); //cbox_mouse_handler->Append("DirectInput"); cbox_audio_out->Append("Null"); cbox_audio_out->Append("OpenAL"); #if defined (_WIN32) cbox_audio_out->Append("XAudio2"); #endif cbox_camera->Append("Null"); cbox_camera->Append("Connected"); cbox_camera_type->Append("Unknown"); cbox_camera_type->Append("EyeToy"); cbox_camera_type->Append("PlayStation Eye"); cbox_camera_type->Append("USB Video Class 1.1"); cbox_hle_loglvl->Append("All"); cbox_hle_loglvl->Append("Warnings"); cbox_hle_loglvl->Append("Success"); cbox_hle_loglvl->Append("Errors"); cbox_hle_loglvl->Append("Nothing"); cbox_net_status->Append("IP Obtained"); cbox_net_status->Append("Obtaining IP"); cbox_net_status->Append("Connecting"); cbox_net_status->Append("Disconnected"); for(const auto& adapterName : GetAdapters()) cbox_net_interface->Append(adapterName); static wxString s_langs[] = { "Japanese", "English (US)", "French", "Spanish", "German", "Italian", "Dutch", "Portuguese (PT)", "Russian", "Korean", "Chinese (Trad.)", "Chinese (Simp.)", "Finnish", "Swedish", "Danish", "Norwegian", "Polish", "English (UK)" }; for (const auto& lang : s_langs) cbox_sys_lang->Append(lang); chbox_core_llvm_exclud->SetValue(cfg->core.llvm.exclusion_range.value()); chbox_gs_log_prog->SetValue(rpcs3::config.rsx.log_programs.value()); chbox_gs_dump_depth->SetValue(cfg->rsx.opengl.write_depth_buffer.value()); chbox_gs_dump_color->SetValue(cfg->rsx.opengl.write_color_buffers.value()); chbox_gs_read_color->SetValue(cfg->rsx.opengl.read_color_buffers.value()); chbox_gs_read_depth->SetValue(cfg->rsx.opengl.read_depth_buffer.value()); chbox_gs_vsync->SetValue(rpcs3::config.rsx.vsync.value()); chbox_gs_debug_output->SetValue(cfg->rsx.d3d12.debug_output.value()); chbox_gs_3dmonitor->SetValue(rpcs3::config.rsx._3dtv.value()); chbox_gs_overlay->SetValue(cfg->rsx.d3d12.overlay.value()); chbox_audio_dump->SetValue(rpcs3::config.audio.dump_to_file.value()); chbox_audio_conv->SetValue(rpcs3::config.audio.convert_to_u16.value()); chbox_hle_logging->SetValue(rpcs3::config.misc.log.hle_logging.value()); chbox_rsx_logging->SetValue(rpcs3::config.misc.log.rsx_logging.value()); chbox_hle_savetty->SetValue(rpcs3::config.misc.log.save_tty.value()); chbox_hle_exitonstop->SetValue(rpcs3::config.misc.exit_on_stop.value()); chbox_hle_always_start->SetValue(rpcs3::config.misc.always_start.value()); chbox_hle_use_default_ini->SetValue(rpcs3::config.misc.use_default_ini.value()); chbox_core_hook_stfunc->SetValue(cfg->core.hook_st_func.value()); chbox_core_load_liblv2->SetValue(cfg->core.load_liblv2.value()); //Auto Pause related chbox_dbg_ap_systemcall->SetValue(rpcs3::config.misc.debug.auto_pause_syscall.value()); chbox_dbg_ap_functioncall->SetValue(rpcs3::config.misc.debug.auto_pause_func_call.value()); //Custom EmulationDir chbox_emulationdir_enable->SetValue(rpcs3::config.system.emulation_dir_path_enable.value()); txt_emulationdir_path->SetValue(rpcs3::config.system.emulation_dir_path.value()); rbox_ppu_decoder->SetSelection((int)cfg->core.ppu_decoder.value()); txt_dbg_range_min->SetValue(cfg->core.llvm.min_id.string_value()); txt_dbg_range_max->SetValue(cfg->core.llvm.max_id.string_value()); txt_llvm_threshold->SetValue(cfg->core.llvm.threshold.string_value()); rbox_spu_decoder->SetSelection((int)cfg->core.spu_decoder.value()); cbox_gs_render->SetSelection((int)cfg->rsx.renderer.value()); cbox_gs_d3d_adaptater->SetSelection(cfg->rsx.d3d12.adaptater.value()); cbox_gs_resolution->SetSelection(ResolutionIdToNum((int)cfg->rsx.resolution.value()) - 1); cbox_gs_aspect->SetSelection((int)cfg->rsx.aspect_ratio.value() - 1); cbox_gs_frame_limit->SetSelection((int)cfg->rsx.frame_limit.value()); cbox_pad_handler->SetSelection((int)cfg->io.pad_handler_mode.value()); cbox_keyboard_handler->SetSelection((int)cfg->io.keyboard_handler_mode.value()); cbox_mouse_handler->SetSelection((int)cfg->io.mouse_handler_mode.value()); cbox_audio_out->SetSelection((int)cfg->audio.out.value()); cbox_camera->SetSelection((int)cfg->io.camera.value()); cbox_camera_type->SetSelection((int)cfg->io.camera_type.value()); cbox_hle_loglvl->SetSelection((int)rpcs3::config.misc.log.level.value()); cbox_net_status->SetSelection((int)rpcs3::config.misc.net.status.value()); cbox_net_interface->SetSelection((int)rpcs3::config.misc.net._interface.value()); cbox_sys_lang->SetSelection((int)rpcs3::config.system.language.value()); // Core s_round_llvm->Add(chbox_core_llvm_exclud, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_llvm_range->Add(txt_dbg_range_min, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_llvm_range->Add(txt_dbg_range_max, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_llvm->Add(s_round_llvm_range, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_llvm_threshold->Add(txt_llvm_threshold, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_llvm->Add(s_round_llvm_threshold, wxSizerFlags().Border(wxALL, 5).Expand()); // Rendering s_round_gs_render->Add(cbox_gs_render, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_gs_d3d_adaptater->Add(cbox_gs_d3d_adaptater, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_gs_res->Add(cbox_gs_resolution, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_gs_aspect->Add(cbox_gs_aspect, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_gs_frame_limit->Add(cbox_gs_frame_limit, wxSizerFlags().Border(wxALL, 5).Expand()); // Input/Output s_round_io_pad_handler->Add(cbox_pad_handler, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_io_keyboard_handler->Add(cbox_keyboard_handler, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_io_mouse_handler->Add(cbox_mouse_handler, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_io_camera->Add(cbox_camera, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_io_camera_type->Add(cbox_camera_type, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_audio_out->Add(cbox_audio_out, wxSizerFlags().Border(wxALL, 5).Expand()); // Miscellaneous s_round_hle_log_lvl->Add(cbox_hle_loglvl, wxSizerFlags().Border(wxALL, 5).Expand()); // Networking s_round_net_status->Add(cbox_net_status, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_net_interface->Add(cbox_net_interface, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_sys_lang->Add(cbox_sys_lang, wxSizerFlags().Border(wxALL, 5).Expand()); // Core s_subpanel_core1->Add(rbox_ppu_decoder, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_core2->Add(rbox_spu_decoder, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_core1->Add(s_round_llvm, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_core1->Add(chbox_core_hook_stfunc, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_core1->Add(chbox_core_load_liblv2, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_core->Add(s_subpanel_core1); s_subpanel_core->Add(s_subpanel_core2); // Graphics s_subpanel_graphics1->Add(s_round_gs_render, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_graphics1->Add(s_round_gs_res, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_graphics1->Add(s_round_gs_d3d_adaptater, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_graphics1->Add(chbox_gs_dump_color, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_graphics1->Add(chbox_gs_read_color, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_graphics1->Add(chbox_gs_dump_depth, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_graphics1->Add(chbox_gs_read_depth, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_graphics1->Add(chbox_gs_vsync, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_graphics2->Add(s_round_gs_aspect, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_graphics2->Add(s_round_gs_frame_limit, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_graphics2->AddSpacer(68); s_subpanel_graphics2->Add(chbox_gs_debug_output, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_graphics2->Add(chbox_gs_3dmonitor, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_graphics2->Add(chbox_gs_overlay, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_graphics2->Add(chbox_gs_log_prog, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_graphics->Add(s_subpanel_graphics1); s_subpanel_graphics->Add(s_subpanel_graphics2); // Input - Output s_subpanel_io1->Add(s_round_io_pad_handler, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_io1->Add(s_round_io_keyboard_handler, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_io1->Add(s_round_io_mouse_handler, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_io2->Add(s_round_io_camera, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_io2->Add(s_round_io_camera_type, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_io->Add(s_subpanel_io1); s_subpanel_io->Add(s_subpanel_io2); // Audio s_subpanel_audio->Add(s_round_audio_out, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_audio->Add(chbox_audio_dump, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_audio->Add(chbox_audio_conv, wxSizerFlags().Border(wxALL, 5).Expand()); // Miscellaneous s_subpanel_misc->Add(s_round_hle_log_lvl, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_misc->Add(chbox_hle_logging, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_misc->Add(chbox_rsx_logging, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_misc->Add(chbox_hle_savetty, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_misc->Add(chbox_hle_exitonstop, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_misc->Add(chbox_hle_always_start, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_misc->Add(chbox_hle_use_default_ini, wxSizerFlags().Border(wxALL, 5).Expand()); // Auto Pause s_subpanel_misc->Add(chbox_dbg_ap_systemcall, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_misc->Add(chbox_dbg_ap_functioncall, wxSizerFlags().Border(wxALL, 5).Expand()); // Networking s_subpanel_networking->Add(s_round_net_status, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_networking->Add(s_round_net_interface, wxSizerFlags().Border(wxALL, 5).Expand()); // System s_subpanel_system->Add(s_round_sys_lang, wxSizerFlags().Border(wxALL, 5).Expand()); // Custom EmulationDir s_subpanel_system->Add(chbox_emulationdir_enable, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_system->Add(txt_emulationdir_path, wxSizerFlags().Border(wxALL, 5).Expand()); // Buttons wxBoxSizer* s_b_panel(new wxBoxSizer(wxHORIZONTAL)); s_b_panel->Add(new wxButton(this, wxID_OK), wxSizerFlags().Border(wxALL, 5).Bottom()); s_b_panel->Add(new wxButton(this, wxID_CANCEL), wxSizerFlags().Border(wxALL, 5).Bottom()); // Resize panels SetSizerAndFit(s_subpanel_core, false); SetSizerAndFit(s_subpanel_graphics, false); SetSizerAndFit(s_subpanel_io, false); SetSizerAndFit(s_subpanel_audio, false); SetSizerAndFit(s_subpanel_misc, false); SetSizerAndFit(s_subpanel_networking, false); SetSizerAndFit(s_subpanel_system, false); SetSizerAndFit(s_b_panel, false); SetSize(width + 26, height + 80); if (ShowModal() == wxID_OK) { long llvmthreshold; long minllvmid, maxllvmid; txt_dbg_range_min->GetValue().ToLong(&minllvmid); txt_dbg_range_max->GetValue().ToLong(&maxllvmid); txt_llvm_threshold->GetValue().ToLong(&llvmthreshold); // individual settings cfg->core.ppu_decoder = rbox_ppu_decoder->GetSelection(); cfg->core.llvm.exclusion_range = chbox_core_llvm_exclud->GetValue(); cfg->core.llvm.min_id = minllvmid; cfg->core.llvm.max_id = maxllvmid; cfg->core.llvm.threshold = llvmthreshold; cfg->core.spu_decoder = rbox_spu_decoder->GetSelection(); cfg->core.hook_st_func = chbox_core_hook_stfunc->GetValue(); cfg->core.load_liblv2 = chbox_core_load_liblv2->GetValue(); cfg->rsx.renderer = cbox_gs_render->GetSelection(); cfg->rsx.d3d12.adaptater = cbox_gs_d3d_adaptater->GetSelection(); cfg->rsx.resolution = ResolutionNumToId(cbox_gs_resolution->GetSelection() + 1); cfg->rsx.aspect_ratio = cbox_gs_aspect->GetSelection() + 1; cfg->rsx.frame_limit = cbox_gs_frame_limit->GetSelection(); cfg->rsx.opengl.write_depth_buffer = chbox_gs_dump_depth->GetValue(); cfg->rsx.opengl.write_color_buffers = chbox_gs_dump_color->GetValue(); cfg->rsx.opengl.read_color_buffers = chbox_gs_read_color->GetValue(); cfg->rsx.opengl.read_depth_buffer = chbox_gs_read_depth->GetValue(); cfg->audio.out = cbox_audio_out->GetSelection(); cfg->io.pad_handler_mode = cbox_pad_handler->GetSelection(); cfg->io.keyboard_handler_mode = cbox_keyboard_handler->GetSelection(); cfg->io.mouse_handler_mode = cbox_mouse_handler->GetSelection(); cfg->io.camera = cbox_camera->GetSelection(); cfg->io.camera_type = cbox_camera_type->GetSelection(); // global settings rpcs3::config.rsx.log_programs = chbox_gs_log_prog->GetValue(); rpcs3::config.rsx.vsync = chbox_gs_vsync->GetValue(); rpcs3::config.rsx._3dtv = chbox_gs_3dmonitor->GetValue(); rpcs3::config.rsx.d3d12.debug_output = chbox_gs_debug_output->GetValue(); rpcs3::config.rsx.d3d12.overlay = chbox_gs_overlay->GetValue(); rpcs3::config.audio.dump_to_file = chbox_audio_dump->GetValue(); rpcs3::config.audio.convert_to_u16 = chbox_audio_conv->GetValue(); rpcs3::config.misc.log.level = cbox_hle_loglvl->GetSelection(); rpcs3::config.misc.log.hle_logging = chbox_hle_logging->GetValue(); rpcs3::config.misc.log.rsx_logging = chbox_rsx_logging->GetValue(); rpcs3::config.misc.log.save_tty = chbox_hle_savetty->GetValue(); rpcs3::config.misc.net.status = cbox_net_status->GetSelection(); rpcs3::config.misc.net._interface = cbox_net_interface->GetSelection(); rpcs3::config.misc.debug.auto_pause_syscall = chbox_dbg_ap_systemcall->GetValue(); rpcs3::config.misc.debug.auto_pause_func_call = chbox_dbg_ap_functioncall->GetValue(); rpcs3::config.misc.always_start = chbox_hle_always_start->GetValue(); rpcs3::config.misc.exit_on_stop = chbox_hle_exitonstop->GetValue(); rpcs3::config.misc.use_default_ini = chbox_hle_use_default_ini->GetValue(); rpcs3::config.system.language = cbox_sys_lang->GetSelection(); rpcs3::config.system.emulation_dir_path_enable = chbox_emulationdir_enable->GetValue(); rpcs3::config.system.emulation_dir_path = txt_emulationdir_path->GetValue().ToStdString(); rpcs3::config.save(); cfg->save(); } if (was_running) Emu.Resume(); }
_Use_decl_annotations_ std::shared_ptr<IEffect> DGSLEffectFactory::Impl::CreateEffect( DGSLEffectFactory* factory, const DGSLEffectFactory::EffectInfo& info, ID3D11DeviceContext* deviceContext ) { if ( mSharing && info.name && *info.name ) { if ( info.enableSkinning ) { auto it = mEffectCacheSkinning.find( info.name ); if ( it != mEffectCacheSkinning.end() ) { return it->second; } } else { auto it = mEffectCache.find( info.name ); if ( it != mEffectCache.end() ) { return it->second; } } } std::shared_ptr<DGSLEffect> effect = std::make_shared<DGSLEffect>( device.Get(), nullptr, info.enableSkinning ); effect->EnableDefaultLighting(); effect->SetLightingEnabled(true); XMVECTOR color = XMLoadFloat3( &info.ambientColor ); effect->SetAmbientColor( color ); color = XMLoadFloat3( &info.diffuseColor ); effect->SetDiffuseColor( color ); effect->SetAlpha( info.alpha ); if ( info.perVertexColor ) { effect->SetVertexColorEnabled( true ); } if ( info.specularColor.x != 0 || info.specularColor.y != 0 || info.specularColor.z != 0 ) { color = XMLoadFloat3( &info.specularColor ); effect->SetSpecularColor( color ); effect->SetSpecularPower( info.specularPower ); } if ( info.emissiveColor.x != 0 || info.emissiveColor.y != 0 || info.emissiveColor.z != 0 ) { color = XMLoadFloat3( &info.emissiveColor ); effect->SetEmissiveColor( color ); } if ( info.texture && *info.texture ) { Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> srv; factory->CreateTexture( info.texture, deviceContext, srv.GetAddressOf() ); effect->SetTexture( srv.Get() ); effect->SetTextureEnabled(true); } if ( mSharing && info.name && *info.name ) { std::lock_guard<std::mutex> lock(mutex); if ( info.enableSkinning ) { mEffectCacheSkinning.insert( EffectCache::value_type( info.name, effect ) ); } else { mEffectCache.insert( EffectCache::value_type( info.name, effect ) ); } } return effect; }
_Use_decl_annotations_ std::shared_ptr<IEffect> DGSLEffectFactory::Impl::CreateDGSLEffect( DGSLEffectFactory* factory, const DGSLEffectFactory::DGSLEffectInfo& info, ID3D11DeviceContext* deviceContext ) { if ( mSharing && info.name && *info.name ) { if ( info.enableSkinning ) { auto it = mEffectCacheSkinning.find( info.name ); if ( it != mEffectCacheSkinning.end() ) { return it->second; } } else { auto it = mEffectCache.find( info.name ); if ( it != mEffectCache.end() ) { return it->second; } } } std::shared_ptr<DGSLEffect> effect; bool lighting = true; bool allowSpecular = true; if ( !info.pixelShader || !*info.pixelShader ) { effect = std::make_shared<DGSLEffect>( device.Get(), nullptr, info.enableSkinning ); } else { wchar_t root[ MAX_PATH ] = {0}; auto last = wcsrchr( info.pixelShader, '_' ); if ( last ) { wcscpy_s( root, last+1 ); } else { wcscpy_s( root, info.pixelShader ); } auto first = wcschr( root, '.' ); if ( first ) *first = 0; if ( !_wcsicmp( root, L"lambert" ) ) { allowSpecular = false; effect = std::make_shared<DGSLEffect>( device.Get(), nullptr, info.enableSkinning ); } else if ( !_wcsicmp( root, L"phong" ) ) { effect = std::make_shared<DGSLEffect>( device.Get(), nullptr, info.enableSkinning ); } else if ( !_wcsicmp( root, L"unlit" ) ) { lighting = false; effect = std::make_shared<DGSLEffect>( device.Get(), nullptr, info.enableSkinning ); } else if ( device->GetFeatureLevel() < D3D_FEATURE_LEVEL_10_0 ) { // DGSL shaders are not compatible with Feature Level 9.x, use fallback shader wcscat_s( root, L".cso" ); Microsoft::WRL::ComPtr<ID3D11PixelShader> ps; factory->CreatePixelShader( root, ps.GetAddressOf() ); effect = std::make_shared<DGSLEffect>( device.Get(), ps.Get(), info.enableSkinning ); } else { // Create DGSL shader and use it for the effect Microsoft::WRL::ComPtr<ID3D11PixelShader> ps; factory->CreatePixelShader( info.pixelShader, ps.GetAddressOf() ); effect = std::make_shared<DGSLEffect>( device.Get(), ps.Get(), info.enableSkinning ); } } if ( lighting ) { effect->EnableDefaultLighting(); effect->SetLightingEnabled(true); } XMVECTOR color = XMLoadFloat3( &info.ambientColor ); effect->SetAmbientColor( color ); color = XMLoadFloat3( &info.diffuseColor ); effect->SetDiffuseColor( color ); effect->SetAlpha( info.alpha ); if ( info.perVertexColor ) { effect->SetVertexColorEnabled( true ); } effect->SetAlphaDiscardEnable(true); if ( allowSpecular && ( info.specularColor.x != 0 || info.specularColor.y != 0 || info.specularColor.z != 0 ) ) { color = XMLoadFloat3( &info.specularColor ); effect->SetSpecularColor( color ); effect->SetSpecularPower( info.specularPower ); } else { effect->DisableSpecular(); } if ( info.emissiveColor.x != 0 || info.emissiveColor.y != 0 || info.emissiveColor.z != 0 ) { color = XMLoadFloat3( &info.emissiveColor ); effect->SetEmissiveColor( color ); } if ( info.texture && *info.texture ) { Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> srv; factory->CreateTexture( info.texture, deviceContext, srv.GetAddressOf() ); effect->SetTexture( srv.Get() ); effect->SetTextureEnabled(true); } for( int j = 0; j < 7; ++j ) { if ( info.textures[j] && *info.textures[j] ) { Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> srv; factory->CreateTexture( info.textures[j], deviceContext, srv.GetAddressOf() ); effect->SetTexture( j+1, srv.Get() ); effect->SetTextureEnabled(true); } } if ( mSharing && info.name && *info.name ) { std::lock_guard<std::mutex> lock(mutex); if ( info.enableSkinning ) { mEffectCacheSkinning.insert( EffectCache::value_type( info.name, effect ) ); } else { mEffectCache.insert( EffectCache::value_type( info.name, effect ) ); } } return effect; }
struct PixelInput \n { \n float4 Pos : SV_POSITION; \n float2 TexCoords : TEXCOORDS0; \n }; \n float4 main(PixelInput In) : SV_TARGET \n { \n return InputTexture.Sample(bilinearSampler, In.TexCoords); \n } ); Microsoft::WRL::ComPtr<ID3DBlob> fsBytecode; Microsoft::WRL::ComPtr<ID3DBlob> errorBlob; CHECK_HRESULT(wrapD3DCompile(fsCode, strlen(fsCode), "test", nullptr, nullptr, "main", "ps_5_0", 0, 0, &fsBytecode, errorBlob.GetAddressOf())); const char *vsCode = STRINGIFY( struct VertexInput \n { \n float2 Pos : POSITION; \n float2 TexCoords : TEXCOORDS0; \n }; \n struct PixelInput \n { \n float4 Pos : SV_POSITION; \n float2 TexCoords : TEXCOORDS0; \n }; \n PixelInput main(VertexInput In) \n
DWRITE_TEXT_METRICS TextFormatD2D::GetMetrics( const WCHAR* str, UINT strLen, bool gdiEmulation, float maxWidth) { // GDI+ compatibility: If the last character is a newline, GDI+ measurements seem to ignore it. bool strippedLastNewLine = false; if (strLen > 2 && str[strLen - 1] == L'\n') { strippedLastNewLine = true; --strLen; if (str[strLen - 1] == L'\r') { --strLen; } } DWRITE_TEXT_METRICS metrics = {0}; Microsoft::WRL::ComPtr<IDWriteTextLayout> textLayout; HRESULT hr = CanvasD2D::c_DWFactory->CreateTextLayout( str, strLen, m_TextFormat.Get(), maxWidth, 10000, textLayout.GetAddressOf()); if (SUCCEEDED(hr)) { const float xOffset = m_TextFormat->GetFontSize() / 6.0f; if (gdiEmulation) { Microsoft::WRL::ComPtr<IDWriteTextLayout1> textLayout1; textLayout.As(&textLayout1); const float emOffset = xOffset / 24.0f; const DWRITE_TEXT_RANGE range = {0, strLen}; textLayout1->SetCharacterSpacing(emOffset, emOffset, 0.0f, range); } textLayout->GetMetrics(&metrics); if (metrics.width > 0.0f) { if (gdiEmulation) { metrics.width += xOffset * 2; metrics.height += m_ExtraHeight; // GDI+ compatibility: If the string contains a newline (even if it is the // stripped last character), GDI+ adds the line gap to the overall height. if (strippedLastNewLine || wmemchr(str, L'\n', strLen) != nullptr) { metrics.height += m_LineGap; } } else { // GDI+ compatibility: With accurate metrics, the line gap needs to be subtracted // from the overall height if the string does not contain newlines. if (!strippedLastNewLine && wmemchr(str, L'\n', strLen) == nullptr) { metrics.height -= m_LineGap; } } } else { // GDI+ compatibility: Get rid of the height that DirectWrite assigns to zero-width // strings. metrics.height = 0.0f; } } return metrics; }
void TextFormatD2D::SetProperties( const WCHAR* fontFamily, int size, bool bold, bool italic, const FontCollection* fontCollection) { auto fontCollectionD2D = (FontCollectionD2D*)fontCollection; Dispose(); WCHAR dwriteFamilyName[LF_FACESIZE]; DWRITE_FONT_WEIGHT dwriteFontWeight = bold ? DWRITE_FONT_WEIGHT_BOLD : DWRITE_FONT_WEIGHT_REGULAR; DWRITE_FONT_STYLE dwriteFontStyle = italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL; DWRITE_FONT_STRETCH dwriteFontStretch = DWRITE_FONT_STRETCH_NORMAL; const float dwriteFontSize = size * (4.0f / 3.0f); // |fontFamily| uses the GDI/GDI+ font naming convention so try to create DirectWrite font // using the GDI family name and then create a text format using the DirectWrite family name // obtained from it. HRESULT hr = Util::GetDWritePropertiesFromGDIProperties( CanvasD2D::c_DWFactory.Get(), fontFamily, bold, italic, dwriteFontWeight, dwriteFontStyle, dwriteFontStretch, dwriteFamilyName, _countof(dwriteFamilyName)); if (SUCCEEDED(hr)) { hr = CanvasD2D::c_DWFactory->CreateTextFormat( dwriteFamilyName, nullptr, dwriteFontWeight, dwriteFontStyle, dwriteFontStretch, dwriteFontSize, L"", &m_TextFormat); } if (FAILED(hr)) { IDWriteFontCollection* dwriteFontCollection = nullptr; // If |fontFamily| is not in the system collection, use the font collection from // |fontCollectionD2D| if possible. if (!Util::IsFamilyInSystemFontCollection(CanvasD2D::c_DWFactory.Get(), fontFamily) && (fontCollectionD2D && fontCollectionD2D->InitializeCollection())) { IDWriteFont* dwriteFont = Util::FindDWriteFontInFontCollectionByGDIFamilyName( fontCollectionD2D->m_Collection, fontFamily); if (dwriteFont) { hr = Util::GetFamilyNameFromDWriteFont( dwriteFont, dwriteFamilyName, _countof(dwriteFamilyName)); if (SUCCEEDED(hr)) { fontFamily = dwriteFamilyName; Util::GetPropertiesFromDWriteFont( dwriteFont, bold, italic, &dwriteFontWeight, &dwriteFontStyle, &dwriteFontStretch); } dwriteFont->Release(); } dwriteFontCollection = fontCollectionD2D->m_Collection; } // Fallback in case above fails. hr = CanvasD2D::c_DWFactory->CreateTextFormat( fontFamily, dwriteFontCollection, dwriteFontWeight, dwriteFontStyle, dwriteFontStretch, dwriteFontSize, L"", &m_TextFormat); } if (SUCCEEDED(hr)) { SetHorizontalAlignment(GetHorizontalAlignment()); SetVerticalAlignment(GetVerticalAlignment()); // Get the family name to in case CreateTextFormat() fallbacked on some other family name. hr = m_TextFormat->GetFontFamilyName(dwriteFamilyName, _countof(dwriteFamilyName)); if (FAILED(hr)) return; Microsoft::WRL::ComPtr<IDWriteFontCollection> collection; Microsoft::WRL::ComPtr<IDWriteFontFamily> fontFamily; UINT32 familyNameIndex; BOOL exists; if (FAILED(m_TextFormat->GetFontCollection(collection.GetAddressOf())) || FAILED(collection->FindFamilyName(dwriteFamilyName, &familyNameIndex, &exists)) || FAILED(collection->GetFontFamily(familyNameIndex, fontFamily.GetAddressOf()))) { return; } Microsoft::WRL::ComPtr<IDWriteFont> font; hr = fontFamily->GetFirstMatchingFont( m_TextFormat->GetFontWeight(), m_TextFormat->GetFontStretch(), m_TextFormat->GetFontStyle(), font.GetAddressOf()); if (FAILED(hr)) return; DWRITE_FONT_METRICS fmetrics; font->GetMetrics(&fmetrics); // GDI+ compatibility: GDI+ adds extra padding below the string when |m_AccurateText| is // |false|. The bottom padding seems to be based on the font metrics so we can calculate it // once and keep using it regardless of the actual string. In some cases, GDI+ also adds // the line gap to the overall height so we will store it as well. const float pixelsPerDesignUnit = dwriteFontSize / (float)fmetrics.designUnitsPerEm; m_ExtraHeight = (((float)fmetrics.designUnitsPerEm / 8.0f) - fmetrics.lineGap) * pixelsPerDesignUnit; m_LineGap = fmetrics.lineGap * pixelsPerDesignUnit; } else { Dispose(); } }
void CanvasD2D::DrawMaskedBitmap(Gdiplus::Bitmap* bitmap, Gdiplus::Bitmap* maskBitmap, const Gdiplus::Rect& dstRect, const Gdiplus::Rect& srcRect, const Gdiplus::Rect& srcRect2) { if (!BeginTargetDraw()) return; auto rDst = ToRectF(dstRect); auto rSrc = ToRectF(srcRect); Util::WICBitmapLockGDIP* bitmapLock = new Util::WICBitmapLockGDIP(); Gdiplus::Rect lockRect(srcRect2); Gdiplus::Status status = bitmap->LockBits( &lockRect, Gdiplus::ImageLockModeRead, PixelFormat32bppPARGB, bitmapLock->GetBitmapData()); if (status == Gdiplus::Ok) { D2D1_BITMAP_PROPERTIES props = D2D1::BitmapProperties( D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED)); Microsoft::WRL::ComPtr<ID2D1Bitmap> d2dBitmap; HRESULT hr = m_Target->CreateSharedBitmap( __uuidof(IWICBitmapLock), bitmapLock, &props, d2dBitmap.GetAddressOf()); if (SUCCEEDED(hr)) { // Create bitmap brush from original |bitmap|. Microsoft::WRL::ComPtr<ID2D1BitmapBrush> brush; D2D1_BITMAP_BRUSH_PROPERTIES propertiesXClampYClamp = D2D1::BitmapBrushProperties( D2D1_EXTEND_MODE_CLAMP, D2D1_EXTEND_MODE_CLAMP, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR); // "Move" and "scale" the |bitmap| to match the destination. D2D1_MATRIX_3X2_F translate = D2D1::Matrix3x2F::Translation(rDst.left, rDst.top); D2D1_MATRIX_3X2_F scale = D2D1::Matrix3x2F::Scale( D2D1::SizeF((rDst.right - rDst.left) / (float)srcRect2.Width, (rDst.bottom - rDst.top) / (float)srcRect2.Height)); D2D1_BRUSH_PROPERTIES brushProps = D2D1::BrushProperties(1.0F, scale * translate); hr = m_Target->CreateBitmapBrush( d2dBitmap.Get(), propertiesXClampYClamp, brushProps, brush.GetAddressOf()); // Load the |maskBitmap| and use the bitmap brush to "fill" its contents. // Note: The image must be aliased when applying the opacity mask. if (SUCCEEDED(hr)) { Util::WICBitmapLockGDIP* maskBitmapLock = new Util::WICBitmapLockGDIP(); Gdiplus::Rect maskLockRect(0, 0, maskBitmap->GetWidth(), maskBitmap->GetHeight()); status = maskBitmap->LockBits( &maskLockRect, Gdiplus::ImageLockModeRead, PixelFormat32bppPARGB, maskBitmapLock->GetBitmapData()); if (status == Gdiplus::Ok) { D2D1_BITMAP_PROPERTIES maskProps = D2D1::BitmapProperties( D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED)); Microsoft::WRL::ComPtr<ID2D1Bitmap> d2dMaskBitmap; hr = m_Target->CreateSharedBitmap( __uuidof(IWICBitmapLock), maskBitmapLock, &props, d2dMaskBitmap.GetAddressOf()); if (SUCCEEDED(hr)) { m_Target->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED); // required m_Target->FillOpacityMask( d2dMaskBitmap.Get(), brush.Get(), D2D1_OPACITY_MASK_CONTENT_GRAPHICS, &rDst, &rSrc); m_Target->SetAntialiasMode(D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); } maskBitmap->UnlockBits(bitmapLock->GetBitmapData()); } maskBitmapLock->Release(); } } bitmap->UnlockBits(bitmapLock->GetBitmapData()); } bitmapLock->Release(); }