Esempio n. 1
0
		/// <summary>
		/// This event will be fired immediately after the Direct3D device has been 
		/// reset, which will happen after a lost device scenario. This is the best location to 
		/// create Pool.Default resources since these resources need to be reloaded whenever 
		/// the device is lost. Resources created here should be released in the OnLostDevice 
		/// event. 
		/// </summary>
		private void OnResetDevice(object sender, DeviceEventArgs e)
		{
			Debug.WriteLine("Engine.OnResetDevice()");
			SurfaceDescription desc = e.BackBufferDescription;
			//            // Create a sprite to help batch calls when drawing many lines of text
			//            textSprite = new Sprite(e.Device);

			// reset scene resources
			Scene.OnReset();
		}
Esempio n. 2
0
        /// <summary>
        /// This event will be fired immediately after the Direct3D device has been 
        /// reset, which will happen after a lost device scenario. This is the best location to 
        /// create Pool.Default resources since these resources need to be reloaded whenever 
        /// the device is lost. Resources created here should be released in the OnLostDevice 
        /// event. 
        /// </summary>
        private void OnResetDevice(object sender, DeviceEventArgs e) {
            SurfaceDescription desc = e.BackBufferDescription;
            // Create a sprite to help batch calls when drawing many lines of text
            textSprite = new Sprite(e.Device);

            // Reset items
            lightControl.OnResetDevice(desc);

            // Setup the camera's projection parameters
            float aspectRatio = (float)desc.Width / (float)desc.Height;
            if(nif!=null) {
                camera.SetProjectionParameters((float)Math.PI / 4, aspectRatio, nif.Radius/50, nif.Radius*5);
            } else {
                camera.SetProjectionParameters((float)Math.PI / 4, aspectRatio, 10, 4000);
            }
            camera.SetWindow(desc.Width, desc.Height);
            camera.SetButtonMasks((int)MouseButtonMask.Left, (int)MouseButtonMask.Wheel, (int)MouseButtonMask.Middle);

            // Setup UI locations
            hud.SetLocation(desc.Width-170, 0);
            hud.SetSize(170, 170);
            sampleUi.SetLocation(desc.Width - 170, 60);
            sampleUi.SetSize(170, 300);

            e.Device.RenderState.ZBufferFunction=Compare.Less;
            if(AF==0) {
                for(int i=0;i<3;i++) {
                    e.Device.SamplerState[i].MagFilter=TextureFilter.Linear;
                    e.Device.SamplerState[i].MinFilter=TextureFilter.Linear;
                }
            } else {
                for(int i=0;i<3;i++) {
                    e.Device.SamplerState[i].MaxAnisotropy=AF;
                    e.Device.SamplerState[i].MinFilter=TextureFilter.Anisotropic;
                    e.Device.SamplerState[i].MagFilter=TextureFilter.Linear;
                }
            }

            e.Device.RenderState.AlphaBlendEnable=true;
            e.Device.RenderState.AlphaTestEnable=true;
            e.Device.RenderState.AlphaFunction=Compare.Greater;
            e.Device.RenderState.SourceBlend=Blend.SourceAlpha;
            e.Device.RenderState.DestinationBlend=Blend.InvSourceAlpha;
        }
Esempio n. 3
0
		/// <summary>
		/// This event will be fired immediately after the Direct3D device has been 
		/// created, which will happen during application initialization and windowed/full screen 
		/// toggles. This is the best location to create Pool.Managed resources since these 
		/// resources need to be reloaded whenever the device is destroyed. Resources created  
		/// here should be released in the Disposing event. 
		/// </summary>
		private void OnCreateDevice(object sender, DeviceEventArgs e)
		{
			Debug.WriteLine("Engine.OnCreateDevice()");

			// Define DEBUG_VS and/or DEBUG_PS to debug vertex and/or pixel shaders with the 
			// shader debugger. Debugging vertex shaders requires either REF or software vertex 
			// processing, and debugging pixel shaders requires REF.  The 
			// ShaderFlags.Force*SoftwareNoOptimizations flag improves the debug experience in the 
			// shader debugger.  It enables source level debugging, prevents instruction 
			// reordering, prevents dead code elimination, and forces the compiler to compile 
			// against the next higher available software target, which ensures that the 
			// unoptimized shaders do not exceed the shader model limitations.  Setting these 
			// flags will cause slower rendering since the shaders will be unoptimized and 
			// forced into software.  See the DirectX documentation for more information about 
			// using the shader debugger.
			ShaderFlags shaderFlags = ShaderFlags.NotCloneable;
#if(DEBUG_VS)
            shaderFlags |= ShaderFlags.ForceVertexShaderSoftwareNoOptimizations;
#endif
#if(DEBUG_PS)
            shaderFlags |= ShaderFlags.ForcePixelShaderSoftwareNoOptimizations;
#endif
			// Read the D3DX effect file
			Fx.Load(e.Device, shaderFlags);			// Replaces the default framework code

			// Initialise or re-initialise the scene, which will initialise everything else
			Scene.OnDeviceCreated();

			// Finally, set the subsequentDevice flag to show that any future events follow the loss of a previous device
			subsequentDevice = true;
		}
Esempio n. 4
0
        /// <summary>
        /// This event will be fired immediately after the Direct3D device has been 
        /// created, which will happen during application initialization and windowed/full screen 
        /// toggles. This is the best location to create Pool.Managed resources since these 
        /// resources need to be reloaded whenever the device is destroyed. Resources created  
        /// here should be released in the Disposing event. 
        /// </summary>
        private void OnCreateDevice(object sender, DeviceEventArgs e) {
            // Setup direction widget
            DirectionWidget.OnCreateDevice(e.Device);

            // Initialize the stats font
            statsFont = ResourceCache.GetGlobalInstance().CreateFont(e.Device, 15, 0, FontWeight.Bold, 1, false, CharacterSet.Default,
                Precision.Default, FontQuality.Default, PitchAndFamily.FamilyDoNotCare | PitchAndFamily.DefaultPitch
                , "Arial");

            // Read the D3DX effect file
            string path = "NifViewer.fx";
            string errors;
            effect = ResourceCache.GetGlobalInstance().CreateEffectFromFile(e.Device, path, null, null, ShaderFlags.NotCloneable, null, out errors);

            if(effect==null) {
                MessageBox.Show("Effects.fx Shader compilation failed.\n"+errors, "Error");
            }

            ehLightDir=effect.GetParameter(null, "g_LightDir");
            ehLightCol=effect.GetParameter(null, "g_LightDiffuse");
            egAmbCol=effect.GetParameter(null, "g_LightAmbient");
            ehViewProj=effect.GetParameter(null, "viewProjection");
            ehEyePos=effect.GetParameter(null, "eyePos");
            ehEyeVec=effect.GetParameter(null, "eyeVec");
            ehHalfVec=effect.GetParameter(null, "g_LightHalfVec");

            NifFile.SetEffect(effect);

            // Setup the camera's view parameters
            camera.SetViewParameters(new Vector3(0.0f, 0.0f, -15.0f), Vector3.Empty);
            camera.IsPositionMovementEnabled=true;

            NifFile.SetCamera(camera);

            lightControl.Radius = 10;
            camera.SetRadius(30.0f, 0, 100.0f);
            
        }