Skip to content

Commit

Permalink
Use RGBA format for textures
Browse files Browse the repository at this point in the history
  • Loading branch information
jvbsl committed Sep 18, 2022
1 parent c8be490 commit ab32b5e
Show file tree
Hide file tree
Showing 3 changed files with 451 additions and 13 deletions.
24 changes: 12 additions & 12 deletions Graphics/Texture2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void LoadFrom(Image<Rgba32> image)
GraphicsDevice.ValidateUiGraphicsThread();
Bind();
GL.TexSubImage2D(Target, 0, 0, 0, Width, Height,
OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, ref span.GetPinnableReference());
OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, ref span.GetPinnableReference());
}
}

Expand Down Expand Up @@ -264,7 +264,7 @@ public void SetData(Image<Rgba32> data, int level = 0)
public void SetData<T>(ReadOnlySpan<T> data, int level = 0)
where T : unmanaged
{
SetData(data,level,OpenTK.Graphics.OpenGL.PixelFormat.Bgra);
SetData(data,level,OpenTK.Graphics.OpenGL.PixelFormat.Rgba);
}

/// <summary>
Expand All @@ -276,7 +276,7 @@ public void SetData<T>(ReadOnlySpan<T> data, int level = 0)
public void SetData<T>(T[] data, int level = 0)
where T : unmanaged
{
SetData(data,level,OpenTK.Graphics.OpenGL.PixelFormat.Bgra);
SetData(data,level,OpenTK.Graphics.OpenGL.PixelFormat.Rgba);
}

internal unsafe void SetData<T>(T[] data, int level,OpenTK.Graphics.OpenGL.PixelFormat format)
Expand Down Expand Up @@ -333,7 +333,7 @@ internal unsafe void SetData<T>(ReadOnlySpan<T> data, int level, OpenTK.Graphics
GL.TexSubImage2D(Target, level, x, y, width, height, format, pxType,
(IntPtr)buffer);

//GL.TexSubImage2D<T> (Target, 0, 0, 0, Width, Height, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, getPixelType (typeof(T)), data);
//GL.TexSubImage2D<T> (Target, 0, 0, 0, Width, Height, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, getPixelType (typeof(T)), data);
}

/// <summary>
Expand All @@ -345,7 +345,7 @@ internal unsafe void SetData<T>(ReadOnlySpan<T> data, int level, OpenTK.Graphics
/// <typeparam name="T">The type to write pixel data as.</typeparam>
public void SetData<T>(T[] data, int startIndex, int elementCount) where T : unmanaged
{
SetData<T>(data.AsSpan().Slice(startIndex, elementCount), 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra);
SetData<T>(data.AsSpan().Slice(startIndex, elementCount), 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba);
}

/// <summary>
Expand All @@ -364,11 +364,11 @@ public void SetData<T>(int level, Rectangle? rect, T[] data, int startIndex, int
if (rect.HasValue)
{
var recVal = rect.Value;
SetData<T>(data.AsSpan(startIndex, elementCount), level, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, recVal.X, recVal.Y, recVal.Width, recVal.Height);
SetData<T>(data.AsSpan(startIndex, elementCount), level, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, recVal.X, recVal.Y, recVal.Width, recVal.Height);
}
else
{
SetData<T>(data.AsSpan(startIndex, elementCount), level, OpenTK.Graphics.OpenGL.PixelFormat.Bgra);
SetData<T>(data.AsSpan(startIndex, elementCount), level, OpenTK.Graphics.OpenGL.PixelFormat.Rgba);
}
}

Expand All @@ -385,7 +385,7 @@ public void GetData<T>(T[] data, int level = 0) where T : unmanaged

Bind();

GL.GetTexImage(Target, level, OpenTK.Graphics.OpenGL.PixelFormat.Bgra,
GL.GetTexImage(Target, level, OpenTK.Graphics.OpenGL.PixelFormat.Rgba,
PixelType.UnsignedByte, data);
}

Expand All @@ -401,7 +401,7 @@ public unsafe void GetData<T>(Span<T> data, int level = 0) where T : unmanaged

Bind();
fixed(T* buffer = &data.GetPinnableReference())
GL.GetTexImage(Target, level, OpenTK.Graphics.OpenGL.PixelFormat.Bgra,
GL.GetTexImage(Target, level, OpenTK.Graphics.OpenGL.PixelFormat.Rgba,
PixelType.UnsignedByte, (IntPtr)buffer);
}

Expand All @@ -424,7 +424,7 @@ public void GetData<T>(int level, Rectangle? rect, T[] data, int startIndex, int
{
//TODO: use ? GL.CopyImageSubData(
var temp = new T[Width * Height];
GL.GetTexImage(Target, level, OpenTK.Graphics.OpenGL.PixelFormat.Bgra,
GL.GetTexImage(Target, level, OpenTK.Graphics.OpenGL.PixelFormat.Rgba,
PixelType.UnsignedByte, temp);
int z = 0, w = 0, index = 0;

Expand All @@ -442,7 +442,7 @@ public void GetData<T>(int level, Rectangle? rect, T[] data, int startIndex, int
}
else
{
GL.GetTexImage(Target, level, OpenTK.Graphics.OpenGL.PixelFormat.Bgra,
GL.GetTexImage(Target, level, OpenTK.Graphics.OpenGL.PixelFormat.Rgba,
PixelType.UnsignedByte, data);
}
}
Expand Down Expand Up @@ -500,7 +500,7 @@ public static Image<Rgba32> ToBitmap(Texture2D text)
text.GraphicsDevice.ValidateUiGraphicsThread();

text.Bind();
GL.GetTexImage(text.Target, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra,
GL.GetTexImage(text.Target, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba,
PixelType.UnsignedByte, ref data);
}

Expand Down
2 changes: 1 addition & 1 deletion Graphics/Texture2DArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public unsafe void SetData<T>(ReadOnlySpan<T> data, int layer, int level=0) wher
pxType = PixelType.Float;

fixed(T* buffer = &data.GetPinnableReference())
GL.TexSubImage3D(Target, level, 0, 0,layer, Width, Height,1, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, pxType, (IntPtr)buffer);
GL.TexSubImage3D(Target, level, 0, 0,layer, Width, Height,1, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, pxType, (IntPtr)buffer);
}

/// <summary>
Expand Down
Loading

0 comments on commit ab32b5e

Please sign in to comment.