mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-19 14:53:50 +02:00
render flag
This commit is contained in:
@@ -20,6 +20,7 @@ namespace VRCX
|
|||||||
private GCHandle _paintBuffer;
|
private GCHandle _paintBuffer;
|
||||||
private int _width;
|
private int _width;
|
||||||
private int _height;
|
private int _height;
|
||||||
|
private bool _dirty;
|
||||||
|
|
||||||
public OffScreenBrowser(string address, int width, int height)
|
public OffScreenBrowser(string address, int width, int height)
|
||||||
: base(
|
: base(
|
||||||
@@ -61,53 +62,57 @@ namespace VRCX
|
|||||||
|
|
||||||
public void RenderToTexture(Texture2D texture)
|
public void RenderToTexture(Texture2D texture)
|
||||||
{
|
{
|
||||||
_paintBufferLock.EnterReadLock();
|
if (_dirty == true)
|
||||||
try
|
|
||||||
{
|
{
|
||||||
if (_width > 0 &&
|
_dirty = false;
|
||||||
_height > 0)
|
_paintBufferLock.EnterReadLock();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var context = texture.Device.ImmediateContext;
|
if (_width > 0 &&
|
||||||
var dataBox = context.MapSubresource(
|
_height > 0)
|
||||||
texture,
|
|
||||||
0,
|
|
||||||
MapMode.WriteDiscard,
|
|
||||||
MapFlags.None
|
|
||||||
);
|
|
||||||
if (dataBox.IsEmpty == false)
|
|
||||||
{
|
{
|
||||||
var sourcePtr = _paintBuffer.AddrOfPinnedObject();
|
var context = texture.Device.ImmediateContext;
|
||||||
var destinationPtr = dataBox.DataPointer;
|
var dataBox = context.MapSubresource(
|
||||||
var pitch = _width * 4;
|
texture,
|
||||||
var rowPitch = dataBox.RowPitch;
|
0,
|
||||||
if (pitch == rowPitch)
|
MapMode.WriteDiscard,
|
||||||
|
MapFlags.None
|
||||||
|
);
|
||||||
|
if (dataBox.IsEmpty == false)
|
||||||
{
|
{
|
||||||
WinApi.CopyMemory(
|
var sourcePtr = _paintBuffer.AddrOfPinnedObject();
|
||||||
destinationPtr,
|
var destinationPtr = dataBox.DataPointer;
|
||||||
sourcePtr,
|
var pitch = _width * 4;
|
||||||
(uint)(_width * _height * 4)
|
var rowPitch = dataBox.RowPitch;
|
||||||
);
|
if (pitch == rowPitch)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (var y = _height; y > 0; --y)
|
|
||||||
{
|
{
|
||||||
WinApi.CopyMemory(
|
WinApi.CopyMemory(
|
||||||
destinationPtr,
|
destinationPtr,
|
||||||
sourcePtr,
|
sourcePtr,
|
||||||
(uint)pitch
|
(uint)(_width * _height * 4)
|
||||||
);
|
);
|
||||||
sourcePtr += pitch;
|
}
|
||||||
destinationPtr += rowPitch;
|
else
|
||||||
|
{
|
||||||
|
for (var y = _height; y > 0; --y)
|
||||||
|
{
|
||||||
|
WinApi.CopyMemory(
|
||||||
|
destinationPtr,
|
||||||
|
sourcePtr,
|
||||||
|
(uint)pitch
|
||||||
|
);
|
||||||
|
sourcePtr += pitch;
|
||||||
|
destinationPtr += rowPitch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
context.UnmapSubresource(texture, 0);
|
||||||
}
|
}
|
||||||
context.UnmapSubresource(texture, 0);
|
|
||||||
}
|
}
|
||||||
}
|
finally
|
||||||
finally
|
{
|
||||||
{
|
_paintBufferLock.ExitReadLock();
|
||||||
_paintBufferLock.ExitReadLock();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,6 +178,7 @@ namespace VRCX
|
|||||||
{
|
{
|
||||||
_paintBufferLock.ExitWriteLock();
|
_paintBufferLock.ExitWriteLock();
|
||||||
}
|
}
|
||||||
|
_dirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user