public MainLoop(IPclWorkarounds pclWorkarounds, IClientStatistics statistics, IClientSettings settings, IContext context, IRavcGameWindow gameWindow, IMainThreadBorderStage mainThreadBorderStage, IFinalFrameProvider finalFrameProvider, IClientStatisticsRenderer statisticsRenderer, ITextureLoader textureLoader) { this.settings = settings; this.context = context; this.statistics = statistics; this.gameWindow = gameWindow; this.mainThreadBorderStage = mainThreadBorderStage; this.finalFrameProvider = finalFrameProvider; this.statisticsRenderer = statisticsRenderer; finalRenderer = new FinalRenderer(pclWorkarounds, settings, context); cursorRenderer = new CursorRenderer(settings, context, textureLoader); stopwatch = new Stopwatch(); }
public unsafe void Draw(IContext context, IRavcGameWindow gameWindow, ITexture2D frameTexture, int x, int y) { var pipeline = context.Pipeline; pipeline.Program = program; pipeline.VertexArray = vertexArray; var windowAspectRatio = (float)gameWindow.ClientWidth / Math.Max(gameWindow.ClientHeight, 1); var textureAspectRatio = (float)frameTexture.Width / Math.Max(frameTexture.Height, 1); int adjustedTextureWidth = gameWindow.ClientWidth; int adjustedTextureHeight = gameWindow.ClientHeight; if (windowAspectRatio > textureAspectRatio) adjustedTextureWidth = (int)(gameWindow.ClientHeight * textureAspectRatio); if (windowAspectRatio < textureAspectRatio) adjustedTextureHeight = (int)(gameWindow.ClientWidth / textureAspectRatio); int aspectOffsetX = (gameWindow.ClientWidth - adjustedTextureWidth) / 2; int aspectOffsetY = (gameWindow.ClientHeight - adjustedTextureHeight) / 2; int adjustedSize = texture.Width * adjustedTextureWidth / frameTexture.Width; int viewportX = x * adjustedTextureWidth / frameTexture.Width + aspectOffsetX; int viewportY = gameWindow.ClientHeight - (y * adjustedTextureHeight / frameTexture.Height + aspectOffsetY) - adjustedSize; pipeline.Viewports[0].Set(viewportX, viewportY, adjustedSize, adjustedSize); pipeline.Rasterizer.SetDefault(); pipeline.Rasterizer.MultisampleEnable = false; pipeline.Textures[0] = texture; pipeline.Samplers[0] = sampler; pipeline.DepthStencil.SetDefault(); pipeline.DepthStencil.DepthMask = false; pipeline.Blend.SetDefault(false); pipeline.Blend.BlendEnable = true; pipeline.Blend.Targets[0].Color.SrcFactor = BlendFactor.SrcAlpha; pipeline.Blend.Targets[0].Color.DestFactor = BlendFactor.OneMinusSrcAlpha; pipeline.Blend.Targets[0].Alpha.SrcFactor = BlendFactor.SrcAlpha; pipeline.Blend.Targets[0].Alpha.SrcFactor = BlendFactor.OneMinusSrcAlpha; context.DrawElements(BeginMode.Triangles, 6, DrawElementsType.UnsignedShort, 0); }