Ejemplo n.º 1
0
 /// <summary>
 /// Dispose
 /// </summary>
 /// <param name="disposing">disposing</param>
 protected override void Dispose(bool disposing)
 {
     try
     {
         if (disposing)
         {
             DisposeShaders();
             _contextStatesManager = null;
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
        /// <summary>
        /// Dispose
        /// </summary>
        /// <param name="disposing">disposing</param>
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    DisposeShaders();

                    Ab3d.DirectX.DisposeHelper.DisposeAndNullify(ref _perFrameCameraConstantsBuffer);
                    Ab3d.DirectX.DisposeHelper.DisposeAndNullify(ref _perFrameLightsConstantsBuffer);
                    Ab3d.DirectX.DisposeHelper.DisposeAndNullify(ref _perObjectConstantsBuffer);

                    _contextStatesManager = null;
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets per frame settings for this effect (this sets camera, lights and other per frame settings).
        /// </summary>
        /// <param name="camera">camera</param>
        /// <param name="lights">list of lights</param>
        /// <param name="renderingContext">RenderingContext</param>
        protected override void OnApplyPerFrameSettings(ICamera camera, IList <ILight> lights, RenderingContext renderingContext)
        {
            _renderingContext     = renderingContext;
            _contextStatesManager = renderingContext.ContextStatesManager;


            // Update per frame Camera constant buffer
            _perFrameCameraConstantsBufferData.ViewProjection = camera.GetViewProjection();
            _perFrameCameraConstantsBufferData.EyePosW        = camera.GetCameraPosition();

            renderingContext.DeviceContext.UpdateSubresource(ref _perFrameCameraConstantsBufferData, _perFrameCameraConstantsBuffer);


            // Update per frame Lights constant buffer
            _perFrameLightsConstantsBufferData.AmbientColor = SetupAmbientLight(lights);

            var firstDirectionalLight = lights.OfType <IDirectionalLight>().FirstOrDefault();

            if (firstDirectionalLight == null)
            {
                // No directional light
                _perFrameLightsConstantsBufferData.LightColor     = Color3.Black;
                _perFrameLightsConstantsBufferData.LightDirection = Vector3.Zero;
            }
            else
            {
                _perFrameLightsConstantsBufferData.LightColor = firstDirectionalLight.DiffuseColor;

                _perFrameLightsConstantsBufferData.LightDirection = firstDirectionalLight.Direction;
                _perFrameLightsConstantsBufferData.LightDirection.Normalize();
            }

            renderingContext.DeviceContext.UpdateSubresource(ref _perFrameLightsConstantsBufferData, _perFrameLightsConstantsBuffer);


            _perObjectConstantsBufferData.World = Matrix.Zero; // Set World so the next time the object's worldMatrix will be compared to this value it will not be threted as equal

            _isLastWorldMatrixIdentity = false;
            _isConstantBufferDirty     = true;
        }
        /// <summary>
        /// Sets per frame settings for this effect (this sets camera, lights and other per frame settings).
        /// </summary>
        /// <param name="camera">camera</param>
        /// <param name="lights">list of lights</param>
        /// <param name="renderingContext">RenderingContext</param>
        protected override void OnApplyPerFrameSettings(ICamera camera, IList <ILight> lights, RenderingContext renderingContext)
        {
            _renderingContext     = renderingContext;
            _contextStatesManager = renderingContext.ContextStatesManager;


            // Update per frame Camera constant buffer
            _perFrameCameraConstantsBufferData.ViewProjection = camera.GetViewProjection();
            _perFrameCameraConstantsBufferData.EyePosW        = camera.GetCameraPosition();

            renderingContext.DeviceContext.UpdateSubresource(ref _perFrameCameraConstantsBufferData, _perFrameCameraConstantsBuffer);


            // Update per frame Lights constant buffer
            _perFrameLightsConstantsBufferData.AmbientColor = SetupAmbientLight(lights);

            renderingContext.DeviceContext.UpdateSubresource(ref _perFrameLightsConstantsBufferData, _perFrameLightsConstantsBuffer);


            _perObjectConstantsBufferData.World = Matrix.Zero; // Set World so the next time the object's worldMatrix will be compared to this value it will not be threted as equal

            _isLastWorldMatrixIdentity = false;
            _isConstantBufferDirty     = true;
        }