Example #1
0
        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);
            }
        }
Example #2
0
        public void AttachScene(RenderScene scene)
        {
            ThrowIfDisposed();

            //Release resources that are tied to the previous scene
            this.scene?.Dispose();

            this.scene = scene;
            CreateRenderCommands(scene);
        }
 internal static DeviceTexture UploadTexture(
     IInternalTexture texture, RenderScene scene, bool generateMipMaps = false)
 {
     return(UploadTexture(
                texture,
                scene.LogicalDevice,
                scene.MemoryPool,
                scene.StagingBuffer,
                scene.Executor,
                generateMipMaps));
 }
        internal Renderer(RenderScene scene, Logger logger = null)
        {
            if (scene == null)
            {
                throw new ArgumentNullException(nameof(scene));
            }

            this.scene = scene;
            this.specializationContainer = new SpecializationContainer(logger);
            this.pushDataContainer       = new PushDataContainer(
                stages: ShaderStages.Vertex | ShaderStages.Fragment, logger);
            this.logger = logger;
        }
 internal static DeviceTexture CreateColorTarget(
     Int2 size,
     Format format,
     RenderScene scene,
     bool allowSampling = true)
 {
     return(CreateColorTarget(
                size,
                format,
                scene.LogicalDevice,
                scene.MemoryPool,
                scene.Executor,
                allowSampling));
 }
        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));
        }
Example #7
0
        internal DeviceMesh(Mesh mesh, RenderScene scene)
        {
            if (mesh == null)
            {
                throw new ArgumentNullException(nameof(mesh));
            }
            if (scene == null)
            {
                throw new ArgumentNullException(nameof(scene));
            }

            topology     = mesh.Topology;
            allowRestart = mesh.AllowRestart;
            vertexCount  = mesh.VertexCount;
            indexCount   = mesh.IndexCount;
            vertexBuffer = mesh.UploadVertices(scene);
            indexBuffer  = mesh.UploadIndices(scene);
        }
Example #8
0
        private void CreateRenderCommands(RenderScene scene)
        {
            scene.CreateResources(swapchainSize, swapchainTextures);

            //Reset the pool (to release any previously created buffers)
            commandPool.Reset(CommandPoolResetFlags.ReleaseResources);

            //Allocate new command buffers
            commandbuffers = commandPool.AllocateBuffers(new CommandBufferAllocateInfo(
                                                             level: CommandBufferLevel.Primary,
                                                             count: swapchainTextures.Length
                                                             ));

            //Record the primary command-buffers
            for (int i = 0; i < commandbuffers.Length; i++)
            {
                commandbuffers[i].Begin(new CommandBufferBeginInfo(flags: CommandBufferUsages.None));
                scene.Record(commandbuffers[i], i);
                commandbuffers[i].End();
            }

            logger?.Log(nameof(Window), $"Rendercommands recorded ({commandbuffers.Length} command-buffers)");
        }