aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics/Gal
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2018-04-14 00:39:24 -0300
committergdkchan <gab.dark.100@gmail.com>2018-04-14 00:39:24 -0300
commit42ebfdff7f2889be38a3415bf33aeb41df90bd98 (patch)
tree556639adf9f0ef20e0fc64f9293ccc8c6e11b5e3 /Ryujinx.Graphics/Gal
parent47100ec8c1b3cabc7d53654163c1dd30b58d483d (diff)
[GPU] Fix frame buffer being upside down in some cases
Diffstat (limited to 'Ryujinx.Graphics/Gal')
-rw-r--r--Ryujinx.Graphics/Gal/GalConsts.cs7
-rw-r--r--Ryujinx.Graphics/Gal/IGalRenderer.cs4
-rw-r--r--Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs36
-rw-r--r--Ryujinx.Graphics/Gal/OpenGL/OGLShader.cs9
-rw-r--r--Ryujinx.Graphics/Gal/OpenGL/OpenGLRenderer.cs15
-rw-r--r--Ryujinx.Graphics/Gal/Shader/GlslDecompiler.cs7
6 files changed, 78 insertions, 0 deletions
diff --git a/Ryujinx.Graphics/Gal/GalConsts.cs b/Ryujinx.Graphics/Gal/GalConsts.cs
new file mode 100644
index 00000000..6c8857c6
--- /dev/null
+++ b/Ryujinx.Graphics/Gal/GalConsts.cs
@@ -0,0 +1,7 @@
+namespace Ryujinx.Graphics.Gal
+{
+ public static class GalConsts
+ {
+ public const string FlipUniformName = "flip";
+ }
+} \ No newline at end of file
diff --git a/Ryujinx.Graphics/Gal/IGalRenderer.cs b/Ryujinx.Graphics/Gal/IGalRenderer.cs
index c30c79fb..af88412a 100644
--- a/Ryujinx.Graphics/Gal/IGalRenderer.cs
+++ b/Ryujinx.Graphics/Gal/IGalRenderer.cs
@@ -42,6 +42,8 @@ namespace Ryujinx.Graphics.Gal
void SetFrameBufferTransform(float SX, float SY, float Rotate, float TX, float TY);
+ void SetViewport(int X, int Y, int Width, int Height);
+
//Rasterizer
void ClearBuffers(int RtIndex, GalClearBufferFlags Flags);
@@ -62,6 +64,8 @@ namespace Ryujinx.Graphics.Gal
void SetUniform1(string UniformName, int Value);
+ void SetUniform2F(string UniformName, float X, float Y);
+
void BindShader(long Tag);
void BindProgram();
diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs
index cca61e18..e0da9179 100644
--- a/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs
+++ b/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs
@@ -7,6 +7,22 @@ namespace Ryujinx.Graphics.Gal.OpenGL
{
class OGLFrameBuffer
{
+ private struct Rect
+ {
+ public int X { get; private set; }
+ public int Y { get; private set; }
+ public int Width { get; private set; }
+ public int Height { get; private set; }
+
+ public Rect(int X, int Y, int Width, int Height)
+ {
+ this.X = X;
+ this.Y = Y;
+ this.Width = Width;
+ this.Height = Height;
+ }
+ }
+
private class FrameBuffer
{
public int Width { get; set; }
@@ -38,6 +54,8 @@ namespace Ryujinx.Graphics.Gal.OpenGL
private ShaderProgram Shader;
+ private Rect Viewport;
+
private bool IsInitialized;
private int RawFbTexWidth;
@@ -178,6 +196,13 @@ namespace Ryujinx.Graphics.Gal.OpenGL
GL.UseProgram(CurrentProgram);
}
+ public void SetViewport(int X, int Y, int Width, int Height)
+ {
+ Viewport = new Rect(X, Y, Width, Height);
+
+ //TODO
+ }
+
public void Render()
{
if (CurrTexHandle != 0)
@@ -196,6 +221,8 @@ namespace Ryujinx.Graphics.Gal.OpenGL
GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
+ GL.Viewport(0, 0, 1280, 720);
+
GL.Clear(
ClearBufferMask.ColorBufferBit |
ClearBufferMask.DepthBufferBit);
@@ -218,6 +245,15 @@ namespace Ryujinx.Graphics.Gal.OpenGL
}
}
+ private void SetViewport()
+ {
+ GL.Viewport(
+ Viewport.X,
+ Viewport.Y,
+ Viewport.Width,
+ Viewport.Height);
+ }
+
private void EnsureInitialized()
{
if (!IsInitialized)
diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLShader.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLShader.cs
index 6d6ac555..fff6362b 100644
--- a/Ryujinx.Graphics/Gal/OpenGL/OGLShader.cs
+++ b/Ryujinx.Graphics/Gal/OpenGL/OGLShader.cs
@@ -158,6 +158,15 @@ namespace Ryujinx.Graphics.Gal.OpenGL
GL.Uniform1(Location, Value);
}
+ public void SetUniform2F(string UniformName, float X, float Y)
+ {
+ BindProgram();
+
+ int Location = GL.GetUniformLocation(CurrentProgramHandle, UniformName);
+
+ GL.Uniform2(Location, X, Y);
+ }
+
public void Bind(long Tag)
{
if (Stages.TryGetValue(Tag, out ShaderStage Stage))
diff --git a/Ryujinx.Graphics/Gal/OpenGL/OpenGLRenderer.cs b/Ryujinx.Graphics/Gal/OpenGL/OpenGLRenderer.cs
index b3ccae5f..5e066e3f 100644
--- a/Ryujinx.Graphics/Gal/OpenGL/OpenGLRenderer.cs
+++ b/Ryujinx.Graphics/Gal/OpenGL/OpenGLRenderer.cs
@@ -141,6 +141,11 @@ namespace Ryujinx.Graphics.Gal.OpenGL
ActionsQueue.Enqueue(() => FrameBuffer.SetTransform(Transform, Offs));
}
+ public void SetViewport(int X, int Y, int Width, int Height)
+ {
+ ActionsQueue.Enqueue(() => FrameBuffer.SetViewport(X, Y, Width, Height));
+ }
+
public void ClearBuffers(int RtIndex, GalClearBufferFlags Flags)
{
ActionsQueue.Enqueue(() => Rasterizer.ClearBuffers(RtIndex, Flags));
@@ -218,6 +223,16 @@ namespace Ryujinx.Graphics.Gal.OpenGL
ActionsQueue.Enqueue(() => Shader.SetUniform1(UniformName, Value));
}
+ public void SetUniform2F(string UniformName, float X, float Y)
+ {
+ if (UniformName == null)
+ {
+ throw new ArgumentNullException(nameof(UniformName));
+ }
+
+ ActionsQueue.Enqueue(() => Shader.SetUniform2F(UniformName, X, Y));
+ }
+
public IEnumerable<ShaderDeclInfo> GetTextureUsage(long Tag)
{
return Shader.GetTextureUsage(Tag);
diff --git a/Ryujinx.Graphics/Gal/Shader/GlslDecompiler.cs b/Ryujinx.Graphics/Gal/Shader/GlslDecompiler.cs
index 7d97ec33..457192dc 100644
--- a/Ryujinx.Graphics/Gal/Shader/GlslDecompiler.cs
+++ b/Ryujinx.Graphics/Gal/Shader/GlslDecompiler.cs
@@ -115,6 +115,11 @@ namespace Ryujinx.Graphics.Gal.Shader
private void PrintDeclUniforms()
{
+ if (Decl.ShaderType == GalShaderType.Vertex)
+ {
+ SB.AppendLine("uniform vec2 " + GalConsts.FlipUniformName + ";");
+ }
+
foreach (ShaderDeclInfo DeclInfo in Decl.Uniforms.Values.OrderBy(DeclKeySelector))
{
SB.AppendLine($"uniform {GetDecl(DeclInfo)};");
@@ -270,6 +275,8 @@ namespace Ryujinx.Graphics.Gal.Shader
//the shader ends here.
if (Decl.ShaderType == GalShaderType.Vertex)
{
+ SB.AppendLine(Identation + "gl_Position.xy *= flip;");
+
SB.AppendLine(Identation + GlslDecl.PositionOutAttrName + " = gl_Position;");
}
}