Skip to content
This repository has been archived by the owner on Mar 6, 2018. It is now read-only.

Commit

Permalink
Add PostPreRender to IRenderContext so rays are calculated correctly (#…
Browse files Browse the repository at this point in the history
…201)

Previously the mouse ray and plane calculations were done at the start of the render pipeline. However, this is not correct as cameras are setup during the Prerender call of entities, which happens much later, and happens per-render pass.

This moves the ray calculations into a PostPreRender call on IRenderContext, which is called automatically by the render pipeline between Prerender and Render, and can optionally be called by developers if the view or projection changes at any other time during rendering and the mouse ray and plane need to be recalculated on game context.
  • Loading branch information
hach-que committed Jun 4, 2017
1 parent 44b4fb9 commit 0398b97
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Protogame/Core/IRenderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ public interface IRenderContext
/// </param>
void Render(IGameContext context);

/// <summary>
/// Called by the render pipeline after entity pre-render has been done, but before entity render
/// has begun. This method is where the render context updates the mouse rays and planes in
/// the game context, based on the current rendering configuration.
/// </summary>
/// <param name="context">The current game context.</param>
void PostPreRender(IGameContext context);

/// <summary>
/// Adds the specified render pass to the render pipeline
/// permanently. This render pass will take effect after the
Expand Down
6 changes: 6 additions & 0 deletions Protogame/Graphics/DefaultRenderPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,17 @@ private void RenderPass(IGameContext gameContext, IRenderContext renderContext,
entity.Prerender(gameContext, renderContext);
}

renderContext.PostPreRender(gameContext);

foreach (var entity in entities)
{
entity.Render(gameContext, renderContext);
}
}
else
{
renderContext.PostPreRender(gameContext);
}

if (!renderPass.SkipWorldRenderAbove && gameContext.World != null)
{
Expand Down
5 changes: 5 additions & 0 deletions Protogame/Graphics/RenderPipelineRenderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ public void Render(IGameContext context)
this.SingleWhitePixel.SetData(new[] { Color.White });
}

PostPreRender(context);
}

public void PostPreRender(IGameContext context)
{
// Update the MouseRay property of the game context.
var mouseState = Mouse.GetState();
var mouse = new Vector2(mouseState.X, mouseState.Y);
Expand Down
5 changes: 5 additions & 0 deletions Protogame/Server/NullRenderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public void Render(IGameContext context)
throw new NotSupportedException();
}

public void PostPreRender(IGameContext context)
{
throw new NotSupportedException();
}

public void SetActiveTexture(Texture2D texture)
{
throw new NotSupportedException();
Expand Down

0 comments on commit 0398b97

Please sign in to comment.