public void PreRender(bool invisibilidadActivada)
        {
            Invisibilidad.Technique = "DefaultTechnique";
            pOldRT = D3DDevice.GetRenderTarget(0);
            pSurf  = g_pRenderTarget.GetSurfaceLevel(0);
            if (invisibilidadActivada)
            {
                D3DDevice.SetRenderTarget(0, pSurf);
            }
            pOldDS = D3DDevice.DepthStencilSurface;

            if (invisibilidadActivada)
            {
                D3DDevice.DepthStencilSurface = g_pDepthStencil;
            }

            D3DDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);

            pSurf.Dispose();
        }
예제 #2
0
    /// <summary>
    /// Restore the font after a device has been reset
    /// </summary>
    public void RestoreDeviceObjects(object sender, EventArgs e)
    {
        vertexBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColoredTextured), MaxNumfontVertices,
                                        device, Usage.WriteOnly | Usage.Dynamic, 0, Pool.Default);

        Surface surf = device.GetRenderTarget(0);
        bool    bSupportsAlphaBlend = Manager.CheckDeviceFormat(device.DeviceCaps.AdapterOrdinal,
                                                                device.DeviceCaps.DeviceType, device.DisplayMode.Format,
                                                                Usage.RenderTarget | Usage.QueryPostPixelShaderBlending, ResourceType.Surface,
                                                                surf.Description.Format);

        // Create the state blocks for rendering text
        for (int which = 0; which < 2; which++)
        {
            device.BeginStateBlock();
            device.SetTexture(0, fontTexture);

            if (isZEnable)
            {
                renderState.ZBufferEnable = true;
            }
            else
            {
                renderState.ZBufferEnable = false;
            }

            if (bSupportsAlphaBlend)
            {
                renderState.AlphaBlendEnable = true;
                renderState.SourceBlend      = Blend.SourceAlpha;
                renderState.DestinationBlend = Blend.InvSourceAlpha;
            }
            else
            {
                renderState.AlphaBlendEnable = false;
            }
            renderState.AlphaTestEnable = true;
            renderState.ReferenceAlpha  = 0x08;
            renderState.AlphaFunction   = Compare.GreaterEqual;
            renderState.FillMode        = FillMode.Solid;
            renderState.CullMode        = Cull.CounterClockwise;
            renderState.StencilEnable   = false;
            renderState.Clipping        = true;
            device.ClipPlanes.DisableAll();
            renderState.VertexBlend = VertexBlend.Disable;
            renderState.IndexedVertexBlendEnable = false;
            renderState.FogEnable                = false;
            renderState.ColorWriteEnable         = ColorWriteEnable.RedGreenBlueAlpha;
            textureState0.ColorOperation         = TextureOperation.Modulate;
            textureState0.ColorArgument1         = TextureArgument.TextureColor;
            textureState0.ColorArgument2         = TextureArgument.Diffuse;
            textureState0.AlphaOperation         = TextureOperation.Modulate;
            textureState0.AlphaArgument1         = TextureArgument.TextureColor;
            textureState0.AlphaArgument2         = TextureArgument.Diffuse;
            textureState0.TextureCoordinateIndex = 0;
            textureState0.TextureTransform       = TextureTransform.Disable; // REVIEW
            textureState1.ColorOperation         = TextureOperation.Disable;
            textureState1.AlphaOperation         = TextureOperation.Disable;
            samplerState0.MinFilter              = TextureFilter.Point;
            samplerState0.MagFilter              = TextureFilter.Point;
            samplerState0.MipFilter              = TextureFilter.None;

            if (which == 0)
            {
                savedStateBlock = device.EndStateBlock();
            }
            else
            {
                drawTextStateBlock = device.EndStateBlock();
            }
        }
    }
예제 #3
0
 /// <summary>
 /// Get the surface from the DX3D Device
 /// </summary>
 /// <returns></returns>
 public static Surface GetSurface()
 {
     return(device.GetRenderTarget(0));
 }
예제 #4
0
        public override void Update()
        {
            D3D9RenderSystem rs = (D3D9RenderSystem)Root.Instance.RenderSystem;

            // access device through driver
            D3D.Device device = driver.Device;

            if (rs.DeviceLost)
            {
                log.Info("In D3DRenderWindow.Update, rs.DeviceLost is true");
                // Test the cooperative mode first
                int status;
                device.CheckCooperativeLevel(out status);
                if (status == (int)Microsoft.DirectX.Direct3D.ResultCode.DeviceLost)
                {
                    // device lost, and we can't reset
                    // can't do anything about it here, wait until we get
                    // D3DERR_DEVICENOTRESET; rendering calls will silently fail until
                    // then (except Present, but we ignore device lost there too)
                    // FIXME: Ogre doesn't do these two Dispose calls here.
#if NOT
                    // This code is what Ogre does for this clause, but since
                    // Ogre gets to immediately call release on the renderSurface
                    // and renderZBuffer, this assign of null will end up leaving
                    // the reference count at 0 for them, and will cause them to
                    // be freed.  For the Axiom code, I'm just going to leave them
                    // alone, and do the proper dispose calls in the devicenotreset
                    // clause.

                    renderSurface = null;
                    // need to release if swap chain
                    if (!isSwapChain)
                    {
                        renderZBuffer = null;
                    }
                    else
                    {
                        // Do I need to dispose of the ZBuffer here?
                        // SAFE_RELEASE (mpRenderZBuffer);
                        if (renderZBuffer != null)
                        {
                            renderZBuffer.Dispose();
                            renderZBuffer = null;
                        }
                    }
#endif
                    Thread.Sleep(50);
                    return;
                }
                else
                {
                    if (status != (int)Microsoft.DirectX.Direct3D.ResultCode.Success &&
                        status != (int)Microsoft.DirectX.Direct3D.ResultCode.DeviceNotReset)
                    {
                        // I've encountered some unexpected device state
                        // Ogre would just continue, but I want to make sure I notice this.
                        throw new Exception(string.Format("Unknown Device State: {0}", status));
                    }
                    // FIXME: Ogre doesn't do these two Dispose calls here.
                    if (renderSurface != null)
                    {
                        log.Info("Disposing of render surface");
                        renderSurface.Dispose();
                        renderSurface = null;
                    }
                    if (renderZBuffer != null)
                    {
                        log.Info("Disposing of render zbuffer");
                        renderZBuffer.Dispose();
                        renderZBuffer = null;
                    }

                    log.InfoFormat("In D3DRenderWindow.Update, calling rs.RestoreLostDevice(); status = {0}", status);
                    // device lost, and we can reset
                    rs.RestoreLostDevice();

                    // Still lost?
                    if (rs.DeviceLost)
                    {
                        // Wait a while
                        Thread.Sleep(50);
                        return;
                    }

                    if (!isSwapChain)
                    {
                        log.Info("In D3DRenderWindow.Update, re-querying buffers");
                        // re-qeuery buffers
                        renderSurface = device.GetRenderTarget(0);
                        renderZBuffer = device.DepthStencilSurface;
                        // release immediately so we don't hog them
                        // mpRenderSurface->Release();
                        // mpRenderZBuffer->Release();
                    }
                    else
                    {
                        log.Info("In D3DRenderWindow.Update, isSwapChain is true, changing viewport dimensions");
                        // Update dimensions incase changed
                        foreach (Axiom.Core.Viewport vp in viewportList)
                        {
                            vp.UpdateDimensions();
                        }
                        // Actual restoration of surfaces will happen in
                        // D3D9RenderSystem.RestoreLostDevice when it calls
                        // CreateD3DResources for each secondary window
                    }
                }
            }
            base.Update();
        }