Ejemplo n.º 1
0
        public BasicSceneRenderer(GraphicsDevice device)
        {
            _device = device;

            _rtvs          = _device.CreateDescriptorHeap(DescriptorHeapType.RenderTargetView, 1);
            _dsvs          = _device.CreateDescriptorHeap(DescriptorHeapType.RenderTargetView, 1);
            _textureHandle = _device.AllocateResourceDescriptors(2);

            _texturedObjects = ModelLoader.LoadGl_Old("Assets/Gltf/Handgun_NoTangent.gltf");
            //_texturedObjects = new[] { GeometryGenerator.CreateCube(0.5f) };

            var texture = TextureLoader.LoadTextureDesc("Assets/Textures/handgun_c.dds");
            var normals = TextureLoader.LoadTextureDesc("Assets/Textures/handgun_n.dds");

            _vertexBuffer = new Buffer[_texturedObjects.Length];
            _indexBuffer  = new Buffer[_texturedObjects.Length];

            using (var list = _device.BeginUploadContext())
            {
                for (var i = 0; i < _texturedObjects.Length; i++)
                {
                    _vertexBuffer[i] = list.UploadBuffer(_texturedObjects[i].Vertices);
                    _vertexBuffer[i].SetName("VertexBuffer");

                    _indexBuffer[i] = list.UploadBuffer(_texturedObjects[i].Indices);
                    _indexBuffer[i].SetName("IndexBuffer");
                }

                _texture = list.UploadTexture(texture);
                _texture.SetName("Gun texture");
            }

            //list.UploadTexture(normals.Data.Span, normals.SubresourceData.Span, normals.Desc, ResourceState.PixelShaderResource, out _normals);
            //_normals.SetName("Gun normals");

            _device.CreateShaderResourceView(_texture, _textureHandle[0]);
            //_normalHandle = _device.CreateShaderResourceView(_normals);
            _objectConstants = new ObjectConstants[_texturedObjects.Length];

            _obj = _device.Allocator.AllocateBuffer(MathHelpers.AlignUp(sizeof(ObjectConstants), 256) * _texturedObjects.Length, MemoryAccess.CpuUpload);
            _obj.SetName("ObjectConstants buffer");

            _frame = _device.Allocator.AllocateBuffer(sizeof(FrameConstants), MemoryAccess.CpuUpload);
            _frame.SetName("FrameConstants buffer");

            _light = _device.Allocator.AllocateBuffer(sizeof(LightConstants), MemoryAccess.CpuUpload);
            _light.SetName("LightConstants buffer");

            CreatePipelines();
            InitializeConstants();
        }
Ejemplo n.º 2
0
        private void UploadTextures()
        {
            using var upload = _device.BeginUploadContext();

            _textures = new Texture[2];

            _textures[0] = upload.UploadTexture("Assets/Textures/bricks.dds");
            _textures[1] = upload.UploadTexture("Assets/Textures/stone.dds");

            _texViews = _device.AllocateResourceDescriptors(_textures.Length);

            for (var i = 0; i < _textures.Length; i++)
            {
                _device.CreateShaderResourceView(_textures[i], _texViews[i]);
            }
        }