Singleton class which holds all GFX related settings
コード例 #1
0
    public static void RenderFor3DMode(GUIGraphicsContext.eRender3DModeHalf renderModeHalf, float timePassed,
      Surface backbuffer, Surface surface, Rectangle targetRect)
    {
      if (GUIGraphicsContext.Render3DMode != GUIGraphicsContext.eRender3DMode.SideBySideFrom2D ||
          GUIGraphicsContext.Render3DMode == GUIGraphicsContext.eRender3DMode.SideBySideFrom2D &&
          renderModeHalf == GUIGraphicsContext.eRender3DModeHalf.SBSLeft)
      {
        GUIGraphicsContext.DX9Device.SetRenderTarget(0, surface);

        GUIGraphicsContext.DX9Device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);

        GUIGraphicsContext.DX9Device.BeginScene();
        GUIGraphicsContext.SetScalingResolution(0, 0, false);

        GUIGraphicsContext.Render3DModeHalf = renderModeHalf;

        try
        {
          if (!GUIGraphicsContext.BlankScreen)
          {
            // Render GUI + Video surface
            GUIGraphicsContext.RenderGUI.RenderFrame(timePassed, GUILayers.all);
            GUIFontManager.Present();
          }
        }
        finally
        {
          GUIGraphicsContext.DX9Device.EndScene();
        }

        GUIGraphicsContext.DX9Device.SetRenderTarget(0, backbuffer);
      }

      if (GUIGraphicsContext.Render3DMode == GUIGraphicsContext.eRender3DMode.SideBySideFrom2D)
      {
        // render left image for 2D to 3D conversion

        if (renderModeHalf == GUIGraphicsContext.eRender3DModeHalf.SBSLeft)
        {
          GUIGraphicsContext.DX9Device.StretchRectangle(surface,
            new Rectangle(0, 0, backbuffer.Description.Width, backbuffer.Description.Height),
            backbuffer,
            targetRect,
            TextureFilter.Point);

          // if texture for last frame does not exist, then create it

          if (GUIGraphicsContext.LastFrames.Count == 0)
          {
            for (int i = 0; i < 2; i++)
            {
              Texture texture = new Texture(GUIGraphicsContext.DX9Device,
                backbuffer.Description.Width,
                backbuffer.Description.Height, 0, Usage.RenderTarget,
                backbuffer.Description.Format, Pool.Default);

              GUIGraphicsContext.LastFrames.Add(texture);
            }
          }

          // store current image, it will be used as right image for next frame

          Surface surfaceLastFrame = GUIGraphicsContext.LastFrames[GUIGraphicsContext.LastFramesIndex].GetSurfaceLevel(0);

          GUIGraphicsContext.DX9Device.StretchRectangle(surface,
            new Rectangle(0, 0, backbuffer.Description.Width, backbuffer.Description.Height),
            surfaceLastFrame,
            new Rectangle(0, 0, backbuffer.Description.Width, backbuffer.Description.Height),
            TextureFilter.Point);
          surfaceLastFrame.Dispose();
        }
        else
          // render right image of the last frame for 2D to 3D conversion, the difference between 2 frames generates a 3D effect only for moving objects...
        {
          int lastIndex = GUIGraphicsContext.LastFramesIndex - 1;

          if (lastIndex < 0)
            lastIndex = GUIGraphicsContext.LastFrames.Count + lastIndex;

          if (GUIGraphicsContext.LastFrames.Count > 0)
          {
            Surface surfaceLastFrame = GUIGraphicsContext.LastFrames[lastIndex].GetSurfaceLevel(0);

            if (surfaceLastFrame != null)
            {
              // generate additional 3D effect for not moving objects by stretching the right image...

              double xSkewPerLine =
                (double) (GUIGraphicsContext.Convert2Dto3DSkewFactor/1000f*backbuffer.Description.Width)/
                (backbuffer.Description.Height - 1);
              int horzOffset = (int) (xSkewPerLine*backbuffer.Description.Height);

              for (int y = 0; y < backbuffer.Description.Height; y++)
              {
                /*int horzDelta = (int)(xSkewPerLine * (backbuffer.Description.Height - y));

                GUIGraphicsContext.DX9Device.StretchRectangle(surfaceLastFrame,
                              new Rectangle(horzDelta, y, backbuffer.Description.Width - horzDelta * 2, 1),
                              backbuffer,
                              new Rectangle(targetRect.X, y, targetRect.Width, 1),
                              TextureFilter.Point);*/

                int horzDelta = (int) (xSkewPerLine*y);

                GUIGraphicsContext.DX9Device.StretchRectangle(surfaceLastFrame,
                  new Rectangle(horzDelta, y, backbuffer.Description.Width - horzOffset*2 + horzDelta, 1),
                  backbuffer,
                  new Rectangle(targetRect.X, y, targetRect.Width, 1),
                  TextureFilter.Point);
              }

              surfaceLastFrame.Dispose();
            }
          }
        }
      }
      else // render normal 3D movie
      {
        GUIGraphicsContext.DX9Device.StretchRectangle(surface,
          new Rectangle(0, 0, backbuffer.Description.Width, backbuffer.Description.Height),
          backbuffer,
          targetRect,
          TextureFilter.Point);
      }
    }
コード例 #2
0
ファイル: PlaneScene.cs プロジェクト: cmendozac/MediaPortal-1
    public static void RenderFor3DMode(GUIGraphicsContext.eRender3DModeHalf renderModeHalf, float timePassed,
                                       Surface backbuffer, Surface surface, Rectangle targetRect)
    {
      GUIGraphicsContext.DX9Device.SetRenderTarget(0, surface);

      GUIGraphicsContext.DX9Device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);

      GUIGraphicsContext.DX9Device.BeginScene();
      GUIGraphicsContext.SetScalingResolution(0, 0, false);

      GUIGraphicsContext.Render3DModeHalf = renderModeHalf;

      try
      {
        if (!GUIGraphicsContext.BlankScreen)
        {
          // Render GUI + Video surface
          GUIGraphicsContext.RenderGUI.RenderFrame(timePassed);
          GUIFontManager.Present();
        }
      }
      finally
      {
        GUIGraphicsContext.DX9Device.EndScene();
      }

      GUIGraphicsContext.DX9Device.SetRenderTarget(0, backbuffer);
      GUIGraphicsContext.DX9Device.StretchRectangle(surface,
                                                    new Rectangle(0, 0, backbuffer.Description.Width,
                                                                  backbuffer.Description.Height), backbuffer, targetRect,
                                                    TextureFilter.Point);
    }