/// <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) { // Initialize the font drawingFont = ResourceCache.GetGlobalInstance().CreateFont(e.Device, 15, 0, FontWeight.Bold, 1, false, CharacterSet.Default, Precision.Default, FontQuality.Default, PitchAndFamily.FamilyDoNotCare | PitchAndFamily.DefaultPitch , "Arial"); // Create the vertex shader and declaration VertexElement[] elements = new VertexElement[] { new VertexElement(0, 0, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.Position, 0), VertexElement.VertexDeclarationEnd }; vertexDecl = new VertexDeclaration(e.Device, elements); // Find the shader file string path = Utility.FindMediaFile("HLSLwithoutEffects.Fx"); // 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.None; #if (DEBUG_VS) shaderFlags |= ShaderFlags.ForceVertexShaderSoftwareNoOptimizations; #endif #if (DEBUG_PS) shaderFlags |= ShaderFlags.ForcePixelShaderSoftwareNoOptimizations; #endif string errors; using (GraphicsStream code = ShaderLoader.CompileShaderFromFile(path, "Ripple", null, null, "vs_1_1", shaderFlags, out errors, out constantTable)) { // We will store these constants in an effect handle here for performance reasons. // You could simply use the string value (i.e., "worldViewProj") in the SetValue call // and it would work just as well, but that actually requires an allocation to be made // and can actually slow your performance down. It's much more efficient to simply // cache these handles for use later worldViewHandle = constantTable.GetConstant(null, "worldViewProj"); timeHandle = constantTable.GetConstant(null, "appTime"); // Create the shader shader = new VertexShader(e.Device, code); } // Setup the camera's view parameters camera.SetViewQuat(new Quaternion(-0.275f, 0.3f, 0.0f, 0.7f)); }