//VertexBuffer mSurfaceVB; //const int NumVertices = 1000; //int mSurfaceVBPointer = 0; //readonly int SurfaceVBSize = NumVertices * CustomVertex.TransformedColoredTextured.StrideSize; public D3DDevice(Device device) { mDevice = device; mWorld2D = Matrix.Identity; //mDevice.DeviceLost += new EventHandler(mDevice_DeviceLost); mDrawBuffer = new DrawBuffer(this); mSurfaceDecl = SDX_VertexBuffer.CreateVertexDeclaration( device, PositionTextureColor.VertexLayout); }
internal void Initialize(SDX_DisplayWindow window, CreateWindowParams windowParams) { if (mInitialized) { return; } if (window.RenderTarget.TopLevelControl == null) { throw new ArgumentException("The specified render target does not have a Form object yet. " + "It's TopLevelControl property is null. You may not create DisplayWindow objects before " + "the control to render to is added to the Form."); } mInitialized = true; // ok, create D3D device PresentParameters present = windowParams.IsFullScreen ? CreateFullScreenPresentParameters(window, windowParams.Width, windowParams.Height, windowParams.Bpp) : CreateWindowedPresentParameters(window, 0, 0, 32); DeviceType dtype = DeviceType.Hardware; int adapterOrdinal = mDirect3Dobject.Adapters.DefaultAdapter.Adapter; var caps = mDirect3Dobject.GetDeviceCaps(adapterOrdinal, Direct3D.DeviceType.Hardware); var flags = Direct3D.CreateFlags.SoftwareVertexProcessing; // Is there support for hardware vertex processing? If so, replace // software vertex processing. if ((caps.DeviceCaps & DeviceCaps.HWTransformAndLight) == DeviceCaps.HWTransformAndLight) { flags = Direct3D.CreateFlags.HardwareVertexProcessing; } // Does the device support a pure device? if ((caps.DeviceCaps & DeviceCaps.PureDevice) == DeviceCaps.PureDevice) { flags |= Direct3D.CreateFlags.PureDevice; } Device device = new Device(mDirect3Dobject, adapterOrdinal, dtype, window.RenderTarget.TopLevelControl.Handle, flags, present); try { Format f = (Format)device.DepthStencilSurface.Description.Format; SetHaveDepthStencil(f); } catch { mHasDepth = true; mHasStencil = false; SetHaveDepthStencil(Format.D16); } //device.DeviceLost += new EventHandler(mDevice_DeviceLost); //device.DeviceReset += new EventHandler(mDevice_DeviceReset); device.SetRenderState(RenderState.StencilEnable, false); device.SetRenderState(RenderState.ZEnable, true); mDevice = new D3DDevice(device); //InitializeShaders(); mPosColorDecl = SDX_VertexBuffer.CreateVertexDeclaration(device, PositionColor.VertexLayout); }