Add support for 16 bit floating point textures.
This commit is contained in:
@@ -125,6 +125,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
void SetData(uint[,] colors);
|
void SetData(uint[,] colors);
|
||||||
void SetData(byte[] colors, int width, int height);
|
void SetData(byte[] colors, int width, int height);
|
||||||
|
void SetFloatData(float[] data, int width, int height);
|
||||||
byte[] GetData();
|
byte[] GetData();
|
||||||
Size Size { get; }
|
Size Size { get; }
|
||||||
TextureScaleFilter ScaleFilter { get; set; }
|
TextureScaleFilter ScaleFilter { get; set; }
|
||||||
|
|||||||
@@ -144,6 +144,8 @@ namespace OpenRA.Platforms.Default
|
|||||||
public const int GL_INFO_LOG_LENGTH = 0x8B84;
|
public const int GL_INFO_LOG_LENGTH = 0x8B84;
|
||||||
public const int GL_ACTIVE_UNIFORMS = 0x8B86;
|
public const int GL_ACTIVE_UNIFORMS = 0x8B86;
|
||||||
|
|
||||||
|
public const int GL_RGBA16F = 0x881A;
|
||||||
|
|
||||||
// OpenGL 4.3
|
// OpenGL 4.3
|
||||||
public const int GL_DEBUG_OUTPUT = 0x92E0;
|
public const int GL_DEBUG_OUTPUT = 0x92E0;
|
||||||
public const int GL_DEBUG_OUTPUT_SYNCHRONOUS = 0x8242;
|
public const int GL_DEBUG_OUTPUT_SYNCHRONOUS = 0x8242;
|
||||||
|
|||||||
@@ -110,6 +110,25 @@ namespace OpenRA.Platforms.Default
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetFloatData(float[] data, int width, int height)
|
||||||
|
{
|
||||||
|
VerifyThreadAffinity();
|
||||||
|
if (!Exts.IsPowerOf2(width) || !Exts.IsPowerOf2(height))
|
||||||
|
throw new InvalidDataException("Non-power-of-two array {0}x{1}".F(width, height));
|
||||||
|
|
||||||
|
Size = new Size(width, height);
|
||||||
|
unsafe
|
||||||
|
{
|
||||||
|
fixed (float* ptr = &data[0])
|
||||||
|
{
|
||||||
|
PrepareTexture();
|
||||||
|
OpenGL.glTexImage2D(OpenGL.GL_TEXTURE_2D, 0, OpenGL.GL_RGBA16F, width, height,
|
||||||
|
0, OpenGL.GL_RGBA, OpenGL.GL_FLOAT, new IntPtr(ptr));
|
||||||
|
OpenGL.CheckGLError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public byte[] GetData()
|
public byte[] GetData()
|
||||||
{
|
{
|
||||||
VerifyThreadAffinity();
|
VerifyThreadAffinity();
|
||||||
|
|||||||
@@ -560,6 +560,8 @@ namespace OpenRA.Platforms.Default
|
|||||||
readonly Func<object, object> setData1;
|
readonly Func<object, object> setData1;
|
||||||
readonly Action<object> setData2;
|
readonly Action<object> setData2;
|
||||||
readonly Func<object, object> setData3;
|
readonly Func<object, object> setData3;
|
||||||
|
readonly Action<object> setData4;
|
||||||
|
readonly Func<object, object> setData5;
|
||||||
readonly Action dispose;
|
readonly Action dispose;
|
||||||
|
|
||||||
public ThreadedTexture(ThreadedGraphicsContext device, ITextureInternal texture)
|
public ThreadedTexture(ThreadedGraphicsContext device, ITextureInternal texture)
|
||||||
@@ -574,6 +576,8 @@ namespace OpenRA.Platforms.Default
|
|||||||
setData1 = colors => { texture.SetData((uint[,])colors); return null; };
|
setData1 = colors => { texture.SetData((uint[,])colors); return null; };
|
||||||
setData2 = tuple => { var t = (ValueTuple<byte[], int, int>)tuple; texture.SetData(t.Item1, t.Item2, t.Item3); };
|
setData2 = tuple => { var t = (ValueTuple<byte[], int, int>)tuple; texture.SetData(t.Item1, t.Item2, t.Item3); };
|
||||||
setData3 = tuple => { setData2(tuple); return null; };
|
setData3 = tuple => { setData2(tuple); return null; };
|
||||||
|
setData4 = tuple => { var t = (ValueTuple<float[], int, int>)tuple; texture.SetFloatData(t.Item1, t.Item2, t.Item3); };
|
||||||
|
setData5 = tuple => { setData4(tuple); return null; };
|
||||||
dispose = texture.Dispose;
|
dispose = texture.Dispose;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -623,6 +627,25 @@ namespace OpenRA.Platforms.Default
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetFloatData(float[] data, int width, int height)
|
||||||
|
{
|
||||||
|
// Objects 85000 bytes or more will be directly allocated in the Large Object Heap (LOH).
|
||||||
|
// https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/large-object-heap
|
||||||
|
if (data.Length < 21250)
|
||||||
|
{
|
||||||
|
// If we are able to create a small array the GC can collect easily, post a message to avoid blocking.
|
||||||
|
var temp = new float[data.Length];
|
||||||
|
Array.Copy(data, temp, temp.Length);
|
||||||
|
device.Post(setData4, (temp, width, height));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If the length is large and would result in an array on the Large Object Heap (LOH),
|
||||||
|
// send a message and block to avoid LOH allocation as this requires a Gen2 collection.
|
||||||
|
device.Send(setData5, (data, width, height));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
device.Post(dispose);
|
device.Post(dispose);
|
||||||
|
|||||||
Reference in New Issue
Block a user