Skip to content

Commit

Permalink
MP1-5214: Add PixelShader support: If the MediaInfo is not available …
Browse files Browse the repository at this point in the history
…then pick the profile later from EVR callback
  • Loading branch information
epbk committed Jun 11, 2024
1 parent 8d1f858 commit b237cab
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions mediaportal/Core/Player/PlaneScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public class PlaneScene : IVMR9PresentCallback, IRenderLayer
private readonly System.Diagnostics.Stopwatch _PixelShaderClock = new System.Diagnostics.Stopwatch();
private long _PixelShaderCounter = 0;
private Texture[] _PixelShaderTexturesTemp = null;
private bool _PixelShaderInitialized = false;

#endregion

Expand Down Expand Up @@ -392,26 +393,38 @@ public void Init()
{
string strProfile = PixelShaderCollection.SHADER_PROFILE_DEFAULT;

//Profile: based on video width
//Profile: based on video size; if MediaInfo is not available(online video), then load the profile during the rendering process later
if (g_Player.MediaInfo != null && g_Player.MediaInfo.Width > 0)
{
if (g_Player.MediaInfo.Width > 1920)
strProfile = "UHD";
else if (g_Player.MediaInfo.Width >= 1440)
strProfile = "HD";
else
strProfile = "SD";
}
strProfile = SelectPixelShaderProfile(g_Player.MediaInfo.Width, g_Player.MediaInfo.Height);

GUIGraphicsContext.VideoPixelShaders.Load(strProfile);
}
else
{
GUIGraphicsContext.VideoPixelShaders.Clear(); //not supported with MadVR
this._PixelShaderInitialized = true;
}

this._PixelShaderClock.Start();
#endregion
}

private string SelectPixelShaderProfile(int iVideoWidth, int iVideoHeight)
{
string strProfile;

if (iVideoWidth > 1920 || iVideoHeight > 1080)
strProfile = "UHD";
else if (iVideoWidth >= 1440 || iVideoHeight >= 720)
strProfile = "HD";
else
strProfile = "SD";

this._PixelShaderInitialized = true;

return strProfile;
}

/// <summary>
/// OnMessage.
/// Handles received GUIMessage's from graphics context.
Expand Down Expand Up @@ -2056,6 +2069,13 @@ private void PresentScene(bool bIsRepaint)
private void DrawTextureSegment(VertexBuffer vertexBuffer, float srcX, float srcY, float srcWidth, float srcHeight,
float dstX, float dstY, float dstWidth, float dstHeight, long lColorDiffuse)
{
if (!this._PixelShaderInitialized)
{
//Pixel shaders not initialized yet; MediaInfo was not available upon initialization
GUIGraphicsContext.VideoPixelShaders.Load(this.SelectPixelShaderProfile((int)srcWidth, (int)srcHeight));
this._PixelShaderInitialized = true;
}

unsafe
{
CustomVertex.TransformedColoredTextured* verts = (CustomVertex.TransformedColoredTextured*)vertexBuffer.LockToPointer(0, 0, this._vertexBufferLock);
Expand Down Expand Up @@ -2115,7 +2135,6 @@ private void DrawTextureSegment(VertexBuffer vertexBuffer, float srcX, float src
vertexBuffer.Unlock();

GUIGraphicsContext.DX9Device.SetStreamSource(0, vertexBuffer, 0, CustomVertex.TransformedColoredTextured.StrideSize);


if (GUIGraphicsContext.VideoPixelShaders.Count > 0)
{
Expand Down

0 comments on commit b237cab

Please sign in to comment.