Example #1
0
        public void InitializeResources(string[] cubetexturePath, string pathVertShader, string pathPixShader, InputElements input, string vertFilePath = "")
        {
            InitializeVertices(vertFilePath);
            // Update();
            VertexBuffer = Direct3D11.Buffer.Create(Device, BindFlags.VertexBuffer, Vertices);

            MainShaderManager.Initialize(Device, input, VertexBuffer, pathVertShader, pathPixShader);
            ShadowShaderManager.Initialize(Device, VertexBuffer, true);

            Material = new Materials.Silver();



            List <Texture2D> temttext = new List <Texture2D>();

            foreach (string texturePath in cubetexturePath)
            {
                temttext.Add(TextureLoader.CreateTexture2DFromBitmap(Device, TextureLoader.LoadBitmap(new ImagingFactory2(), texturePath)));
            }

            Texture2D texture2D = new Texture2D(Device, new Texture2DDescription
            {
                ArraySize         = 6,
                MipLevels         = 1,
                Height            = temttext[0].Description.Height,
                Width             = temttext[0].Description.Width,
                CpuAccessFlags    = CpuAccessFlags.None,
                Format            = DXGI.Format.R8G8B8A8_UNorm,
                BindFlags         = BindFlags.ShaderResource,
                OptionFlags       = ResourceOptionFlags.TextureCube,
                SampleDescription = new DXGI.SampleDescription(1, 0),
                Usage             = ResourceUsage.Default //!!
            });

            TexturesCube = temttext.ToArray();

            isTextureCube = true;

            for (int i = 0; i < 6; i++)
            {
                Device.ImmediateContext.CopySubresourceRegion(TexturesCube[i], 0, null, texture2D, i);
                TexturesCube[i].Dispose();
            }

            TextureView = new ShaderResourceView(Device, texture2D);

            ShadowTransformBuffer = new Direct3D11.Buffer(Device, Utilities.SizeOf <Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            ShadowWorldBuffer     = new Direct3D11.Buffer(Device, Utilities.SizeOf <MatrixBufferStruct>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        public ConstantBuffer(Direct3D11.Device device, Direct3D11.BufferDescription desc)
        {
            desc.SizeInBytes = Marshal.SizeOf(typeof(T));

            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            this.m_device = device;
            //_device.AddReference();

            m_buffer     = new Direct3D11.Buffer(device, desc);
            m_dataStream = new DataStream(desc.SizeInBytes, true, true);
        }
Example #3
0
        public void InitializeResources(ShaderResourceView textureResourceView, Materials.AbstractMaterial material, string pathVertShader, string pathPixShader, InputElements input, string vertFilePath = "")
        {
            InitializeVertices(vertFilePath);
            // this.Update();
            VertexBuffer = Direct3D11.Buffer.Create(Device, BindFlags.VertexBuffer, Vertices);

            MainShaderManager.Initialize(Device, input, VertexBuffer, pathVertShader, pathPixShader);
            ShadowShaderManager.Initialize(Device, VertexBuffer, true);

            Material = material;

            TextureView = textureResourceView;

            ShadowTransformBuffer = new Direct3D11.Buffer(Device, Utilities.SizeOf <Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            ShadowWorldBuffer     = new Direct3D11.Buffer(Device, Utilities.SizeOf <MatrixBufferStruct>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        private void Dispose(bool disposing)
        {
            if (m_device == null)
            {
                return;
            }

            if (disposing)
            {
                m_dataStream.Dispose();
            }
            // NOTE: SharpDX 1.3 requires explicit Dispose() of all resource
            m_device.Dispose();
            m_buffer.Dispose();
            m_device = null;
            m_buffer = null;
        }
Example #5
0
 /// <summary>
 /// Initializes the specified device arg.
 /// </summary>
 /// <param name="deviceArg">The device arg.</param>
 /// <param name="resource">The resource.</param>
 protected void Initialize(GraphicsDevice deviceArg, Direct3D11.Buffer resource)
 {
     base.Initialize(deviceArg, resource);
     this.InitializeViews();
 }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BufferBase" /> class.
 /// </summary>
 /// <param name="deviceLocal">The device local.</param>
 /// <param name="nativeBuffer">The native buffer.</param>
 protected BufferBase(GraphicsDevice deviceLocal, Direct3D11.Buffer nativeBuffer)
 {
     Description = nativeBuffer.Description;
     Initialize(deviceLocal, nativeBuffer);
 }
Example #7
0
 public void Update()
 {
     Vertices     = Transformation(Vertices, InitialPosition, Rotation);
     VertexBuffer = Direct3D11.Buffer.Create(Device, BindFlags.VertexBuffer, Vertices);
 }