Exemplo n.º 1
0
 private void OnDeviceDestroy()
 {
     if (_device != null)
     {
         Logger.Debug("Direct3D: dispose Device, threadId={0}", Thread.CurrentThread.ManagedThreadId);
         _device.Dispose();
         _device = null;
     }
 }
Exemplo n.º 2
0
 public void LoadResources(Direct3DDevice9 device)
 {
     if (device == null || Texture != null)
     {
         return;
     }
     using (var stream = m_iconDesc.GetImageStream())
     {
         Texture = D3DX9.CreateTextureFromStream(device, stream);
     }
 }
Exemplo n.º 3
0
        public static D3DXFont CreateFont(Direct3DDevice9 device, Font gdiFont)
        {
            var dc         = GetDC(IntPtr.Zero);
            var logPixelsY = GetDeviceCaps(dc, LOGPIXELSY);

            ReleaseDC(IntPtr.Zero, dc);
            var height = (int)((double)gdiFont.Size * (double)logPixelsY / -72d);

            return(D3DX9.CreateFont(
                       device,
                       height,                   // height
                       0,                        // width
                       gdiFont.Bold ? 700 : 400, // weight
                       0,                        // mipLevels
                       gdiFont.Italic,           // italic
                       1,                        // charSet
                       0,                        // outputPrecision
                       0,                        // quality
                       0,                        // pitchAndFamily
                       gdiFont.Name));           // faceName
        }
Exemplo n.º 4
0
        private void OnDeviceCheck()
        {
            if (_device != null)
            {
                return;
            }
            _size  = _window.Size;
            _d3dpp = CreatePresentParams(_window.Handle);

            _monitorId = _window.MonitorId;
            var adapterId = _window.AdapterId;

            using (var d3d = new Direct3D9())
            {
                D3DCAPS9 caps;
                d3d.GetDeviceCaps(adapterId, D3DDEVTYPE.D3DDEVTYPE_HAL, out caps).CheckError();
                var flags = D3DCREATE.D3DCREATE_NOWINDOWCHANGES | D3DCREATE.D3DCREATE_FPU_PRESERVE;// CreateFlags.MultiThreaded;
                if ((caps.DevCaps & D3DDEVCAPS.D3DDEVCAPS_HWTRANSFORMANDLIGHT) != 0)
                {
                    flags |= D3DCREATE.D3DCREATE_HARDWARE_VERTEXPROCESSING;
                }
                else
                {
                    flags |= D3DCREATE.D3DCREATE_SOFTWARE_VERTEXPROCESSING;
                }

                Logger.Debug("Direct3D: create Device, threadId={0}", Thread.CurrentThread.ManagedThreadId);
                _device = d3d.CreateDevice(
                    adapterId,
                    D3DDEVTYPE.D3DDEVTYPE_HAL,
                    _window.Handle,
                    flags,
                    _d3dpp);
            }
            //TODO: check
            //_device.DeviceResizing += (s, e) => e.Cancel = true;
            //_device.DeviceReset += Device_OnDeviceReset;

            OnDeviceInit();
        }