daily update on 20240828 by nitload youmu, autotexture added
This commit is contained in:
@@ -32,7 +32,7 @@ using StgSharp.Data;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Logic;
|
||||
|
||||
using StgSharp.Math;
|
||||
using StgSharp.MVVM;
|
||||
|
||||
@@ -48,32 +48,88 @@ namespace StgSharp.Stg
|
||||
{
|
||||
public interface IOneDimensionalCollisionTexture2D
|
||||
{
|
||||
|
||||
public void Init(Radius angleStride, string name);
|
||||
|
||||
}
|
||||
|
||||
public sealed class OneDimensionalCollisionTexture2D_GL :glRenderStream, IOneDimensionalCollisionTexture2D
|
||||
public sealed class OneDimensionalCollisionTexture2D_GL : glRenderStream, IOneDimensionalCollisionTexture2D
|
||||
{
|
||||
|
||||
private const string inputName = "InstanceBufferList";
|
||||
private const string outputName = "CollisionTextureOutput";
|
||||
|
||||
float[] textureOutput;
|
||||
ElementBuffer ebo;
|
||||
private FrameBuffer fbo;
|
||||
RenderBuffer rbo;
|
||||
|
||||
ShaderProgram generatingShader;
|
||||
|
||||
TextureGL t;
|
||||
|
||||
VertexArray vao;
|
||||
VertexBuffer vbo;
|
||||
ElementBuffer ebo;
|
||||
|
||||
public OneDimensionalCollisionTexture2D_GL()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override bool IsContextSharable => false;
|
||||
|
||||
#pragma warning disable CS8618
|
||||
public void GenerateCollisionTexture(IEnumerable<IInstancingBuffer> bufferEnumeration)
|
||||
{
|
||||
fbo.Bind(0);
|
||||
GL.ClearColor(0, 0, 0, 1);
|
||||
GL.Clear(MaskBufferBit.DEPTH | MaskBufferBit.COLOR);
|
||||
generatingShader.Use();
|
||||
vao.Bind(0);
|
||||
|
||||
foreach (IInstancingBuffer item in bufferEnumeration)
|
||||
{
|
||||
IGeometry g = item.TypicalShape;
|
||||
|
||||
if (!(g is PlainGeometry))
|
||||
{
|
||||
throw new InvalidOperationException("The current particle buffer contains non-planar geometry,");
|
||||
}
|
||||
|
||||
ebo.Bind(0);
|
||||
ebo.SetValue<int>(0, g.VertexIndices, BufferUsage.StreamDraw);
|
||||
|
||||
vbo.WriteVectorData<vec4d>(0, item.CoordAndRotationSpan, BufferUsage.StreamDraw);
|
||||
vao.SetVertexAttribute(1, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
vao.SetVertexAttribute(2, 1, TypeCode.Single, false, 4 * sizeof(float), 3 * sizeof(float));
|
||||
|
||||
vbo.WriteScalerData<float>(2, item.ScalingSpan, BufferUsage.StreamDraw);
|
||||
vao.SetVertexAttribute(3, 1, TypeCode.Single, false, sizeof(float), 0);
|
||||
|
||||
vbo.WriteVectorData(1, g.VertexStream, BufferUsage.StreamDraw);
|
||||
vao.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
|
||||
GL.DrawElementsInstanced(GeometryType.TRIANGLES, ((uint)g.VertexIndices.Length) / 3,
|
||||
TypeCode.UInt32, IntPtr.Zero, (uint)item.ScalingSpan.Length);
|
||||
}
|
||||
|
||||
t.Bind2D(0);
|
||||
GL.GetTextureImage(Texture2DTarget.Texture2D, 0, ImageChannel.SingleColor, PixelChannelLayout.Float, textureOutput);
|
||||
VertexArray.BindNull();
|
||||
}
|
||||
|
||||
public void Init(Radius angleStride, string name)
|
||||
{
|
||||
primeArgs = new ViewPort
|
||||
{
|
||||
Height = 1,
|
||||
Width = (int)((new Radius(Scaler.Pi)) / angleStride),
|
||||
Name = name,
|
||||
};
|
||||
|
||||
_coordStretch = (1, 1, 1);
|
||||
|
||||
PlatformSpecifiedInitialize();
|
||||
CustomizeInit();
|
||||
}
|
||||
|
||||
#pragma warning disable CS8618
|
||||
|
||||
protected override void CustomizeDeinit()
|
||||
{
|
||||
@@ -111,8 +167,8 @@ namespace StgSharp.Stg
|
||||
GL.TextureImage2d<byte>(Texture2DTarget.Texture2D, 0, (int)ImageChannel.WithAlphaChannel,
|
||||
(uint)Width, (uint)Height, (int)ImageChannel.WithAlphaChannel, PixelChannelLayout.Byte, Array.Empty<byte>());
|
||||
|
||||
t.Set2dWrapProperty(Wrap.Repeat, Wrap.Repeat);
|
||||
t.Set2dFilterProperty(Filter.Nearest, Filter.Nearest);
|
||||
t.Set2dWrapProperty(0, TextureWrap.Repeat, TextureWrap.Repeat);
|
||||
t.Set2dFilterProperty(0, TextureFilter.Nearest, TextureFilter.Nearest);
|
||||
|
||||
GL.FrameBufferTexture2d(FrameBufferTarget.All, glAttachment.Color(0),
|
||||
Texture2DTarget.Texture2D, t[0], 0);
|
||||
@@ -122,67 +178,10 @@ namespace StgSharp.Stg
|
||||
textureOutput = new float[this.Width];
|
||||
}
|
||||
|
||||
TextureGL t;
|
||||
RenderBuffer rbo;
|
||||
float[] textureOutput;
|
||||
|
||||
protected override void Main()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public void GenerateCollisionTexture(IEnumerable<IInstancingBuffer> bufferEnumeration)
|
||||
{
|
||||
fbo.Bind(0);
|
||||
GL.ClearColor(0, 0, 0, 1);
|
||||
GL.Clear(MaskBufferBit.DEPTH | MaskBufferBit.COLOR);
|
||||
generatingShader.Use();
|
||||
vao.Bind(0);
|
||||
|
||||
foreach (IInstancingBuffer item in bufferEnumeration)
|
||||
{
|
||||
IGeometry g = item.TypicalShape;
|
||||
|
||||
if (!(g is PlainGeometry))
|
||||
{
|
||||
throw new InvalidOperationException("The current particle buffer contains non-planar geometry,");
|
||||
}
|
||||
|
||||
ebo.Bind(0);
|
||||
ebo.SetValue<int>(0, g.VertexIndices, BufferUsage.StreamDraw);
|
||||
|
||||
vbo.WriteVectorData<vec4d>(0, item.CoordAndRotationSpan, BufferUsage.StreamDraw);
|
||||
vao.SetVertexAttribute(1, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
vao.SetVertexAttribute(2, 1, TypeCode.Single, false, 4 * sizeof(float), 3 * sizeof(float));
|
||||
|
||||
vbo.WriteScalerData<float>(2, item.ScalingSpan, BufferUsage.StreamDraw);
|
||||
vao.SetVertexAttribute(3, 1, TypeCode.Single, false, sizeof(float), 0);
|
||||
|
||||
vbo.WriteVectorData(1, g.VertexStream, BufferUsage.StreamDraw);
|
||||
vao.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
|
||||
GL.DrawElementsInstanced(GeometryType.TRIANGLES, (uint)g.VertexIndices.Length / 3,
|
||||
TypeCode.UInt32, IntPtr.Zero, (uint)item.ScalingSpan.Length);
|
||||
}
|
||||
|
||||
t.Bind2D(0);
|
||||
GL.GetTextureImage(Texture2DTarget.Texture2D, 0, ImageChannel.SingleColor, PixelChannelLayout.Float, textureOutput);
|
||||
VertexArray.BindNull();
|
||||
}
|
||||
|
||||
public void Init(Radius angleStride, string name)
|
||||
{
|
||||
primeArgs = new ViewPort()
|
||||
{
|
||||
Height = 1,
|
||||
Width = (int)((new Radius(Scaler.Pi)) / angleStride),
|
||||
Name = name,
|
||||
};
|
||||
|
||||
_coordStretch = (1, 1, 1);
|
||||
|
||||
PlatformSpecifiedInitialize();
|
||||
CustomizeInit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user