public AttributelessObject( RenderScene scene, int vertexCount, ReadOnlySpan <TextureInfo> textureInfos) { if (scene == null) { throw new ArgumentNullException(nameof(scene)); } this.vertexCount = vertexCount; //Prepare the inputs inputs = new IShaderInput[textureInfos.Length]; for (int i = 0; i < inputs.Length; i++) { DeviceTexture texture = DeviceTexture.UploadTexture( texture: textureInfos[i].Texture as IInternalTexture, scene, generateMipMaps: textureInfos[i].UseMipMaps); inputs[i] = new DeviceSampler( scene.LogicalDevice, texture, disposeTexture: true, repeat: textureInfos[i].Repeat, maxAnisotropy: 8f); } }
public InstancedObject( RenderScene scene, Mesh mesh, TextureInfo[] textureInfos, int maxInstances = 100_000) { if (scene == null) { throw new ArgumentNullException(nameof(scene)); } if (mesh == null) { throw new ArgumentNullException(nameof(mesh)); } //Prepare the inputs inputs = new IShaderInput[textureInfos.Length]; for (int i = 0; i < inputs.Length; i++) { DeviceTexture texture = DeviceTexture.UploadTexture( texture: textureInfos[i].Texture as IInternalTexture, scene, generateMipMaps: textureInfos[i].UseMipMaps); inputs[i] = new DeviceSampler( scene.LogicalDevice, texture, disposeTexture: true, repeat: textureInfos[i].Repeat, maxAnisotropy: 8f); } //Upload our mesh to the gpu deviceMesh = new DeviceMesh(mesh, scene); //Allocate a buffers for the instance data and indirect args instanceDataBuffer = new Memory.HostBuffer( logicalDevice: scene.LogicalDevice, memoryPool: scene.MemoryPool, usages: BufferUsages.VertexBuffer, size: InstanceData.SIZE * maxInstances); indirectArgumentsBuffer = new Memory.HostBuffer( logicalDevice: scene.LogicalDevice, memoryPool: scene.MemoryPool, usages: BufferUsages.IndirectBuffer, size: DrawIndexedIndirectCommand.SIZE); //Write defaults to the indirect args buffer indirectArgumentsBuffer.Write(new DrawIndexedIndirectCommand( indexCount: (uint)deviceMesh.IndexCount, instanceCount: 0, firstIndex: 0, vertexOffset: 0, firstInstance: 0)); }